|
@@ -0,0 +1,173 @@
|
|
|
+package cn.cslg.pas.service.impl;
|
|
|
+
|
|
|
+import cn.cslg.pas.common.model.dto.StructureAddNewDTO;
|
|
|
+import cn.cslg.pas.common.model.dto.StructureQueryPageDTO;
|
|
|
+import cn.cslg.pas.common.model.dto.StructureUpdateDTO;
|
|
|
+import cn.cslg.pas.common.model.dto.UploadFileDTO;
|
|
|
+import cn.cslg.pas.common.model.vo.StructureVO;
|
|
|
+import cn.cslg.pas.common.utils.FileUtils;
|
|
|
+import cn.cslg.pas.domain.Structure;
|
|
|
+import cn.cslg.pas.domain.asso.AssoStructurePicture;
|
|
|
+import cn.cslg.pas.exception.XiaoShiException;
|
|
|
+import cn.cslg.pas.mapper.AssoStructurePictureMapper;
|
|
|
+import cn.cslg.pas.mapper.StructureMapper;
|
|
|
+import cn.cslg.pas.service.IStructureService;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 架构的Service层接口实现类
|
|
|
+ *
|
|
|
+ * @Author chenyu
|
|
|
+ * @Date 2023/3/10
|
|
|
+ */
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class StructureServiceImpl implements IStructureService {
|
|
|
+ private final StructureMapper structureMapper;
|
|
|
+ private final AssoStructurePictureMapper assoStructurePictureMapper;
|
|
|
+ private final FileUtils fileUtils;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增架构
|
|
|
+ *
|
|
|
+ * @param structureAddNewDTO 新增架构DTO对象
|
|
|
+ * @param files 架构图片
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void addNew(StructureAddNewDTO structureAddNewDTO, List<MultipartFile> files) {
|
|
|
+ log.info("开始处理【新增架构】的业务,参数为:{}, {}", structureAddNewDTO, files);
|
|
|
+
|
|
|
+ //取出DTO中父级id,若父级id为null则表示该架构为第1级架构,手动给其父级id设为0
|
|
|
+ if (structureAddNewDTO.getParentId() == null) {
|
|
|
+ structureAddNewDTO.setParentId(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer parentId = structureAddNewDTO.getParentId();
|
|
|
+ String structureName = structureAddNewDTO.getStructureName();
|
|
|
+ //检查名称是否被占用(检查当前父级下是否有同名架构)
|
|
|
+ log.info("检查名称是否被占用(检查当前父级下是否有同名架构)");
|
|
|
+ int count = structureMapper.countByparentIdAndStructureName(parentId, structureName);
|
|
|
+ if (count > 0) {
|
|
|
+ String message = "新增架构失败,当前父级下已存在【" + structureName + "】";
|
|
|
+ log.info("{}", message);
|
|
|
+ throw new XiaoShiException(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ //DTO对象赋值给实体类
|
|
|
+ Structure structure = new Structure();
|
|
|
+ BeanUtils.copyProperties(structureAddNewDTO, structure);
|
|
|
+ //数据入架构表(此时数据暂不含路径path)
|
|
|
+ log.info("数据入架构表");
|
|
|
+ int rows = structureMapper.insert(structure);
|
|
|
+ if (rows != 1) {
|
|
|
+ String message = "新增架构失败,服务器忙请稍后再次尝试!";
|
|
|
+ log.info("{}", message);
|
|
|
+ throw new XiaoShiException(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ //数据入架构表后,取出id
|
|
|
+ Integer structureId = structure.getId();
|
|
|
+ String parentPath = structureAddNewDTO.getParentPath();
|
|
|
+ String path;
|
|
|
+ if (parentPath != null) {
|
|
|
+ path = parentPath + "," + structureId;
|
|
|
+ } else {
|
|
|
+ path = "0," + structureId;
|
|
|
+ }
|
|
|
+ structure.setPath(path);
|
|
|
+ log.info("更新架构表");
|
|
|
+ rows = structureMapper.update(structure);
|
|
|
+ if (rows != 1) {
|
|
|
+ String message = "新增架构失败,服务器忙请稍后再次尝试!";
|
|
|
+ log.info("{}", message);
|
|
|
+ throw new XiaoShiException(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果前端有传来架构图片,则图片上传服务器并获取图片信息,将图片信息入架构图片关联表
|
|
|
+ if (files != null && files.size() > 0) {
|
|
|
+ ArrayList<AssoStructurePicture> assoStructurePictures = new ArrayList<>();
|
|
|
+ for (MultipartFile file : files) {
|
|
|
+ UploadFileDTO fileDTO = fileUtils.uploadFile(file);
|
|
|
+ AssoStructurePicture assoStructurePicture = new AssoStructurePicture()
|
|
|
+ .setStructureId(structureId)
|
|
|
+ .setName(fileDTO.getName())
|
|
|
+ .setSuffix(fileDTO.getExtName())
|
|
|
+ .setUrl(fileDTO.getPath());
|
|
|
+ assoStructurePictures.add(assoStructurePicture);
|
|
|
+ }
|
|
|
+ rows = assoStructurePictureMapper.insertBatch(assoStructurePictures);
|
|
|
+ if (rows != assoStructurePictures.size()) {
|
|
|
+ String message = "新增架构失败,数据入架构图片关联表失败,服务器忙请稍后再次尝试!";
|
|
|
+ log.info("{}", message);
|
|
|
+ throw new XiaoShiException(message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("新增架构完成");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改架构
|
|
|
+ *
|
|
|
+ * @param structureUpdateDTO 修改架构DTO对象
|
|
|
+ * @param files 架构图片
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void update(StructureUpdateDTO structureUpdateDTO, List<MultipartFile> files) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public StructureVO query(StructureQueryPageDTO structureQueryPageDTO) {
|
|
|
+ log.info("开始处理【分页查询架构】的业务,参数为:{}", structureQueryPageDTO);
|
|
|
+
|
|
|
+ //从DTO中取出产品id、架构id、架构名称
|
|
|
+ Integer productId = structureQueryPageDTO.getProductId();
|
|
|
+ Integer structureId = structureQueryPageDTO.getStructureId();
|
|
|
+ String structureName = structureQueryPageDTO.getStructureName();
|
|
|
+ StructureVO structureVO = new StructureVO()
|
|
|
+ .setProductId(productId)
|
|
|
+ .setId(structureId)
|
|
|
+ .setStructureName(structureName);
|
|
|
+ List<StructureVO> structureVOs = structureMapper.selectByParentId(structureId);
|
|
|
+ if (structureVOs != null) {
|
|
|
+ structureVO.setChildren(structureVOs);
|
|
|
+ for (StructureVO n : structureVOs) {
|
|
|
+ Integer nId = n.getId();
|
|
|
+ List<StructureVO> ns = structureMapper.selectByParentId(nId);
|
|
|
+ if (ns != null) {
|
|
|
+ n.setChildren(ns);
|
|
|
+ for (StructureVO b : ns) {
|
|
|
+ Integer id = b.getId();
|
|
|
+ List<StructureVO> nns = structureMapper.selectByParentId(nId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return structureVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ //递归组装集合树
|
|
|
+ private void diGui(Integer structureId) {
|
|
|
+ ArrayList<StructureVO> structureVOS = new ArrayList<>();
|
|
|
+ List<StructureVO> structureVOs = structureMapper.selectByParentId(structureId);
|
|
|
+ if (structureVOs != null) {
|
|
|
+ for (StructureVO structureVO : structureVOs) {
|
|
|
+ structureId = structureVO.getId();
|
|
|
+ diGui(structureId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|