|
@@ -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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|