From 2c00cad1a56cb213c8f20e5a4e85b1496093e9d2 Mon Sep 17 00:00:00 2001 From: wangli Date: Thu, 13 Aug 2026 14:12:26 +0800 Subject: [PATCH] fix(mes): 修复排班计划倒班字段联动清理及生成排班异常 --- 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/MesCalPlanServiceImpl.java | 18 +++++++++++++++++- yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftServiceImpl.java | 16 ++++++++++++---- 3 files changed, 31 insertions(+), 5 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 14c22c2..f2f805d 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 @@ -137,6 +137,8 @@ public interface ErrorCodeConstants { ErrorCode CAL_TEAM_SHIFT_NOT_EXISTS = new ErrorCode(1_040_201_200, "班组排班记录不存在"); ErrorCode CAL_TEAM_SHIFT_GENERATE_TEAM_NOT_ENOUGH = new ErrorCode(1_040_201_201, "班组数量不满足轮班方式要求"); ErrorCode CAL_TEAM_SHIFT_GENERATE_SHIFT_NOT_ENOUGH = new ErrorCode(1_040_201_202, "班次数量不满足轮班方式要求"); + ErrorCode CAL_TEAM_SHIFT_GENERATE_SHIFT_COUNT_INVALID = new ErrorCode(1_040_201_203, "按天倒班必须填写合法的倒班天数"); + ErrorCode CAL_TEAM_SHIFT_GENERATE_SHIFT_METHOD_INVALID = new ErrorCode(1_040_201_204, "不支持的倒班方式:{}"); // ========== MES 日历排班-排班计划(1-040-202-000) ========== ErrorCode CAL_PLAN_NOT_EXISTS = new ErrorCode(1_040_202_000, "排班计划不存在"); 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 8148102..c751329 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 @@ -8,9 +8,11 @@ import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.MesCalPlanSaveRe import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanDO; import cn.iocoder.yudao.module.mes.dal.mysql.cal.plan.MesCalPlanMapper; import cn.iocoder.yudao.module.mes.enums.cal.MesCalPlanStatusEnum; +import cn.iocoder.yudao.module.mes.enums.cal.MesCalShiftMethodEnum; import cn.iocoder.yudao.module.mes.enums.cal.MesCalShiftTypeEnum; import cn.iocoder.yudao.module.mes.service.cal.team.MesCalTeamShiftService; import cn.hutool.core.util.ObjUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import jakarta.annotation.Resource; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; @@ -78,8 +80,22 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { // 2. 更新 updateReqVO.setStatus(null); // 不允许通过 update 修改状态,状态变更走专用接口 + // 2.1 倒班字段联动清理:单白班不倒班,倒班方式非按天时不需要倒班天数 + boolean clearShiftMethod = MesCalShiftTypeEnum.SINGLE.getType().equals(updateReqVO.getShiftType()); + boolean clearShiftCount = clearShiftMethod || updateReqVO.getShiftMethod() == null + || !MesCalShiftMethodEnum.DAY.getMethod().equals(updateReqVO.getShiftMethod()); + if (clearShiftMethod) { + updateReqVO.setShiftMethod(null); + } + if (clearShiftCount) { + updateReqVO.setShiftCount(null); + } MesCalPlanDO updateObj = BeanUtils.toBean(updateReqVO, MesCalPlanDO.class); - planMapper.updateById(updateObj); + // 2.2 entity 提供非 null 字段的 SET(NOT_NULL 策略),wrapper 负责显式 SET NULL 清掉旧值 + planMapper.update(updateObj, Wrappers.lambdaUpdate() + .eq(MesCalPlanDO::getId, updateObj.getId()) + .set(clearShiftMethod, MesCalPlanDO::getShiftMethod, null) + .set(clearShiftCount, MesCalPlanDO::getShiftCount, null)); } @Override diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftServiceImpl.java index 8dbb2dc..52fa763 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftServiceImpl.java +++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftServiceImpl.java @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.CAL_TEAM_SHIFT_GENERATE_SHIFT_COUNT_INVALID; +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.CAL_TEAM_SHIFT_GENERATE_SHIFT_METHOD_INVALID; import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.CAL_TEAM_SHIFT_GENERATE_SHIFT_NOT_ENOUGH; import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.CAL_TEAM_SHIFT_GENERATE_TEAM_NOT_ENOUGH; @@ -78,8 +80,10 @@ public class MesCalTeamShiftServiceImpl implements MesCalTeamShiftService { for (int i = 0; i < days; i++) { LocalDate currentDate = startDate.plusDays(i); LocalDateTime currentDay = currentDate.atStartOfDay(); - // 2.2.1 根据倒班方式计算 shiftIndex - shiftIndex = calculateShiftIndex(shiftIndex, i, currentDate, startDate, plan); + // 2.2.1 根据倒班方式计算 shiftIndex 单白班不倒班,跳过 + if (!MesCalShiftTypeEnum.SINGLE.getType().equals(plan.getShiftType())) { + shiftIndex = calculateShiftIndex(shiftIndex, i, currentDate, startDate, plan); + } // 2.2.2 根据轮班方式生成排班记录,收集到列表 buildRecordsForDay(allRecords, planId, currentDay, shiftIndex, plan.getShiftType(), teams, shifts); } @@ -119,11 +123,15 @@ public class MesCalTeamShiftServiceImpl implements MesCalTeamShiftService { } } else if (MesCalShiftMethodEnum.DAY.getMethod().equals(plan.getShiftMethod())) { // 按天轮班:到了指定轮班天数的倍数 - if (dayOffset % plan.getShiftCount() == 0) { + Integer shiftCount = plan.getShiftCount(); + if (shiftCount == null || shiftCount <= 0) { + throw exception(CAL_TEAM_SHIFT_GENERATE_SHIFT_COUNT_INVALID); + } + if (dayOffset % shiftCount == 0) { return shiftIndex + 1; } } else { - throw new IllegalArgumentException("不支持的倒班方式: " + plan.getShiftMethod()); + throw exception(CAL_TEAM_SHIFT_GENERATE_SHIFT_METHOD_INVALID, plan.getShiftMethod()); } return shiftIndex; } -- libgit2 0.21.4