|
@@ -7,8 +7,10 @@ import cn.cslg.report.common.model.vo.ProductIncludeFilesVO;
|
|
|
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.entity.AssoProductFile;
|
|
|
import cn.cslg.report.entity.Product;
|
|
|
import cn.cslg.report.exception.XiaoShiException;
|
|
|
+import cn.cslg.report.mapper.AssoProductFileMapper;
|
|
|
import cn.cslg.report.mapper.ProductMapper;
|
|
|
import cn.cslg.report.service.IAssoProductFileService;
|
|
|
import cn.cslg.report.service.IProductService;
|
|
@@ -32,47 +34,75 @@ import java.util.List;
|
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
|
public class ProductServiceImpl implements IProductService {
|
|
|
- private final ProductMapper productMapper; //产品的Mapper层接口
|
|
|
- private final ReportFileService reportFileService; //报告系统文件的Service层实现类
|
|
|
- private final IAssoProductFileService assoProductFileService; //产品文件关联的Service层实现类
|
|
|
+ private final ProductMapper productMapper; //产品表的Mapper层装配
|
|
|
+ private final AssoProductFileMapper assoProductFileMapper; //产品文件关联表的Mapper层装配
|
|
|
+ private final ReportFileService reportFileService; //报告系统文件的Service层装配
|
|
|
+ private final IAssoProductFileService assoProductFileService; //产品文件关联的Service层装配
|
|
|
private final CacheUtils cacheUtils;
|
|
|
private final LoginUtils loginUtils;
|
|
|
|
|
|
/**
|
|
|
* 新增产品
|
|
|
*
|
|
|
- * @param productDTO 产品数据前端传输DTO对象
|
|
|
- * @param files 附件
|
|
|
+ * @param productDTO 新增产品的前端传输DTO类对象
|
|
|
+ * @param files 产品附件
|
|
|
*/
|
|
|
@Override
|
|
|
public void addProduct(ProductDTO productDTO, List<MultipartFile> files) {
|
|
|
- log.info("开始处理【新增产品】的业务,参数为:{}, {}", productDTO, files);
|
|
|
- //新增产品DTO类对象赋值给产品表实体类对象
|
|
|
+ log.info("开始处理【新增产品】的业务,参数为产品信息:{}, 产品附件:{}", productDTO, files);
|
|
|
+
|
|
|
+ //DTO赋值给产品表实体类
|
|
|
Product product = new Product();
|
|
|
BeanUtils.copyProperties(productDTO, product);
|
|
|
- //获取创建人信息
|
|
|
+ //获取登陆人信息
|
|
|
PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
|
- //将创建人id和姓名赋值给产品表实体类对象
|
|
|
+ //登陆人id和姓名赋值给产品表实体类
|
|
|
product.setCreatePersonId(personnelVO.getId())
|
|
|
.setCreatePersonName(personnelVO.getName());
|
|
|
|
|
|
- //检查当前报告是否已有创建的产品 (根据报告id查询产品,1个报告只能创建有1个产品)
|
|
|
+ //检查当前报告是否已创建产品 (一个报告只能创建一个产品,根据报告id查询产品)
|
|
|
Integer reportId = product.getReportId();
|
|
|
+ log.info("检查当前报告是否已创建产品");
|
|
|
int count = productMapper.countByReportId(reportId);
|
|
|
if (count > 0) {
|
|
|
- String message = "新增产品失败,当前报告产品已创建";
|
|
|
+ String message = "新增产品失败,当前报告产品已创建产品";
|
|
|
+ log.info("{}", message);
|
|
|
+ throw new XiaoShiException(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ //1.数据入产品表
|
|
|
+ log.info("数据入产品表");
|
|
|
+ int rows = productMapper.insert(product);
|
|
|
+ if (rows != 1) {
|
|
|
+ String message = "新增产品失败,服务器忙请稍后再试";
|
|
|
log.info("{}", message);
|
|
|
throw new XiaoShiException(message);
|
|
|
}
|
|
|
|
|
|
- //1.产品数据入产品表
|
|
|
- productMapper.insert(product);
|
|
|
- //2.附件数据(如果有附件)入报告系统文件表并返回附件的id集合
|
|
|
+ //2.数据入报告系统文件表(并返回附件的id集合)
|
|
|
if (files != null && files.size() != 0) {
|
|
|
+ log.info("数据入报告系统文件表");
|
|
|
List<Integer> fileIds = reportFileService.uploadFiles(files);
|
|
|
- //3.产品productId和附件fileId入产品文件关联表
|
|
|
- assoProductFileService.addAsso(product.getId(), fileIds);
|
|
|
+ //3.数据入产品文件关联表
|
|
|
+ Integer productId = product.getId();
|
|
|
+ //之前是直接调用产品文件关联的Service层业务:assoProductFileService.addAsso(productId, fileIds); 现在自己敲👇
|
|
|
+ ArrayList<AssoProductFile> assoProductFiles = new ArrayList<>();
|
|
|
+ for (Integer fileId : fileIds) {
|
|
|
+ AssoProductFile assoProductFile = new AssoProductFile()
|
|
|
+ .setProductId(productId)
|
|
|
+ .setFileId(fileId)
|
|
|
+ .setFileUseType(0);
|
|
|
+ assoProductFiles.add(assoProductFile);
|
|
|
+ }
|
|
|
+ log.info("数据入产品文件关联表");
|
|
|
+ rows = assoProductFileMapper.insertBatch(assoProductFiles);
|
|
|
+ if (rows != fileIds.size()) {
|
|
|
+ String message = "新增产品失败,服务器忙请稍后再试";
|
|
|
+ log.info("{}", message);
|
|
|
+ throw new XiaoShiException(message);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
log.info("新增产品完成");
|
|
|
|
|
|
}
|