Commit 756fc771960629d6c518473cf4c60e27e8bce73c
1 parent
5fbd35bb
✨ feat(mes): 添加盘点方案状态更新功能及参数校验
新增更新盘点方案状态的接口,确保在启用状态时,相关参数不为空。 同时,更新了相关权限控制和错误码定义,提升了系统的健壮性和用户体验。
Showing
8 changed files
with
62 additions
and
28 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/wm/stocktaking/plan/MesWmStockTakingPlanController.java
| ... | ... | @@ -40,23 +40,36 @@ public class MesWmStockTakingPlanController { |
| 40 | 40 | |
| 41 | 41 | @PostMapping("/create") |
| 42 | 42 | @Operation(summary = "创建盘点方案") |
| 43 | - @PreAuthorize("@ss.hasPermission('mes:wm-stocktaking-plan:create')") | |
| 43 | + @PreAuthorize("@ss.hasPermission('mes:wm-stock-taking-plan:create')") | |
| 44 | 44 | public CommonResult<Long> createStockTakingPlan(@Valid @RequestBody MesWmStockTakingPlanSaveReqVO createReqVO) { |
| 45 | 45 | return success(stockTakingPlanService.createStockTakingPlan(createReqVO)); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | @PutMapping("/update") |
| 49 | 49 | @Operation(summary = "修改盘点方案") |
| 50 | - @PreAuthorize("@ss.hasPermission('mes:wm-stocktaking-plan:update')") | |
| 50 | + @PreAuthorize("@ss.hasPermission('mes:wm-stock-taking-plan:update')") | |
| 51 | 51 | public CommonResult<Boolean> updateStockTakingPlan(@Valid @RequestBody MesWmStockTakingPlanSaveReqVO updateReqVO) { |
| 52 | 52 | stockTakingPlanService.updateStockTakingPlan(updateReqVO); |
| 53 | 53 | return success(true); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | + @PutMapping("/update-status") | |
| 57 | + @Operation(summary = "更新盘点方案状态") | |
| 58 | + @Parameters({ | |
| 59 | + @Parameter(name = "id", description = "编号", required = true), | |
| 60 | + @Parameter(name = "status", description = "状态", required = true) | |
| 61 | + }) | |
| 62 | + @PreAuthorize("@ss.hasPermission('mes:wm-stock-taking-plan:update')") | |
| 63 | + public CommonResult<Boolean> updateStockTakingPlanStatus(@RequestParam("id") Long id, | |
| 64 | + @RequestParam("status") Integer status) { | |
| 65 | + stockTakingPlanService.updateStockTakingPlanStatus(id, status); | |
| 66 | + return success(true); | |
| 67 | + } | |
| 68 | + | |
| 56 | 69 | @DeleteMapping("/delete") |
| 57 | 70 | @Operation(summary = "删除盘点方案") |
| 58 | 71 | @Parameter(name = "id", description = "编号", required = true) |
| 59 | - @PreAuthorize("@ss.hasPermission('mes:wm-stocktaking-plan:delete')") | |
| 72 | + @PreAuthorize("@ss.hasPermission('mes:wm-stock-taking-plan:delete')") | |
| 60 | 73 | public CommonResult<Boolean> deleteStockTakingPlan(@RequestParam("id") Long id) { |
| 61 | 74 | stockTakingPlanService.deleteStockTakingPlan(id); |
| 62 | 75 | return success(true); |
| ... | ... | @@ -65,7 +78,7 @@ public class MesWmStockTakingPlanController { |
| 65 | 78 | @GetMapping("/get") |
| 66 | 79 | @Operation(summary = "获得盘点方案") |
| 67 | 80 | @Parameter(name = "id", description = "编号", required = true) |
| 68 | - @PreAuthorize("@ss.hasPermission('mes:wm-stocktaking-plan:query')") | |
| 81 | + @PreAuthorize("@ss.hasPermission('mes:wm-stock-taking-plan:query')") | |
| 69 | 82 | public CommonResult<MesWmStockTakingPlanRespVO> getStockTakingPlan(@RequestParam("id") Long id) { |
| 70 | 83 | MesWmStockTakingPlanDO plan = stockTakingPlanService.getStockTakingPlan(id); |
| 71 | 84 | return success(plan == null ? null : BeanUtils.toBean(plan, MesWmStockTakingPlanRespVO.class)); |
| ... | ... | @@ -73,7 +86,7 @@ public class MesWmStockTakingPlanController { |
| 73 | 86 | |
| 74 | 87 | @GetMapping("/page") |
| 75 | 88 | @Operation(summary = "获得盘点方案分页") |
| 76 | - @PreAuthorize("@ss.hasPermission('mes:wm-stocktaking-plan:query')") | |
| 89 | + @PreAuthorize("@ss.hasPermission('mes:wm-stock-taking-plan:query')") | |
| 77 | 90 | public CommonResult<PageResult<MesWmStockTakingPlanRespVO>> getStockTakingPlanPage(@Valid MesWmStockTakingPlanPageReqVO pageReqVO) { |
| 78 | 91 | PageResult<MesWmStockTakingPlanDO> pageResult = stockTakingPlanService.getStockTakingPlanPage(pageReqVO); |
| 79 | 92 | return success(BeanUtils.toBean(pageResult, MesWmStockTakingPlanRespVO.class)); |
| ... | ... | @@ -81,7 +94,7 @@ public class MesWmStockTakingPlanController { |
| 81 | 94 | |
| 82 | 95 | @GetMapping("/export-excel") |
| 83 | 96 | @Operation(summary = "导出盘点方案 Excel") |
| 84 | - @PreAuthorize("@ss.hasPermission('mes:wm-stocktaking-plan:export')") | |
| 97 | + @PreAuthorize("@ss.hasPermission('mes:wm-stock-taking-plan:export')") | |
| 85 | 98 | @ApiAccessLog(operateType = EXPORT) |
| 86 | 99 | public void exportStockTakingPlanExcel(@Valid MesWmStockTakingPlanPageReqVO pageReqVO, |
| 87 | 100 | HttpServletResponse response) throws IOException { |
| ... | ... | @@ -91,23 +104,13 @@ public class MesWmStockTakingPlanController { |
| 91 | 104 | BeanUtils.toBean(pageResult.getList(), MesWmStockTakingPlanRespVO.class)); |
| 92 | 105 | } |
| 93 | 106 | |
| 94 | - private List<MesWmStockTakingPlanRespVO> buildRespVOList(List<MesWmStockTakingPlanDO> list, boolean includeParams) { | |
| 95 | - if (CollUtil.isEmpty(list)) { | |
| 96 | - return Collections.emptyList(); | |
| 97 | - } | |
| 98 | - final Map<Long, List<MesWmStockTakingPlanParamRespVO>> finalParamMap; | |
| 99 | - if (includeParams) { | |
| 100 | - Collection<Long> planIds = convertSet(list, MesWmStockTakingPlanDO::getId); | |
| 101 | - Map<Long, List<MesWmStockTakingPlanParamRespVO>> paramMap = new java.util.HashMap<>(); | |
| 102 | - stockTakingPlanParamService.getStockTakingPlanParamMap(planIds) | |
| 103 | - .forEach((planId, params) -> paramMap.put(planId, | |
| 104 | - BeanUtils.toBean(params, MesWmStockTakingPlanParamRespVO.class))); | |
| 105 | - finalParamMap = paramMap; | |
| 106 | - } else { | |
| 107 | - finalParamMap = Collections.emptyMap(); | |
| 108 | - } | |
| 109 | - return BeanUtils.toBean(list, MesWmStockTakingPlanRespVO.class, | |
| 110 | - vo -> vo.setParams(finalParamMap.getOrDefault(vo.getId(), Collections.emptyList()))); | |
| 107 | + @GetMapping("/simple-list") | |
| 108 | + @Operation(summary = "获得已启用的盘点方案精简列表") | |
| 109 | + @PreAuthorize("@ss.hasPermission('mes:wm-stock-taking-task:query')") | |
| 110 | + public CommonResult<List<MesWmStockTakingPlanRespVO>> getEnabledStockTakingPlanSimpleList() { | |
| 111 | + List<MesWmStockTakingPlanDO> list = stockTakingPlanService.getStockTakingPlanListByStatus( | |
| 112 | + CommonStatusEnum.ENABLE.getStatus()); | |
| 113 | + return success(BeanUtils.toBean(list, MesWmStockTakingPlanRespVO.class)); | |
| 111 | 114 | } |
| 112 | 115 | |
| 113 | 116 | } | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/wm/stocktaking/plan/MesWmStockTakingPlanParamController.java
| ... | ... | @@ -30,14 +30,14 @@ public class MesWmStockTakingPlanParamController { |
| 30 | 30 | |
| 31 | 31 | @PostMapping("/create") |
| 32 | 32 | @Operation(summary = "创建盘点方案参数") |
| 33 | - @PreAuthorize("@ss.hasPermission('mes:wm-stocktaking-plan:update')") | |
| 33 | + @PreAuthorize("@ss.hasPermission('mes:wm-stock-taking-plan:update')") | |
| 34 | 34 | public CommonResult<Long> createStockTakingPlanParam(@Valid @RequestBody MesWmStockTakingPlanParamSaveReqVO createReqVO) { |
| 35 | 35 | return success(stockTakingPlanParamService.createStockTakingPlanParam(createReqVO)); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | @PutMapping("/update") |
| 39 | 39 | @Operation(summary = "修改盘点方案参数") |
| 40 | - @PreAuthorize("@ss.hasPermission('mes:wm-stocktaking-plan:update')") | |
| 40 | + @PreAuthorize("@ss.hasPermission('mes:wm-stock-taking-plan:update')") | |
| 41 | 41 | public CommonResult<Boolean> updateStockTakingPlanParam(@Valid @RequestBody MesWmStockTakingPlanParamSaveReqVO updateReqVO) { |
| 42 | 42 | stockTakingPlanParamService.updateStockTakingPlanParam(updateReqVO); |
| 43 | 43 | return success(true); |
| ... | ... | @@ -46,7 +46,7 @@ public class MesWmStockTakingPlanParamController { |
| 46 | 46 | @DeleteMapping("/delete") |
| 47 | 47 | @Operation(summary = "删除盘点方案参数") |
| 48 | 48 | @Parameter(name = "id", description = "编号", required = true) |
| 49 | - @PreAuthorize("@ss.hasPermission('mes:wm-stocktaking-plan:update')") | |
| 49 | + @PreAuthorize("@ss.hasPermission('mes:wm-stock-taking-plan:update')") | |
| 50 | 50 | public CommonResult<Boolean> deleteStockTakingPlanParam(@RequestParam("id") Long id) { |
| 51 | 51 | stockTakingPlanParamService.deleteStockTakingPlanParam(id); |
| 52 | 52 | return success(true); |
| ... | ... | @@ -55,7 +55,7 @@ public class MesWmStockTakingPlanParamController { |
| 55 | 55 | @GetMapping("/get") |
| 56 | 56 | @Operation(summary = "获得盘点方案参数") |
| 57 | 57 | @Parameter(name = "id", description = "编号", required = true) |
| 58 | - @PreAuthorize("@ss.hasPermission('mes:wm-stocktaking-plan:query')") | |
| 58 | + @PreAuthorize("@ss.hasPermission('mes:wm-stock-taking-plan:query')") | |
| 59 | 59 | public CommonResult<MesWmStockTakingPlanParamRespVO> getStockTakingPlanParam(@RequestParam("id") Long id) { |
| 60 | 60 | MesWmStockTakingPlanParamDO param = stockTakingPlanParamService.getStockTakingPlanParam(id); |
| 61 | 61 | return success(param == null ? null : BeanUtils.toBean(param, MesWmStockTakingPlanParamRespVO.class)); | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/ErrorCodeConstants.java
| ... | ... | @@ -475,6 +475,7 @@ public interface ErrorCodeConstants { |
| 475 | 475 | ErrorCode WM_STOCK_TAKING_PLAN_NOT_DISABLED = new ErrorCode(1_040_714_102, "只有禁用状态的盘点方案才允许修改、删除或维护参数"); |
| 476 | 476 | ErrorCode WM_STOCK_TAKING_PLAN_NOT_ENABLED = new ErrorCode(1_040_714_103, "只有启用状态的盘点方案才允许生成任务"); |
| 477 | 477 | ErrorCode WM_STOCK_TAKING_PLAN_PARAM_NOT_EXISTS = new ErrorCode(1_040_714_104, "盘点方案参数不存在"); |
| 478 | + ErrorCode WM_STOCK_TAKING_PLAN_PARAM_EMPTY = new ErrorCode(1_040_714_105, "盘点方案参数不能为空,请先配置盘点参数"); | |
| 478 | 479 | ErrorCode WM_STOCK_TAKING_TASK_NOT_EXISTS = new ErrorCode(1_040_714_110, "盘点任务不存在"); |
| 479 | 480 | ErrorCode WM_STOCK_TAKING_TASK_CODE_DUPLICATE = new ErrorCode(1_040_714_111, "盘点任务编码已存在"); |
| 480 | 481 | ErrorCode WM_STOCK_TAKING_TASK_NOT_PREPARE = new ErrorCode(1_040_714_112, "只有草稿状态的盘点任务才允许此操作"); | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/MesBizTypeConstants.java
| ... | ... | @@ -58,4 +58,8 @@ public final class MesBizTypeConstants { |
| 58 | 58 | public static final int MD_USER = 604; // 人员:系统用户 |
| 59 | 59 | public static final int MD_CLIENT = 605; // 客户:MesMdClientDO |
| 60 | 60 | |
| 61 | + // ========== 特殊类型(非业务实体) [900, 1000) ========== | |
| 62 | + | |
| 63 | + public static final int QUALITY_STATUS = 900; // 质量状态:非实体,用于盘点等场景的状态筛选 | |
| 64 | + | |
| 61 | 65 | } | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/wm/MesWmStockTakingPlanParamTypeEnum.java
| ... | ... | @@ -18,7 +18,8 @@ public enum MesWmStockTakingPlanParamTypeEnum implements ArrayValuable<Integer> |
| 18 | 18 | LOCATION(MesBizTypeConstants.WM_LOCATION, "库区"), |
| 19 | 19 | AREA(MesBizTypeConstants.WM_AREA, "库位"), |
| 20 | 20 | ITEM(MesBizTypeConstants.MD_ITEM, "物料"), |
| 21 | - BATCH(MesBizTypeConstants.WM_BATCH, "批次"); | |
| 21 | + BATCH(MesBizTypeConstants.WM_BATCH, "批次"), | |
| 22 | + QUALITY_STATUS(MesBizTypeConstants.QUALITY_STATUS, "质量状态"); | |
| 22 | 23 | |
| 23 | 24 | public static final Integer[] ARRAYS = Arrays.stream(values()) |
| 24 | 25 | .map(MesWmStockTakingPlanParamTypeEnum::getType).toArray(Integer[]::new); | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/stocktaking/plan/MesWmStockTakingPlanParamService.java
| ... | ... | @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.mes.controller.admin.wm.stocktaking.plan.vo.param |
| 6 | 6 | import cn.iocoder.yudao.module.mes.dal.dataobject.wm.stocktaking.plan.MesWmStockTakingPlanParamDO; |
| 7 | 7 | import jakarta.validation.Valid; |
| 8 | 8 | |
| 9 | +import java.util.List; | |
| 10 | + | |
| 9 | 11 | /** |
| 10 | 12 | * MES 盘点方案参数 Service 接口 |
| 11 | 13 | */ |
| ... | ... | @@ -64,4 +66,12 @@ public interface MesWmStockTakingPlanParamService { |
| 64 | 66 | */ |
| 65 | 67 | MesWmStockTakingPlanParamDO validateStockTakingPlanParamExists(Long id); |
| 66 | 68 | |
| 69 | + /** | |
| 70 | + * 根据盘点方案编号获取参数列表 | |
| 71 | + * | |
| 72 | + * @param planId 盘点方案编号 | |
| 73 | + * @return 盘点方案参数列表 | |
| 74 | + */ | |
| 75 | + List<MesWmStockTakingPlanParamDO> getStockTakingPlanParamListByPlanId(Long planId); | |
| 76 | + | |
| 67 | 77 | } | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/stocktaking/plan/MesWmStockTakingPlanParamServiceImpl.java
| ... | ... | @@ -11,6 +11,8 @@ import org.springframework.context.annotation.Lazy; |
| 11 | 11 | import org.springframework.stereotype.Service; |
| 12 | 12 | import org.springframework.validation.annotation.Validated; |
| 13 | 13 | |
| 14 | +import java.util.List; | |
| 15 | + | |
| 14 | 16 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 15 | 17 | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_STOCK_TAKING_PLAN_PARAM_NOT_EXISTS; |
| 16 | 18 | |
| ... | ... | @@ -86,4 +88,9 @@ public class MesWmStockTakingPlanParamServiceImpl implements MesWmStockTakingPla |
| 86 | 88 | return param; |
| 87 | 89 | } |
| 88 | 90 | |
| 91 | + @Override | |
| 92 | + public List<MesWmStockTakingPlanParamDO> getStockTakingPlanParamListByPlanId(Long planId) { | |
| 93 | + return stockTakingPlanParamMapper.selectListByPlanId(planId); | |
| 94 | + } | |
| 95 | + | |
| 89 | 96 | } | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/stocktaking/plan/MesWmStockTakingPlanServiceImpl.java
| ... | ... | @@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 8 | 8 | import cn.iocoder.yudao.module.mes.controller.admin.wm.stocktaking.plan.vo.MesWmStockTakingPlanPageReqVO; |
| 9 | 9 | import cn.iocoder.yudao.module.mes.controller.admin.wm.stocktaking.plan.vo.MesWmStockTakingPlanSaveReqVO; |
| 10 | 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 | 12 | import cn.iocoder.yudao.module.mes.dal.mysql.wm.stocktaking.plan.MesWmStockTakingPlanMapper; |
| 12 | 13 | import jakarta.annotation.Resource; |
| 13 | 14 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -73,6 +74,13 @@ public class MesWmStockTakingPlanServiceImpl implements MesWmStockTakingPlanServ |
| 73 | 74 | public void updateStockTakingPlanStatus(Long id, Integer status) { |
| 74 | 75 | // 校验盘点方案存在 |
| 75 | 76 | validateStockTakingPlanExists(id); |
| 77 | + // 开启时,需要校验 params 非空 | |
| 78 | + if (CommonStatusEnum.isEnable(status)) { | |
| 79 | + List<MesWmStockTakingPlanParamDO> params = stockTakingPlanParamService.getStockTakingPlanParamListByPlanId(id); | |
| 80 | + if (CollUtil.isEmpty(params)) { | |
| 81 | + throw exception(WM_STOCK_TAKING_PLAN_PARAM_EMPTY); | |
| 82 | + } | |
| 83 | + } | |
| 76 | 84 | |
| 77 | 85 | // 更新状态 |
| 78 | 86 | stockTakingPlanMapper.updateById(new MesWmStockTakingPlanDO().setId(id).setStatus(status)); | ... | ... |