package com.njcn.harmonic.controller;


import cn.hutool.core.util.StrUtil;
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.harmonic.pojo.param.*;
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
import com.njcn.harmonic.pojo.vo.*;
import com.njcn.harmonic.service.IRStatLimitRateDService;
import com.njcn.web.controller.BaseController;
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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Validated
@RestController
@RequiredArgsConstructor
@Api(tags = "合格率统计日表(越限次数)")
public class RStatLimitRateDController extends BaseController {

    private final IRStatLimitRateDService limitRateDService;

    /**
     * 来源于RStatLimitController的monitorIdsGetLimitRateInfo
     */
    @PostMapping("/limitRateD/monitorIdsGetLimitRateInfo")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("获取指定日期超标监测点详细信息")
    public HttpResult<List<RStatLimitRateDPO>> monitorIdsGetLimitRateInfo(@RequestBody RStatLimitQueryParam rStatLimitQueryParam) {
        String methodDescribe = getMethodDescribe("monitorIdsGetLimitRateInfo");
        List<RStatLimitRateDPO> result = limitRateDService.monitorIdsGetLimitRateInfo(rStatLimitQueryParam.getDate(), rStatLimitQueryParam.getIds());
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    /**
     * 来源于RStatLimitController的getOverData
     */
    @PostMapping("/limitRateD/getOverData")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("查询单监测点超标数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineId", value = "监测点id"),
            @ApiImplicitParam(name = "startTime", value = "开始时间"),
            @ApiImplicitParam(name = "endTime", value = "结束时间"),
            @ApiImplicitParam(name = "type", value = "指标"),
    })
    public HttpResult<List<RStatLimitRateDPO>> getOverData(@RequestParam("lineId") String lineId, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime, @RequestParam("type") Integer type) {
        String methodDescribe = getMethodDescribe("getOverData");
        List<RStatLimitRateDPO> result = limitRateDService.getOverData(lineId, startTime, endTime, type);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    /**
     * 来源于 HistoryResultController的getLinesRate
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/harmonic/getLinesRate")
    @ApiOperation("获取越线监测点越线次数")
    @ApiImplicitParam(name = "param", value = "获取越线监测点越线次数请求参数", required = true)
    public HttpResult<List<RStatLimitRateDPO>> getLinesRate(@RequestBody StatSubstationBizBaseParam param) {
        String methodDescribe = getMethodDescribe("getLinesTarget");
        List<RStatLimitRateDPO> list = limitRateDService.list(new LambdaQueryWrapper<RStatLimitRateDPO>()
                .in(RStatLimitRateDPO::getLineId, param.getIds())
                .eq(RStatLimitRateDPO::getPhasicType, "T")
                .ge(StrUtil.isNotBlank(param.getStartTime()), RStatLimitRateDPO::getTime, param.getStartTime())
                .le(StrUtil.isNotBlank(param.getEndTime()), RStatLimitRateDPO::getTime, param.getEndTime())

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

    @PostMapping("/mainLine/list")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("获取主要监测点列表")
    public HttpResult<Page<MainLineVO>> mainLineList(@RequestBody MainLineQueryParam mainLineQueryParam) {
        String methodDescribe = getMethodDescribe("mainLineList");
        Page<MainLineVO> list = limitRateDService.mainLineList(mainLineQueryParam);

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

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/mainLine/statLimitRateDetails")
    @ApiOperation("监测点指标越限详情")
    @ApiImplicitParam(name = "param", value = "获取监测点指标越限详情请求参数", required = true)
    public HttpResult<List<MainLineStatLimitRateDetailsVO>> mainLineStatLimitRateDetails(@RequestBody MainLineStatLimitRateDetailsQueryParam param) {
        String methodDescribe = getMethodDescribe("mainLineStatLimitRateDetails");
        List<MainLineStatLimitRateDetailsVO> list = limitRateDService.mainLineStatLimitRateDetails(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    @PostMapping("/totalLimitStatistics/data")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("总体指标越限统计数据")
    public HttpResult<TotalLimitTotalStatisticsVO> totalLimitTotalStatisticsData(@RequestBody TotalLimitStatisticsParam mainLineQueryParam) {
        String methodDescribe = getMethodDescribe("totalLimitStatisticsList");
        TotalLimitTotalStatisticsVO data = limitRateDService.totalLimitTotalStatisticsData(mainLineQueryParam);

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

    @PostMapping("/totalLimitStatistics/list")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("总体指标越限统计列表")
    public HttpResult<List<TotalLimitStatisticsVO>> totalLimitStatisticsList(@RequestBody TotalLimitStatisticsParam mainLineQueryParam) {
        String methodDescribe = getMethodDescribe("totalLimitStatisticsList");
        List<TotalLimitStatisticsVO> list = limitRateDService.totalLimitStatisticsList(mainLineQueryParam);

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

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/totalLimitStatistics/details")
    @ApiOperation("每日越限占比统计")
    @ApiImplicitParam(name = "param", value = "每日越限占比统计请求参数", required = true)
    public HttpResult<List<TotalLimitStatisticsDetailsVO>> totalLimitStatisticsDetails(@RequestBody TotalLimitStatisticsDetailsQueryParam param) {
        String methodDescribe = getMethodDescribe("totalLimitStatisticsDetails");
        List<TotalLimitStatisticsDetailsVO> list = limitRateDService.totalLimitStatisticsDetails(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    @PostMapping("/gridSideLimitStatistics/data")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("电网侧指标越限统计数据")
    public HttpResult<TotalLimitTotalStatisticsVO> gridSideLimitTotalStatisticsData(@RequestBody TotalLimitStatisticsParam mainLineQueryParam) {
        String methodDescribe = getMethodDescribe("gridSideLimitTotalStatisticsData");
        TotalLimitTotalStatisticsVO data = limitRateDService.gridSideLimitTotalStatisticsData(mainLineQueryParam);

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

    @PostMapping("/gridSideLimitStatistics/list")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("电网侧指标越限统计列表")
    public HttpResult<List<TotalLimitStatisticsVO>> gridSideLimitStatisticsList(@RequestBody TotalLimitStatisticsParam mainLineQueryParam) {
        String methodDescribe = getMethodDescribe("gridSideLimitStatisticsList");
        List<TotalLimitStatisticsVO> list = limitRateDService.gridSideLimitStatisticsList(mainLineQueryParam);

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