Browse Source

实时状态计算

xushili 5 months ago
parent
commit
5d3a31d5e6
1 changed files with 279 additions and 59 deletions
  1. 279 59
      ruoyi-admin/src/test/java/com/ruoyi/JavaFunctionJobHandler.java

+ 279 - 59
ruoyi-admin/src/test/java/com/ruoyi/JavaFunctionJobHandler.java

@@ -14,7 +14,6 @@ import com.ruoyi.ucp.service.*;
 import com.ruoyi.ucp.util.CalcCache;
 import org.apache.commons.math3.fitting.PolynomialCurveFitter;
 import org.apache.commons.math3.fitting.WeightedObservedPoints;
-import org.junit.Test;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Service;
 
@@ -144,15 +143,15 @@ public class JavaFunctionJobHandler extends IJobHandler {
 
     public Map<String, Double> getTurbinePowerLoss(double rfdl, PointInfo piZt, List<PointData> fsList, List<PointData> glList) {
         String tbId = piZt.getTurbineId();
-//        Map<Double, Long> collect = piZt.getPointDatas().stream().collect(Collectors.groupingBy(PointData::getValue, Collectors.counting()));
+        //        Map<Double, Long> collect = piZt.getPointDatas().stream().collect(Collectors.groupingBy(PointData::getValue, Collectors.counting()));
         double sum1 = glList.stream().mapToDouble(PointData::getValue).sum();
         double xs = rfdl / (sum1 / 240);
-//        double sum2 = fsList.stream().mapToDouble(pd -> {
-//            Double v = CalcCache.fitcoef.get(tbId).get(pd.getValue());
-//            if (v == null) v = 0.0;
-//            return v;
-//        }).sum();
-//        sum2=sum2/240;
+        //        double sum2 = fsList.stream().mapToDouble(pd -> {
+        //            Double v = CalcCache.fitcoef.get(tbId).get(pd.getValue());
+        //            if (v == null) v = 0.0;
+        //            return v;
+        //        }).sum();
+        //        sum2=sum2/240;
 
         List<PointData> collectZt = piZt.getPointDatas();
         double jxss = 0, sdtj = 0, gzss = 0, djss = 0, xnss = 0, fdjcl = 0, xdjcl = 0, xdtj = 0;
@@ -344,7 +343,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
         pi.setUniformCode("Z-ZXYG-JX");
         pi.setLineId("all");
         List<PointInfo> entity = pointService.getByEntity(pi);
-//        entity = entity.stream().filter(e -> e.getStationId().equals("GJNY_SXGS_ZZ_FDC_STA")).collect(Collectors.toList());
+        //        entity = entity.stream().filter(e -> e.getStationId().equals("GJNY_SXGS_ZZ_FDC_STA")).collect(Collectors.toList());
         String keys = pointInfos2Keys(entity);
         Map<String, PointData> latest2 = adapter.getHistorySection(goldenUri(), keys, time2.getTime());
         Map<String, PointData> latest1 = adapter.getHistorySection(goldenUri(), keys, time1.getTime());
@@ -388,7 +387,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
                 .groupBy("station_id");
         List<LineInfoDay> list = lineInfoDayService.list(wrapper);
         List<StationInfoDay> byDate = getStationinfoByDate(time0.toJdkDate());
-//        list = list.stream().filter(b -> b.getStationId().equals("GJNY_SXGS_ZZ_FDC_STA")).collect(Collectors.toList());
+        //        list = list.stream().filter(b -> b.getStationId().equals("GJNY_SXGS_ZZ_FDC_STA")).collect(Collectors.toList());
 
         Map<String, StationInfoDay> collect = new HashMap<>();
         if (!byDate.isEmpty()) {
@@ -705,18 +704,18 @@ public class JavaFunctionJobHandler extends IJobHandler {
             cxInfo.setPointDatas(cxc);
 
             //风机风速、功率->场站风速、功率
-//            List<PointData> firstFs = new ArrayList<>();
-//            List<PointData> firstGl = new ArrayList<>();
+            //            List<PointData> firstFs = new ArrayList<>();
+            //            List<PointData> firstGl = new ArrayList<>();
             List<PointData> firstZsgl = new ArrayList<>();
             double v1, v2, v3;
             for (int i = 0; i < 5760; i++) {
                 int finalI = i;
                 long ts = start.getTime() + i * 15000;
-//                v1 = fsMap.values().stream().mapToDouble(pds -> pds.getPointDatas().get(finalI).getValue()).average().orElse(0.0);
-//                v2 = glMap.values().stream().mapToDouble(pds -> pds.getPointDatas().get(finalI).getValue()).sum();
+                //                v1 = fsMap.values().stream().mapToDouble(pds -> pds.getPointDatas().get(finalI).getValue()).average().orElse(0.0);
+                //                v2 = glMap.values().stream().mapToDouble(pds -> pds.getPointDatas().get(finalI).getValue()).sum();
                 v3 = pdsZsglMap.values().stream().mapToDouble(pds -> pds.get(finalI).getValue()).sum();
-//                firstFs.add(new PointData(ts, v1));
-//                firstGl.add(new PointData(ts, v2));
+                //                firstFs.add(new PointData(ts, v1));
+                //                firstGl.add(new PointData(ts, v2));
                 firstZsgl.add(new PointData(ts, v3));
             }
 
@@ -736,7 +735,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
         Map<String, EquipmentModel> map = equipmentModelService.map();
         Double capacity = map.get(ztInfo.getSpare()).getPowerProduction();
         List<PointData> zts = ztInfo.getPointDatas();
-        for (int i = 0; i < 5760; i++) {
+        for (int i = 0; i < fss.size(); i++) {
             double ssgl = gls.get(i).getValue();
             double ssfs = fss.get(i).getValue();
             double ylzsgd = ylzsgds.get(i).getValue();
@@ -764,7 +763,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
         List<PointData> czxd = zsglSnap.stream().map(s -> new PointData(s.getTs(), 0.0)).collect(Collectors.toList());
         //之前是否限电
         boolean iszqxd = false;
-        for (int i = 0; i < 5760; i++) {
+        for (int i = 0; i < zsglSnap.size(); i++) {
             boolean isxd = false;
             double zsgl = zsglSnap.get(i).getValue();
             double zsgl5 = zsgl5s.get(i).getValue();
@@ -881,7 +880,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
                 } else if (map.get("MX006").getPointDatas().get(i).getValue() == 1.0) {
                     data0.setDoubleValue(6.0);
                 } else {
-//                    System.out.println(wtId + data0.getTs() + ":di无对应状态!");
+                    //                    System.out.println(wtId + data0.getTs() + ":di无对应状态!");
                     data0.setDoubleValue(2.0);
                 }
             }
@@ -995,7 +994,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
         Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(
                 StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
 
-//        Map<String, Map<Double,Double>> fitMap = new HashMap<>();
+        //        Map<String, Map<Double,Double>> fitMap = new HashMap<>();
         for (PointInfo ef : entityFs) {
             String wtId = ef.getTurbineId();
             PointInfo glInfo = glMap.get(wtId);
@@ -1011,13 +1010,13 @@ public class JavaFunctionJobHandler extends IJobHandler {
             if (turbineZt != null) {
                 double capacity = map.get(turbineZt.getSpare()).getPowerProduction();
                 fit = dataProcessAndFit(ef, glInfo, turbineZt, CalcCache.bzgl.get(turbineZt.getSpare()), capacity);
-//                fitMap.put(wtId, fit);
+                //                fitMap.put(wtId, fit);
                 turbineZt.setPointDatas(null);
             }
             if (turbineAizt != null) {
                 double capacity = map.get(turbineAizt.getSpare()).getPowerProduction();
                 fit = dataProcessAndFit(ef, glInfo, turbineAizt, CalcCache.bzgl.get(turbineAizt.getSpare()), capacity);
-//                fitMap.put(wtId, fit);
+                //                fitMap.put(wtId, fit);
                 turbineAizt.setPointDatas(null);
             }
             ef.setPointDatas(null);
@@ -1025,7 +1024,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
             stringRedisTemplate.opsForValue().set("edfs:" + end.getMonth() + ":" + wtId, JSON.toJSONString(fit));
         }
         System.out.println("苹果天涯");
-//        stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
+        //        stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
     }
 
 
@@ -1195,7 +1194,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
             queryWrapper.eq("uniform_code", "AI066");
 
             List<PointInfo> pointInfos = getEntity("AI066", "turbine");
-//        List<PointInfo> pointInfos = pointInfo.selectList(queryWrapper);
+            //        List<PointInfo> pointInfos = pointInfo.selectList(queryWrapper);
 
             //定义切入风速map集合
             ConcurrentHashMap<String, ConcurrentHashMap<String, Double>> mapIn = new ConcurrentHashMap<>();
@@ -1242,15 +1241,15 @@ public class JavaFunctionJobHandler extends IJobHandler {
                     //如果1的值为0,2的值为2,则为切入状态
                     if (value1 == 0 && value2 == 2) {
                         ts1 = pointData2.getTs();
-//                    String stringDate = DateUtil.date(ts1).toString("yyyy-MM-dd HH:mm:ss");
-//                    System.out.println(turbine.getTurbineId() + "切入" + stringDate);
+                        //                    String stringDate = DateUtil.date(ts1).toString("yyyy-MM-dd HH:mm:ss");
+                        //                    System.out.println(turbine.getTurbineId() + "切入" + stringDate);
                         //切入时间前5分钟
                         long ts11 = ts1 - 300000;
                         //根据风速key,从适配器取切入前5分钟的所有风速
                         List<PointData> pointDatas1 = adapter.getHistorySnap(goldenUri(), windSpeedKey, ts11, ts1, 10);
                         //平均所有风速即为平均切入风速
                         double avgCutInWindSpeed = pointDatas1.stream().mapToDouble(PointData::getValue).average().orElse(0);
-//                    System.out.println(turbine.getTurbineId() + "切入风速" + avgCutInWindSpeed);
+                        //                    System.out.println(turbine.getTurbineId() + "切入风速" + avgCutInWindSpeed);
 
                         //存入map集合,外层key为turbineId,内层key为ts1,value为平均切入风速
 
@@ -1262,12 +1261,12 @@ public class JavaFunctionJobHandler extends IJobHandler {
                     if (value1 == 2 && value2 != 2) {
                         ts2 = pointData2.getTs();
                         String stringDate = DateUtil.date(ts2).toString("yyyy-MM-dd HH:mm:ss");
-//                    System.out.println(turbine.getTurbineId() + "切出" + stringDate);
+                        //                    System.out.println(turbine.getTurbineId() + "切出" + stringDate);
                         //切出时间前5分钟
                         long ts22 = ts2 - 300000;
                         List<PointData> pointDatas2 = adapter.getHistorySnap(goldenUri(), windSpeedKey, ts22, ts2, 10);
                         double avgCutOutWindSpeed = pointDatas2.stream().mapToDouble(PointData::getValue).average().orElse(0);
-//                    System.out.println(turbine.getTurbineId() + "切出风速" + avgCutOutWindSpeed);
+                        //                    System.out.println(turbine.getTurbineId() + "切出风速" + avgCutOutWindSpeed);
 
                         //存入map集合,外层key为turbineId,内层key为ts2,value为平均切出风速
 
@@ -1341,21 +1340,21 @@ public class JavaFunctionJobHandler extends IJobHandler {
                     System.out.println(turbineInfoDay);
 
                     interest.add(turbineInfoDay);
-//                turbineInfoDayService.save(turbineInfoDay);
+                    //                turbineInfoDayService.save(turbineInfoDay);
                 } else {
                     one.setXfqrfs(avgCutInWindSpeed);
                     System.out.println(one);
-//                turbineInfoDayService.updateById(one);
+                    //                turbineInfoDayService.updateById(one);
                     update.add(one);
                 }
 
             }
 
             //        //批量插入
-//        turbineInfoDayService.saveBatch(interest);
-//        //批量更新
-//        turbineInfoDayService.updateBatchById(update);
-//        //批量插入或更新
+            //        turbineInfoDayService.saveBatch(interest);
+            //        //批量更新
+            //        turbineInfoDayService.updateBatchById(update);
+            //        //批量插入或更新
             turbineInfoDayService.saveOrUpdateBatch(interest);
             turbineInfoDayService.saveOrUpdateBatch(update);
         }
@@ -1409,7 +1408,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
             Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(
                     StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
 
-//        Map<String, Map<Double,Double>> fitMap = new HashMap<>();
+            //        Map<String, Map<Double,Double>> fitMap = new HashMap<>();
 
             //插入集合
             List<TurbineInfoDay> interest = new ArrayList<>();
@@ -1437,21 +1436,21 @@ public class JavaFunctionJobHandler extends IJobHandler {
                         System.out.println("数据处理拟合");
                         capacity = map.get(turbineZt.getSpare()).getPowerProduction();
                         fit = dataProcessAndFit(ef, glInfo, turbineZt, CalcCache.bzgl.get(turbineZt.getSpare()), capacity);
-//                fitMap.put(wtId, fit);
+                        //                fitMap.put(wtId, fit);
                         turbineZt.setPointDatas(null);
                     }
                     if (turbineAizt != null) {
                         System.out.println("数据处理拟合");
                         capacity = map.get(turbineAizt.getSpare()).getPowerProduction();
                         fit = dataProcessAndFit(ef, glInfo, turbineAizt, CalcCache.bzgl.get(turbineAizt.getSpare()), capacity);
-//                fitMap.put(wtId, fit);
+                        //                fitMap.put(wtId, fit);
                         turbineAizt.setPointDatas(null);
                     }
                     ef.setPointDatas(null);
                     glInfo.setPointDatas(null);
 
                     //存redis
-//            stringRedisTemplate.opsForValue().set("glqxnh:" + end.getMonth() + ":" + wtId, JSON.toJSONString(fit));
+                    //            stringRedisTemplate.opsForValue().set("glqxnh:" + end.getMonth() + ":" + wtId, JSON.toJSONString(fit));
 
                     System.out.println("拟合曲线的大小" + fit.size() + ":" + wtId);
 
@@ -1491,12 +1490,12 @@ public class JavaFunctionJobHandler extends IJobHandler {
                         turbineInfoDay.setRecordDate(start);
                         turbineInfoDay.setEdfs(agValue);
                         System.out.println(turbineInfoDay);
-//                    turbineInfoDayService.save(turbineInfoDay);
+                        //                    turbineInfoDayService.save(turbineInfoDay);
                         interest.add(turbineInfoDay);
                     } else {
                         one.setEdfs(agValue);
                         System.out.println(one);
-//                    turbineInfoDayService.updateById(one);
+                        //                    turbineInfoDayService.updateById(one);
                         update.add(one);
                     }
 
@@ -1509,16 +1508,16 @@ public class JavaFunctionJobHandler extends IJobHandler {
 
 
             //        //批量插入
-//        turbineInfoDayService.saveBatch(interest);
-//        //批量更新
-//        turbineInfoDayService.updateBatchById(update);
-//        //批量插入或更新
+            //        turbineInfoDayService.saveBatch(interest);
+            //        //批量更新
+            //        turbineInfoDayService.updateBatchById(update);
+            //        //批量插入或更新
             turbineInfoDayService.saveOrUpdateBatch(interest);
             turbineInfoDayService.saveOrUpdateBatch(update);
         }
 
 
-//        stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
+        //        stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
     }
 
     //环境温度
@@ -1567,20 +1566,20 @@ public class JavaFunctionJobHandler extends IJobHandler {
                 turbineInfoDay.setHjwd(avgCutInWindSpeed);
                 System.out.println(turbineInfoDay);
                 interest.add(turbineInfoDay);
-//                turbineInfoDayService.save(turbineInfoDay);
+                //                turbineInfoDayService.save(turbineInfoDay);
             } else {
                 one.setHjwd(avgCutInWindSpeed);
                 System.out.println(one);
                 update.add(one);
-//                turbineInfoDayService.updateById(one);
+                //                turbineInfoDayService.updateById(one);
             }
 
         }
-//        //批量插入
-//        turbineInfoDayService.saveBatch(interest);
-//        //批量更新
-//        turbineInfoDayService.updateBatchById(update);
-//        //批量插入或更新
+        //        //批量插入
+        //        turbineInfoDayService.saveBatch(interest);
+        //        //批量更新
+        //        turbineInfoDayService.updateBatchById(update);
+        //        //批量插入或更新
         turbineInfoDayService.saveOrUpdateBatch(interest);
         turbineInfoDayService.saveOrUpdateBatch(update);
 
@@ -1613,9 +1612,9 @@ public class JavaFunctionJobHandler extends IJobHandler {
         List<StationInfoDay> yearDays = stationInfoDayService.list(wrapper);
         Map<String, StationInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
 
-//        QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
-//        wrapperrp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
-//        List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
+        //        QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
+        //        wrapperrp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
+        //        List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
 
         QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
         wrapperrp.eq("record_date", time0)
@@ -1769,8 +1768,8 @@ public class JavaFunctionJobHandler extends IJobHandler {
         List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
         Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
 
-//        QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
-//        wrapperrp.eq("record_date", time0).last("and foreign_key_id = project_id");
+        //        QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
+        //        wrapperrp.eq("record_date", time0).last("and foreign_key_id = project_id");
 
         QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
         wrapperrp.eq("record_date", time0)
@@ -1869,7 +1868,6 @@ public class JavaFunctionJobHandler extends IJobHandler {
         double nzhcydl = 0;
 
 
-
         for (ProEconReportIndicatorPool pool : list) {
             rfdl += pool.getRfdldb();
             swdl += pool.getRswdldb();
@@ -1905,10 +1903,232 @@ public class JavaFunctionJobHandler extends IJobHandler {
         reportIndicatorPoolService.saveOrUpdate(GSZB);
 
 
+    }
+
+
+    public void calcRealtimeTurbineZt() {
+        DateTime date = DateUtil.date();
+
+        List<PointInfo> turbineZt = calcRealtimeTurbineDizt();
+        List<PointInfo> turbineAizt = calcRealtimeTurbineAizt();
+        turbineZt.addAll(turbineAizt);
+        turbineZt = turbineZt.stream().peek(t -> {
+            if (t.getPointDatas().get(0).getTs() + 9 * 60 * 1000 <= date.getTime()) {
+                t.getPointDatas().get(0).setDoubleValue(12.0);
+            }
+        }).collect(Collectors.toList());
+        Map<String, Map<String, PointInfo>> ztMapMap = turbineZt.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
+                Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
+        //AGC
+        List<PointInfo> entityAgc = getEntity("AGC002", "booster");
+        getSnapDataByEntity(entityAgc, DateUtil.offsetMinute(date, -5), date, 15);
+        //出线
+        List<PointInfo> entityCx = getEntity("AGC001", "booster");
+        getSnapDataByEntity(entityCx, DateUtil.offsetMinute(date, -5), date, 15);
+        //叶轮转速给定
+        List<PointInfo> entityYlzsgd = getEntity("AI110", "turbine");
+        getLatestByEntity(entityYlzsgd);
+        //风速
+        List<PointInfo> entityFs = getEntity("AI066", "turbine");
+        getSnapDataByEntity(entityFs, DateUtil.offsetMinute(date, -5), date, 15);
+        //功率
+        List<PointInfo> entityGl = getEntity("AI114", "turbine");
+        //getLatestByEntity(entityFs);
+        getLatestByEntity(entityGl);
+
+        Map<String, PointInfo> collectAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
+        Map<String, PointInfo> collectCx = entityCx.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
+        Map<String, Map<String, List<PointData>>> collectYlzsgd = entityYlzsgd.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
+                Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
+        Map<String, Map<String, PointInfo>> fsMapMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
+                Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
+        Map<String, Map<String, List<PointData>>> glMapMap = entityGl.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
+                Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
+
+        ztMapMap.forEach((stId, ztMap) -> {
+            PointInfo agcInfo = collectAgc.get(stId);
+            PointInfo cxInfo = collectCx.get(stId);
+            Map<String, PointInfo> fsMap = fsMapMap.get(stId);
+
+            Map<String, List<PointData>> pdsZsglMap = new HashMap<>();
+            ztMap.forEach((wtId, zt) -> {
+                List<PointData> peek = fsMap.get(wtId).getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue() > 25 ? 25.0
+                        : pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
+                fsMap.get(wtId).setPointDatas(peek);
+                List<PointData> zsglSnap = fsMap.get(wtId).getPointDatas().stream().map(pd -> {
+                    Double v = CalcCache.fitcoef.get(wtId).get(pd.getValue());
+                    return new PointData(pd.getTs(), v == null ? 0 : v);
+                }).collect(Collectors.toList());
+                pdsZsglMap.put(wtId, zsglSnap);
+            });
+            List<PointData> agcc = agcInfo.getPointDatas().stream().peek(agc -> {
+                agc.setDoubleValue(agc.getValue() * agcInfo.getCoef());
+                agc.setLongValue(0L);
+            }).collect(Collectors.toList());
+            agcInfo.setPointDatas(agcc);
+            List<PointData> cxc = cxInfo.getPointDatas().stream().peek(cx -> {
+                cx.setDoubleValue(cx.getValue() * cxInfo.getCoef());
+                cx.setLongValue(0L);
+            }).collect(Collectors.toList());
+            cxInfo.setPointDatas(cxc);
+
+            //风机风速、功率->场站风速、功率
+            List<PointData> firstZsgl = new ArrayList<>();
+            double v3 = pdsZsglMap.values().stream().mapToDouble(pds -> pds.get(0).getValue()).sum();
+            firstZsgl.add(new PointData(date.getTime(), v3));
 
+            List<PointData> czxd = calcStationXd2(agcInfo, cxInfo.getPointDatas(), firstZsgl);
+            ztMap.forEach((wtId, ztInfo) -> {
+                List<PointData> fss = fsMap.get(wtId).getPointDatas();
+                List<PointData> gls = glMapMap.get(stId).get(wtId);
+                //叶轮转速给定
+                List<PointData> ylzsgds = collectYlzsgd.get(stId).get(wtId);
+                calcRealtimeTurbineXd(ztInfo, gls.get(0), fss.get(fss.size() - 1), ylzsgds.get(0), czxd.get(czxd.size() - 1));
+            });
+        });
+
+        Map<String, String> entityMxzt = getEntityMap("MXZT", "turbine");
+        List<PointData> dataList = turbineZt.stream().map(zt -> {
+            PointData data = zt.getPointDatas().get(0);
+            data.setTagName(entityMxzt.get(zt.getTurbineId()));
+            return data;
+        }).collect(Collectors.toList());
+        adapter.writeHistoryBatch(taosUri(), dataList);
+        ThreadUtil.sleep(1000);
+    }
+    //此处加公式
+
+    public List<PointInfo> getLatest(String uniformCode, String institutionType) {
+        List<PointInfo> entity = getEntity(uniformCode, institutionType);
+        String collect = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
+        Map<String, PointData> latest = adapter.getLatest(goldenUri(), collect);
+        entity.forEach(e -> {
+            e.setPointDatas(Collections.singletonList(latest.get(e.getPointKey())));
+        });
+        return entity;
     }
 
+    public void getLatestByEntity(List<PointInfo> entity) {
+        String collect = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
+        Map<String, PointData> latest = adapter.getLatest(goldenUri(), collect);
+        entity.forEach(e -> {
+            e.setPointDatas(Collections.singletonList(latest.get(e.getPointKey())));
+        });
+    }
+
+    public List<PointInfo> calcRealtimeTurbineDizt() {
+        List<PointInfo> entity = new ArrayList<>();
+        List<PointInfo> result = new ArrayList<>();
+        List<PointInfo> entity0 = getEntity("MX000", "state");
+        List<PointInfo> entity1 = getEntity("MX001", "state");
+        List<PointInfo> entity2 = getEntity("MX002", "state");
+        List<PointInfo> entity4 = getEntity("MX004", "state");
+        List<PointInfo> entity6 = getEntity("MX006", "state");
+        entity.addAll(entity0);
+        entity.addAll(entity1);
+        entity.addAll(entity2);
+        entity.addAll(entity4);
+        entity.addAll(entity6);
+        List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
+        Map<String, PointData> latest = adapter.getLatest(goldenUri(), String.join(",", keys));
 
+        Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy
+                (PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
+        wtUcPis.forEach((wtId, map) -> {
+            PointInfo info2 = map.get("MX002");
+            PointData data2 = latest.get(info2.getPointKey());
+            if (data2.getValue() == 1.0) {
+                data2.setDoubleValue(2.0);
+                data2.setBooleanValue(false);
+                info2.setPointDatas(Collections.singletonList(data2));
+                result.add(info2);
+            } else {
+                PointInfo info0 = map.get("MX000");
+                PointData data0 = latest.get(info0.getPointKey());
+                if (data0.getValue() == 1.0) {
+                    data0.setDoubleValue(0.0);
+                    data0.setBooleanValue(false);
+                    info0.setPointDatas(Collections.singletonList(data0));
+                    result.add(info0);
+                } else {
+                    PointInfo info6 = map.get("MX006");
+                    PointData data6 = latest.get(info6.getPointKey());
+                    if (data6.getValue() == 1.0) {
+                        data6.setDoubleValue(6.0);
+                        data6.setBooleanValue(false);
+                        info6.setPointDatas(Collections.singletonList(data6));
+                        result.add(info6);
+                    } else {
+                        PointInfo info4 = map.get("MX004");
+                        PointData data4 = latest.get(info4.getPointKey());
+                        if (data4.getValue() == 1.0) {
+                            data4.setDoubleValue(4.0);
+                            data4.setBooleanValue(false);
+                            info4.setPointDatas(Collections.singletonList(data4));
+                            result.add(info4);
+                        } else {
+                            PointInfo info1 = map.get("MX001");
+                            PointData data1 = latest.get(info1.getPointKey());
+                            if (data1.getValue() == 1.0) {
+                                data1.setDoubleValue(1.0);
+                                data1.setBooleanValue(false);
+                                info1.setPointDatas(Collections.singletonList(data1));
+                                result.add(info1);
+                            } else {
+                                data1.setDoubleValue(2.0);
+                                System.out.println("wtId: " + wtId + ",状态值无批配: " + data1.getValue());
+                                info1.setPointDatas(Collections.singletonList(data1));
+                                result.add(info1);
+                            }
+                        }
+                    }
+                }
+            }
+        });
+        return result;
+    }
+
+    public List<PointInfo> calcRealtimeTurbineAizt() {
+        List<PointInfo> entityAiZt = getEntity("AI422", "state");
+        List<StateAi> list = stateAiService.list();
+        //机型,源状态,目标状态
+        Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(
+                StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
+        String collect = entityAiZt.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
+        Map<String, PointData> latest = adapter.getLatest(goldenUri(), collect);
+
+        for (PointInfo info : entityAiZt) {
+            PointData data = latest.get(info.getPointKey());
+            Integer m = collectAi.get(info.getSpare()).get((int) data.getValue());
+            if (m == null) m = 2;
+            data.setDoubleValue(m);
+            info.setPointDatas(Collections.singletonList(data));
+        }
+        return entityAiZt;
+    }
+
+    public void getAgoAvg(List<PointInfo> entity, Date start, Date end) {
+        for (PointInfo info : entity) {
+            DoubleStatData snap = adapter.getHistoryStat(goldenUri(), info.getPointKey(), start.getTime(), end.getTime());
+            ThreadUtil.sleep(20);
+            info.setPointDatas(Collections.singletonList(snap.getAvg()));
+        }
+    }
+
+    public void calcRealtimeTurbineXd(PointInfo ztInfo, PointData gl, PointData fs, PointData ylzsgd, PointData czxd) {
+        Map<String, EquipmentModel> map = equipmentModelService.map();
+        Double capacity = map.get(ztInfo.getSpare()).getPowerProduction();
+        PointData zt = ztInfo.getPointDatas().get(0);
+
+        if (czxd.isBooleanValue() && gl.getValue() < capacity * 0.9) {
+            if (fs.getValue() >= 12) {
+                zt.setDoubleValue(8.0);
+            }
+            if (ylzsgd.getValue() != 0 && ylzsgd.getValue() < 17.3) {//降出力
+                zt.setDoubleValue(8.0);
+            }
+        }
+    }
 }