diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/cal/plan/MesCalPlanMapper.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/cal/plan/MesCalPlanMapper.java index d2cd4b7..9478a13 100644 --- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/cal/plan/MesCalPlanMapper.java +++ b/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; 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 { return selectOne(MesCalPlanDO::getCode, code); } + default void updateWithShiftFieldCleanup(MesCalPlanDO plan, boolean clearShiftMethod, boolean clearShiftCount) { + update(plan, Wrappers.lambdaUpdate() + .eq(MesCalPlanDO::getId, plan.getId()) + .set(clearShiftMethod, MesCalPlanDO::getShiftMethod, null) + .set(clearShiftCount, MesCalPlanDO::getShiftCount, null)); + } + } 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 c751329..68631dd 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 @@ -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.lambdaUpdate() - .eq(MesCalPlanDO::getId, updateObj.getId()) - .set(clearShiftMethod, MesCalPlanDO::getShiftMethod, null) - .set(clearShiftCount, MesCalPlanDO::getShiftCount, null)); + planMapper.updateWithShiftFieldCleanup(updateObj, clearShiftMethod, clearShiftCount); } @Override