|
@@ -138,13 +138,15 @@ public class IotTemplateManagerService extends SuperService {
|
|
|
List<IotMain> saveList = new ArrayList<>();
|
|
List<IotMain> saveList = new ArrayList<>();
|
|
|
// 模版对应的数据
|
|
// 模版对应的数据
|
|
|
List<IotMain> list = iotMainDao.findByIotTemplateOrderByCreateTimeAsc(iotTemplate);
|
|
List<IotMain> list = iotMainDao.findByIotTemplateOrderByCreateTimeAsc(iotTemplate);
|
|
|
|
|
+
|
|
|
// 以前绑定的数据
|
|
// 以前绑定的数据
|
|
|
List<IotMain> oldList = iotMainDao.findByIotTemplateOrderByCreateTimeAsc(newIotTemplate);
|
|
List<IotMain> oldList = iotMainDao.findByIotTemplateOrderByCreateTimeAsc(newIotTemplate);
|
|
|
-
|
|
|
|
|
|
|
+ List<String> oldIds = new ArrayList<>();
|
|
|
HashMap<String, String> map = new HashMap<>();
|
|
HashMap<String, String> map = new HashMap<>();
|
|
|
if (ObjectUtils.isNotEmpty(oldList)) {
|
|
if (ObjectUtils.isNotEmpty(oldList)) {
|
|
|
oldList.stream().forEach(it -> {
|
|
oldList.stream().forEach(it -> {
|
|
|
map.put(it.getIotMainTemplateId(), it.getId());
|
|
map.put(it.getIotMainTemplateId(), it.getId());
|
|
|
|
|
+ oldIds.add(it.getId());
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
DeviceInfo gateWayInfo = gateWayInfoService.getDeviceGateWayInfo(deviceInfo);
|
|
DeviceInfo gateWayInfo = gateWayInfoService.getDeviceGateWayInfo(deviceInfo);
|
|
@@ -153,12 +155,12 @@ public class IotTemplateManagerService extends SuperService {
|
|
|
IotTemplate finalNewIotTemplate = newIotTemplate;
|
|
IotTemplate finalNewIotTemplate = newIotTemplate;
|
|
|
list.stream().forEach(it -> {
|
|
list.stream().forEach(it -> {
|
|
|
IotMain main = new IotMain();
|
|
IotMain main = new IotMain();
|
|
|
- BeanUtils.copyProperties(it, main, "id", "createTime", "updateTime");
|
|
|
|
|
- if (oldList.contains(it.getId())) {
|
|
|
|
|
- main.setId(map.get(it.getId()));
|
|
|
|
|
-
|
|
|
|
|
- map.remove(it.getId());
|
|
|
|
|
|
|
+ if (map.containsKey(it.getId())) {
|
|
|
|
|
+ String oldId = map.get(it.getId());
|
|
|
|
|
+ main = iotMainDao.findTopById(oldId);
|
|
|
|
|
+ oldIds.remove(oldId);
|
|
|
}
|
|
}
|
|
|
|
|
+ BeanUtils.copyProperties(it, main, "id", "createTime", "updateTime");
|
|
|
main.setIotThingId(iotThingId);
|
|
main.setIotThingId(iotThingId);
|
|
|
|
|
|
|
|
// 所属产品副本
|
|
// 所属产品副本
|
|
@@ -182,9 +184,8 @@ public class IotTemplateManagerService extends SuperService {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
iotMainDao.saveAll(saveList);
|
|
iotMainDao.saveAll(saveList);
|
|
|
- if (!map.isEmpty()) {
|
|
|
|
|
- List<String> ids = new ArrayList<>(map.values());
|
|
|
|
|
- iotMainDao.deleteAllById(ids);
|
|
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(oldIds)) {
|
|
|
|
|
+ iotMainDao.deleteAllById(oldIds);
|
|
|
}
|
|
}
|
|
|
return ResultContent.buildSuccess();
|
|
return ResultContent.buildSuccess();
|
|
|
}
|
|
}
|