//获取到的新list
final List<AppChannelConfig> appList = CopyUtil.copyList(appConfigUpdateDTO.getAppChannelConfigs(), AppChannelConfig::new);
//1.获取库中 appList
List<AppChannelConfig> appChannels = appChannelConfigService.list(new Query().eq("app_id", appConfigUpdateDTO.getId()));
List<AppChannelConfig> addList = appChannels.stream().filter(item -> appList.stream().noneMatch(newItem -> newItem.getChannelId().equals(item.getChannelId())&& newItem.getAppId().equals(newItem.getAppId()))).collect(Collectors.toList());
appList.forEach(ac -> {
ac.setAppId(existApp.getId());
ac.setCreateUserId(UserHolder.getUser().getUserId());
ac.setIsDeleted((int) StatusEnum.DISABLE.getStatus());
});
appChannelConfigService.saveBatch(addList);
List<AppChannelConfig> updateList = appList.stream().filter(item -> appChannels.stream().anyMatch(newItem -> newItem.getChannelId().equals(item.getChannelId()) && newItem.getAppId().equals(newItem.getAppId()))).collect(Collectors.toList());
for (AppChannelConfig a : updateList) {
appChannelConfigService.updateIgnoreNull(a);
}
List<AppChannelConfig> deleteList = addList.stream().filter(item -> appChannels.stream().noneMatch(newItem -> newItem.getChannelId().equals(item.getChannelId()) && newItem.getAppId().equals(newItem.getAppId()))).collect(Collectors.toList());
for (AppChannelConfig b : deleteList) {
appChannelConfigService.delete(b);
}
两个List通过某字段匹配比较,进行更新新增及删除操作
最新推荐文章于 2024-07-15 03:24:57 发布