|
@@ -166,7 +166,12 @@ public class IotDevicePersonServiceImpl implements IotDevicePersonService {
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
// 批量保存 设备与 责任人的关联
|
|
// 批量保存 设备与 责任人的关联
|
|
|
- iotDevicePersonMapper.insertBatch(devicePersons);
|
|
|
|
|
|
|
+ // 按 (deviceId, personId) 去重 ---
|
|
|
|
|
+ Set<String> personKeySet = new HashSet<>();
|
|
|
|
|
+ List<IotDevicePersonDO> distinctDevicePersons = devicePersons.stream()
|
|
|
|
|
+ .filter(dp -> personKeySet.add(dp.getDeviceId() + "-" + dp.getPersonId()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ iotDevicePersonMapper.insertBatch(distinctDevicePersons);
|
|
|
// 记录设备责任人调整日志
|
|
// 记录设备责任人调整日志
|
|
|
// 先查询保存之前的设备责任人
|
|
// 先查询保存之前的设备责任人
|
|
|
// 将新的设备及责任人 设置成 map<deviceId, personIds> 格式
|
|
// 将新的设备及责任人 设置成 map<deviceId, personIds> 格式
|
|
@@ -203,7 +208,17 @@ public class IotDevicePersonServiceImpl implements IotDevicePersonService {
|
|
|
devicePersonLogDOS.add(devicePersonLog);
|
|
devicePersonLogDOS.add(devicePersonLog);
|
|
|
});
|
|
});
|
|
|
if (CollUtil.isNotEmpty(devicePersonLogDOS)) {
|
|
if (CollUtil.isNotEmpty(devicePersonLogDOS)) {
|
|
|
- iotDevicePersonLogMapper.insertBatch(devicePersonLogDOS);
|
|
|
|
|
|
|
+ // 按 (deviceId, oldPersonIds, newPersonIds) 去重 ---
|
|
|
|
|
+ Set<String> logKeySet = new HashSet<>();
|
|
|
|
|
+ List<IotDevicePersonLogDO> distinctLogs = devicePersonLogDOS.stream()
|
|
|
|
|
+ .filter(log -> logKeySet.add(
|
|
|
|
|
+ log.getDeviceId() + "|" +
|
|
|
|
|
+ Objects.toString(log.getOldPersonIds(), "") + "|" +
|
|
|
|
|
+ log.getNewPersonIds()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ if (CollUtil.isNotEmpty(distinctLogs)) {
|
|
|
|
|
+ iotDevicePersonLogMapper.insertBatch(distinctLogs);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return 1l;
|
|
return 1l;
|