Commit 2c00cad1a56cb213c8f20e5a4e85b1496093e9d2

Authored by wangli
Committed by YunaiV
1 parent b639029e

fix(mes): 修复排班计划倒班字段联动清理及生成排班异常

yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java
... ... @@ -137,6 +137,8 @@ public interface ErrorCodeConstants {
137 137 ErrorCode CAL_TEAM_SHIFT_NOT_EXISTS = new ErrorCode(1_040_201_200, "班组排班记录不存在");
138 138 ErrorCode CAL_TEAM_SHIFT_GENERATE_TEAM_NOT_ENOUGH = new ErrorCode(1_040_201_201, "班组数量不满足轮班方式要求");
139 139 ErrorCode CAL_TEAM_SHIFT_GENERATE_SHIFT_NOT_ENOUGH = new ErrorCode(1_040_201_202, "班次数量不满足轮班方式要求");
  140 + ErrorCode CAL_TEAM_SHIFT_GENERATE_SHIFT_COUNT_INVALID = new ErrorCode(1_040_201_203, "按天倒班必须填写合法的倒班天数");
  141 + ErrorCode CAL_TEAM_SHIFT_GENERATE_SHIFT_METHOD_INVALID = new ErrorCode(1_040_201_204, "不支持的倒班方式:{}");
140 142  
141 143 // ========== MES 日历排班-排班计划(1-040-202-000) ==========
142 144 ErrorCode CAL_PLAN_NOT_EXISTS = new ErrorCode(1_040_202_000, "排班计划不存在");
... ...
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
8 8 import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanDO;
9 9 import cn.iocoder.yudao.module.mes.dal.mysql.cal.plan.MesCalPlanMapper;
10 10 import cn.iocoder.yudao.module.mes.enums.cal.MesCalPlanStatusEnum;
  11 +import cn.iocoder.yudao.module.mes.enums.cal.MesCalShiftMethodEnum;
11 12 import cn.iocoder.yudao.module.mes.enums.cal.MesCalShiftTypeEnum;
12 13 import cn.iocoder.yudao.module.mes.service.cal.team.MesCalTeamShiftService;
13 14 import cn.hutool.core.util.ObjUtil;
  15 +import com.baomidou.mybatisplus.core.toolkit.Wrappers;
14 16 import jakarta.annotation.Resource;
15 17 import org.springframework.context.annotation.Lazy;
16 18 import org.springframework.stereotype.Service;
... ... @@ -78,8 +80,22 @@ public class MesCalPlanServiceImpl implements MesCalPlanService {
78 80  
79 81 // 2. 更新
80 82 updateReqVO.setStatus(null); // 不允许通过 update 修改状态,状态变更走专用接口
  83 + // 2.1 倒班字段联动清理:单白班不倒班,倒班方式非按天时不需要倒班天数
  84 + boolean clearShiftMethod = MesCalShiftTypeEnum.SINGLE.getType().equals(updateReqVO.getShiftType());
  85 + boolean clearShiftCount = clearShiftMethod || updateReqVO.getShiftMethod() == null
  86 + || !MesCalShiftMethodEnum.DAY.getMethod().equals(updateReqVO.getShiftMethod());
  87 + if (clearShiftMethod) {
  88 + updateReqVO.setShiftMethod(null);
  89 + }
  90 + if (clearShiftCount) {
  91 + updateReqVO.setShiftCount(null);
  92 + }
81 93 MesCalPlanDO updateObj = BeanUtils.toBean(updateReqVO, MesCalPlanDO.class);
82   - planMapper.updateById(updateObj);
  94 + // 2.2 entity 提供非 null 字段的 SET(NOT_NULL 策略),wrapper 负责显式 SET NULL 清掉旧值
  95 + planMapper.update(updateObj, Wrappers.<MesCalPlanDO>lambdaUpdate()
  96 + .eq(MesCalPlanDO::getId, updateObj.getId())
  97 + .set(clearShiftMethod, MesCalPlanDO::getShiftMethod, null)
  98 + .set(clearShiftCount, MesCalPlanDO::getShiftCount, null));
83 99 }
84 100  
85 101 @Override
... ...
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/team/MesCalTeamShiftServiceImpl.java
... ... @@ -25,6 +25,8 @@ import java.util.ArrayList;
25 25 import java.util.List;
26 26  
27 27 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  28 +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.CAL_TEAM_SHIFT_GENERATE_SHIFT_COUNT_INVALID;
  29 +import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.CAL_TEAM_SHIFT_GENERATE_SHIFT_METHOD_INVALID;
28 30 import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.CAL_TEAM_SHIFT_GENERATE_SHIFT_NOT_ENOUGH;
29 31 import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.CAL_TEAM_SHIFT_GENERATE_TEAM_NOT_ENOUGH;
30 32  
... ... @@ -78,8 +80,10 @@ public class MesCalTeamShiftServiceImpl implements MesCalTeamShiftService {
78 80 for (int i = 0; i < days; i++) {
79 81 LocalDate currentDate = startDate.plusDays(i);
80 82 LocalDateTime currentDay = currentDate.atStartOfDay();
81   - // 2.2.1 根据倒班方式计算 shiftIndex
82   - shiftIndex = calculateShiftIndex(shiftIndex, i, currentDate, startDate, plan);
  83 + // 2.2.1 根据倒班方式计算 shiftIndex 单白班不倒班,跳过
  84 + if (!MesCalShiftTypeEnum.SINGLE.getType().equals(plan.getShiftType())) {
  85 + shiftIndex = calculateShiftIndex(shiftIndex, i, currentDate, startDate, plan);
  86 + }
83 87 // 2.2.2 根据轮班方式生成排班记录,收集到列表
84 88 buildRecordsForDay(allRecords, planId, currentDay, shiftIndex, plan.getShiftType(), teams, shifts);
85 89 }
... ... @@ -119,11 +123,15 @@ public class MesCalTeamShiftServiceImpl implements MesCalTeamShiftService {
119 123 }
120 124 } else if (MesCalShiftMethodEnum.DAY.getMethod().equals(plan.getShiftMethod())) {
121 125 // 按天轮班:到了指定轮班天数的倍数
122   - if (dayOffset % plan.getShiftCount() == 0) {
  126 + Integer shiftCount = plan.getShiftCount();
  127 + if (shiftCount == null || shiftCount <= 0) {
  128 + throw exception(CAL_TEAM_SHIFT_GENERATE_SHIFT_COUNT_INVALID);
  129 + }
  130 + if (dayOffset % shiftCount == 0) {
123 131 return shiftIndex + 1;
124 132 }
125 133 } else {
126   - throw new IllegalArgumentException("不支持的倒班方式: " + plan.getShiftMethod());
  134 + throw exception(CAL_TEAM_SHIFT_GENERATE_SHIFT_METHOD_INVALID, plan.getShiftMethod());
127 135 }
128 136 return shiftIndex;
129 137 }
... ...