package com.ruoyi.adapter.api;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.adapter.domain.TjDataFormat;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.json.JSONObject;
import com.ruoyi.common.utils.DateTimeUtil;
import com.ruoyi.predict.api.ShareController;
import com.ruoyi.predict.domain.*;
import com.ruoyi.predict.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * @author hlf
 * @date 2022/10/12 15:52
 * 文件说明：图迹功率数据
 * 超短期功率预测(场站(风电、光伏)、期次(风电))
 * 短期功率预测(场站(风电、光伏)、期次(风电))
 * 实时功率(场站(风电、光伏)、期次(风电))
 * 可用功率(场站(风电、光伏)、期次(风电))
 * 理论功率(场站(风电、光伏)、期次(风电))
 */
@Api(value = "图迹功率数据Controller", tags = {"图迹功率数据操作接口"})
@Controller
@RequestMapping("/adapter/api/tjpdc")
public class TuJiPowerDataController extends BaseController {

    @Autowired
    private IWfFileConfigService wfFileConfigService;

    @Autowired
    private IWfUspTsPeriodDataService wfUspTsPeriodDataService;

    @Autowired
    private IPvUspTsPeriodDataService pvUspTsPeriodDataService;

    @Autowired
    private IProjectUspTsPeriodDataService projectUspTsPeriodDataService;

    @Autowired
    private INoscaleWfDaPfPeriodDataService noscaleWfDaPfPeriodDataService;

    @Autowired
    private IPvDaPfPeriodDataService pvDaPfPeriodDataService;

    @Autowired
    private INoscalePrDaPfPeriodDataService noscalePrDaPfPeriodDataService;

    @Autowired
    private IWfStatPeriodDataService wfStatPeriodDataService;

    @Autowired
    private IPvPowerStationService pvPowerStationService;

    @Autowired
    private IWfYcHistoryData1Service wfYcHistoryData1Service;

    @Autowired
    private IWindplantprojectService windplantprojectService;

    @Autowired
    private IWfTheorypowerDataService wfTheorypowerDataService;

    @Autowired
    private IPrTheorypowerDataService prTheorypowerDataService;

    @ApiOperation("超短期功率预测-场站")
    @GetMapping("/getTerminalCdqglycData") 
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationNumber", value = "场站编号", required = true),
            @ApiImplicitParam(name = "itemVal", value = "场站类型(0风电场 4光伏电站)", required = true),
            @ApiImplicitParam(name = "timeScale", value = "时间尺度", required = true),
            @ApiImplicitParam(name = "beginDataTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endDataTime", value = "结束时间", required = true),
    })
    public AjaxResult getTerminalCdqglycData(@RequestParam(value = "stationNumber") String stationNumber,
                                             @RequestParam(value = "itemVal") int itemVal,
                                             @RequestParam(value = "timeScale") int timeScale,
                                             @RequestParam(value = "beginDataTime") String beginDataTime,
                                             @RequestParam(value = "endDataTime") String endDataTime) {
        JSONObject json = new JSONObject();
        //获取所有时间
        List<Date> dateList = DateTimeUtil.getDateList15(DateUtil.parse(beginDataTime), DateUtil.parse(endDataTime));
        LinkedMultiValueMap<String, Double> map = new LinkedMultiValueMap<String, Double>();
        Map<String, Object> params = new HashMap<>();
        params.put("beginDataTime", beginDataTime);
        params.put("endDataTime", endDataTime);
        if (itemVal == 0) {//风电场
            WfFileConfig wfFileConfig = wfFileConfigService.selectWfFileConfigById(Convert.toLong(stationNumber));
            if (ObjectUtil.isNotNull(wfFileConfig)) {
                WfUspTsPeriodData wfUspTsPeriodData = new WfUspTsPeriodData();
                wfUspTsPeriodData.setWindplantNo(Convert.toLong(stationNumber));
                wfUspTsPeriodData.setModelNo(wfFileConfig.getUwpfmodelNo());
                wfUspTsPeriodData.setTimeScale(Convert.toLong(timeScale));
                wfUspTsPeriodData.setParams(params);
                List<WfUspTsPeriodData> wfUspTsPeriodDataList = wfUspTsPeriodDataService.selectWfUspTsPeriodDataList(wfUspTsPeriodData);
                if (wfUspTsPeriodDataList.size() > 0) {
                    for (WfUspTsPeriodData w : wfUspTsPeriodDataList) {
                        ShareController.addMapValue(map, w.getModPower(), DateUtil.format(w.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                    }
                }
            }
        } else if (itemVal == 4) {//光伏电站
            WfFileConfig wfFileConfig = wfFileConfigService.selectWfFileConfigById(Convert.toLong(stationNumber));
            if (ObjectUtil.isNotNull(wfFileConfig)) {
                PvUspTsPeriodData pvUspTsPeriodData = new PvUspTsPeriodData();
                pvUspTsPeriodData.setPvNo(Convert.toLong(stationNumber));
                pvUspTsPeriodData.setModelNo(wfFileConfig.getUwpfmodelNo());
                pvUspTsPeriodData.setTimeScale(Convert.toLong(timeScale));
                pvUspTsPeriodData.setParams(params);
                List<PvUspTsPeriodData> pvUspTsPeriodDataList = pvUspTsPeriodDataService.selectPvUspTsPeriodDataList(pvUspTsPeriodData);
                for (PvUspTsPeriodData p : pvUspTsPeriodDataList) {
                    ShareController.addMapValue(map, p.getPower(), DateUtil.format(p.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                }
            }
        }
        List<TjDataFormat> tjDataFormatList = new ArrayList<>();
        for (Date date : dateList) {
            String stringDateTime = DateUtil.format(date, "yyyy-MM-dd HH:mm");
            TjDataFormat tjDataFormat = new TjDataFormat();
            tjDataFormat.setDataTime(stringDateTime);
            List<Double> entry = map.get(stringDateTime);
            if (entry != null) {
                if (entry.size() > 0) {
                    tjDataFormat.setData(entry.get(0));
                }
            }
            tjDataFormatList.add(tjDataFormat);
        }
        json.put("list", tjDataFormatList);
        return AjaxResult.success(json);
    }

    @ApiOperation("超短期功率预测-期次")
    @GetMapping("/getPeriodCdqglycData")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationNumber", value = "场站编号", required = true),
            @ApiImplicitParam(name = "projectNo", value = "期次编号", required = true),
            @ApiImplicitParam(name = "itemVal", value = "场站类型(0风电场 4光伏电站)", required = true),
            @ApiImplicitParam(name = "timeScale", value = "时间尺度", required = true),
            @ApiImplicitParam(name = "beginDataTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endDataTime", value = "结束时间", required = true),
    })
    public AjaxResult getPeriodCdqglycData(@RequestParam(value = "stationNumber") String stationNumber,
                                           @RequestParam(value = "projectNo") String projectNo,
                                           @RequestParam(value = "itemVal") int itemVal,
                                           @RequestParam(value = "timeScale") int timeScale,
                                           @RequestParam(value = "beginDataTime") String beginDataTime,
                                           @RequestParam(value = "endDataTime") String endDataTime) {
        JSONObject json = new JSONObject();
        //获取所有时间
        List<Date> dateList = DateTimeUtil.getDateList15(DateUtil.parse(beginDataTime), DateUtil.parse(endDataTime));
        LinkedMultiValueMap<String, Double> map = new LinkedMultiValueMap<String, Double>();
        Map<String, Object> params = new HashMap<>();
        params.put("beginDataTime", beginDataTime);
        params.put("endDataTime", endDataTime);
        if (itemVal == 0) {//风电场
            ProjectUspTsPeriodData projectUspTsPeriodData = new ProjectUspTsPeriodData();
            projectUspTsPeriodData.setProjectNo(Convert.toLong(projectNo));
            projectUspTsPeriodData.setModelNo((long) 7041);
            projectUspTsPeriodData.setTimeScale(Convert.toLong(timeScale));
            projectUspTsPeriodData.setParams(params);
            List<ProjectUspTsPeriodData> projectUspTsPeriodDataList = projectUspTsPeriodDataService.selectProjectUspTsPeriodDataList(projectUspTsPeriodData);
            if (projectUspTsPeriodDataList.size() > 0) {
                for (ProjectUspTsPeriodData p : projectUspTsPeriodDataList) {
                    ShareController.addMapValue(map, p.getModPower(), DateUtil.format(p.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                }
            }
        } else if (itemVal == 4) {//光伏电站
            //暂无 后补
        }
        List<TjDataFormat> tjDataFormatList = new ArrayList<>();
        for (Date date : dateList) {
            String stringDateTime = DateUtil.format(date, "yyyy-MM-dd HH:mm");
            TjDataFormat tjDataFormat = new TjDataFormat();
            tjDataFormat.setDataTime(stringDateTime);
            List<Double> entry = map.get(stringDateTime);
            if (entry != null) {
                if (entry.size() > 0) {
                    tjDataFormat.setData(entry.get(0));
                }
            }
            tjDataFormatList.add(tjDataFormat);
        }
        json.put("list", tjDataFormatList);
        return AjaxResult.success(json);
    }

    @ApiOperation("短期功率预测-场站")
    @GetMapping("/getTerminalDqglycData")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationNumber", value = "场站编号", required = true),
            @ApiImplicitParam(name = "itemVal", value = "场站类型(0风电场 4光伏电站)", required = true),
            @ApiImplicitParam(name = "beginDataTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endDataTime", value = "结束时间", required = true),
    })
    public AjaxResult getTerminalDqglycData(@RequestParam(value = "stationNumber") String stationNumber,
                                            @RequestParam(value = "itemVal") int itemVal,
                                            @RequestParam(value = "beginDataTime") String beginDataTime,
                                            @RequestParam(value = "endDataTime") String endDataTime) {
        JSONObject json = new JSONObject();
        //获取所有时间
        List<Date> dateList = DateTimeUtil.getDateList15(DateUtil.parse(beginDataTime), DateUtil.parse(endDataTime));
        LinkedMultiValueMap<String, Double> map = new LinkedMultiValueMap<String, Double>();
        Map<String, Object> params = new HashMap<>();
        params.put("beginDataTime", beginDataTime);
        params.put("endDataTime", endDataTime);
        if (itemVal == 0) {//风电场
            WfFileConfig wfFileConfig = wfFileConfigService.selectWfFileConfigById(Convert.toLong(stationNumber));
            if (ObjectUtil.isNotNull(wfFileConfig)) {
                NoscaleWfDaPfPeriodData noscaleWfDaPfPeriodData = new NoscaleWfDaPfPeriodData();
                noscaleWfDaPfPeriodData.setWindplantNo(Convert.toLong(stationNumber));
                noscaleWfDaPfPeriodData.setModelNo(wfFileConfig.getWpfmodelNo());
                noscaleWfDaPfPeriodData.setParams(params);
                List<NoscaleWfDaPfPeriodData> noscaleWfDaPfPeriodDataList = noscaleWfDaPfPeriodDataService.selectNoscaleWfDaPfPeriodDataList(noscaleWfDaPfPeriodData);
                if (noscaleWfDaPfPeriodDataList.size() > 0) {
                    for (NoscaleWfDaPfPeriodData n : noscaleWfDaPfPeriodDataList) {
                        ShareController.addMapValue(map, n.getValue(), DateUtil.format(n.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                    }
                }
            }
        } else if (itemVal == 4) {//光伏电站
            WfFileConfig wfFileConfig = wfFileConfigService.selectWfFileConfigById(Convert.toLong(stationNumber));
            if (ObjectUtil.isNotNull(wfFileConfig)) {
                PvDaPfPeriodData pvDaPfPeriodData = new PvDaPfPeriodData();
                pvDaPfPeriodData.setPvNo(Convert.toLong(stationNumber));
                pvDaPfPeriodData.setModelNo(wfFileConfig.getWpfmodelNo());
                pvDaPfPeriodData.setParams(params);
                List<PvDaPfPeriodData> pvDaPfPeriodDataList = pvDaPfPeriodDataService.selectPvDaPfPeriodDataList(pvDaPfPeriodData);
                for (PvDaPfPeriodData p : pvDaPfPeriodDataList) {
                    ShareController.addMapValue(map, p.getPower(), DateUtil.format(p.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                }
            }
        }
        List<TjDataFormat> tjDataFormatList = new ArrayList<>();
        for (Date date : dateList) {
            String stringDateTime = DateUtil.format(date, "yyyy-MM-dd HH:mm");
            TjDataFormat tjDataFormat = new TjDataFormat();
            tjDataFormat.setDataTime(stringDateTime);
            List<Double> entry = map.get(stringDateTime);
            if (entry != null) {
                if (entry.size() > 0) {
                    tjDataFormat.setData(entry.get(0));
                }
            }
            tjDataFormatList.add(tjDataFormat);
        }
        json.put("list", tjDataFormatList);
        return AjaxResult.success(json);
    }

    @ApiOperation("短期功率预测-期次")
    @GetMapping("/getPeriodDqglycData")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationNumber", value = "场站编号", required = true),
            @ApiImplicitParam(name = "projectNo", value = "期次编号", required = true),
            @ApiImplicitParam(name = "itemVal", value = "场站类型(0风电场 4光伏电站)", required = true),
            @ApiImplicitParam(name = "beginDataTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endDataTime", value = "结束时间", required = true),
    })
    public AjaxResult getPeriodDqglycData(@RequestParam(value = "stationNumber") String stationNumber,
                                          @RequestParam(value = "projectNo") String projectNo,
                                          @RequestParam(value = "itemVal") int itemVal,
                                          @RequestParam(value = "beginDataTime") String beginDataTime,
                                          @RequestParam(value = "endDataTime") String endDataTime) {
        JSONObject json = new JSONObject();
        //获取所有时间
        List<Date> dateList = DateTimeUtil.getDateList15(DateUtil.parse(beginDataTime), DateUtil.parse(endDataTime));
        LinkedMultiValueMap<String, Double> map = new LinkedMultiValueMap<String, Double>();
        Map<String, Object> params = new HashMap<>();
        params.put("beginDataTime", beginDataTime);
        params.put("endDataTime", endDataTime);
        if (itemVal == 0) {//风电场
            NoscalePrDaPfPeriodData noscalePrDaPfPeriodData = new NoscalePrDaPfPeriodData();
            noscalePrDaPfPeriodData.setWfPrNo(Convert.toLong(projectNo));
            noscalePrDaPfPeriodData.setModelNo((long) 7042);
            noscalePrDaPfPeriodData.setParams(params);
            List<NoscalePrDaPfPeriodData> noscalePrDaPfPeriodDataList = noscalePrDaPfPeriodDataService.selectNoscalePrDaPfPeriodDataList(noscalePrDaPfPeriodData);
            if (noscalePrDaPfPeriodDataList.size() > 0) {
                for (NoscalePrDaPfPeriodData n : noscalePrDaPfPeriodDataList) {
                    ShareController.addMapValue(map, n.getValue(), DateUtil.format(n.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                }
            }
        } else if (itemVal == 4) {//光伏电站
            //暂无 后补
        }
        List<TjDataFormat> tjDataFormatList = new ArrayList<>();
        for (Date date : dateList) {
            String stringDateTime = DateUtil.format(date, "yyyy-MM-dd HH:mm");
            TjDataFormat tjDataFormat = new TjDataFormat();
            tjDataFormat.setDataTime(stringDateTime);
            List<Double> entry = map.get(stringDateTime);
            if (entry != null) {
                if (entry.size() > 0) {
                    tjDataFormat.setData(entry.get(0));
                }
            }
            tjDataFormatList.add(tjDataFormat);
        }
        json.put("list", tjDataFormatList);
        return AjaxResult.success(json);
    }

    @ApiOperation("实时功率-场站")
    @GetMapping("/getTerminalSsglData")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationNumber", value = "场站编号", required = true),
            @ApiImplicitParam(name = "itemVal", value = "场站类型(0风电场 4光伏电站)", required = true),
            @ApiImplicitParam(name = "beginDataTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endDataTime", value = "结束时间", required = true),
    })
    public AjaxResult getTerminalSsglData(@RequestParam(value = "stationNumber") String stationNumber,
                                          @RequestParam(value = "itemVal") int itemVal,
                                          @RequestParam(value = "beginDataTime") String beginDataTime,
                                          @RequestParam(value = "endDataTime") String endDataTime) {
        JSONObject json = new JSONObject();
        //获取所有时间
        List<Date> dateList = DateTimeUtil.getDateList15(DateUtil.parse(beginDataTime), DateUtil.parse(endDataTime));
        LinkedMultiValueMap<String, Double> map = new LinkedMultiValueMap<String, Double>();
        Map<String, Object> params = new HashMap<>();
        params.put("beginDataTime", beginDataTime);
        params.put("endDataTime", endDataTime);
        if (itemVal == 0) {//风电场
            WfFileConfig wfFileConfig = wfFileConfigService.selectWfFileConfigById(Convert.toLong(stationNumber));
            if (ObjectUtil.isNotNull(wfFileConfig)) {
                WfStatPeriodData wfStatPeriodData = new WfStatPeriodData();
                wfStatPeriodData.setWindplantNo(Convert.toLong(stationNumber));
                wfStatPeriodData.setParams(params);
                List<WfStatPeriodData> wfStatPeriodDataList = wfStatPeriodDataService.selectWfStatPeriodDataList(wfStatPeriodData);
                if (wfStatPeriodDataList.size() > 0) {
                    for (WfStatPeriodData w : wfStatPeriodDataList) {
                        ShareController.addMapValue(map, w.getP0(), DateUtil.format(w.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                    }
                }
            }
        } else if (itemVal == 4) {//光伏电站
            WfFileConfig wfFileConfig = wfFileConfigService.selectWfFileConfigById(Convert.toLong(stationNumber));
            if (ObjectUtil.isNotNull(wfFileConfig)) {
                PvPowerStation pvPowerStation = pvPowerStationService.selectPvPowerStationById(Convert.toLong(stationNumber));
                if (ObjectUtil.isNotNull(pvPowerStation)) {
                    WfYcHistoryData1 wfYcHistoryData1 = new WfYcHistoryData1();
                    wfYcHistoryData1.setAnalogNo(pvPowerStation.getApYcNo());
                    wfYcHistoryData1.setParams(params);
                    List<WfYcHistoryData1> wfYcHistoryData1List = wfYcHistoryData1Service.selectWfYcHistoryData1List(wfYcHistoryData1);
                    for (WfYcHistoryData1 w : wfYcHistoryData1List) {
                        ShareController.addMapValue(map, w.getYcVal(), DateUtil.format(w.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                    }
                }
            }
        }
        List<TjDataFormat> tjDataFormatList = new ArrayList<>();
        for (Date date : dateList) {
            String stringDateTime = DateUtil.format(date, "yyyy-MM-dd HH:mm");
            TjDataFormat tjDataFormat = new TjDataFormat();
            tjDataFormat.setDataTime(stringDateTime);
            List<Double> entry = map.get(stringDateTime);
            if (entry != null) {
                if (entry.size() > 0) {
                    tjDataFormat.setData(entry.get(0));
                }
            }
            tjDataFormatList.add(tjDataFormat);
        }
        json.put("list", tjDataFormatList);
        return AjaxResult.success(json);
    }

    @ApiOperation("实时功率-期次")
    @GetMapping("/getPeriodSsglData")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationNumber", value = "场站编号", required = true),
            @ApiImplicitParam(name = "projectNo", value = "期次编号", required = true),
            @ApiImplicitParam(name = "itemVal", value = "场站类型(0风电场 4光伏电站)", required = true),
            @ApiImplicitParam(name = "beginDataTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endDataTime", value = "结束时间", required = true),
    })
    public AjaxResult getPeriodSsglData(@RequestParam(value = "stationNumber") String stationNumber,
                                        @RequestParam(value = "projectNo") String projectNo,
                                        @RequestParam(value = "itemVal") int itemVal,
                                        @RequestParam(value = "beginDataTime") String beginDataTime,
                                        @RequestParam(value = "endDataTime") String endDataTime) {
        JSONObject json = new JSONObject();
        //获取所有时间
        List<Date> dateList = DateTimeUtil.getDateList15(DateUtil.parse(beginDataTime), DateUtil.parse(endDataTime));
        LinkedMultiValueMap<String, Double> map = new LinkedMultiValueMap<String, Double>();
        Map<String, Object> params = new HashMap<>();
        params.put("beginDataTime", beginDataTime);
        params.put("endDataTime", endDataTime);
        if (itemVal == 0) {//风电场
            Windplantproject windplantproject = windplantprojectService.selectWindplantprojectByWpNoProjectNo(Convert.toLong(stationNumber), Convert.toLong(projectNo));
            if (ObjectUtil.isNotNull(windplantproject)) {
                WfYcHistoryData1 wfYcHistoryData1 = new WfYcHistoryData1();
                wfYcHistoryData1.setAnalogNo(windplantproject.getAnalogNo());
                wfYcHistoryData1.setParams(params);
                List<WfYcHistoryData1> wfYcHistoryData1List = wfYcHistoryData1Service.selectWfYcHistoryData1List(wfYcHistoryData1);
                for (WfYcHistoryData1 w : wfYcHistoryData1List) {
                    ShareController.addMapValue(map, w.getYcVal(), DateUtil.format(w.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                }
            }
        } else if (itemVal == 4) {//光伏电站
            //暂无 后补
        }
        List<TjDataFormat> tjDataFormatList = new ArrayList<>();
        for (Date date : dateList) {
            String stringDateTime = DateUtil.format(date, "yyyy-MM-dd HH:mm");
            TjDataFormat tjDataFormat = new TjDataFormat();
            tjDataFormat.setDataTime(stringDateTime);
            List<Double> entry = map.get(stringDateTime);
            if (entry != null) {
                if (entry.size() > 0) {
                    tjDataFormat.setData(entry.get(0));
                }
            }
            tjDataFormatList.add(tjDataFormat);
        }
        json.put("list", tjDataFormatList);
        return AjaxResult.success(json);
    }

    @ApiOperation("可用功率-场站")
    @GetMapping("/getTerminalKyglData")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationNumber", value = "场站编号", required = true),
            @ApiImplicitParam(name = "itemVal", value = "场站类型(0风电场 4光伏电站)", required = true),
            @ApiImplicitParam(name = "beginDataTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endDataTime", value = "结束时间", required = true),
    })
    public AjaxResult getTerminalKyglData(@RequestParam(value = "stationNumber") String stationNumber,
                                          @RequestParam(value = "itemVal") int itemVal,
                                          @RequestParam(value = "beginDataTime") String beginDataTime,
                                          @RequestParam(value = "endDataTime") String endDataTime) {
        JSONObject json = new JSONObject();
        //获取所有时间
        List<Date> dateList = DateTimeUtil.getDateList15(DateUtil.parse(beginDataTime), DateUtil.parse(endDataTime));
        LinkedMultiValueMap<String, Double> map = new LinkedMultiValueMap<String, Double>();
        Map<String, Object> params = new HashMap<>();
        params.put("beginDataTime", beginDataTime);
        params.put("endDataTime", endDataTime);
        if (itemVal == 0) {//风电场
            WfFileConfig wfFileConfig = wfFileConfigService.selectWfFileConfigById(Convert.toLong(stationNumber));
            if (ObjectUtil.isNotNull(wfFileConfig)) {
                WfTheorypowerData wfTheorypowerData = new WfTheorypowerData();
                wfTheorypowerData.setWindplantNo(Convert.toLong(stationNumber));
                wfTheorypowerData.setParams(params);
                List<WfTheorypowerData> wfTheorypowerDataList = wfTheorypowerDataService.selectWfTheorypowerDataList(wfTheorypowerData);
                if (wfTheorypowerDataList.size() > 0) {
                    for (WfTheorypowerData w : wfTheorypowerDataList) {
                        ShareController.addMapValue(map, w.getAvailablepower(), DateUtil.format(w.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                    }
                }
            }
        } else if (itemVal == 4) {//光伏电站
            WfFileConfig wfFileConfig = wfFileConfigService.selectWfFileConfigById(Convert.toLong(stationNumber));
            if (ObjectUtil.isNotNull(wfFileConfig)) {
                PvPowerStation pvPowerStation = pvPowerStationService.selectPvPowerStationById(Convert.toLong(stationNumber));
                if (ObjectUtil.isNotNull(pvPowerStation)) {
                    WfTheorypowerData wfTheorypowerData = new WfTheorypowerData();
                    wfTheorypowerData.setWindplantNo(pvPowerStation.getPvStationNo());
                    wfTheorypowerData.setParams(params);
                    List<WfTheorypowerData> wfTheorypowerDataList = wfTheorypowerDataService.selectWfTheorypowerDataList(wfTheorypowerData);
                    if (wfTheorypowerDataList.size() > 0) {
                        for (WfTheorypowerData w : wfTheorypowerDataList) {
                            ShareController.addMapValue(map, w.getAvailablepower(), DateUtil.format(w.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                        }
                    }
                }
            }
        }
        List<TjDataFormat> tjDataFormatList = new ArrayList<>();
        for (Date date : dateList) {
            String stringDateTime = DateUtil.format(date, "yyyy-MM-dd HH:mm");
            TjDataFormat tjDataFormat = new TjDataFormat();
            tjDataFormat.setDataTime(stringDateTime);
            List<Double> entry = map.get(stringDateTime);
            if (entry != null) {
                if (entry.size() > 0) {
                    tjDataFormat.setData(entry.get(0));
                }
            }
            tjDataFormatList.add(tjDataFormat);
        }
        json.put("list", tjDataFormatList);
        return AjaxResult.success(json);
    }

    @ApiOperation("可用功率-期次")
    @GetMapping("/getPeriodKyglData")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationNumber", value = "场站编号", required = true),
            @ApiImplicitParam(name = "projectNo", value = "期次编号", required = true),
            @ApiImplicitParam(name = "itemVal", value = "场站类型(0风电场 4光伏电站)", required = true),
            @ApiImplicitParam(name = "beginDataTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endDataTime", value = "结束时间", required = true),
    })
    public AjaxResult getPeriodKyglData(@RequestParam(value = "stationNumber") String stationNumber,
                                        @RequestParam(value = "projectNo") String projectNo,
                                        @RequestParam(value = "itemVal") int itemVal,
                                        @RequestParam(value = "beginDataTime") String beginDataTime,
                                        @RequestParam(value = "endDataTime") String endDataTime) {
        JSONObject json = new JSONObject();
        //获取所有时间
        List<Date> dateList = DateTimeUtil.getDateList15(DateUtil.parse(beginDataTime), DateUtil.parse(endDataTime));
        LinkedMultiValueMap<String, Double> map = new LinkedMultiValueMap<String, Double>();
        Map<String, Object> params = new HashMap<>();
        params.put("beginDataTime", beginDataTime);
        params.put("endDataTime", endDataTime);
        if (itemVal == 0) {//风电场
            PrTheorypowerData prTheorypowerData = new PrTheorypowerData();
            prTheorypowerData.setWindplantNo(Convert.toLong(stationNumber));
            prTheorypowerData.setProjectNo(Convert.toLong(projectNo));
            prTheorypowerData.setParams(params);
            List<PrTheorypowerData> prTheorypowerDataList = prTheorypowerDataService.selectPrTheorypowerDataList(prTheorypowerData);
            if (prTheorypowerDataList.size() > 0) {
                for (PrTheorypowerData p : prTheorypowerDataList) {
                    ShareController.addMapValue(map, p.getAvailablepower(), DateUtil.format(p.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                }
            }
        } else if (itemVal == 4) {//光伏电站
            //暂无 后补
        }
        List<TjDataFormat> tjDataFormatList = new ArrayList<>();
        for (Date date : dateList) {
            String stringDateTime = DateUtil.format(date, "yyyy-MM-dd HH:mm");
            TjDataFormat tjDataFormat = new TjDataFormat();
            tjDataFormat.setDataTime(stringDateTime);
            List<Double> entry = map.get(stringDateTime);
            if (entry != null) {
                if (entry.size() > 0) {
                    tjDataFormat.setData(entry.get(0));
                }
            }
            tjDataFormatList.add(tjDataFormat);
        }
        json.put("list", tjDataFormatList);
        return AjaxResult.success(json);
    }

    @ApiOperation("理论功率-场站")
    @GetMapping("/getTerminalLlglData")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationNumber", value = "场站编号", required = true),
            @ApiImplicitParam(name = "itemVal", value = "场站类型(0风电场 4光伏电站)", required = true),
            @ApiImplicitParam(name = "beginDataTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endDataTime", value = "结束时间", required = true),
    })
    public AjaxResult getTerminalLlglData(@RequestParam(value = "stationNumber") String stationNumber,
                                          @RequestParam(value = "itemVal") int itemVal,
                                          @RequestParam(value = "beginDataTime") String beginDataTime,
                                          @RequestParam(value = "endDataTime") String endDataTime) {
        JSONObject json = new JSONObject();
        //获取所有时间
        List<Date> dateList = DateTimeUtil.getDateList15(DateUtil.parse(beginDataTime), DateUtil.parse(endDataTime));
        LinkedMultiValueMap<String, Double> map = new LinkedMultiValueMap<String, Double>();
        Map<String, Object> params = new HashMap<>();
        params.put("beginDataTime", beginDataTime);
        params.put("endDataTime", endDataTime);
        if (itemVal == 0) {//风电场
            WfFileConfig wfFileConfig = wfFileConfigService.selectWfFileConfigById(Convert.toLong(stationNumber));
            if (ObjectUtil.isNotNull(wfFileConfig)) {
                WfTheorypowerData wfTheorypowerData = new WfTheorypowerData();
                wfTheorypowerData.setWindplantNo(Convert.toLong(stationNumber));
                wfTheorypowerData.setParams(params);
                List<WfTheorypowerData> wfTheorypowerDataList = wfTheorypowerDataService.selectWfTheorypowerDataList(wfTheorypowerData);
                if (wfTheorypowerDataList.size() > 0) {
                    for (WfTheorypowerData w : wfTheorypowerDataList) {
                        ShareController.addMapValue(map, w.getTheorypower(), DateUtil.format(w.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                    }
                }
            }
        } else if (itemVal == 4) {//光伏电站
            WfFileConfig wfFileConfig = wfFileConfigService.selectWfFileConfigById(Convert.toLong(stationNumber));
            if (ObjectUtil.isNotNull(wfFileConfig)) {
                PvPowerStation pvPowerStation = pvPowerStationService.selectPvPowerStationById(Convert.toLong(stationNumber));
                if (ObjectUtil.isNotNull(pvPowerStation)) {
                    WfTheorypowerData wfTheorypowerData = new WfTheorypowerData();
                    wfTheorypowerData.setWindplantNo(pvPowerStation.getPvStationNo());
                    wfTheorypowerData.setParams(params);
                    List<WfTheorypowerData> wfTheorypowerDataList = wfTheorypowerDataService.selectWfTheorypowerDataList(wfTheorypowerData);
                    if (wfTheorypowerDataList.size() > 0) {
                        for (WfTheorypowerData w : wfTheorypowerDataList) {
                            ShareController.addMapValue(map, w.getTheorypower(), DateUtil.format(w.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                        }
                    }
                }
            }
        }
        List<TjDataFormat> tjDataFormatList = new ArrayList<>();
        for (Date date : dateList) {
            String stringDateTime = DateUtil.format(date, "yyyy-MM-dd HH:mm");
            TjDataFormat tjDataFormat = new TjDataFormat();
            tjDataFormat.setDataTime(stringDateTime);
            List<Double> entry = map.get(stringDateTime);
            if (entry != null) {
                if (entry.size() > 0) {
                    tjDataFormat.setData(entry.get(0));
                }
            }
            tjDataFormatList.add(tjDataFormat);
        }
        json.put("list", tjDataFormatList);
        return AjaxResult.success(json);
    }

    @ApiOperation("理论功率-期次")
    @GetMapping("/getPeriodLlglData")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationNumber", value = "场站编号", required = true),
            @ApiImplicitParam(name = "projectNo", value = "期次编号", required = true),
            @ApiImplicitParam(name = "itemVal", value = "场站类型(0风电场 4光伏电站)", required = true),
            @ApiImplicitParam(name = "beginDataTime", value = "开始时间", required = true),
            @ApiImplicitParam(name = "endDataTime", value = "结束时间", required = true),
    })
    public AjaxResult getPeriodLlglData(@RequestParam(value = "stationNumber") String stationNumber,
                                        @RequestParam(value = "projectNo") String projectNo,
                                        @RequestParam(value = "itemVal") int itemVal,
                                        @RequestParam(value = "beginDataTime") String beginDataTime,
                                        @RequestParam(value = "endDataTime") String endDataTime) {
        JSONObject json = new JSONObject();
        //获取所有时间
        List<Date> dateList = DateTimeUtil.getDateList15(DateUtil.parse(beginDataTime), DateUtil.parse(endDataTime));
        LinkedMultiValueMap<String, Double> map = new LinkedMultiValueMap<String, Double>();
        Map<String, Object> params = new HashMap<>();
        params.put("beginDataTime", beginDataTime);
        params.put("endDataTime", endDataTime);
        if (itemVal == 0) {//风电场
            PrTheorypowerData prTheorypowerData = new PrTheorypowerData();
            prTheorypowerData.setWindplantNo(Convert.toLong(stationNumber));
            prTheorypowerData.setProjectNo(Convert.toLong(projectNo));
            prTheorypowerData.setParams(params);
            List<PrTheorypowerData> prTheorypowerDataList = prTheorypowerDataService.selectPrTheorypowerDataList(prTheorypowerData);
            if (prTheorypowerDataList.size() > 0) {
                for (PrTheorypowerData p : prTheorypowerDataList) {
                    ShareController.addMapValue(map, p.getTheorypower(), DateUtil.format(p.getDataTime(), "yyyy-MM-dd HH:mm"), 0, 1);
                }
            }
        } else if (itemVal == 4) {//光伏电站
            //暂无 后补
        }
        List<TjDataFormat> tjDataFormatList = new ArrayList<>();
        for (Date date : dateList) {
            String stringDateTime = DateUtil.format(date, "yyyy-MM-dd HH:mm");
            TjDataFormat tjDataFormat = new TjDataFormat();
            tjDataFormat.setDataTime(stringDateTime);
            List<Double> entry = map.get(stringDateTime);
            if (entry != null) {
                if (entry.size() > 0) {
                    tjDataFormat.setData(entry.get(0));
                }
            }
            tjDataFormatList.add(tjDataFormat);
        }
        json.put("list", tjDataFormatList);
        return AjaxResult.success(json);
    }
}