|
@@ -6,12 +6,18 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ruoyi.common.core.domain.PageQuery;
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
+import com.ruoyi.common.helper.LoginHelper;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
+import com.ruoyi.zdsz.domain.ZEngiineeringPhoto;
|
|
|
import com.ruoyi.zdsz.domain.ZEngineeringIndustry;
|
|
|
+import com.ruoyi.zdsz.domain.bo.ZEngiineeringPhotoBo;
|
|
|
import com.ruoyi.zdsz.domain.bo.ZEngineeringIndustryBo;
|
|
|
import com.ruoyi.zdsz.domain.bo.ZEngineeringNodeBo;
|
|
|
+import com.ruoyi.zdsz.domain.bo.ZFileBo;
|
|
|
+import com.ruoyi.zdsz.domain.vo.ZEngiineeringPhotoVo;
|
|
|
import com.ruoyi.zdsz.domain.vo.ZEngineeringIndustryVo;
|
|
|
import com.ruoyi.zdsz.mapper.ZEngineeringIndustryMapper;
|
|
|
+import com.ruoyi.zdsz.service.IZEngiineeringPhotoService;
|
|
|
import com.ruoyi.zdsz.service.IZEngineeringIndustryService;
|
|
|
import com.ruoyi.zdsz.service.IZEngineeringNodeService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
@@ -19,10 +25,8 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 工业工程|市政工程Service业务层处理
|
|
@@ -42,12 +46,19 @@ public class ZEngineeringIndustryServiceImpl implements IZEngineeringIndustrySer
|
|
|
|
|
|
@Resource
|
|
|
private IZEngineeringNodeService nodeService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IZEngiineeringPhotoService photoService;
|
|
|
/**
|
|
|
* 查询工业工程|市政工程
|
|
|
*/
|
|
|
@Override
|
|
|
public ZEngineeringIndustryVo queryById(String id) {
|
|
|
ZEngineeringIndustryVo zEngineeringIndustryVo = baseMapper.selectVoById(id);
|
|
|
+ ZEngiineeringPhotoBo zEngiineeringPhotoBo = new ZEngiineeringPhotoBo();
|
|
|
+ zEngiineeringPhotoBo.setParentId(zEngineeringIndustryVo.getId());
|
|
|
+ zEngiineeringPhotoBo.setCreateTime(zEngineeringIndustryVo.getCreateTime());
|
|
|
+ zEngineeringIndustryVo.setPics(photoService.queryList(zEngiineeringPhotoBo));
|
|
|
ZEngineeringNodeBo zEngineeringNodeBo = new ZEngineeringNodeBo();
|
|
|
zEngineeringNodeBo.setCivliId(id);
|
|
|
zEngineeringNodeBo.setCreateTime(zEngineeringIndustryVo.getCreateTime());
|
|
@@ -105,6 +116,19 @@ public class ZEngineeringIndustryServiceImpl implements IZEngineeringIndustrySer
|
|
|
boolean flag = baseMapper.insert(add) > 0;
|
|
|
if (flag) {
|
|
|
bo.setId(add.getId());
|
|
|
+ List<ZEngiineeringPhoto> list = new ArrayList<>();
|
|
|
+ bo.getFiles().forEach(o->{
|
|
|
+ ZEngiineeringPhoto pic = new ZEngiineeringPhoto();
|
|
|
+ pic.setParentId(bo.getId());
|
|
|
+ pic.setPicUrl(o.getUrl());
|
|
|
+ pic.setFileName(o.getName());
|
|
|
+ pic.setCreateBy(String.valueOf(LoginHelper.getUserId()));
|
|
|
+ pic.setCreateTime(new Date());
|
|
|
+ list.add(pic);
|
|
|
+ });
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ photoService.insertBatch(list);
|
|
|
+ }
|
|
|
}
|
|
|
bo.getzEngineeringNodeBo().setCivliId(add.getId());
|
|
|
bo.getzEngineeringNodeBo().setCreateTime(new Date());
|
|
@@ -120,6 +144,40 @@ public class ZEngineeringIndustryServiceImpl implements IZEngineeringIndustrySer
|
|
|
ZEngineeringIndustry update = BeanUtil.toBean(bo, ZEngineeringIndustry.class);
|
|
|
validEntityBeforeSave(update);
|
|
|
boolean flag = baseMapper.updateById(update) > 0;
|
|
|
+ if (flag){
|
|
|
+ List<ZEngiineeringPhoto> list = new ArrayList<>();
|
|
|
+ // 查询数据库中已存在的文件列表
|
|
|
+ ZEngiineeringPhotoBo zEngiineeringPhotoBo = new ZEngiineeringPhotoBo();
|
|
|
+ zEngiineeringPhotoBo.setParentId(update.getId());
|
|
|
+ List<String> existingPhotos = photoService.queryList(zEngiineeringPhotoBo).stream()
|
|
|
+ .map(ZEngiineeringPhotoVo::getPicUrl)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ // 插入前端传来的新文件
|
|
|
+ for (ZFileBo pic : bo.getFiles()) {
|
|
|
+ if (!existingPhotos.contains(pic)) {
|
|
|
+ ZEngiineeringPhoto newPhoto = new ZEngiineeringPhoto();
|
|
|
+ newPhoto.setParentId(bo.getId());
|
|
|
+ newPhoto.setPicUrl(pic.getUrl());
|
|
|
+ newPhoto.setFileName(pic.getName());
|
|
|
+ newPhoto.setCreateBy(String.valueOf(LoginHelper.getUserId()));
|
|
|
+ newPhoto.setCreateTime(new Date());
|
|
|
+ list.add(newPhoto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 删除数据库中多余的文件
|
|
|
+ List<String> photosToDelete = existingPhotos.stream()
|
|
|
+ .filter(pic -> !bo.getFiles().contains(pic))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!photosToDelete.isEmpty()) {
|
|
|
+ photosToDelete.forEach(item->{
|
|
|
+ photoService.deleteWithValidByurls(item);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 批量插入新图片
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ photoService.insertBatch(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
bo.getzEngineeringNodeBo().setCivliId(bo.getId());
|
|
|
bo.getzEngineeringNodeBo().setType(bo.getType());
|
|
|
izEngineeringNodeService.update(bo.getzEngineeringNodeBo());
|
|
@@ -142,14 +200,32 @@ public class ZEngineeringIndustryServiceImpl implements IZEngineeringIndustrySer
|
|
|
//TODO 做一些业务上的校验,判断是否需要校验
|
|
|
}
|
|
|
ids.forEach(item -> {
|
|
|
+ // 查询数据库中已存在的文件列表
|
|
|
+ ZEngiineeringPhotoBo zEngiineeringPhotoBo = new ZEngiineeringPhotoBo();
|
|
|
+ zEngiineeringPhotoBo.setParentId(item);
|
|
|
+ // 将查询出的url放入existingPhotos
|
|
|
+ List<String> existingPhotos = photoService.queryList(zEngiineeringPhotoBo).stream()
|
|
|
+ .map(ZEngiineeringPhotoVo::getPicUrl)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ // 若存在 则进行删除
|
|
|
+ if (!existingPhotos.isEmpty()) {
|
|
|
+ existingPhotos.forEach(i->{
|
|
|
+ photoService.deleteWithValidByurls(i);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 初始化工程节点对象
|
|
|
ZEngineeringIndustryVo vo = baseMapper.selectVoById(item);
|
|
|
ZEngineeringNodeBo zEngineeringNodeBo = new ZEngineeringNodeBo();
|
|
|
zEngineeringNodeBo.setCreateTime(vo.getCreateTime());
|
|
|
zEngineeringNodeBo.setCivliId(vo.getId());
|
|
|
+ // 查询数据库中已存在的工程节点
|
|
|
List<ZEngineeringNodeBo> zEngineeringNodeBos = nodeService.queryListDetails(zEngineeringNodeBo);
|
|
|
- zEngineeringNodeBos.forEach(ite ->
|
|
|
- nodeService.delete(ite)
|
|
|
- );
|
|
|
+ // 若存在 则进行删除
|
|
|
+ if (!zEngineeringNodeBos.isEmpty()){
|
|
|
+ zEngineeringNodeBos.forEach(ite ->
|
|
|
+ nodeService.delete(ite)
|
|
|
+ );
|
|
|
+ }
|
|
|
});
|
|
|
return baseMapper.deleteBatchIds(ids) > 0;
|
|
|
}
|