package com.cpp.web.service.station.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cpp.web.domain.station.PowerStationStatusData;
import com.cpp.web.mapper.station.PowerStationStatusDataMapper;
import com.cpp.web.service.cloud.ForecastPowerShortTermCloudService;
import com.cpp.web.service.cloud.ForecastPowerUltraShortTermCloudService;
import com.cpp.web.service.cloud.NwpCloudService;
import com.cpp.web.service.station.*;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * cpp_power_station_status_data
 *
 * @author tl
 * @date 2024-09-23 15:28:33
 */
@Service
@RequiredArgsConstructor
public class PowerStationStatusDataServiceImpl extends ServiceImpl<PowerStationStatusDataMapper, PowerStationStatusData> implements PowerStationStatusDataService {
    private final ForecastPowerUltraShortTermStationService forecastPowerUltraShortTermStationService;
    private final ForecastPowerUltraShortTermCloudService forecastPowerUltraShortTermCloudService;
    private final ForecastPowerShortTermCloudService forecastPowerShortTermCloudService;
    private final ElectricFieldService electricFieldService;
//    private final ForecastManufactorService forecastManufactorService;
    private final ForecastPowerShortTermStationService forecastPowerShortTermStationService;

    private final WindTowerStatusDataService windTowerStatusDataService;

//    private final SysParameterService sysParameterService;

    private final WeatherStationStatusDataService weatherStationStatusDataService;

    private final NwpCloudService nwpCloudService;


    @Override
    public List<PowerStationStatusData> findByStationCodeAndStartTimeAndEndTime(String stationCode, Date startTime, Date endTime) {
        QueryWrapper<PowerStationStatusData> wrapper = new QueryWrapper<>();
        if (stationCode != null && !stationCode.equals("")) {
            wrapper.eq("station_code", stationCode);
        }
        if (startTime != null && !startTime.equals("") && endTime != null && !endTime.equals("")) {
            wrapper.between("time", startTime, endTime);
        }
        return baseMapper.selectList(wrapper);
    }

    public List<ArrayList<String>> timeStamp(Date startTime, Date endTime) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String startDate = sdf.format(startTime);
        String endDate = sdf.format(endTime);
        List<ArrayList<String>> dateList = new ArrayList<>();
        while (startDate.compareTo(endDate) <= 0) {
            List<String> subList = new ArrayList<>();
            subList.add(startDate);
            dateList.add(new ArrayList<>(subList));
            startDate = nextSecond(startDate);
        }
        return dateList;
    }

    @Override
    public Map<String, List> getCompositeData(String stationCode, Date startTime, Date endTime, String forecastManufactor, Integer cdqPoint, Integer dqPoint) {
        return null;
    }

    @Override
    public Map<String, List> getCenterData(Date startTime, Date endTime) {
        return null;
    }

    public static String nextSecond(String str) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = sdf.parse(str);
        long time = date.getTime() + 1000L * 60 * 15;
        date = new Date(time);
        return sdf.format(date);
    }

//    public Map<String, List> getCompositeData(String stationCode, Date startTime, Date endTime, String forecastManufactor, Integer cdqPoint, Integer dqPoint) {
//        Long startDateTime = startTime.getTime();
//        Long endDateTime = endTime.getTime();
//        ElectricField electricField = electricFieldService.findByStationCode(stationCode);
//        String station = "";
//        String queryForecastManufactor ="";
//        if (stationCode != null && !stationCode.equals("")) {
//            station = electricField.getName();
//        }
//        List<ForecastManufactor> forecastManufactorList = forecastManufactorService.list();
//
//        // 页面查询预测厂家条件为空，需要查询场站信息下绑定的所有厂家
//        if ("".equals(forecastManufactor)||forecastManufactor==null){
//            queryForecastManufactor = electricField.getForecastManufactor();
//        }
//        else{
//            // 查询页面条件选择的厂家
//            queryForecastManufactor = forecastManufactor;
//        }
//
//        // 封装列表头信息
//        List headList = new ArrayList();
//        Map<String,String> czmcHeadMap = new HashMap<>();
//        czmcHeadMap.put("field", "czmc");
//        czmcHeadMap.put("label", "场站名称");
//        headList.add(czmcHeadMap);
//        Map<String,String> timeHeadMap = new HashMap<>();
//        timeHeadMap.put("field", "time");
//        timeHeadMap.put("label", "时间");
//        headList.add(timeHeadMap);
//        Map<String,String> sjglHeadMap = new HashMap<>();
//        sjglHeadMap.put("field", "sjgl");
//        sjglHeadMap.put("label", "实际功率");
//        headList.add(sjglHeadMap);
//
//
//        String[] fm = queryForecastManufactor.split(",");
//        // 按厂家过滤出数据
//        Map<String,List> tempDqMap = new HashMap<>();
//        Map<String,List> tableDqMap = new HashMap<>();
//       if(dqPoint>0){
//           // 获取短期数据
//           List<ForecastPowerShortTermHis> forecastPowerShortTermHisList = forecastPowerShortTermHisService.findByForecastTimeBetweenAndForecastHowLongAgoAndStationCode(startTime.getTime(), endTime.getTime(),dqPoint,stationCode);
//           for (int i=0;i<fm.length;i++){
//               int finalI = i;
//               List<ForecastPowerShortTermHis> result = forecastPowerShortTermHisList.stream().filter(c -> c.getForecastManufactor().equals(fm[finalI])).collect(Collectors.toList());
//               Map<Long, String> dqMap = new HashMap<>();
//               for (ForecastPowerShortTermHis forecastPowerShortTermHis : result) {
//                   dqMap.put(forecastPowerShortTermHis.getForecastTime().getTime(), forecastPowerShortTermHis.getAbleValue().toString());
//               }
//               List tempdqList = new ArrayList();
//               for (Long tempDateTime = startDateTime; tempDateTime < endDateTime; tempDateTime = tempDateTime + 15 * 60 * 1000) {
//                   if (dqMap.get(tempDateTime) != null) {
//                       tempdqList.add(dqMap.get(tempDateTime).toString());
//                   } else {
//                       tempdqList.add(null);
//                   }
//               }
//               String manufactorName = "";
//               for (ForecastManufactor forecastManufactor1:forecastManufactorList){
//                   if (fm[finalI].equals(forecastManufactor1.getSign())){
//                       manufactorName = forecastManufactor1.getName();
//                       break;
//                   }
//               }
//               if ("".equals(manufactorName)){
//                   manufactorName = fm[finalI];
//               }
//               tempDqMap.put(manufactorName,tempdqList);
//               tableDqMap.put(fm[finalI],tempdqList);
//               Map<String,String> dqHeadMap = new HashMap<>();
//               dqHeadMap.put("field", fm[finalI]+"DQ");
//               dqHeadMap.put("label", manufactorName+"短期");
//               headList.add(dqHeadMap);
//           }
//       }else {
//           // 获取短期数据
//           List<ForecastPowerShortTerm> forecastPowerShortTermList = forecastPowerShortTermService.findByStationCodeAndStartTimeAndEndTime(stationCode,startTime,endTime);
//
//
//           for (int i=0;i<fm.length;i++){
//               int finalI = i;
//               List<ForecastPowerShortTerm> result = forecastPowerShortTermList.stream().filter(c -> c.getForecastManufactor().equals(fm[finalI])).collect(Collectors.toList());
//               Map<Long, String> dqMap = new HashMap<>();
//               for (ForecastPowerShortTerm forecastPowerShortTerm : result) {
//                   dqMap.put(forecastPowerShortTerm.getForecastTime().getTime(), forecastPowerShortTerm.getFpValue().toString());
//               }
//               List tempdqList = new ArrayList();
//               for (Long tempDateTime = startDateTime; tempDateTime < endDateTime; tempDateTime = tempDateTime + 15 * 60 * 1000) {
//                   if (dqMap.get(tempDateTime) != null) {
//                       tempdqList.add(dqMap.get(tempDateTime).toString());
//                   } else {
//                       tempdqList.add(null);
//                   }
//               }
//               String manufactorName = "";
//               for (ForecastManufactor forecastManufactor1:forecastManufactorList){
//                   if (fm[finalI].equals(forecastManufactor1.getSign())){
//                       manufactorName = forecastManufactor1.getName();
//                       break;
//                   }
//               }
//               if ("".equals(manufactorName)){
//                   manufactorName = fm[finalI];
//               }
//               tempDqMap.put(manufactorName,tempdqList);
//               tableDqMap.put(fm[finalI],tempdqList);
//               Map<String,String> dqHeadMap = new HashMap<>();
//               dqHeadMap.put("field", fm[finalI]+"DQ");
//               dqHeadMap.put("label", manufactorName+"短期");
//               headList.add(dqHeadMap);
//           }
//       }
//
//        Map<String,List> tempCdqMap = new HashMap<>();
//        Map<String,List> tableCdqMap = new HashMap<>();
//        if(cdqPoint>0){
//            // 获取超短期数据
//            List<ForecastPowerUltraShortTermHis> forecastPowerUltraShortTermHisList = forecastPowerUltraShortTermHisService.findByForecastTimeBetweenAndForecastHowLongAgoAndStationCode(startTime.getTime(), endTime.getTime(), cdqPoint, stationCode);
//            // 按厂家过滤出数据
//            for (int i=0;i<fm.length;i++){
//                int finalI = i;
//                List<ForecastPowerUltraShortTermHis> result = forecastPowerUltraShortTermHisList.stream().filter(c -> c.getForecastManufactor().equals(fm[finalI])).collect(Collectors.toList());
//                Map<Long, String> cdqMap = new HashMap<>();
//                for (ForecastPowerUltraShortTermHis forecastPowerUltraShortTermHis : result) {
//                    cdqMap.put(forecastPowerUltraShortTermHis.getForecastTime().getTime(), forecastPowerUltraShortTermHis.getAbleValue().toString());
//                }
//                List tempcdqList = new ArrayList();
//                for (Long tempDateTime = startDateTime; tempDateTime < endDateTime; tempDateTime = tempDateTime + 15 * 60 * 1000) {
//                    if (cdqMap.get(tempDateTime) != null) {
//                        tempcdqList.add(cdqMap.get(tempDateTime).toString());
//                    } else {
//                        tempcdqList.add(null);
//                    }
//                }
//                String manufactorName = "";
//                for (ForecastManufactor forecastManufactor1:forecastManufactorList){
//                    if (fm[finalI].equals(forecastManufactor1.getSign())){
//                        manufactorName = forecastManufactor1.getName();
//                        break;
//                    }
//                }
//                if ("".equals(manufactorName)){
//                    manufactorName = fm[finalI];
//                }
//                tempCdqMap.put(manufactorName,tempcdqList);
//                tableCdqMap.put(fm[finalI],tempcdqList);
//                Map<String,String> cdqHeadMap = new HashMap<>();
//                cdqHeadMap.put("field", fm[finalI]+"CDQ");
//                cdqHeadMap.put("label", manufactorName+"超短期");
//                headList.add(cdqHeadMap);
//            }
//        }
//        else{
//            // 获取超短期实时数据
//            List<ForecastPowerUltraShortTerm> forecastPowerUltraShortTermList = forecastPowerUltraShortTermService.findByStationCodeAndStartTimeAndEndTime(stationCode,startTime, endTime);
//            // 按厂家过滤出数据
//            for (int i=0;i<fm.length;i++){
//                int finalI = i;
//                List<ForecastPowerUltraShortTerm> result = forecastPowerUltraShortTermList.stream().filter(c -> c.getForecastManufactor().equals(fm[finalI])).collect(Collectors.toList());
//                Map<Long, String> cdqMap = new HashMap<>();
//                for (ForecastPowerUltraShortTerm forecastPowerUltraShortTerm : result) {
//                    cdqMap.put(forecastPowerUltraShortTerm.getForecastTime().getTime(), forecastPowerUltraShortTerm.getFpValue().toString());
//                }
//                List tempcdqList = new ArrayList();
//                for (Long tempDateTime = startDateTime; tempDateTime < endDateTime; tempDateTime = tempDateTime + 15 * 60 * 1000) {
//                    if (cdqMap.get(tempDateTime) != null) {
//                        tempcdqList.add(cdqMap.get(tempDateTime).toString());
//                    } else {
//                        tempcdqList.add(null);
//                    }
//                }
//                String manufactorName = "";
//                for (ForecastManufactor forecastManufactor1:forecastManufactorList){
//                    if (fm[finalI].equals(forecastManufactor1.getSign())){
//                        manufactorName = forecastManufactor1.getName();
//                        break;
//                    }
//                }
//                if ("".equals(manufactorName)){
//                    manufactorName = fm[finalI];
//                }
//                tempCdqMap.put(manufactorName,tempcdqList);
//                tableCdqMap.put(fm[finalI],tempcdqList);
//                Map<String,String> cdqHeadMap = new HashMap<>();
//                cdqHeadMap.put("field", fm[finalI]+"CDQ");
//                cdqHeadMap.put("label", manufactorName+"超短期");
//                headList.add(cdqHeadMap);
//            }
//        }
//
//        // 获取云端nwp
//        Map<Long, String> nwpMap = new HashMap<>();
//        QueryWrapper<Nwp> nwpWrapper = new QueryWrapper<>();
//        nwpWrapper.between("pre_time", startTime, endTime);
//        nwpWrapper.eq("station_code",stationCode);
//        nwpWrapper.eq("forecast_manufactor","SYJY");
//        List<Nwp> nwpDataList = nwpService.list(nwpWrapper);
//        // 保存环境数据map
//        Map<Long, String> hjsjMap = new HashMap<>();
//        if ("1".equals(electricField.getElectricFieldTypeEnum())){
//            for (Nwp nwp : nwpDataList) {
//                nwpMap.put(nwp.getPreTime().getTime(), nwp.getSwr().toString());
//            }
//            QueryWrapper<WeatherStationStatusData> qxzWrapper = new QueryWrapper<>();
//            qxzWrapper.between("time", startTime, endTime);
//            qxzWrapper.eq("station_code",stationCode);
//            List<WeatherStationStatusData> qxzDataList = weatherStationStatusDataService.list(qxzWrapper);
//            for (WeatherStationStatusData weatherStationStatusData : qxzDataList) {
//                hjsjMap.put(weatherStationStatusData.getTime().getTime(), weatherStationStatusData.getGlobalR().toString());
//            }
//        }
//        else{
//            int nwpHubHeight = Integer.parseInt(sysParameterService.getSysParameterAndStationCode("NWP_HubHeight", "100", stationCode));
//            for (Nwp nwp : nwpDataList) {
//                // 获取nwp轮毂风速
//                if (nwpHubHeight==170){
//                    nwpMap.put(nwp.getPreTime().getTime(), nwp.getWs170().toString());
//                }
//                else if (nwpHubHeight==100){
//                    nwpMap.put(nwp.getPreTime().getTime(), nwp.getWs100().toString());
//                }
//                else if (nwpHubHeight==90){
//                    nwpMap.put(nwp.getPreTime().getTime(), nwp.getWs90().toString());
//                }
//                else if (nwpHubHeight==80){
//                    nwpMap.put(nwp.getPreTime().getTime(), nwp.getWs80().toString());
//                }
//                else if (nwpHubHeight==70){
//                    nwpMap.put(nwp.getPreTime().getTime(), nwp.getWs70().toString());
//                }
//                else if (nwpHubHeight==50){
//                    nwpMap.put(nwp.getPreTime().getTime(), nwp.getWs50().toString());
//                }
//                else if (nwpHubHeight==30){
//                    nwpMap.put(nwp.getPreTime().getTime(), nwp.getWs30().toString());
//                }
//                else if (nwpHubHeight==10){
//                    nwpMap.put(nwp.getPreTime().getTime(), nwp.getWs10().toString());
//                }
//            }
//
//            // 获取测风塔轮毂风速
//            QueryWrapper<WindTowerStatusData> cftWrapper = new QueryWrapper<>();
//            cftWrapper.between("time", startTime, endTime);
//            cftWrapper.eq("station_code",stationCode);
//            List<WindTowerStatusData> cftDataList = windTowerStatusDataService.list(cftWrapper);
//            for (WindTowerStatusData windTowerStatusData : cftDataList) {
//                hjsjMap.put(windTowerStatusData.getTime().getTime(), windTowerStatusData.getWsInstHubHeight().toString());
//            }
//        }
//
//        List<String> timeList = new ArrayList<>();
//        List<String> sjList = new ArrayList();
//        List<String> nwpList = new ArrayList();
//        List<String> hjsjList = new ArrayList();
//        List<Map> dqList = new ArrayList();
//        dqList.add(tempDqMap);
//        List<Map> cdqList = new ArrayList();
//        cdqList.add(tempCdqMap);
//        // 获取实际功率
//        Map<Long, String> sjMap = new HashMap<>();
//        List<PowerStationStatusData> powerStationStatusDataList = findByStationCodeAndStartTimeAndEndTime(stationCode, startTime, endTime);
//        for (PowerStationStatusData powerStationStatusData : powerStationStatusDataList) {
//            sjMap.put(powerStationStatusData.getTime().toInstant(ZoneOffset.of("+8")).toEpochMilli(), powerStationStatusData.getRealValue().toString());
//        }
//        List<Map<String,Object>> tableList = new ArrayList();
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        int i=0;
//        for (Long tempDateTime = startDateTime; tempDateTime < endDateTime; tempDateTime = tempDateTime + 15 * 60 * 1000) {
//            // 封装实际功率list
//            if (sjMap.get(tempDateTime) != null) {
//                if (Double.parseDouble(sjMap.get(tempDateTime))==-99) {
//                    sjList.add(null);
//                }
//                else{
//                    sjList.add(sjMap.get(tempDateTime).toString());
//                }
//            } else {
//                sjList.add(null);
//            }
//
//            // 封装时间轴list
//            String time = format.format(tempDateTime);
//            timeList.add(time);
//            // 封装列表的数据
//            Map<String,Object> map1 = new HashMap<>();
//            map1.put("czmc", station);
//            map1.put("time", DateUtil.format(new Date(tempDateTime), "yyyy-MM-dd HH:mm"));
//            map1.put("sjgl",sjMap.get(tempDateTime) != null?sjMap.get(tempDateTime).toString():null);
//            // 遍历短期数据
//            for (Map.Entry<String, List> entry : tableDqMap.entrySet()) {
//                List tempdqList = entry.getValue();
//                map1.put(entry.getKey()+"DQ",tempdqList.get(i));
//            }
//            // 遍历超短期数据
//            for (Map.Entry<String, List> entry : tableCdqMap.entrySet()) {
//                List tempcdqList = entry.getValue();
//                map1.put(entry.getKey()+"CDQ",tempcdqList.get(i));
//            }
//
//            if ("1".equals(electricField.getElectricFieldTypeEnum())){
//                // 封装nwplist
//                if (nwpMap.get(tempDateTime) != null) {
//                    if (Double.parseDouble(nwpMap.get(tempDateTime))==-99) {
//                        nwpList.add(null);
//                        // 中心侧nwp总辐射
//                        map1.put("ZXCNWPZFS","");
//                    }
//                    else{
//                        nwpList.add(nwpMap.get(tempDateTime).toString());
//                        map1.put("ZXCNWPZFS",nwpMap.get(tempDateTime).toString());
//                    }
//                } else {
//                    nwpList.add(null);
//                    map1.put("ZXCNWPZFS","");
//                }
//                // 封装qxzlist
//                if (hjsjMap.get(tempDateTime) != null) {
//                    if (Double.parseDouble(hjsjMap.get(tempDateTime))==-99) {
//                        hjsjList.add(null);
//                        map1.put("QXZZFS","");
//                    }
//                    else{
//                        hjsjList.add(hjsjMap.get(tempDateTime).toString());
//                        map1.put("QXZZFS",hjsjMap.get(tempDateTime).toString());
//                    }
//                } else {
//                    hjsjList.add(null);
//                    map1.put("QXZZFS","");
//                }
//            }
//            else{
//                // 封装nwplist
//                if (nwpMap.get(tempDateTime) != null) {
//                    if (Double.parseDouble(nwpMap.get(tempDateTime))==-99) {
//                        nwpList.add(null);
//                        map1.put("ZXCNWPWS","");
//                    }
//                    else{
//                        nwpList.add(nwpMap.get(tempDateTime).toString());
//                        map1.put("ZXCNWPWS",nwpMap.get(tempDateTime).toString());
//                    }
//                } else {
//                    nwpList.add(null);
//                    map1.put("ZXCNWPWS","");
//                }
//                // 封装cftlist
//                if (hjsjMap.get(tempDateTime) != null) {
//                    if (Double.parseDouble(hjsjMap.get(tempDateTime))==-99) {
//                        hjsjList.add(null);
//                        map1.put("CFTWS","");
//                    }
//                    else{
//                        hjsjList.add(hjsjMap.get(tempDateTime).toString());
//                        map1.put("CFTWS",hjsjMap.get(tempDateTime).toString());
//                    }
//                } else {
//                    hjsjList.add(null);
//                    map1.put("CFTWS","");
//                }
//            }
//
//            i++;
//            tableList.add(map1);
//        }
//
//        if ("1".equals(electricField.getElectricFieldTypeEnum())){
//            Map<String,String> nwpHeadMap = new HashMap<>();
//            nwpHeadMap.put("field", "ZXCNWPZFS");
//            nwpHeadMap.put("label", "中心侧NWP总辐射");
//            headList.add(nwpHeadMap);
//
//            Map<String,String> cftHeadMap = new HashMap<>();
//            cftHeadMap.put("field", "QXZZFS");
//            cftHeadMap.put("label", "气象站总辐射");
//            headList.add(cftHeadMap);
//        }
//        else{
//            Map<String,String> nwpHeadMap = new HashMap<>();
//            nwpHeadMap.put("field", "ZXCNWPWS");
//            nwpHeadMap.put("label", "中心侧NWP轮毂风速");
//            headList.add(nwpHeadMap);
//
//            Map<String,String> cftHeadMap = new HashMap<>();
//            cftHeadMap.put("field", "CFTWS");
//            cftHeadMap.put("label", "测风塔轮毂风速");
//            headList.add(cftHeadMap);
//        }
//
//        Map<String, List> map = new HashMap<>();
//        map.put("dq", dqList);
//        map.put("cdq", cdqList);
//        map.put("sj", sjList);
//        map.put("nwp", nwpList);
//        map.put("hjsj", hjsjList);
//        map.put("time", timeList);
//        map.put("fromHead", headList);
//        map.put("tableList", tableList);
//
//        return map;
//    }map

    @Override
    public List<PowerStationStatusData> findByTimeBetweenAndStationCode(Date pointStarTime, Date pointEndTime, String stationCode) {
        QueryWrapper<PowerStationStatusData> wrapper = new QueryWrapper<>();

        if (stationCode != null && !stationCode.equals("")) {
            wrapper.eq("station_code", stationCode);
        }
        if (pointStarTime != null && pointEndTime != null) {
            wrapper.between("time", pointStarTime, pointEndTime);
        }
        return baseMapper.selectList(wrapper);
    }


    /**
     * 中心侧预测数据统计，查询短期、超短期实时表厂家是SYJY的，每个点位值累加一起展示
     * @param startTime
     * @param endTime
     * @return
     */
//    public Map<String, List> getCenterData(Date startTime, Date endTime) {
//        Long startDateTime = startTime.getTime();
//        Long endDateTime = endTime.getTime();
//
//        // 封装列表头信息
//        List headList = new ArrayList();
//        Map<String,String> timeHeadMap = new HashMap<>();
//        timeHeadMap.put("field", "time");
//        timeHeadMap.put("label", "时间");
//        headList.add(timeHeadMap);
//        Map<String,String> dqHeadMap = new HashMap<>();
//        dqHeadMap.put("field", "dq");
//        dqHeadMap.put("label", "短期(MW)");
//        headList.add(dqHeadMap);
//        Map<String,String> cdqHeadMap = new HashMap<>();
//        cdqHeadMap.put("field", "cdq");
//        cdqHeadMap.put("label", "超短期(MW)");
//        headList.add(cdqHeadMap);
//
//        // 获取短期数据SYJY
//        QueryWrapper<ForecastPowerShortTermCloud> wrapper = new QueryWrapper<>();
//        wrapper.eq("forecast_manufactor","SYJY");
//        wrapper.between("forecast_time", startTime, endTime);
//        List<ForecastPowerShortTermCloud> forecastPowerShortTermCloudList = forecastPowerShortTermService.list(wrapper);
////        Map<Long, List<ForecastPowerShortTermCloud>> shortGroupMap = forecastPowerShortTermCloudList.stream().collect(Collectors.groupingBy(s->s.getForecastTime().getTime()));
//
//        // 获取超短期数据SYJY
//        QueryWrapper<ForecastPowerUltraShortTermCloud> ultrawrapper = new QueryWrapper<>();
//        ultrawrapper.eq("forecast_manufactor","SYJY");
//        ultrawrapper.between("forecast_time", startTime, endTime);
//        List<ForecastPowerUltraShortTermCloud> forecastPowerUltraShortTermCloudList = forecastPowerUltraShortTermService.list(ultrawrapper);
////        Map<Long, List<ForecastPowerUltraShortTermCloud>> ultraGroupMap = forecastPowerUltraShortTermCloudList.stream().collect(Collectors.groupingBy(s->s.getForecastTime().getTime()));
//
//        List<String> timeList = new ArrayList<>();
//        List<String> dqList = new ArrayList();
//        List<String> cdqList = new ArrayList();
//
//        List<Map<String,Object>> tableList = new ArrayList();
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        int i=0;
//        for (Long tempDateTime = startDateTime; tempDateTime < endDateTime; tempDateTime = tempDateTime + 15 * 60 * 1000) {
//            // 封装时间轴list
//            String time = format.format(tempDateTime);
//            timeList.add(time);
//            // 封装列表的数据
//            Map<String,Object> map1 = new HashMap<>();
//            map1.put("time", DateUtil.format(new Date(tempDateTime), "yyyy-MM-dd HH:mm"));
//            // 短期数据求和
//            BigDecimal dqBigDecimal = new BigDecimal(0);
//            if (shortGroupMap.get(tempDateTime)!=null){
//                List<ForecastPowerShortTermCloud> forecastPowerShortTermCloudList1 = shortGroupMap.get(tempDateTime);
//                for (ForecastPowerShortTermCloud forecastPowerShortTermCloud : forecastPowerShortTermCloudList1){
//                    dqBigDecimal = dqBigDecimal.add(forecastPowerShortTermCloud.getFpValue());
//                }
//                map1.put("dq",dqBigDecimal.toString());
//            }
//            else{
//                map1.put("dq",0);
//            }
//            dqList.add(dqBigDecimal.toString());
//
//            // 超短期数据求和
//            BigDecimal cdqBigDecimal = new BigDecimal(0);
//            if (ultraGroupMap.get(tempDateTime)!=null){
//                List<ForecastPowerUltraShortTermCloud> forecastPowerUltraShortTermCloudList1 = ultraGroupMap.get(tempDateTime);
//                for (ForecastPowerUltraShortTermCloud forecastPowerUltraShortTermCloud : forecastPowerUltraShortTermCloudList1){
//                    cdqBigDecimal = cdqBigDecimal.add(forecastPowerUltraShortTermCloud.getFpValue());
//                }
//                map1.put("cdq",cdqBigDecimal.toString());
//            }
//            else{
//                map1.put("cdq",0);
//            }
//            cdqList.add(cdqBigDecimal.toString());
//
//            tableList.add(map1);
//        }
//
//        Map<String, List> map = new HashMap<>();
//        map.put("dq", dqList);
//        map.put("cdq", cdqList);
//        map.put("time", timeList);
//        map.put("fromHead", headList);
//        map.put("tableList", tableList);
//
//        return map;
//    }
}
