Commit 3f2c13f3272b5436330d053b8ff3838587912c8c

Authored by YunaiV
1 parent f163e105

✨ feat(mes/cal-plan): 新增排班计划专用 confirm 接口

- 后端新增 PUT /mes/cal/plan/confirm 接口,仅接收 id 参数
- Service 层新增 confirmPlan(Long id) 方法,含草稿状态校验和班组数量校验
- updatePlan 中强制忽略 status 字段,禁止通过 update 修改状态
- 前端 API 新增 confirmPlan(id: number) 方法
- CalPlanForm handleConfirm 改为调用专用 confirmPlan 接口
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/MesCalPlanController.java
@@ -51,6 +51,15 @@ public class MesCalPlanController { @@ -51,6 +51,15 @@ public class MesCalPlanController {
51 return success(true); 51 return success(true);
52 } 52 }
53 53
  54 + @PutMapping("/confirm")
  55 + @Operation(summary = "确认排班计划")
  56 + @Parameter(name = "id", description = "编号", required = true)
  57 + @PreAuthorize("@ss.hasPermission('mes:cal-plan:update')")
  58 + public CommonResult<Boolean> confirmPlan(@RequestParam("id") Long id) {
  59 + planService.confirmPlan(id);
  60 + return success(true);
  61 + }
  62 +
54 @DeleteMapping("/delete") 63 @DeleteMapping("/delete")
55 @Operation(summary = "删除排班计划") 64 @Operation(summary = "删除排班计划")
56 @Parameter(name = "id", description = "编号", required = true) 65 @Parameter(name = "id", description = "编号", required = true)
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanService.java
@@ -29,6 +29,13 @@ public interface MesCalPlanService { @@ -29,6 +29,13 @@ public interface MesCalPlanService {
29 void updatePlan(@Valid MesCalPlanSaveReqVO updateReqVO); 29 void updatePlan(@Valid MesCalPlanSaveReqVO updateReqVO);
30 30
31 /** 31 /**
  32 + * 确认排班计划
  33 + *
  34 + * @param id 编号
  35 + */
  36 + void confirmPlan(Long id);
  37 +
  38 + /**
32 * 删除排班计划 39 * 删除排班计划
33 * 40 *
34 * @param id 编号 41 * @param id 编号
@@ -39,8 +46,9 @@ public interface MesCalPlanService { @@ -39,8 +46,9 @@ public interface MesCalPlanService {
39 * 校验排班计划为草稿状态(确认后不允许编辑) 46 * 校验排班计划为草稿状态(确认后不允许编辑)
40 * 47 *
41 * @param planId 计划编号 48 * @param planId 计划编号
  49 + * @return 排班计划
42 */ 50 */
43 - void validatePlanPrepare(Long planId); 51 + MesCalPlanDO validatePlanPrepare(Long planId);
44 52
45 /** 53 /**
46 * 获得排班计划 54 * 获得排班计划
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java
@@ -65,15 +65,26 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { @@ -65,15 +65,26 @@ public class MesCalPlanServiceImpl implements MesCalPlanService {
65 } 65 }
66 // 1.3 校验编码唯一 66 // 1.3 校验编码唯一
67 validatePlanCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); 67 validatePlanCodeUnique(updateReqVO.getId(), updateReqVO.getCode());
68 - // 1.4 若 status 变为 CONFIRMED,校验班组数量  
69 - if (MesCalPlanStatusEnum.CONFIRMED.getStatus().equals(updateReqVO.getStatus())) {  
70 - validateTeamCountForConfirm(updateReqVO.getId(), updateReqVO.getShiftType());  
71 - }  
72 68
73 // 2. 更新 69 // 2. 更新
  70 + updateReqVO.setStatus(null); // 不允许通过 update 修改状态,状态变更走专用接口
74 MesCalPlanDO updateObj = BeanUtils.toBean(updateReqVO, MesCalPlanDO.class); 71 MesCalPlanDO updateObj = BeanUtils.toBean(updateReqVO, MesCalPlanDO.class);
75 planMapper.updateById(updateObj); 72 planMapper.updateById(updateObj);
  73 + }
76 74
  75 + @Override
  76 + @Transactional(rollbackFor = Exception.class)
  77 + public void confirmPlan(Long id) {
  78 + // 1.1 校验存在 + 校验状态为草稿
  79 + MesCalPlanDO plan = validatePlanPrepare(id);
  80 + // 1.2 校验班组数量与轮班方式匹配
  81 + validateTeamCountForConfirm(id, plan.getShiftType());
  82 +
  83 + // 2. 更新状态为已确认
  84 + MesCalPlanDO updateObj = new MesCalPlanDO();
  85 + updateObj.setId(id);
  86 + updateObj.setStatus(MesCalPlanStatusEnum.CONFIRMED.getStatus());
  87 + planMapper.updateById(updateObj);
77 // TODO @芋艿:确认时调用 calTeamshiftService.genRecords(planId) 生成排班记录,等 cal_team_shift 迁移后 88 // TODO @芋艿:确认时调用 calTeamshiftService.genRecords(planId) 生成排班记录,等 cal_team_shift 迁移后
78 } 89 }
79 90
@@ -101,11 +112,12 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { @@ -101,11 +112,12 @@ public class MesCalPlanServiceImpl implements MesCalPlanService {
101 } 112 }
102 113
103 @Override 114 @Override
104 - public void validatePlanPrepare(Long planId) { 115 + public MesCalPlanDO validatePlanPrepare(Long planId) {
105 MesCalPlanDO plan = validatePlanExists(planId); 116 MesCalPlanDO plan = validatePlanExists(planId);
106 if (ObjUtil.notEqual(MesCalPlanStatusEnum.PREPARE.getStatus(), plan.getStatus())) { 117 if (ObjUtil.notEqual(MesCalPlanStatusEnum.PREPARE.getStatus(), plan.getStatus())) {
107 throw exception(CAL_PLAN_NOT_PREPARE); 118 throw exception(CAL_PLAN_NOT_PREPARE);
108 } 119 }
  120 + return plan;
109 } 121 }
110 122
111 private MesCalPlanDO validatePlanExists(Long id) { 123 private MesCalPlanDO validatePlanExists(Long id) {