Просмотр исходного кода

Merge branch 'master' of http://124.70.43.205:3000/xushili/calc-hub

# Conflicts:
#	ruoyi-admin/src/test/java/com/ruoyi/NewTests.java
#	universal-computing-platform/src/main/java/com/ruoyi/ucp/entity/LineInfoDay.java
xushili 5 месяцев назад
Родитель
Сommit
90ad731120

+ 21 - 3
ruoyi-admin/src/main/resources/FunctionTemplate.java

@@ -1,11 +1,29 @@
 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.ucp.entity.*;
 import com.ruoyi.ucp.feign.AdapterApi;
 import com.ruoyi.ucp.service.*;
-import org.springframework.data.redis.core.RedisTemplate;
+import com.ruoyi.ucp.util.CalcCache;
+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;
+import java.util.*;
+import java.util.function.Function;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
 
 public class JavaFunctionJobHandler extends IJobHandler {
 
@@ -22,7 +40,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
     @Resource
     private IStateAiService stateAiService;
     @Resource
-    private RedisTemplate redisTemplate;
+    private StringRedisTemplate stringRedisTemplate;
     @Resource
     private IEquipmentModelService equipmentModelService;
     @Resource
@@ -44,5 +62,5 @@ public class JavaFunctionJobHandler extends IJobHandler {
     public void setFunctionHandler(IJobHandler jobHandler) {
 
     }
-    //此处加公式
+//此处加公式
 }

+ 795 - 84
ruoyi-admin/src/test/java/com/ruoyi/JavaFunctionJobHandler.java

@@ -1,5 +1,6 @@
 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;
@@ -13,18 +14,24 @@ 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;
 
 import javax.annotation.Resource;
 import java.net.URI;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
 @Service
 public class JavaFunctionJobHandler extends IJobHandler {
 
+/*    @Resource
+    private PointInfo pointInfo;*/
+
     @Resource
     private AdapterApi adapter;
     @Resource
@@ -322,61 +329,6 @@ public class JavaFunctionJobHandler extends IJobHandler {
         stationInfoHourService.saveOrUpdateBatch(byHours);
     }
 
-    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);
-
-        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());
-
-        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);
-        }
-        reportIndicatorPoolService.saveOrUpdateBatch(poolList);
-    }
 
     public void calcLineDjlRfdl(Date date) {
         //date当天零点
@@ -1044,12 +996,7 @@ public class JavaFunctionJobHandler extends IJobHandler {
                 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);
@@ -1075,13 +1022,15 @@ public class JavaFunctionJobHandler extends IJobHandler {
             }
             ef.setPointDatas(null);
             glInfo.setPointDatas(null);
-            stringRedisTemplate.opsForValue().set("glqxnh:" + end.getMonth() + ":" + wtId, JSON.toJSONString(fit));
+            stringRedisTemplate.opsForValue().set("edfs:" + 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) {
+        System.out.println("开始拟合");
         List<PointData> fsPds = fsPI.getPointDatas();
         List<PointData> glPds = glPI.getPointDatas();
         List<PointData> ztPds = ztPI.getPointDatas();
@@ -1114,30 +1063,40 @@ public class JavaFunctionJobHandler extends IJobHandler {
         }
         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];
+        try {
+            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());
             }
-            glyc.put(i, NumberUtil.round(ru, 2).doubleValue());
+
+        } catch (Exception e) {
+            System.out.println(ztPI.getTurbineId());
+            System.out.println(ztPI.getSpare());
+            System.out.println(e.getMessage());
         }
+        System.out.println("拟合完成" + glyc);
         return glyc;
     }
 
@@ -1204,4 +1163,756 @@ public class JavaFunctionJobHandler extends IJobHandler {
         }
         return y;
     }
-}
+
+
+    //切入切出风速
+
+    public void cutInWindSpeed() {
+        //date当天零点
+        DateTime timeNow00 = DateUtil.beginOfDay(new Date());
+        //date昨天零点
+        DateTime timeBegin00 = DateUtil.offsetDay(timeNow00, -1);
+        //上个月
+        DateTime timeBegin2 = DateUtil.offsetMonth(timeBegin00, -1);
+        //上个月第一天
+        DateTime timeBegin1 = DateUtil.beginOfMonth(timeBegin2);
+        //上个月最后一天
+        DateTime timeEnd2 = DateUtil.endOfMonth(timeBegin2);
+        //上个月天数
+        int days = (int) DateUtil.betweenDay(timeBegin1, timeEnd2, false);
+        //遍历天数
+        for (int i = 1; i <= days; i++) {
+            DateTime timeNow = DateUtil.offsetDay(timeBegin1, i);
+            DateTime timeBegin = DateUtil.offsetDay(timeBegin1, i - 1);
+
+
+            List<PointInfo> turbineZt = calcTurbineAizt(timeBegin, timeNow, 60);
+            List<PointInfo> turbineZtDI = calcTurbineDizt(timeBegin, timeNow, 60);
+            turbineZt.addAll(turbineZtDI);
+
+            //所有风机的风速测点
+            QueryWrapper<PointInfo> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("uniform_code", "AI066");
+
+            List<PointInfo> pointInfos = getEntity("AI066", "turbine");
+//        List<PointInfo> pointInfos = pointInfo.selectList(queryWrapper);
+
+            //定义切入风速map集合
+            ConcurrentHashMap<String, ConcurrentHashMap<String, Double>> mapIn = new ConcurrentHashMap<>();
+
+            //定义切出风速集合
+            ConcurrentHashMap<String, ConcurrentHashMap<String, Double>> mapOut = new ConcurrentHashMap<>();
+
+
+            //插入集合
+            List<TurbineInfoDay> interest = new ArrayList<>();
+            //更新集合
+            List<TurbineInfoDay> update = new ArrayList<>();
+            //遍历每台风机,取出每台风机的pointDatas
+            for (PointInfo turbine : turbineZt) {
+
+                mapIn.put(turbine.getTurbineId(), new ConcurrentHashMap<>());
+                mapOut.put(turbine.getTurbineId(), new ConcurrentHashMap<>());
+
+                List<PointData> pointDatas = turbine.getPointDatas();
+
+                //风速测点key
+                String windSpeedKey = null;
+
+
+                //遍历pointInfos,找出pointData1的id和pointInfos中相等的,取出pointInfo的pointKey
+                for (PointInfo info : pointInfos) {
+                    if (Objects.equals(turbine.getTurbineId(), info.getTurbineId())) {
+                        windSpeedKey = info.getPointKey();
+                    }
+                }
+
+
+                //遍历pointDatas,取出当前状态和后一个状态
+                for (int k = 1; k < pointDatas.size(); k++) {
+                    PointData pointData1 = pointDatas.get(k - 1);
+                    PointData pointData2 = pointDatas.get(k);
+                    double value1 = pointData1.getValue();
+                    double value2 = pointData2.getValue();
+                    //切入时间
+                    long ts1;
+                    //切出时间
+                    long ts2;
+
+                    //如果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);
+                        //切入时间前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);
+
+                        //存入map集合,外层key为turbineId,内层key为ts1,value为平均切入风速
+
+                        mapIn.get(turbine.getTurbineId()).put(String.valueOf(ts1), avgCutInWindSpeed);
+
+                    }
+
+                    //切出
+                    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);
+                        //切出时间前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);
+
+                        //存入map集合,外层key为turbineId,内层key为ts2,value为平均切出风速
+
+                        mapOut.get(turbine.getTurbineId()).put(String.valueOf(ts2), avgCutOutWindSpeed);
+                    }
+
+                }
+                //遍历map集合,取出每个风机的所有切入风速,算一个平均值
+                ConcurrentHashMap<String, Double> mapTurbineValues = mapIn.get(turbine.getTurbineId());
+                //平均切入风速
+                double avgCutInWindSpeed = 0;
+                if (mapTurbineValues != null) {
+                    AtomicReference<Double> sum = new AtomicReference<>(0.0);
+                    //遍历mapTurbineValues,V大于5的舍弃,剩余算平均值
+                    for (String key : mapTurbineValues.keySet()) {
+                        if (mapTurbineValues.get(key) > 5) {
+                            mapTurbineValues.remove(key);
+                        }
+                    }
+                    mapTurbineValues.forEach((k1, v) -> {
+                        sum.updateAndGet(v1 -> v1 + v);
+                    });
+
+                    //如果值为空则置0
+                    if (sum.get() == 0) {
+                        avgCutInWindSpeed = 0;
+                    } else {
+                        avgCutInWindSpeed = sum.get() / mapTurbineValues.size();
+                    }
+                    System.out.println(turbine.getTurbineId() + "切入平均风速" + avgCutInWindSpeed + "时间" + timeBegin);
+                }
+
+                //遍历map集合,取出每个风机的所有切出风速,算一个平均值
+                ConcurrentHashMap<String, Double> mapTurbineValues2 = mapOut.get(turbine.getTurbineId());
+
+                double avgCutOutWindSpeed;
+                if (mapTurbineValues2 != null) {
+                    AtomicReference<Double> sum = new AtomicReference<>(0.0);
+
+                    for (String key : mapTurbineValues2.keySet()) {
+                        if (mapTurbineValues2.get(key) > 5) {
+                            mapTurbineValues2.remove(key);
+                        }
+                    }
+                    mapTurbineValues2.forEach((k2, v) -> {
+                        sum.updateAndGet(v1 -> v1 + v);
+                    });
+
+                    if (sum.get() == 0) {
+                        avgCutOutWindSpeed = 0;
+                    } else {
+                        avgCutOutWindSpeed = sum.get() / mapTurbineValues2.size();
+                    }
+                    System.out.println(turbine.getTurbineId() + "切出平均风速" + avgCutOutWindSpeed + "时间" + timeBegin);
+                }
+
+                //存入数据库
+                String turbineId = turbine.getTurbineId();
+                Date jdkDate = timeBegin.toJdkDate();
+                System.out.println(turbineId + " " + jdkDate);
+                QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
+                turbineInfoDayQueryWrapper.eq("turbine_id", turbine.getTurbineId());
+                turbineInfoDayQueryWrapper.eq("record_date", timeBegin.toJdkDate());
+                TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
+                System.out.println(one);
+                if (one == null) {
+                    TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
+                    turbineInfoDay.setTurbineId(turbine.getTurbineId());
+                    turbineInfoDay.setRecordDate(timeBegin.toJdkDate());
+                    turbineInfoDay.setXfqrfs(avgCutInWindSpeed);
+                    System.out.println(turbineInfoDay);
+
+                    interest.add(turbineInfoDay);
+//                turbineInfoDayService.save(turbineInfoDay);
+                } else {
+                    one.setXfqrfs(avgCutInWindSpeed);
+                    System.out.println(one);
+//                turbineInfoDayService.updateById(one);
+                    update.add(one);
+                }
+
+            }
+
+            //        //批量插入
+//        turbineInfoDayService.saveBatch(interest);
+//        //批量更新
+//        turbineInfoDayService.updateBatchById(update);
+//        //批量插入或更新
+            turbineInfoDayService.saveOrUpdateBatch(interest);
+            turbineInfoDayService.saveOrUpdateBatch(update);
+        }
+    }
+
+    //算额定风速
+    public void calcGlqxnh_edfs() {
+        //date当天零点
+        DateTime timeNow00 = DateUtil.beginOfDay(new Date());
+        //date昨天零点
+        DateTime timeBegin00 = DateUtil.offsetDay(timeNow00, -1);
+        //上个月
+        DateTime timeBegin2 = DateUtil.offsetMonth(timeBegin00, -1);
+        //上个月第一天
+        DateTime timeBegin1 = DateUtil.beginOfMonth(timeBegin2);
+        //上个月最后一天
+        DateTime timeEnd2 = DateUtil.endOfMonth(timeBegin2);
+        //上个月天数
+        int days = (int) DateUtil.betweenDay(timeBegin1, timeEnd2, false);
+        //遍历天数
+        for (int i = 1; i <= days; i++) {
+            DateTime end = DateUtil.offsetDay(timeBegin1, i);
+            DateTime start = DateUtil.offsetDay(timeBegin1, i - 1);
+
+            //风速
+            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<>();
+
+            //插入集合
+            List<TurbineInfoDay> interest = new ArrayList<>();
+            //更新集合
+            List<TurbineInfoDay> update = new ArrayList<>();
+
+
+            for (PointInfo ef : entityFs) {
+                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);
+
+                try {
+                    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<>();
+                    double capacity = 2000;
+                    if (turbineZt != null) {
+                        System.out.println("数据处理拟合");
+                        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) {
+                        System.out.println("数据处理拟合");
+                        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);
+
+                    //存redis
+//            stringRedisTemplate.opsForValue().set("glqxnh:" + end.getMonth() + ":" + wtId, JSON.toJSONString(fit));
+
+                    System.out.println("拟合曲线的大小" + fit.size() + ":" + wtId);
+
+                    //符合条件的风速和
+                    List<Double> listDouble = new ArrayList<>();
+                    //遍历fit集合,取出值与capacity相等的key
+                    if (!fit.isEmpty()) {
+                        for (double key : fit.keySet()) {
+                            Double v = fit.get(key);
+                            //如果v-capacity的值小于10大于-10,则把key加入listDouble
+                            if ((Math.abs(v - capacity) <= 10) && Math.abs(v - capacity) >= -10) {
+                                listDouble.add(key);
+                            }
+                        }
+                    }
+                    //取出listDouble的值求平均值
+                    double agValue = 0;
+                    if (!listDouble.isEmpty()) {
+                        for (Double aDouble : listDouble) {
+                            agValue += aDouble;
+                        }
+                        agValue = agValue / listDouble.size();
+                    }
+                    System.out.println("wtId:" + wtId + "agValue平均额定风速:" + agValue);
+
+
+                    //存入数据库
+                    System.out.println(wtId + " " + start);
+                    QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
+                    turbineInfoDayQueryWrapper.eq("turbine_id", wtId);
+                    turbineInfoDayQueryWrapper.eq("record_date", start);
+                    TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
+                    System.out.println(one);
+                    if (one == null) {
+                        TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
+                        turbineInfoDay.setTurbineId(wtId);
+                        turbineInfoDay.setRecordDate(start);
+                        turbineInfoDay.setEdfs(agValue);
+                        System.out.println(turbineInfoDay);
+//                    turbineInfoDayService.save(turbineInfoDay);
+                        interest.add(turbineInfoDay);
+                    } else {
+                        one.setEdfs(agValue);
+                        System.out.println(one);
+//                    turbineInfoDayService.updateById(one);
+                        update.add(one);
+                    }
+
+                } catch (Exception e) {
+                    System.out.println(wtId + " " + start);
+                }
+
+
+            }
+
+
+            //        //批量插入
+//        turbineInfoDayService.saveBatch(interest);
+//        //批量更新
+//        turbineInfoDayService.updateBatchById(update);
+//        //批量插入或更新
+            turbineInfoDayService.saveOrUpdateBatch(interest);
+            turbineInfoDayService.saveOrUpdateBatch(update);
+        }
+
+
+//        stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
+    }
+
+    //环境温度
+    public void ambientTemperature() {
+        //date当天零点
+        DateTime timeNow = DateUtil.beginOfDay(new Date());
+        //date昨天零点
+        DateTime timeBegin = DateUtil.offsetDay(timeNow, -1);
+
+
+        //所有风机的温度
+        QueryWrapper<PointInfo> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("uniform_code", "AI072");
+
+        List<PointInfo> pointInfos = getEntity("AI072", "turbine");
+
+        //插入集合
+        List<TurbineInfoDay> interest = new ArrayList<>();
+        //更新集合
+        List<TurbineInfoDay> update = new ArrayList<>();
+
+
+        //遍历pointInfos
+        for (PointInfo turbine : pointInfos) {
+            List<PointData> pointDatas = adapter.getHistorySnap(goldenUri(), turbine.getPointKey(), timeBegin.getTime(), timeNow.getTime(), 10);
+            //遍历pointDatas,取出数据算平均值
+            double avgCutInWindSpeed = 0;
+            for (PointData pointData : pointDatas) {
+                avgCutInWindSpeed += pointData.getValue();
+            }
+            avgCutInWindSpeed /= pointDatas.size();
+
+            //存入数据库
+            String turbineId = turbine.getTurbineId();
+            Date jdkDate = timeBegin.toJdkDate();
+            System.out.println(turbineId + " " + jdkDate);
+            QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
+            turbineInfoDayQueryWrapper.eq("turbine_id", turbine.getTurbineId());
+            turbineInfoDayQueryWrapper.eq("record_date", timeBegin.toJdkDate());
+            TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
+            System.out.println(one);
+            if (one == null) {
+                TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
+                turbineInfoDay.setTurbineId(turbine.getTurbineId());
+                turbineInfoDay.setRecordDate(timeBegin.toJdkDate());
+                turbineInfoDay.setHjwd(avgCutInWindSpeed);
+                System.out.println(turbineInfoDay);
+                interest.add(turbineInfoDay);
+//                turbineInfoDayService.save(turbineInfoDay);
+            } else {
+                one.setHjwd(avgCutInWindSpeed);
+                System.out.println(one);
+                update.add(one);
+//                turbineInfoDayService.updateById(one);
+            }
+
+        }
+//        //批量插入
+//        turbineInfoDayService.saveBatch(interest);
+//        //批量更新
+//        turbineInfoDayService.updateBatchById(update);
+//        //批量插入或更新
+        turbineInfoDayService.saveOrUpdateBatch(interest);
+        turbineInfoDayService.saveOrUpdateBatch(update);
+
+
+    }
+
+
+    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);
+
+        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);
+
+        QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
+        wrapperrp.eq("record_date", time0)
+                .in("foreign_key_id", days.stream().map(StationInfoDay::getStationId).collect(Collectors.toList()));
+        List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
+
+        if (!pools.isEmpty()) {
+            StationInfoDay day, month, year;
+            List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
+            for (ProEconReportIndicatorPool pool : pools) {
+                String stationId = pool.getForeignKeyId();
+                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);
+            }
+            reportIndicatorPoolService.saveOrUpdateBatch(poolList);
+        } else {
+
+            List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
+            for (StationInfoDay day : days) {
+                ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
+                pool.setRecordDate(time0.toLocalDateTime().toLocalDate());
+                pool.setForeignKeyId(day.getStationId());
+                poolList.add(pool);
+            }
+            reportIndicatorPoolService.saveOrUpdateBatch(poolList);
+
+        }
+
+
+    }
+
+    public void writeReportPoolProject(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);
+
+        QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
+        wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id")
+                .eq("record_date", time0)
+                .groupBy("project_id");
+        List<LineInfoDay> days = lineInfoDayService.list(wrapper);
+        Map<String, LineInfoDay> dayMap = days.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
+        wrapper = new QueryWrapper<>();
+        wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id")
+                .between("record_date", beginOfMonth, time0)
+                .groupBy("project_id");
+        List<LineInfoDay> monthDays = lineInfoDayService.list(wrapper);
+        Map<String, LineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
+        wrapper = new QueryWrapper<>();
+        wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id")
+                .between("record_date", beginOfYear, time0)
+                .groupBy("project_id");
+        List<LineInfoDay> yearDays = lineInfoDayService.list(wrapper);
+        Map<String, LineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
+
+        QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
+        wrapperrp.eq("record_date", time0).last("and foreign_key_id = project_id");
+        List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
+
+
+        QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
+        wrapperrp2.eq("record_date", time0)
+                .in("foreign_key_id", days.stream().map(LineInfoDay::getProjectId).collect(Collectors.toList()));
+        List<ProEconReportIndicatorPool> pools2 = reportIndicatorPoolService.list(wrapperrp2);
+
+        if (!pools2.isEmpty()) {
+            LineInfoDay day, month, year;
+            List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
+            String projectId;
+            for (ProEconReportIndicatorPool pool : pools2) {
+                projectId = pool.getForeignKeyId();
+                day = dayMap.get(projectId);
+                pool.setRfdldb(day.getRfdl().doubleValue());
+                pool.setRswdldb(day.getSwdl());
+                pool.setRgwgwdldb(day.getGwdl());
+                pool.setRfdcydldb(day.getCydl());
+                pool.setRzhcydldb(day.getRfdl().doubleValue() + day.getGwdl() - day.getSwdl());
+                month = monthMap.get(projectId);
+                pool.setYfdldb(month.getRfdl().doubleValue());
+                pool.setYswdldb(month.getSwdl());
+                pool.setYgwgwdldb(month.getGwdl());
+                pool.setYfdcydldb(month.getCydl());
+                pool.setRzhcydldb(month.getRfdl().doubleValue() + month.getGwdl() - month.getSwdl());
+                year = yearMap.get(projectId);
+                pool.setNfdldb(year.getRfdl().doubleValue());
+                pool.setNswdldb(year.getSwdl());
+                pool.setNgwgwdldb(year.getGwdl());
+                pool.setNfdcydldb(year.getCydl());
+                pool.setRzhcydldb(year.getRfdl().doubleValue() + year.getGwdl() - year.getSwdl());
+                poolList.add(pool);
+            }
+            reportIndicatorPoolService.saveOrUpdateBatch(poolList);
+        } else {
+
+            List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
+            for (LineInfoDay day : days) {
+                ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
+                pool.setRecordDate(time0.toLocalDateTime().toLocalDate());
+                pool.setForeignKeyId(day.getProjectId());
+                poolList.add(pool);
+            }
+            reportIndicatorPoolService.saveOrUpdateBatch(poolList);
+
+        }
+    }
+
+    public void writeReportPoolPjfs(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);
+
+        QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
+        wrapper.select("avg(pjfs) pjfs,project_id")
+                .eq("record_date", time0)
+                .groupBy("project_id");
+        List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
+        Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
+        wrapper = new QueryWrapper<>();
+        wrapper.select("avg(pjfs) pjfs,project_id")
+                .between("record_date", beginOfMonth, time0)
+                .groupBy("project_id");
+        List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
+        Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
+        wrapper = new QueryWrapper<>();
+        wrapper.select("avg(pjfs) pjfs,project_id")
+                .between("record_date", beginOfYear, time0)
+                .groupBy("project_id");
+        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)
+                .in("foreign_key_id", days.stream().map(TurbineInfoDay::getProjectId).collect(Collectors.toList()));
+        List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
+
+
+        ProEconReportIndicatorPool GSPJFS = new ProEconReportIndicatorPool();
+        GSPJFS.setRecordDate(time0.toLocalDateTime().toLocalDate());
+        GSPJFS.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
+        GSPJFS.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
+        reportIndicatorPoolService.save(GSPJFS);
+
+
+        wrapperrp = new QueryWrapper<>();
+        wrapperrp.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
+        List<ProEconReportIndicatorPool> pools2 = reportIndicatorPoolService.list(wrapperrp);
+
+        TurbineInfoDay day, month, year;
+        String projectId;
+
+        if (!pools.isEmpty()) {
+            for (ProEconReportIndicatorPool pool : pools) {
+                projectId = pool.getForeignKeyId();
+                day = dayMap.get(projectId);
+                pool.setRpjfs(day.getPjfs());
+                month = monthMap.get(projectId);
+                pool.setYpjfs(month.getPjfs());
+                year = yearMap.get(projectId);
+                pool.setNpjfs(year.getPjfs());
+            }
+            double v1 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getRpjfs).average().orElse(0);
+            double v2 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getYpjfs).average().orElse(0);
+            double v3 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getNpjfs).average().orElse(0);
+            if (CollUtil.isNotEmpty(pools2)) {
+                pools2.get(0).setRpjfs(v1);
+                pools2.get(0).setYpjfs(v2);
+                pools2.get(0).setNpjfs(v3);
+                reportIndicatorPoolService.saveOrUpdateBatch(pools2);
+            }
+            reportIndicatorPoolService.saveOrUpdateBatch(pools);
+        } else {
+            List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
+            for (TurbineInfoDay day2 : days) {
+                ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
+                pool.setRecordDate(time0.toLocalDateTime().toLocalDate());
+                pool.setForeignKeyId(day2.getProjectId());
+                poolList.add(pool);
+            }
+            reportIndicatorPoolService.saveOrUpdateBatch(poolList);
+
+        }
+
+    }
+
+    public void gongsizhibiao() {
+        //date当天零点
+        DateTime time = DateUtil.beginOfDay(new Date());
+        //date昨天零点
+        DateTime time0 = DateUtil.offsetDay(time, -1);
+        DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
+        DateTime beginOfYear = DateUtil.beginOfYear(time0);
+
+        QueryWrapper<ProEconReportIndicatorPool> wrapper = new QueryWrapper<>();
+        wrapper.eq("record_date", time0)
+                //包含"STA"
+                .like("foreign_key_id", "_STA");
+        List<ProEconReportIndicatorPool> list = reportIndicatorPoolService.list(wrapper);
+        //遍历list,累加指标RFDL
+
+        //公司指标,日发电量
+        double rfdl = 0;
+        //公司指标,日上网电量
+        double swdl = 0;
+        //公司指标,日购网电量
+        double gwdl = 0;
+        //公司指标,日综合厂用电量
+        double zhcydl = 0;
+
+        //公司指标,月发电量
+        double yfdl = 0;
+        //公司指标,月上网电量
+        double yswdl = 0;
+        //公司指标,月购网电量
+        double ygwdl = 0;
+        //公司指标,月综合厂用电量
+        double yzhcydl = 0;
+
+        //公司指标,年发电量
+        double nfdl = 0;
+        //公司指标,年上网电量
+        double nswdl = 0;
+        //公司指标,年购网电量
+        double ngwdl = 0;
+        //公司指标,年综合厂用电量
+        double nzhcydl = 0;
+
+
+
+        for (ProEconReportIndicatorPool pool : list) {
+            rfdl += pool.getRfdldb();
+            swdl += pool.getRswdldb();
+            gwdl += pool.getRgwgwdldb();
+            zhcydl += pool.getRzhcydldb();
+            yfdl += pool.getYfdldb();
+            yswdl += pool.getYswdldb();
+            ygwdl += pool.getYgwgwdldb();
+            yzhcydl += pool.getYzhcydldb();
+            nfdl += pool.getNfdldb();
+            nswdl += pool.getNswdldb();
+            ngwdl += pool.getNgwgwdldb();
+            nzhcydl += pool.getNzhcydldb();
+        }
+
+        QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
+        wrapperrp2.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
+        ProEconReportIndicatorPool GSZB = reportIndicatorPoolService.getOne(wrapperrp2);
+        //公司指标集合
+        GSZB.setRfdldb(rfdl);
+        GSZB.setRswdldb(swdl);
+        GSZB.setRgwgwdldb(gwdl);
+        GSZB.setRzhcydldb(zhcydl);
+        GSZB.setYfdldb(yfdl);
+        GSZB.setYswdldb(yswdl);
+        GSZB.setYgwgwdldb(ygwdl);
+        GSZB.setYzhcydldb(yzhcydl);
+        GSZB.setNfdldb(nfdl);
+        GSZB.setNswdldb(nswdl);
+        GSZB.setNgwgwdldb(ngwdl);
+        GSZB.setNzhcydldb(nzhcydl);
+
+        reportIndicatorPoolService.saveOrUpdate(GSZB);
+
+
+
+    }
+
+
+}
+
+
+
+
+
+

+ 32 - 59
ruoyi-admin/src/test/java/com/ruoyi/NewTests.java

@@ -4,17 +4,22 @@ 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 com.ruoyi.ucp.entity.PointData;
-import com.ruoyi.ucp.entity.PointInfo;
+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.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+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
@@ -27,69 +32,37 @@ public class NewTests {
     @Test
     public void test() {
         Date date = DateUtil.date().toJdkDate();
-        //        calcStationZhcydl(date);
-        //        calcNhglZs(date);
+//        calcStationZhcydl(date);
+//        calcNhglZs(date);
         // 创建日期范围生成器
-        //        DateTime start = DateUtil.parse("2024-01-05");
-        DateTime start = DateUtil.parse("2024-05-01");
-        DateTime end = DateUtil.parse("2024-05-31");
+        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();
+            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.calcLineDjlRfdl(date);
-            task.calcStationRfdlFj(date);
-            //            task.writeReportPool(date);
+//            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.writeReportPool(date);
+//            task.calcTurbine5s2(date);
 
         }
-        //        calcTurbineRFDL(date);
+        task.calcGlqxnh(start,end);
+//        calcTurbineRFDL(date);
         task.calcTurbine5s2(date);
-        //        writeReportPool(date);
-
-    }
-
-    public static void main(String[] args) {
-        PointInfo info = new PointInfo();
-        PointData data = new PointData();
-        data.setTs(System.currentTimeMillis());
-        data.setDoubleValue(1.0);
-        List<PointData> datas = new ArrayList<>();
-        datas.add(data);
-        info.setPointDatas(datas);
-        List<PointData> pointDatas = info.getPointDatas();
-
-        PointInfo info2 = new PointInfo();
-        PointData data2 = new PointData();
-        data2.setTs(System.currentTimeMillis());
-        data2.setDoubleValue(2.0);
-        List<PointData> datas2 = new ArrayList<>();
-        datas2.add(data2);
-        info2.setPointDatas(datas2);
-        List<PointData> pointDatas2 = info2.getPointDatas();
-        List<PointInfo> pis= new ArrayList<>();
-        pis.add(info);
-        pis.add(info2);
-
-        List<List<PointData>> collect = pis.stream().map(pi->{
-            List<PointData> pd = pi.getPointDatas();
-            for (PointData pd2 : pd) {
-                pd2.setDoubleValue(33);
-            }
-            return pi.getPointDatas();
-        }).collect(Collectors.toList());
-        List<PointInfo> collect1 = pis.stream().peek(PointInfo::getPointDatas).collect(Collectors.toList());
-        System.out.println();
+//        writeReportPool(date);
 
+//        task.calcStationSspjfs();
     }
 }

+ 142 - 0
ruoyi-admin/src/test/java/com/ruoyi/Test.java

@@ -0,0 +1,142 @@
+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.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.ITurbineInfoDayService;
+import com.ruoyi.ucp.util.CalcCache;
+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.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * Author: malijun
+ * Data  : 2024: 07: 03
+ **/
+@SpringBootTest
+@RunWith(SpringRunner.class)
+public class Test {
+
+    @Resource
+    private AdapterApi adapter;
+    @Resource
+    private JavaFunctionJobHandler javaFunctionJobHandler;
+    @Resource
+    private ITurbineInfoDayService turbineInfoDayService;
+
+
+    @org.junit.Test
+    public void test() {
+        javaFunctionJobHandler.cutInWindSpeed();
+        javaFunctionJobHandler.calcGlqxnh_edfs();
+    }
+
+    //平均温度
+    @org.junit.Test
+    public void ambientTemperature() {
+        //date当天零点
+        DateTime timeNow00 = DateUtil.beginOfDay(new Date());
+        //date昨天零点
+        DateTime timeBegin00 = DateUtil.offsetDay(timeNow00, -1);
+        //上个月
+        DateTime timeBegin2 = DateUtil.offsetMonth(timeBegin00, -1);
+        //上个月第一天
+        DateTime timeBegin1 = DateUtil.beginOfMonth(timeBegin2);
+        //上个月最后一天
+        DateTime timeEnd2 = DateUtil.endOfMonth(timeBegin2);
+        //上个月天数
+        int days = (int) DateUtil.betweenDay(timeBegin1, timeEnd2, false);
+        //遍历天数
+        for (int i = 1; i <= days; i++) {
+            DateTime timeNow = DateUtil.offsetDay(timeBegin1, i);
+            DateTime timeBegin = DateUtil.offsetDay(timeBegin1, i - 1);
+
+
+            //所有风机的温度
+            QueryWrapper<PointInfo> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("uniform_code", "AI072");
+
+            List<PointInfo> pointInfos = javaFunctionJobHandler.getEntity("AI072", "turbine");
+
+            //插入集合
+            List<TurbineInfoDay> interest = new ArrayList<>();
+            //更新集合
+            List<TurbineInfoDay> update = new ArrayList<>();
+
+
+            //遍历pointInfos
+            for (PointInfo turbine : pointInfos) {
+                List<PointData> pointDatas = adapter.getHistorySnap(javaFunctionJobHandler.goldenUri(), turbine.getPointKey(), timeBegin.getTime(), timeNow.getTime(), 10);
+                //遍历pointDatas,取出数据算平均值
+                double avgCutInWindSpeed = 0;
+                for (PointData pointData : pointDatas) {
+                    avgCutInWindSpeed += pointData.getValue();
+                }
+                avgCutInWindSpeed /= pointDatas.size();
+
+                //存入数据库
+                String turbineId = turbine.getTurbineId();
+                Date jdkDate = timeBegin.toJdkDate();
+                System.out.println(turbineId + " " + jdkDate);
+                QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
+                turbineInfoDayQueryWrapper.eq("turbine_id", turbine.getTurbineId());
+                turbineInfoDayQueryWrapper.eq("record_date", timeBegin.toJdkDate());
+                TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
+                System.out.println(one);
+                if (one == null) {
+                    TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
+                    turbineInfoDay.setTurbineId(turbine.getTurbineId());
+                    turbineInfoDay.setRecordDate(timeBegin.toJdkDate());
+                    turbineInfoDay.setHjwd(avgCutInWindSpeed);
+                    System.out.println(turbineInfoDay);
+                    interest.add(turbineInfoDay);
+//                turbineInfoDayService.save(turbineInfoDay);
+                } else {
+                    one.setHjwd(avgCutInWindSpeed);
+                    System.out.println(one);
+                    update.add(one);
+//                turbineInfoDayService.updateById(one);
+                }
+
+            }
+//        //批量插入
+//        turbineInfoDayService.saveBatch(interest);
+//        //批量更新
+//        turbineInfoDayService.updateBatchById(update);
+//        //批量插入或更新
+        turbineInfoDayService.saveOrUpdateBatch(interest);
+        turbineInfoDayService.saveOrUpdateBatch(update);
+        }
+
+    }
+
+
+    @org.junit.Test
+    public void test1() {
+        Date date = DateUtil.date().toJdkDate();
+        javaFunctionJobHandler.writeReportPool(date);
+        javaFunctionJobHandler.writeReportPoolProject(date);
+        javaFunctionJobHandler.writeReportPoolPjfs(date);
+
+    }
+
+    @org.junit.Test
+    public void test2() {
+        javaFunctionJobHandler.gongsizhibiao();
+
+    }
+
+
+}
+

+ 0 - 208
ruoyi-admin/src/test/java/com/ruoyi/ZhiBiaoCalculation.java

@@ -1,208 +0,0 @@
-package com.ruoyi;
-
-import cn.hutool.core.date.DateTime;
-import cn.hutool.core.date.DateUtil;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.ruoyi.ucp.entity.PointData;
-import com.ruoyi.ucp.entity.PointInfo;
-import com.ruoyi.ucp.entity.TurbineInfoDay;
-import com.ruoyi.ucp.feign.AdapterApi;
-import com.ruoyi.ucp.service.impl.TurbineInfoDayServiceImpl;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit4.SpringRunner;
-
-import javax.annotation.Resource;
-import java.util.*;
-import java.util.concurrent.atomic.AtomicReference;
-
-/**
- * Author: malijun
- * Data  : 2024: 07: 01
- * 指标计算
- **/
-
-@SpringBootTest
-@RunWith(SpringRunner.class)
-public class ZhiBiaoCalculation {
-
-    @Autowired
-    private JavaFunctionJobHandler javaFunctionJobHandler;
-
-    @Resource
-    private PointInfo pointInfo;
-
-    @Resource
-    private AdapterApi adapter;
-
-    @Resource
-    private TurbineInfoDayServiceImpl turbineInfoDayService;
-
-
-    //切入切出风速
-    @Test
-    public void cutInWindSpeed() {
-        //date当天零点
-        DateTime timeNow = DateUtil.beginOfDay(new Date());
-        //date昨天零点
-        DateTime timeBegin = DateUtil.offsetDay(timeNow, -1);
-        List<PointInfo> turbineZt = javaFunctionJobHandler.calcTurbineAizt(timeBegin, timeNow, 60);
-        List<PointInfo> turbineZtDI = javaFunctionJobHandler.calcTurbineDizt(timeBegin, timeNow, 60);
-        turbineZt.addAll(turbineZtDI);
-
-        //所有风机的风速测点
-        QueryWrapper<PointInfo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("uniform_code", "AI066");
-        List<PointInfo> pointInfos = pointInfo.selectList(queryWrapper);
-
-        //定义切入风速map集合
-        HashMap<String, HashMap<String, Double>> mapIn = new HashMap<>();
-        //定义切出风速集合
-        HashMap<String, HashMap<String, Double>> mapOut = new HashMap<>();
-
-
-        //遍历每台风机,取出每台风机的pointDatas
-        for (PointInfo turbine : turbineZt) {
-
-            List<PointData> pointDatas = turbine.getPointDatas();
-
-            //风速测点key
-            String windSpeedKey = null;
-
-            //平均切入风速
-            double avgCutInWindSpeedOne = 0;
-
-
-            //遍历pointInfos,找出pointData1的id和pointInfos中相等的,取出pointInfo的pointKey
-            for (PointInfo info : pointInfos) {
-                if (Objects.equals(turbine.getTurbineId(), info.getTurbineId())) {
-                    windSpeedKey = info.getPointKey();
-                }
-            }
-
-
-            //遍历pointDatas,取出当前状态和后一个状态
-            for (int k = 1; k < pointDatas.size(); k++) {
-                PointData pointData1 = pointDatas.get(k - 1);
-                PointData pointData2 = pointDatas.get(k);
-                double value1 = pointData1.getValue();
-                double value2 = pointData2.getValue();
-                //切入时间
-                long ts1;
-                //切出时间
-                long ts2;
-
-                //如果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);
-                    //切入时间前5分钟
-                    long ts11 = ts1 - 300000;
-                    //根据风速key,从适配器取切入前5分钟的所有风速
-                    List<PointData> pointDatas1 = adapter.getHistorySnap(javaFunctionJobHandler.goldenUri(), windSpeedKey, ts11, ts1, 10);
-                    //平均所有风速即为平均切入风速
-                    double avgCutInWindSpeed = pointDatas1.stream().mapToDouble(PointData::getValue).average().orElse(0);
-//                    System.out.println(turbine.getTurbineId() + "切入风速" + avgCutInWindSpeed);
-
-                    //存入map集合,外层key为turbineId,内层key为ts1,value为平均切入风速
-                    mapIn.put(turbine.getTurbineId(), new HashMap<String, Double>() {{
-                        put(String.valueOf(ts1), avgCutInWindSpeed);
-                    }});
-                }
-
-                //切出
-                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);
-                    //切出时间前5分钟
-                    long ts22 = ts2 - 300000;
-                    List<PointData> pointDatas2 = adapter.getHistorySnap(javaFunctionJobHandler.goldenUri(), windSpeedKey, ts22, ts2, 10);
-                    double avgCutOutWindSpeed = pointDatas2.stream().mapToDouble(PointData::getValue).average().orElse(0);
-//                    System.out.println(turbine.getTurbineId() + "切出风速" + avgCutOutWindSpeed);
-
-                    //存入map集合,外层key为turbineId,内层key为ts2,value为平均切出风速
-                    mapOut.put(turbine.getTurbineId(), new HashMap<String, Double>() {{
-                        put(String.valueOf(ts2), avgCutOutWindSpeed);
-                    }});
-                }
-            }
-            //遍历map集合,取出每个风机的所有切入风速,算一个平均值
-            HashMap<String, Double> mapTurbineValues = mapIn.get(turbine.getTurbineId());
-            if (mapTurbineValues != null) {
-                AtomicReference<Double> sum = new AtomicReference<>(0.0);
-                //遍历mapTurbineValues,V大于5的舍弃,剩余算平均值
-                for (Map.Entry<String, Double> entry : mapTurbineValues.entrySet()) {
-                    String key = entry.getKey();
-                    Double value = entry.getValue();
-                    if (value > 5) {
-                        mapTurbineValues.remove(key);
-                    }
-                }
-                mapTurbineValues.forEach((k, v) -> {
-                    sum.updateAndGet(v1 -> v1 + v);
-                });
-
-
-                //如果值为空则置0
-                if (sum.get() == 0) {
-                    avgCutInWindSpeedOne = 0;
-                } else {
-                    avgCutInWindSpeedOne = sum.get() / mapTurbineValues.size();
-                }
-
-                System.out.println(turbine.getTurbineId() + "切入平均风速" + avgCutInWindSpeedOne + "时间" + timeBegin);
-            }
-
-            //遍历map集合,取出每个风机的所有切出风速,算一个平均值
-            HashMap<String, Double> mapTurbineValues2 = mapOut.get(turbine.getTurbineId());
-
-            if (mapTurbineValues2 != null) {
-                AtomicReference<Double> sum = new AtomicReference<>(0.0);
-
-                for (Map.Entry<String, Double> entry : mapTurbineValues2.entrySet()) {
-                    String key = entry.getKey();
-                    Double value = entry.getValue();
-                    if (value > 5) {
-                        mapTurbineValues2.remove(key);
-                    }
-                }
-                mapTurbineValues2.forEach((k, v) -> {
-                    sum.updateAndGet(v1 -> v1 + v);
-                });
-                double avgCutOutWindSpeed;
-                if (sum.get() == 0) {
-                    avgCutOutWindSpeed = 0;
-                } else {
-                    avgCutOutWindSpeed = sum.get() / mapTurbineValues2.size();
-                }
-                System.out.println(turbine.getTurbineId() + "切出平均风速" + avgCutOutWindSpeed + "时间" + timeBegin);
-            }
-
-            //存入数据库
-            String turbineId = turbine.getTurbineId();
-            Date jdkDate = timeBegin.toJdkDate();
-            System.out.println(turbineId + " " + jdkDate);
-            QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
-            turbineInfoDayQueryWrapper.eq("turbine_id", turbine.getTurbineId());
-            turbineInfoDayQueryWrapper.eq("record_date", timeBegin.toJdkDate());
-            TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
-            if (one == null) {
-                TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
-                turbineInfoDay.setTurbineId(turbine.getTurbineId());
-                turbineInfoDay.setRecordDate(timeBegin.toJdkDate());
-                turbineInfoDay.setXfqrfs(avgCutInWindSpeedOne);
-            }else {
-                one.setXfqrfs(avgCutInWindSpeedOne);
-            }
-            System.out.println(one);
-//            turbineInfoDayService.saveOrUpdate(one);
-
-        }
-    }
-
-
-}

+ 10 - 4
universal-computing-platform/src/main/java/com/ruoyi/ucp/entity/LineInfoDay.java

@@ -24,12 +24,18 @@ public class LineInfoDay implements Serializable {
 
     @TableId(value = "id", type = IdType.AUTO)
     private Integer id;
+
     private String stationId;
+
     private String projectId;
+
     private String lineId;
+
     private Date recordDate;
-    private Integer rfdl;
-    private Double swdl;
-    private Double gwdl;
-    private Double cydl;
+
+    private Integer  rfdl;
+    private double  swdl;
+    private double  gwdl;
+    private double  cydl;
+
 }

+ 1 - 2
universal-computing-platform/src/main/java/com/ruoyi/ucp/entity/PointInfo.java

@@ -21,8 +21,7 @@ import java.util.List;
  */
 @Data
 @TableName("point_info")
-@Component
-public class PointInfo extends Model<PointInfo> {
+public class PointInfo  implements Serializable {
 
     private static final long serialVersionUID = 1L;
 

+ 2 - 0
universal-computing-platform/src/main/java/com/ruoyi/ucp/entity/TurbineInfoDay.java

@@ -39,4 +39,6 @@ public class TurbineInfoDay implements Serializable {
     private Double pjfs;
     private Double edfs;
     private Double xfqrfs;
+    private Double hjwd;
+
 }

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

@@ -32,4 +32,23 @@ public class ProEconReportIndicatorPoolServiceImpl extends ServiceImpl<ProEconRe
     public boolean saveOrUpdateBatch(Collection<ProEconReportIndicatorPool> entityList) {
         return super.saveOrUpdateBatch(entityList);
     }
+
+    //重写save
+    @Override
+    public boolean save(ProEconReportIndicatorPool entity) {
+        return super.save(entity);
+    }
+
+    //getone
+    @Override
+    public ProEconReportIndicatorPool getOne(Wrapper<ProEconReportIndicatorPool> queryWrapper) {
+        return super.getOne(queryWrapper);
+    }
+
+    //saveorupdate
+    @Override
+    public boolean saveOrUpdate(ProEconReportIndicatorPool entity) {
+        return super.saveOrUpdate(entity);
+    }
+
 }

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

@@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -28,6 +29,27 @@ public class TurbineInfoDayServiceImpl extends ServiceImpl<TurbineInfoDayMapper,
         return super.list(queryWrapper);
     }
 
+    //save方法
+    @Override
+    public boolean save(TurbineInfoDay entity) {
+        return super.save(entity);
+    }
+
+    //getOne
+    @Override
+    public TurbineInfoDay getOne(Wrapper<TurbineInfoDay> queryWrapper) {
+        return super.getOne(queryWrapper);
+    }
+
+    //根据ID更新
+    @Override
+    public boolean updateById(TurbineInfoDay entity) {
+        return super.updateById(entity);
+    }
+
+
+
+
     @Override
     public boolean saveOrUpdateBatch(Collection<TurbineInfoDay> entityList) {
         return super.saveOrUpdateBatch(entityList);