Browse Source

报告代码

王波 2 weeks ago
parent
commit
054866472b

+ 1 - 0
common/src/main/java/com/gyee/common/contant/ContantXk.java

@@ -180,6 +180,7 @@ public class ContantXk {
     public static final String CJ_FX = "AI067";  //风向
     public static final String CJ_WGGL = "AI107";  //风向
     public static final String CJ_DFJD = "AI073";  //对风角度
+    public static final String CJ_PHJD = "AI028";  //对风角度
 
     public static final String TPOINT_WP_AGC = "AGC002";// agc
     public static final String TPOINT_WP_CXGL = "AGC001";// 出线

+ 3 - 4
runeconomy-xk/src/main/java/com/gyee/runeconomy/controller/EarlyWarning/EarlyWarningController.java

@@ -69,15 +69,14 @@ public class EarlyWarningController {
     @GetMapping(value = "/econreport")
     @ApiOperation(value = "经济运行分析报告", notes = "经济运行分析报告")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "wpid", value = "场站", required = true, dataType = "string", paramType = "query"),
             @ApiImplicitParam(name = "wtid", value = "风机", required = true, dataType = "string", paramType = "query"),
             @ApiImplicitParam(name = "time", value = "时间", required = true, dataType = "string", paramType = "query")
     })
-    public JSONObject geteconreportinformation(String wpid,String wtid,String time) throws Exception {
+    public JSONObject geteconreportinformation(String wtid,String time) throws Exception {
 
         Map<String, String> map = new HashMap<>();
-        if (!wpid.isEmpty()) {
-            map = reportService.Electricity(wpid,wtid,time);
+        if (!wtid.isEmpty()) {
+            map = reportService.Electricity(wtid,time);
         }
         if (map.size() > 0) {
             return JsonResult.successData(ResultCode.SUCCESS, map);

+ 1 - 8
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/EarlyWarning/ReportService.java

@@ -3,11 +3,9 @@ package com.gyee.runeconomy.service.EarlyWarning;
 import com.gyee.common.util.DoubleUtils;
 import com.gyee.runeconomy.init.CacheContext;
 import com.gyee.runeconomy.model.auto.ProBasicEquipment;
-import com.gyee.runeconomy.model.auto.ProBasicPowerstation;
 import com.gyee.runeconomy.model.auto.ProEconEquipmentmodel;
 import com.gyee.runeconomy.model.auto.TurbineInfoDay;
 import com.gyee.runeconomy.model.vo.IndicatorData;
-import com.gyee.runeconomy.service.auto.IProBasicPowerstationService;
 import com.gyee.runeconomy.service.auto.ITurbineInfoDayService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -26,12 +24,9 @@ import java.util.stream.Collectors;
 public class ReportService {
 
     @Autowired
-    private IProBasicPowerstationService powerstationService;
-
-    @Autowired
     private ITurbineInfoDayService turbineInfoDayService;
 
-    public Map Electricity(String wpid, String wtid, String time) throws Exception {
+    public Map Electricity(String wtid, String time) throws Exception {
 
         //查询时间-开始结束
         String[] timeRange = generateTimeRange(time);
@@ -49,8 +44,6 @@ public class ReportService {
 
         Map<String, Object> map = new HashMap<>();
 
-        List<ProBasicPowerstation> selectwpid = powerstationService.selectwpid(wpid);
-
         List<ProBasicEquipment> collect = CacheContext.wtls.stream()
                 .filter(wt -> wtid.equals(wt.getId())).collect(Collectors.toList());
         //获取单机设备容量

+ 78 - 58
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/WindDirection/WindDirectionService.java

@@ -20,6 +20,7 @@ import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 @Service
@@ -48,67 +49,48 @@ public class WindDirectionService {
         if (list == null || list.size() == 0)
             return null;
 
-        ProBasicEquipmentPoint pjfs = null;
-        ProBasicEquipmentPoint pjfx = null;
-        ProBasicEquipmentPoint sbzt = null;
-        ProBasicEquipmentPoint dfwc = null;
-        ProBasicEquipmentPoint phjd = null;
-        ProBasicEquipmentPoint gl = null;
-
-        pjfs = proBasicEquipmentPointService.getEquipmentPoint(wtid, ContantXk.CJ_SSFS);
-
-        pjfx = proBasicEquipmentPointService.getEquipmentPoint(wtid, ContantXk.CJ_FX);
-
-        sbzt = proBasicEquipmentPointService.getEquipmentPoint(wtid, ContantXk.MXZT);
-        List<TsDoubleData> pjfsls = remoteService.adapterfd().getHistorySnap(pjfs.getNemCode(), startDate.getTime(), endDate.getTime(), 900);
-        List<TsDoubleData> pjfxls = remoteService.adapterfd().getHistorySnap(pjfx.getNemCode(), startDate.getTime(), endDate.getTime(), 900);
-        List<TsDoubleData> sbztls = remoteService.adapterfd().getHistorySnap(sbzt.getNemCode(), startDate.getTime(), endDate.getTime(), 900);
-        PointData sbztlSs = edosUtil.getRealData(sbzt);
-
+        // 初始化设备点
+        Map<EquipmentPointType, ProBasicEquipmentPoint> points = Arrays.stream(EquipmentPointType.values())
+                .collect(Collectors.toMap(type -> type, type -> getEquipmentPoint(wtid, type)));
+
+        // 获取历史数据
+        Map<EquipmentPointType, List<TsDoubleData>> historyData = points.entrySet().stream()
+                .collect(Collectors.toMap(Map.Entry::getKey,
+                        entry -> getSortedHistory(entry.getValue(), startDate.getTime(), endDate.getTime(), 900)));
+
+        // 创建时间戳到数据的映射表
+        Map<Long, TsDoubleData> pjfsMap = historyData.get(EquipmentPointType.PJFS).stream()
+                .collect(Collectors.toMap(TsDoubleData::getTs, Function.identity(), (a, b) -> a));
+        Map<Long, TsDoubleData> sbztMap = historyData.get(EquipmentPointType.SBZT).stream()
+                .collect(Collectors.toMap(TsDoubleData::getTs, Function.identity(), (a, b) -> a));
+        Map<Long, TsDoubleData> dfwcMap = historyData.get(EquipmentPointType.DFWC).stream()
+                .collect(Collectors.toMap(TsDoubleData::getTs, Function.identity(), (a, b) -> a));
+        Map<Long, TsDoubleData> phjdMap = historyData.get(EquipmentPointType.PHJD).stream()
+                .collect(Collectors.toMap(TsDoubleData::getTs, Function.identity(), (a, b) -> a));
+        Map<Long, TsDoubleData> glMap = historyData.get(EquipmentPointType.GL).stream()
+                .collect(Collectors.toMap(TsDoubleData::getTs, Function.identity(), (a, b) -> a));
+
+        // 构造结果数据
         List<PowerPointData> lslist = new ArrayList<>();
-        for (int i = 0; i < pjfxls.size(); i++) {
-            TsDoubleData fxData = pjfxls.get(i);
-            TsDoubleData fsData = null;
-            TsDoubleData ztData = null;
-
-            for (TsDoubleData fs : pjfsls) {
-                if (fxData.getTs() == fs.getTs()) {
-                    fsData = fs;
-                    break; // 找到匹配的时间戳后退出循环
-                }
-            }
-
-            for (TsDoubleData zt : sbztls) {
-                if (fxData.getTs() == zt.getTs()) {
-                    ztData = zt;
-                    break; // 找到匹配的时间戳后退出循环
-                }
-            }
-
-            // 将时间戳转换为 LocalDateTime 对象
-            LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(fxData.getTs()), ZoneId.systemDefault());
-            // 格式化输出日期
-            DateTimeFormatter formatter11 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-            String formattedDate = dateTime.format(formatter11);
-
-            // 创建 PowerPointData 对象
-            PowerPointData data1 = new PowerPointData();
-            data1.setFx(fxData.getDoubleValue());
-//            data1.setMxzt(ztData.getPointValueInDouble());
-            data1.setTime(formattedDate);
-
-            // 如果没有找到对应的 fsData,默认设置 setFs 为 0
-            if (fsData != null) {
-                data1.setSpeed(fsData.getDoubleValue());
-            } else {
-                data1.setSpeed(0);  // 默认值
-            }
-
-            // 将 data1 添加到 lslist
-            lslist.add(data1);
+        for (TsDoubleData fxData : historyData.get(EquipmentPointType.PJFX)) {
+            long ts = fxData.getTs();
+            TsDoubleData fsData = pjfsMap.get(ts);
+            TsDoubleData ztData = sbztMap.get(ts);
+            TsDoubleData dfwcData = dfwcMap.get(ts);
+            TsDoubleData phjdData = phjdMap.get(ts);
+            TsDoubleData glData = glMap.get(ts);
+
+            PowerPointData data = new PowerPointData();
+            data.setTime(formatTimestamp(ts));
+            data.setFx(fxData.getDoubleValue());
+            data.setSpeed(fsData != null ? fsData.getDoubleValue() : 0);
+            data.setMxzt(ztData != null ? (int) ztData.getDoubleValue() : 0);
+            data.setDfwc(dfwcData != null ? dfwcData.getDoubleValue() : 0);
+            data.setAngle(phjdData != null ? phjdData.getDoubleValue() : 0);
+            data.setPower(glData != null ? glData.getDoubleValue() : 0);
+            lslist.add(data);
         }
 
-
         List<Object> result = new ArrayList<>();
 
         for (ProBasicEquipment obj : list) {
@@ -158,4 +140,42 @@ public class WindDirectionService {
         Date endDate = jssjCalendar.getTime();
         return new Date[] {startDate, endDate};
     }
+    // 工具方法:获取设备点
+    private ProBasicEquipmentPoint getEquipmentPoint(String wtid, EquipmentPointType type) {
+        return proBasicEquipmentPointService.getEquipmentPoint(wtid, type.getCode());
+    }
+
+    // 工具方法:获取历史数据并排序
+    private List<TsDoubleData> getSortedHistory(ProBasicEquipmentPoint point, long startTime, long endTime, int interval) {
+        if (point == null) return new ArrayList<>();
+        List<TsDoubleData> data = remoteService.adapterfd().getHistorySnap(point.getNemCode(), startTime, endTime, interval);
+        data.sort(Comparator.comparing(TsDoubleData::getTs));
+        return data;
+    }
+
+    // 工具方法:格式化时间戳
+    private String formatTimestamp(long timestamp) {
+        LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
+        return dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+    }
+    // 枚举定义
+    public enum EquipmentPointType {
+        PJFS(ContantXk.CJ_SSFS),
+        PJFX(ContantXk.CJ_FX),
+        SBZT(ContantXk.MXZT),
+        DFWC(ContantXk.CJ_DFJD),
+        GL(ContantXk.CJ_SSGL),
+        PHJD(ContantXk.CJ_PHJD);
+
+        private final String code;
+
+        EquipmentPointType(String code) {
+            this.code = code;
+        }
+
+        public String getCode() {
+            return code;
+        }
+    }
+
 }