package com.njcn.cssystem.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.dto.DeviceLogDTO;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.cssystem.pojo.po.CsLogsPO;
import com.njcn.cssystem.service.CsLogsPOService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.RestController;

/**
 * Description:
 * Date: 2023/8/7  14:21【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@RestController
@Slf4j
@Api(tags = "日志管理")
@AllArgsConstructor
@RequestMapping("/cslog")
public class CsLogController extends BaseController {

    private final CsLogsPOService csLogsPOService;

    /**
     * 插入审计日志
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("插入设备日志")
    @ApiImplicitParam(name = "deviceLogDTO", value = "插入日志参数", required = true)
    public HttpResult addUserLog(@RequestBody DeviceLogDTO deviceLogDTO) {
        String methodDescribe = getMethodDescribe("addUserLog");
        csLogsPOService.addLog(deviceLogDTO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryLog")
    @ApiOperation("查询日志")
    @ApiImplicitParam(name = "baseParam", value = "查询日志参数", required = true)
    public HttpResult<IPage<CsLogsPO>> queryLog(@RequestBody BaseParam baseParam){
        String methodDescribe = getMethodDescribe("queryLog");
        IPage<CsLogsPO> list = csLogsPOService.queryPage(baseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

}
