Browse Source

fix(data): 适配新数据源并优化数据处理逻辑

- 在 PowerFittingData 类中添加对 ProBasicModelPowerRd 的引用,用于获取理论功率数据- 优化 PowerFittingData构造函数,增加空值判断和类型转换
- 修改 TsDataService 中的数据获取逻辑,统一处理以 "NX" 开头的标签名
- 优化数据统计方法,提高代码可读性和维护性
xushili 1 month ago
parent
commit
9880343095

+ 8 - 8
data-adapter/src/main/java/com/gyee/dataadapter/service/TsDataService.java

@@ -34,7 +34,7 @@ public class TsDataService {
     public Map<String, PointData> getLatest(List<String> tagNames) {
         Map<String, PointData> latest = new HashMap<>();
         if(CollUtil.isEmpty(tagNames)) return latest;
-        Map<Boolean, List<String>> nxFgs = tagNames.stream().collect(Collectors.groupingBy(tn -> tn.startsWith("NX_FGS_")));
+        Map<Boolean, List<String>> nxFgs = tagNames.stream().collect(Collectors.groupingBy(tn -> tn.startsWith("NX")));
         try {
             latest = historyDao.getLatest(nxFgs.get(true));
         } catch (Exception e) {
@@ -65,7 +65,7 @@ public class TsDataService {
 
     public List<PointData> getHistoryRaw(String tagName, Date startTime, Date endTime) {
         try {
-            if (tagName.startsWith("NX_FGS_")) {
+            if (tagName.startsWith("NX")) {
                 return historyDao.getHistoryRaw(tagName, startTime, endTime);
             } else {
                 startTime = DateUtil.offsetHour(startTime, -8);
@@ -90,7 +90,7 @@ public class TsDataService {
     public List<PointData> getHistorySnap(String tagName, Date startTime, Date endTime, Integer interval) {
         if (interval == null || interval == 0) interval = 60;
         try {
-            if (tagName.startsWith("NX_FGS_")) {
+            if (tagName.startsWith("NX")) {
                 return historyDao.getHistorySnap(tagName, startTime, endTime, interval);
             } else {
                 return adapterService.getPointData(startTime, endTime, 0, interval, tagName);
@@ -113,7 +113,7 @@ public class TsDataService {
         if (interval == null || interval == 0) interval = 60;
         if (type == null || type < 2 || type > 4) type = 4;
         try {
-            if (tagName.startsWith("NX_FGS_") || tagName.startsWith("NXFGS_")) {
+            if (tagName.startsWith("NX") || tagName.startsWith("NXFGS_")) {
                 return historyDao.getHistoryStat(tagName, startTime, endTime, interval, type);
             } else {
                 return adapterService.getPointData(startTime, endTime, type, interval, tagName);
@@ -129,7 +129,7 @@ public class TsDataService {
     public List<PointData> getHistoryStat2(String tagName, Date startTime, Date endTime, Integer type) {
         if (type == null || type < 2 || type > 4) type = 4;
         try {
-            if (tagName.startsWith("NX_FGS_") || tagName.startsWith("NXFGS_")) {
+            if (tagName.startsWith("NX") || tagName.startsWith("NXFGS_")) {
                 return historyDao.getHistoryStat2(tagName, startTime, endTime, type);
             } else {
                 return adapterService.getPointData2(startTime, endTime, type, tagName);
@@ -142,7 +142,7 @@ public class TsDataService {
     }
 
     public PointData getHistoryStat0(String tagName, Date startTime, Date endTime, Integer type) {
-        if (tagName.startsWith("NX_FGS_")) {
+        if (tagName.startsWith("NX")) {
             try {
                 return historyDao.getHistoryStat0(tagName, startTime, endTime, type);
             } catch (Exception e) {
@@ -172,7 +172,7 @@ public class TsDataService {
         Map<String, PointData> result = new HashMap<>();
         if(StrUtil.isBlank(tagNames)) return result;
         Map<Boolean, List<String>> nxFgs = Arrays.stream(tagNames.split(",")).collect(
-                Collectors.groupingBy(tn -> tn.toUpperCase().startsWith("NX_FGS_")));
+                Collectors.groupingBy(tn -> tn.toUpperCase().startsWith("NX")));
         try {
             Map<String, PointData> latest = historyDao.getHistorySection(time, nxFgs.get(true));
             result.putAll(latest);
@@ -197,7 +197,7 @@ public class TsDataService {
         Map<String, PointData> result = new HashMap<>();
         if(StrUtil.isBlank(tagNames)) return result;
         Map<Boolean, List<String>> nxFgs = Arrays.stream(tagNames.split(",")).collect(
-                Collectors.groupingBy(tn -> tn.toUpperCase().startsWith("NX_FGS_")));
+                Collectors.groupingBy(tn -> tn.toUpperCase().startsWith("NX")));
         try {
             Map<String, PointData> latest = historyDao.getHistorySection(time, nxFgs.get(true));
             result.putAll(latest);

+ 11 - 7
runeconomy-xk/src/main/java/com/gyee/runeconomy/model/PowerFittingData.java

@@ -2,6 +2,7 @@ package com.gyee.runeconomy.model;
 
 import com.gyee.runeconomy.dto.speed.Desc;
 import com.gyee.runeconomy.init.CacheContext;
+import com.gyee.runeconomy.model.auto.ProBasicModelPowerRd;
 import lombok.Data;
 
 /**
@@ -10,21 +11,24 @@ import lombok.Data;
 @Data
 public class PowerFittingData {
 
-    public PowerFittingData(){}
+    public PowerFittingData() {
+    }
 
     public PowerFittingData(String[] str) {
-        if (str.length >= 2){
+        if (str.length >= 2) {
             this.speed = Double.valueOf(str[0]);
             this.nhdata = Double.valueOf(str[1]);
-            this.cpdata = ((double)((int)(Double.valueOf(str[2])*1000)))/1000;
+            this.cpdata = ((double) ((int) (Double.valueOf(str[2]) * 1000))) / 1000;
         }
     }
-    public PowerFittingData(String[] str,String modleId) {
-        if (str.length >= 2){
+
+    public PowerFittingData(String[] str, String modleId) {
+        if (str.length >= 2) {
             this.speed = Double.valueOf(str[0]);
             this.nhdata = Double.valueOf(str[1]);
-            this.xzdata = CacheContext.theoreticalPowerMap.get(modleId).get(this.speed).getEnsurePower();
-            this.cpdata = ((double)((int)(Double.valueOf(str[2])*1000)))/1000;
+            ProBasicModelPowerRd rd = CacheContext.theoreticalPowerMap.get(modleId).get(this.speed);
+            this.xzdata = rd == null ? 0 : rd.getEnsurePower();
+            this.cpdata = ((double) ((int) (Double.valueOf(str[2]) * 1000))) / 1000;
         }
     }