|
@@ -132,33 +132,49 @@ public class ZComprehensiveServiceImpl implements IZComprehensiveService {
|
|
|
public Boolean updateByBo(ZComprehensiveBo bo) {
|
|
|
ZComprehensive update = BeanUtil.toBean(bo, ZComprehensive.class);
|
|
|
validEntityBeforeSave(update);
|
|
|
+
|
|
|
if (StringUtils.isNotBlank(bo.getId())) {
|
|
|
- bo.setId(bo.getId());
|
|
|
List<ZEngiineeringPhoto> list = new ArrayList<>();
|
|
|
- if (!bo.getPicIds().isEmpty()) {
|
|
|
- ZEngiineeringPhotoBo bo1 = new ZEngiineeringPhotoBo();
|
|
|
- bo1.setParentId(update.getId());
|
|
|
- bo1.setCreateTime(update.getCreateTime());
|
|
|
-// List<String> collect = photoService.queryList(bo1).stream().map(ele -> ele.getPicUrl()).collect(Collectors.toList());
|
|
|
-// if (!collect.isEmpty()) {
|
|
|
-// bo.setPicIds(bo.getPicIds().stream().filter(pic -> !collect.contains(pic)).collect(Collectors.toList()));
|
|
|
-// }
|
|
|
- bo.getPicIds().stream().forEach(o -> {
|
|
|
- ZEngiineeringPhoto pic = new ZEngiineeringPhoto();
|
|
|
- pic.setParentId(bo.getId());
|
|
|
- pic.setPicUrl(o);
|
|
|
- pic.setCreateBy(String.valueOf(LoginHelper.getUserId()));
|
|
|
- pic.setCreateTime(new Date());
|
|
|
- list.add(pic);
|
|
|
- });
|
|
|
- if (!list.isEmpty()) {
|
|
|
- photoService.updateBatch(list);
|
|
|
+
|
|
|
+ // 查询数据库中已存在的图片列表
|
|
|
+ ZEngiineeringPhotoBo bo1 = new ZEngiineeringPhotoBo();
|
|
|
+ bo1.setParentId(update.getId());
|
|
|
+ List<String> existingPhotos = photoService.queryList(bo1).stream()
|
|
|
+ .map(ZEngiineeringPhotoVo::getPicUrl)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 插入前端传来的新图片
|
|
|
+ for (String pic : bo.getPicIds()) {
|
|
|
+ if (!existingPhotos.contains(pic)) {
|
|
|
+ ZEngiineeringPhoto newPhoto = new ZEngiineeringPhoto();
|
|
|
+ newPhoto.setParentId(bo.getId());
|
|
|
+ newPhoto.setPicUrl(pic);
|
|
|
+ newPhoto.setCreateBy(String.valueOf(LoginHelper.getUserId()));
|
|
|
+ newPhoto.setCreateTime(new Date());
|
|
|
+ list.add(newPhoto);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 删除数据库中多余的图片
|
|
|
+ List<String> photosToDelete = existingPhotos.stream()
|
|
|
+ .filter(pic -> !bo.getPicIds().contains(pic))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!photosToDelete.isEmpty()) {
|
|
|
+ photosToDelete.forEach(item->{
|
|
|
+ photoService.deleteWithValidByurls(item);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量插入新图片
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ photoMapper.insertBatch(list);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
return baseMapper.updateById(update) > 0;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 保存前的数据校验
|
|
|
*/
|