|
@@ -7,22 +7,32 @@ 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.common.utils.SystemFileToReportFile;
|
|
|
import cn.cslg.report.entity.AssoProductFile;
|
|
|
import cn.cslg.report.entity.Product;
|
|
|
+import cn.cslg.report.entity.ReportFiles;
|
|
|
+import cn.cslg.report.entity.SystemFile;
|
|
|
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;
|
|
|
import cn.cslg.report.service.business.ReportFileService;
|
|
|
+import cn.cslg.report.service.file.FileManagerService;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
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.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* 产品的Service层实现类
|
|
@@ -33,11 +43,13 @@ import java.util.List;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
|
-public class ProductServiceImpl implements IProductService {
|
|
|
+public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> {
|
|
|
private final ProductMapper productMapper; //产品表的Mapper层装配
|
|
|
private final AssoProductFileMapper assoProductFileMapper; //产品文件关联表的Mapper层装配
|
|
|
+ private final AssoProductFileServiceImpl assoProductFileService; //产品文件关联表的Mapper层装配
|
|
|
private final ReportFileService reportFileService; //报告系统文件的Service层装配
|
|
|
- private final IAssoProductFileService assoProductFileService; //产品文件关联的Service层装配
|
|
|
+ //private final IAssoProductFileService assoProductFileService; //产品文件关联的Service层装配
|
|
|
+ private final FileManagerService fileManagerService; //产品文件关联的Service层装配
|
|
|
private final CacheUtils cacheUtils;
|
|
|
private final LoginUtils loginUtils;
|
|
|
|
|
@@ -47,8 +59,7 @@ public class ProductServiceImpl implements IProductService {
|
|
|
* @param productDTO 新增产品的前端传输DTO数据对象
|
|
|
* @param files 产品附件
|
|
|
*/
|
|
|
- @Override
|
|
|
- public void addProduct(ProductDTO productDTO, List<MultipartFile> files) {
|
|
|
+ public void addProduct(ProductDTO productDTO, List<MultipartFile> files) throws IOException {
|
|
|
log.info("开始处理【新增产品】的业务,参数为:{}, {}", productDTO, files);
|
|
|
|
|
|
//DTO赋值给产品表实体类
|
|
@@ -82,7 +93,10 @@ public class ProductServiceImpl implements IProductService {
|
|
|
//3.数据入报告系统文件表(并返回附件的id集合)
|
|
|
if (files != null && files.size() != 0) {
|
|
|
log.info("数据入报告系统文件表");
|
|
|
- List<Integer> fileIds = reportFileService.uploadFiles(files);
|
|
|
+ //List<Integer> fileIds = reportFileService.uploadFiles(files);
|
|
|
+ String res = fileManagerService.uploadFile(files);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ List<Integer> fileIds = JSONArray.parseArray(jsonObject.get("data").toString(), Integer.class);
|
|
|
//4.数据入产品文件关联表
|
|
|
Integer productId = product.getId();
|
|
|
//之前是直接调用产品文件关联的Service层业务:assoProductFileService.addAsso(productId, fileIds); 现在自己敲👇
|
|
@@ -113,8 +127,7 @@ public class ProductServiceImpl implements IProductService {
|
|
|
* @param productIncludeFilesDTO 修改产品的前端传输DTO数据对象
|
|
|
* @param files 产品附件
|
|
|
*/
|
|
|
- @Override
|
|
|
- public void updateProduct(ProductIncludeFilesDTO productIncludeFilesDTO, List<MultipartFile> files) {
|
|
|
+ public void updateProduct(ProductIncludeFilesDTO productIncludeFilesDTO, List<MultipartFile> files) throws IOException {
|
|
|
log.info("开始处理【修改产品】的业务,参数为:{}, {}", productIncludeFilesDTO, files);
|
|
|
|
|
|
//DTO赋值给产品表实体类
|
|
@@ -130,61 +143,50 @@ public class ProductServiceImpl implements IProductService {
|
|
|
throw new XiaoShiException(message);
|
|
|
}
|
|
|
|
|
|
- //根据报告reportId关联查询产品表、产品文件关联表、报告系统文件表三表,获得产品和原附件数据
|
|
|
- Integer reportId = product.getReportId();
|
|
|
- log.info("根据报告reportId关联产品表、产品文件关联表、报告系统文件表三表,查询产品和附件的数据");
|
|
|
- ProductIncludeFilesVO queryResult = productMapper.getWholeByReportId(reportId);
|
|
|
-
|
|
|
- //从产品和原附件数据中获得原附件数据,遍历原附件,取出所有原附件fileId存入集合
|
|
|
- List<ReportFileStandardVO> oldReportFiles = queryResult.getReportFiles();
|
|
|
- ArrayList<Integer> oldFileIds = new ArrayList<>();
|
|
|
- for (ReportFileStandardVO oldReportFile : oldReportFiles) {
|
|
|
- Integer oldFileId = oldReportFile.getId();
|
|
|
- oldFileIds.add(oldFileId);
|
|
|
- }
|
|
|
- //从DTO中获得新的原附件数据,遍历新的原附件,取出所有新的原附件fileId存入集合
|
|
|
- List<ReportFileStandardVO> newOldReportFiles = productIncludeFilesDTO.getReportFiles();
|
|
|
- ArrayList<Integer> newOldFileIds = new ArrayList<>();
|
|
|
- for (ReportFileStandardVO newOldReportFile : newOldReportFiles) {
|
|
|
- Integer newOldFileId = newOldReportFile.getId();
|
|
|
- newOldFileIds.add(newOldFileId);
|
|
|
- }
|
|
|
- //fileId集合去重,去重后留下的fileId即为被删除的原附件fileId
|
|
|
- oldFileIds.removeAll(newOldFileIds);
|
|
|
-
|
|
|
- //如果去重后的oldFileIds仍有长度(即表示集合中留下的被删除的部分原附件fileId),则删除产品文件关联表和报告系统文件表中被删除的部分原附件fileId相关数据
|
|
|
- if (oldFileIds.size() != 0) {
|
|
|
- //2.删除产品文件关联表中被删除附件的数据
|
|
|
- log.info("删除产品文件关联表数据");
|
|
|
- rows = assoProductFileMapper.deleteByFileIds(oldFileIds);
|
|
|
- if (rows != oldFileIds.size()) {
|
|
|
- String message = "修改产品失败,服务器忙请稍后再试";
|
|
|
- log.info("删除产品文件关联表数据失败,{}", message);
|
|
|
- throw new XiaoShiException(message);
|
|
|
+ List<AssoProductFile> assoProductFiles = assoProductFileService.list(new LambdaQueryWrapper<AssoProductFile>().eq(AssoProductFile::getProductId, product.getId()));
|
|
|
+ if (assoProductFiles != null && assoProductFiles.size() > 0) {
|
|
|
+ List<Integer> oldFileIds = assoProductFiles.stream().map(AssoProductFile::getFileId).collect(Collectors.toList());
|
|
|
+ List<Integer> updateFileIds = productIncludeFilesDTO.getReportFiles().stream().map(ReportFileStandardVO::getId).collect(Collectors.toList());
|
|
|
+ //fileId集合去重,去重后留下的fileId即为被删除的原附件fileId
|
|
|
+ oldFileIds.removeAll(updateFileIds);
|
|
|
+ //如果去重后的oldFileIds仍有长度(即表示集合中留下的被删除的部分原附件fileId),则删除产品文件关联表和报告系统文件表中被删除的部分原附件fileId相关数据
|
|
|
+ if (oldFileIds.size() > 0) {
|
|
|
+ //2.删除产品文件关联表中被删除附件的数据
|
|
|
+ log.info("删除产品文件关联表数据");
|
|
|
+ rows = assoProductFileMapper.deleteByFileIds(oldFileIds);
|
|
|
+ if (rows != oldFileIds.size()) {
|
|
|
+ String message = "修改产品失败,服务器忙请稍后再试";
|
|
|
+ log.info("删除产品文件关联表数据失败,{}", message);
|
|
|
+ throw new XiaoShiException(message);
|
|
|
+ }
|
|
|
+ //2.删除报告系统文件表中被删除附件的数据
|
|
|
+ log.info("删除报告系统文件表数据");
|
|
|
+ //reportFileService.deleteFiles(oldFileIds);
|
|
|
+ fileManagerService.deleteFileFromFMS(oldFileIds);
|
|
|
}
|
|
|
- //2.删除报告系统文件表中被删除附件的数据
|
|
|
- log.info("删除报告系统文件表数据");
|
|
|
- reportFileService.deleteFiles(oldFileIds);
|
|
|
}
|
|
|
|
|
|
//如果前端传来的files附件不为null(即表示新增了若干附件),则新附件数据入报告系统文件表和产品文件关联表
|
|
|
if (files != null) {
|
|
|
//3.新的附件入报告系统文件表,返回附件fileId
|
|
|
log.info("数据入报告系统文件表");
|
|
|
- List<Integer> fileIds = reportFileService.uploadFiles(files);
|
|
|
+ //List<Integer> fileIds = reportFileService.uploadFiles(files);
|
|
|
+ String res = fileManagerService.uploadFile(files);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ List<Integer> fileIds = JSONArray.parseArray(jsonObject.get("data").toString(), Integer.class);
|
|
|
//3.新的附件fileId入产品文件关联表
|
|
|
Integer productId = product.getId();
|
|
|
- ArrayList<AssoProductFile> assoProductFiles = new ArrayList<>();
|
|
|
+ ArrayList<AssoProductFile> assoProductFiles1 = new ArrayList<>();
|
|
|
for (Integer fileId : fileIds) {
|
|
|
AssoProductFile assoProductFile = new AssoProductFile()
|
|
|
.setProductId(productId)
|
|
|
.setFileId(fileId)
|
|
|
.setFileUseType(0);
|
|
|
- assoProductFiles.add(assoProductFile);
|
|
|
+ assoProductFiles1.add(assoProductFile);
|
|
|
}
|
|
|
log.info("数据入产品文件关联表");
|
|
|
- rows = assoProductFileMapper.insertBatch(assoProductFiles);
|
|
|
- if (rows != assoProductFiles.size()) {
|
|
|
+ rows = assoProductFileMapper.insertBatch(assoProductFiles1);
|
|
|
+ if (rows != assoProductFiles1.size()) {
|
|
|
String message = "修改产品失败,服务器忙请稍后再试";
|
|
|
log.info("数据入产品文件关联表失败,{}", message);
|
|
|
throw new XiaoShiException(message);
|
|
@@ -201,10 +203,46 @@ public class ProductServiceImpl implements IProductService {
|
|
|
* @param reportId 报告id
|
|
|
* @return 返回查询到的产品和产品附件数据对象
|
|
|
*/
|
|
|
- @Override
|
|
|
- public ProductIncludeFilesVO getProduct(Integer reportId) {
|
|
|
+ public ProductIncludeFilesVO getProduct(Integer reportId) throws IOException {
|
|
|
log.info("开始处理【查询产品】的业务,参数为:{}", reportId);
|
|
|
- ProductIncludeFilesVO queryResult = productMapper.getWholeByReportId(reportId);
|
|
|
+ //ProductIncludeFilesVO queryResult = productMapper.getWholeByReportId(reportId);
|
|
|
+
|
|
|
+ List<Product> products = this.list(new LambdaQueryWrapper<Product>().eq(Product::getReportId, reportId));
|
|
|
+ Product product = new Product();
|
|
|
+ if (products != null && products.size() > 0) {
|
|
|
+ product = products.get(0);
|
|
|
+ }
|
|
|
+ ProductIncludeFilesVO queryResult = new ProductIncludeFilesVO();
|
|
|
+ BeanUtils.copyProperties(product, queryResult);
|
|
|
+ if (products != null && products.size() > 0) {
|
|
|
+ List<Integer> productIds = products.stream().map(Product::getId).collect(Collectors.toList());
|
|
|
+ List<AssoProductFile> assoProductFiles = assoProductFileService.list(new LambdaQueryWrapper<AssoProductFile>().in(AssoProductFile::getProductId, productIds));
|
|
|
+ if (assoProductFiles != null && assoProductFiles.size() > 0) {
|
|
|
+ List<Integer> fileIds = assoProductFiles.stream().map(AssoProductFile::getFileId).collect(Collectors.toList());
|
|
|
+ String res = fileManagerService.getSystemFileFromFMS(fileIds);
|
|
|
+ List<SystemFile> systemFiles = JSONArray.parseArray(res, SystemFile.class);
|
|
|
+ ArrayList<ReportFileStandardVO> reportFiles = new ArrayList<>();
|
|
|
+ systemFiles.forEach(systemFile -> {
|
|
|
+ ReportFileStandardVO reportFileStandardVO = new ReportFileStandardVO();
|
|
|
+ reportFileStandardVO.setId(systemFile.getId());
|
|
|
+ reportFileStandardVO.setName(systemFile.getOriginalName().substring(0, systemFile.getOriginalName().lastIndexOf(".")));
|
|
|
+ reportFileStandardVO.setAddress(systemFile.getFilePath().substring(systemFile.getFilePath().indexOf("file") + 4));
|
|
|
+ //reportFileStandardVO.setZid();
|
|
|
+ //reportFileStandardVO.setRemark();
|
|
|
+ reportFileStandardVO.setUpdateTime(systemFile.getUpdateTime());
|
|
|
+ reportFileStandardVO.setUid(systemFile.getCreateId());
|
|
|
+ //reportFileStandardVO.setType();
|
|
|
+ reportFileStandardVO.setSize(Integer.valueOf(systemFile.getFileLength()));
|
|
|
+ reportFileStandardVO.setSuffix(systemFile.getFilePath().substring(systemFile.getFilePath().lastIndexOf(".") + 1));
|
|
|
+ reportFileStandardVO.setFileName(systemFile.getFileName());
|
|
|
+ reportFiles.add(reportFileStandardVO);
|
|
|
+ });
|
|
|
+ queryResult.setReportFiles(reportFiles);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
return queryResult;
|
|
|
}
|
|
|
|
|
@@ -213,8 +251,7 @@ public class ProductServiceImpl implements IProductService {
|
|
|
*
|
|
|
* @param reportId 报告id
|
|
|
*/
|
|
|
- @Override
|
|
|
- public void deleteProduct(Integer reportId) {
|
|
|
+ public void deleteProduct(Integer reportId) throws IOException {
|
|
|
log.info("开始处理【删除产品】的业务,参数为:{}", reportId);
|
|
|
//1.根据产品productId删除产品文件关联表数据:先根据报告id关联查询产品关联附件的数据,取出产品productId
|
|
|
ProductIncludeFilesVO queryResult = this.getProduct(reportId);
|