package com.njcn.csdevice.controller.equipment;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
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.csdevice.pojo.po.CsEventSendMsg;
import com.njcn.csdevice.pojo.vo.CsEventSendMsgVO;
import com.njcn.csdevice.service.ICsEventSendMsgService;
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;

import java.util.List;

/**
 * <p>
 * 事件推送日志表 前端控制器
 * </p>
 *
 * @author xuyang
 * @since 2023-09-18
 */
@RestController
@RequestMapping("/csEventSendMsg")
@Slf4j
@Api(tags = "推送日志管理")
@AllArgsConstructor
public class CsEventSendMsgController extends BaseController {

    private final ICsEventSendMsgService csEventSendMsgService;

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("新增推送日志")
    @ApiImplicitParam(name = "list", value = "日志记录", required = true)
    public HttpResult<String> addLogs(@RequestBody List<CsEventSendMsg> list) {
        String methodDescribe = getMethodDescribe("addLogs");
        csEventSendMsgService.saveBatch(list);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryLog")
    @ApiOperation("查询推送日志")
    @ApiImplicitParam(name = "baseParam", value = "查询日志参数", required = true)
    public HttpResult<Page<CsEventSendMsgVO>> queryLog(@RequestBody BaseParam baseParam){
        String methodDescribe = getMethodDescribe("queryLog");
        Page<CsEventSendMsgVO> list = csEventSendMsgService.queryPage(baseParam);

        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

}

