|
@@ -26,6 +26,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -205,6 +207,96 @@ public class ZEngineeringIndustryServiceImpl implements IZEngineeringIndustrySer
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
+ private void batchUpdatePic(ZEngineeringIndustryBo bo, String methodName, String type) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
|
|
|
+ // 获取类对象
|
|
|
+ Class<?> cls = ZEngineeringInfoBo.class;
|
|
|
+ // 获取指定方法
|
|
|
+ Method method = cls.getDeclaredMethod(methodName);
|
|
|
+// System.out.println("method.invoke(obj);==="+method.invoke(bo.getzEngineeringNodeBo().getzEngineeringInfoBoList().get(0)));
|
|
|
+ // 故事正文开始
|
|
|
+ List<ZEngineeringInfoBo> zEngineeringInfoBoList = bo.getzEngineeringNodeBo().getzEngineeringInfoBoList();
|
|
|
+ for (int i = 0; i < zEngineeringInfoBoList.size(); i++) {
|
|
|
+ ZEngineeringInfoBo zEngineeringInfoBo = zEngineeringInfoBoList.get(i);
|
|
|
+ if (!ObjectUtils.isEmpty(method.invoke(zEngineeringInfoBo))) {
|
|
|
+ List<ZEngiineeringPhoto> list = new ArrayList<>();
|
|
|
+ // 查询数据库中已存在的文件列表
|
|
|
+ ZEngiineeringPhotoBo zEngiineeringPhotoBo = new ZEngiineeringPhotoBo();
|
|
|
+ zEngiineeringPhotoBo.setCreateTime(zEngineeringInfoBo.getCreateTime());//
|
|
|
+ zEngiineeringPhotoBo.setType(type);
|
|
|
+ zEngiineeringPhotoBo.setParentId(zEngineeringInfoBo.getId());
|
|
|
+ List<String> existingPhotos = photoService.queryList(zEngiineeringPhotoBo).stream().map(ZEngiineeringPhotoVo::getPicUrl).collect(Collectors.toList());
|
|
|
+ // 插入前端传来的新文件
|
|
|
+ for (String pic : (List<String>)method.invoke(zEngineeringInfoBo)) {
|
|
|
+ if (!existingPhotos.contains(pic)) {
|
|
|
+ ZEngiineeringPhoto newPhoto = new ZEngiineeringPhoto();
|
|
|
+ newPhoto.setParentId(zEngineeringInfoBo.getId());
|
|
|
+ newPhoto.setPicUrl(pic);
|
|
|
+ newPhoto.setFileName(pic);
|
|
|
+ newPhoto.setType(type);
|
|
|
+ newPhoto.setCreateBy(String.valueOf(LoginHelper.getUsername()));
|
|
|
+ newPhoto.setCreateTime(bo.getCreateTime());
|
|
|
+ newPhoto.setUpdateTime(new Date());
|
|
|
+ list.add(newPhoto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 删除数据库中多余的文件
|
|
|
+ List<String> photosToDelete = existingPhotos.stream().filter(pic -> {
|
|
|
+ try {
|
|
|
+ return !((List<String>)(method.invoke(zEngineeringInfoBo))).contains(pic);
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (InvocationTargetException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ if (!photosToDelete.isEmpty()) {
|
|
|
+ photosToDelete.forEach(item -> {
|
|
|
+ ZEngiineeringPhoto zEngiineeringPhoto = new ZEngiineeringPhoto();
|
|
|
+ zEngiineeringPhoto.setType(type);
|
|
|
+ zEngiineeringPhoto.setPicUrl(item);
|
|
|
+ zEngiineeringPhoto.setCreateTime(bo.getCreateTime());
|
|
|
+ photoService.deleteWithValid(zEngiineeringPhoto);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 批量插入新图片
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ photoService.insertBatch(list);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ // 查询数据库中已存在的文件列表
|
|
|
+ ZEngiineeringPhotoBo zEngiineeringPhotoBo = new ZEngiineeringPhotoBo();
|
|
|
+ zEngiineeringPhotoBo.setCreateTime(zEngineeringInfoBo.getCreateTime());//
|
|
|
+ zEngiineeringPhotoBo.setParentId(zEngineeringInfoBo.getId());
|
|
|
+ zEngiineeringPhotoBo.setType(type);
|
|
|
+ List<String> existingPhotos = photoService.queryList(zEngiineeringPhotoBo).stream().map(ZEngiineeringPhotoVo::getPicUrl).collect(Collectors.toList());
|
|
|
+ // 删除数据库中多余的文件
|
|
|
+ List<String> photosToDelete = null;
|
|
|
+ try {
|
|
|
+ photosToDelete = existingPhotos.stream().filter(pic -> {
|
|
|
+ try {
|
|
|
+ return !((List<String>)(method.invoke(zEngineeringInfoBo))).contains(pic);
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } catch (InvocationTargetException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
+ if (!photosToDelete.isEmpty()) {
|
|
|
+ photosToDelete.forEach(item -> {
|
|
|
+ ZEngiineeringPhoto zEngiineeringPhoto = new ZEngiineeringPhoto();
|
|
|
+ zEngiineeringPhoto.setType(type);
|
|
|
+ zEngiineeringPhoto.setPicUrl(item);
|
|
|
+ zEngiineeringPhoto.setCreateTime(bo.getCreateTime());
|
|
|
+ photoService.deleteWithValid(zEngiineeringPhoto);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改工业工程|市政工程
|
|
|
*/
|
|
@@ -248,6 +340,31 @@ public class ZEngineeringIndustryServiceImpl implements IZEngineeringIndustrySer
|
|
|
photoService.insertBatch(list);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// // 市政施工-沟上施工 焊接
|
|
|
+// public List<String> welding;
|
|
|
+// // 市政施工-沟上施工 防腐
|
|
|
+// public List<String> aczoiling;
|
|
|
+// // 市政施工-沟下施工 管道下沟
|
|
|
+// public List<String> piping;
|
|
|
+// // 市政施工-沟下施工 警示带铺设
|
|
|
+// public List<String> warning;
|
|
|
+// // 市政施工-沟下施工 回填
|
|
|
+// public List<String> backfilling;
|
|
|
+ /**
|
|
|
+ * 焊接照片
|
|
|
+ * 防腐照片
|
|
|
+ *
|
|
|
+ */
|
|
|
+ try {
|
|
|
+ batchUpdatePic(bo, "getWelding", "welding");
|
|
|
+ batchUpdatePic(bo, "getAczoiling", "aczoiling");
|
|
|
+ batchUpdatePic(bo, "getPiping", "piping");
|
|
|
+ batchUpdatePic(bo, "getWarning", "warning");
|
|
|
+ batchUpdatePic(bo, "getBackfilling", "backfilling");
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
if (!ObjectUtils.isEmpty(bo.getzEngineeringNodeBo())){
|
|
|
List<ZEngineeringInfoBo> engineeringInfoBoList1 = bo.getzEngineeringNodeBo().getzEngineeringInfoBoList();
|