Commit aca010b7d39022608af3e7b765bdc0828a484c31

Authored by YunaiV
1 parent 9c36c2cf

feedback

yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/feedback/MesProFeedbackController.java
@@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; @@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
5 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 5 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
6 import cn.iocoder.yudao.framework.common.pojo.PageParam; 6 import cn.iocoder.yudao.framework.common.pojo.PageParam;
7 import cn.iocoder.yudao.framework.common.pojo.PageResult; 7 import cn.iocoder.yudao.framework.common.pojo.PageResult;
8 -import cn.iocoder.yudao.framework.common.util.collection.MapUtils;  
9 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 8 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
10 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; 9 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
11 import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackPageReqVO; 10 import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackPageReqVO;
@@ -41,12 +40,11 @@ import org.springframework.web.bind.annotation.*; @@ -41,12 +40,11 @@ import org.springframework.web.bind.annotation.*;
41 40
42 import java.io.IOException; 41 import java.io.IOException;
43 import java.util.*; 42 import java.util.*;
44 -import java.util.stream.Collectors; 43 +import java.util.stream.Stream;
45 44
46 import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; 45 import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
47 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 46 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
48 -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;  
49 -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap; 47 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
50 import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; 48 import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
51 49
52 @Tag(name = "管理后台 - MES 生产报工") 50 @Tag(name = "管理后台 - MES 生产报工")
@@ -188,49 +186,28 @@ public class MesProFeedbackController { @@ -188,49 +186,28 @@ public class MesProFeedbackController {
188 // 1.2 工单 186 // 1.2 工单
189 Map<Long, MesProWorkOrderDO> workOrderMap = workOrderService.getWorkOrderMap( 187 Map<Long, MesProWorkOrderDO> workOrderMap = workOrderService.getWorkOrderMap(
190 convertSet(list, MesProFeedbackDO::getWorkOrderId)); 188 convertSet(list, MesProFeedbackDO::getWorkOrderId));
191 - // 1.3 工作站(逐个查询,因为没有批量方法)  
192 - // TODO @AI:getWorkstationMap 必须有办法  
193 - Set<Long> workstationIds = convertSet(list, MesProFeedbackDO::getWorkstationId);  
194 - Map<Long, MesMdWorkstationDO> workstationMap = new HashMap<>();  
195 - workstationIds.forEach(wsId -> {  
196 - MesMdWorkstationDO ws = workstationService.getWorkstation(wsId);  
197 - if (ws != null) {  
198 - workstationMap.put(wsId, ws);  
199 - }  
200 - });  
201 - // 1.4 工艺路线(逐个查询)  
202 - // TODO @AI:getRouteMap 必须有办法;里面调用 getRouteList;如果不行,就加个; 189 + // 1.3 工作站
  190 + Map<Long, MesMdWorkstationDO> workstationMap = workstationService.getWorkstationMap(
  191 + convertSet(list, MesProFeedbackDO::getWorkstationId));
  192 + // 1.4 工艺路线
203 Set<Long> routeIds = convertSet(list, MesProFeedbackDO::getRouteId); 193 Set<Long> routeIds = convertSet(list, MesProFeedbackDO::getRouteId);
204 - Map<Long, MesProRouteDO> routeMap = new HashMap<>();  
205 - routeIds.forEach(rId -> {  
206 - MesProRouteDO route = routeService.getRoute(rId);  
207 - if (route != null) {  
208 - routeMap.put(rId, route);  
209 - }  
210 - }); 194 + Map<Long, MesProRouteDO> routeMap = routeService.getRouteMap(routeIds);
211 // 1.5 工序 195 // 1.5 工序
212 - // TODO @AI:getProcessMap 必须有办法;里面调用 getProcessList;如果不行,就加个;  
213 - Set<Long> processIds = convertSet(list, MesProFeedbackDO::getProcessId);  
214 - List<MesProProcessDO> processList = processService.getProcessList(new ArrayList<>(processIds));  
215 - Map<Long, MesProProcessDO> processMap = processList.stream()  
216 - .collect(Collectors.toMap(MesProProcessDO::getId, p -> p, (a, b) -> a));  
217 - // 1.6 工序的 checkFlag(按路线维度缓存)  
218 - // TODO @AI:collutils 里面有个 convertMultiMap 的方法;  
219 - Map<Long, List<MesProRouteProcessDO>> routeProcessMap = new HashMap<>();  
220 - routeIds.forEach(rId -> routeProcessMap.put(rId, routeProcessService.getRouteProcessListByRouteId(rId))); 196 + Map<Long, MesProProcessDO> processMap = processService.getProcessMap(
  197 + new ArrayList<>(convertSet(list, MesProFeedbackDO::getProcessId)));
  198 + // 1.6 工序的 checkFlag:批量查询后按 routeId 分组,再按 processId 建内层 Map
  199 + List<MesProRouteProcessDO> allRouteProcesses = routeProcessService.getRouteProcessListByRouteIds(routeIds);
  200 + // TODO @AI:直接构建出 checkFlagMap,避免构建 routeProcessMultiMap 的中间结果,减少内存占用;另外,变量名字在想下;
  201 + Map<Long, List<MesProRouteProcessDO>> routeProcessMultiMap = convertMultiMap(allRouteProcesses,
  202 + MesProRouteProcessDO::getRouteId);
  203 + Map<Long, Map<Long, Boolean>> checkFlagMap = new HashMap<>();
  204 + routeProcessMultiMap.forEach((routeId, rpList) ->
  205 + checkFlagMap.put(routeId, convertMap(rpList, MesProRouteProcessDO::getProcessId,
  206 + rp -> Boolean.TRUE.equals(rp.getCheckFlag()))));
221 // 1.7 报工人/审核人 207 // 1.7 报工人/审核人
222 Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( 208 Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
223 - convertSetByFlatMap(list, feedback -> {  
224 - // TODO @AI:必须要判空,里面已经处理了;  
225 - Set<Long> userIds = new HashSet<>();  
226 - if (feedback.getFeedbackUserId() != null) {  
227 - userIds.add(feedback.getFeedbackUserId());  
228 - }  
229 - if (feedback.getApproveUserId() != null) {  
230 - userIds.add(feedback.getApproveUserId());  
231 - }  
232 - return userIds.stream();  
233 - })); 209 + convertSetByFlatMap(list, feedback ->
  210 + Stream.of(feedback.getFeedbackUserId(), feedback.getApproveUserId())));
234 211
235 // 2. 拼接 VO 212 // 2. 拼接 VO
236 return BeanUtils.toBean(list, MesProFeedbackRespVO.class, vo -> { 213 return BeanUtils.toBean(list, MesProFeedbackRespVO.class, vo -> {
@@ -244,14 +221,8 @@ public class MesProFeedbackController { @@ -244,14 +221,8 @@ public class MesProFeedbackController {
244 findAndThen(processMap, vo.getProcessId(), process -> 221 findAndThen(processMap, vo.getProcessId(), process ->
245 vo.setProcessCode(process.getCode()).setProcessName(process.getName())); 222 vo.setProcessCode(process.getCode()).setProcessName(process.getName()));
246 // checkFlag 223 // checkFlag
247 - // TODO @AI:这个判断有点复杂,是不是上面构建更合适的 map?  
248 - List<MesProRouteProcessDO> rps = routeProcessMap.get(vo.getRouteId());  
249 - if (rps != null) {  
250 - rps.stream()  
251 - .filter(rp -> rp.getProcessId().equals(vo.getProcessId()))  
252 - .findFirst()  
253 - .ifPresent(rp -> vo.setCheckFlag(Boolean.TRUE.equals(rp.getCheckFlag())));  
254 - } 224 + findAndThen(checkFlagMap, vo.getRouteId(), processCheckMap ->
  225 + findAndThen(processCheckMap, vo.getProcessId(), vo::setCheckFlag));
255 // 工单 226 // 工单
256 findAndThen(workOrderMap, vo.getWorkOrderId(), wo -> 227 findAndThen(workOrderMap, vo.getWorkOrderId(), wo ->
257 vo.setWorkOrderCode(wo.getCode()).setWorkOrderName(wo.getName())); 228 vo.setWorkOrderCode(wo.getCode()).setWorkOrderName(wo.getName()));
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/feedback/vo/MesProFeedbackSaveReqVO.java
@@ -14,6 +14,10 @@ public class MesProFeedbackSaveReqVO { @@ -14,6 +14,10 @@ public class MesProFeedbackSaveReqVO {
14 @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") 14 @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
15 private Long id; 15 private Long id;
16 16
  17 + @Schema(description = "报工单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "FB202503001")
  18 + @NotNull(message = "报工单编号不能为空")
  19 + private String code;
  20 +
17 @Schema(description = "报工类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") 21 @Schema(description = "报工类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
18 @NotNull(message = "报工类型不能为空") 22 @NotNull(message = "报工类型不能为空")
19 private Integer type; 23 private Integer type;
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/pro/route/MesProRouteProcessMapper.java
@@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
5 import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProcessDO; 5 import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProcessDO;
6 import org.apache.ibatis.annotations.Mapper; 6 import org.apache.ibatis.annotations.Mapper;
7 7
  8 +import java.util.Collection;
8 import java.util.List; 9 import java.util.List;
9 10
10 /** 11 /**
@@ -48,4 +49,9 @@ public interface MesProRouteProcessMapper extends BaseMapperX&lt;MesProRouteProcess @@ -48,4 +49,9 @@ public interface MesProRouteProcessMapper extends BaseMapperX&lt;MesProRouteProcess
48 return selectList(MesProRouteProcessDO::getProcessId, processId); 49 return selectList(MesProRouteProcessDO::getProcessId, processId);
49 } 50 }
50 51
  52 + default List<MesProRouteProcessDO> selectListByRouteIds(Collection<Long> routeIds) {
  53 + return selectList(new LambdaQueryWrapperX<MesProRouteProcessDO>()
  54 + .in(MesProRouteProcessDO::getRouteId, routeIds));
  55 + }
  56 +
51 } 57 }
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/feedback/MesProFeedbackServiceImpl.java
1 package cn.iocoder.yudao.module.mes.service.pro.feedback; 1 package cn.iocoder.yudao.module.mes.service.pro.feedback;
2 2
3 -import cn.hutool.core.util.IdUtil; 3 +import cn.hutool.core.collection.CollUtil;
  4 +import cn.hutool.core.util.BooleanUtil;
4 import cn.hutool.core.util.ObjUtil; 5 import cn.hutool.core.util.ObjUtil;
5 import cn.iocoder.yudao.framework.common.pojo.PageResult; 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 7 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  8 +import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
7 import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackPageReqVO; 9 import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackPageReqVO;
8 import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackSaveReqVO; 10 import cn.iocoder.yudao.module.mes.controller.admin.pro.feedback.vo.MesProFeedbackSaveReqVO;
9 import cn.iocoder.yudao.module.mes.dal.dataobject.pro.feedback.MesProFeedbackDO; 11 import cn.iocoder.yudao.module.mes.dal.dataobject.pro.feedback.MesProFeedbackDO;
10 import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProcessDO; 12 import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProcessDO;
11 -import cn.iocoder.yudao.module.mes.dal.dataobject.pro.workorder.MesProWorkOrderDO;  
12 import cn.iocoder.yudao.module.mes.dal.mysql.pro.feedback.MesProFeedbackMapper; 13 import cn.iocoder.yudao.module.mes.dal.mysql.pro.feedback.MesProFeedbackMapper;
13 import cn.iocoder.yudao.module.mes.enums.pro.MesProFeedbackStatusEnum; 14 import cn.iocoder.yudao.module.mes.enums.pro.MesProFeedbackStatusEnum;
14 -import cn.iocoder.yudao.module.mes.enums.pro.MesProWorkOrderStatusEnum;  
15 import cn.iocoder.yudao.module.mes.service.pro.route.MesProRouteProcessService; 15 import cn.iocoder.yudao.module.mes.service.pro.route.MesProRouteProcessService;
16 import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderService; 16 import cn.iocoder.yudao.module.mes.service.pro.workorder.MesProWorkOrderService;
17 import jakarta.annotation.Resource; 17 import jakarta.annotation.Resource;
@@ -46,35 +46,21 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService { @@ -46,35 +46,21 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService {
46 46
47 @Override 47 @Override
48 public Long createFeedback(MesProFeedbackSaveReqVO createReqVO) { 48 public Long createFeedback(MesProFeedbackSaveReqVO createReqVO) {
49 - // 1.1 校验工单已确认  
50 - // TODO @AI: workOrderService 里抽个校验方法;  
51 - MesProWorkOrderDO workOrder = workOrderService.validateWorkOrderExists(createReqVO.getWorkOrderId());  
52 - if (ObjUtil.notEqual(workOrder.getStatus(), MesProWorkOrderStatusEnum.CONFIRMED.getStatus())) {  
53 - throw exception(PRO_FEEDBACK_WORK_ORDER_NOT_CONFIRMED);  
54 - } 49 + // 1. 校验工单已确认
  50 + workOrderService.validateWorkOrderConfirmed(createReqVO.getWorkOrderId());
55 // TODO @芋艿:校验 pro_task 存在且未完成(待 pro_task 服务迁移) 51 // TODO @芋艿:校验 pro_task 存在且未完成(待 pro_task 服务迁移)
56 52
57 - // TODO @AI:2 和 3 融合成 插入;  
58 - // 2. 自动生成报工单编号 53 + // 2. 插入
59 MesProFeedbackDO feedback = BeanUtils.toBean(createReqVO, MesProFeedbackDO.class); 54 MesProFeedbackDO feedback = BeanUtils.toBean(createReqVO, MesProFeedbackDO.class);
60 - // TODO @AI:这个 id 前端生成,createReqVO 必须传递;  
61 - feedback.setCode("FB" + IdUtil.getSnowflakeNextIdStr());  
62 feedback.setStatus(MesProFeedbackStatusEnum.PREPARE.getStatus()); 55 feedback.setStatus(MesProFeedbackStatusEnum.PREPARE.getStatus());
63 -  
64 - // 3. 插入  
65 feedbackMapper.insert(feedback); 56 feedbackMapper.insert(feedback);
66 return feedback.getId(); 57 return feedback.getId();
67 } 58 }
68 59
69 @Override 60 @Override
70 public void updateFeedback(MesProFeedbackSaveReqVO updateReqVO) { 61 public void updateFeedback(MesProFeedbackSaveReqVO updateReqVO) {
71 - // 1.1 校验存在  
72 - MesProFeedbackDO feedback = validateFeedbackExists(updateReqVO.getId());  
73 - // 1.2 只能修改草稿状态  
74 - // TODO @AI:抽个校验方法,校验状态为草稿;  
75 - if (ObjUtil.notEqual(feedback.getStatus(), MesProFeedbackStatusEnum.PREPARE.getStatus())) {  
76 - throw exception(PRO_FEEDBACK_NOT_PREPARE);  
77 - } 62 + // 1. 校验存在 + 草稿状态
  63 + validateFeedbackStatusPrepare(updateReqVO.getId());
78 64
79 // 2. 更新 65 // 2. 更新
80 MesProFeedbackDO updateObj = BeanUtils.toBean(updateReqVO, MesProFeedbackDO.class); 66 MesProFeedbackDO updateObj = BeanUtils.toBean(updateReqVO, MesProFeedbackDO.class);
@@ -83,13 +69,8 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService { @@ -83,13 +69,8 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService {
83 69
84 @Override 70 @Override
85 public void deleteFeedback(Long id) { 71 public void deleteFeedback(Long id) {
86 - // 1.1 校验存在  
87 - MesProFeedbackDO feedback = validateFeedbackExists(id);  
88 - // 1.2 只能删除草稿状态  
89 - // TODO @AI:抽个校验方法,校验状态为草稿;  
90 - if (ObjUtil.notEqual(feedback.getStatus(), MesProFeedbackStatusEnum.PREPARE.getStatus())) {  
91 - throw exception(PRO_FEEDBACK_NOT_PREPARE);  
92 - } 72 + // 1. 校验存在 + 草稿状态
  73 + validateFeedbackStatusPrepare(id);
93 74
94 // 2. 删除 75 // 2. 删除
95 feedbackMapper.deleteById(id); 76 feedbackMapper.deleteById(id);
@@ -108,11 +89,7 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService { @@ -108,11 +89,7 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService {
108 @Override 89 @Override
109 public void submitFeedback(Long id) { 90 public void submitFeedback(Long id) {
110 // 1. 校验存在 + 草稿状态 91 // 1. 校验存在 + 草稿状态
111 - MesProFeedbackDO feedback = validateFeedbackExists(id);  
112 - // TODO @AI:抽个校验方法,校验状态为草稿;  
113 - if (ObjUtil.notEqual(feedback.getStatus(), MesProFeedbackStatusEnum.PREPARE.getStatus())) {  
114 - throw exception(PRO_FEEDBACK_STATUS_ERROR);  
115 - } 92 + validateFeedbackStatusPrepare(id);
116 93
117 // 2. 更新状态为审批中,记录报工人和报工时间 94 // 2. 更新状态为审批中,记录报工人和报工时间
118 feedbackMapper.updateById(new MesProFeedbackDO().setId(id) 95 feedbackMapper.updateById(new MesProFeedbackDO().setId(id)
@@ -124,11 +101,7 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService { @@ -124,11 +101,7 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService {
124 @Override 101 @Override
125 public void rejectFeedback(Long id) { 102 public void rejectFeedback(Long id) {
126 // 1. 校验存在 + 审批中状态 103 // 1. 校验存在 + 审批中状态
127 - MesProFeedbackDO feedback = validateFeedbackExists(id);  
128 - // TODO @AI:抽个校验方法,校验状态为审批中;  
129 - if (ObjUtil.notEqual(feedback.getStatus(), MesProFeedbackStatusEnum.APPROVING.getStatus())) {  
130 - throw exception(PRO_FEEDBACK_NOT_APPROVING);  
131 - } 104 + validateFeedbackStatusApproving(id);
132 105
133 // 2. 更新状态为草稿 106 // 2. 更新状态为草稿
134 feedbackMapper.updateById(new MesProFeedbackDO().setId(id) 107 feedbackMapper.updateById(new MesProFeedbackDO().setId(id)
@@ -139,11 +112,7 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService { @@ -139,11 +112,7 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService {
139 @Transactional(rollbackFor = Exception.class) 112 @Transactional(rollbackFor = Exception.class)
140 public void executeFeedback(Long id) { 113 public void executeFeedback(Long id) {
141 // 1. 校验存在 + 审批中状态 114 // 1. 校验存在 + 审批中状态
142 - MesProFeedbackDO feedback = validateFeedbackExists(id);  
143 - // TODO @AI:抽个校验方法,校验状态为审批中;  
144 - if (ObjUtil.notEqual(feedback.getStatus(), MesProFeedbackStatusEnum.APPROVING.getStatus())) {  
145 - throw exception(PRO_FEEDBACK_NOT_APPROVING);  
146 - } 115 + MesProFeedbackDO feedback = validateFeedbackStatusApproving(id);
147 116
148 // 2.1 查询工序的 checkFlag,决定目标状态 117 // 2.1 查询工序的 checkFlag,决定目标状态
149 boolean checkFlag = getCheckFlag(feedback.getRouteId(), feedback.getProcessId()); 118 boolean checkFlag = getCheckFlag(feedback.getRouteId(), feedback.getProcessId());
@@ -155,9 +124,8 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService { @@ -155,9 +124,8 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService {
155 .setStatus(targetStatus) 124 .setStatus(targetStatus)
156 .setApproveUserId(getLoginUserId())); 125 .setApproveUserId(getLoginUserId()));
157 126
158 - // 4. 如果不需要检验(直接完成),执行后续操作  
159 - // TODO @AI:BoolUtil.isFalse(checkFlag)  
160 - if (!checkFlag) { 127 + // 3. 如果不需要检验(直接完成),执行后续操作
  128 + if (BooleanUtil.isFalse(checkFlag)) {
161 // TODO @芋艿:WM 物料消耗(WmItemConsumeService)未迁移,此处需补充物料消耗逻辑 129 // TODO @芋艿:WM 物料消耗(WmItemConsumeService)未迁移,此处需补充物料消耗逻辑
162 // TODO @芋艿:WM 产品产出(WmProductProduceService)未迁移,此处需补充产品产出逻辑 130 // TODO @芋艿:WM 产品产出(WmProductProduceService)未迁移,此处需补充产品产出逻辑
163 // TODO @芋艿:updateProTaskAndWorkorder 待 pro_task 服务迁移后补充级联更新任务/工单的已生产数量 131 // TODO @芋艿:updateProTaskAndWorkorder 待 pro_task 服务迁移后补充级联更新任务/工单的已生产数量
@@ -168,10 +136,10 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService { @@ -168,10 +136,10 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService {
168 public void cancelFeedback(Long id) { 136 public void cancelFeedback(Long id) {
169 // 1.1 校验存在 137 // 1.1 校验存在
170 MesProFeedbackDO feedback = validateFeedbackExists(id); 138 MesProFeedbackDO feedback = validateFeedbackExists(id);
171 - // 1.2 只有草稿或审批中可以取消  
172 - // TODO @AI: ObjUtils.equalsAny,看起来更简洁;  
173 - if (ObjUtil.equal(feedback.getStatus(), MesProFeedbackStatusEnum.FINISHED.getStatus())  
174 - || ObjUtil.equal(feedback.getStatus(), MesProFeedbackStatusEnum.CANCELED.getStatus())) { 139 + // 1.2 只有草稿或审批中可以取消(已完成、已取消不可操作)
  140 + if (ObjectUtils.equalsAny(feedback.getStatus(),
  141 + MesProFeedbackStatusEnum.FINISHED.getStatus(),
  142 + MesProFeedbackStatusEnum.CANCELED.getStatus())) {
175 throw exception(PRO_FEEDBACK_STATUS_ERROR); 143 throw exception(PRO_FEEDBACK_STATUS_ERROR);
176 } 144 }
177 145
@@ -190,6 +158,22 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService { @@ -190,6 +158,22 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService {
190 return feedback; 158 return feedback;
191 } 159 }
192 160
  161 + private MesProFeedbackDO validateFeedbackStatusPrepare(Long id) {
  162 + MesProFeedbackDO feedback = validateFeedbackExists(id);
  163 + if (ObjUtil.notEqual(feedback.getStatus(), MesProFeedbackStatusEnum.PREPARE.getStatus())) {
  164 + throw exception(PRO_FEEDBACK_NOT_PREPARE);
  165 + }
  166 + return feedback;
  167 + }
  168 +
  169 + private MesProFeedbackDO validateFeedbackStatusApproving(Long id) {
  170 + MesProFeedbackDO feedback = validateFeedbackExists(id);
  171 + if (ObjUtil.notEqual(feedback.getStatus(), MesProFeedbackStatusEnum.APPROVING.getStatus())) {
  172 + throw exception(PRO_FEEDBACK_NOT_APPROVING);
  173 + }
  174 + return feedback;
  175 + }
  176 +
193 /** 177 /**
194 * 获取指定工艺路线中指定工序的 checkFlag 178 * 获取指定工艺路线中指定工序的 checkFlag
195 * 179 *
@@ -198,13 +182,11 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService { @@ -198,13 +182,11 @@ public class MesProFeedbackServiceImpl implements MesProFeedbackService {
198 * @return 是否需要检验 182 * @return 是否需要检验
199 */ 183 */
200 private boolean getCheckFlag(Long routeId, Long processId) { 184 private boolean getCheckFlag(Long routeId, Long processId) {
  185 + // TODO @AI:是不是 routeProcessService 提供一个查询 routeeProcess 的方法更好?目前只能查询 routeProcesses 全列表,效率较低
201 List<MesProRouteProcessDO> routeProcesses = routeProcessService.getRouteProcessListByRouteId(routeId); 186 List<MesProRouteProcessDO> routeProcesses = routeProcessService.getRouteProcessListByRouteId(routeId);
202 - // TODO @AI:CollUtil findOne 更简洁;  
203 - return routeProcesses.stream()  
204 - .filter(rp -> ObjUtil.equal(rp.getProcessId(), processId))  
205 - .findFirst()  
206 - .map(rp -> Boolean.TRUE.equals(rp.getCheckFlag()))  
207 - .orElse(false); 187 + MesProRouteProcessDO routeProcess = CollUtil.findOne(routeProcesses,
  188 + rp -> ObjUtil.equal(rp.getProcessId(), processId));
  189 + return routeProcess != null && Boolean.TRUE.equals(routeProcess.getCheckFlag());
208 } 190 }
209 191
210 } 192 }
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProcessService.java
@@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.process.MesProR @@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.process.MesProR
4 import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProcessDO; 4 import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteProcessDO;
5 import jakarta.validation.Valid; 5 import jakarta.validation.Valid;
6 6
  7 +import java.util.Collection;
7 import java.util.List; 8 import java.util.List;
8 9
9 /** 10 /**
@@ -39,6 +40,14 @@ public interface MesProRouteProcessService { @@ -39,6 +40,14 @@ public interface MesProRouteProcessService {
39 List<MesProRouteProcessDO> getRouteProcessListByRouteId(Long routeId); 40 List<MesProRouteProcessDO> getRouteProcessListByRouteId(Long routeId);
40 41
41 /** 42 /**
  43 + * 按多个工艺路线获得工序列表
  44 + *
  45 + * @param routeIds 工艺路线编号数组
  46 + * @return 工序列表
  47 + */
  48 + List<MesProRouteProcessDO> getRouteProcessListByRouteIds(Collection<Long> routeIds);
  49 +
  50 + /**
42 * 按工艺路线删除工序(级联删除使用) 51 * 按工艺路线删除工序(级联删除使用)
43 * 52 *
44 * @param routeId 工艺路线编号 53 * @param routeId 工艺路线编号
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteProcessServiceImpl.java
@@ -12,6 +12,8 @@ import org.springframework.stereotype.Service; @@ -12,6 +12,8 @@ import org.springframework.stereotype.Service;
12 import org.springframework.transaction.annotation.Transactional; 12 import org.springframework.transaction.annotation.Transactional;
13 import org.springframework.validation.annotation.Validated; 13 import org.springframework.validation.annotation.Validated;
14 14
  15 +import java.util.Collection;
  16 +import java.util.Collections;
15 import java.util.Comparator; 17 import java.util.Comparator;
16 import java.util.List; 18 import java.util.List;
17 19
@@ -169,6 +171,14 @@ public class MesProRouteProcessServiceImpl implements MesProRouteProcessService @@ -169,6 +171,14 @@ public class MesProRouteProcessServiceImpl implements MesProRouteProcessService
169 } 171 }
170 172
171 @Override 173 @Override
  174 + public List<MesProRouteProcessDO> getRouteProcessListByRouteIds(Collection<Long> routeIds) {
  175 + if (CollUtil.isEmpty(routeIds)) {
  176 + return Collections.emptyList();
  177 + }
  178 + return routeProcessMapper.selectListByRouteIds(routeIds);
  179 + }
  180 +
  181 + @Override
172 public void deleteRouteProcessByRouteId(Long routeId) { 182 public void deleteRouteProcessByRouteId(Long routeId) {
173 routeProcessMapper.deleteByRouteId(routeId); 183 routeProcessMapper.deleteByRouteId(routeId);
174 } 184 }
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteService.java
@@ -6,7 +6,11 @@ import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.MesProRouteSave @@ -6,7 +6,11 @@ import cn.iocoder.yudao.module.mes.controller.admin.pro.route.vo.MesProRouteSave
6 import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteDO; 6 import cn.iocoder.yudao.module.mes.dal.dataobject.pro.route.MesProRouteDO;
7 import jakarta.validation.Valid; 7 import jakarta.validation.Valid;
8 8
  9 +import java.util.Collection;
9 import java.util.List; 10 import java.util.List;
  11 +import java.util.Map;
  12 +
  13 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
10 14
11 /** 15 /**
12 * MES 工艺路线 Service 接口 16 * MES 工艺路线 Service 接口
@@ -60,4 +64,22 @@ public interface MesProRouteService { @@ -60,4 +64,22 @@ public interface MesProRouteService {
60 */ 64 */
61 void validateRouteNotEnable(Long routeId); 65 void validateRouteNotEnable(Long routeId);
62 66
  67 + /**
  68 + * 获得工艺路线列表
  69 + *
  70 + * @param ids 编号数组
  71 + * @return 工艺路线列表
  72 + */
  73 + List<MesProRouteDO> getRouteList(Collection<Long> ids);
  74 +
  75 + /**
  76 + * 获得工艺路线 Map
  77 + *
  78 + * @param ids 编号数组
  79 + * @return 工艺路线 Map
  80 + */
  81 + default Map<Long, MesProRouteDO> getRouteMap(Collection<Long> ids) {
  82 + return convertMap(getRouteList(ids), MesProRouteDO::getId);
  83 + }
  84 +
63 } 85 }
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/route/MesProRouteServiceImpl.java
@@ -19,6 +19,8 @@ import org.springframework.stereotype.Service; @@ -19,6 +19,8 @@ import org.springframework.stereotype.Service;
19 import org.springframework.transaction.annotation.Transactional; 19 import org.springframework.transaction.annotation.Transactional;
20 import org.springframework.validation.annotation.Validated; 20 import org.springframework.validation.annotation.Validated;
21 21
  22 +import java.util.Collection;
  23 +import java.util.Collections;
22 import java.util.List; 24 import java.util.List;
23 25
24 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 26 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -163,4 +165,12 @@ public class MesProRouteServiceImpl implements MesProRouteService { @@ -163,4 +165,12 @@ public class MesProRouteServiceImpl implements MesProRouteService {
163 } 165 }
164 } 166 }
165 167
  168 + @Override
  169 + public List<MesProRouteDO> getRouteList(Collection<Long> ids) {
  170 + if (CollUtil.isEmpty(ids)) {
  171 + return Collections.emptyList();
  172 + }
  173 + return routeMapper.selectByIds(ids);
  174 + }
  175 +
166 } 176 }
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/workorder/MesProWorkorderService.java
@@ -84,6 +84,14 @@ public interface MesProWorkOrderService { @@ -84,6 +84,14 @@ public interface MesProWorkOrderService {
84 } 84 }
85 85
86 /** 86 /**
  87 + * 校验工单已确认
  88 + *
  89 + * @param id 编号
  90 + * @return 工单
  91 + */
  92 + MesProWorkOrderDO validateWorkOrderConfirmed(Long id);
  93 +
  94 + /**
87 * 确认工单(草稿 → 已确认) 95 * 确认工单(草稿 → 已确认)
88 * 96 *
89 * @param id 编号 97 * @param id 编号
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pro/workorder/MesProWorkorderServiceImpl.java
@@ -148,6 +148,15 @@ public class MesProWorkOrderServiceImpl implements MesProWorkOrderService { @@ -148,6 +148,15 @@ public class MesProWorkOrderServiceImpl implements MesProWorkOrderService {
148 } 148 }
149 149
150 @Override 150 @Override
  151 + public MesProWorkOrderDO validateWorkOrderConfirmed(Long id) {
  152 + MesProWorkOrderDO workOrder = validateWorkOrderExists(id);
  153 + if (ObjUtil.notEqual(workOrder.getStatus(), MesProWorkOrderStatusEnum.CONFIRMED.getStatus())) {
  154 + throw exception(PRO_WORK_ORDER_NOT_CONFIRMED);
  155 + }
  156 + return workOrder;
  157 + }
  158 +
  159 + @Override
151 public void confirmWorkOrder(Long id) { 160 public void confirmWorkOrder(Long id) {
152 // 1. 校验存在 161 // 1. 校验存在
153 MesProWorkOrderDO workOrder = validateWorkOrderExists(id); 162 MesProWorkOrderDO workOrder = validateWorkOrderExists(id);