package com.gree.mall.manager.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.manager.bean.admin.AdminUserBean;
import com.gree.mall.manager.exception.RemoteServiceException;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.admin.OperationLogLogic;
import com.gree.mall.manager.plus.entity.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@Api(value = "操作日志", tags ={"操作日志"} )
@RequestMapping(value = "/admin/operation/log", produces = "application/json; charset=utf-8")
public class OperationLogController {

    @Autowired
    OperationLogLogic operationLogLogic;

    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public ResponseHelper<IPage<OperationLog>> list(
            HttpServletRequest request,
            @ApiParam(value = "模块名称",required = false) @RequestParam(required = false) String moduleName,
            @ApiParam(value = "开始时间",required = false) @RequestParam(required = false) String startTime,
            @ApiParam(value = "结束时间",required = false) @RequestParam(required = false) String endTime,
            @ApiParam(value = "页号",required = true) @RequestParam(required = true) Integer pageNo,
            @ApiParam(value = "页大小",required = true) @RequestParam(required = true) Integer pageSize
    ) throws RemoteServiceException {
        IPage<OperationLog> operationLogIPage = operationLogLogic.listPage(request, moduleName, startTime, endTime, pageNo, pageSize);
        return ResponseHelper.success(operationLogIPage);
    }

    @GetMapping("/module")
    @ApiOperation(value = "所属模块")
    public ResponseHelper<List<String>> moduleList(HttpServletRequest request){
        return ResponseHelper.success(operationLogLogic.moduleList(request));
    }


    @GetMapping("/detail")
    @ApiOperation(value = "详情")
    public ResponseHelper<OperationLog> detail(
            @ApiParam(value = "operationLogId",required = true) @RequestParam(required = true) String operationLogId
    ) throws RemoteServiceException {
        OperationLog detail = operationLogLogic.detail(operationLogId);
        return ResponseHelper.success(detail);
    }
}
