package com.njcn.csharmonic.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
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.csharmonic.mapper.CsEventUserPOMapper;
import com.njcn.csharmonic.param.CldWarnParam;
import com.njcn.csharmonic.param.CsEventUserQueryPage;
import com.njcn.csharmonic.param.CsEventUserQueryParam;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
import com.njcn.csharmonic.pojo.vo.EventDetailVO;
import com.njcn.csharmonic.pojo.vo.FrontWarnVo;
import com.njcn.csharmonic.pojo.vo.event.EventStatisticVO;
import com.njcn.csharmonic.service.CsEventUserPOService;
import com.njcn.web.controller.BaseController;
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;

/**
 * Description:
 * Date: 2023/9/4  16:18【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/eventUser")
@Api(tags = "事件")
@AllArgsConstructor
public class EventUserController extends BaseController {

    private final CsEventUserPOService csEventUserPOService;
    private final CsEventUserPOMapper csEventUserPOMapper;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryEvent")
    @ApiOperation("暂降事件未读消息")
    @ApiImplicitParam(name = "csEventUserQueryParam", value = "暂降事件查询参数", required = true)
    public HttpResult<Integer> queryEvent(@RequestBody CsEventUserQueryParam csEventUserQueryParam) {
        String methodDescribe = getMethodDescribe("queryEvent");
        Integer count = csEventUserPOService.queryEventCount(csEventUserQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, count, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryEventList")
    @ApiOperation("事件消息")
    @ApiImplicitParam(name = "csEventUserQueryParam", value = "暂降事件查询参数", required = true)
    public HttpResult<List<EventDetailVO>> queryEventList(@RequestBody CsEventUserQueryParam csEventUserQueryParam) {
        String methodDescribe = getMethodDescribe("queryEventList");
        List<EventDetailVO> list = csEventUserPOService.queryUserEventList(csEventUserQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryEventpage")
    @ApiOperation("事件消息(app)")
    @ApiImplicitParam(name = "csEventUserQueryPage", value = "暂降事件查询参数", required = true)
    public HttpResult<Page<EventDetailVO>> queryEventpage(@RequestBody CsEventUserQueryPage csEventUserQueryPage) {
        String methodDescribe = getMethodDescribe("queryEventpage");
        Page<EventDetailVO> list = csEventUserPOService.queryEventpage(csEventUserQueryPage);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryEventpageWeb")
    @ApiOperation("事件消息(web)")
    @ApiImplicitParam(name = "csEventUserQueryPage", value = "暂降事件查询参数", required = true)
    public HttpResult<Page<EventDetailVO>> queryEventpageWeb(@RequestBody CsEventUserQueryPage csEventUserQueryPage) {
        String methodDescribe = getMethodDescribe("queryEventpageWeb");
        Page<EventDetailVO> list = csEventUserPOService.queryEventPageWeb(csEventUserQueryPage);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/frontWarnInfo")
    @ApiOperation("前置告警信息")
    @ApiImplicitParam(name = "baseParam", value = "基础查询数据", required = true)
    public HttpResult<Page<FrontWarnVo>> frontWarnInfo(@RequestBody CldWarnParam baseParam) {
        String methodDescribe = getMethodDescribe("frontWarnInfo");
        Page<FrontWarnVo> list = csEventUserPOService.getFrontWarnInfo(baseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/updateStatus")
    @ApiOperation("已读事件")
    @ApiImplicitParam(name = "csEventUserQueryParam", value = "暂降事件查询参数", required = true)
    public HttpResult<Boolean> updateStatus(@RequestBody CsEventUserQueryParam csEventUserQueryParam) {
        String methodDescribe = getMethodDescribe("updateStatus");
         csEventUserPOService.updateStatus(csEventUserQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addUserEventList")
    @ApiOperation("新增数据")
    public HttpResult<Boolean> addUserEventList(@RequestBody List<CsEventUserPO> list) {
        String methodDescribe = getMethodDescribe("addUserEventList");
        Boolean result = csEventUserPOService.saveBatch(list);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/deleteByIds")
    @ApiOperation("根据id删除数据")
    public HttpResult<Boolean> deleteByIds(@RequestBody List<String> eventList) {
        String methodDescribe = getMethodDescribe("deleteByIds");
        LambdaQueryWrapper<CsEventUserPO> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(CsEventUserPO::getEventId, eventList);
        Boolean result = csEventUserPOService.remove(wrapper);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryTempEvent")
    @ApiOperation("查询暂态事件(未读)")
    @ApiImplicitParam(name = "param", value = "暂降事件查询参数", required = true)
    public HttpResult<List<String>> queryTempEvent(@RequestBody CsEventUserQueryParam param) {
        String methodDescribe = getMethodDescribe("queryTempEvent");
        List<String> result = csEventUserPOMapper.queryTempEvent(param.getUserId(), param.getStartTime(), param.getEndTime(), param.getEventIds());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryTempEventDetail")
    @ApiOperation("查询暂态事件详细信息(未读)")
    @ApiImplicitParam(name = "param", value = "暂降事件查询参数", required = true)
    public HttpResult<List<CsEventPO>> queryTempEventDetail(@RequestBody CsEventUserQueryParam param) {
        String methodDescribe = getMethodDescribe("queryTempEventDetail");
        List<CsEventPO> result = csEventUserPOMapper.queryTempEventDetail(param.getUserId(), param.getStartTime(), param.getEndTime(), param.getEventIds());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryTempHarmonic")
    @ApiOperation("查询稳态事件(未读)")
    @ApiImplicitParam(name = "param", value = "暂降事件查询参数", required = true)
    public HttpResult<List<String>> queryTempHarmonic(@RequestBody CsEventUserQueryParam param) {
        String methodDescribe = getMethodDescribe("queryTempEvent");
        List<String> result = csEventUserPOMapper.queryTempHarmonic(param.getUserId(), param.getStartTime(), param.getEndTime(), param.getEventIds());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryAlarmEvent")
    @ApiOperation("查询告警事件(未读)")
    @ApiImplicitParam(name = "param", value = "暂降事件查询参数", required = true)
    public HttpResult<List<String>> queryAlarmEvent(@RequestBody CsEventUserQueryParam param) {
        String methodDescribe = getMethodDescribe("queryAlarmEvent");
        List<String> result = csEventUserPOMapper.queryAlarmEvent(param.getUserId(), param.getStartTime(), param.getEndTime(), param.getEventIds());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryRunEvent")
    @ApiOperation("查询运行事件(未读)")
    @ApiImplicitParam(name = "param", value = "暂降事件查询参数", required = true)
    public HttpResult<List<String>> queryRunEvent(@RequestBody CsEventUserQueryParam param) {
        String methodDescribe = getMethodDescribe("queryRunEvent");
        List<String> result = csEventUserPOMapper.queryRunEvent(param.getUserId(), param.getStartTime(), param.getEndTime(), param.getEventIds());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/queryAppEventCounts")
    @ApiOperation("查询App暂态事件总数")
    @ApiImplicitParam(name = "param", value = "暂降事件查询参数", required = true)
    public HttpResult<EventStatisticVO> queryAppEventCounts(@RequestBody CsEventUserQueryPage param) {
        String methodDescribe = getMethodDescribe("queryAppEventCounts");
        EventStatisticVO result = csEventUserPOService.queryAppEventCounts(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

}
