Commit 728eb76bc3321eef632c43d8a2d31ff60dcc15cd
1 parent
746345aa
✨ feat(mes): 添加生产任务编码字段,优化任务创建和更新逻辑
新增生产任务编码字段,更新任务创建和更新方法以校验关联数据的存在性,确保数据一致性和完整性。
Showing
5 changed files
with
66 additions
and
29 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/task/vo/MesProTaskSaveReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.mes.controller.admin.pro.task.vo; |
| 2 | 2 | |
| 3 | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import jakarta.validation.constraints.NotEmpty; | |
| 4 | +import jakarta.validation.constraints.DecimalMin; | |
| 5 | +import jakarta.validation.constraints.Min; | |
| 5 | 6 | import jakarta.validation.constraints.NotNull; |
| 6 | 7 | import lombok.Data; |
| 7 | 8 | |
| ... | ... | @@ -15,14 +16,6 @@ public class MesProTaskSaveReqVO { |
| 15 | 16 | @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") |
| 16 | 17 | private Long id; |
| 17 | 18 | |
| 18 | - @Schema(description = "任务编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "PT202503150001") | |
| 19 | - @NotEmpty(message = "任务编码不能为空") | |
| 20 | - private String code; | |
| 21 | - | |
| 22 | - @Schema(description = "任务名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "注塑任务") | |
| 23 | - @NotEmpty(message = "任务名称不能为空") | |
| 24 | - private String name; | |
| 25 | - | |
| 26 | 19 | @Schema(description = "生产工单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 27 | 20 | @NotNull(message = "生产工单不能为空") |
| 28 | 21 | private Long workOrderId; |
| ... | ... | @@ -45,27 +38,14 @@ public class MesProTaskSaveReqVO { |
| 45 | 38 | |
| 46 | 39 | @Schema(description = "排产数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") |
| 47 | 40 | @NotNull(message = "排产数量不能为空") |
| 41 | + @DecimalMin(value = "0", inclusive = false, message = "排产数量必须大于 0") | |
| 48 | 42 | private BigDecimal quantity; |
| 49 | 43 | |
| 50 | - @Schema(description = "已生产数量", example = "0") | |
| 51 | - private BigDecimal producedQuantity; | |
| 52 | - | |
| 53 | - @Schema(description = "合格品数量", example = "0") | |
| 54 | - private BigDecimal qualifyQuantity; | |
| 55 | - | |
| 56 | - @Schema(description = "不良品数量", example = "0") | |
| 57 | - private BigDecimal unqualifyQuantity; | |
| 58 | - | |
| 59 | - @Schema(description = "调整数量", example = "0") | |
| 60 | - private BigDecimal changedQuantity; | |
| 61 | - | |
| 62 | - @Schema(description = "客户编号", example = "300") | |
| 63 | - private Long clientId; | |
| 64 | - | |
| 65 | 44 | @Schema(description = "开始生产时间") |
| 66 | 45 | private LocalDateTime startTime; |
| 67 | 46 | |
| 68 | 47 | @Schema(description = "生产时长(工作日)", example = "3") |
| 48 | + @Min(value = 1, message = "生产时长必须大于 0") | |
| 69 | 49 | private Integer duration; |
| 70 | 50 | |
| 71 | 51 | @Schema(description = "结束生产时间") |
| ... | ... | @@ -77,4 +57,4 @@ public class MesProTaskSaveReqVO { |
| 77 | 57 | @Schema(description = "备注", example = "备注") |
| 78 | 58 | private String remark; |
| 79 | 59 | |
| 80 | - } | |
| 60 | +} | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/enums/md/autocode/MesMdAutoCodeRuleCodeEnum.java
| ... | ... | @@ -14,7 +14,8 @@ public enum MesMdAutoCodeRuleCodeEnum { |
| 14 | 14 | |
| 15 | 15 | SN_CODE("SN_CODE", "SN 码"), |
| 16 | 16 | PACKAGE_CODE("PACKAGE_CODE", "装箱单编码"), |
| 17 | - BATCH_CODE("BATCH_CODE", "批次编码"); | |
| 17 | + BATCH_CODE("BATCH_CODE", "批次编码"), | |
| 18 | + TASK_CODE("TASK_CODE", "生产任务编码"); | |
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * 规则代码 | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteService.java
| ... | ... | @@ -65,6 +65,14 @@ public interface MesProRouteService { |
| 65 | 65 | void validateRouteNotEnable(Long routeId); |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | + * 校验工艺路线存在 | |
| 69 | + * | |
| 70 | + * @param id 工艺路线编号 | |
| 71 | + * @return 工艺路线 | |
| 72 | + */ | |
| 73 | + MesProRouteDO validateRouteExists(Long id); | |
| 74 | + | |
| 75 | + /** | |
| 68 | 76 | * 获得工艺路线列表 |
| 69 | 77 | * |
| 70 | 78 | * @param ids 编号数组 | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteServiceImpl.java
| ... | ... | @@ -99,7 +99,8 @@ public class MesProRouteServiceImpl implements MesProRouteService { |
| 99 | 99 | routeMapper.deleteById(id); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - private MesProRouteDO validateRouteExists(Long id) { | |
| 102 | + @Override | |
| 103 | + public MesProRouteDO validateRouteExists(Long id) { | |
| 103 | 104 | MesProRouteDO route = routeMapper.selectById(id); |
| 104 | 105 | if (route == null) { |
| 105 | 106 | throw exception(PRO_ROUTE_NOT_EXISTS); | ... | ... |
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/task/MesProTaskServiceImpl.java
| ... | ... | @@ -5,10 +5,19 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | 6 | import cn.iocoder.yudao.module.mes.controller.admin.pro.task.vo.MesProTaskPageReqVO; |
| 7 | 7 | import cn.iocoder.yudao.module.mes.controller.admin.pro.task.vo.MesProTaskSaveReqVO; |
| 8 | +import cn.iocoder.yudao.module.mes.dal.dataobject.md.item.MesMdItemDO; | |
| 8 | 9 | import cn.iocoder.yudao.module.mes.dal.dataobject.pro.task.MesProTaskDO; |
| 9 | 10 | import cn.iocoder.yudao.module.mes.dal.mysql.pro.task.MesProTaskMapper; |
| 11 | +import cn.iocoder.yudao.module.mes.enums.md.autocode.MesMdAutoCodeRuleCodeEnum; | |
| 10 | 12 | import cn.iocoder.yudao.module.mes.enums.pro.MesProTaskStatusEnum; |
| 13 | +import cn.iocoder.yudao.module.mes.service.md.autocode.MesMdAutoCodeRecordService; | |
| 14 | +import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; | |
| 15 | +import cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService; | |
| 16 | +import cn.iocoder.yudao.module.mes.service.pro.process.MesProProcessService; | |
| 17 | +import cn.iocoder.yudao.module.mes.service.pro.route.MesProRouteService; | |
| 18 | +import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderService; | |
| 11 | 19 | import jakarta.annotation.Resource; |
| 20 | +import org.springframework.context.annotation.Lazy; | |
| 12 | 21 | import org.springframework.stereotype.Service; |
| 13 | 22 | import org.springframework.validation.annotation.Validated; |
| 14 | 23 | |
| ... | ... | @@ -32,23 +41,61 @@ public class MesProTaskServiceImpl implements MesProTaskService { |
| 32 | 41 | @Resource |
| 33 | 42 | private MesProTaskMapper taskMapper; |
| 34 | 43 | |
| 44 | + @Resource | |
| 45 | + @Lazy | |
| 46 | + private MesProWorkOrderService workOrderService; | |
| 47 | + @Resource | |
| 48 | + private MesMdWorkstationService workstationService; | |
| 49 | + @Resource | |
| 50 | + private MesProProcessService processService; | |
| 51 | + @Resource | |
| 52 | + private MesMdItemService itemService; | |
| 53 | + @Resource | |
| 54 | + private MesProRouteService routeService; | |
| 55 | + @Resource | |
| 56 | + private MesMdAutoCodeRecordService autoCodeRecordService; | |
| 57 | + | |
| 35 | 58 | @Override |
| 36 | 59 | public Long createTask(MesProTaskSaveReqVO createReqVO) { |
| 37 | - MesProTaskDO task = BeanUtils.toBean(createReqVO, MesProTaskDO.class); | |
| 60 | + // 1. 校验关联数据存在 | |
| 61 | + workOrderService.validateWorkOrderExists(createReqVO.getWorkOrderId()); | |
| 62 | + workstationService.validateWorkstationExists(createReqVO.getWorkstationId()); | |
| 63 | + routeService.validateRouteExists(createReqVO.getRouteId()); | |
| 64 | + processService.validateProcessExists(createReqVO.getProcessId()); | |
| 65 | + MesMdItemDO item = itemService.validateItemExists(createReqVO.getItemId()); | |
| 66 | + | |
| 67 | + // 2.1 构建任务 DO | |
| 68 | + MesProTaskDO task = BeanUtils.toBean(createReqVO, MesProTaskDO.class) | |
| 69 | + .setName(item.getName() + "【" + createReqVO.getQuantity() + "】") | |
| 70 | + .setCode(autoCodeRecordService.generateAutoCode(MesMdAutoCodeRuleCodeEnum.TASK_CODE.getCode())) | |
| 71 | + .setStatus(MesProTaskStatusEnum.PREPARE.getStatus()); | |
| 72 | + // 2.2 插入 | |
| 38 | 73 | taskMapper.insert(task); |
| 39 | 74 | return task.getId(); |
| 40 | 75 | } |
| 41 | 76 | |
| 42 | 77 | @Override |
| 43 | 78 | public void updateTask(MesProTaskSaveReqVO updateReqVO) { |
| 79 | + // 1.1 校验存在 | |
| 44 | 80 | validateTaskExists(updateReqVO.getId()); |
| 45 | - MesProTaskDO updateObj = BeanUtils.toBean(updateReqVO, MesProTaskDO.class); | |
| 81 | + // 1.2 校验关联数据存在 | |
| 82 | + workOrderService.validateWorkOrderExists(updateReqVO.getWorkOrderId()); | |
| 83 | + workstationService.validateWorkstationExists(updateReqVO.getWorkstationId()); | |
| 84 | + routeService.validateRouteExists(updateReqVO.getRouteId()); | |
| 85 | + processService.validateProcessExists(updateReqVO.getProcessId()); | |
| 86 | + MesMdItemDO item = itemService.validateItemExists(updateReqVO.getItemId()); | |
| 87 | + | |
| 88 | + // 2. 更新 | |
| 89 | + MesProTaskDO updateObj = BeanUtils.toBean(updateReqVO, MesProTaskDO.class) | |
| 90 | + .setName(item.getName() + "【" + updateReqVO.getQuantity() + "】"); | |
| 46 | 91 | taskMapper.updateById(updateObj); |
| 47 | 92 | } |
| 48 | 93 | |
| 49 | 94 | @Override |
| 50 | 95 | public void deleteTask(Long id) { |
| 96 | + // 1. 校验存在 | |
| 51 | 97 | validateTaskExists(id); |
| 98 | + // 2. 删除 | |
| 52 | 99 | taskMapper.deleteById(id); |
| 53 | 100 | } |
| 54 | 101 | ... | ... |