coa可以上传文件视频图片修改
This commit is contained in:
parent
e9878b80c3
commit
10533bdd7f
|
|
@ -1,6 +1,7 @@
|
|||
package com.nflg.wms.common.pojo.qo;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -29,10 +30,10 @@ public class QmsCoaReviewAddQO {
|
|||
private String batchNo;
|
||||
|
||||
/**
|
||||
* COA报告/文件地址(必传)
|
||||
* COA报告文件ID列表(必传)
|
||||
*/
|
||||
@NotBlank(message = "COA报告不能为空")
|
||||
private String coaFile;
|
||||
@NotEmpty(message = "COA报告不能为空")
|
||||
private List<Long> coaFileIds;
|
||||
|
||||
/**
|
||||
* 图片列表(可选)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.nflg.wms.common.pojo.qo;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
|
|
@ -37,10 +38,10 @@ public class QmsCoaReviewUpdateQO {
|
|||
private String batchNo;
|
||||
|
||||
/**
|
||||
* COA报告
|
||||
* COA报告文件ID列表
|
||||
*/
|
||||
@NotBlank(message = "COA报告不能为空")
|
||||
private String coaFile;
|
||||
@NotEmpty(message = "COA报告不能为空")
|
||||
private List<Long> coaFileIds;
|
||||
|
||||
/**
|
||||
* 图片列表(可选)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class QmsCoaReviewDetailVO {
|
|||
private Long id;
|
||||
|
||||
/**
|
||||
* 供应商编号
|
||||
* 供应商编码
|
||||
*/
|
||||
private String supplierCode;
|
||||
|
||||
|
|
@ -74,9 +74,9 @@ public class QmsCoaReviewDetailVO {
|
|||
private String rejectionReason;
|
||||
|
||||
/**
|
||||
* COA文件地址
|
||||
* COA文件列表
|
||||
*/
|
||||
private String coaFile;
|
||||
private List<FileUploadVO> coaFiles;
|
||||
|
||||
/**
|
||||
* 报告模板
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class QmsCoaReviewVO {
|
|||
private Long id;
|
||||
|
||||
/**
|
||||
* 供应商编号
|
||||
* 供应商编码
|
||||
*/
|
||||
private String supplierCode;
|
||||
|
||||
|
|
@ -84,9 +84,9 @@ public class QmsCoaReviewVO {
|
|||
private String createBy;
|
||||
|
||||
/**
|
||||
* COA文件地址
|
||||
* COA文件列表
|
||||
*/
|
||||
private String coaFile;
|
||||
private List<FileUploadVO> coaFiles;
|
||||
|
||||
/**
|
||||
* 图片列表
|
||||
|
|
|
|||
|
|
@ -14,15 +14,18 @@ import com.nflg.wms.common.pojo.qo.QmsCoaReviewAddQO;
|
|||
import com.nflg.wms.common.pojo.qo.QmsCoaReviewAuditQO;
|
||||
import com.nflg.wms.common.pojo.qo.QmsCoaReviewSearchQO;
|
||||
import com.nflg.wms.common.pojo.qo.QmsCoaReviewUpdateQO;
|
||||
import com.nflg.wms.common.pojo.vo.FileUploadVO;
|
||||
import com.nflg.wms.common.pojo.vo.QmsCoaReviewDetailVO;
|
||||
import com.nflg.wms.common.pojo.vo.QmsCoaReviewVO;
|
||||
import com.nflg.wms.common.util.UserUtil;
|
||||
import com.nflg.wms.repository.entity.FileUploadRecord;
|
||||
import com.nflg.wms.repository.entity.QmsCoaTask;
|
||||
import com.nflg.wms.repository.entity.QmsCoaReview;
|
||||
import com.nflg.wms.repository.entity.QmsQcMaterial;
|
||||
import com.nflg.wms.repository.entity.User;
|
||||
import com.nflg.wms.repository.entity.UserSupplier;
|
||||
import com.nflg.wms.repository.mapper.QmsCoaReviewMapper;
|
||||
import com.nflg.wms.repository.service.IFileUploadRecordService;
|
||||
import com.nflg.wms.repository.service.IQmsCoaTaskService;
|
||||
import com.nflg.wms.repository.service.IQmsCoaReviewService;
|
||||
import com.nflg.wms.repository.service.IQmsQcMaterialService;
|
||||
|
|
@ -33,6 +36,8 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
|
@ -46,6 +51,8 @@ import java.util.stream.Collectors;
|
|||
public class QmsCoaReviewServiceImpl extends ServiceImpl<QmsCoaReviewMapper, QmsCoaReview>
|
||||
implements IQmsCoaReviewService {
|
||||
|
||||
private static final String COA_FILE_ID_SEPARATOR = ";";
|
||||
|
||||
@Resource
|
||||
private IQmsQcMaterialService qcMaterialService;
|
||||
|
||||
|
|
@ -58,6 +65,9 @@ public class QmsCoaReviewServiceImpl extends ServiceImpl<QmsCoaReviewMapper, Qms
|
|||
@Resource
|
||||
private IQmsCoaTaskService coaTaskService;
|
||||
|
||||
@Resource
|
||||
private IFileUploadRecordService fileUploadRecordService;
|
||||
|
||||
// ==================== 新增 ====================
|
||||
|
||||
@Transactional
|
||||
|
|
@ -113,6 +123,7 @@ public class QmsCoaReviewServiceImpl extends ServiceImpl<QmsCoaReviewMapper, Qms
|
|||
|
||||
String operator = UserUtil.getUserName();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String coaFile = joinCoaFileIds(qo.getCoaFileIds());
|
||||
|
||||
QmsCoaReview review = new QmsCoaReview()
|
||||
.setTaskId(task.getId())
|
||||
|
|
@ -121,7 +132,7 @@ public class QmsCoaReviewServiceImpl extends ServiceImpl<QmsCoaReviewMapper, Qms
|
|||
.setUserId(currentUserId)
|
||||
.setPurchaseNo(qo.getPurchaseNo())
|
||||
.setBatchNo(qo.getBatchNo())
|
||||
.setCoaFile(qo.getCoaFile())
|
||||
.setCoaFile(coaFile)
|
||||
.setImage(CollUtil.isNotEmpty(qo.getImages()) ? String.join(",", qo.getImages()) : null)
|
||||
.setStatus(0)
|
||||
.setDeleted(false)
|
||||
|
|
@ -179,6 +190,7 @@ public class QmsCoaReviewServiceImpl extends ServiceImpl<QmsCoaReviewMapper, Qms
|
|||
Integer status = review.getStatus();
|
||||
String operator = UserUtil.getUserName();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String coaFile = joinCoaFileIds(qo.getCoaFileIds());
|
||||
|
||||
var updater = lambdaUpdate().eq(QmsCoaReview::getId, qo.getId());
|
||||
|
||||
|
|
@ -197,9 +209,7 @@ public class QmsCoaReviewServiceImpl extends ServiceImpl<QmsCoaReviewMapper, Qms
|
|||
if (Objects.nonNull(qo.getPurchaseNo()) && !qo.getPurchaseNo().isEmpty()) {
|
||||
updater.set(QmsCoaReview::getPurchaseNo, qo.getPurchaseNo());
|
||||
}
|
||||
if (Objects.nonNull(qo.getCoaFile()) && !qo.getCoaFile().isEmpty()) {
|
||||
updater.set(QmsCoaReview::getCoaFile, qo.getCoaFile());
|
||||
}
|
||||
updater.set(QmsCoaReview::getCoaFile, coaFile);
|
||||
updater.set(QmsCoaReview::getBatchNo, qo.getBatchNo());
|
||||
// 修改图片
|
||||
if (qo.getImages() != null) {
|
||||
|
|
@ -207,9 +217,7 @@ public class QmsCoaReviewServiceImpl extends ServiceImpl<QmsCoaReviewMapper, Qms
|
|||
}
|
||||
} else if (Objects.equals(status, 3)) {
|
||||
// 状态3时只能改COA报告和图片
|
||||
if (Objects.nonNull(qo.getCoaFile()) && !qo.getCoaFile().isEmpty()) {
|
||||
updater.set(QmsCoaReview::getCoaFile, qo.getCoaFile());
|
||||
}
|
||||
updater.set(QmsCoaReview::getCoaFile, coaFile);
|
||||
// 修改图片
|
||||
if (qo.getImages() != null) {
|
||||
updater.set(QmsCoaReview::getImage, qo.getImages().isEmpty() ? null : String.join(",", qo.getImages()));
|
||||
|
|
@ -513,9 +521,10 @@ public class QmsCoaReviewServiceImpl extends ServiceImpl<QmsCoaReviewMapper, Qms
|
|||
Map<Long, User> userMap = userIds.isEmpty() ? Map.of() :
|
||||
userService.lambdaQuery().in(User::getId, userIds).list()
|
||||
.stream().collect(Collectors.toMap(User::getId, u -> u));
|
||||
Map<Long, FileUploadRecord> coaFileMap = getCoaFileMap(records);
|
||||
|
||||
List<QmsCoaReviewVO> vos = records.stream()
|
||||
.map(r -> toVO(r, supplierMap, materialMap, userMap))
|
||||
.map(r -> toVO(r, supplierMap, materialMap, userMap, coaFileMap))
|
||||
.collect(Collectors.toList());
|
||||
return buildPageData(page, vos);
|
||||
}
|
||||
|
|
@ -537,7 +546,7 @@ public class QmsCoaReviewServiceImpl extends ServiceImpl<QmsCoaReviewMapper, Qms
|
|||
vo.setReviewBy(review.getReviewBy());
|
||||
vo.setReviewTime(review.getReviewTime());
|
||||
vo.setRejectionReason(review.getRejectionReason());
|
||||
vo.setCoaFile(review.getCoaFile());
|
||||
vo.setCoaFiles(buildCoaFiles(review.getCoaFile(), getCoaFileMap(List.of(review))));
|
||||
vo.setImages(StrUtil.isNotBlank(review.getImage()) ? List.of(review.getImage().split(",")) : List.of());
|
||||
vo.setCreateTime(review.getCreateTime());
|
||||
vo.setCreateBy(review.getCreateBy());
|
||||
|
|
@ -634,8 +643,72 @@ public class QmsCoaReviewServiceImpl extends ServiceImpl<QmsCoaReviewMapper, Qms
|
|||
|
||||
// ==================== 私有工具方法 ====================
|
||||
|
||||
private String joinCoaFileIds(List<Long> coaFileIds) {
|
||||
if (CollUtil.isEmpty(coaFileIds)) {
|
||||
throw new NflgException(STATE.BusinessError, "COA报告不能为空");
|
||||
}
|
||||
Set<Long> fileIds = coaFileIds.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
if (fileIds.isEmpty()) {
|
||||
throw new NflgException(STATE.BusinessError, "COA报告不能为空");
|
||||
}
|
||||
List<FileUploadRecord> files = fileUploadRecordService.lambdaQuery()
|
||||
.in(FileUploadRecord::getId, fileIds)
|
||||
.list();
|
||||
Set<Long> existingFileIds = files.stream()
|
||||
.map(FileUploadRecord::getId)
|
||||
.collect(Collectors.toSet());
|
||||
if (existingFileIds.size() != fileIds.size()) {
|
||||
throw new NflgException(STATE.BusinessError, "COA报告文件不存在");
|
||||
}
|
||||
return fileIds.stream()
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining(COA_FILE_ID_SEPARATOR));
|
||||
}
|
||||
|
||||
private List<Long> parseCoaFileIds(String coaFile) {
|
||||
if (StrUtil.isBlank(coaFile)) {
|
||||
return List.of();
|
||||
}
|
||||
return StrUtil.split(coaFile, COA_FILE_ID_SEPARATOR).stream()
|
||||
.map(StrUtil::trim)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.map(Long::valueOf)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private Map<Long, FileUploadRecord> getCoaFileMap(List<QmsCoaReview> records) {
|
||||
Set<Long> fileIds = records.stream()
|
||||
.map(QmsCoaReview::getCoaFile)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.flatMap(coaFile -> parseCoaFileIds(coaFile).stream())
|
||||
.collect(Collectors.toCollection(LinkedHashSet::new));
|
||||
if (fileIds.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
return fileUploadRecordService.lambdaQuery()
|
||||
.in(FileUploadRecord::getId, fileIds)
|
||||
.list()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(FileUploadRecord::getId, file -> file, (a, b) -> a));
|
||||
}
|
||||
|
||||
private List<FileUploadVO> buildCoaFiles(String coaFile, Map<Long, FileUploadRecord> fileMap) {
|
||||
return parseCoaFileIds(coaFile).stream()
|
||||
.map(fileMap::get)
|
||||
.filter(Objects::nonNull)
|
||||
.map(file -> new FileUploadVO()
|
||||
.setId(file.getId())
|
||||
.setFileName(file.getFileName())
|
||||
.setUrl(file.getUrl())
|
||||
.setSize(0L))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private QmsCoaReviewVO toVO(QmsCoaReview r, Map<Long, UserSupplier> supplierMap,
|
||||
Map<Long, QmsQcMaterial> materialMap, Map<Long, User> userMap) {
|
||||
Map<Long, QmsQcMaterial> materialMap, Map<Long, User> userMap,
|
||||
Map<Long, FileUploadRecord> coaFileMap) {
|
||||
QmsCoaReviewVO vo = new QmsCoaReviewVO();
|
||||
vo.setId(r.getId());
|
||||
vo.setPurchaseNo(r.getPurchaseNo());
|
||||
|
|
@ -644,7 +717,7 @@ public class QmsCoaReviewServiceImpl extends ServiceImpl<QmsCoaReviewMapper, Qms
|
|||
vo.setReviewBy(r.getReviewBy());
|
||||
vo.setReviewTime(r.getReviewTime());
|
||||
vo.setRejectionReason(r.getRejectionReason());
|
||||
vo.setCoaFile(r.getCoaFile());
|
||||
vo.setCoaFiles(buildCoaFiles(r.getCoaFile(), coaFileMap));
|
||||
vo.setImages(StrUtil.isNotBlank(r.getImage()) ? List.of(r.getImage().split(",")) : List.of());
|
||||
vo.setCreateTime(r.getCreateTime());
|
||||
vo.setCreateBy(r.getCreateBy());
|
||||
|
|
|
|||
Loading…
Reference in New Issue