package com.lantone.security.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lantone.common.api.CommonResult;
import com.lantone.common.dto.AbnormalLogDTO;
import com.lantone.common.dto.GetOperationLogDTO;
import com.lantone.common.dto.LoginLogDTO;
import com.lantone.common.dto.OperationLogDTO;
import com.lantone.common.vo.BlockLossTypeGatherVO;
import com.lantone.common.vo.DataCompareVO;
import com.lantone.security.vo.GetAbnormalLogVO;
import com.lantone.security.vo.GetAbnormalWayAndIpVO;
import com.lantone.security.vo.GetLoginLogVO;
import com.lantone.security.vo.GetLoginNameAndIpVO;
import com.lantone.security.vo.GetOperationLogVO;
import com.lantone.security.facade.LogManagementFacade;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

/**
 * @Description: 日志管理API
 * @author: cy
 * @time: 2021/9/06 13:51
 */
@RestController
@Api(value = "日志管理API", tags = { "日志管理API" })
@RequestMapping("/logManage")
public class LogManagementController {
    @Autowired
    private LogManagementFacade logManagementFacade;


    @ApiOperation(value = "查看登录日志[by:cy]")
    @PostMapping("/getLoginLog")
    public CommonResult<IPage<LoginLogDTO>> getLoginLog(@RequestBody GetLoginLogVO getLoginLogVO) {
        return CommonResult.success(logManagementFacade.getLoginLog(getLoginLogVO));
    }

    @ApiOperation(value = "查看登录日志登录用户|登录ip地址[by:cy]")
    @PostMapping("/getLoginLogNameAndIp")
    public CommonResult<List<String>> getLoginLogNameAndIp(@RequestBody @Valid GetLoginNameAndIpVO getLoginNameAndIpVO) {
        return CommonResult.success(logManagementFacade.getLoginLogNameAndIp(getLoginNameAndIpVO));
    }

    @ApiOperation(value = "新增登录日志[by:cy]")
    @PostMapping("/addLoginLog")
    @ApiIgnore
    public CommonResult<Boolean> addLoginLog(@RequestBody LoginLogDTO loginLog) {
        return CommonResult.success(logManagementFacade.addLoginLog(loginLog));
    }

    @ApiOperation(value = "查看操作日志[by:cy]")
    @PostMapping("/getOperationLog")
    public CommonResult<IPage<OperationLogDTO>> getOperationLog(@RequestBody GetOperationLogVO getOperationLogVO) {
        return CommonResult.success(logManagementFacade.getOperationLog(getOperationLogVO));
    }

    @ApiOperation(value = "查看操作日志操作用户[by:cy]")
    @PostMapping("/getOperationLogName")
    public CommonResult<List<String>> getOperationLogName(@RequestParam String operationName) {
        return CommonResult.success(logManagementFacade.getOperationLogName(operationName));
    }

    @ApiOperation(value = "新增操作日志[by:cy]")
    @PostMapping("/addOperLog")
    @ApiIgnore
    public CommonResult<Boolean> addOperLog(@RequestBody OperationLogDTO operationLog) {
        return CommonResult.success(logManagementFacade.addOperLog(operationLog));
    }

    @ApiOperation(value = "查看异常日志[by:cy]")
    @PostMapping("/getAbnormalLog")
    public CommonResult<IPage<AbnormalLogDTO>> getAbnormalLog(@RequestBody GetAbnormalLogVO getAbnormalLogVO) {
        return CommonResult.success(logManagementFacade.getAbnormalLog(getAbnormalLogVO));
    }

    @ApiOperation(value = "查看异常日志请求方式|ip地址[by:cy]")
    @PostMapping("/getAbnormalLogWayAndIp")
    public CommonResult<List<String>> getAbnormalLogWayAndIp(@RequestBody @Valid GetAbnormalWayAndIpVO getAbnormalWayAndIpVO) {
        return CommonResult.success(logManagementFacade.getAbnormalLogWayAndIp(getAbnormalWayAndIpVO));
    }

    @ApiOperation(value = "新增异常日志[by:cy]")
    @PostMapping("/addOperErrorLog")
    @ApiIgnore
    public CommonResult<Boolean> addOperErrorLog(@RequestBody AbnormalLogDTO abnormalLogDTO) {
        return CommonResult.success(logManagementFacade.addOperErrorLog(abnormalLogDTO));
    }

    @ApiOperation(value = "获取操作记录数据[by:songxl]")
    @PostMapping("/getOperationLogs")
    public CommonResult<List<GetOperationLogDTO>> getOperationLogs(@RequestBody DataCompareVO dataCompareVO) {
        return CommonResult.success(logManagementFacade.getOperationLogs(dataCompareVO));
    }

    @ApiOperation(value = "获取该时间段的日志数量[by:songxl]")
    @PostMapping("/getOperationLogNum")
    public CommonResult<Integer> getOperationLogNum(@RequestBody BlockLossTypeGatherVO blockLossTypeGatherVO) {
        return CommonResult.success(logManagementFacade.getOperationLogNum(blockLossTypeGatherVO));
    }

}