From a5d04d067d53f9f7d947a7e9c8879ab26a5aa17a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Sat, 9 May 2026 09:36:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(qms-sampling-plan):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=96=B9=E6=A1=88=E5=90=8D=E7=A7=B0=E5=94=AF=E4=B8=80=E6=80=A7?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=8F=8A=E7=BB=86=E5=8C=96=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在新增抽样方案时校验方案名称是否已存在,防止重复 - 在编辑抽样方案时校验名称唯一性,排除当前方案自身 - 补充编辑和删除操作中方案存在性及发布状态校验 - 优化多个查询接口的空行及格式,提升代码可读性 - 细化字码矩阵及方案检验相关异常抛出信息,增强错误提示准确性 - 删除操作增加关联子表数据的级联清理,防止数据残留 --- .../QmsSamplingPlanControllerService.java | 51 +++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/QmsSamplingPlanControllerService.java b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/QmsSamplingPlanControllerService.java index dab4ff1f..2044b71b 100644 --- a/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/QmsSamplingPlanControllerService.java +++ b/nflg-qms-admin/src/main/java/com/nflg/qms/admin/service/QmsSamplingPlanControllerService.java @@ -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 search(QmsSamplingPlanSearchQO request) { Page 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 result = query.page(page); - + List voList = result.getRecords().stream() .map(plan -> BeanUtil.copyProperties(plan, QmsSamplingPlanVO.class)) .collect(Collectors.toList()); - + PageData 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 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 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 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 aqlPriorityValueMap = aqlPriorityValues.stream() .collect(Collectors.toMap(QmsAqlPriorityValue::getId, QmsAqlPriorityValue::getPriorityValue)); - + // 6. 查询字码矩阵维护 List codeLetterMatrices = codeLetterMatrixService.lambdaQuery() .eq(QmsCodeLetterMatrix::getSamplingPlanId, id) @@ -489,7 +500,7 @@ public class QmsSamplingPlanControllerService { }) .collect(Collectors.toList())); } - + // 7. 查询抽样方案检验 List inspections = samplingPlanInspectionService.lambdaQuery() .eq(QmsSamplingPlanInspection::getSamplingPlanId, id) @@ -503,7 +514,7 @@ public class QmsSamplingPlanControllerService { }) .collect(Collectors.toList())); } - + return detail; } }