fix(qms-sampling-plan): 添加方案名称唯一性校验及细化异常处理
- 在新增抽样方案时校验方案名称是否已存在,防止重复 - 在编辑抽样方案时校验名称唯一性,排除当前方案自身 - 补充编辑和删除操作中方案存在性及发布状态校验 - 优化多个查询接口的空行及格式,提升代码可读性 - 细化字码矩阵及方案检验相关异常抛出信息,增强错误提示准确性 - 删除操作增加关联子表数据的级联清理,防止数据残留
This commit is contained in:
parent
c636e24ae3
commit
a5d04d067d
|
|
@ -63,6 +63,11 @@ public class QmsSamplingPlanControllerService {
|
|||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void add(@Valid QmsSamplingPlanAddQO request) {
|
||||
VUtil.trueThrowBusinessError(samplingPlanService.lambdaQuery()
|
||||
.eq(QmsSamplingPlan::getPlanName, request.getPlanName())
|
||||
.exists()
|
||||
).throwMessage("方案名称已存在");
|
||||
|
||||
String operator = UserUtil.getUserName();
|
||||
Long operatorId = UserUtil.getUserId();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
|
@ -147,7 +152,7 @@ public class QmsSamplingPlanControllerService {
|
|||
// 通过AQL优先值获取AQL优先值ID
|
||||
Long aqlPriorityValueId = aqlPriorityValueIdMap.get(qo.getAqlPriorityValue());
|
||||
VUtil.trueThrowBusinessError(aqlPriorityValueId == null).throwMessage("字码矩阵维护中的AQL优先值[" + qo.getAqlPriorityValue() + "]在AQL优先值列表中不存在");
|
||||
|
||||
|
||||
QmsCodeLetterMatrix entity = new QmsCodeLetterMatrix()
|
||||
.setSamplingPlanId(planId)
|
||||
.setInspectionType(qo.getInspectionType())
|
||||
|
|
@ -168,7 +173,7 @@ public class QmsSamplingPlanControllerService {
|
|||
// 通过字码内容获取字码ID
|
||||
Long codeLetterId = codeLetterIdMap.get(qo.getCodeLetter());
|
||||
VUtil.trueThrowBusinessError(codeLetterId == null).throwMessage("抽样方案检验中的字码[" + qo.getCodeLetter() + "]在字码列表中不存在");
|
||||
|
||||
|
||||
QmsSamplingPlanInspection entity = new QmsSamplingPlanInspection()
|
||||
.setSamplingPlanId(planId)
|
||||
.setRangeStart(qo.getRangeStart())
|
||||
|
|
@ -187,13 +192,19 @@ public class QmsSamplingPlanControllerService {
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public void edit(@Valid QmsSamplingPlanEditQO request) {
|
||||
Long planId = request.getId();
|
||||
|
||||
|
||||
VUtil.trueThrowBusinessError(samplingPlanService.lambdaQuery()
|
||||
.eq(QmsSamplingPlan::getPlanName, request.getPlanName())
|
||||
.ne(QmsSamplingPlan::getId, planId)
|
||||
.exists()
|
||||
).throwMessage("方案名称已存在");
|
||||
|
||||
// 0. 验证抽样方案是否存在
|
||||
QmsSamplingPlan existPlan = samplingPlanService.getById(planId);
|
||||
VUtil.trueThrowBusinessError(ObjectUtil.isNull(existPlan)).throwMessage("抽样方案不存在");
|
||||
// 已发布状态不能编辑
|
||||
VUtil.trueThrowBusinessError(existPlan.getPublishStatus() == 1).throwMessage("已发布的抽样方案不能编辑");
|
||||
|
||||
|
||||
String operator = UserUtil.getUserName();
|
||||
Long operatorId = UserUtil.getUserId();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
|
@ -283,7 +294,7 @@ public class QmsSamplingPlanControllerService {
|
|||
// 通过AQL优先值获取AQL优先值ID
|
||||
Long aqlPriorityValueId = aqlPriorityValueIdMap.get(qo.getAqlPriorityValue());
|
||||
VUtil.trueThrowBusinessError(aqlPriorityValueId == null).throwMessage("字码矩阵维护中的AQL优先值[" + qo.getAqlPriorityValue() + "]在AQL优先值列表中不存在");
|
||||
|
||||
|
||||
QmsCodeLetterMatrix entity = new QmsCodeLetterMatrix()
|
||||
.setSamplingPlanId(planId)
|
||||
.setInspectionType(qo.getInspectionType())
|
||||
|
|
@ -307,7 +318,7 @@ public class QmsSamplingPlanControllerService {
|
|||
// 通过字码内容获取字码ID
|
||||
Long codeLetterId = codeLetterIdMap.get(qo.getCodeLetter());
|
||||
VUtil.trueThrowBusinessError(codeLetterId == null).throwMessage("抽样方案检验中的字码[" + qo.getCodeLetter() + "]在字码列表中不存在");
|
||||
|
||||
|
||||
QmsSamplingPlanInspection entity = new QmsSamplingPlanInspection()
|
||||
.setSamplingPlanId(planId)
|
||||
.setRangeStart(qo.getRangeStart())
|
||||
|
|
@ -363,7 +374,7 @@ public class QmsSamplingPlanControllerService {
|
|||
VUtil.trueThrowBusinessError(ObjectUtil.isNull(existPlan)).throwMessage("抽样方案不存在");
|
||||
// 已发布状态不能删除
|
||||
VUtil.trueThrowBusinessError(existPlan.getPublishStatus() == 1).throwMessage("已发布的抽样方案不能删除");
|
||||
|
||||
|
||||
// 1. 删除关联的子表数据
|
||||
aqlPriorityValueService.lambdaUpdate()
|
||||
.eq(QmsAqlPriorityValue::getSamplingPlanId, id)
|
||||
|
|
@ -380,7 +391,7 @@ public class QmsSamplingPlanControllerService {
|
|||
samplingPlanInspectionService.lambdaUpdate()
|
||||
.eq(QmsSamplingPlanInspection::getSamplingPlanId, id)
|
||||
.remove();
|
||||
|
||||
|
||||
// 2. 删除主表数据
|
||||
samplingPlanService.removeById(id);
|
||||
}
|
||||
|
|
@ -390,7 +401,7 @@ public class QmsSamplingPlanControllerService {
|
|||
*/
|
||||
public PageData<QmsSamplingPlanVO> search(QmsSamplingPlanSearchQO request) {
|
||||
Page<QmsSamplingPlan> page = new Page<>(request.getPage(), request.getPageSize());
|
||||
|
||||
|
||||
var query = samplingPlanService.lambdaQuery()
|
||||
.eq(request.getPublishStatus() != null, QmsSamplingPlan::getPublishStatus, request.getPublishStatus())
|
||||
.ge(request.getStartDate() != null, QmsSamplingPlan::getCreateTime, request.getStartDate())
|
||||
|
|
@ -399,13 +410,13 @@ public class QmsSamplingPlanControllerService {
|
|||
.like(StrUtil.isNotBlank(request.getPlanName()), QmsSamplingPlan::getPlanName, request.getPlanName())
|
||||
.orderByAsc(QmsSamplingPlan::getPublishStatus)
|
||||
.orderByDesc(QmsSamplingPlan::getId);
|
||||
|
||||
|
||||
IPage<QmsSamplingPlan> result = query.page(page);
|
||||
|
||||
|
||||
List<QmsSamplingPlanVO> voList = result.getRecords().stream()
|
||||
.map(plan -> BeanUtil.copyProperties(plan, QmsSamplingPlanVO.class))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
PageData<QmsSamplingPlanVO> pageData = new PageData<>();
|
||||
pageData.setPage((int) result.getCurrent());
|
||||
pageData.setPageSize((int) result.getSize());
|
||||
|
|
@ -436,9 +447,9 @@ public class QmsSamplingPlanControllerService {
|
|||
// 1. 查询主表
|
||||
QmsSamplingPlan plan = samplingPlanService.getById(id);
|
||||
VUtil.trueThrowBusinessError(ObjectUtil.isNull(plan)).throwMessage("抽样方案不存在");
|
||||
|
||||
|
||||
QmsSamplingPlanDetailVO detail = BeanUtil.copyProperties(plan, QmsSamplingPlanDetailVO.class);
|
||||
|
||||
|
||||
// 2. 查询AQL优先值预定义
|
||||
List<QmsAqlPriorityValue> aqlPriorityValues = aqlPriorityValueService.lambdaQuery()
|
||||
.eq(QmsAqlPriorityValue::getSamplingPlanId, id)
|
||||
|
|
@ -448,7 +459,7 @@ public class QmsSamplingPlanControllerService {
|
|||
.map(v -> BeanUtil.copyProperties(v, QmsSamplingPlanDetailVO.AqlPriorityValueVO.class))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
|
||||
// 3. 查询抽样严格性转移规则
|
||||
List<QmsSamplingStrictnessTransferRule> transferRules = strictnessTransferRuleService.lambdaQuery()
|
||||
.eq(QmsSamplingStrictnessTransferRule::getSamplingPlanId, id)
|
||||
|
|
@ -458,7 +469,7 @@ public class QmsSamplingPlanControllerService {
|
|||
.map(r -> BeanUtil.copyProperties(r, QmsSamplingPlanDetailVO.StrictnessTransferRuleVO.class))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
|
||||
// 4. 查询字码
|
||||
List<QmsCodeLetter> codeLetters = codeLetterService.lambdaQuery()
|
||||
.eq(QmsCodeLetter::getSamplingPlanId, id)
|
||||
|
|
@ -470,11 +481,11 @@ public class QmsSamplingPlanControllerService {
|
|||
.map(c -> BeanUtil.copyProperties(c, QmsSamplingPlanDetailVO.CodeLetterVO.class))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
|
||||
// 5. 查询AQL优先值Map
|
||||
Map<Long, java.math.BigDecimal> aqlPriorityValueMap = aqlPriorityValues.stream()
|
||||
.collect(Collectors.toMap(QmsAqlPriorityValue::getId, QmsAqlPriorityValue::getPriorityValue));
|
||||
|
||||
|
||||
// 6. 查询字码矩阵维护
|
||||
List<QmsCodeLetterMatrix> codeLetterMatrices = codeLetterMatrixService.lambdaQuery()
|
||||
.eq(QmsCodeLetterMatrix::getSamplingPlanId, id)
|
||||
|
|
@ -489,7 +500,7 @@ public class QmsSamplingPlanControllerService {
|
|||
})
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
|
||||
// 7. 查询抽样方案检验
|
||||
List<QmsSamplingPlanInspection> inspections = samplingPlanInspectionService.lambdaQuery()
|
||||
.eq(QmsSamplingPlanInspection::getSamplingPlanId, id)
|
||||
|
|
@ -503,7 +514,7 @@ public class QmsSamplingPlanControllerService {
|
|||
})
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
|
||||
return detail;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue