package com.ruoyi.predict.api;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
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.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.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.*;
import java.util.stream.Collectors;

/**
 * @author hlf
 * @date 2022/8/22 9:17
 * 文件说明：功率预测
 */
@Api(value = "功率预测Controller", tags = {"功率预测操作接口"})
@Controller
@RequestMapping("/predict/api/ppc")
public class PowerPredictionController extends BaseController {

    @Autowired
    private IWindplantService windplantService;

    @Autowired
    private IPvPowerStationService pvPowerStationService;

    @Autowired
    private IWfFileConfigService wfFileConfigService;

    @Autowired
    private IPfEvaRulsDayDataService pfEvaRulsDayDataService;

    @Autowired
    private IPfEvaRulsMonthDataService pfEvaRulsMonthDataService;

    @Autowired
    private IWfNwpDataService wfNwpDataService;

    @Autowired
    private IWfStatPeriodDataService wfStatPeriodDataService;

    @Autowired
    private IWpuspSvrParaService wpuspSvrParaService;

    @Autowired
    private IWfYcHistoryData1Service wfYcHistoryData1Service;

    @Autowired
    private IWfProjectCwWtgService wfProjectCwWtgService;

    @Autowired
    private IWturService wturService;

    @Autowired
    private IWfTheorypowerDataService wfTheorypowerDataService;

    @ApiOperation("功率统计")
    @GetMapping("/installedCapacity")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationNumber", value = "场站编号", required = true),
            @ApiImplicitParam(name = "itemVal", value = "场站类型", required = true),
    })
    public AjaxResult installedCapacity(@RequestParam(value = "stationNumber") String stationNumber,
                                        @RequestParam(value = "itemVal") int itemVal) {
        JSONObject json = new JSONObject();
        //装机
        double installed = 0;
        //并网
        double gridConnected = 0;
        //实时
        double realTime = 0;
        //可用
        double available = 0;
        //场站名称
        String name = "";
        Map<String, Object> params = new HashMap<>();
        params.put("beginDataTime", DateUtil.formatDateTime(DateUtil.date(DateUtil.beginOfDay(DateUtil.date()).getTime() + 900000)));
        params.put("endDataTime", DateUtil.formatDateTime(DateUtil.date(DateUtil.endOfDay(DateUtil.date()).getTime() + 1000)));
        if (itemVal == 0) {//风电场
            Windplant windplant = windplantService.selectWindplantById(Convert.toLong(stationNumber));
            //装机
            installed = windplant.getInstallPower();
            //并网
            List<WfProjectCwWtg> wfProjectCwWtgList = wfProjectCwWtgService.selectWfProjectCwWtgByWindplantNo(windplant.getWindplantNo());
            for (WfProjectCwWtg wfProjectCwWtg : wfProjectCwWtgList) {
                if (wfProjectCwWtg.getMag() == 1) {//运行
                    Wtur wtur = wturService.selectWturById(wfProjectCwWtg.getWtgNo());
                    if (ObjectUtil.isNotNull(wtur)) {
                        gridConnected += wtur.getRatedPower();
                    }
                }
            }
            //实时
            WfStatPeriodData wfStatPeriodData = new WfStatPeriodData();
            wfStatPeriodData.setWindplantNo(windplant.getWindplantNo());
            wfStatPeriodData.setParams(params);
            List<WfStatPeriodData> wfStatPeriodDataList = wfStatPeriodDataService.selectWfStatPeriodDataList(wfStatPeriodData);
            if (wfStatPeriodDataList.size() > 0) {
                realTime += wfStatPeriodDataList.get(wfStatPeriodDataList.size() - 1).getP0();
            }
            //可用
            WfTheorypowerData wfTheorypowerData = new WfTheorypowerData();
            wfTheorypowerData.setWindplantNo(windplant.getWindplantNo());
            wfTheorypowerData.setParams(params);
            List<WfTheorypowerData> wfTheorypowerDataList = wfTheorypowerDataService.selectWfTheorypowerDataList(wfTheorypowerData);
            if (wfTheorypowerDataList.size() > 0) {
                available += wfTheorypowerDataList.get(wfTheorypowerDataList.size() - 1).getAvailablepower();
            }
            name = windplant.getName();
        } else if (itemVal == 4) {//光伏场站
            PvPowerStation pvPowerStation = pvPowerStationService.selectPvPowerStationById(Convert.toLong(stationNumber));
            //装机
            installed = pvPowerStation.getRatingPower();
            //实时
            WfYcHistoryData1 wfYcHistoryData1 = new WfYcHistoryData1();
            wfYcHistoryData1.setAnalogNo(pvPowerStation.getApYcNo());
            wfYcHistoryData1.setParams(params);
            List<WfYcHistoryData1> wfYcHistoryData1List = wfYcHistoryData1Service.selectWfYcHistoryData1List(wfYcHistoryData1);
            if (wfYcHistoryData1List.size() > 0) {
                realTime += wfYcHistoryData1List.get(wfYcHistoryData1List.size() - 1).getYcVal();
            }
            //可用
            WfTheorypowerData wfTheorypowerData = new WfTheorypowerData();
            wfTheorypowerData.setWindplantNo(pvPowerStation.getPvStationNo());
            wfTheorypowerData.setParams(params);
            List<WfTheorypowerData> wfTheorypowerDataList = wfTheorypowerDataService.selectWfTheorypowerDataList(wfTheorypowerData);
            if (wfTheorypowerDataList.size() > 0) {
                available += wfTheorypowerDataList.get(wfTheorypowerDataList.size() - 1).getAvailablepower();
            }
            name = pvPowerStation.getName();
        }
        List<DataFormat> dataFormatList = new ArrayList<>();

        Double[] dataZj = new Double[1];
        dataZj[0] = installed;
        DataFormat dataFormatZj = new DataFormat();
        dataFormatZj.setName("装机");
        dataFormatZj.setData(dataZj);
        dataFormatList.add(dataFormatZj);

        Double[] dataBw = new Double[1];
        dataBw[0] = gridConnected / 1000;
        DataFormat dataFormatBw = new DataFormat();
        dataFormatBw.setName("并网");
        dataFormatBw.setData(dataBw);
        dataFormatList.add(dataFormatBw);

        Double[] dataSs = new Double[1];
        dataSs[0] = realTime;
        DataFormat dataFormatSs = new DataFormat();
        dataFormatSs.setName("实时");
        dataFormatSs.setData(dataSs);
        dataFormatList.add(dataFormatSs);

        Double[] dataKy = new Double[1];
        dataKy[0] = available;
        DataFormat dataFormatKy = new DataFormat();
        dataFormatKy.setName("可用");
        dataFormatKy.setData(dataKy);
        dataFormatList.add(dataFormatKy);

        json.put("dataFormatList", dataFormatList);
        json.put("name", new String[]{name});
        return AjaxResult.success(json);
    }

    @ApiOperation("预测考核分数")
    @GetMapping("/predictedAssessmentScores")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationNumber", value = "场站编号", required = true),
    })
    public AjaxResult predictedAssessmentScores(@RequestParam(value = "stationNumber") String stationNumber) {
        JSONObject json = new JSONObject();
        List<DataFormat> dataFormatList = new ArrayList<>();
        WfFileConfig wfFileConfig = wfFileConfigService.selectWfFileConfigById(Convert.toLong(stationNumber));
        if (ObjectUtil.isNotNull(wfFileConfig)) {
            /*年统计开始*/
            //当年的开始时间
            Date beginOfYearN1 = DateUtil.beginOfYear(DateUtil.date());
            //当年的上月结束时间
            Date endOfYearN1 = DateUtil.lastMonth();
            Map<String, Object> paramsN1 = new HashMap<>();
            paramsN1.put("beginDataTime", DateUtil.formatDateTime(beginOfYearN1));
            paramsN1.put("endDataTime", DateUtil.formatDateTime(endOfYearN1));
            //当月的开始时间
            Date beginOfYearN2 = DateUtil.beginOfMonth(DateUtil.date());
            //昨日的结束时间
            Date endOfYearN2 = DateUtil.endOfDay(DateUtil.yesterday());
            Map<String, Object> paramsN2 = new HashMap<>();
            paramsN2.put("beginDataTime", DateUtil.formatDateTime(beginOfYearN2));
            paramsN2.put("endDataTime", DateUtil.formatDateTime(endOfYearN2));
            double accuracyRateDlDqN = 0;
            double accuracyRateDlCdqN = 0;
            //短期type=-1 超短期type=7
            long typeN;
            long modelNoN;
            for (int i = 0; i < 2; i++) {
                if (i == 0) {//短期
                    typeN = -1;
                    modelNoN = wfFileConfig.getWpfmodelNo();
                } else {//超短期
                    typeN = 7;
                    modelNoN = wfFileConfig.getUwpfmodelNo();
                }
                PfEvaRulsMonthData pfEvaRulsMonthData = new PfEvaRulsMonthData();
                pfEvaRulsMonthData.setRtuNo(Convert.toLong(stationNumber));
                pfEvaRulsMonthData.setModelNo(modelNoN);
                pfEvaRulsMonthData.setType(typeN);
                pfEvaRulsMonthData.setParams(paramsN1);
                List<PfEvaRulsMonthData> pfEvaRulsMonthDataList = pfEvaRulsMonthDataService.selectPfEvaRulsMonthDataList(pfEvaRulsMonthData);
                if (pfEvaRulsMonthDataList.size() > 0) {
                    if (i == 0) {
                        accuracyRateDlDqN = pfEvaRulsMonthDataList.stream().mapToDouble(PfEvaRulsMonthData::getAccuracyRateDl).sum();
                    } else {
                        accuracyRateDlCdqN = pfEvaRulsMonthDataList.stream().mapToDouble(PfEvaRulsMonthData::getAccuracyRateDl).sum();
                    }
                }
                PfEvaRulsDayData pfEvaRulsDayData = new PfEvaRulsDayData();
                pfEvaRulsDayData.setRtuNo(Convert.toLong(stationNumber));
                pfEvaRulsDayData.setModelNo(wfFileConfig.getWpfmodelNo());
                pfEvaRulsDayData.setType(typeN);
                pfEvaRulsDayData.setParams(paramsN2);
                List<PfEvaRulsDayData> pfEvaRulsDayDataList = pfEvaRulsDayDataService.selectPfEvaRulsDayDataList(pfEvaRulsDayData);
                if (pfEvaRulsDayDataList.size() > 0) {
                    if (i == 0) {
                        accuracyRateDlDqN += pfEvaRulsDayDataList.stream().mapToDouble(PfEvaRulsDayData::getAccuracyRateDl).sum();
                    } else {
                        accuracyRateDlCdqN += pfEvaRulsDayDataList.stream().mapToDouble(PfEvaRulsDayData::getAccuracyRateDl).sum();
                    }
                }
            }
            Double[] dataN = new Double[2];
            dataN[0] = accuracyRateDlDqN;
            dataN[1] = accuracyRateDlCdqN;
            DataFormat dataFormatN = new DataFormat();
            dataFormatN.setName("年");
            dataFormatN.setData(dataN);
            dataFormatList.add(dataFormatN);
            /*年统计结束*/
            /*月统计开始*/
            //当月的开始时间
            Date beginOfYearY = DateUtil.beginOfMonth(DateUtil.date());
            //昨日的结束时间
            Date endOfYearY = DateUtil.endOfDay(DateUtil.yesterday());
            Map<String, Object> paramsY = new HashMap<>();
            paramsY.put("beginDataTime", DateUtil.formatDateTime(beginOfYearY));
            paramsY.put("endDataTime", DateUtil.formatDateTime(endOfYearY));
            double accuracyRateDlDqY = 0;
            double accuracyRateDlCdqY = 0;
            //短期type=-1 超短期type=7
            long typeY;
            long modelNoY;
            for (int i = 0; i < 2; i++) {
                if (i == 0) {//短期
                    typeY = -1;
                    modelNoY = wfFileConfig.getWpfmodelNo();
                } else {//超短期
                    typeY = 7;
                    modelNoY = wfFileConfig.getUwpfmodelNo();
                }
                PfEvaRulsDayData pfEvaRulsDayData = new PfEvaRulsDayData();
                pfEvaRulsDayData.setRtuNo(Convert.toLong(stationNumber));
                pfEvaRulsDayData.setModelNo(modelNoY);
                pfEvaRulsDayData.setType(typeY);
                pfEvaRulsDayData.setParams(paramsY);
                List<PfEvaRulsDayData> pfEvaRulsDayDataList = pfEvaRulsDayDataService.selectPfEvaRulsDayDataList(pfEvaRulsDayData);
                if (pfEvaRulsDayDataList.size() > 0) {
                    if (i == 0) {
                        accuracyRateDlDqY = pfEvaRulsDayDataList.stream().mapToDouble(PfEvaRulsDayData::getAccuracyRateDl).sum();
                    } else {
                        accuracyRateDlCdqY = pfEvaRulsDayDataList.stream().mapToDouble(PfEvaRulsDayData::getAccuracyRateDl).sum();
                    }
                }
            }
            Double[] dataY = new Double[2];
            dataY[0] = accuracyRateDlDqY;
            dataY[1] = accuracyRateDlCdqY;
            DataFormat dataFormatY = new DataFormat();
            dataFormatY.setName("月");
            dataFormatY.setData(dataY);
            dataFormatList.add(dataFormatY);
            /*月统计结束*/
            /*日统计开始*/
            double accuracyRateDlDqR = 0;
            double accuracyRateDlCdqR = 0;
            //短期type=-1 超短期type=7
            long typeR;
            long modelNoR;
            for (int i = 0; i < 2; i++) {
                if (i == 0) {//短期
                    typeR = -1;
                    modelNoR = wfFileConfig.getWpfmodelNo();
                } else {//超短期
                    typeR = 7;
                    modelNoR = wfFileConfig.getUwpfmodelNo();
                }
                PfEvaRulsDayData pfEvaRulsDayData = new PfEvaRulsDayData();
                pfEvaRulsDayData.setRtuNo(Convert.toLong(stationNumber));
                pfEvaRulsDayData.setModelNo(modelNoR);
                pfEvaRulsDayData.setType(typeR);
                pfEvaRulsDayData.setDataTime(DateUtil.parse(DateUtil.formatDate(DateUtil.yesterday()), "yyyy-MM-dd"));
                List<PfEvaRulsDayData> pfEvaRulsDayDataList = pfEvaRulsDayDataService.selectPfEvaRulsDayDataList(pfEvaRulsDayData);
                if (pfEvaRulsDayDataList.size() > 0) {
                    if (i == 0) {
                        accuracyRateDlDqR = pfEvaRulsDayDataList.get(0).getAccuracyRateDl();
                    } else {
                        accuracyRateDlCdqR = pfEvaRulsDayDataList.get(0).getAccuracyRateDl();
                    }
                }
            }
            Double[] dataR = new Double[2];
            dataR[0] = accuracyRateDlDqR;
            dataR[1] = accuracyRateDlCdqR;
            DataFormat dataFormatR = new DataFormat();
            dataFormatR.setName("日");
            dataFormatR.setData(dataR);
            dataFormatList.add(dataFormatR);
            /*日统计结束*/
        }
        json.put("dataFormatList", dataFormatList);
        json.put("name", new String[]{"短期考核", "超短期考核"});
        return AjaxResult.success(json);
    }

    @ApiOperation("气象要素")
    @GetMapping("/meteorologicalElements")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationNumber", value = "场站编号", required = true),
            @ApiImplicitParam(name = "dateTime", value = "时间", required = true),
    })
    public AjaxResult meteorologicalElements(@RequestParam(value = "stationNumber") String stationNumber,
                                             @RequestParam(value = "dateTime") String dateTime) {
        JSONObject json = new JSONObject();
        List<DataFormat> dataFormatList = new ArrayList<>();
        String[] names = {"温度", "湿度", "压强"};
        WfFileConfig wfFileConfig = wfFileConfigService.selectWfFileConfigById(Convert.toLong(stationNumber));
        if (ObjectUtil.isNotNull(wfFileConfig)) {
            //预测温度
            double temperature = 0;
            //预测湿度
            double humidity = 0;
            //预测压强
            double airPressure = 0;
            //实际温度
            double avgTemp = 0;
            //实际湿度
            double avgHum = 0;
            //实际压强
            double avgPre = 0;
            /*预测数据开始*/
            Date time = DateUtil.date(DateUtil.parse(dateTime).getTime() - 900000);
            List<WfNwpData> wfNwpDataList = wfNwpDataService.selectWfNwpData(Convert.toLong(stationNumber), wfFileConfig.getUspNwpNo(), DateUtil.parse(dateTime));
            if (wfNwpDataList.size() > 0) {
                wfNwpDataList.sort((o1, o2) -> o2.getFileTime().compareTo(o1.getFileTime()));
                temperature = wfNwpDataList.get(0).getTemperature();
                humidity = wfNwpDataList.get(0).getHumidity();
                airPressure = wfNwpDataList.get(0).getAirPressure();
            } else {
                List<WfNwpData> list = wfNwpDataService.selectWfNwpData(Convert.toLong(stationNumber), wfFileConfig.getUspNwpNo(), time);
                if (list.size() > 0) {
                    list.sort((o1, o2) -> o2.getFileTime().compareTo(o1.getFileTime()));
                    temperature = list.get(0).getTemperature();
                    humidity = list.get(0).getHumidity();
                    airPressure = list.get(0).getAirPressure();
                }
            }
            /*预测数据结束*/
            /*实际数据开始*/
            WfStatPeriodData wfStatPeriodData = wfStatPeriodDataService.selectWfStatPeriodData(Convert.toLong(stationNumber), DateUtil.parse(dateTime));
            if (ObjectUtil.isNotNull(wfStatPeriodData)) {
                avgTemp = wfStatPeriodData.getAvgTemp();
            } else {
                WfStatPeriodData data = wfStatPeriodDataService.selectWfStatPeriodData(Convert.toLong(stationNumber), time);
                if (ObjectUtil.isNotNull(data)) {
                    avgTemp = data.getAvgTemp();
                }
            }
            WpuspSvrPara wpuspSvrPara = wpuspSvrParaService.selectWpuspSvrParaById(Convert.toLong(stationNumber));
            if (ObjectUtil.isNotNull(wpuspSvrPara)) {
                //湿度
                WfYcHistoryData1 w1 = wfYcHistoryData1Service.selectWfYcHistoryData1(wpuspSvrPara.getAvgHumYcNo(), DateUtil.parse(dateTime));
                if (ObjectUtil.isNotNull(w1)) {
                    avgHum = w1.getYcRawVal();
                } else {
                    WfYcHistoryData1 data = wfYcHistoryData1Service.selectWfYcHistoryData1(wpuspSvrPara.getAvgHumYcNo(), time);
                    if (ObjectUtil.isNotNull(data)) {
                        avgHum = data.getYcRawVal();
                    }
                }
                //压强
                WfYcHistoryData1 w2 = wfYcHistoryData1Service.selectWfYcHistoryData1(wpuspSvrPara.getAvgPreYcNo(), DateUtil.parse(dateTime));
                if (ObjectUtil.isNotNull(w2)) {
                    avgPre = w2.getYcRawVal();
                } else {
                    WfYcHistoryData1 data = wfYcHistoryData1Service.selectWfYcHistoryData1(wpuspSvrPara.getAvgPreYcNo(), time);
                    if (ObjectUtil.isNotNull(data)) {
                        avgPre = data.getYcRawVal();
                    }
                }
            }
            /*实际数据结束*/
            for (int i = 0; i < 3; i++) {
                Double[] data = new Double[2];
                if (i == 0) {//温度
                    data[0] = temperature;
                    data[1] = avgTemp;
                } else if (i == 1) {//湿度
                    data[0] = humidity;
                    data[1] = avgHum;
                } else {//压强
                    data[0] = airPressure;
                    data[1] = avgPre;
                }
                DataFormat dataFormat = new DataFormat();
                dataFormat.setName(names[i]);
                dataFormat.setData(data);
                dataFormatList.add(dataFormat);
            }
        }
        json.put("dataFormatList", dataFormatList);
        return AjaxResult.success(json);
    }

    @ApiOperation("风向玫瑰图")
    @GetMapping("/windRosetteChart")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "stationNumber", value = "场站编号", required = true),
    })
    public AjaxResult windRosetteChart(@RequestParam(value = "stationNumber") String stationNumber) {
        JSONObject json = new JSONObject();
        //当日的开始时间
        Date beginOfDay = DateUtil.date(DateUtil.beginOfDay(DateUtil.date()).getTime() + 900000);
        //当日的结束时间
        Date endOfDay = DateUtil.date(DateUtil.endOfDay(DateUtil.date()).getTime() + 1000);
        Map<String, Object> params = new HashMap<>();
        params.put("beginDataTime", DateUtil.formatDateTime(beginOfDay));
        params.put("endDataTime", DateUtil.formatDateTime(endOfDay));
        List<DataFormat> dataFormatList = new ArrayList<>();
        WfFileConfig wfFileConfig = wfFileConfigService.selectWfFileConfigById(Convert.toLong(stationNumber));
        if (ObjectUtil.isNotNull(wfFileConfig)) {
            /*预测数据开始*/
            WfNwpData wfNwpData = new WfNwpData();
            wfNwpData.setWindplantNo(Convert.toLong(stationNumber));
            wfNwpData.setNwpType(wfFileConfig.getUspNwpNo());
            wfNwpData.setParams(params);
            List<WfNwpData> list = new ArrayList<>();
            List<WfNwpData> wfNwpDataList = wfNwpDataService.selectWfNwpDataList(wfNwpData);
            Map<Date, List<WfNwpData>> map = wfNwpDataList.stream().collect(Collectors.groupingBy(WfNwpData::getDataTime));
            TreeMap<Date, List<WfNwpData>> treeMap = new TreeMap<Date, List<WfNwpData>>(map);
            for (Map.Entry<Date, List<WfNwpData>> entry : treeMap.entrySet()) {
                List<WfNwpData> value = entry.getValue();
                if (value.size() > 0) {
                    //排序
                    value.sort((o1, o2) -> o2.getFileTime().compareTo(o1.getFileTime()));
                    list.add(value.get(0));
                }
            }
            //排序 升序
            list.sort(Comparator.comparing(WfNwpData::getWindDir));
            int windDirB1 = 0;
            int windDirE1 = 5;
            Double[] dataYc = new Double[72];
            for (int i = 0; i < 72; i++) {
                List<WfNwpData> wndL = new ArrayList<>();
                for (WfNwpData w : list) {
                    if (w.getWindDir() >= windDirB1 && w.getWindDir() < windDirE1) {
                        wndL.add(w);
                    }
                }
                double windSpeed = 0;
                if (wndL.size() > 0) {
                    //排序 降序
                    wndL.sort(Comparator.comparing(WfNwpData::getWindDir).reversed());
                    windSpeed = wndL.get(0).getWindSpeed();
                }
                dataYc[i] = windSpeed;
                windDirB1 += 5;
                windDirE1 += 5;
            }
            DataFormat dataFormat1 = new DataFormat();
            dataFormat1.setName("预测风速");
            dataFormat1.setData(dataYc);
            dataFormatList.add(dataFormat1);
            /*预测数据结束*/
            /*实际数据开始*/
            WpuspSvrPara wpuspSvrPara = wpuspSvrParaService.selectWpuspSvrParaById(Convert.toLong(stationNumber));
            if (ObjectUtil.isNotNull(wpuspSvrPara)) {
                WfYcHistoryData1 wfYcHistoryData1Fx = new WfYcHistoryData1();
                wfYcHistoryData1Fx.setAnalogNo(wpuspSvrPara.getAvgWdirYcNo());
                wfYcHistoryData1Fx.setParams(params);
                List<WfYcHistoryData1> wfYcHistoryData1ListFx = wfYcHistoryData1Service.selectWfYcHistoryData1List(wfYcHistoryData1Fx);
                WfYcHistoryData1 wfYcHistoryData1Fs = new WfYcHistoryData1();
                wfYcHistoryData1Fs.setAnalogNo(wpuspSvrPara.getWspeedYcNo());
                wfYcHistoryData1Fs.setParams(params);
                List<WfYcHistoryData1> wfYcHistoryData1ListFs = wfYcHistoryData1Service.selectWfYcHistoryData1List(wfYcHistoryData1Fs);
                int windDirB2 = 0;
                int windDirE2 = 5;
                Double[] dataSj = new Double[72];
                for (int i = 0; i < 72; i++) {
                    List<WfYcHistoryData1> wyhdL = new ArrayList<>();
                    for (WfYcHistoryData1 w : wfYcHistoryData1ListFx) {
                        if (w.getYcVal() >= windDirB2 && w.getYcVal() < windDirE2) {
                            WfYcHistoryData1 lastData = wfYcHistoryData1ListFs.stream().filter(item -> DateUtil.formatDateTime(item.getDataTime()).equals(DateUtil.formatDateTime(w.getDataTime()))).findAny().orElse(null);
                            if (ObjectUtil.isNotNull(lastData)) {
                                wyhdL.add(lastData);
                            }
                        }
                    }
                    double ycRawVal = 0;
                    if (wyhdL.size() > 0) {
                        //排序 降序
                        wyhdL.sort(Comparator.comparing(WfYcHistoryData1::getYcVal).reversed());
                        ycRawVal = wyhdL.get(0).getYcRawVal();
                    }
                    dataSj[i] = ycRawVal;
                    windDirB2 += 5;
                    windDirE2 += 5;
                }
                DataFormat dataFormat2 = new DataFormat();
                dataFormat2.setName("实际风速");
                dataFormat2.setData(dataSj);
                dataFormatList.add(dataFormat2);
            }
            /*实际数据结束*/
        }
        json.put("dataFormatList", dataFormatList);
        return AjaxResult.success(json);
    }
}
