package com.njcn.event.controller.majornetwork;

import cn.hutool.core.collection.CollectionUtil;
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.device.pq.pojo.param.GridDiagramParam;
import com.njcn.event.pojo.dto.EventCount;
import com.njcn.event.pojo.param.EventBaseParam;
import com.njcn.event.pojo.param.UniversalFrontEndParam;
import com.njcn.event.pojo.po.RmpEventDetailPO;
import com.njcn.event.pojo.vo.AdvanceEventDetailVO;
import com.njcn.event.pojo.vo.RmpEventDetailVO;
import com.njcn.event.pojo.vo.TransientVO;
import com.njcn.event.service.majornetwork.RmpEventDetailService;
import com.njcn.system.pojo.po.DictData;
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.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 主网-暂态事件明细
 *
 * @author yzh
 * @date 2022/10/12
 */

@RestController
@RequestMapping("/rmpEventDetail")
@Api(tags = "暂态事件明细")
@RequiredArgsConstructor
public class RmpEventDetailController extends BaseController {

    private final RmpEventDetailService rmpEventDetailService;

    /**
     * 获取暂态事件明细
     *
     * @param param 前端传入参数
     * @return 暂态事件明细
     */
    @PostMapping("/getDetailsOfTransientEvents")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取暂态事件明细")
    @ApiImplicitParam(name = "param", value = "条件参数", required = true)
    public HttpResult<Page<RmpEventDetailVO>> getRmpEventDetail(@RequestBody UniversalFrontEndParam param) {
        String methodDescribe = getMethodDescribe("getRmpEventDetail");
        Page<RmpEventDetailVO> list = rmpEventDetailService.getRmpEventDetail(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    /**
     * 获取暂态指标类型列表
     *
     * @return 暂态指标类型列表
     */
    @GetMapping("/getEventStatisList")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取暂态指标类型列表")
    public HttpResult<List<DictData>> getEventStatisList() {
        String methodDescribe = getMethodDescribe("getEventStatisList");
        List<DictData> list = rmpEventDetailService.getEventStatisList();
        if (CollectionUtil.isEmpty(list)) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.NO_DATA, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
        }
    }

    /**
     * 根据暂降事件id获取详情
     * @author cdf
     * @date 2023/5/17
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getTransientDetailById")
    @ApiOperation("根据暂降事件id获取详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "eventId", value = "暂降事件id", required = true),
            @ApiImplicitParam(name = "sysType", value = "系统类型 pq,pms", required = true),
            @ApiImplicitParam(name = "smallType", value = "主网，配网， 0.主网 1.配网 不填默认主网"),
    })
    public HttpResult<RmpEventDetailVO> getTransientDetailById(@RequestParam("eventId")String eventId,@RequestParam("sysType")String sysType,@RequestParam(value = "smallType",required = false)Integer smallType){
        String methodDescribe = getMethodDescribe("getTransientDetailById");
        RmpEventDetailVO rmpEventDetailVO = rmpEventDetailService.getTransientDetailById(eventId,sysType,smallType);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, rmpEventDetailVO, methodDescribe);
    }


    /**
     * 高级算法-暂降事件关联分析主列表
     * @author cdf
     * @date 2023/7/20
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/querySagEvents")
    @ApiOperation("高级算法-暂降事件关联分析主列表")
    public HttpResult<Page<AdvanceEventDetailVO>> querySagEvents(@RequestBody BaseParam baseParam){
        String methodDescribe = getMethodDescribe("querySagEvents");
        Page<AdvanceEventDetailVO> page = rmpEventDetailService.querySagEvents(baseParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }




    /**
     * 获取暂态事件明细
     * @author cdf
     * @date 2023/7/28
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/queryEventDetailByEventId")
    @ApiOperation("获取暂态事件明细")
    public HttpResult<RmpEventDetailPO> queryEventDetailByEventId(@RequestParam("eventId")String eventId){
        String methodDescribe = getMethodDescribe("queryEventDetailByEventId");
        RmpEventDetailPO objResult = rmpEventDetailService.queryEventDetailByEventId(eventId);
        if(Objects.nonNull(objResult)){
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, objResult, methodDescribe);
        }
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
    }


    /**
     * 查询重要监测点指定时间发生的暂降次数
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getImMonitorEvents")
    @ApiOperation("查询重要监测点指定时间发生的暂降次数")
    public HttpResult<List<Map<String,Object>>> getImMonitorEvents(@RequestBody EventBaseParam param) {
        String methodDescribe = getMethodDescribe("getImMonitorEvents");
        List<Map<String,Object>> result = rmpEventDetailService.getImMonitorEvents(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getEventCount")
    @ApiOperation("根据特征幅值进行统计")
    public HttpResult<List<EventCount>> getEventCount(@RequestBody GridDiagramParam param) {
        String methodDescribe = getMethodDescribe("getEventCount");
        List<EventCount> eventCount = rmpEventDetailService.getEventCount(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, eventCount, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getEventByLineIdsCount")
    @ApiOperation("全景暂降详情列表")
    public HttpResult<Page<AdvanceEventDetailVO>> getEventByLineIdsCount(@RequestBody EventBaseParam.Info param) {
        String methodDescribe = getMethodDescribe("getEventByLineIdsCount");
        Page<AdvanceEventDetailVO> page = rmpEventDetailService.getEventByLineIdsCount(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }
}
