|
@@ -1,5 +1,9 @@
|
|
|
package cn.cslg.report.service.impl;
|
|
|
|
|
|
+import cn.cslg.report.common.model.vo.PersonnelVO;
|
|
|
+import cn.cslg.report.common.model.vo.ReportFileStandardVO;
|
|
|
+import cn.cslg.report.common.utils.CacheUtils;
|
|
|
+import cn.cslg.report.common.utils.SecurityUtils.LoginUtils;
|
|
|
import cn.cslg.report.mapper.ProductMapper;
|
|
|
import cn.cslg.report.common.model.dto.ProductDTO;
|
|
|
import cn.cslg.report.entity.Product;
|
|
@@ -13,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -25,13 +30,17 @@ import java.util.List;
|
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
|
public class ProductServiceImpl implements IProductService {
|
|
|
- private ProductMapper productMapper;
|
|
|
- private ReportFileService reportFileService;
|
|
|
- private AssoProductFileServiceImpl assoProductFileService;
|
|
|
+ private final ProductMapper productMapper;
|
|
|
+ private final ReportFileService reportFileService;
|
|
|
+ private final AssoProductFileServiceImpl assoProductFileService;
|
|
|
+ private final CacheUtils cacheUtils;
|
|
|
+ private final LoginUtils loginUtils;
|
|
|
|
|
|
/**
|
|
|
- * 新增产品的业务层方法
|
|
|
- * @param productDTO 前端新增产品数据对象
|
|
|
+ * 新增产品数据的业务层方法
|
|
|
+ *
|
|
|
+ * @param productDTO 产品数据对象
|
|
|
+ * @param files 产品图片附件
|
|
|
*/
|
|
|
@Override
|
|
|
public void addProduct(ProductDTO productDTO, List<MultipartFile> files) {
|
|
@@ -39,37 +48,83 @@ public class ProductServiceImpl implements IProductService {
|
|
|
Product product = new Product();
|
|
|
BeanUtils.copyProperties(productDTO, product);
|
|
|
//product.setProductIdentify("产品标识???"); 产品标识字段未知逻辑???
|
|
|
+ PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
+ product.setCreatePersonId(personnelVO.getId()); //获取创建人ID
|
|
|
+ product.setCreatePersonName(personnelVO.getName()); //获取创建人姓名
|
|
|
+ //插入产品数据信息入产品表
|
|
|
productMapper.insert(product);
|
|
|
|
|
|
//上传图片/文件入库,返回图片/文件的ids,将ids插入产品文件关联表中
|
|
|
if (files != null && files.size() != 0) {
|
|
|
//将文档上传并返回文件入库的Ids集合
|
|
|
List<Integer> fileIds = reportFileService.uploadFiles(files);
|
|
|
- assoProductFileService.addAsso(product.getId(), fileIds);
|
|
|
+ Integer productId = product.getId();
|
|
|
+ assoProductFileService.addAsso(productId, fileIds);
|
|
|
}
|
|
|
- log.info("新增产品成功");
|
|
|
+ log.info("产品新增完成!");
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据id修改产品的业务层方法
|
|
|
+ * 根据id修改产品数据的业务层方法
|
|
|
+ *
|
|
|
* @param productDTO 待修改的产品新数据
|
|
|
+ * @param files 待修改的产品图片附件
|
|
|
*/
|
|
|
@Override
|
|
|
- public void updateProduct(ProductDTO productDTO) {
|
|
|
- log.info("开始处理【修改产品】的业务,参数为:{}", productDTO);
|
|
|
+ public void updateProduct(ProductDTO productDTO, List<MultipartFile> files) {
|
|
|
+ log.info("开始处理【修改产品】的业务,参数为:{}, {}", productDTO, files);
|
|
|
+ Product product = new Product();
|
|
|
+ BeanUtils.copyProperties(productDTO, product);
|
|
|
+ //1.修改产品表数据
|
|
|
+ productMapper.update(product);
|
|
|
+
|
|
|
+ //2.删除文件表中原来的图片文件,根据reportId(报告id)关联查询取出产品表数据对象
|
|
|
+ ProductStandardVO queryResult = productMapper.getStandardByReportId(product.getReportId());
|
|
|
+
|
|
|
+ //3.取出对象中的附件集合属性,遍历取出原所有附件fileIds
|
|
|
+ List<ReportFileStandardVO> oldReportFiles = queryResult.getReportFiles();
|
|
|
+ ArrayList<Integer> oldFileIdList = new ArrayList<>();
|
|
|
+ for (ReportFileStandardVO reportFile : oldReportFiles) {
|
|
|
+ Integer fileId = reportFile.getId();
|
|
|
+ oldFileIdList.add(fileId);
|
|
|
+ }
|
|
|
+ //4.取出对象中的附件集合属性,遍历取出现所有附件fileIds
|
|
|
+ List<ReportFileStandardVO> newReportFiles = productDTO.getReportFiles();
|
|
|
+ ArrayList<Integer> newFileIdList = new ArrayList<>();
|
|
|
+ for (ReportFileStandardVO reportFile : newReportFiles) {
|
|
|
+ Integer fileId = reportFile.getId();
|
|
|
+ newFileIdList.add(fileId);
|
|
|
+ }
|
|
|
+ //5.去重保留被删除的附件fileId
|
|
|
+ oldFileIdList.removeAll(newFileIdList);
|
|
|
+
|
|
|
+ //6.若去重后的原fileId集合仍有长度(即表示被删除了部分原附件),则删除文件表和产品文件关联表中被删除的附件的数据
|
|
|
+ if (oldFileIdList.size() != 0) {
|
|
|
+ reportFileService.deleteFiles(oldFileIdList); //删除文件表中被删除附件的数据
|
|
|
+ assoProductFileService.deleteAsso(oldFileIdList); //删除产品文件关联表中被删除附件的数据
|
|
|
+ }
|
|
|
|
|
|
+ //7.插入新的附件入文件表中,返回文件id
|
|
|
+ List<Integer> fileIds = reportFileService.uploadFiles(files);
|
|
|
+ Integer productId = product.getId();
|
|
|
+ //8.插入新的文件id入产品文件关联表中
|
|
|
+ assoProductFileService.addAsso(productId, fileIds);
|
|
|
+
|
|
|
+ log.info("产品修改完成!");
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据报告id查询产品数据的业务层方法
|
|
|
+ *
|
|
|
* @param reportId 报告id
|
|
|
* @return 返回查询到的产品数据对象
|
|
|
*/
|
|
|
@Override
|
|
|
public ProductStandardVO getProduct(Integer reportId) {
|
|
|
- log.info("开始处理【根据报告id查询产品数据信息】的业务,参数为:{}", reportId);
|
|
|
+ log.info("开始处理【查询产品】的业务,参数为:{}", reportId);
|
|
|
return productMapper.getStandardByReportId(reportId);
|
|
|
+
|
|
|
}
|
|
|
}
|