Commit 941b871c authored by “yiyousong”'s avatar “yiyousong”
parents b84f88d6 d4a82cf9
...@@ -93,6 +93,8 @@ public class SyncSiteDeviceTaskImpl implements ITaskExcuteService { ...@@ -93,6 +93,8 @@ public class SyncSiteDeviceTaskImpl implements ITaskExcuteService {
List<DeviceEntity> oldDeviceList = deviceService.find(new DeviceQuery().siteId(site.getId())); List<DeviceEntity> oldDeviceList = deviceService.find(new DeviceQuery().siteId(site.getId()));
Map<String, DeviceEntity> oldDeviceMap = oldDeviceList.stream().collect(Collectors.toMap(x -> x.getDeviceCode(), y -> y, (o, n) -> n)); Map<String, DeviceEntity> oldDeviceMap = oldDeviceList.stream().collect(Collectors.toMap(x -> x.getDeviceCode(), y -> y, (o, n) -> n));
Map<String, DeviceEntity> newDeviceMap = newDeviceList.stream().collect(Collectors.toMap(x -> x.getDeviceCode(), y -> y, (o, n) -> n));
List<DeviceEntity> updateDeviceLsit = newDeviceList.stream().map(item -> { List<DeviceEntity> updateDeviceLsit = newDeviceList.stream().map(item -> {
if (oldDeviceMap.containsKey(item.getDeviceCode())) { if (oldDeviceMap.containsKey(item.getDeviceCode())) {
item.setId(oldDeviceMap.get(item.getDeviceCode()).getId()); item.setId(oldDeviceMap.get(item.getDeviceCode()).getId());
...@@ -116,6 +118,14 @@ public class SyncSiteDeviceTaskImpl implements ITaskExcuteService { ...@@ -116,6 +118,14 @@ public class SyncSiteDeviceTaskImpl implements ITaskExcuteService {
return null; return null;
}).filter(f -> f != null).collect(Collectors.toList()); }).filter(f -> f != null).collect(Collectors.toList());
//做差集
List<Long> delDeviceList = oldDeviceList.stream().map(item -> {
if (!newDeviceMap.containsKey(item.getDeviceCode())) {
return item.getId();
}
return null;
}).filter(f -> f != null).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(updateDeviceLsit)) { if (!ObjectUtils.isEmpty(updateDeviceLsit)) {
log.info("设备更新,size:{}", updateDeviceLsit.size()); log.info("设备更新,size:{}", updateDeviceLsit.size());
deviceService.update(updateDeviceLsit); deviceService.update(updateDeviceLsit);
...@@ -125,6 +135,11 @@ public class SyncSiteDeviceTaskImpl implements ITaskExcuteService { ...@@ -125,6 +135,11 @@ public class SyncSiteDeviceTaskImpl implements ITaskExcuteService {
log.info("设备新增,size:{}", saveDeviceList.size()); log.info("设备新增,size:{}", saveDeviceList.size());
deviceService.save(saveDeviceList); deviceService.save(saveDeviceList);
} }
if (!ObjectUtils.isEmpty(delDeviceList)) {
log.info("设备删除,size:{}", delDeviceList.size());
deviceService.remove(delDeviceList,null);
}
} }
} else { } else {
log.info("设备列表查询异常,{}", JSON.toJSONString(deviceRest)); log.info("设备列表查询异常,{}", JSON.toJSONString(deviceRest));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment