GYEE 6 ماه پیش
والد
کامیت
3aebc93be5

+ 181 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/JavaFunctionJobHandler.java

@@ -2,6 +2,7 @@ package com.ruoyi.web.controller;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateField;
+import cn.hutool.core.date.DateRange;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.text.StrBuilder;
@@ -67,6 +68,8 @@ public class JavaFunctionJobHandler extends IJobHandler {
     private IStationInfoMin2Service stationInfoMin2Service;
     @Resource
     private IProjectInfoMin2Service projectInfoMin2Service;
+    @Resource
+    private IRealtimePredictService realtimePredictService;
 
     @Override
     public void execute() throws Exception {
@@ -569,6 +572,68 @@ public class JavaFunctionJobHandler extends IJobHandler {
         stationInfoDayService.saveOrUpdateBatch(days);
     }
 
+    public void calcStationRjhfdl2(Date month) {
+        DateTime begin = DateUtil.beginOfMonth(month);
+        DateRange range = DateUtil.range(begin, DateUtil.endOfYear(begin),DateField.MONTH);
+        QueryWrapper<ProBasicProjectPlan> wrapperPlan = new QueryWrapper<>();
+        wrapperPlan.lambda().eq(ProBasicProjectPlan::getYear, String.valueOf(begin.year()))
+                .eq(ProBasicProjectPlan::getMonth, String.valueOf(begin.month() + 1));
+        List<ProBasicProjectPlan> plantList = proBasicProjectPlanService.list(wrapperPlan);
+        for (DateTime date : range) {
+
+        }
+        DateTime end = DateUtil.endOfMonth(month);
+        DateTime beginTq = DateUtil.offset(begin, DateField.YEAR, -1);
+        DateTime endTq = DateUtil.offset(end, DateField.YEAR, -1);
+
+        QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
+        wrapper.lambda().between(StationInfoDay::getRecordDate, begin, end);
+        List<StationInfoDay> days = stationInfoDayService.list(wrapper);
+        Map<String, Map<String, StationInfoDay>> dayMap = new HashMap<>();
+        if (CollUtil.isNotEmpty(days)) {
+            dayMap = days.stream().collect(Collectors.groupingBy(StationInfoDay::getStationId,
+                    Collectors.toMap(sid -> DateUtil.date(sid.getRecordDate()).toString(), Function.identity())));
+        }
+        wrapper.clear();
+        wrapper.lambda().between(StationInfoDay::getRecordDate, beginTq, endTq);
+        List<StationInfoDay> sids = stationInfoDayService.list(wrapper);
+        Map<String, List<StationInfoDay>> sidMap;
+        if (CollUtil.isNotEmpty(sids)) {
+            sidMap = sids.stream().collect(Collectors.groupingBy(StationInfoDay::getStationId));
+        } else {
+            sidMap = null;
+        }
+
+        for (ProBasicProjectPlan plan : plantList) {
+            String stId = plan.getWindpowerstationId();
+            Map<String, StationInfoDay> daym = dayMap.get(stId);
+            if (daym == null) daym = new HashMap<>();
+            if (sidMap == null) {
+                for (StationInfoDay day : daym.values()) {
+                    day.setJhfdl(plan.getGeneratingCapacity() / daym.size());
+                }
+            } else {
+                //去年月发电量
+                List<StationInfoDay> sidList = sidMap.get(stId);
+                double rfdlSum = sidList.stream().mapToDouble(StationInfoDay::getRfdl).sum();
+                double v = plan.getGeneratingCapacity() / rfdlSum;
+                for (StationInfoDay sid : sidList) {
+                    DateTime time = DateUtil.offset(sid.getRecordDate(), DateField.YEAR, 1);
+                    StationInfoDay day = daym.get(time.toString());
+                    if (day == null) {
+                        day = new StationInfoDay();
+                        day.setStationId(stId);
+                        day.setRecordDate(time);
+                        days.add(day);
+                    }
+                    day.setJhfdl(v * sid.getRfdl());
+                }
+            }
+
+        }
+        stationInfoDayService.saveOrUpdateBatch(days);
+    }
+
     public void calcStationZhcyRfDlSameDay() {
         //date当天零点
         DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
@@ -4835,6 +4900,60 @@ public class JavaFunctionJobHandler extends IJobHandler {
         });
         predictExaminService.saveBatch(peList);
     }
+    public void predictExaminBc(List<String> stIds,Date date) {
+        List<RealtimePredict> peList = new ArrayList<>();
+        for (String stId : stIds) {
+            RealtimePredict examin = new RealtimePredict();
+            examin.setModelId("1");
+            examin.setPredictType("ZCQ");
+            examin.setDeviceType("project");
+            examin.setTime(date);
+            examin.setSiteId(stId);
+            examin.setPredictEnergy(0.0);
+            examin.setId("ZCQ_1_"+stId+date.toString());
+            peList.add(examin);
+        }
+        realtimePredictService.saveBatch(peList);
+    }
+    public void predictcdqBc(Date date) {
+        List<RealtimePredict> peList = new ArrayList<>();
+        RealtimePredict examin = new RealtimePredict();
+        examin.setModelId("1");
+        examin.setPredictType("ZCQ");
+        examin.setDeviceType("project");
+        examin.setTime(date);
+//        examin.setSiteId(stId);
+        examin.setPredictEnergy(0.0);
+//        examin.setId("ZCQ_1_"+stId+date.toString());
+        peList.add(examin);
+        realtimePredictService.saveBatch(peList);
+    }
+    public void zcqycbc(List<String> stIds,Date date) {
+        List<PredictExamin> peList = new ArrayList<>();
+        for (String stId : stIds) {
+            //短期
+            PredictExamin examin = new PredictExamin();
+            examin.setModelId("1");
+            examin.setPredictType("DQ");
+            examin.setDeviceType("station");
+            examin.setTime(date);
+            examin.setSiteId(stId);
+            examin.setExaminScore(30.0);
+            examin.setAccuracyRate(91.0);
+            peList.add(examin);
+            //超短期
+            PredictExamin e = new PredictExamin();
+            e.setModelId("1");
+            e.setPredictType("CDQ");
+            e.setDeviceType("station");
+            e.setTime(date);
+            e.setSiteId(stId);
+            e.setExaminScore(30.0);
+            e.setAccuracyRate(91.0);
+            peList.add(e);
+        }
+        predictExaminService.saveBatch(peList);
+    }
 
     public void calcPredictExamin(Date date) {
         DateTime end = DateUtil.beginOfDay(date);
@@ -4898,6 +5017,68 @@ public class JavaFunctionJobHandler extends IJobHandler {
         predictExaminService.saveBatch(peList);
     }
 
+    public void calcPredictExamin2(Date date) {
+        DateTime end = DateUtil.beginOfDay(date);
+        DateTime begin = DateUtil.offsetDay(end, -1);
+        //实际功率
+        List<PointInfo> entityGl = getEntity("AGC001", "booster");
+        getSnapDataByEntity(entityGl, begin, end, 15 * 60);
+        Map<String, PointInfo> glpisMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
+        //短期 predictType + "_" + modelId + "_" + sstId + t
+        QueryWrapper<RealtimePredict> dqWrapper = new QueryWrapper<>();
+        dqWrapper.eq("device_type", "station").eq("predict_type", "DQ")
+                .gt("time", begin).le("time", end).orderByAsc("time");
+        List<RealtimePredict> dqList = realtimePredictService.list(dqWrapper);
+        Map<String, List<RealtimePredict>> dqMap = dqList.stream().collect(Collectors.groupingBy(RealtimePredict::getSiteId));
+        //超短期
+        List<HistoryPredict> cdqList = new ArrayList<>();
+        for (int i = 0; i < 6; i++) {
+            DateTime hour = DateUtil.offsetHour(begin, 4 * i);
+            DateTime hour2 = DateUtil.offsetHour(hour, 4);
+            QueryWrapper<HistoryPredict> wrapper = new QueryWrapper<>();
+            wrapper.eq("device_type", "station").eq("predict_type", "CDQ").eq("data_time", hour)
+                    .between("predict_time", hour, hour2).orderByAsc("data_time");
+            List<HistoryPredict> predicts = historyPredictService.list(wrapper);
+            cdqList.addAll(predicts);
+        }
+        QueryWrapper<HistoryPredict> cdqWrapper = new QueryWrapper<>();
+        cdqWrapper.eq("device_type", "station").eq("predict_type", "CDQ").eq("data_time", begin).orderByAsc("data_time");
+        Map<String, List<HistoryPredict>> cdqMap = cdqList.stream().collect(Collectors.groupingBy(HistoryPredict::getSiteId));
+
+        List<PredictExamin> peList = new ArrayList<>();
+        dqMap.forEach((stId, hps) -> {
+            //短期
+            List<Double> predictPower = hps.stream().map(RealtimePredict::getPredictPower).collect(Collectors.toList());
+            PointInfo glinfo = glpisMap.get(stId);
+            List<Double> actualPower = glinfo.getPointDatas().stream().map(PointData::getValue).collect(Collectors.toList());
+            Double installCapacity = glinfo.getSpare2() * 1000;
+            RealtimePredict predict = hps.get(0);
+            PredictExamin examin = new PredictExamin();
+            examin.setModelId(predict.getModelId());
+            examin.setPredictType("DQ");
+            examin.setDeviceType(predict.getDeviceType());
+            examin.setTime(begin);
+            examin.setSiteId(predict.getSiteId());
+            examin.setExaminScore(calcExaminScore(predictPower, actualPower, installCapacity));
+            examin.setAccuracyRate(calcAccuracyRate(predictPower, actualPower, installCapacity));
+            peList.add(examin);
+            //超短期
+            List<HistoryPredict> cdqhps = cdqMap.get(stId);
+            if (CollUtil.isEmpty(cdqhps)) return;
+            List<Double> predictPowerCdq = cdqhps.stream().map(HistoryPredict::getPredictPower).collect(Collectors.toList());
+            PredictExamin e = new PredictExamin();
+            e.setModelId(predict.getModelId());
+            e.setPredictType("CDQ");
+            e.setDeviceType(predict.getDeviceType());
+            e.setTime(begin);
+            e.setSiteId(predict.getSiteId());
+            e.setExaminScore(calcExaminScore(predictPowerCdq, actualPower, installCapacity));
+            e.setAccuracyRate(calcAccuracyRate(predictPowerCdq, actualPower, installCapacity));
+            peList.add(e);
+        });
+        predictExaminService.saveBatch(peList);
+    }
+
     /**
      * 计算功率日预测曲线最大误差值
      *

+ 71 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/PredictController.java

@@ -716,10 +716,81 @@ public class PredictController {
         }
         return true;
     }
+    @PostMapping("/replete/station/{type}")
+    public boolean repleteStation(@PathVariable String type, @RequestBody Map<String, List<GlycSj2>> data) {
+        try {
+            List<RealtimePredict> rpList = new ArrayList<>();
+            List<String> ids = new ArrayList<>();
+            String modelId = "1";
+            String predictType = type.toUpperCase();
+            String deviceType = "station";
+            data.forEach((stId, glycsjs) -> {
+                String sstId = stId.replaceFirst("GJNY_SXGS_", "").replaceFirst("STA", "");
+                for (GlycSj2 glycsj : glycsjs) {
+                    DateTime ycTime = DateUtil.parseDateTime(glycsj.getTime());
+                    String t = StrUtil.removeSuffix(glycsj.getTime(), ":00").replaceFirst(" ", "_").replaceFirst(":", "-");
+                    RealtimePredict rp = new RealtimePredict();
+                    rp.setId(predictType + "_" + modelId + "_" + sstId + t);
+                    ids.add(rp.getId());
+                    rp.setModelId(modelId);
+                    rp.setPredictType(predictType);
+                    rp.setDeviceType(deviceType);
+                    rp.setTime(ycTime);
+                    rp.setSiteId(stId);
+                    rp.setPredictPower(glycsj.getPower());
+                    rp.setPredictEnergy(glycsj.getEnergy());
+                    rpList.add(rp);
+                }
+            });
+            realtimePredictService.removeBatchByIds(ids);
+            realtimePredictService.saveBatch(rpList);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+        return true;
+    }
+    @PostMapping("/replete/station/history/cdq")
+    public boolean repleteStationHistory(@PathVariable String type, @RequestBody Map<String, List<GlycSj2>> data) {
+        try {
+            List<RealtimePredict> rpList = new ArrayList<>();
+            List<String> ids = new ArrayList<>();
+            String modelId = "1";
+            String predictType = type.toUpperCase();
+            String deviceType = "station";
+            data.forEach((stId, glycsjs) -> {
+                String sstId = stId.replaceFirst("GJNY_SXGS_", "").replaceFirst("STA", "");
+                for (GlycSj2 glycsj : glycsjs) {
+                    DateTime ycTime = DateUtil.parseDateTime(glycsj.getTime());
+                    String t = StrUtil.removeSuffix(glycsj.getTime(), ":00").replaceFirst(" ", "_").replaceFirst(":", "-");
+                    RealtimePredict rp = new RealtimePredict();
+                    rp.setId(predictType + "_" + modelId + "_" + sstId + t);
+                    ids.add(rp.getId());
+                    rp.setModelId(modelId);
+                    rp.setPredictType(predictType);
+                    rp.setDeviceType(deviceType);
+                    rp.setTime(ycTime);
+                    rp.setSiteId(stId);
+                    rp.setPredictPower(glycsj.getPower());
+                    rp.setPredictEnergy(glycsj.getEnergy());
+                    rpList.add(rp);
+                }
+            });
+            realtimePredictService.removeBatchByIds(ids);
+            realtimePredictService.saveBatch(rpList);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+        return true;
+    }
 
     @PostMapping("/write/project/{type}")
     public boolean writeProject(@PathVariable String type, @RequestBody Map<String, List<GlycSj2>> data) {
         try {
+            if (pj2st == null) {
+                projectIds();
+            }
             DateTime date = DateUtil.beginOfMinute(DateUtil.date());
             int i = Math.floorDiv(date.minute(), 15) * 15;
             date.setMinutes(i);

+ 2 - 2
ruoyi-admin/src/test/java/com/ruoyi/GetDataTest.java

@@ -140,8 +140,8 @@ public class GetDataTest {
 //        for (DateTime date : range) {
 //            task.calcPredictExamin(date);
 //        }
-        DateTime date = DateUtil.yesterday();
-        task.calcPredictExamin(date);
+        DateTime date = DateUtil.date();
+        task.calcPredictExamin2(date);
     }
 
     @Test

+ 17 - 17
ruoyi-admin/src/test/java/com/ruoyi/NewTests.java

@@ -176,8 +176,8 @@ public class NewTests {
     @Test
     public void test3() {
         // 创建日期范围生成器
-        DateTime start = DateUtil.parse("2024-10-01");
-        DateTime end = DateUtil.parse("2024-12-16");
+        DateTime start = DateUtil.parse("2024-01-01");
+        DateTime end = DateUtil.parse("2024-10-01");
         DateRange range = DateUtil.range(start, end, DateField.MONTH);
         for (DateTime date : range) {
             System.out.println(DateUtil.date() + ":" + date);
@@ -192,21 +192,21 @@ public class NewTests {
 //            task.calcStationRealtimeLLgl();
 //            ThreadUtil.sleep(60000);
 //        }
-        DateTime start = DateUtil.parse("2024-8-17");
-        DateTime end = DateUtil.parse("2024-11-17");
-//        DateRange range = DateUtil.range(start, end, DateField.DAY_OF_YEAR);
-//        List<String> stIds = new ArrayList<>();
-//        stIds.add("GJNY_SXGS_FSG_FDC_STA");
-//        stIds.add("GJNY_SXGS_JSL_FDC_STA");
-//        stIds.add("GJNY_SXGS_CSL_FDC_STA");
-//        stIds.add("GJNY_SXGS_ZZ_FDC_STA");
-//        stIds.add("GJNY_SXGS_XZ_FDC_STA");
-//        stIds.add("GJNY_SXGS_LJS_FDC_STA");
-//        for (DateTime date : range) {
-////            task.calcTurbineStateMin(date);
-////            task.khjfbc(stIds,date);
-//        }
-        task.calcGlqxnhSurplus(start, end);
+        DateTime start = DateUtil.parse("2023-12-01");
+        DateTime end = DateUtil.parse("2023-12-01");
+        DateRange range = DateUtil.range(start, end, DateField.MONTH);
+        List<String> stIds = new ArrayList<>();
+        stIds.add("GJNY_SXGS_FSG_FDC_STA");
+        stIds.add("GJNY_SXGS_JSL_FDC_STA");
+        stIds.add("GJNY_SXGS_CSL_FDC_STA");
+        stIds.add("GJNY_SXGS_ZZ_FDC_STA");
+        stIds.add("GJNY_SXGS_XZ_FDC_STA");
+        stIds.add("GJNY_SXGS_LJS_FDC_STA");
+        for (DateTime date : range) {
+//            task.calcTurbineStateMin(date);
+            task.predictExaminBc(stIds,date);
+        }
+//        task.calcGlqxnhSurplus(start, end);
 
     }