Commit f801196822b3bc298abfb76cd62ee2b8f87509eb
1 parent
fcf7db04
✨ feat(mes): 新增盘点方案保存数据校验逻辑,优化动态盘点时间处理
Showing
1 changed file
with
22 additions
and
4 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/stocktaking/plan/MesWmStockTakingPlanServiceImpl.java
| @@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.mes.controller.admin.wm.stocktaking.plan.vo.MesWm | @@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.mes.controller.admin.wm.stocktaking.plan.vo.MesWm | ||
| 10 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.stocktaking.plan.MesWmStockTakingPlanDO; | 10 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.stocktaking.plan.MesWmStockTakingPlanDO; |
| 11 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.stocktaking.plan.MesWmStockTakingPlanParamDO; | 11 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.stocktaking.plan.MesWmStockTakingPlanParamDO; |
| 12 | import cn.iocoder.yudao.module.mes.dal.mysql.wm.stocktaking.plan.MesWmStockTakingPlanMapper; | 12 | import cn.iocoder.yudao.module.mes.dal.mysql.wm.stocktaking.plan.MesWmStockTakingPlanMapper; |
| 13 | +import cn.iocoder.yudao.module.mes.enums.wm.MesWmStockTakingTypeEnum; | ||
| 13 | import jakarta.annotation.Resource; | 14 | import jakarta.annotation.Resource; |
| 14 | import org.springframework.stereotype.Service; | 15 | import org.springframework.stereotype.Service; |
| 15 | import org.springframework.transaction.annotation.Transactional; | 16 | import org.springframework.transaction.annotation.Transactional; |
| @@ -38,8 +39,8 @@ public class MesWmStockTakingPlanServiceImpl implements MesWmStockTakingPlanServ | @@ -38,8 +39,8 @@ public class MesWmStockTakingPlanServiceImpl implements MesWmStockTakingPlanServ | ||
| 38 | 39 | ||
| 39 | @Override | 40 | @Override |
| 40 | public Long createStockTakingPlan(MesWmStockTakingPlanSaveReqVO createReqVO) { | 41 | public Long createStockTakingPlan(MesWmStockTakingPlanSaveReqVO createReqVO) { |
| 41 | - // 校验 code 的唯一性 | ||
| 42 | - validatePlanCodeUnique(null, createReqVO.getCode()); | 42 | + // 校验并处理保存数据 |
| 43 | + validatePlanSaveData(createReqVO); | ||
| 43 | 44 | ||
| 44 | // 插入数据 | 45 | // 插入数据 |
| 45 | MesWmStockTakingPlanDO plan = BeanUtils.toBean(createReqVO, MesWmStockTakingPlanDO.class); | 46 | MesWmStockTakingPlanDO plan = BeanUtils.toBean(createReqVO, MesWmStockTakingPlanDO.class); |
| @@ -52,8 +53,8 @@ public class MesWmStockTakingPlanServiceImpl implements MesWmStockTakingPlanServ | @@ -52,8 +53,8 @@ public class MesWmStockTakingPlanServiceImpl implements MesWmStockTakingPlanServ | ||
| 52 | public void updateStockTakingPlan(MesWmStockTakingPlanSaveReqVO updateReqVO) { | 53 | public void updateStockTakingPlan(MesWmStockTakingPlanSaveReqVO updateReqVO) { |
| 53 | // 校验盘点方案存在,并且是可编辑状态 | 54 | // 校验盘点方案存在,并且是可编辑状态 |
| 54 | validatePlanEditable(updateReqVO.getId()); | 55 | validatePlanEditable(updateReqVO.getId()); |
| 55 | - // 校验 code 的唯一性 | ||
| 56 | - validatePlanCodeUnique(updateReqVO.getId(), updateReqVO.getCode()); | 56 | + // 校验并处理保存数据 |
| 57 | + validatePlanSaveData(updateReqVO); | ||
| 57 | 58 | ||
| 58 | // 更新数据 | 59 | // 更新数据 |
| 59 | MesWmStockTakingPlanDO updateObj = BeanUtils.toBean(updateReqVO, MesWmStockTakingPlanDO.class); | 60 | MesWmStockTakingPlanDO updateObj = BeanUtils.toBean(updateReqVO, MesWmStockTakingPlanDO.class); |
| @@ -152,4 +153,21 @@ public class MesWmStockTakingPlanServiceImpl implements MesWmStockTakingPlanServ | @@ -152,4 +153,21 @@ public class MesWmStockTakingPlanServiceImpl implements MesWmStockTakingPlanServ | ||
| 152 | return plan; | 153 | return plan; |
| 153 | } | 154 | } |
| 154 | 155 | ||
| 156 | + private void validatePlanSaveData(MesWmStockTakingPlanSaveReqVO saveReqVO) { | ||
| 157 | + // 校验 code 的唯一性 | ||
| 158 | + validatePlanCodeUnique(saveReqVO.getId(), saveReqVO.getCode()); | ||
| 159 | + | ||
| 160 | + // 校验/处理动态盘点时间 | ||
| 161 | + if (ObjUtil.notEqual(MesWmStockTakingTypeEnum.DYNAMIC.getType(), saveReqVO.getType())) { | ||
| 162 | + // 非动态盘点类型清空时间字段 | ||
| 163 | + saveReqVO.setStartTime(null); | ||
| 164 | + saveReqVO.setEndTime(null); | ||
| 165 | + } else { | ||
| 166 | + if (saveReqVO.getStartTime() == null || saveReqVO.getEndTime() == null | ||
| 167 | + || saveReqVO.getStartTime().compareTo(saveReqVO.getEndTime()) >= 0) { | ||
| 168 | + throw exception(WM_STOCK_TAKING_PLAN_DYNAMIC_TIME_INVALID); | ||
| 169 | + } | ||
| 170 | + } | ||
| 171 | + } | ||
| 172 | + | ||
| 155 | } | 173 | } |