|
@@ -9,6 +9,8 @@ import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDevice
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -74,11 +76,49 @@ public interface IotDeviceRunLogService {
|
|
|
List<IotDeviceRunLogRespVO> list = distinctDevices(ids);
|
|
|
// 删除集合中的NULL元素
|
|
|
list.removeIf(deviceLog -> isAllFieldsNull(deviceLog));
|
|
|
- return CollectionUtils.convertMap(list, IotDeviceRunLogRespVO::getDeviceId);
|
|
|
+ // 暂时将查询出的2条记录设置为1条
|
|
|
+ // device_id total_run_time total_mileage point_name point_code
|
|
|
+ // 136 2444.00 0.00 台上发动机累计运转时长 sc
|
|
|
+ // 136 0.00 16510.00 底盘发动机累计公里数 gls
|
|
|
+ // 按 deviceId 分组并合并数据
|
|
|
+ Map<Long, IotDeviceRunLogRespVO> mergedMap = new HashMap<>();
|
|
|
+ for (IotDeviceRunLogRespVO log : list) {
|
|
|
+ Long deviceId = log.getDeviceId();
|
|
|
+ // 跳过无效设备ID
|
|
|
+ if (deviceId == null) continue;
|
|
|
+
|
|
|
+ if (mergedMap.containsKey(deviceId)) {
|
|
|
+ // 合并已有记录
|
|
|
+ IotDeviceRunLogRespVO existing = mergedMap.get(deviceId);
|
|
|
+ mergeLogRecords(existing, log);
|
|
|
+ } else {
|
|
|
+ // 首次遇到该设备ID,直接放入Map
|
|
|
+ mergedMap.put(deviceId, log);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<IotDeviceRunLogRespVO> mergedList = new ArrayList<>(mergedMap.values());
|
|
|
+ return CollectionUtils.convertMap(mergedList, IotDeviceRunLogRespVO::getDeviceId);
|
|
|
}
|
|
|
|
|
|
// 检查是否所有字段都为NULL的辅助方法
|
|
|
default boolean isAllFieldsNull(IotDeviceRunLogRespVO deviceLog) {
|
|
|
return ObjectUtil.isEmpty(deviceLog.getDeviceId());
|
|
|
}
|
|
|
+
|
|
|
+ default void mergeLogRecords(IotDeviceRunLogRespVO target, IotDeviceRunLogRespVO source) {
|
|
|
+ // 累加数值字段(假设类型为BigDecimal)
|
|
|
+ if (target.getTotalRunTime() != null && source.getTotalRunTime() != null) {
|
|
|
+ target.setTotalRunTime(target.getTotalRunTime().add(source.getTotalRunTime()));
|
|
|
+ } else if (source.getTotalRunTime() != null) {
|
|
|
+ target.setTotalRunTime(source.getTotalRunTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (target.getTotalMileage() != null && source.getTotalMileage() != null) {
|
|
|
+ target.setTotalMileage(target.getTotalMileage().add(source.getTotalMileage()));
|
|
|
+ } else if (source.getTotalMileage() != null) {
|
|
|
+ target.setTotalMileage(source.getTotalMileage());
|
|
|
+ }
|
|
|
+ // 非数值字段保持target的原始值(即第一条记录的值)
|
|
|
+ // 不需要额外操作
|
|
|
+ }
|
|
|
}
|