GYEE 1 jaar geleden
bovenliggende
commit
621babb7be

+ 6 - 0
ruoyi-admin/pom.xml

@@ -93,6 +93,12 @@
             <artifactId>ruoyi-generator</artifactId>
         </dependency>-->
 
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.8.25</version>
+        </dependency>
+
     </dependencies>
 
     <build>

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

@@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
-@Service
+//@Service
 public class JavaFunctionJobHandler extends IJobHandler {
 
     @Resource

+ 32 - 12
ruoyi-admin/src/main/java/com/ruoyi/web/runner/LoadDataSourceRunner.java

@@ -1,6 +1,10 @@
 package com.ruoyi.web.runner;
 
 import cn.hutool.core.bean.BeanUtil;
+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.io.file.FileReader;
 import com.alibaba.druid.pool.DruidDataSource;
 import com.alibaba.fastjson2.JSON;
@@ -16,18 +20,19 @@ import com.ruoyi.ucp.entity.UcpDataSource;
 import com.ruoyi.ucp.feign.AdapterApi;
 import com.ruoyi.ucp.service.*;
 import com.ruoyi.ucp.util.CalcCache;
+import com.ruoyi.web.controller.JavaFunctionJobHandler;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 import java.io.File;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 
 @Component
 public class LoadDataSourceRunner implements CommandLineRunner {
@@ -53,10 +58,13 @@ public class LoadDataSourceRunner implements CommandLineRunner {
     @Resource
     private IFormulaService formulaService;
     @Resource
-    @Autowired
     private RedisTemplate redisTemplate;
+    @Resource
+    private StringRedisTemplate stringRedisTemplate;
     @Value("${ruoyi.profile}")
     private String path;
+//    @Resource
+//    private JavaFunctionJobHandler task;
 
     @Override
     public void run(String... args) {
@@ -91,10 +99,10 @@ public class LoadDataSourceRunner implements CommandLineRunner {
             e.printStackTrace();
         }
 
-        LettuceConnectionFactory factory = (LettuceConnectionFactory) redisTemplate.getConnectionFactory();
+        LettuceConnectionFactory factory = (LettuceConnectionFactory) stringRedisTemplate.getConnectionFactory();
         int database = factory.getDatabase();
         factory.setDatabase(9);
-        redisTemplate.setConnectionFactory(factory);
+        stringRedisTemplate.setConnectionFactory(factory);
         factory.afterPropertiesSet();
         factory.resetConnection();
         /*Set<String> keys = redisTemplate.keys("monthCurve_*");
@@ -109,13 +117,13 @@ public class LoadDataSourceRunner implements CommandLineRunner {
             CalcCache.wtMcfMap.put(powerList.get(0).getWindturbineId(), collect);
         }*/
 
-        String zllgl = (String) redisTemplate.opsForValue().get("ZLLGL");
+        String zllgl = stringRedisTemplate.opsForValue().get("ZLLGL");
         //字符串类型转换为list月拟合曲线集合
         Map<String, Map<Double, ProBasicModelPowerRd>> bzgl = JSON.parseObject(zllgl, new TypeReference<Map<String, Map<Double, ProBasicModelPowerRd>>>() {
         }.getType());
-        Map<String, Map<Double, Double>> bz = new HashMap<>();
+        Map<String, ConcurrentHashMap<Double, Double>> bz = new HashMap<>();
         bzgl.forEach((modeId, map) -> {
-            Map<Double, Double> mdd = new HashMap<>();
+            ConcurrentHashMap<Double, Double> mdd = new ConcurrentHashMap<>();
             map.forEach((speed, mprd) -> {
                 mdd.put(speed, mprd.getEnsurePower());
             });
@@ -126,8 +134,20 @@ public class LoadDataSourceRunner implements CommandLineRunner {
         factory.setDatabase(database);
         factory.afterPropertiesSet();
         factory.resetConnection();
-        String glqxnh = (String) redisTemplate.opsForValue().get("glqxnh");
-        CalcCache.fitcoef = JSON.parseObject(glqxnh, new TypeReference<Map<String, double[]>>() {
-        }.getType());
+
+
+        Set<String> keys = stringRedisTemplate.keys("glqxnh:5:*");
+        for (String key : keys) {
+            String yc = stringRedisTemplate.opsForValue().get(key);
+            ConcurrentHashMap<Double, Double> wtyc = JSON.parseObject(yc, new TypeReference<ConcurrentHashMap<Double, Double>>() {}.getType());
+            CalcCache.fitcoef.put(key.replaceFirst("glqxnh:5:",""),wtyc);
+        }
+
+
+
+//        DateTime start = DateUtil.parse("2024-03-25");
+//        DateTime end = DateUtil.parse("2024-06-25");
+//        task.calcGlqxnh(start,end);
+//        System.out.println("选否");
     }
 }

+ 14 - 13
ruoyi-admin/src/main/resources/application-druid.yml

@@ -5,20 +5,21 @@ spring:
     driver-class-name: org.postgresql.Driver                # pgsql驱动包
     druid:
       master:
-        url: jdbc:postgresql://192.168.126.128:5432/calc_hub
-        username: gfhd
-        password: zghww693
+#        url: jdbc:postgresql://192.168.126.128:5432/calc_hub
+#        username: gfhd
+#        password: zghww693
+        url: jdbc:postgresql://172.16.12.102:5432/calc_hub
+        username: postgres
+        password: GYee@#56
       taos:
-        url: jdbc:TAOS-RS://192.168.126.128:6041/jsfw_db?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8
+#        url: jdbc:TAOS-RS://192.168.126.128:6041/jsfw_db?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8
+        url: jdbc:TAOS-RS://172.16.12.101:6041/jsfw_db?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8
         username: root
         password: taosdata
         driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
 #        url: jdbc:postgresql://123.60.219.66:5432/ry-vue
 #        username: postgres
 #        password: gyeepd@123
-#        url: jdbc:postgresql://172.16.12.102:5432/calc_hub
-#        username: postgres
-#        password: GYee@#56
 #        url: jdbc:mysql://49.234.50.218:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
 #        username: root
 #        password: zghww693
@@ -27,15 +28,15 @@ spring:
 #        url: jdbc:postgresql://192.168.126.128:5432/postgres
 #        username: gfhd
 #        password: zghww693
-        url: jdbc:postgresql://192.168.2.232:5432/power_lcm
-        username: postgres
-        password: gd123
+#        url: jdbc:postgresql://192.168.2.232:5432/power_lcm
+#        username: postgres
+#        password: gd123
 #        url: jdbc:postgresql://123.60.219.66:5432/power_lcm
 #        username: postgres
 #        password: gyeepd@123
-#        url: jdbc:postgresql://172.16.12.102:5432/power_lcm
-#        username: postgres
-#        password: GYee@#56
+        url: jdbc:postgresql://172.16.12.102:5432/power_lcm
+        username: postgres
+        password: GYee@#56
 #        driver-class-name: org.postgresql.Driver
         enabled: true
       # 初始连接数

+ 13 - 6
ruoyi-admin/src/main/resources/application.yml

@@ -9,7 +9,8 @@ ruoyi:
   # 实例演示开关
   demoEnabled: true
   # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
-  profile: D:/ruoyi/uploadPath
+#  profile: /home/ruoyi
+  profile: D:/ruoyi/
   # 获取ip地址开关
   addressEnabled: false
   # 验证码类型 math 数组计算 char 字符验证
@@ -77,15 +78,15 @@ spring:
   # redis 配置
   redis:
     # 地址
-#    host: 172.16.12.103
-    host: 127.0.0.1
+    host: 172.16.12.103
+#    host: 127.0.0.1
     # 端口,默认为6379
     port: 6379
     # 数据库索引
     database: 5
     # 密码
-#    password: GYee@#56
-    password:
+    password: GYee@#56
+#    password:
     # 连接超时时间
     timeout: 10s
     lettuce:
@@ -145,4 +146,10 @@ xss:
   # 匹配链接
   urlPatterns: /system/*,/monitor/*,/tool/*
 
-url: ws://43.156.3.30:8080/gs-guide-websocket
+#url: ws://43.156.3.30:8080/gs-guide-websocket
+feign:
+  client:
+    config:
+      default:
+        connect-timeout: 5000
+        read-timeout: 300000

+ 71 - 0
ruoyi-admin/src/test/java/com/ruoyi/GetDataTest.java

@@ -0,0 +1,71 @@
+package com.ruoyi;
+
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.text.csv.CsvUtil;
+import cn.hutool.core.text.csv.CsvWriter;
+import cn.hutool.core.util.CharsetUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.ucp.entity.*;
+import com.ruoyi.ucp.feign.AdapterApi;
+import com.ruoyi.ucp.service.*;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+import java.net.URI;
+import java.util.*;
+
+@SpringBootTest
+@RunWith(SpringRunner.class)
+public class GetDataTest {
+
+    @Resource
+    private IPointInfoService pointInfoService;
+    @Resource
+    private AdapterApi adapterApi;
+    @Test
+    public void test() {
+        DateTime start = DateUtil.parse("2023-06-01");
+        DateTime end = DateUtil.parse("2024-05-31");
+
+        String[] names = {"AI004","AI005","AI006","AI007","AI008","AI009","AI073","AI037","AI039","AI038","AI047","AI048","AI056","AI057","AI060","DI022","AI066","AI067","AI069","AI072","AI074","DI025","DI080","AI082","AI084","AI083","AI065"};
+        QueryWrapper<PointInfo> wrapper = new QueryWrapper<>();
+        wrapper.lambda().eq(PointInfo::getInstitutionType, "turbine")
+//                .eq(PointInfo::getStationId,"GJNY_SXGS_LJS_FDC_STA")
+                .eq(PointInfo::getTurbineId,"GJNY_SXGS_LJS_F_WT_0001_EQ")
+                .in(PointInfo::getUniformCode,names);
+        List<PointInfo> list = pointInfoService.list(wrapper);
+        for (PointInfo pi : list) {
+            CsvWriter writer = null;
+            if(pi.getPointKey().equals("INITIAL")){
+                //指定路径和编码
+                writer = CsvUtil.getWriter("D:/数据/"+pi.getTurbineId()+"/"+pi.getName()+"无测点"+
+                        ".csv", CharsetUtil.CHARSET_GBK);
+                continue;
+            }
+            List<PointData> s = adapterApi.getHistorySnap(URI.create("http://172.16.12.103:8011/ts"), pi.getPointKey(),
+                    start.getTime(), end.getTime(), 60);
+
+                //指定路径和编码
+                writer = CsvUtil.getWriter("D:/数据/"+pi.getTurbineId()+"/"+pi.getName()+
+                        ".csv", CharsetUtil.CHARSET_GBK);
+                //按行写出
+                writer.write(new String[] {"时间","时间戳","对齐时间戳", "值"});
+
+                long j=start.getTime();
+            for (int i = 0; i <s.size(); i++) {
+                String[] r = new String[4];
+                r[0]=DateUtil.formatDateTime(new Date(j));
+                r[1]=Long.toString(s.get(i).getTs());
+                r[2]=Long.toString(j);
+                r[3]=Double.toString(s.get(i).getValue());
+                writer.write(r);
+                j+=60*1000;
+            }
+
+        }
+    }
+}

+ 987 - 258
ruoyi-admin/src/test/java/com/ruoyi/JavaFunctionJobHandler.java

@@ -1,16 +1,20 @@
 package com.ruoyi;
 
-import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.thread.ThreadUtil;
+import cn.hutool.core.util.NumberUtil;
+import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.ruoyi.quartz.handler.IJobHandler;
-import com.ruoyi.quartz.task.ChangedSave;
 import com.ruoyi.ucp.entity.*;
 import com.ruoyi.ucp.feign.AdapterApi;
 import com.ruoyi.ucp.service.*;
 import com.ruoyi.ucp.util.CalcCache;
-import org.springframework.data.redis.core.RedisTemplate;
+import org.apache.commons.math3.fitting.PolynomialCurveFitter;
+import org.apache.commons.math3.fitting.WeightedObservedPoints;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.net.URI;
@@ -18,6 +22,7 @@ import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
+@Service
 public class JavaFunctionJobHandler extends IJobHandler {
 
     @Resource
@@ -33,9 +38,13 @@ public class JavaFunctionJobHandler extends IJobHandler {
     @Resource
     private IStateAiService stateAiService;
     @Resource
-    private RedisTemplate redisTemplate;
+    private StringRedisTemplate stringRedisTemplate;
     @Resource
     private IEquipmentModelService equipmentModelService;
+    @Resource
+    private ITurbineInfoDayService turbineInfoDayService;
+    @Resource
+    private IProEconReportIndicatorPoolService reportIndicatorPoolService;
 
     @Override
     public void execute() throws Exception {
@@ -52,6 +61,151 @@ public class JavaFunctionJobHandler extends IJobHandler {
 
     }
 
+    public URI taosGoldenUriTest() {
+        return URI.create("http://127.0.0.1:8011/ts");
+    }
+
+    public String pointInfos2Keys(List<PointInfo> entity) {
+        return entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
+    }
+
+    public List<StationInfoHour> getStationinfoByHour(Date hour) {
+        QueryWrapper<StationInfoHour> wrapper = new QueryWrapper<>();
+        wrapper.eq("record_date", DateUtil.beginOfHour(hour));
+        return stationInfoHourService.list(wrapper);
+    }
+
+    public List<StationInfoDay> getStationinfoByDate(Date date) {
+        QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
+        wrapper.eq("record_date", date);
+        return stationInfoDayService.list(wrapper);
+    }
+
+    public List<LineInfoDay> getLineinfoByDate(Date date) {
+        QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
+        wrapper.eq("record_date", date);
+        return lineInfoDayService.list(wrapper);
+    }
+
+    public URI taosUri() {
+        return URI.create("http://172.16.12.101:8012/ts");
+    }
+
+    public URI goldenUri() {
+        return URI.create("http://172.16.12.103:8011/ts");
+    }
+
+    public Map<String, String> getEntityMap(String uniformCode, String institutionType) {
+        PointInfo pi = new PointInfo();
+        pi.setUniformCode(uniformCode);
+        pi.setInstitutionType(institutionType);
+        List<PointInfo> entity = pointService.getByEntity(pi);
+        switch (institutionType) {
+            case "turbine":
+            case "state":
+                return entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointKey));
+            case "station":
+                return entity.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getPointKey));
+        }
+        return new HashMap<>();
+    }
+
+    public Map<String, TurbineInfoDay> getTurbineinfoMap(Date date, List<PointInfo> entity) {
+        QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
+        wrapper.eq("record_date", date);
+        List<TurbineInfoDay> list = turbineInfoDayService.list(wrapper);
+        if (list.isEmpty()) {
+            entity.forEach(pi -> {
+                TurbineInfoDay day = new TurbineInfoDay();
+                day.setStationId(pi.getStationId());
+                day.setProjectId(pi.getProjectId());
+                day.setLineId(pi.getLineId());
+                day.setTurbineId(pi.getTurbineId());
+                day.setRecordDate(date);
+                list.add(day);
+            });
+        }
+        return list.stream().collect(Collectors.toMap(TurbineInfoDay::getTurbineId, Function.identity()));
+    }
+
+    public List<PointInfo> getEntity(String uniformCode, String institutionType) {
+        PointInfo pi = new PointInfo();
+        pi.setUniformCode(uniformCode);
+        pi.setInstitutionType(institutionType);
+        return pointService.getByEntity(pi);
+    }
+
+    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()));
+        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;
+
+        List<PointData> collectZt = piZt.getPointDatas();
+        double jxss = 0, sdtj = 0, gzss = 0, djss = 0, xnss = 0, fdjcl = 0, xdjcl = 0, xdtj = 0;
+        Map<String, Double> map = new HashMap<>();
+        if (collectZt.size() == fsList.size() && fsList.size() == glList.size()) {
+            for (int i = 0; i < collectZt.size(); i++) {
+                Double v = CalcCache.fitcoef.get(tbId).get(fsList.get(i).getValue());
+                if (v == null) v = 0.0;
+                switch ((int) collectZt.get(i).getValue()) {
+                    //计划检修损失:
+                    case 6:
+                        //检修
+                        jxss += v;
+                        break;
+                    case 1:
+                        //手动停机
+                        sdtj += v;
+                        break;
+                    //非计划检修损失:
+                    case 4:
+                        //故障
+                        gzss += v;
+                        break;
+                    case 0:
+                        //待机
+                        djss += v;
+                        break;
+                    //性能损失:
+                    case 2:
+                        //性能
+                        xnss += v - glList.get(i).getValue();
+                        break;
+                    case 3:
+                        //发电降出力
+                        fdjcl += v - glList.get(i).getValue();
+                        break;
+                    //限电损失:
+                    case 8:
+                        //限电降出力
+                        xdjcl += v - glList.get(i).getValue();
+                        break;
+                    case 9:
+                        //限电停机
+                        xdtj += v;
+                        break;
+                }
+            }
+        }
+        //15秒*60分钟
+        map.put("jxss", jxss > 0 ? jxss / 240 * xs : 0);
+        map.put("sdtj", sdtj > 0 ? sdtj / 240 * xs : 0);
+        map.put("gzss", gzss > 0 ? gzss / 240 * xs : 0);
+        map.put("djss", djss > 0 ? djss / 240 * xs : 0);
+        map.put("xnss", xnss > 0 ? xnss / 240 * xs : 0);
+        map.put("fdjcl", fdjcl > 0 ? fdjcl / 240 * xs : 0);
+        map.put("xdjcl", xdjcl > 0 ? xdjcl / 240 * xs : 0);
+        map.put("xdtj", xdtj > 0 ? xdtj / 240 * xs : 0);
+        return map;
+    }
+
     public void calcAQTS(Date date) {
         QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
         wrapper.select("min(record_date) record_date");
@@ -79,18 +233,69 @@ public class JavaFunctionJobHandler extends IJobHandler {
         stationInfoDayService.saveOrUpdateBatch(today);
     }
 
-    public List<StationInfoDay> getStationinfoByDate(Date date) {
-        QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
-        wrapper.eq("record_date", date);
-        return stationInfoDayService.list(wrapper);
-    }
+    public void calcStationSwGwCyDl(Date date) {
+        //date当天零点
+        DateTime time = DateUtil.beginOfDay(date);
+        //date昨天零点
+        DateTime time0 = DateUtil.offsetDay(time, -1);
+        //date当天零点加三分钟
+        DateTime time2 = DateUtil.offsetMinute(time, 3);
+        //date昨天零点加三分钟
+        DateTime time1 = DateUtil.offsetMinute(time0, 3);
 
-    public URI taosGoldenUriTest() {
-        return URI.create("http://127.0.0.1:8011/ts");
-    }
+        PointInfo swdlPi = new PointInfo();
+        swdlPi.setUniformCode("Z-ZXYG-CX");
+        PointInfo gwdlPi = new PointInfo();
+        gwdlPi.setUniformCode("Z-FXYG-CX");
+        PointInfo cydlPi = new PointInfo();
+        cydlPi.setUniformCode("Z-ZXYG-ZYB");
 
-    public URI taosUri() {
-        return URI.create("http://172.16.12.101:8012/ts");
+        List<PointInfo> swdlEt = pointService.getByEntity(swdlPi);
+        List<PointInfo> gwdlEt = pointService.getByEntity(gwdlPi);
+        Map<String, PointInfo> gwdlMap = gwdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
+        List<PointInfo> cydlEt = pointService.getByEntity(cydlPi);
+        Map<String, PointInfo> cydlMap = cydlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
+
+        String swdlK = pointInfos2Keys(swdlEt);
+        String gwdlK = pointInfos2Keys(gwdlEt);
+        String cydlK = pointInfos2Keys(cydlEt);
+
+        Map<String, PointData> swdlL2 = adapter.getHistorySection(goldenUri(), swdlK, time2.getTime());
+        Map<String, PointData> swdlL1 = adapter.getHistorySection(goldenUri(), swdlK, time1.getTime());
+        Map<String, PointData> gwdlL2 = adapter.getHistorySection(goldenUri(), gwdlK, time2.getTime());
+        Map<String, PointData> gwdlL1 = adapter.getHistorySection(goldenUri(), gwdlK, time1.getTime());
+        Map<String, PointData> cydlL2 = adapter.getHistorySection(goldenUri(), cydlK, time2.getTime());
+        Map<String, PointData> cydlL1 = adapter.getHistorySection(goldenUri(), cydlK, time1.getTime());
+
+        List<StationInfoDay> byDate = getStationinfoByDate(time0.toJdkDate());
+        Map<String, StationInfoDay> collect = new HashMap<>();
+        if (!byDate.isEmpty()) {
+            collect = byDate.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
+        }
+        StationInfoDay infoDay;
+        String stationId;
+        PointInfo gwdlKey, cydlKey;
+        List<StationInfoDay> infoDays = new ArrayList<>();
+        for (PointInfo info : swdlEt) {
+            stationId = info.getStationId();
+            if (byDate.isEmpty()) {
+                infoDay = new StationInfoDay();
+                infoDay.setStationId(stationId);
+                infoDay.setRecordDate(time0.toJdkDate());
+            } else {
+                infoDay = collect.get(stationId);
+            }
+            infoDay.setSwdl((int) ((swdlL2.get(info.getPointKey()).getValue() -
+                    swdlL1.get(info.getPointKey()).getValue()) * info.getCoef()));
+            gwdlKey = gwdlMap.get(stationId);
+            infoDay.setGwdl((int) ((gwdlL2.get(gwdlKey.getPointKey()).getValue() -
+                    gwdlL1.get(gwdlKey.getPointKey()).getValue()) * gwdlKey.getCoef()));
+            cydlKey = cydlMap.get(stationId);
+            infoDay.setCydl((int) ((cydlL2.get(cydlKey.getPointKey()).getValue() -
+                    cydlL1.get(cydlKey.getPointKey()).getValue()) * cydlKey.getCoef()));
+            infoDays.add(infoDay);
+        }
+        stationInfoDayService.saveOrUpdateBatch(infoDays);
     }
 
     public void calcStationHourRFDL(Date hour) {
@@ -98,64 +303,79 @@ public class JavaFunctionJobHandler extends IJobHandler {
         pointInfo.setInstitutionType("station");
         pointInfo.setUniformCode("RFDLSYZ");
         List<PointInfo> entity = pointService.getByEntity(pointInfo);
-        Map<String, PointData> section = adapter.getHistorySection(taosGoldenUriTest()
-                , pointInfos2Keys(entity), hour.getTime());
+        Map<String, PointData> section = adapter.getHistorySection(taosUri(), pointInfos2Keys(entity), hour.getTime());
         List<StationInfoHour> byHours = getStationinfoByHour(hour);
         if (byHours.isEmpty()) {
             for (PointInfo point : entity) {
                 StationInfoHour info = new StationInfoHour();
                 info.setStationId(point.getStationId());
                 info.setRecordDate(DateUtil.beginOfHour(hour));
-                info.setRfdl(section.get(point.getPointKey()).getDoubleValue());
+                info.setRfdl(section.get(point.getPointKey()).getValue());
                 byHours.add(info);
             }
         } else {
             Map<String, String> collect = entity.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getPointKey));
             for (StationInfoHour byHour : byHours) {
-                byHour.setRfdl(section.get(collect.get(byHour.getStationId())).getDoubleValue());
+                byHour.setRfdl(section.get(collect.get(byHour.getStationId())).getValue());
             }
         }
         stationInfoHourService.saveOrUpdateBatch(byHours);
     }
 
-    public List<StationInfoHour> getStationinfoByHour(Date hour) {
-        QueryWrapper<StationInfoHour> wrapper = new QueryWrapper<>();
-        wrapper.eq("record_date", DateUtil.beginOfHour(hour));
-        return stationInfoHourService.list(wrapper);
-    }
+    public void writeReportPool(Date date) {
+        //date当天零点
+        DateTime time = DateUtil.beginOfDay(date);
+        //date昨天零点
+        DateTime time0 = DateUtil.offsetDay(time, -1);
+        DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
+        DateTime beginOfYear = DateUtil.beginOfYear(time0);
 
-    public String pointInfos2Keys(List<PointInfo> entity) {
-        return entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
-    }
+        QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
+        wrapper.eq("record_date", time0);
+        List<StationInfoDay> days = stationInfoDayService.list(wrapper);
+        Map<String, StationInfoDay> dayMap = days.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
+        wrapper = new QueryWrapper<>();
+        wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,sum(zhcydl) zhcydl,station_id")
+                .between("record_date", beginOfMonth.toJdkDate(), time0.toJdkDate())
+                .groupBy("station_id");
+        List<StationInfoDay> monthDays = stationInfoDayService.list(wrapper);
+        Map<String, StationInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
+        wrapper = new QueryWrapper<>();
+        wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,sum(zhcydl) zhcydl,station_id")
+                .between("record_date", beginOfYear.toJdkDate(), time0.toJdkDate())
+                .groupBy("station_id");
+        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);
+//        pools = pools.stream().filter(p -> p.getWindpowerstationId().equals("GJNY_SXGS_ZZ_FDC_STA")).collect(Collectors.toList());
 
-    public void calcStationHourPJGL(Date hour) {
-        PointInfo pointInfo = new PointInfo();
-        pointInfo.setInstitutionType("station");
-        pointInfo.setUniformCode("SSZGL");
-        List<PointInfo> entity = pointService.getByEntity(pointInfo);
-        List<StationInfoHour> byHours = getStationinfoByHour(hour);
-        Map<String, StationInfoHour> collect = new HashMap<>();
-        if (byHours.size() > 0) {
-            collect = byHours.stream().collect(
-                    Collectors.toMap(StationInfoHour::getStationId, Function.identity()));
+        StationInfoDay day, month, year;
+        List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
+        for (ProEconReportIndicatorPool pool : pools) {
+            String stationId = pool.getWindpowerstationId();
+            day = dayMap.get(stationId);
+            pool.setRfdldb(day.getRfdl().doubleValue());
+            pool.setRswdldb(day.getSwdl().doubleValue());
+            pool.setRgwgwdldb(day.getGwdl().doubleValue());
+            pool.setRfdcydldb(day.getCydl().doubleValue());
+            pool.setRzhcydldb(day.getZhcydl().doubleValue());
+            month = monthMap.get(stationId);
+            pool.setYfdldb(month.getRfdl().doubleValue());
+            pool.setYswdldb(month.getSwdl().doubleValue());
+            pool.setYgwgwdldb(month.getGwdl().doubleValue());
+            pool.setYfdcydldb(month.getCydl().doubleValue());
+            pool.setYzhcydldb(month.getZhcydl().doubleValue());
+            year = yearMap.get(stationId);
+            pool.setNfdldb(year.getRfdl().doubleValue());
+            pool.setNswdldb(year.getSwdl().doubleValue());
+            pool.setNgwgwdldb(year.getGwdl().doubleValue());
+            pool.setNfdcydldb(year.getCydl().doubleValue());
+            pool.setNzhcydldb(year.getZhcydl().doubleValue());
+            poolList.add(pool);
         }
-        DoubleStatData stat;
-        List<StationInfoHour> byHours2 = new ArrayList<>();
-        for (PointInfo point : entity) {
-            stat = adapter.getHistoryStat(taosGoldenUriTest(),
-                    point.getPointKey(), DateUtil.offsetHour(hour, -1).getTime(), hour.getTime());
-            if (byHours.isEmpty()) {
-                StationInfoHour info = new StationInfoHour();
-                info.setStationId(point.getStationId());
-                info.setRecordDate(DateUtil.beginOfHour(hour));
-                if (stat==null) info.setPjgl(0.0);
-                info.setPjgl(stat.getAvg().getDoubleValue());
-                byHours2.add(info);
-            } else {
-                collect.get(point.getStationId()).setPjgl(stat.getAvg().getDoubleValue());
-            }
-        }
-        stationInfoHourService.saveOrUpdateBatch(byHours.isEmpty() ? byHours2 : byHours);
+        reportIndicatorPoolService.saveOrUpdateBatch(poolList);
     }
 
     public void calcLineDjlRfdl(Date date) {
@@ -172,13 +392,14 @@ 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());
         String keys = pointInfos2Keys(entity);
-        Map<String, PointData> latest2 = adapter.getHistorySection(taosGoldenUriTest(), keys, time2.getTime());
-        Map<String, PointData> latest1 = adapter.getHistorySection(taosGoldenUriTest(), keys, time1.getTime());
+        Map<String, PointData> latest2 = adapter.getHistorySection(goldenUri(), keys, time2.getTime());
+        Map<String, PointData> latest1 = adapter.getHistorySection(goldenUri(), keys, time1.getTime());
 
         List<LineInfoDay> byDate = getLineinfoByDate(time0.toJdkDate());
         Map<String, LineInfoDay> collect = new HashMap<>();
-        if (byDate.size() > 0) {
+        if (!byDate.isEmpty()) {
             collect = byDate.stream().collect(Collectors.toMap(LineInfoDay::getLineId, Function.identity()));
         }
 
@@ -194,104 +415,101 @@ public class JavaFunctionJobHandler extends IJobHandler {
             } else {
                 day = collect.get(info.getLineId());
             }
-            day.setRfdl((int) ((latest2.get(info.getPointKey()).getDoubleValue() -
-                    latest1.get(info.getPointKey()).getDoubleValue()) * info.getCoef()));
+            day.setRfdl((int) ((latest2.get(info.getPointKey()).getValue() -
+                    latest1.get(info.getPointKey()).getValue()) * info.getCoef()));
+            if (day.getRfdl() <= 0 || day.getRfdl() > 30000000) {
+                day.setRfdl(0);
+            }
             list.add(day);
         }
         lineInfoDayService.saveOrUpdateBatch(list);
     }
 
-    public List<LineInfoDay> getLineinfoByDate(Date date) {
-        QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
-        wrapper.eq("record_date", date);
-        return lineInfoDayService.list(wrapper);
-    }
-
-    public void calcStationSwGwCyDl(Date date) {
+    public void calcStationZhcydl(Date date) {
         //date当天零点
         DateTime time = DateUtil.beginOfDay(date);
         //date昨天零点
         DateTime time0 = DateUtil.offsetDay(time, -1);
-        //date当天零点加三分钟
-        DateTime time2 = DateUtil.offsetMinute(time, 3);
-        //date昨天零点加三分钟
-        DateTime time1 = DateUtil.offsetMinute(time0, 3);
-
-        PointInfo swdlPi = new PointInfo();
-        swdlPi.setUniformCode("Z-ZXYG-CX");
-        PointInfo gwdlPi = new PointInfo();
-        gwdlPi.setUniformCode("Z-FXYG-CX");
-        PointInfo cydlPi = new PointInfo();
-        cydlPi.setUniformCode("Z-ZXYG-ZYB");
-
-        List<PointInfo> swdlEt = pointService.getByEntity(swdlPi);
-        List<PointInfo> gwdlEt = pointService.getByEntity(gwdlPi);
-        Map<String, PointInfo> gwdlMap = gwdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
-        List<PointInfo> cydlEt = pointService.getByEntity(cydlPi);
-        Map<String, PointInfo> cydlMap = cydlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
-
-        String swdlK = pointInfos2Keys(swdlEt);
-        String gwdlK = pointInfos2Keys(gwdlEt);
-        String cydlK = pointInfos2Keys(cydlEt);
-
-        Map<String, PointData> swdlL2 = adapter.getHistorySection(taosGoldenUriTest(), swdlK, time2.getTime());
-        Map<String, PointData> swdlL1 = adapter.getHistorySection(taosGoldenUriTest(), swdlK, time1.getTime());
-        Map<String, PointData> gwdlL2 = adapter.getHistorySection(taosGoldenUriTest(), gwdlK, time2.getTime());
-        Map<String, PointData> gwdlL1 = adapter.getHistorySection(taosGoldenUriTest(), gwdlK, time1.getTime());
-        Map<String, PointData> cydlL2 = adapter.getHistorySection(taosGoldenUriTest(), cydlK, time2.getTime());
-        Map<String, PointData> cydlL1 = adapter.getHistorySection(taosGoldenUriTest(), cydlK, time1.getTime());
 
+        QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
+        wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0.toJdkDate())
+                .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());
+
         Map<String, StationInfoDay> collect = new HashMap<>();
-        if (byDate.size() > 0) {
+        if (!byDate.isEmpty()) {
             collect = byDate.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
         }
+
         StationInfoDay infoDay;
-        String stationId;
-        PointInfo gwdlKey, cydlKey;
         List<StationInfoDay> infoDays = new ArrayList<>();
-        for (PointInfo info : swdlEt) {
-            stationId = info.getStationId();
+        for (LineInfoDay day : list) {
             if (byDate.isEmpty()) {
                 infoDay = new StationInfoDay();
-                infoDay.setStationId(stationId);
+                infoDay.setStationId(day.getStationId());
                 infoDay.setRecordDate(time0.toJdkDate());
             } else {
-                infoDay = collect.get(stationId);
+                infoDay = collect.get(day.getStationId());
             }
-            infoDay.setSwdl((int) ((swdlL2.get(info.getPointKey()).getDoubleValue() -
-                    swdlL1.get(info.getPointKey()).getDoubleValue()) * info.getCoef()));
-            gwdlKey = gwdlMap.get(stationId);
-            infoDay.setGwdl((int) ((gwdlL2.get(gwdlKey.getPointKey()).getDoubleValue() -
-                    gwdlL1.get(gwdlKey.getPointKey()).getDoubleValue()) * gwdlKey.getCoef()));
-            cydlKey = cydlMap.get(stationId);
-            infoDay.setCydl((int) ((cydlL2.get(cydlKey.getPointKey()).getDoubleValue() -
-                    cydlL1.get(cydlKey.getPointKey()).getDoubleValue()) * cydlKey.getCoef()));
+            infoDay.setRfdl(day.getRfdl());
+            infoDay.setZhcydl(infoDay.getRfdl() + infoDay.getGwdl() - infoDay.getSwdl());
             infoDays.add(infoDay);
         }
         stationInfoDayService.saveOrUpdateBatch(infoDays);
     }
 
-    public void calcStationZhcydl(Date date) {
+    public void calcStationHourPJGL(Date hour) {
+        PointInfo pointInfo = new PointInfo();
+        pointInfo.setInstitutionType("station");
+        pointInfo.setUniformCode("SSZGL");
+        List<PointInfo> entity = pointService.getByEntity(pointInfo);
+        List<StationInfoHour> byHours = getStationinfoByHour(hour);
+        Map<String, StationInfoHour> collect = new HashMap<>();
+        if (!byHours.isEmpty()) {
+            collect = byHours.stream().collect(
+                    Collectors.toMap(StationInfoHour::getStationId, Function.identity()));
+        }
+        DoubleStatData stat;
+        List<StationInfoHour> byHours2 = new ArrayList<>();
+        for (PointInfo point : entity) {
+            stat = adapter.getHistoryStat(taosGoldenUriTest(),
+                    point.getPointKey(), DateUtil.offsetHour(hour, -1).getTime(), hour.getTime());
+            if (byHours.isEmpty()) {
+                StationInfoHour info = new StationInfoHour();
+                info.setStationId(point.getStationId());
+                info.setRecordDate(DateUtil.beginOfHour(hour));
+                if (stat == null || stat.getAvg() == null) info.setPjgl(0.0);
+                info.setPjgl(stat.getAvg().getDoubleValue());
+                byHours2.add(info);
+            } else {
+                collect.get(point.getStationId()).setPjgl(stat.getAvg().getDoubleValue());
+            }
+        }
+        stationInfoHourService.saveOrUpdateBatch(byHours.isEmpty() ? byHours2 : byHours);
+    }
+
+    public void calcStationRfdlFj(Date date) {
         //date当天零点
         DateTime time = DateUtil.beginOfDay(date);
         //date昨天零点
         DateTime time0 = DateUtil.offsetDay(time, -1);
 
-        QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
+        QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
         wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0.toJdkDate())
                 .groupBy("station_id");
-        List<LineInfoDay> list = lineInfoDayService.list(wrapper);
+        List<TurbineInfoDay> list = turbineInfoDayService.list(wrapper);
         List<StationInfoDay> byDate = getStationinfoByDate(time0.toJdkDate());
 
         Map<String, StationInfoDay> collect = new HashMap<>();
-        if (byDate.size() > 0) {
+        if (!byDate.isEmpty()) {
             collect = byDate.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
         }
 
         StationInfoDay infoDay;
         List<StationInfoDay> infoDays = new ArrayList<>();
-        for (LineInfoDay day : list) {
+        for (TurbineInfoDay day : list) {
             if (byDate.isEmpty()) {
                 infoDay = new StationInfoDay();
                 infoDay.setStationId(day.getStationId());
@@ -299,180 +517,691 @@ public class JavaFunctionJobHandler extends IJobHandler {
             } else {
                 infoDay = collect.get(day.getStationId());
             }
-            infoDay.setRfdl(day.getRfdl());
-            infoDay.setZhcydl(infoDay.getRfdl() + infoDay.getGwdl() - infoDay.getSwdl());
+            infoDay.setRfdlFj(day.getRfdl());
             infoDays.add(infoDay);
         }
         stationInfoDayService.saveOrUpdateBatch(infoDays);
     }
 
-    public void calcTurbine5s(){
+    public void calcTurbineRFDL(Date date) {
+        //date当天零点
+        DateTime time = DateUtil.beginOfDay(date);
+        //date昨天零点
+        DateTime time0 = DateUtil.offsetDay(time, -1);
+        //date当天零点加三分钟
+        DateTime time2 = DateUtil.offsetMinute(time, 3);
+        //date昨天零点加三分钟
+        DateTime time1 = DateUtil.offsetMinute(time0, 3);
+
 
-    }
-    //此处加公式
-    public void calcTurbineSsztAi(Date date) {
         PointInfo pi = new PointInfo();
-        pi.setUniformCode("AI422");
-        pi.setInstitutionType("state");
-        List<PointInfo> entity = pointService.getByEntity(pi);
-        Map<String, PointInfo> collect = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
+        pi.setUniformCode("AI121");
+        pi.setInstitutionType("turbine");
+        List<PointInfo> entity = getEntity("AI121", "turbine");
+        Map<String, String> turMap = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointKey));
+        Map<String, String> fsMap = getEntityMap("AI066", "turbine");
+
         String keys = pointInfos2Keys(entity);
 
-        PointInfo pimx = new PointInfo();
-        pimx.setUniformCode("MXZT");
-        pimx.setInstitutionType("turbine");
-        List<PointInfo> entityMx = pointService.getByEntity(pimx);
-        Map<String, PointInfo> collectMX = entityMx.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
-        PointInfo pisb = new PointInfo();
-        pisb.setUniformCode("SBZT");
-        pisb.setInstitutionType("turbine");
-        List<PointInfo> entitySB = pointService.getByEntity(pimx);
-        Map<String, PointInfo> collectSB = entitySB.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
-
-        Map<String, PointData> latest = adapter.getLatest(taosGoldenUriTest(), keys);
-        List<StateAi> list = stateAiService.list();
-        Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
+        Map<String, PointData> swdlL2 = adapter.getHistorySection(goldenUri(), keys, time2.getTime());
+        Map<String, PointData> swdlL1 = adapter.getHistorySection(goldenUri(), keys, time1.getTime());
+
+        Map<String, TurbineInfoDay> byDate = getTurbineinfoMap(time0.toJdkDate(), entity);
 
-        List<PointData> pointDatas = new ArrayList<>();
-        int i1;
+        TurbineInfoDay infoDay;
+        String turbineId, key;
+        List<TurbineInfoDay> infoDays = new ArrayList<>();
+        DoubleStatData stat;
         for (PointInfo info : entity) {
-            PointData data = latest.get(info.getPointKey());
-            data.setTagName(collectMX.get(info.getTurbineId()).getPointKey());
-            i1 = (int) data.getDoubleValue();
-            //缓存值
-            Integer i2 = ChangedSave.map.get(info.getPointKey());
-            if (i2 != null && i1 == i2) continue;
-            ChangedSave.map.put(info.getPointKey(), i1);
-            Integer i = collectAi.get(info.getSpare()).get(i1);
-            data.setDoubleValue(i);
-            pointDatas.add(data);
+            turbineId = info.getTurbineId();
+            infoDay = byDate.get(turbineId);
+
+            key = turMap.get(turbineId);
+            double v = (swdlL2.get(key).getValue() - swdlL1.get(key).getValue()) * info.getCoef();
+            if (v < 0 || v > 1000000) {
+                v = 0;
+            } else if (v > 30000) {
+                v = v / (v % 30000 + 3);
+            }
+            infoDay.setRfdl(v);
+            stat = adapter.getHistoryStat(goldenUri(), fsMap.get(turbineId), time1.getTime(), time2.getTime());
+            if (stat == null) {
+                infoDay.setPjfs(0.0);
+            } else {
+                infoDay.setPjfs(stat.getAvg().getValue());
+            }
+
+            infoDays.add(infoDay);
         }
-        adapter.writeHistoryBatch(taosGoldenUriTest(), pointDatas);
+        turbineInfoDayService.saveOrUpdateBatch(infoDays);
+    }
+
+    /*public void calcTurbine5s(Date date) {
+        //date当天零点
+        DateTime time = DateUtil.beginOfDay(date);
+        //date昨天零点
+        DateTime time0 = DateUtil.offsetDay(time, -1);
+
+        //状态
+        List<PointInfo> entityZt = getEntity("MXZT", "turbine");
+        //功率
+        Map<String, String> collectGl = getEntityMap("AI114", "turbine");
+        //风速
+        Map<String, String> collectFs = getEntityMap("AI066", "turbine");
+
+        Map<String, TurbineInfoDay> dayMap = getTurbineinfoMap(time0.toJdkDate(), entityZt);
+
+        String tbId;
+        TurbineInfoDay infoDay;
+        List<TurbineInfoDay> infoDays = new ArrayList<>();
+        for (PointInfo info : entityZt) {
+            tbId = info.getTurbineId();
+            List<PointData> snapZt = adapter.getHistorySnap(taosUri(), info.getPointKey(), time0.getTime(), time.getTime(), 60);
+            //0 待机,1 手动停机,2 正常发电,3 发电降出力,4 故障,5 故障受累,6 检修,7 检修受累,8 限电降出力,
+            // 9 限电停机,10 电网受累,11 环境受累,12 通讯中断,13 设备离线
+
+            List<DoubleStatData> statGl = adapter.getHistoryStat2(goldenUri(), collectGl.get(tbId), time0.getTime(), time.getTime(), 60);
+            List<DoubleStatData> statFs = adapter.getHistoryStat2(goldenUri(), collectFs.get(tbId), time0.getTime(), time.getTime(), 60);
+            List<PointData> glList = statGl.stream().map(DoubleStatData::getAvg).collect(Collectors.toList());
+            List<PointData> fsList = statFs.stream().map(DoubleStatData::getAvg)
+                    .peek(fs -> {
+                        if (fs.getValue() < 25) {
+                            fs.setDoubleValue(NumberUtil.round(fs.getValue(), 2).doubleValue());
+                        } else {
+                            fs.setDoubleValue(25.0);
+                        }
+                    }).collect(Collectors.toList());
+
+//            Map<String, Double> loss = getTurbinePowerLoss(snapZt, fsList, tbId, glList);
+            Map<String, Double> loss = new HashMap<>();
+
+            infoDay = dayMap.get(tbId);
+            infoDay.setJhjxss(loss.get("jxss") + loss.get("sdtj"));
+            infoDay.setFjhjxss(loss.get("gzss") + loss.get("djss") + loss.get("fdjcl"));
+            infoDay.setXdss(loss.get("xdjcl") + loss.get("xdtj"));
+            infoDay.setSlss(0.0);
+            if (infoDay.getRfdl() == 0) {
+                infoDay.setXnss(0.0);
+            } else {
+                infoDay.setXnss(loss.get("xnss") * 0.1);
+            }
+            infoDay.setLlfdl(infoDay.getRfdl() + infoDay.getJhjxss() + infoDay.getFjhjxss() +
+                    infoDay.getXdss() + infoDay.getSlss() + infoDay.getXnss());
+            infoDays.add(infoDay);
+        }
+        turbineInfoDayService.saveOrUpdateBatch(infoDays);
+    }*/
+
+    //此处加公式
+    public void calcStationSspjfs() {
+        List<PointInfo> fsEntity = getEntity("AI066", "turbine");
+        String keys = pointInfos2Keys(fsEntity);
+        Map<String, PointData> latest = adapter.getLatest(goldenUri(), keys);
+        Map<String, List<String>> listMap = fsEntity.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.mapping(PointInfo::getPointKey, Collectors.toList())));
 
-        //redisTemplate.opsForHash().put("state_point",key,value);
+        Map<String, String> entityMap = getEntityMap("SSPJFS", "station");
 
+        List<PointData> tsData = new ArrayList<>();
+        listMap.forEach((stId, keyList) -> {
+            double v = keyList.stream().mapToDouble(key -> latest.get(key).getValue()).average().orElse(0.0);
+            PointData data = new PointData();
+            data.setTs(System.currentTimeMillis());
+            data.setTagName(entityMap.get(stId));
+            data.setDoubleValue(v);
+            tsData.add(data);
+        });
+        adapter.writeHistoryBatch(taosUri(), tsData);
     }
-    public void calcStationXd(boolean priorRation){
-        //限电状态
-        PointInfo piAgc = new PointInfo();
-        //AGC
-        piAgc.setUniformCode("AGC002");
-        piAgc.setInstitutionType("booster");
-        List<PointInfo> entityAgc = pointService.getByEntity(piAgc);
-        Map<String, PointInfo> collectAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
-        String keysAgc = pointInfos2Keys(entityAgc);
 
+
+    public void calcTurbine5s2(Date date) {
+        //date当天零点
+        DateTime time = DateUtil.beginOfDay(date);
+        //date昨天零点
+        DateTime time0 = DateUtil.offsetDay(time, -1);
+        //风速
+        List<PointInfo> entityFs = getEntity("AI066", "turbine");
+        //功率
+        List<PointInfo> entityGl = getEntity("AI114", "turbine");
+        getSnapDataByEntity(entityFs, time0, time, 15);
+        getSnapDataByEntity(entityGl, time0, time, 15);
+
+        List<PointInfo> ztMapMap = calcTurbineZt(time0, time, entityFs, entityGl);
+        Map<String, Map<String, PointInfo>> ztMapMapInfos = ztMapMap.stream().collect(
+                Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
+        Map<String, TurbineInfoDay> dayMap = getTurbineinfoMap(time0, entityFs);
+
+        List<TurbineInfoDay> infoDays = new ArrayList<>();
+        Map<String, Map<String, List<PointData>>> fsMapMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
+                Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
+        Map<String, Map<String, List<PointData>>> glMapMap = entityGl.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
+                Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
+
+        ztMapMapInfos.forEach((stId, ztMapInfo) -> ztMapInfo.forEach((wtId, ztInfo) -> {
+            //0 待机,1 手动停机,2 正常发电,3 发电降出力,4 故障,5 故障受累,6 检修,7 检修受累,8 限电降出力,
+            // 9 限电停机,10 电网受累,11 环境受累,12 通讯中断,13 设备离线
+            TurbineInfoDay infoDay = dayMap.get(wtId);
+            Map<String, Double> loss = getTurbinePowerLoss(infoDay.getRfdl(), ztMapMapInfos.get(stId).get(wtId), fsMapMap.get(stId).get(wtId), glMapMap.get(stId).get(wtId));
+            infoDay.setJhjxss(loss.get("jxss") + loss.get("sdtj"));
+            infoDay.setFjhjxss(loss.get("gzss") + loss.get("djss") + loss.get("fdjcl"));
+            infoDay.setXdss(loss.get("xdjcl") + loss.get("xdtj"));
+            infoDay.setSlss(0.0);
+            if (infoDay.getRfdl() == 0) {
+                infoDay.setXnss(0.0);
+            } else {
+                infoDay.setXnss(loss.get("xnss"));
+            }
+            infoDay.setLlfdl(infoDay.getRfdl() + infoDay.getJhjxss() + infoDay.getFjhjxss() +
+                    infoDay.getXdss() + infoDay.getSlss() + infoDay.getXnss());
+            infoDays.add(infoDay);
+        }));
+        turbineInfoDayService.saveOrUpdateBatch(infoDays);
+    }
+
+    public List<PointInfo> calcTurbineZt(Date start, Date end, List<PointInfo> fsInfos, List<PointInfo> glInfos) {
+
+        List<PointInfo> turbineZt = calcTurbineDizt(start, end, 15);
+        List<PointInfo> turbineAizt = calcTurbineAizt(start, end, 15);
+        turbineZt.addAll(turbineAizt);
+        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, start, end, 15);
         //出线
-        PointInfo piCx = new PointInfo();
-        piCx.setUniformCode("AGC001");
-        piCx.setInstitutionType("booster");
-        List<PointInfo> entityCx = pointService.getByEntity(piCx);
-        Map<String, PointInfo> collectCx = entityCx.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
-        String keysCx = pointInfos2Keys(entityCx);
-
-        Map<String, PointData> statAgc = adapter.getLatest(goldenUri(), keysAgc);
-        Map<String, PointData> statCx = adapter.getLatest(goldenUri(), keysCx);
-        DateTime time5 = DateUtil.offsetMinute(DateUtil.date(), -5);
-        DoubleStatData statAgc5 = adapter.getHistoryStat(goldenUri(), keysAgc, time5.getTime(), DateUtil.date().getTime());
-        DoubleStatData statCx5 = adapter.getHistoryStat(goldenUri(), keysCx, time5.getTime(), DateUtil.date().getTime());
-
-        //AI066
-        for (PointInfo info : entityAgc) {
-            //如果场站限电状态为0
-            /*if (priorRation) {
-                if (zsgl5 >= sub.getCapacity() * 0.4) {
-                    if (zsgl / agc > 1.15) {
-                        b = true;
-                    }
+        List<PointInfo> entityCx = getEntity("AGC001", "booster");
+        getSnapDataByEntity(entityCx, start, end, 15);
+        //叶轮转速给定
+        List<PointInfo> entityYlzsgd = getEntity("AI110", "turbine");
+        getSnapDataByEntity(entityYlzsgd, start, end, 15);
+
+        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 = fsInfos.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
+                Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
+        Map<String, Map<String, List<PointData>>> glMapMap = glInfos.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> 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();
+                v3 = pdsZsglMap.values().stream().mapToDouble(pds -> pds.get(finalI).getValue()).sum();
+//                firstFs.add(new PointData(ts, v1));
+//                firstGl.add(new PointData(ts, v2));
+                firstZsgl.add(new PointData(ts, 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);
+                calcTurbineXd(ztInfo, gls, fss, ylzsgds, czxd);
+            });
+        });
+        return turbineZt;
+    }
+
+    public void calcTurbineXd(PointInfo ztInfo, List<PointData> gls, List<PointData> fss, List<PointData> ylzsgds, List<PointData> czxd) {
+        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++) {
+            double ssgl = gls.get(i).getValue();
+            double ssfs = fss.get(i).getValue();
+            double ylzsgd = ylzsgds.get(i).getValue();
+
+            if (czxd.get(i).isBooleanValue() && ssgl < capacity * 0.9) {
+                if (ssfs >= 12) {
+                    zts.get(i).setDoubleValue(8.0);
+                }
+                if (ylzsgd != 0 && ylzsgd < 17.3) {//降出力
+                    zts.get(i).setDoubleValue(8.0);
+                }
+            }
+        }
+    }
+
+    //此处加公式
+    public List<PointData> calcStationXd2(PointInfo agcInfo, List<PointData> cxSnap, List<PointData> zsglSnap) {
+        String stId = agcInfo.getStationId();
+
+        List<PointData> agcSnap = agcInfo.getPointDatas();
+        List<PointData> zsgl5s = get5Avg(zsglSnap);
+        List<PointData> agc5s = get5Avg(agcSnap);
+        List<PointData> cx5s = get5Avg(cxSnap);
+        //场站限电
+        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++) {
+            boolean isxd = false;
+            double zsgl = zsglSnap.get(i).getValue();
+            double zsgl5 = zsgl5s.get(i).getValue();
+            double agc = agcSnap.get(i).getValue();
+            double agc5 = agc5s.get(i).getValue();
+            double cxgl = cxSnap.get(i).getValue();
+            double cxgl5 = cx5s.get(i).getValue();
+
+            boolean k;   //agc一直不变
+            //第一次初始化复制实时数据到缓存
+            if (CalcCache.powerCache.get(stId) == null || CalcCache.powerCache.get(stId) != agc) {
+                CalcCache.powerCache.put(stId, agc);
+                k = false;
+            } else {
+                k = true;
+            }
+            if (agc != 0) {
+                //如果场站限电状态为不限电
+                if (zsgl5 >= agcInfo.getSpare2() * 40) {
                     if (agc5 <= cxgl5) {
-                        b = true;
+                        isxd = true;
+                    } else if (iszqxd) {
+                        if (zsgl / agc > 1.15) {
+                            isxd = true;
+                        } else if (zsgl > agc && agc5 - cxgl5 < 400) {
+                            isxd = true;
+                        }
+                    } else if (zsgl / agc >= 1.2 && agc - cxgl <= 200) {
+                        isxd = true;
                     }
-                    if (zsgl > agc && agc5 - cxgl5 < 4) {
-                        b = true;
+                } else if (k) {
+                    if (zsgl / agc >= 1.1 && agc5 - cxgl5 <= 200) {
+                        isxd = true;
                     }
                 }
+            }
+            czxd.get(i).setBooleanValue(isxd);
+            iszqxd = isxd;
+        }
+        return czxd;
+    }
+
+    private List<PointData> get5Avg(List<PointData> pointData) {
+        List<PointData> result = new ArrayList<>();
+        for (int i = 0; i < pointData.size(); i++) {
+            PointData data = new PointData();
+            data.setTs(pointData.get(i).getTs());
+            double v;
+            if (i > 4) {
+                v = (pointData.get(i).getValue() + pointData.get(i - 1).getValue() + pointData.get(i - 2).getValue() + pointData.get(i - 3).getValue() + pointData.get(i - 4).getValue()) / 5;
             } else {
+                v = pointData.get(i).getValue();
+            }
+            data.setDoubleValue(v);
+            result.add(data);
+        }
+        return result;
+    }
 
-                if (zsgl5 >= sub.getCapacity() * 0.4) {
-                    if (zsgl / agc >= 1.2 && agc - cxgl <= 2) {
-                        b = true;
-                    }
-                    if (agc5 <= cxgl5) {
-                        b = true;
-                    }
+
+    public List<PointInfo> calcTurbineAizt(Date start, Date end, int interval) {
+        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)));
+        getSnapDataByEntity(entityAiZt, start, end, interval);
+        for (PointInfo info : entityAiZt) {
+            List<PointData> peek = info.getPointDatas().stream().peek(pd -> {
+                Integer m = collectAi.get(info.getSpare()).get((int) pd.getValue());
+                if (m == null) m = 2;
+                pd.setDoubleValue(m);
+            }).collect(Collectors.toList());
+            info.setPointDatas(peek);
+        }
+        return entityAiZt;
+    }
+
+    public List<PointInfo> calcTurbineDizt(Date start, Date end, int interval) {
+        List<PointInfo> entity = 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.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
+
+        Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
+        wtUcPis.forEach((wtId, map) -> {
+            map.forEach((uc, pi) -> {
+                List<PointData> raw = adapter.getHistoryRaw(goldenUri(), pi.getPointKey(), start.getTime(), end.getTime());
+                List<PointData> ds = boolPointDatasFull(latest.get(pi.getPointKey()).isBooleanValue(), raw, start.getTime(), end.getTime(), interval);
+                pi.setPointDatas(ds);
+                ThreadUtil.sleep(20);
+            });
+            List<PointData> mx000 = map.get("MX000").getPointDatas();
+            PointData data0;
+            for (int i = 0; i < mx000.size(); i++) {
+                data0 = mx000.get(i);
+                if (data0.getValue() == 1.0) {
+                    data0.setDoubleValue(0.0);
+                    data0.setBooleanValue(false);
+                } else if (map.get("MX001").getPointDatas().get(i).getValue() == 1.0) {
+                    data0.setDoubleValue(1.0);
+                } else if (map.get("MX002").getPointDatas().get(i).getValue() == 1.0) {
+                    data0.setDoubleValue(2.0);
+                } else if (map.get("MX004").getPointDatas().get(i).getValue() == 1.0) {
+                    data0.setDoubleValue(4.0);
+                } else if (map.get("MX006").getPointDatas().get(i).getValue() == 1.0) {
+                    data0.setDoubleValue(6.0);
                 } else {
-                    if (k) {
-                        if (agc5 <= cxgl5) {
-                            b = true;
-                        }
-                        if (zsgl / agc >= 1.1 && agc5 - cxgl5 <= 2) {
-                            b = true;
-                        }
-                    }
+                    System.out.println(wtId + data0.getTs() + ":di无对应状态!");
+                    data0.setDoubleValue(2.0);
                 }
-            }*/
-        }
-    }
-
-
-    public void calcNhglZs(boolean priorRation){
-        //拟合功率(自算)
-        //实时风速
-        PointInfo piFs = new PointInfo();
-        piFs.setUniformCode("AI066");
-        piFs.setInstitutionType("turbine");
-        List<PointInfo> entityFs = pointService.getByEntity(piFs);
-        Map<String, PointInfo> collectFs = entityFs.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
-        Map<String, List<PointInfo>> collect = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
-        String keysFs = pointInfos2Keys(entityFs);
-        //设备拟合功率(自算)
-        PointInfo piFjzsgl = new PointInfo();
-        piFjzsgl.setUniformCode("ZSGL");
-        piFjzsgl.setInstitutionType("turbine");
-        List<PointInfo> entityFjzsgl = pointService.getByEntity(piFjzsgl);
-        Map<String, String> collectFjzsgl = entityFjzsgl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointKey));
-        String keysFjzsgl = pointInfos2Keys(entityFjzsgl);
-        //场站自算功率
-        PointInfo piCzzsgl = new PointInfo();
-        piCzzsgl.setUniformCode("AGC010");
-        piCzzsgl.setInstitutionType("booster");
-        List<PointInfo> entityCzzsgl = pointService.getByEntity(piCzzsgl);
-        Map<String, String> collectCzzsgl = entityCzzsgl.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getPointKey));
-        String keysCzzsgl = pointInfos2Keys(entityCzzsgl);
-
-        DateTime time = DateUtil.beginOfMinute(DateUtil.date());
-        DateTime time5 = DateUtil.offsetMinute(time, -5);
-        DoubleStatData statFs5;
-        PointData avg;
-        List<PointData> avgs = new ArrayList<>();
-        double value,v;
-        for (Map.Entry<String, List<PointInfo>> entry : collect.entrySet()) {
-            double stV=0;
-            for (PointInfo info : entry.getValue()) {
-                //todo
-                statFs5 = adapter.getHistoryStat(goldenUri(), info.getPointKey(), time5.getTime(), time.getTime());
-                if(statFs5!=null){
-                    //todo
-                    value = statFs5.getAvg().getValue();
-                    avg = new PointData();
-                    v = CalcCache.wtMcfMap.get(info.getTurbineId()).get(value);
-                    stV += v;
-                    avg.setTs(time.getTime());
-                    avg.setDoubleValue(v);
-                    avg.setTagName(collectFjzsgl.get(info.getTurbineId()));
-                    avgs.add(avg);
+            }
+            map.get("MX001").setPointDatas(null);
+            map.get("MX002").setPointDatas(null);
+            map.get("MX004").setPointDatas(null);
+            map.get("MX006").setPointDatas(null);
+        });
+        return entity0;
+    }
+
+    public PointInfo calcTurbineAizt2(PointInfo entityAiZt, Map<String, Map<Integer, Integer>> collectAi, Date start, Date end, int interval) {
+        if (entityAiZt == null) return null;
+        getSnapDataByEntity(entityAiZt, start, end, interval);
+        Map<Integer, Integer> integerMap = collectAi.get(entityAiZt.getSpare());
+        List<PointData> data = entityAiZt.getPointDatas().stream().peek(pd -> {
+            Integer m = integerMap.get((int) pd.getValue());
+            if (m == null) m = 2;
+            pd.setDoubleValue(m);
+        }).collect(Collectors.toList());
+        entityAiZt.setPointDatas(data);
+        return entityAiZt;
+    }
+
+    public PointInfo calcTurbineDizt2(Map<String, PointInfo> wtucpi, Map<String, PointData> latest, Date start, Date end, int interval) {
+        if (wtucpi == null) return null;
+        wtucpi.forEach((uc, pi) -> {
+            List<PointData> raw = adapter.getHistoryRaw(goldenUri(), pi.getPointKey(), start.getTime(), end.getTime());
+            List<PointData> ds = boolPointDatasFull(latest.get(pi.getPointKey()).isBooleanValue(), raw, start.getTime(), end.getTime(), interval);
+            pi.setPointDatas(ds);
+            ThreadUtil.sleep(20);
+        });
+        PointInfo mx000 = wtucpi.get("MX000");
+        PointData data0;
+        for (int i = 0; i < mx000.getPointDatas().size(); i++) {
+            data0 = mx000.getPointDatas().get(i);
+            if (data0.getValue() == 1.0) {
+                data0.setDoubleValue(0.0);
+                data0.setBooleanValue(false);
+            } else if (wtucpi.get("MX001").getPointDatas().get(i).getValue() == 1.0) {
+                data0.setDoubleValue(1.0);
+            } else if (wtucpi.get("MX002").getPointDatas().get(i).getValue() == 1.0) {
+                data0.setDoubleValue(2.0);
+            } else if (wtucpi.get("MX004").getPointDatas().get(i).getValue() == 1.0) {
+                data0.setDoubleValue(4.0);
+            } else if (wtucpi.get("MX006").getPointDatas().get(i).getValue() == 1.0) {
+                data0.setDoubleValue(6.0);
+            } else {
+                System.out.println(mx000.getTurbineId() + data0.getTs() + ":di无对应状态!");
+                data0.setDoubleValue(2.0);
+            }
+        }
+        wtucpi.get("MX001").setPointDatas(null);
+        wtucpi.get("MX002").setPointDatas(null);
+        wtucpi.get("MX004").setPointDatas(null);
+        wtucpi.get("MX006").setPointDatas(null);
+        return mx000;
+    }
+
+    public List<PointData> boolPointDatasFull(boolean v, List<PointData> data, long startTime, long endTime, int interval) {
+        int j = 0, m = 0;
+        List<PointData> data2 = new ArrayList<>();
+        for (long i = startTime; i < endTime; i += interval * 1000L) {
+            PointData dt = new PointData();
+            dt.setTs(i);
+            data2.add(dt);
+            //超出范围
+            if (j >= data.size() - 1) continue;
+            if (i < data.get(j).getTs()) {
+                if (m == 0) {
+                    dt.setBooleanValue(v);
+                } else {
+                    dt.setBooleanValue(data.get(j - 1).isBooleanValue());
                 }
+            } else {
+                dt.setBooleanValue(data.get(j).isBooleanValue());
+                j++;
+                m++;
             }
-            adapter.writeHistoryBatch(taosUri(), avgs);
-            PointData data = new PointData();
-            data.setTs(time.getTime());
-            data.setDoubleValue(stV);
-            data.setTagName(collectCzzsgl.get(entry.getKey()));
-            adapter.writeHistory(taosUri(), data);
         }
+        return data2;
     }
 
-    public URI goldenUri(){
-        return URI.create("http://172.16.12.103:8011/ts");
+    public void calcGlqxnh(Date start, Date end) {
+        //风速
+        List<PointInfo> entityFs = getEntity("AI066", "turbine");
+        //功率
+        List<PointInfo> entityGl = getEntity("AI114", "turbine");
+        Map<String, PointInfo> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
+
+        Map<String, EquipmentModel> map = equipmentModelService.map();
+
+        List<PointInfo> entity = 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.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
+        Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
+
+        List<PointInfo> entityAiZt = getEntity("AI422", "state");
+        Map<String, PointInfo> aiztMap = entityAiZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
+        List<StateAi> list = stateAiService.list();
+        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<>();
+        int i = 0;
+        for (PointInfo ef : entityFs) {
+            if (i < 280) {
+                i++;
+                continue;
+            }
+            String wtId = ef.getTurbineId();
+            PointInfo glInfo = glMap.get(wtId);
+            getSnapDataByEntity(ef, start, end, 60);
+            getSnapDataByEntity(glInfo, start, end, 60);
+            List<PointData> peek = ef.getPointDatas().stream().peek(pd -> pd.setDoubleValue(
+                    NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
+            ef.setPointDatas(peek);
+
+            PointInfo turbineZt = calcTurbineDizt2(wtUcPis.get(wtId), latest, start, end, 60);
+            PointInfo turbineAizt = calcTurbineAizt2(aiztMap.get(wtId), collectAi, start, end, 60);
+            Map<Double, Double> fit = new TreeMap<>();
+            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);
+                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);
+                turbineAizt.setPointDatas(null);
+            }
+            ef.setPointDatas(null);
+            glInfo.setPointDatas(null);
+            stringRedisTemplate.opsForValue().set("glqxnh:" + end.getMonth() + ":" + wtId, JSON.toJSONString(fit));
+        }
+        System.out.println("苹果天涯");
+//        stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
+    }
+
+    public Map<Double, Double> dataProcessAndFit(PointInfo fsPI, PointInfo glPI, PointInfo ztPI, Map<Double, Double> modelPowerMap, double capacity) {
+        List<PointData> fsPds = fsPI.getPointDatas();
+        List<PointData> glPds = glPI.getPointDatas();
+        List<PointData> ztPds = ztPI.getPointDatas();
+        WeightedObservedPoints points = new WeightedObservedPoints();
+        //数据过滤 0正常,1过滤掉
+        if (fsPds.size() != glPds.size() || glPds.size() != ztPds.size()) return new HashMap<>();
+
+        Double bzv;
+        for (int i = 0; i < ztPds.size(); i++) {
+            double fs = fsPds.get(i).getValue();
+            double gl = glPds.get(i).getValue();
+            // 过滤非并网值  风机状态不等于2
+            if (ztPds.get(i).getValue() != 2.0) {
+                //
+            } else if (fs < 0 || fs > 25 || gl < 0 || gl > capacity * 1.05) {// 按给定风速功率过滤
+                //
+            } else {
+                bzv = modelPowerMap.get(fs);
+                if (bzv == null || bzv == 0.0) {
+                    points.add(fs, gl);
+                    continue;
+                }
+                double k = gl / bzv;  //功率曲线偏差: 保证功率/实际功率   k:偏差百分比
+                if (k < 0.61 || k > 1.25) {
+                    //
+                } else {
+                    points.add(fs, gl);
+                }
+            }
+        }
+        Map<Double, Double> glyc = new TreeMap<>();
+        PolynomialCurveFitter fitter = PolynomialCurveFitter.create(4);
+        double[] result = fitter.fit(points.toList());
+        double min = calcMin(result);
+        System.out.println(ztPI.getTurbineId());
+        System.out.println(ztPI.getSpare());
+        System.out.println(min);
+        double[] max = calcMax(result);
+        if (min == 0 || max[0] == 0 || max[1] == 0) {
+            System.out.println();
+        }
+        System.out.println(max[0] + "," + max[1]);
+        double ru;
+        for (double i = 0; i < 25; i += 0.01) {
+            i = NumberUtil.round(i, 2).doubleValue();
+            if (i < 3) {
+                ru = 0.0;
+            } else if (i < min) {
+                ru = modelPowerMap.get(i);
+            } else if (i < max[0]) {
+                ru = calcPoly(i, result);
+            } else {
+                ru = max[1];
+            }
+            glyc.put(i, NumberUtil.round(ru, 2).doubleValue());
+        }
+        return glyc;
+    }
+
+    public double calcMin(double[] coef) {
+        double minX = 0, minY = 9000;
+        for (double x = 0; x < 8; x += 0.01) {
+            double y = calcPoly(x, coef);
+            if (y < minY) {
+                minY = y;
+                minX = x;
+            }
+        }
+        return minX;
+    }
+
+    public double[] calcMax(double[] coef) {
+        double[] a = new double[2];
+        for (double x = 8; x < 16; x += 0.01) {
+            double y = calcPoly(x, coef);
+            if (y > a[1]) {
+                a[0] = x;
+                a[1] = y;
+            }
+        }
+        return a;
+    }
+
+    public void printResult(double[] r, double accuracy) {
+
+        for (double index = 0; index < 25; index += accuracy) {
+            System.out.println("[" + index + "," + calcPoly(index, r) + "],");
+        }
+    }
+
+    public void getSnapDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end, int interval) {
+        for (PointInfo info : entity) {
+            List<PointData> snap = adapter.getHistorySnap(uri, info.getPointKey(), start.getTime(), end.getTime(), interval);
+            ThreadUtil.sleep(20);
+            info.setPointDatas(snap);
+        }
+    }
+
+    public void getSnapDataByEntity(PointInfo entity, URI uri, Date start, Date end, int interval) {
+        getSnapDataByEntity(Collections.singletonList(entity), uri, start, end, interval);
+    }
+
+    public void getSnapDataByEntity(List<PointInfo> entity, Date start, Date end, int interval) {
+        getSnapDataByEntity(entity, goldenUri(), start, end, interval);
+    }
+
+    public void getSnapDataByEntity(PointInfo entity, Date start, Date end, int interval) {
+        getSnapDataByEntity(entity, goldenUri(), start, end, interval);
+    }
+
+
+    public double calcPoly(String wtId, double value) {
+        return CalcCache.fitcoef.get(wtId).get(value);
+    }
+
+    public double calcPoly(double x, double[] factor) {
+        double y = 0;
+        for (int deg = 0; deg < factor.length; deg++) {
+            y += Math.pow(x, deg) * factor[deg];
+        }
+        return y;
     }
 }

+ 68 - 0
ruoyi-admin/src/test/java/com/ruoyi/NewTests.java

@@ -0,0 +1,68 @@
+package com.ruoyi;
+
+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.util.NumberUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.ucp.entity.*;
+import com.ruoyi.ucp.feign.AdapterApi;
+import com.ruoyi.ucp.service.*;
+import com.ruoyi.ucp.util.CalcCache;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+import java.net.URI;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+@SpringBootTest//classes = RuoYiApp.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
+@RunWith(SpringRunner.class)
+public class NewTests {
+
+    @Resource
+    private JavaFunctionJobHandler task;
+
+    @Test
+    public void test() {
+        Date date = DateUtil.date().toJdkDate();
+//        calcStationZhcydl(date);
+//        calcNhglZs(date);
+        // 创建日期范围生成器
+        DateTime start = DateUtil.parse("2024-06-26");
+//        DateTime start = DateUtil.parse("2024-05-01");
+        DateTime end = DateUtil.parse("2024-06-26");
+        DateRange range = DateUtil.range(start, end, DateField.DAY_OF_YEAR);
+        for (DateTime time : range) {
+            date=time.toJdkDate();
+            System.out.println(DateUtil.date().toString() + ":" + time.toString());
+            //安全天数
+//            calcAQTS(time.toJdkDate());
+//            task.calcLineDjlRfdl(date);
+//            //上网购网厂用电量
+//            task.calcStationSwGwCyDl(date);
+//            //计算综合厂用电量
+//            task.calcStationZhcydl(date);
+//
+//            task.calcTurbineRFDL(date);
+//            task.calcStationRfdlFj(date);
+//            task.writeReportPool(date);
+
+//            task.writeReportPool(date);
+//            task.calcTurbine5s2(date);
+
+        }
+//        task.calcGlqxnh(start,end);
+//        calcTurbineRFDL(date);
+        task.calcTurbine5s2(date);
+//        writeReportPool(date);
+
+//        task.calcStationSspjfs();
+    }
+}