package com.njcn.product.event.transientes.controller;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
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.product.event.dataTransmit.DataSynchronization;
import com.njcn.product.event.devcie.pojo.dto.DeviceDTO;
import com.njcn.product.event.transientes.pojo.dto.MessaeDTO;
import com.njcn.product.event.transientes.pojo.param.LargeScreenCountParam;
import com.njcn.product.event.transientes.pojo.param.MessageEventFeedbackParam;
import com.njcn.product.event.transientes.pojo.po.MsgEventInfo;
import com.njcn.product.event.transientes.pojo.vo.*;
import com.njcn.product.event.transientes.service.LargeScreenCountService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description:
 * Date: 2025/06/19  下午 3:00【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Slf4j
@Api(tags = "大屏统计")
@RestController
@RequestMapping("/largescreen")
@RequiredArgsConstructor
public class LargeScreenCountController extends BaseController {

    private final LargeScreenCountService largeScreenCountService;

    @OperateInfo
    @PostMapping("/initLedger")
    @ApiOperation("台账规模统计")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<Object> initLedger(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("initLedger");
        largeScreenCountService.initLedger(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo
    @PostMapping("/ledgercount")
    @ApiOperation("台账规模统计")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<LedgerCountVO> scaleStatistics(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("scaleStatistics");
        LedgerCountVO result = largeScreenCountService.scaleStatistics(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo
    @PostMapping("/alarmAnalysis")
    @ApiOperation("告警统计分析")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<AlarmAnalysisVO> alarmAnalysis(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("alarmAnalysis");
        AlarmAnalysisVO result = largeScreenCountService.alarmAnalysis(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }
    @OperateInfo
    @PostMapping("/alarmAnalysisDetail")
    @ApiOperation("告警统计分析详情")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<AlarmAnalysisVO> alarmAnalysisDetail(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("alarmAnalysisDetail");
        AlarmAnalysisVO result = largeScreenCountService.alarmAnalysisDetail(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo
    @PostMapping("/eventTablePage")
    @ApiOperation("告警统计分析详情")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<Page<EventDetailVO>> eventTablePage(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("alarmAnalysisDetail");
        Page<EventDetailVO> result = largeScreenCountService.eventTablePage(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo
    @PostMapping("/eventTrend")
    @ApiOperation("暂降事件趋势")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<List<EventTrendVO>> eventTrend(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("eventTrend");
        List<EventTrendVO> result = largeScreenCountService.eventTrend(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo
    @PostMapping("/eventList")
    @ApiOperation("暂降事件列表")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<Page<EventDetailVO>> eventList(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("eventList");
        Page<EventDetailVO> result = largeScreenCountService.eventList(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo
    @PostMapping("/noDealEventList")
    @ApiOperation("未处理暂降事件列表")
    @Deprecated
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<List<EventDetailVO>> noDealEventList(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("noDealEventList");
        List<EventDetailVO> result = largeScreenCountService.noDealEventList(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }
    @OperateInfo
    @PostMapping("/noDealEventListMessage")
    @ApiOperation("未处理暂降事件列表(短信)")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<List<MessageEventVO>> noDealEventListMessage(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("noDealEventListMessage");
        List<MessageEventVO> result = largeScreenCountService.noDealEventListMessage(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }
    @OperateInfo
    @PostMapping("/mapCount")
    @ApiOperation("地图统计")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<List<MapCountVO>> mapCount(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("mapCount");
        List<MapCountVO> result = largeScreenCountService.mapCount(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo(operateType= OperateType.UPDATE)
    @PostMapping("/lookEvent")
    @ApiOperation("处理暂降事件")
    @Deprecated
    @ApiImplicitParam(name = "eventIds", value = "暂降事件id", required = true)
    public HttpResult<Boolean> lookEvent(@RequestBody List<String> eventIds) {
        String methodDescribe = getMethodDescribe("lookEvent");
        boolean result = largeScreenCountService.lookEvent(eventIds);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(operateType= OperateType.UPDATE)
    @PostMapping("/lookMessage")
    @ApiOperation("处理推送消息")
    @ApiImplicitParam(name = "eventIds", value = "暂降事件id", required = true)
    public HttpResult<Boolean> lookMessage(@RequestBody List<String> messageIds) {
        String methodDescribe = getMethodDescribe("lookMessage");
        boolean result = largeScreenCountService.lookMessage(messageIds);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo
    @GetMapping("/eventMsgDetail")
    @ApiOperation("暂降事件列表详情按钮")
    @ApiImplicitParam(name = "eventId", value = "暂降事件id", required = true)
    public HttpResult<EventMsgDetailVO> eventMsgDetail(@RequestParam("eventId")String eventId) {
        String methodDescribe = getMethodDescribe("eventMsgDetail");
        EventMsgDetailVO result = largeScreenCountService.eventMsgDetail(eventId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo
    @PostMapping("/msgSendList")
    @ApiOperation("远程通知列表")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "参数", required = true)
    public HttpResult<List<MsgEventInfo>> msgSendList(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("msgSendList");
        List<MsgEventInfo> result = largeScreenCountService.msgSendList(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo
    @PostMapping("/hasSendMsgPage")
    @ApiOperation("已发送短信列表")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "参数", required = true)
    public HttpResult<Page<MsgEventInfo>> hasSendMsgPage(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("hasSendMsgPage");
        Page<MsgEventInfo> result = largeScreenCountService.hasSendMsgPage(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(operateType = OperateType.ADD)
    @PostMapping("/msgHandle")
    @ApiOperation("短信处理")
    @ApiImplicitParam(name = "eventId", value = "暂降事件id", required = true)
    public HttpResult<Boolean> msgHandle(@RequestBody @Validated MessageEventFeedbackParam messageEventFeedbackParam) {
        String methodDescribe = getMethodDescribe("msgHandle");
        largeScreenCountService.msgHandle(messageEventFeedbackParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }


    @OperateInfo
    @PostMapping("/devFlagCount")
    @ApiOperation("终端运行统计")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<DeviceCountVO> devFlagCount(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("devFlagCount");
        DeviceCountVO deviceCountVO = largeScreenCountService.devFlagCount(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, deviceCountVO, methodDescribe);
    }
    @OperateInfo
    @PostMapping("/devDetail")
    @ApiOperation("终端运行统计")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<List<DeviceDTO>> devDetail(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("devDetail");
        List<DeviceDTO> deviceDTOList = largeScreenCountService.devDetail(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, deviceDTOList, methodDescribe);
    }

    @OperateInfo
    @PostMapping("/areaDevCount")
    @ApiOperation("区域终端统计")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<List<RegionDevCountVO>> areaDevCount(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("areaDevCount");
        List<RegionDevCountVO> result = largeScreenCountService.regionDevCount(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo
    @PostMapping("/substationCount")
    @ApiOperation("变电站统计")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<List<SubStationCountVO>> substationCount(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("substationCount");
        List<SubStationCountVO> result = largeScreenCountService.substationCount(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo
    @PostMapping("/regionDevCount")
    @ApiOperation("区域终端统计")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<List<RegionDevCountVO>> rightUserStatistic(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("rightUserStatistic");
        List<RegionDevCountVO> result = largeScreenCountService.regionDevCount(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }




    @OperateInfo
    @PostMapping("/eventPage")
    @ApiOperation("分页查询暂降事件")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<Page<EventDetailVO>> eventPage(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("eventPage");
        Page<EventDetailVO> result = largeScreenCountService.eventPage(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo
    @PostMapping("/eventPageExport")
    @ApiOperation("导出暂降事件报告")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<List<EventDetailVO>> eventPageExport(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("eventPageExport");
        List<EventDetailVO> result = largeScreenCountService.eventPageExport(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    @OperateInfo
    @PostMapping("/devicePage")
    @ApiOperation("终端分页查询")
    @ApiImplicitParam(name = "largeScreenCountParam", value = "查询参数", required = true)
    public HttpResult<Page<DeviceDTO>> devicePage(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("devicePage");
        Page<DeviceDTO> result = largeScreenCountService.devicePage(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @OperateInfo(operateType= OperateType.UPDATE)
    @PostMapping("/userEventList")
    @ApiOperation("查询暂降事件")
    @ApiImplicitParam(name = "eventIds", value = "暂降事件id", required = true)
    public HttpResult<Page<EventDetailVO>> userEventList(@RequestBody LargeScreenCountParam largeScreenCountParam) {
        String methodDescribe = getMethodDescribe("userEventList");
        Page<EventDetailVO> result = largeScreenCountService.userEventList(largeScreenCountParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/exportLineData")
    @ApiOperation("导出台账数据数据")
    public void exportEventData() {
        largeScreenCountService.exportLineData();
    }

    @Autowired
    private DataSynchronization synchronization;

    @GetMapping("sycnEvent")
    public boolean sycnEvent(@RequestParam("startDateTime")   String startDateTime,@RequestParam("endDateTime")  String endDateTime) throws Exception {
        synchronization.syncEvents(LocalDateTimeUtil.parse(startDateTime, DatePattern.NORM_DATETIME_PATTERN),LocalDateTimeUtil.parse(endDateTime, DatePattern.NORM_DATETIME_PATTERN));
        return true;
    }

    @GetMapping("sycnUser")
    public boolean sycnUser() throws Exception {
        synchronization.syncUser();
        return true;
    }


}
