Commit d20d820dcb366f140877c46ef9230a95df0cddf6

Authored by YunaiV
1 parent 2c00cad1

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

yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/cal/plan/MesCalPlanMapper.java
@@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; 5 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
6 import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.MesCalPlanPageReqVO; 6 import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.MesCalPlanPageReqVO;
7 import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanDO; 7 import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanDO;
  8 +import com.baomidou.mybatisplus.core.toolkit.Wrappers;
8 import org.apache.ibatis.annotations.Mapper; 9 import org.apache.ibatis.annotations.Mapper;
9 10
10 /** 11 /**
@@ -31,4 +32,11 @@ public interface MesCalPlanMapper extends BaseMapperX<MesCalPlanDO> { @@ -31,4 +32,11 @@ public interface MesCalPlanMapper extends BaseMapperX<MesCalPlanDO> {
31 return selectOne(MesCalPlanDO::getCode, code); 32 return selectOne(MesCalPlanDO::getCode, code);
32 } 33 }
33 34
  35 + default void updateWithShiftFieldCleanup(MesCalPlanDO plan, boolean clearShiftMethod, boolean clearShiftCount) {
  36 + update(plan, Wrappers.<MesCalPlanDO>lambdaUpdate()
  37 + .eq(MesCalPlanDO::getId, plan.getId())
  38 + .set(clearShiftMethod, MesCalPlanDO::getShiftMethod, null)
  39 + .set(clearShiftCount, MesCalPlanDO::getShiftCount, null));
  40 + }
  41 +
34 } 42 }
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/cal/plan/MesCalPlanServiceImpl.java
@@ -12,7 +12,6 @@ import cn.iocoder.yudao.module.mes.enums.cal.MesCalShiftMethodEnum; @@ -12,7 +12,6 @@ import cn.iocoder.yudao.module.mes.enums.cal.MesCalShiftMethodEnum;
12 import cn.iocoder.yudao.module.mes.enums.cal.MesCalShiftTypeEnum; 12 import cn.iocoder.yudao.module.mes.enums.cal.MesCalShiftTypeEnum;
13 import cn.iocoder.yudao.module.mes.service.cal.team.MesCalTeamShiftService; 13 import cn.iocoder.yudao.module.mes.service.cal.team.MesCalTeamShiftService;
14 import cn.hutool.core.util.ObjUtil; 14 import cn.hutool.core.util.ObjUtil;
15 -import com.baomidou.mybatisplus.core.toolkit.Wrappers;  
16 import jakarta.annotation.Resource; 15 import jakarta.annotation.Resource;
17 import org.springframework.context.annotation.Lazy; 16 import org.springframework.context.annotation.Lazy;
18 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
@@ -78,9 +77,8 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { @@ -78,9 +77,8 @@ public class MesCalPlanServiceImpl implements MesCalPlanService {
78 // 1.3 校验编码唯一 77 // 1.3 校验编码唯一
79 validatePlanCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); 78 validatePlanCodeUnique(updateReqVO.getId(), updateReqVO.getCode());
80 79
81 - // 2. 更新  
82 - updateReqVO.setStatus(null); // 不允许通过 update 修改状态,状态变更走专用接口  
83 // 2.1 倒班字段联动清理:单白班不倒班,倒班方式非按天时不需要倒班天数 80 // 2.1 倒班字段联动清理:单白班不倒班,倒班方式非按天时不需要倒班天数
  81 + updateReqVO.setStatus(null); // 不允许通过 update 修改状态,状态变更走专用接口
84 boolean clearShiftMethod = MesCalShiftTypeEnum.SINGLE.getType().equals(updateReqVO.getShiftType()); 82 boolean clearShiftMethod = MesCalShiftTypeEnum.SINGLE.getType().equals(updateReqVO.getShiftType());
85 boolean clearShiftCount = clearShiftMethod || updateReqVO.getShiftMethod() == null 83 boolean clearShiftCount = clearShiftMethod || updateReqVO.getShiftMethod() == null
86 || !MesCalShiftMethodEnum.DAY.getMethod().equals(updateReqVO.getShiftMethod()); 84 || !MesCalShiftMethodEnum.DAY.getMethod().equals(updateReqVO.getShiftMethod());
@@ -90,12 +88,9 @@ public class MesCalPlanServiceImpl implements MesCalPlanService { @@ -90,12 +88,9 @@ public class MesCalPlanServiceImpl implements MesCalPlanService {
90 if (clearShiftCount) { 88 if (clearShiftCount) {
91 updateReqVO.setShiftCount(null); 89 updateReqVO.setShiftCount(null);
92 } 90 }
  91 + // 2.2 更新
93 MesCalPlanDO updateObj = BeanUtils.toBean(updateReqVO, MesCalPlanDO.class); 92 MesCalPlanDO updateObj = BeanUtils.toBean(updateReqVO, MesCalPlanDO.class);
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)); 93 + planMapper.updateWithShiftFieldCleanup(updateObj, clearShiftMethod, clearShiftCount);
99 } 94 }
100 95
101 @Override 96 @Override