package com.njcn.device.pq.controller;

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.param.StatisticsBizBaseParam;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.pq.pojo.param.GridDiagramParam;
import com.njcn.device.pq.pojo.po.RStatIntegrityD;
import com.njcn.device.pq.pojo.po.RStatOnlinerateD;
import com.njcn.device.pq.pojo.vo.GridDiagramProVO;
import com.njcn.device.pq.pojo.vo.GridDiagramVO;
import com.njcn.device.pq.pojo.vo.LoadTypeVO;
import com.njcn.device.pq.service.GridDiagramService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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


@Validated
@Slf4j
@RestController
@RequestMapping("/gridDiagram")
@Api(tags = "冀北电网一张图信息展示")
@AllArgsConstructor
public class GridDiagramController extends BaseController {

    private final GridDiagramService gridDiagramService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getGridDiagramMonitor")
    @ApiOperation("监测点统计(总数/在线)")
    public HttpResult<GridDiagramVO> getGridDiagramMonitor(@RequestBody GridDiagramParam param){
        String methodDescribe = getMethodDescribe("getGridDiagramMonitor");
        GridDiagramVO gridDiagramMonitor = gridDiagramService.getGridDiagramMonitor(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, gridDiagramMonitor, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getGridDiagramDev")
    @ApiOperation("终端统计(在运/在线)")
    public HttpResult<GridDiagramVO> getGridDiagramDev(@RequestBody GridDiagramParam param){
        String methodDescribe = getMethodDescribe("getGridDiagramDev");
        GridDiagramVO gridDiagramMonitor = gridDiagramService.getGridDiagramDev(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, gridDiagramMonitor, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getGridDiagramSubTendency")
    @ApiOperation("变电站趋势分析")
    public HttpResult<Map<String, Long>> getGridDiagramSubTendency(@RequestBody GridDiagramParam param){
        String methodDescribe = getMethodDescribe("getGridDiagramSubTendency");
        Map<String, Long> gridDiagramDevTendency = gridDiagramService.getGridDiagramDevTendency(param,3);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, gridDiagramDevTendency, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getGridDiagramDevTendency")
    @ApiOperation("终端趋势分析")
    public HttpResult<Map<String, Long>> getGridDiagramDevTendency(@RequestBody GridDiagramParam param){
        String methodDescribe = getMethodDescribe("getGridDiagramDevTendency");
        Map<String, Long> gridDiagramDevTendency = gridDiagramService.getGridDiagramDevTendency(param,4);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, gridDiagramDevTendency, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getGridDiagramDevData")
    @ApiOperation("终端分布统计")
    public HttpResult<List<GridDiagramVO.DeviceData>> getGridDiagramDevData(@RequestBody GridDiagramParam param){
        String methodDescribe = getMethodDescribe("getGridDiagramDevData");
        List<GridDiagramVO.DeviceData> gridDiagramDevData = gridDiagramService.getGridDiagramDevData(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, gridDiagramDevData, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getGridDiagramDevDataList")
    @ApiOperation("区域终端统计")
    public HttpResult<List<GridDiagramVO.DevData>> getGridDiagramDevDataList(@RequestBody GridDiagramParam param){
        String methodDescribe = getMethodDescribe("getGridDiagramDevDataList");
        List<GridDiagramVO.DevData> gridDiagramDevDataList = gridDiagramService.getGridDiagramDevDataList(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, gridDiagramDevDataList, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getGridDiagramLineTendency")
    @ApiOperation("监测点趋势分析")
    public HttpResult<Map<String, Long>> getGridDiagramLineTendency(@RequestBody GridDiagramParam param){
        String methodDescribe = getMethodDescribe("getGridDiagramLineTendency");
        param.getDeviceInfoParam().setLineRunFlag(0);
        Map<String, Long> gridDiagramDevTendency = gridDiagramService.getGridDiagramDevTendency(param,6);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, gridDiagramDevTendency, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getGridDiagramStatistics")
    @ApiOperation("监测点指标统计")
    public HttpResult<GridDiagramProVO> getGridDiagramStatistics(@RequestBody StatisticsBizBaseParam param){
        String methodDescribe = getMethodDescribe("getGridDiagramStatistics");
        GridDiagramProVO gridDiagramDevTendency = gridDiagramService.getGridDiagramStatistics(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, gridDiagramDevTendency, methodDescribe);
    }



    //---------------------------------------------------市级---------------------------------------

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getGridDiagramCityDev")
    @ApiOperation("监测终端状态")
    public HttpResult<List<String>> getGridDiagramCityDev(@RequestBody GridDiagramParam param){
        String methodDescribe = getMethodDescribe("getGridDiagramCityDev");
        param.getDeviceInfoParam().setLineRunFlag(0);
        List<String> gridDiagramCityDev = gridDiagramService.getGridDiagramCityDev(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, gridDiagramCityDev, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getGridDiagramIntegrityD")
    @ApiOperation("监测点完整性")
    public HttpResult<List<RStatIntegrityD>> getGridDiagramIntegrityD(@RequestBody StatisticsBizBaseParam param){
        String methodDescribe = getMethodDescribe("getGridDiagramIntegrityD");
        List<RStatIntegrityD> gridDiagramIntegrityD = gridDiagramService.getGridDiagramIntegrityD(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, gridDiagramIntegrityD, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getGridDiagramOnLineRateD")
    @ApiOperation("终端在线率列表")
    public HttpResult<List<RStatOnlinerateD>> getGridDiagramOnLineRateD(@RequestBody StatisticsBizBaseParam param){
        String methodDescribe = getMethodDescribe("getGridDiagramOnLineRateD");
        List<RStatOnlinerateD> gridDiagramOnLineRateD = gridDiagramService.getGridDiagramOnLineRateD(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, gridDiagramOnLineRateD, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/loadTypeVOList")
    @ApiOperation("干扰源类型统计")
    public HttpResult<List<LoadTypeVO>> loadTypeVOList(@RequestBody GridDiagramParam param){
        String methodDescribe = getMethodDescribe("loadTypeVOList");
        List<LoadTypeVO> loadTypeVOList = gridDiagramService.loadTypeVOList(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, loadTypeVOList, methodDescribe);
    }
}
