2026-08-04 cfbddbd52f8c4d35b06c8b7e7e68b6cf22ce400a
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pro/workorder/MesProWorkOrderProcessController.java
@@ -28,6 +28,7 @@
import org.springframework.web.bind.annotation.*;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
@@ -134,11 +135,21 @@
        processIds.addAll(nextProcessIds);
        Map<Long, MesProProcessDO> processMap = CollUtil.isNotEmpty(processIds)
                ? processService.getProcessMap(processIds) : Collections.emptyMap();
        // 获取产出物料
        Set<Long> outputItemIds = convertSet(list, MesProWorkOrderProcessDO::getOutputItemId);
        outputItemIds.removeAll(Collections.singleton(null));
        Map<Long, MesMdItemDO> itemMap = CollUtil.isNotEmpty(outputItemIds)
                ? itemService.getItemMap(outputItemIds) : Collections.emptyMap();
        // 获取产出物料(解析逗号分隔的字符串)
        Set<Long> allOutputItemIds = new HashSet<>();
        Map<Long, List<Long>> voOutputItemIdsMap = new HashMap<>();
        for (int i = 0; i < list.size(); i++) {
            String outputItemIdStr = list.get(i).getOutputItemId();
            if (outputItemIdStr != null && !outputItemIdStr.isBlank()) {
                List<Long> ids = Arrays.stream(outputItemIdStr.split(","))
                        .map(String::trim).filter(s -> !s.isEmpty())
                        .map(Long::valueOf).collect(Collectors.toList());
                voOutputItemIdsMap.put((long) i, ids);
                allOutputItemIds.addAll(ids);
            }
        }
        Map<Long, MesMdItemDO> itemMap = CollUtil.isNotEmpty(allOutputItemIds)
                ? itemService.getItemMap(allOutputItemIds) : Collections.emptyMap();
        // 2. 查询投料BOM(按工序分组)
        Set<Long> workOrderIds = convertSet(list, MesProWorkOrderProcessDO::getWorkOrderId);
@@ -165,17 +176,35 @@
        }));
        // 3. 拼接 VO
        List<MesProWorkOrderProcessRespVO> result = BeanUtils.toBean(list, MesProWorkOrderProcessRespVO.class, vo -> {
        List<MesProWorkOrderProcessRespVO> result = BeanUtils.toBean(list, MesProWorkOrderProcessRespVO.class);
        for (int i = 0; i < result.size(); i++) {
            MesProWorkOrderProcessRespVO vo = result.get(i);
            MapUtils.findAndThen(processMap, vo.getProcessId(), process -> {
                vo.setProcessCode(process.getCode()).setProcessName(process.getName());
            });
            MapUtils.findAndThen(processMap, vo.getNextProcessId(), process -> {
                vo.setNextProcessName(process.getName());
            });
            MapUtils.findAndThen(itemMap, vo.getOutputItemId(), item -> {
                vo.setOutputItemCode(item.getCode()).setOutputItemName(item.getName());
            });
        });
            // 产出物料(支持多选)
            List<Long> ids = voOutputItemIdsMap.getOrDefault((long) i, Collections.emptyList());
            if (!ids.isEmpty()) {
                vo.setOutputItemIds(ids);
                List<String> names = ids.stream()
                        .map(id -> {
                            MesMdItemDO item = itemMap.get(id);
                            return item != null ? item.getName() : String.valueOf(id);
                        }).collect(Collectors.toList());
                vo.setOutputItemNames(String.join(", ", names));
                // 向后兼容:第一个产出物料
                Long firstId = ids.get(0);
                vo.setOutputItemId(firstId);
                MesMdItemDO firstItem = itemMap.get(firstId);
                if (firstItem != null) {
                    vo.setOutputItemCode(firstItem.getCode());
                    vo.setOutputItemName(firstItem.getName());
                }
            }
        }
        // 设置每个工序各自的投料BOM
        result.forEach(vo -> vo.setBomItems(bomItemsByProcessId.getOrDefault(vo.getProcessId(), Collections.emptyList())));
        return result;