Przeglądaj źródła

重写超短期SYJY的生成及保存

xusl 9 miesięcy temu
rodzic
commit
b1ec21cf33

+ 67 - 32
ipp-idp/src/main/java/com/jiayue/ipp/idp/api/CallForecastPowerUltraShortTermApi.java

@@ -3,7 +3,7 @@ package com.jiayue.ipp.idp.api;
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpResponse;
 import cn.hutool.json.JSONUtil;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.jiayue.ipp.common.data.entity.ForecastPowerShortTerm;
 import com.jiayue.ipp.common.data.entity.ForecastPowerUltraShortTerm;
 import com.jiayue.ipp.common.data.entity.ForecastPowerUltraShortTermHis;
@@ -16,7 +16,6 @@ import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.time.DateUtils;
-import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
@@ -24,7 +23,6 @@ import org.springframework.transaction.annotation.Transactional;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.time.Instant;
-import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.util.*;
@@ -220,10 +218,10 @@ public class CallForecastPowerUltraShortTermApi {
                 Long endTime = DateUtils.addMinutes(new Date(startTime), forecastMinutes).getTime();
 
                 // 查询该时间段内的短期预测功率
-                List<ForecastPowerShortTerm> forecastPowerShortTermList = this.forecastPowerShortTermService.findByStationCodeAndStartTimeAndEndTime(stationCode, new Date(startTime), new Date(endTime));
+                List<ForecastPowerShortTerm> forecastPowerShortTermList = this.forecastPowerShortTermService.findByStationCodeAndStartTimeAndEndTimeAndForecastManufactor(stationCode, new Date(startTime), new Date(endTime),"SYJY");
 
-                Map<Date, List<ForecastPowerShortTerm>> forecastPowerShortTermsMap =
-                        forecastPowerShortTermList.stream().collect(Collectors.groupingBy(ForecastPowerShortTerm::getForecastTime));
+//                Map<Date, List<ForecastPowerShortTerm>> forecastPowerShortTermsMap =
+//                        forecastPowerShortTermList.stream().collect(Collectors.groupingBy(ForecastPowerShortTerm::getForecastTime));
 
 //            List<ForecastPowerShortTerm> addForecastPowerShortTermList = new ArrayList<>();
 //            // 判断短期数据是否缺点
@@ -255,7 +253,8 @@ public class CallForecastPowerUltraShortTermApi {
 //                } else if (ElectricFieldTypeEnum.E2.compareTo(electricField.getElectricFieldTypeEnum()) == 0) {
                 // 风力电场
                 this.executeForecastForWind(forecastPowerShortTermList, e.getCapacity(), e.getStationCode());
-//                } else {
+//                }
+//                else {
 //                    log.error("场站类型非法!");
 //                }
 
@@ -278,7 +277,7 @@ public class CallForecastPowerUltraShortTermApi {
         List<ForecastPowerUltraShortTerm> forecastPowerUltraShortTermList = new ArrayList<>();
         ForecastPowerUltraShortTerm forecastPowerUltraShortTerm;
         //获取系统参数cdqjsfs,超短期计算方式,0为默认乘系数的方式,1为根据可用功率计算的方式
-        String cdqjsfs = sysParameterService.getSysParameterAndStationCode("cdqjsfs", "1", stationCode);
+        String cdqjsfs = sysParameterService.getSysParameterAndStationCode("cdqjsfs", "0", stationCode);
         log.info("参数cdqjsfs值为:" + cdqjsfs + ",超短期计算方式,0为默认乘系数的方式,1为根据可用功率计算的方式。");
         BigDecimal stPower, ustPower, ustPowers;
         // 查询当前时间点标记时间前10分钟的可用功率
@@ -295,6 +294,7 @@ public class CallForecastPowerUltraShortTermApi {
         } catch (Exception e) {
             log.error("获取当前时刻错误", e);
         }
+
         if (filterList.size() > 0) {
             // 获取当前时刻对应的短期
             List<ForecastPowerShortTerm> currentForecastPowerShortTermList;
@@ -378,35 +378,70 @@ public class CallForecastPowerUltraShortTermApi {
             }
         }
 
-        if (forecastPowerUltraShortTermList.size() > 0) {
-            // 获取数据开始时间和结束时间
-            Date oldStarTime = forecastPowerUltraShortTermList.get(0).getForecastTime();
-            Date oldEndTime = forecastPowerUltraShortTermList.get(forecastPowerShortTermList.size() - 1).getForecastTime();
-
+        int ago = 1;
+        List<ForecastPowerUltraShortTermHis> forecastPowerUltraShortTermHisList = new ArrayList<>();
 
-            // 保存超短期预测结果
-            this.forecastPowerUltraShortTermService.remove(Wrappers.lambdaQuery(ForecastPowerUltraShortTerm.class).between(ForecastPowerUltraShortTerm::getForecastTime, oldStarTime, oldEndTime).eq(ForecastPowerUltraShortTerm::getStationCode, stationCode));
-
-        }
-        List<ForecastPowerUltraShortTermHis> forecastPowerUltraShortTermHiss = new ArrayList<>();
-        int i = 1;
-        for (ForecastPowerUltraShortTerm f : forecastPowerUltraShortTermList) {
+        for (ForecastPowerUltraShortTerm forecastPowerUltraShortTerm1 : forecastPowerUltraShortTermList) {
+            // 构造ForecastPowerUltraShortTermHis对象
             ForecastPowerUltraShortTermHis forecastPowerUltraShortTermHis = new ForecastPowerUltraShortTermHis();
-            forecastPowerUltraShortTermHis.setAbleValue(f.getFpValue());
-            forecastPowerUltraShortTermHis.setCapacity(capacity);
-            forecastPowerUltraShortTermHis.setForecastHowLongAgo(i);
-            forecastPowerUltraShortTermHis.setForecastTime(f.getForecastTime());
-            forecastPowerUltraShortTermHis.setForecastManufactor(f.getForecastManufactor());
-            forecastPowerUltraShortTermHis.setGenDate(f.getGenDate());
-            forecastPowerUltraShortTermHis.setSuCapacity(capacity);
-            forecastPowerUltraShortTermHis.setTheoryValue(f.getFpValue());
+            forecastPowerUltraShortTermHis.setGenDate(new Date(monentTime));
             forecastPowerUltraShortTermHis.setStationCode(stationCode);
-            forecastPowerUltraShortTermHiss.add(forecastPowerUltraShortTermHis);
-            i++;
+            forecastPowerUltraShortTermHis.setAbleValue(forecastPowerUltraShortTerm1.getFpValue());
+            forecastPowerUltraShortTermHis.setForecastTime(forecastPowerUltraShortTerm1.getForecastTime());
+            forecastPowerUltraShortTermHis.setForecastHowLongAgo(ago);
+            forecastPowerUltraShortTermHis.setForecastManufactor("SYJY");
+            forecastPowerUltraShortTermHisList.add(forecastPowerUltraShortTermHis);
+            ago++;
         }
 
-        this.forecastPowerUltraShortTermHisService.saveBatch(forecastPowerUltraShortTermHiss);
-        this.forecastPowerUltraShortTermService.saveBatch(forecastPowerUltraShortTermList);
+        // 删除之前的ForecastPowerUltraShortTerm记录
+        LambdaQueryWrapper<ForecastPowerUltraShortTerm> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+        lambdaQueryWrapper.eq(ForecastPowerUltraShortTerm::getStationCode, stationCode);
+        lambdaQueryWrapper.eq(ForecastPowerUltraShortTerm::getForecastManufactor, "SYJY");
+        lambdaQueryWrapper.between(ForecastPowerUltraShortTerm::getForecastTime, forecastPowerUltraShortTermList.get(0).getForecastTime(), forecastPowerUltraShortTermList.get(forecastPowerUltraShortTermList.size() - 1).getForecastTime());
+        forecastPowerUltraShortTermService.remove(lambdaQueryWrapper);
+        // 批量保存新的ForecastPowerUltraShortTerm记录
+        forecastPowerUltraShortTermService.saveBatch(forecastPowerUltraShortTermList);
+
+        // 删除当天的ForecastPowerUltraShortTermHis记录
+        LambdaQueryWrapper<ForecastPowerUltraShortTermHis> forecastPowerUltraShortTermHisLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        forecastPowerUltraShortTermHisLambdaQueryWrapper.eq(ForecastPowerUltraShortTermHis::getGenDate, new Date(monentTime));
+        forecastPowerUltraShortTermHisLambdaQueryWrapper.eq(ForecastPowerUltraShortTermHis::getStationCode, stationCode);
+        forecastPowerUltraShortTermHisLambdaQueryWrapper.eq(ForecastPowerUltraShortTermHis::getForecastManufactor, "SYJY");
+        forecastPowerUltraShortTermHisService.remove(forecastPowerUltraShortTermHisLambdaQueryWrapper);
+        // 批量保存新的ForecastPowerUltraShortTermHis记录
+        forecastPowerUltraShortTermHisService.saveBatch(forecastPowerUltraShortTermHisList);
+
+
+//        if (forecastPowerUltraShortTermList.size() > 0) {
+//            // 获取数据开始时间和结束时间
+//            Date oldStarTime = forecastPowerUltraShortTermList.get(0).getForecastTime();
+//            Date oldEndTime = forecastPowerUltraShortTermList.get(forecastPowerShortTermList.size() - 1).getForecastTime();
+//
+//
+//            // 保存超短期预测结果
+//            this.forecastPowerUltraShortTermService.remove(Wrappers.lambdaQuery(ForecastPowerUltraShortTerm.class).between(ForecastPowerUltraShortTerm::getForecastTime, oldStarTime, oldEndTime).eq(ForecastPowerUltraShortTerm::getStationCode, stationCode));
+//
+//        }
+//        List<ForecastPowerUltraShortTermHis> forecastPowerUltraShortTermHiss = new ArrayList<>();
+//        int i = 1;
+//        for (ForecastPowerUltraShortTerm f : forecastPowerUltraShortTermList) {
+//            ForecastPowerUltraShortTermHis forecastPowerUltraShortTermHis = new ForecastPowerUltraShortTermHis();
+//            forecastPowerUltraShortTermHis.setAbleValue(f.getFpValue());
+//            forecastPowerUltraShortTermHis.setCapacity(capacity);
+//            forecastPowerUltraShortTermHis.setForecastHowLongAgo(i);
+//            forecastPowerUltraShortTermHis.setForecastTime(f.getForecastTime());
+//            forecastPowerUltraShortTermHis.setForecastManufactor(f.getForecastManufactor());
+//            forecastPowerUltraShortTermHis.setGenDate(f.getGenDate());
+//            forecastPowerUltraShortTermHis.setSuCapacity(capacity);
+//            forecastPowerUltraShortTermHis.setTheoryValue(f.getFpValue());
+//            forecastPowerUltraShortTermHis.setStationCode(stationCode);
+//            forecastPowerUltraShortTermHiss.add(forecastPowerUltraShortTermHis);
+//            i++;
+//        }
+//
+//        this.forecastPowerUltraShortTermHisService.saveBatch(forecastPowerUltraShortTermHiss);
+//        this.forecastPowerUltraShortTermService.saveBatch(forecastPowerUltraShortTermList);
 
     }
 

+ 1 - 1
ipp-idp/src/main/java/com/jiayue/ipp/idp/job/ApiJob.java

@@ -25,7 +25,7 @@ public class ApiJob {
     @Autowired
     private CallPowerStationStatusDataApi callPowerStationStatusDataApi;
 
-//    @Scheduled(cron = "30 0,15,30,45 * * * ? ")
+    @Scheduled(cron = "30 0,15,30,45 * * * ? ")
     public void ultraShortTermApi(){
         callForecastPowerUltraShortTermApi.executeForecast();
     }

+ 2 - 0
ipp-idp/src/main/java/com/jiayue/ipp/idp/service/ForecastPowerShortTermService.java

@@ -23,4 +23,6 @@ public interface ForecastPowerShortTermService extends IService<ForecastPowerSho
      * @return
      */
     List<ForecastPowerShortTerm> findByStationCodeAndStartTimeAndEndTime(String stationCode, Date startTime, Date endTime);
+
+    List<ForecastPowerShortTerm> findByStationCodeAndStartTimeAndEndTimeAndForecastManufactor(String stationCode, Date startTime, Date endTime,String forecastManufactor);
 }

+ 15 - 0
ipp-idp/src/main/java/com/jiayue/ipp/idp/service/impl/ForecastPowerShortTermServiceImpl.java

@@ -33,4 +33,19 @@ public class ForecastPowerShortTermServiceImpl extends ServiceImpl<ForecastPower
 
         return baseMapper.selectList(wrapper);
     }
+    @Override
+    public List<ForecastPowerShortTerm> findByStationCodeAndStartTimeAndEndTimeAndForecastManufactor(String stationCode, Date startTime, Date endTime,String forecastManufactor) {
+        QueryWrapper<ForecastPowerShortTerm> wrapper = new QueryWrapper<>();
+        if (stationCode != null && !stationCode.equals("")) {
+            wrapper.eq("station_code", stationCode);
+        }
+        if (startTime != null && !startTime.equals("") && endTime != null && !endTime.equals("")) {
+            wrapper.between("forecast_time", startTime, endTime);
+        }
+        if (forecastManufactor != null && !forecastManufactor.equals("")) {
+            wrapper.eq("forecast_manufactor", forecastManufactor);
+        }
+        return baseMapper.selectList(wrapper);
+    }
+
 }