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

This commit is contained in:
YunaiV
2026-08-30 14:39:34 +08:00
parent 2c00cad1a5
commit d20d820dcb
2 changed files with 11 additions and 8 deletions
@@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.MesCalPlanPageReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanDO;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.ibatis.annotations.Mapper;
/**
@@ -31,4 +32,11 @@ public interface MesCalPlanMapper extends BaseMapperX<MesCalPlanDO> {
return selectOne(MesCalPlanDO::getCode, code);
}
default void updateWithShiftFieldCleanup(MesCalPlanDO plan, boolean clearShiftMethod, boolean clearShiftCount) {
update(plan, Wrappers.<MesCalPlanDO>lambdaUpdate()
.eq(MesCalPlanDO::getId, plan.getId())
.set(clearShiftMethod, MesCalPlanDO::getShiftMethod, null)
.set(clearShiftCount, MesCalPlanDO::getShiftCount, null));
}
}
@@ -12,7 +12,6 @@ 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,9 +77,8 @@ public class MesCalPlanServiceImpl implements MesCalPlanService {
// 1.3 校验编码唯一
validatePlanCodeUnique(updateReqVO.getId(), updateReqVO.getCode());
// 2. 更新
updateReqVO.setStatus(null); // 不允许通过 update 修改状态,状态变更走专用接口
// 2.1 倒班字段联动清理:单白班不倒班,倒班方式非按天时不需要倒班天数
updateReqVO.setStatus(null); // 不允许通过 update 修改状态,状态变更走专用接口
boolean clearShiftMethod = MesCalShiftTypeEnum.SINGLE.getType().equals(updateReqVO.getShiftType());
boolean clearShiftCount = clearShiftMethod || updateReqVO.getShiftMethod() == null
|| !MesCalShiftMethodEnum.DAY.getMethod().equals(updateReqVO.getShiftMethod());
@@ -90,12 +88,9 @@ public class MesCalPlanServiceImpl implements MesCalPlanService {
if (clearShiftCount) {
updateReqVO.setShiftCount(null);
}
// 2.2 更新
MesCalPlanDO updateObj = BeanUtils.toBean(updateReqVO, MesCalPlanDO.class);
// 2.2 entity 提供非 null 字段的 SET(NOT_NULL 策略),wrapper 负责显式 SET NULL 清掉旧值
planMapper.update(updateObj, Wrappers.<MesCalPlanDO>lambdaUpdate()
.eq(MesCalPlanDO::getId, updateObj.getId())
.set(clearShiftMethod, MesCalPlanDO::getShiftMethod, null)
.set(clearShiftCount, MesCalPlanDO::getShiftCount, null));
planMapper.updateWithShiftFieldCleanup(updateObj, clearShiftMethod, clearShiftCount);
}
@Override