|
@@ -1,19 +1,20 @@
|
|
package cn.cslg.report.service.impl;
|
|
package cn.cslg.report.service.impl;
|
|
|
|
|
|
|
|
+import cn.cslg.report.common.model.dto.ProductIncludeFilesDTO;
|
|
import cn.cslg.report.common.model.vo.PersonnelVO;
|
|
import cn.cslg.report.common.model.vo.PersonnelVO;
|
|
import cn.cslg.report.common.model.vo.ReportFileStandardVO;
|
|
import cn.cslg.report.common.model.vo.ReportFileStandardVO;
|
|
import cn.cslg.report.common.utils.CacheUtils;
|
|
import cn.cslg.report.common.utils.CacheUtils;
|
|
|
|
+import cn.cslg.report.common.utils.Response;
|
|
import cn.cslg.report.common.utils.SecurityUtils.LoginUtils;
|
|
import cn.cslg.report.common.utils.SecurityUtils.LoginUtils;
|
|
import cn.cslg.report.mapper.ProductMapper;
|
|
import cn.cslg.report.mapper.ProductMapper;
|
|
import cn.cslg.report.common.model.dto.ProductDTO;
|
|
import cn.cslg.report.common.model.dto.ProductDTO;
|
|
import cn.cslg.report.entity.Product;
|
|
import cn.cslg.report.entity.Product;
|
|
-import cn.cslg.report.common.model.vo.ProductStandardVO;
|
|
|
|
|
|
+import cn.cslg.report.common.model.vo.ProductIncludeFilesVO;
|
|
import cn.cslg.report.service.IProductService;
|
|
import cn.cslg.report.service.IProductService;
|
|
import cn.cslg.report.service.business.ReportFileService;
|
|
import cn.cslg.report.service.business.ReportFileService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
@@ -21,66 +22,69 @@ import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 产品表的业务层实现类
|
|
|
|
|
|
+ * 产品的Service层实现类
|
|
*
|
|
*
|
|
* @Author chenyu
|
|
* @Author chenyu
|
|
- * @Data 2022/12/20 11:28
|
|
|
|
|
|
+ * @Data 2022/12/20
|
|
*/
|
|
*/
|
|
@Slf4j
|
|
@Slf4j
|
|
@Service
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
public class ProductServiceImpl implements IProductService {
|
|
public class ProductServiceImpl implements IProductService {
|
|
- private final ProductMapper productMapper; //产品表Mapper接口
|
|
|
|
- private final ReportFileService reportFileService; //报告系统文件表业务层
|
|
|
|
- private final AssoProductFileServiceImpl assoProductFileService; //产品文件关联表业务层
|
|
|
|
|
|
+ private final ProductMapper productMapper; //产品的Mapper层接口
|
|
|
|
+ private final ReportFileService reportFileService; //报告系统文件的Service层实现类
|
|
|
|
+ private final AssoProductFileServiceImpl assoProductFileService; //产品文件关联的Service层实现类
|
|
private final CacheUtils cacheUtils;
|
|
private final CacheUtils cacheUtils;
|
|
private final LoginUtils loginUtils;
|
|
private final LoginUtils loginUtils;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 新增产品表数据和产品文件关联表数据和报告系统文件表中产品图片数据的业务层方法
|
|
|
|
|
|
+ * 新增产品的业务层方法
|
|
*
|
|
*
|
|
- * @param productDTO 产品数据对象
|
|
|
|
- * @param files 产品图片附件
|
|
|
|
|
|
+ * @param productDTO 产品的前端传输DTO类
|
|
|
|
+ * @param files 产品附件
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public void addProduct(ProductDTO productDTO, List<MultipartFile> files) {
|
|
public void addProduct(ProductDTO productDTO, List<MultipartFile> files) {
|
|
log.info("开始处理【新增产品】的业务,参数为:{}, {}", productDTO, files);
|
|
log.info("开始处理【新增产品】的业务,参数为:{}, {}", productDTO, files);
|
|
|
|
+ //产品DTO类赋值给产品实体类
|
|
Product product = new Product();
|
|
Product product = new Product();
|
|
BeanUtils.copyProperties(productDTO, product);
|
|
BeanUtils.copyProperties(productDTO, product);
|
|
- //product.setProductIdentify("产品标识???"); 产品标识字段未知逻辑???
|
|
|
|
|
|
+ //获取当前管理员的人员信息
|
|
PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
PersonnelVO personnelVO = cacheUtils.getLoginUser(loginUtils.getId());
|
|
- product.setCreatePersonId(personnelVO.getId()); //获取创建人ID
|
|
|
|
- product.setCreatePersonName(personnelVO.getName()); //获取创建人姓名
|
|
|
|
- //插入产品数据信息入产品表
|
|
|
|
- productMapper.insert(product);
|
|
|
|
|
|
+ //获取创建人id和创建人姓名并赋值给实体类
|
|
|
|
+ product.setCreatePersonId(personnelVO.getId())
|
|
|
|
+ .setCreatePersonName(personnelVO.getName());
|
|
|
|
|
|
- //上传图片/文件入库,返回图片/文件的ids,将ids插入产品文件关联表中
|
|
|
|
|
|
+ //1.插入产品数据入产品表
|
|
|
|
+ productMapper.insert(product);
|
|
|
|
+ //2.插入产品附件数据入报告系统文件表并返回附件的ids
|
|
if (files != null && files.size() != 0) {
|
|
if (files != null && files.size() != 0) {
|
|
- //将文档上传并返回文件入库的Ids集合
|
|
|
|
List<Integer> fileIds = reportFileService.uploadFiles(files);
|
|
List<Integer> fileIds = reportFileService.uploadFiles(files);
|
|
- Integer productId = product.getId();
|
|
|
|
- assoProductFileService.addAsso(productId, fileIds);
|
|
|
|
|
|
+ //3.插入产品id和附件id入产品文件关联表
|
|
|
|
+ assoProductFileService.addAsso(product.getId(), fileIds);
|
|
}
|
|
}
|
|
log.info("产品新增完成!");
|
|
log.info("产品新增完成!");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 根据id修改产品表数据和产品文件关联表数据和报告系统文件表中产品图片数据的业务层方法
|
|
|
|
|
|
+ * 修改产品的业务层方法
|
|
*
|
|
*
|
|
- * @param productDTO 待修改的产品新数据
|
|
|
|
- * @param files 待修改的产品图片附件
|
|
|
|
|
|
+ * @param productIncludeFilesDTO 产品的新数据
|
|
|
|
+ * @param files 产品的新附件
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public void updateProduct(ProductDTO productDTO, List<MultipartFile> files) {
|
|
|
|
- log.info("开始处理【修改产品】的业务,参数为:{}, {}", productDTO, files);
|
|
|
|
|
|
+ public void updateProduct(ProductIncludeFilesDTO productIncludeFilesDTO, List<MultipartFile> files) {
|
|
|
|
+ log.info("开始处理【修改产品】的业务,参数为:{}, {}", productIncludeFilesDTO, files);
|
|
|
|
+ //产品关联附件的前端传输DTO类赋值给产品实体类
|
|
Product product = new Product();
|
|
Product product = new Product();
|
|
- BeanUtils.copyProperties(productDTO, product);
|
|
|
|
- //1.根据reportId(报告id)修改产品表数据
|
|
|
|
|
|
+ BeanUtils.copyProperties(productIncludeFilesDTO, product);
|
|
|
|
+
|
|
|
|
+ //1.根据id修改产品表数据
|
|
productMapper.update(product);
|
|
productMapper.update(product);
|
|
|
|
|
|
- //2.根据reportId(报告id)关联查询出产品表数据对象
|
|
|
|
- ProductStandardVO queryResult = productMapper.getStandardByReportId(product.getReportId());
|
|
|
|
|
|
+ //2.根据reportId(报告id)关联查询出产品关联附件的数据信息
|
|
|
|
+ ProductIncludeFilesVO queryResult = productMapper.getStandardByReportId(product.getReportId());
|
|
|
|
|
|
//3.取出对象中的附件集合属性,遍历取出原所有附件fileIds
|
|
//3.取出对象中的附件集合属性,遍历取出原所有附件fileIds
|
|
List<ReportFileStandardVO> oldReportFiles = queryResult.getReportFiles();
|
|
List<ReportFileStandardVO> oldReportFiles = queryResult.getReportFiles();
|
|
@@ -90,7 +94,7 @@ public class ProductServiceImpl implements IProductService {
|
|
oldFileIdList.add(fileId);
|
|
oldFileIdList.add(fileId);
|
|
}
|
|
}
|
|
//4.取出对象中的附件集合属性,遍历取出现所有附件fileIds
|
|
//4.取出对象中的附件集合属性,遍历取出现所有附件fileIds
|
|
- List<ReportFileStandardVO> newReportFiles = productDTO.getReportFiles();
|
|
|
|
|
|
+ List<ReportFileStandardVO> newReportFiles = productIncludeFilesDTO.getReportFiles();
|
|
ArrayList<Integer> newFileIdList = new ArrayList<>();
|
|
ArrayList<Integer> newFileIdList = new ArrayList<>();
|
|
for (ReportFileStandardVO reportFile : newReportFiles) {
|
|
for (ReportFileStandardVO reportFile : newReportFiles) {
|
|
Integer fileId = reportFile.getId();
|
|
Integer fileId = reportFile.getId();
|
|
@@ -105,10 +109,11 @@ public class ProductServiceImpl implements IProductService {
|
|
assoProductFileService.deleteAssoByFileIds(oldFileIdList); //删除产品文件关联表中被删除附件的数据
|
|
assoProductFileService.deleteAssoByFileIds(oldFileIdList); //删除产品文件关联表中被删除附件的数据
|
|
}
|
|
}
|
|
|
|
|
|
- //7.插入新的附件入文件表中,返回文件id
|
|
|
|
|
|
+ //7.插入新的附件入报告系统文件表中,返回文件id
|
|
List<Integer> fileIds = reportFileService.uploadFiles(files);
|
|
List<Integer> fileIds = reportFileService.uploadFiles(files);
|
|
- Integer productId = product.getId();
|
|
|
|
|
|
+
|
|
//8.插入新的文件id入产品文件关联表中
|
|
//8.插入新的文件id入产品文件关联表中
|
|
|
|
+ Integer productId = product.getId();
|
|
assoProductFileService.addAsso(productId, fileIds);
|
|
assoProductFileService.addAsso(productId, fileIds);
|
|
|
|
|
|
log.info("产品修改完成");
|
|
log.info("产品修改完成");
|
|
@@ -122,8 +127,9 @@ public class ProductServiceImpl implements IProductService {
|
|
* @return 返回查询到的产品数据对象
|
|
* @return 返回查询到的产品数据对象
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public ProductStandardVO getProduct(Integer reportId) {
|
|
|
|
|
|
+ public ProductIncludeFilesVO getProduct(Integer reportId) {
|
|
log.info("开始处理【查询产品】的业务,参数为:{}", reportId);
|
|
log.info("开始处理【查询产品】的业务,参数为:{}", reportId);
|
|
|
|
+ ProductIncludeFilesVO queryResult = productMapper.getStandardByReportId(reportId);
|
|
return productMapper.getStandardByReportId(reportId);
|
|
return productMapper.getStandardByReportId(reportId);
|
|
|
|
|
|
}
|
|
}
|
|
@@ -140,7 +146,7 @@ public class ProductServiceImpl implements IProductService {
|
|
productMapper.deleteByReportId(reportId);
|
|
productMapper.deleteByReportId(reportId);
|
|
|
|
|
|
//2.删除产品文件关联表数据:根据报告id关联查询产品数据,取出产品id,根据产品id删除产品与文件关联表数据
|
|
//2.删除产品文件关联表数据:根据报告id关联查询产品数据,取出产品id,根据产品id删除产品与文件关联表数据
|
|
- ProductStandardVO queryResult = this.getProduct(reportId);
|
|
|
|
|
|
+ ProductIncludeFilesVO queryResult = this.getProduct(reportId);
|
|
Integer productId = queryResult.getId();
|
|
Integer productId = queryResult.getId();
|
|
assoProductFileService.deleteAssoByProductId(productId);
|
|
assoProductFileService.deleteAssoByProductId(productId);
|
|
|
|
|