Prechádzať zdrojové kódy

日发电量实时更新

xushili 6 mesiacov pred
rodič
commit
8cf6976aed

+ 89 - 79
ruoyi-admin/src/main/java/com/ruoyi/web/controller/JavaFunctionJobHandler.java

@@ -344,7 +344,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
                 Double v = CalcCache.fitcoef.get(tbId).get(fsList.get(i).getValue());
                 if (v == null) v = 0.0;
                 v = v - glList.get(i).getValue();
-//                double v2 = v > 0 ? v : 0;
+                //                double v2 = v > 0 ? v : 0;
                 double v2 = v;
                 switch ((int) collectZt.get(i).getValue()) {
                     //计划检修损失:
@@ -514,67 +514,69 @@ public class JavaFunctionJobHandler extends IJobHandler {
         stationInfoDayService.saveOrUpdateBatch(byDate);
     }
 
-    public void calcStationRjhfdl(Date month) {
-        DateTime begin = DateUtil.beginOfMonth(month);
-        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;
-        }
-        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 (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());
-                }
+    public void calcStationRjhfdl(Date date) {
+        DateRange months = DateUtil.range(date, DateUtil.endOfYear(date), DateField.MONTH);
+        for (DateTime month : months) {
+            DateTime begin = DateUtil.beginOfMonth(month);
+            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.formatDate(sid.getRecordDate()), 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 {
-                //去年月发电量
-                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);
+                sidMap = null;
+            }
+            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 (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(DateUtil.formatDate(time));
+                        if (day == null) {
+                            day = new StationInfoDay();
+                            day.setStationId(stId);
+                            day.setRecordDate(time);
+                            days.add(day);
+                        }
+                        day.setJhfdl(v * sid.getRfdl());
                     }
-                    day.setJhfdl(v * sid.getRfdl());
                 }
             }
-
+            stationInfoDayService.saveOrUpdateBatch(days);
         }
-        stationInfoDayService.saveOrUpdateBatch(days);
     }
 
     public void calcStationRjhfdl2(Date month) {
         DateTime begin = DateUtil.beginOfMonth(month);
-        DateRange range = DateUtil.range(begin, DateUtil.endOfYear(begin),DateField.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));
@@ -2110,17 +2112,22 @@ public class JavaFunctionJobHandler extends IJobHandler {
         }
     }
 
+
     public void getSectionDataByEntity(List<PointInfo> entitys, URI uri, Date start, Date end) {
         String collect = entitys.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
         Map<String, PointData> section0 = adapter.getHistorySection(uri, collect, start.getTime());
         Map<String, PointData> section1 = adapter.getHistorySection(uri, collect, end.getTime());
         for (PointInfo entity : entitys) {
-            entity.setPointDatas(new ArrayList<>());
-            entity.getPointDatas().add(section0.get(entity.getPointKey()));
-            entity.getPointDatas().add(section1.get(entity.getPointKey()));
+            List<PointData> list = new ArrayList<>();
+            PointData p0 = section0.get(entity.getPointKey());
+            PointData p1 = section1.get(entity.getPointKey());
+            if (p0 != null && p1 != null) {
+                list.add(p0);
+                list.add(p1);
+            }
+            entity.setPointDatas(list);
         }
     }
-
     public void getSectionDataByEntity(List<PointInfo> entitys, URI uri, Date end) {
         String collect = entitys.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
         Map<String, PointData> section1 = adapter.getHistorySection(uri, collect, end.getTime());
@@ -4900,7 +4907,8 @@ public class JavaFunctionJobHandler extends IJobHandler {
         });
         predictExaminService.saveBatch(peList);
     }
-    public void predictExaminBc(List<String> stIds,Date date) {
+
+    public void predictExaminBc(List<String> stIds, Date date) {
         List<RealtimePredict> peList = new ArrayList<>();
         for (String stId : stIds) {
             RealtimePredict examin = new RealtimePredict();
@@ -4910,11 +4918,12 @@ public class JavaFunctionJobHandler extends IJobHandler {
             examin.setTime(date);
             examin.setSiteId(stId);
             examin.setPredictEnergy(0.0);
-            examin.setId("ZCQ_1_"+stId+date.toString());
+            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();
@@ -4922,13 +4931,14 @@ public class JavaFunctionJobHandler extends IJobHandler {
         examin.setPredictType("ZCQ");
         examin.setDeviceType("project");
         examin.setTime(date);
-//        examin.setSiteId(stId);
+        //        examin.setSiteId(stId);
         examin.setPredictEnergy(0.0);
-//        examin.setId("ZCQ_1_"+stId+date.toString());
+        //        examin.setId("ZCQ_1_"+stId+date.toString());
         peList.add(examin);
         realtimePredictService.saveBatch(peList);
     }
-    public void zcqycbc(List<String> stIds,Date date) {
+
+    public void zcqycbc(List<String> stIds, Date date) {
         List<PredictExamin> peList = new ArrayList<>();
         for (String stId : stIds) {
             //短期
@@ -5155,7 +5165,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
         entityHjwd = entityHjwd.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
         getRawDataByEntity(entityHjwd, goldenUri(), begin, end);
         Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
-//        StationInfoMin2 min2 = getStationinfoByMin2(end, stId);
+        //        StationInfoMin2 min2 = getStationinfoByMin2(end, stId);
         StationInfoMin2 min2 = new StationInfoMin2();
         min2.setStationId(stId);
         min2.setRecordDate(end);
@@ -5180,7 +5190,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
             hjwds.add(v);
         }
         min2.setHjwd(hjwds.stream().filter(d -> d != 0.0).mapToDouble(Double::doubleValue).average().orElse(0.0));
-//        stationInfoMin2Service.saveOrUpdate(min2);
+        //        stationInfoMin2Service.saveOrUpdate(min2);
         stationInfoMin2Service.save(min2);
     }
 
@@ -5202,27 +5212,27 @@ public class JavaFunctionJobHandler extends IJobHandler {
             List<PointInfo> infos = sortPointInfo(pis, PointInfo::getTurbineId);
             List<Integer> fjidns = infos.stream().map(pi -> Integer.parseInt(pi.getTurbineId().replaceFirst("GJNY_SXGS_.+_F_WT_", "")
                     .replaceFirst("_EQ", ""))).collect(Collectors.toList());
-//            Map<Double, Long> zttsMap = calcSectionZtts(end,pjId,PointInfo::getProjectId);
-//            Long l = zttsMap.get(2.0);
-//            if (l == null) l = 0L;
+            //            Map<Double, Long> zttsMap = calcSectionZtts(end,pjId,PointInfo::getProjectId);
+            //            Long l = zttsMap.get(2.0);
+            //            if (l == null) l = 0L;
             //日发电量
-//            List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
-//            entity=filterPointInfo(entity,pjId,PointInfo::getProjectId);
-//            getSectionDataByEntity(entity, goldenUri(), begin, end);
-//            double rfdl = entity.stream().mapToDouble(pi -> {
-//                double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
-//                if (v < 0) v = 0;
-//                return v;
-//            }).sum();
-//            if (rfdl >= 32500) rfdl = 32500.0;
+            //            List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
+            //            entity=filterPointInfo(entity,pjId,PointInfo::getProjectId);
+            //            getSectionDataByEntity(entity, goldenUri(), begin, end);
+            //            double rfdl = entity.stream().mapToDouble(pi -> {
+            //                double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
+            //                if (v < 0) v = 0;
+            //                return v;
+            //            }).sum();
+            //            if (rfdl >= 32500) rfdl = 32500.0;
             ProjectInfoMin2 min2 = new ProjectInfoMin2();
             min2.setStationId(stId);
             min2.setProjectId(pjId);
             min2.setRecordDate(end);
-//            min2.setRfdl(rfdl);
+            //            min2.setRfdl(rfdl);
             min2.setRfdl(min.getRfdl());
             min2.setHjwd(min.getHjwd());
-//            min2.setYxts(l);
+            //            min2.setYxts(l);
             min2.setYxts(min.getYxts());
             sm2fs2pm2(fjidns, min2, min);
             min2s.add(min2);
@@ -5243,7 +5253,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
             if (ef.getPointDatas() == null || ef.getPointDatas().isEmpty()) {
                 Map<String, PointData> latest = adapter.getLatest(goldenUri(), ef.getPointKey());
                 PointData data = latest.get(ef.getPointKey());
-                if (data!=null) v = data.getValue();
+                if (data != null) v = data.getValue();
             } else {
                 v = ef.getPointDatas().stream().mapToDouble(p -> p.getValue() > 23 ? 23.0 : p.getValue() < 0 ? 0.0 : p.getValue()).average().orElse(0.0);
             }

+ 23 - 19
ruoyi-admin/src/main/java/com/ruoyi/web/controller/PredictController.java

@@ -751,33 +751,37 @@ public class PredictController {
         return true;
     }
     @PostMapping("/replete/station/history/cdq")
-    public boolean repleteStationHistory(@PathVariable String type, @RequestBody Map<String, List<GlycSj2>> data) {
+    public boolean repleteStationHistory(@RequestBody Map<String, List<GlycSj2>> data) {
         try {
-            List<RealtimePredict> rpList = new ArrayList<>();
-            List<String> ids = new ArrayList<>();
+            List<HistoryPredict> rpList = new ArrayList<>();
+            List<HistoryPredict> scList = new ArrayList<>();
             String modelId = "1";
-            String predictType = type.toUpperCase();
+            String predictType = "CDQ";
             String deviceType = "station";
             data.forEach((stId, glycsjs) -> {
-                String sstId = stId.replaceFirst("GJNY_SXGS_", "").replaceFirst("STA", "");
+                DateTime dataTime = DateUtil.offsetMinute(DateUtil.parseDateTime(glycsjs.get(0).getTime()), -15);
+                QueryWrapper<HistoryPredict> wrapper = new QueryWrapper<>();
+                wrapper.lambda().eq(HistoryPredict::getPredictType, predictType).eq(HistoryPredict::getDeviceType, deviceType)
+                        .eq(HistoryPredict::getSiteId, stId).eq(HistoryPredict::getDataTime, dataTime);
+                List<HistoryPredict> list = historyPredictService.list(wrapper);
+                scList.addAll(list);
                 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);
+                    HistoryPredict hp = new HistoryPredict();
+                    hp.setModelId(modelId);
+                    hp.setPredictType(predictType);
+                    hp.setDeviceType(deviceType);
+                    hp.setDataTime(dataTime);
+                    hp.setPredictTime(ycTime);
+                    hp.setSiteId(stId);
+                    hp.setPredictPower(glycsj.getPower());
+                    hp.setPredictEnergy(glycsj.getEnergy());
+                    rpList.add(hp);
                 }
             });
-            realtimePredictService.removeBatchByIds(ids);
-            realtimePredictService.saveBatch(rpList);
+            List<Integer> scIds = scList.stream().map(HistoryPredict::getId).collect(Collectors.toList());
+            historyPredictService.removeBatchByIds(scIds);
+            historyPredictService.saveBatch(rpList);
         } catch (Exception e) {
             e.printStackTrace();
             return false;

+ 10 - 1
ruoyi-admin/src/test/java/com/ruoyi/NewTests.java

@@ -213,7 +213,16 @@ public class NewTests {
     @Test
     public void test5() {
         DateTime date = DateUtil.date();
-        task.calcTurbineStateMin(date);
+        //task.calcTurbineStateMin(date);
+        task.calcStationRjhfdl(date);
+    }
+
+    public static void main(String[] args) {
+        DateTime date = DateUtil.date();
+        DateRange months = DateUtil.range(date, DateUtil.endOfYear(date), DateField.MONTH);
+        for (DateTime month : months) {
+            System.out.println(month);
+        }
     }
 
     @Test

+ 5 - 0
universal-computing-platform/src/main/java/com/ruoyi/ucp/service/impl/HistoryPredictServiceImpl.java

@@ -48,4 +48,9 @@ public class HistoryPredictServiceImpl extends ServiceImpl<HistoryPredictMapper,
     public List<HistoryPredict> list(Wrapper<HistoryPredict> queryWrapper) {
         return super.list(queryWrapper);
     }
+
+    @Override
+    public boolean removeBatchByIds(Collection<?> list) {
+        return super.removeBatchByIds(list);
+    }
 }