package com.njcn.energy.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.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.energy.pojo.enums.EnergyResponseEnum;
import com.njcn.energy.pojo.param.ElectComparaParam;
import com.njcn.energy.pojo.param.JobInfoParam;
import com.njcn.common.utils.LogUtil;
import com.njcn.energy.pojo.param.LineParam;
import com.njcn.energy.pojo.param.LoadStatisticParam;
import com.njcn.energy.pojo.po.EleLine;
import com.njcn.energy.pojo.po.LogicDev;
import com.njcn.energy.pojo.vo.ElectCompareVO;
import com.njcn.energy.pojo.vo.LoadStatisticVO;
import com.njcn.energy.pojo.vo.LoadTendencyVO;
import com.njcn.energy.service.HighAnalyticService;

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.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;


/**
 * pqs
 * 高级分析
 * @author cdf
 * @date 2022/4/14
 */
@Slf4j
@RestController
@RequestMapping("/advance")
@AllArgsConstructor
@Api(tags = "高级分析")
public class HighAnalyticController extends BaseController {

    private final HighAnalyticService highAnalyticService;


    /**
     * 获取负荷趋势分析
     * @author cdf
     * @date 2022/4/15
     */

    @GetMapping("getLoadTendency")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取负荷趋势分析")
    public HttpResult<List<LoadTendencyVO>> getLoadTendency(@RequestParam("loadType")String loadType,@RequestParam("startTime")String startTime,@RequestParam("endTime")String endTime){
        String methodDescribe = getMethodDescribe("getLoadTendency");
        List<LoadTendencyVO> res = highAnalyticService.getLoadTendency(loadType,startTime,endTime);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
    }

    /**
     * 负荷占比
     * @author cdf
     * @date 2022/4/19
     */
    @PostMapping("getLoadRate")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("负荷占比分析")
    public HttpResult<List<Map<String,String>>> getLoadRate(@RequestParam("loadType")String loadType,@RequestParam("startTime")String startTime){
        String methodDescribe = getMethodDescribe("getLoadRate");
        List<Map<String,String>> res = highAnalyticService.getLoadRate(loadType,startTime);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
    }

    /**
     * 获取负荷趋势分析
     * @author cdf
     * @date 2022/4/15
     */

    @GetMapping("getLoadDetail")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取负荷详情")
    public HttpResult<List<LoadTendencyVO>> getLoadDetail(@RequestParam("loadType")String loadType,@RequestParam("startTime")String startTime,@RequestParam("endTime")String endTime){
        String methodDescribe = getMethodDescribe("getLoadDetail");
        List<LoadTendencyVO> res = highAnalyticService.getLoadDetail(loadType,startTime,endTime);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
    }


    /**
     * 负荷统计分析
     * @author cdf
     * @date 2022/4/18
     */
    @PostMapping("getLoadStatistics")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("负荷统计分析")
    public HttpResult<List<LoadStatisticVO>> getLoadStatistics(@Validated @RequestBody LoadStatisticParam loadStatisticParam){
        String methodDescribe = getMethodDescribe("getLoadStatistics");
        if(loadStatisticParam.getLoadType().size() !=1){
            if(loadStatisticParam.getValType().size()!=1){
                throw new BusinessException(EnergyResponseEnum.LOAD_VAL_CONFLICT);
            }
        }
        List<LoadStatisticVO> res = highAnalyticService.getLoadStatistics(loadStatisticParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
    }


    /**
     * 电度趋势分析
     * @author cdf
     * @date 2022/4/19
     */
    @GetMapping("getElectTendency")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取电度趋势分析")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "loadType", value = "指标类型id", required = true),
            @ApiImplicitParam(name = "type", value = "0.增量 1.累计", required = true),
    })
    public HttpResult<List<LoadTendencyVO>> getElectTendency(@RequestParam("loadType")String loadType,@RequestParam("type")Integer type,@RequestParam("startTime")String startTime,@RequestParam("endTime")String endTime){
        String methodDescribe = getMethodDescribe("getElectTendency");
        List<LoadTendencyVO> res = highAnalyticService.getElectTendency(loadType,type,startTime,endTime);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
    }


    /**
     * 电度对比分析
     * @author cdf
     * @date 2022/4/19
     */
    @PostMapping("getElectCompare")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("电度对比分析")
    public HttpResult<List<ElectCompareVO>> getElectCompare(@RequestBody ElectComparaParam electComparaParam){
        String methodDescribe = getMethodDescribe("getElectCompare");
        List<ElectCompareVO> res = highAnalyticService.getElectCompare(electComparaParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
    }

    /**
     * 电度占比
     * @author cdf
     * @date 2022/4/19
     */
    @PostMapping("getElectRate")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("电度占比")
    public HttpResult<List<Map<String,String>>> getElectRate(@RequestBody ElectComparaParam electComparaParam){
        String methodDescribe = getMethodDescribe("getElectRate");
        List<Map<String,String>> res = highAnalyticService.getElectRate(electComparaParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
    }


    /**
     * 电度统计分析
     * @author cdf
     * @date 2022/4/19
     */
    @PostMapping("getElectStatistic")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("电度统计分析")
    public HttpResult<List<LoadStatisticVO>> getElectStatistic(@Validated @RequestBody ElectComparaParam electComparaParam){
        String methodDescribe = getMethodDescribe("getElectStatistic");
        List<LoadStatisticVO> res = highAnalyticService.getElectStatistic(electComparaParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
    }


    /**
     * 获取空调趋势
     * @author cdf
     * @date 2022/4/18
     */
    @GetMapping("getAirTendency")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取空调趋势")
    public HttpResult<List<LoadTendencyVO>> getAirTendency(@RequestParam("startTime")String startTime,@RequestParam("endTime")String endTime){
        String methodDescribe = getMethodDescribe("getAirTendency");
        List<LoadTendencyVO> res = highAnalyticService.getAirTendency(startTime,endTime);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
    }







}
