From c82e0937f7f72e71d9cf7a313d405d59dc61edb4 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 17 Feb 2026 15:20:27 +0800 Subject: [PATCH] fix(mes-cal): 排班计划抽取 validatePlanPrepare 校验方法,确认后禁止修改删除 --- yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java | 2 +- yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanService.java | 7 +++++++ yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java | 29 +++++++++++++++++------------ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java index ae99e75..065b39d 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java @@ -91,7 +91,7 @@ public interface ErrorCodeConstants { // ========== MES 日历排班-排班计划(1-040-202-000) ========== ErrorCode CAL_PLAN_NOT_EXISTS = new ErrorCode(1_040_202_000, "排班计划不存在"); ErrorCode CAL_PLAN_CODE_DUPLICATE = new ErrorCode(1_040_202_001, "排班计划编码已存在"); - ErrorCode CAL_PLAN_NOT_PREPARE = new ErrorCode(1_040_202_002, "只能删除草稿状态的排班计划"); + ErrorCode CAL_PLAN_NOT_PREPARE = new ErrorCode(1_040_202_002, "排班计划已确认,不允许修改或删除"); ErrorCode CAL_PLAN_TEAM_COUNT_NOT_MATCH = new ErrorCode(1_040_202_003, "确认排班计划时,分配的班组数量与轮班方式不匹配"); // ========== MES 日历排班-计划班组关联(1-040-202-100) ========== ErrorCode CAL_PLAN_TEAM_NOT_EXISTS = new ErrorCode(1_040_202_100, "计划班组关联不存在"); diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanService.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanService.java index a0ff629..945dc01 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanService.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanService.java @@ -36,6 +36,13 @@ public interface MesCalPlanService { void deletePlan(Long id); /** + * 校验排班计划为草稿状态(确认后不允许编辑) + * + * @param planId 计划编号 + */ + void validatePlanPrepare(Long planId); + + /** * 获得排班计划 * * @param id 编号 diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java index 5ce96b9..6cc7d8f 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java @@ -57,14 +57,16 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { @Override @Transactional(rollbackFor = Exception.class) public void updatePlan(MesCalPlanSaveReqVO updateReqVO) { - // TODO @AI:需要校验下,plan 未确定;(确认后,不允许编辑) // 1.1 校验存在 MesCalPlanDO existPlan = validatePlanExists(updateReqVO.getId()); - // 1.2 校验编码唯一 + // 1.2 校验计划未确认(已确认不允许编辑) + if (MesCalPlanStatusEnum.CONFIRMED.getStatus().equals(existPlan.getStatus())) { + throw exception(CAL_PLAN_NOT_PREPARE); + } + // 1.3 校验编码唯一 validatePlanCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); - // 1.3 若 status 变为 CONFIRMED,校验班组数量 - if (MesCalPlanStatusEnum.CONFIRMED.getStatus().equals(updateReqVO.getStatus()) - && !MesCalPlanStatusEnum.CONFIRMED.getStatus().equals(existPlan.getStatus())) { + // 1.4 若 status 变为 CONFIRMED,校验班组数量 + if (MesCalPlanStatusEnum.CONFIRMED.getStatus().equals(updateReqVO.getStatus())) { validateTeamCountForConfirm(updateReqVO.getId(), updateReqVO.getShiftType()); } @@ -78,13 +80,8 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { @Override @Transactional(rollbackFor = Exception.class) public void deletePlan(Long id) { - // 1.1 校验存在 - MesCalPlanDO plan = validatePlanExists(id); - // 1.2 校验状态为草稿 - // TODO @AI:需要校验下,plan 未确定;(确认后,不允许编辑)【最好抽成一个方法,各个地方可以调用】 - if (ObjUtil.notEqual(MesCalPlanStatusEnum.PREPARE.getStatus(), plan.getStatus())) { - throw exception(CAL_PLAN_NOT_PREPARE); - } + // 1.1 校验存在 + 校验状态为草稿 + validatePlanPrepare(id); // 2.1 级联删除班次 + 班组关联 planShiftService.deletePlanShiftByPlanId(id); @@ -103,6 +100,14 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { return planMapper.selectPage(pageReqVO); } + @Override + public void validatePlanPrepare(Long planId) { + MesCalPlanDO plan = validatePlanExists(planId); + if (ObjUtil.notEqual(MesCalPlanStatusEnum.PREPARE.getStatus(), plan.getStatus())) { + throw exception(CAL_PLAN_NOT_PREPARE); + } + } + private MesCalPlanDO validatePlanExists(Long id) { MesCalPlanDO plan = planMapper.selectById(id); if (plan == null) { -- libgit2 0.21.4