Browse Source

增加 风机功率风速分析 接口和状态时间接口

wangb 1 month ago
parent
commit
aa84f7f070

+ 145 - 3
runeconomy-xk/src/main/java/com/gyee/runeconomy/controller/agc/AgcDeviateController.java

@@ -1,18 +1,32 @@
 package com.gyee.runeconomy.controller.agc;
 
 
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.TypeReference;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.gyee.common.model.PointData;
 import com.gyee.runeconomy.config.GyeeConfig;
+import com.gyee.runeconomy.init.CacheContext;
+import com.gyee.runeconomy.model.StatusTime;
+import com.gyee.runeconomy.model.auto.PointInfo;
+import com.gyee.runeconomy.model.auto.ProBasicEquipment;
+import com.gyee.runeconomy.model.auto.ProBasicEquipmentPoint;
 import com.gyee.runeconomy.service.agc.AgcDeviateService;
+import com.gyee.runeconomy.service.auto.IPointInfoService;
+import com.gyee.runeconomy.util.realtimesource.IEdosUtil;
+import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
+import java.util.*;
 
-import java.util.List;
-import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
 /**
@@ -21,11 +35,22 @@ import java.util.stream.Collectors;
 @RestController
 @RequestMapping("/agc")
 public class AgcDeviateController {
+    public static Map<String, ConcurrentHashMap<Double, Double>> fitcoef = new ConcurrentHashMap<>();
+
     @Resource
     private AgcDeviateService agcDeviateService;
     @Resource
     private GyeeConfig gyeeConfig;
 
+    @Resource
+    private StringRedisTemplate stringRedisTemplate;
+
+    @Resource
+    private IEdosUtil edosUtil;
+
+    @Resource
+    private IPointInfoService pointInfoService;
+
     /**
      * 获取偏差信息
      *
@@ -58,4 +83,121 @@ public class AgcDeviateController {
     public Object getAgcConifg() {
         return agcDeviateService.getConfig();
     }
+
+
+    @GetMapping("/windturbine/curve")
+    public Map<String, List<SpeedPowerAnalysis>> getWindturbineData(@RequestParam(value = "startTs") long startTs,
+                                                       @RequestParam(value = "endTs") long endTs,
+                                                       @RequestParam(value = "windturbineId") String windturbineId,
+                                                       @RequestParam(value = "interval", defaultValue = "60", required = false) int interval) throws Exception {
+        //切换数据库
+        LettuceConnectionFactory factory = (LettuceConnectionFactory) stringRedisTemplate.getConnectionFactory();
+        int database = factory.getDatabase();
+        factory.setDatabase(5);
+        stringRedisTemplate.setConnectionFactory(factory);
+        factory.afterPropertiesSet();
+        factory.resetConnection();
+
+        DateTime date = DateUtil.date(endTs * 1000);
+        Map<String, List<SpeedPowerAnalysis>> map = new HashMap<>();
+        List<SpeedPowerAnalysis> ls = new ArrayList<>();
+        String[] wtIds = windturbineId.split(",");
+        List<String> wtIdsLs = Arrays.asList(wtIds);
+        for (String wtId : wtIdsLs) {
+            SpeedPowerAnalysis spa = new SpeedPowerAnalysis();
+            List<ProBasicEquipmentPoint> proBasicEquipmentPoints = CacheContext.pointNewMap.get(wtId);
+            List<ProBasicEquipmentPoint> speedPoint = proBasicEquipmentPoints.stream().filter(p -> p.getUniformCode().equals("AI066")).collect(Collectors.toList());
+            List<PointData> historyspeedDatas = edosUtil.getHistoryDatasSnap(speedPoint.get(0).getNemCode(), startTs, endTs, interval);
+            List<Double> speedDatas = historyspeedDatas.stream().map(PointData::getPointValueInDouble).collect(Collectors.toList());
+            spa.setWindSpeed(speedDatas);
+            List<ProBasicEquipmentPoint> powerPoint = proBasicEquipmentPoints.stream().filter(p -> p.getUniformCode().equals("AI114")).collect(Collectors.toList());
+            List<PointData> historyPowerDatas = edosUtil.getHistoryDatasSnap(powerPoint.get(0).getNemCode(), startTs, endTs, interval);
+            List<Double> powerData = historyPowerDatas.stream().map(PointData::getPointValueInDouble).collect(Collectors.toList());
+            spa.setActuatedPower(powerData);
+            String powerCurveMonth = "glqxnh:" + date.month() + ":";
+            Set<String> keys = stringRedisTemplate.keys(powerCurveMonth + windturbineId);
+            Iterator<String> iterator = keys.iterator(); // 获取迭代器
+            String firstKey = iterator.hasNext() ? iterator.next() : null;
+            String yc = stringRedisTemplate.opsForValue().get(firstKey);
+            ConcurrentHashMap<Double, Double> wtyc = JSON.parseObject(yc, new TypeReference<ConcurrentHashMap<Double, Double>>() {
+            }.getType());
+            fitcoef.put(firstKey.replaceFirst(powerCurveMonth, ""), wtyc);
+            List<Double> llgl = speedDatas.stream().map(a -> fitcoef.get(wtId).get(a)).collect(Collectors.toList());
+            spa.setTheoreticalPower(llgl);
+            ls.add(spa);
+            map.put(wtId, ls);
+        }
+
+        //关闭数据库切换
+        factory.setDatabase(database);
+        factory.afterPropertiesSet();
+        factory.resetConnection();
+
+        return map;
+    }
+
+    @GetMapping("/windtur")
+    public Map<String, List<StatusTime>> getTestData(@RequestParam(value = "startTs") long startTs,
+                                                    @RequestParam(value = "endTs") long endTs,
+                                                    @RequestParam(value = "uniformcode") String uniformcode) throws Exception {
+
+        Map<String, List<StatusTime>> map = new HashMap<>();
+        QueryWrapper<PointInfo> qw = new QueryWrapper<>();
+        qw.lambda().eq(PointInfo::getUniformCode, uniformcode);
+        List<PointInfo> list = pointInfoService.list(qw);
+        for (PointInfo ls : list) {
+            List<StatusTime> ll = new ArrayList<>();
+            List<PointData> historyDatasRaw = edosUtil.getHistoryDatasRaw(ls.getPointKey(), startTs, endTs);
+            for (PointData pointData : historyDatasRaw) {
+                StatusTime st = new StatusTime();
+                st.setName(ls.getName());
+                Date da=new Date(pointData.getPointTime());
+                st.setTime(DateUtil.formatDateTime(da));
+                String getstatus = getstatus((int) pointData.getPointValueInDouble());
+                st.setStatus(getstatus);
+                ll.add(st);
+            }
+            List<String> collect = CacheContext.wtls.stream().filter(w -> w.getId().equals(ls.getTurbineId())).map(ProBasicEquipment::getNemCode).collect(Collectors.toList());
+            map.put(collect.get(0), ll);
+        }
+        List<String> sortedKeys = new ArrayList<>(map.keySet());
+        Collections.sort(sortedKeys);
+        Map<String, List<StatusTime>> sortedMap = new LinkedHashMap<>();
+        for (String key : sortedKeys) {
+            sortedMap.put(key, map.get(key));
+        }
+        return sortedMap;
+    }
+
+    private String getstatus(int number) {
+        String statusText = "";
+            switch (number) {
+                case 0:
+                    statusText = "待机";
+                    break;
+                case 1:
+                    statusText = "停机";
+                    break;
+                case 2:
+                    statusText = "并网";
+                    break;
+                case 4:
+                    statusText = "故障";
+                    break;
+                case 6:
+                    statusText = "检修";
+                    break;
+                case 8:
+                    statusText = "限电";
+                    break;
+                case 12:
+                    statusText = "离线";
+                    break;
+                default:
+                    statusText = "未知";
+                    break;
+            }
+        return statusText;
+    }
+
 }

+ 26 - 26
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/bmk/BenchmarkingService.java

@@ -402,40 +402,40 @@ public class BenchmarkingService {
 
                 double quantity = CacheContext.lnmap.get(i.getLineId().trim()).getQuantity();
                 if (getype.equals("-2")) {
-                    BigDecimal rpjfs = new BigDecimal(String.valueOf(i.getPjfs()));
+                    BigDecimal rpjfs = BigDecimal.valueOf(i.getPjfs());
                     BigDecimal speed = rpjfs.divide(new BigDecimal(quantity), 2, RoundingMode.HALF_UP);
                     vo.setSpeed(speed.doubleValue());
                 } else {
-                    vo.setSpeed(BigDecimalUtils.divide(new BigDecimal(String.valueOf(i.getPjfs())), new BigDecimal(1), 2).doubleValue());
+                    vo.setSpeed(BigDecimalUtils.divide(BigDecimal.valueOf(i.getPjfs()), new BigDecimal(1), 2).doubleValue());
                 }
             } else {
                 vo.setId(i.getTurbineId());
                 vo.setName(CacheContext.wtmap.get(i.getTurbineId().trim()).getAname());
                 vo.setOrdernum(CacheContext.wtmap.get(i.getTurbineId().trim()).getOrderNum());
             }
-            vo.setSjfdl(BigDecimalUtils.divide(new BigDecimal(String.valueOf(i.getRfdl())), new BigDecimal(1000), 2).doubleValue());
-            vo.setLlfdl(BigDecimalUtils.divide(new BigDecimal(String.valueOf(i.getLlfdl())), new BigDecimal(1000), 2).doubleValue());
+            vo.setSjfdl(BigDecimalUtils.divide(BigDecimal.valueOf(i.getRfdl()), new BigDecimal(1), 2).doubleValue());
+            vo.setLlfdl(BigDecimalUtils.divide(BigDecimal.valueOf(i.getLlfdl()), new BigDecimal(1), 2).doubleValue());
 
             if (sttype.isEmpty()) {
-                vo.setSpeed(BigDecimalUtils.divide(new BigDecimal(String.valueOf(i.getPjfs())), new BigDecimal(1), 2).doubleValue());
+                vo.setSpeed(BigDecimalUtils.divide(BigDecimal.valueOf(i.getPjfs()), new BigDecimal(1), 2).doubleValue());
             }
-            vo.setFjhjx(BigDecimalUtils.divide(new BigDecimal(String.valueOf(i.getFjhjxss())), new BigDecimal(1000), 2).doubleValue());
-            vo.setJhjx(BigDecimalUtils.divide(new BigDecimal(String.valueOf(i.getJhjxss())), new BigDecimal(1000), 2).doubleValue());
-            vo.setXd(BigDecimalUtils.divide(new BigDecimal(String.valueOf(i.getXdss())), new BigDecimal(1000), 2).doubleValue());
-            vo.setSl(BigDecimalUtils.divide(new BigDecimal(String.valueOf(i.getSlss())), new BigDecimal(1000), 2).doubleValue());
-            vo.setXn(BigDecimalUtils.divide(new BigDecimal(String.valueOf(i.getXnss())), new BigDecimal(1000), 2).doubleValue());
+            vo.setFjhjx(BigDecimalUtils.divide(BigDecimal.valueOf(i.getFjhjxss()), new BigDecimal(1), 2).doubleValue());
+            vo.setJhjx(BigDecimalUtils.divide(BigDecimal.valueOf(i.getJhjxss()), new BigDecimal(1), 2).doubleValue());
+            vo.setXd(BigDecimalUtils.divide(BigDecimal.valueOf(i.getXdss()), new BigDecimal(1), 2).doubleValue());
+            vo.setSl(BigDecimalUtils.divide(BigDecimal.valueOf(i.getSlss()), new BigDecimal(1), 2).doubleValue());
+            vo.setXn(BigDecimalUtils.divide(BigDecimal.valueOf(i.getXnss()), new BigDecimal(1), 2).doubleValue());
             //            vo.setLlfdl(DoubleUtils.getRoundingNum(vo.getSjfdl()+vo.getFjhjx()+vo.getJhjx()+vo.getXd()+vo.getXn(),2));
             vo.setFnlly(vo.getLlfdl() != 0 ? DoubleUtils.keepPrecision(vo.getSjfdl() / vo.getLlfdl() * 100, 2) : 0);
             vo.setPoint(DoubleUtils.keepPrecision(vo.getLlfdl() * 1.1, 2));
 
-            llfdl.updateAndGet(v -> new Double((double) (v + vo.getLlfdl())));
-            sjfdl.updateAndGet(v -> new Double((double) (v + vo.getSjfdl())));
-            pjfs.updateAndGet(v -> new Double((double) (v + vo.getSpeed())));
-            wh.updateAndGet(v -> new Double((double) (v + vo.getJhjx())));
-            gz.updateAndGet(v -> new Double((double) (v + vo.getFjhjx())));
-            xd.updateAndGet(v -> new Double((double) (v + vo.getXd())));
-            xn.updateAndGet(v -> new Double((double) (v + vo.getXn())));
-            sl.updateAndGet(v -> new Double((double) (v + vo.getSl())));
+            llfdl.updateAndGet(v -> (double) (v + vo.getLlfdl()));
+            sjfdl.updateAndGet(v -> (double) (v + vo.getSjfdl()));
+            pjfs.updateAndGet(v -> (double) (v + vo.getSpeed()));
+            wh.updateAndGet(v -> (double) (v + vo.getJhjx()));
+            gz.updateAndGet(v -> (double) (v + vo.getFjhjx()));
+            xd.updateAndGet(v -> (double) (v + vo.getXd()));
+            xn.updateAndGet(v -> (double) (v + vo.getXn()));
+            sl.updateAndGet(v -> (double) (v + vo.getSl()));
             resultList.add(vo);
         });
         if (StringUtils.isNotEmpty(target) && StringUtils.isNotEmpty(sort)) {
@@ -451,14 +451,14 @@ public class BenchmarkingService {
         FjjxbVo vo = new FjjxbVo();
         vo.setId("hj");
         vo.setName("合计");
-        vo.setSjfdl(DoubleUtils.keepPrecision(sjfdl.get().doubleValue(), 2));
-        vo.setLlfdl(DoubleUtils.keepPrecision(llfdl.get().doubleValue(), 2));
-        vo.setSpeed(list.size() != 0 ? DoubleUtils.keepPrecision(pjfs.get().doubleValue() / list.size(), 2) : 0.0);
-        vo.setJhjx(DoubleUtils.keepPrecision(wh.get().doubleValue(), 2));
-        vo.setFjhjx(DoubleUtils.keepPrecision(gz.get().doubleValue(), 2));
-        vo.setXd(DoubleUtils.keepPrecision(xd.get().doubleValue(), 2));
-        vo.setXn(DoubleUtils.keepPrecision(xn.get().doubleValue(), 2));
-        vo.setSl(DoubleUtils.keepPrecision(sl.get().doubleValue(), 2));
+        vo.setSjfdl(DoubleUtils.keepPrecision(sjfdl.get()/1000, 2));
+        vo.setLlfdl(DoubleUtils.keepPrecision(llfdl.get()/1000, 2));
+        vo.setSpeed(list.size() != 0 ? DoubleUtils.keepPrecision(pjfs.get() / list.size(), 2) : 0.0);
+        vo.setJhjx(DoubleUtils.keepPrecision(wh.get()/1000, 2));
+        vo.setFjhjx(DoubleUtils.keepPrecision(gz.get()/1000, 2));
+        vo.setXd(DoubleUtils.keepPrecision(xd.get()/1000, 2));
+        vo.setXn(DoubleUtils.keepPrecision(xn.get()/1000, 2));
+        vo.setSl(DoubleUtils.keepPrecision(sl.get()/1000, 2));
         vo.setFnlly(vo.getLlfdl() != 0 ? DoubleUtils.keepPrecision(vo.getSjfdl() / vo.getLlfdl() * 100, 2) : 0.0);
         vo.setPoint(DoubleUtils.keepPrecision(vo.getLlfdl() * 1.1, 2));
         resultList.add(vo);