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; } }