Sfoglia il codice sorgente

pms 编辑保养计划查询出 所有多种累计属性

zhangcl 1 giorno fa
parent
commit
f8a47ab84a

+ 45 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/IotDeviceServiceImpl.java

@@ -69,6 +69,7 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.regex.Matcher;
@@ -693,7 +694,10 @@ public class IotDeviceServiceImpl implements IotDeviceService {
 
                 // 根据设备id 运行记录模板属性名称 查询对应的 累计运行时长 累计运行公里数
                 if (CollUtil.isNotEmpty(multipleAttrDeviceIds) && CollUtil.isNotEmpty(multipleAttrNames)) {
+                    // 这里只查询了存在运行记录值的属性 todo 如果还没有记录运行记录数据 也要显示出来
                     List<IotDeviceRunLogRespVO> accumulatedData = iotDeviceRunLogMapper.multipleAccumulatedData(multipleAttrDeviceIds, multipleAttrNames);
+                    // key设备id  value设备对应的已经生成运行记录的多累计属性名称
+                    Map<Long, List<String>> loggedAttrNamePair = new HashMap<>();
                     // 组装每个设备对应的属性 累计时长 累计里程 集合
                     if (CollUtil.isNotEmpty(accumulatedData)) {
                         accumulatedData.forEach(data -> {
@@ -706,8 +710,49 @@ public class IotDeviceServiceImpl implements IotDeviceService {
                                 tempRunLogs.add(data);
                                 deviceRunLogPair.put(data.getDeviceId(), tempRunLogs);
                             }
+                            // 组装每个设备的多累计属性名称集合
+                            if (loggedAttrNamePair.containsKey(data.getDeviceId())) {
+                                List<String> tempAttrNames = loggedAttrNamePair.get(data.getDeviceId());
+                                tempAttrNames.add(data.getPointName());
+                                loggedAttrNamePair.put(data.getDeviceId(), tempAttrNames);
+                            } else {
+                                List<String> tempAttrNames = new ArrayList<>();
+                                tempAttrNames.add(data.getPointName());
+                                loggedAttrNamePair.put(data.getDeviceId(), tempAttrNames);
+                            }
                         });
                     }
+                    // todo 如果还没有记录运行记录数据 也要显示出来
+                    deviceAttrsPair.forEach((deviceId, templateAttrs) -> {
+                        // 循环每个设备对应的多累计属性集合 找到没有生成运行记录的属性 使用空对象补全
+                        List<String> loggedAttrNames;
+                        if (loggedAttrNamePair.containsKey(deviceId)) {
+                            // 当前设备对应的已经生成运行记录的多累计属性名称集合
+                            loggedAttrNames = loggedAttrNamePair.get(deviceId);
+                        } else {
+                            loggedAttrNames = new ArrayList<>();
+                        }
+                        List<IotDeviceRunLogRespVO> loggedRunLogs;
+                        if (deviceRunLogPair.containsKey(deviceId)) {
+                            // 当前设备对应的已经生成运行记录的多累计属性名称集合
+                            loggedRunLogs = deviceRunLogPair.get(deviceId);
+                        } else {
+                            loggedRunLogs = new ArrayList<>();
+                        }
+                        // 组装没有生成运行记录的多累计属性集合
+                        templateAttrs.forEach(attr -> {
+                            // 找到没有生成运行记录的多累计属性
+                            if (!loggedAttrNames.contains(attr.getName())) {
+                                IotDeviceRunLogRespVO tempRunLog = new IotDeviceRunLogRespVO();
+                                tempRunLog.setDeviceId(deviceId);
+                                tempRunLog.setPointName(attr.getName());
+                                tempRunLog.setTotalMileage(BigDecimal.ZERO);
+                                tempRunLog.setTotalRunTime(BigDecimal.ZERO);
+                                loggedRunLogs.add(tempRunLog);
+                            }
+                        });
+                    });
+
                 }
             }