diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/MesCalPlanController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/MesCalPlanController.java index 5081f6c..9d8ff07 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/MesCalPlanController.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/cal/plan/MesCalPlanController.java @@ -51,6 +51,15 @@ public class MesCalPlanController { return success(true); } + @PutMapping("/confirm") + @Operation(summary = "确认排班计划") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('mes:cal-plan:update')") + public CommonResult confirmPlan(@RequestParam("id") Long id) { + planService.confirmPlan(id); + return success(true); + } + @DeleteMapping("/delete") @Operation(summary = "删除排班计划") @Parameter(name = "id", description = "编号", required = true) 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 945dc01..f42f0a1 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 @@ -29,6 +29,13 @@ public interface MesCalPlanService { void updatePlan(@Valid MesCalPlanSaveReqVO updateReqVO); /** + * 确认排班计划 + * + * @param id 编号 + */ + void confirmPlan(Long id); + + /** * 删除排班计划 * * @param id 编号 @@ -39,8 +46,9 @@ public interface MesCalPlanService { * 校验排班计划为草稿状态(确认后不允许编辑) * * @param planId 计划编号 + * @return 排班计划 */ - void validatePlanPrepare(Long planId); + MesCalPlanDO validatePlanPrepare(Long planId); /** * 获得排班计划 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 6cc7d8f..d28b262 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 @@ -65,15 +65,26 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { } // 1.3 校验编码唯一 validatePlanCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); - // 1.4 若 status 变为 CONFIRMED,校验班组数量 - if (MesCalPlanStatusEnum.CONFIRMED.getStatus().equals(updateReqVO.getStatus())) { - validateTeamCountForConfirm(updateReqVO.getId(), updateReqVO.getShiftType()); - } // 2. 更新 + updateReqVO.setStatus(null); // 不允许通过 update 修改状态,状态变更走专用接口 MesCalPlanDO updateObj = BeanUtils.toBean(updateReqVO, MesCalPlanDO.class); planMapper.updateById(updateObj); + } + @Override + @Transactional(rollbackFor = Exception.class) + public void confirmPlan(Long id) { + // 1.1 校验存在 + 校验状态为草稿 + MesCalPlanDO plan = validatePlanPrepare(id); + // 1.2 校验班组数量与轮班方式匹配 + validateTeamCountForConfirm(id, plan.getShiftType()); + + // 2. 更新状态为已确认 + MesCalPlanDO updateObj = new MesCalPlanDO(); + updateObj.setId(id); + updateObj.setStatus(MesCalPlanStatusEnum.CONFIRMED.getStatus()); + planMapper.updateById(updateObj); // TODO @芋艿:确认时调用 calTeamshiftService.genRecords(planId) 生成排班记录,等 cal_team_shift 迁移后 } @@ -101,11 +112,12 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { } @Override - public void validatePlanPrepare(Long planId) { + public MesCalPlanDO validatePlanPrepare(Long planId) { MesCalPlanDO plan = validatePlanExists(planId); if (ObjUtil.notEqual(MesCalPlanStatusEnum.PREPARE.getStatus(), plan.getStatus())) { throw exception(CAL_PLAN_NOT_PREPARE); } + return plan; } private MesCalPlanDO validatePlanExists(Long id) {