liyong
3 天以前 f57064d2fa563ee4cfeeccd715850ba8b8aa4f60
src/main/java/com/ruoyi/production/service/impl/ProductionOrderServiceImpl.java
@@ -14,8 +14,10 @@
import com.ruoyi.basic.utils.FileUtil;
import com.ruoyi.common.constant.StorageAttachmentConstants;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.production.bean.dto.ProductionOperationTaskDto;
import com.ruoyi.production.bean.dto.ProductionOrderDto;
import com.ruoyi.production.bean.vo.ProductionBomStructureVo;
import com.ruoyi.production.bean.vo.ProductionOperationTaskVo;
import com.ruoyi.production.bean.vo.ProductionOrderPickVo;
import com.ruoyi.production.bean.vo.ProductionOrderVo;
import com.ruoyi.production.bean.vo.ProductionPlanVo;
@@ -80,6 +82,7 @@
    @Override
    public IPage<ProductionOrderVo> pageProductionOrder(Page<ProductionOrderDto> page, ProductionOrderDto dto) {
        // 分页查询生产订单
        Page<ProductionOrderVo> result = (Page<ProductionOrderVo>) baseMapper.pageProductionOrder(page, dto);
        fillProductImages(result.getRecords());
        return result;
@@ -87,6 +90,7 @@
    @Override
    public List<ProductionOrderVo> listProductionOrder(ProductionOrderDto dto) {
        // 查询生产订单列表
        List<ProductionOrderVo> records = baseMapper.listProductionOrder(dto);
        fillProductImages(records);
        return records;
@@ -94,6 +98,7 @@
    @Override
    public ProductionOrderVo getProductionOrderInfo(Long id) {
        // 获取生产订单详情
        ProductionOrderVo item = baseMapper.getProductionOrderInfo(id);
        if (item == null) {
            return null;
@@ -104,6 +109,7 @@
    @Override
    public boolean saveProductionOrder(ProductionOrder productionOrder) {
        // 保存生产订单
        ProductionOrder oldOrder = productionOrder.getId() == null ? null : this.getById(productionOrder.getId());
        // 下单入口统一补齐来源单据、计划和工艺信息,避免前端分别传多套字段。
        validateAndFillOrder(productionOrder, oldOrder);
@@ -135,6 +141,7 @@
    @Override
    public boolean removeProductionOrder(List<Long> ids) {
        // 删除生产订单
        if (ids == null || ids.isEmpty()) {
            return false;
        }
@@ -148,6 +155,7 @@
    @Override
    public Integer bindingRoute(ProductionOrderDto productionOrderDto) {
        // 为订单绑定工艺路线
        if (productionOrderDto == null || productionOrderDto.getId() == null) {
            throw new ServiceException("生产订单ID不能为空");
        }
@@ -191,6 +199,7 @@
    @Override
    public List<ProductionPlanVo> getSource(Long id) {
        // 查询订单关联来源计划
        ProductionOrder productionOrder = baseMapper.selectById(id);
        if (productionOrder != null && productionOrder.getProductionPlanIds() != null) {
            List<Long> planIds = parsePlanIds(productionOrder.getProductionPlanIds());
@@ -201,7 +210,9 @@
    @Override
    public int syncProductionOrderSnapshot(Long productionOrderId) {
        // 同步订单工艺、工序、参数和BOM快照
        ProductionOrder productionOrder = this.getById(productionOrderId);
        // 参数与前置条件校验
        if (productionOrder == null) {
            throw new ServiceException("生产订单不存在");
        }
@@ -216,6 +227,7 @@
        clearProductionSnapshot(productionOrderId);
        ProductionOrderBom orderBom = syncProductionOrderBomSnapshot(productionOrder, technologyRouting);
        //生产订单工艺路线表
        ProductionOrderRouting orderRouting = new ProductionOrderRouting();
        orderRouting.setProductionOrderId(productionOrder.getId());
        orderRouting.setTechnologyRoutingId(technologyRouting.getId());
@@ -227,12 +239,26 @@
        productionOrderRoutingMapper.insert(orderRouting);
        int syncedParamCount = 0;
        // 查询并准备业务数据
        List<TechnologyRoutingOperation> routingOperations = technologyRoutingOperationMapper.selectList(
                Wrappers.<TechnologyRoutingOperation>lambdaQuery()
                        .eq(TechnologyRoutingOperation::getTechnologyRoutingId, technologyRouting.getId())
                        .orderByDesc(TechnologyRoutingOperation::getDragSort)
                        .orderByDesc(TechnologyRoutingOperation::getId));
        // Build task plan quantities from order BOM snapshot demand instead of recomputing from technology BOM units.
        Long rootProductModelId = orderBom != null && orderBom.getProductModelId() != null
                ? orderBom.getProductModelId()
                : productionOrder.getProductModelId();
        List<ProductionBomStructure> orderBomStructureList = orderBom == null || orderBom.getId() == null
                ? Collections.emptyList()
                : productionBomStructureMapper.selectList(
                Wrappers.<ProductionBomStructure>lambdaQuery()
                        .eq(ProductionBomStructure::getProductionOrderBomId, orderBom.getId())
                        .orderByAsc(ProductionBomStructure::getId));
        Map<String, BigDecimal> operationDemandedQuantityMap =
                buildOperationDemandedQuantityMap(orderBomStructureList, rootProductModelId);
        Map<Long, String> operationNameMap = technologyOperationMapper.selectBatchIds(
        // 遍历处理数据并组装结果
                        routingOperations.stream()
                                .map(TechnologyRoutingOperation::getTechnologyOperationId)
                                .filter(Objects::nonNull)
@@ -256,6 +282,7 @@
            targetOperation.setIsQuality(sourceOperation.getIsQuality());
            targetOperation.setOperationName(operationNameMap.get(sourceOperation.getTechnologyOperationId()));
            targetOperation.setTechnologyOperationId(sourceOperation.getTechnologyOperationId());
            targetOperation.setType(sourceOperation.getType());
            productionOrderRoutingOperationMapper.insert(targetOperation);
            boolean isLastOperation = lastDragSort != null && Objects.equals(sourceOperation.getDragSort(), lastDragSort);
@@ -263,7 +290,11 @@
                ProductionOperationTask task = new ProductionOperationTask();
                task.setProductionOrderRoutingOperationId(targetOperation.getId());
                task.setProductionOrderId(productionOrder.getId());
                task.setPlanQuantity(defaultDecimal(productionOrder.getQuantity()));
                task.setPlanQuantity(resolveTaskPlanQuantity(
                        sourceOperation,
                        operationDemandedQuantityMap,
                        productionOrder,
                        rootProductModelId));
                task.setCompleteQuantity(BigDecimal.ZERO);
                task.setWorkOrderNo(generateNextTaskNo());
                task.setStatus(2);
@@ -298,7 +329,87 @@
        return syncedParamCount;
    }
    private Map<String, BigDecimal> buildOperationDemandedQuantityMap(List<ProductionBomStructure> bomStructures,
                                                                      Long rootProductModelId) {
        if (bomStructures == null || bomStructures.isEmpty()) {
            return Collections.emptyMap();
        }
        Map<Long, ProductionBomStructure> structureById = bomStructures.stream()
                .filter(item -> item != null && item.getId() != null)
                .collect(Collectors.toMap(ProductionBomStructure::getId, item -> item, (left, right) -> left));
        Map<String, BigDecimal> demandedQuantityMap = new HashMap<>();
        Set<String> mergedOutputNodeKeySet = new HashSet<>();
        for (ProductionBomStructure bomStructure : bomStructures) {
            if (bomStructure == null || bomStructure.getTechnologyOperationId() == null) {
                continue;
            }
            // The BOM row points to the producing operation; task quantity should come from that operation's output node.
            ProductionBomStructure outputNode = resolveOperationOutputNode(bomStructure, structureById);
            Long outputProductModelId = resolveOutputProductModelId(outputNode, rootProductModelId);
            if (outputProductModelId == null) {
                continue;
            }
            String mergedOutputNodeKey = buildOperationOutputNodeKey(
                    bomStructure.getTechnologyOperationId(),
                    outputNode == null ? null : outputNode.getId(),
                    outputProductModelId);
            if (!mergedOutputNodeKeySet.add(mergedOutputNodeKey)) {
                continue;
            }
            // demandedQuantity is already the order-level required output quantity for the current output node.
            BigDecimal demandedQuantity = defaultDecimal(outputNode == null ? null : outputNode.getDemandedQuantity());
            String key = buildOperationDemandedQuantityKey(bomStructure.getTechnologyOperationId(), outputProductModelId);
            demandedQuantityMap.merge(key, demandedQuantity, BigDecimal::add);
        }
        return demandedQuantityMap;
    }
    private BigDecimal resolveTaskPlanQuantity(TechnologyRoutingOperation sourceOperation,
                                               Map<String, BigDecimal> operationDemandedQuantityMap,
                                               ProductionOrder productionOrder,
                                               Long rootProductModelId) {
        if (sourceOperation == null || operationDemandedQuantityMap == null || operationDemandedQuantityMap.isEmpty()) {
            return defaultDecimal(productionOrder == null ? null : productionOrder.getQuantity());
        }
        Long outputProductModelId = sourceOperation.getProductModelId() != null
                ? sourceOperation.getProductModelId()
                : rootProductModelId;
        String key = buildOperationDemandedQuantityKey(sourceOperation.getTechnologyOperationId(), outputProductModelId);
        BigDecimal planQuantity = operationDemandedQuantityMap.get(key);
        return planQuantity != null ? planQuantity : defaultDecimal(productionOrder == null ? null : productionOrder.getQuantity());
    }
    private String buildOperationDemandedQuantityKey(Long operationId, Long outputProductModelId) {
        return String.valueOf(operationId) + "#" + String.valueOf(outputProductModelId);
    }
    private String buildOperationOutputNodeKey(Long operationId, Long outputNodeId, Long outputProductModelId) {
        return String.valueOf(operationId) + "#" + String.valueOf(outputNodeId) + "#" + String.valueOf(outputProductModelId);
    }
    private ProductionBomStructure resolveOperationOutputNode(ProductionBomStructure bomStructure,
                                                              Map<Long, ProductionBomStructure> structureById) {
        if (bomStructure == null) {
            return null;
        }
        // The root node is the first output node; child rows use their direct parent as the current operation output.
        if (bomStructure.getParentId() == null) {
            return bomStructure;
        }
        ProductionBomStructure parent = structureById.get(bomStructure.getParentId());
        return parent != null ? parent : bomStructure;
    }
    private Long resolveOutputProductModelId(ProductionBomStructure outputNode,
                                             Long rootProductModelId) {
        if (outputNode == null) {
            return rootProductModelId;
        }
        return outputNode.getProductModelId() != null ? outputNode.getProductModelId() : rootProductModelId;
    }
    private ProductionOrderBom syncProductionOrderBomSnapshot(ProductionOrder productionOrder, TechnologyRouting technologyRouting) {
        // 同步订单BOM快照结构
        if (technologyRouting.getBomId() == null) {
            return null;
        }
@@ -306,10 +417,12 @@
        if (technologyBom == null) {
            throw new ServiceException("工艺BOM不存在");
        }
        // 查询并准备业务数据
        List<TechnologyBomStructure> structureList = technologyBomStructureMapper.selectList(
                Wrappers.<TechnologyBomStructure>lambdaQuery()
                        .eq(TechnologyBomStructure::getBomId, technologyBom.getId())
                        .orderByAsc(TechnologyBomStructure::getId));
        // 遍历处理数据并组装结果
        TechnologyBomStructure root = structureList.stream().filter(item -> item.getParentId() == null).findFirst().orElse(null);
        BigDecimal orderQuantity = defaultDecimal(productionOrder.getQuantity());
@@ -320,9 +433,11 @@
        orderBom.setRemark(technologyBom.getRemark());
        orderBom.setBomNo(technologyBom.getBomNo());
        orderBom.setVersion(technologyBom.getVersion());
        // 持久化或输出处理结果
        productionOrderBomMapper.insert(orderBom);
        Map<Long, Long> idMap = new HashMap<>();
        BigDecimal lastProcessDemandedQuantity = orderQuantity;
        for (TechnologyBomStructure source : structureList) {
            // 子节点 parentId 需要映射成新快照节点 id,才能保留原始 BOM 层级。
            ProductionBomStructure target = new ProductionBomStructure();
@@ -332,25 +447,29 @@
            target.setProductModelId(source.getProductModelId());
            target.setTechnologyOperationId(source.getOperationId());
            target.setUnitQuantity(source.getUnitQuantity());
            target.setDemandedQuantity(source.getUnitQuantity().multiply(orderQuantity));
            target.setDemandedQuantity(lastProcessDemandedQuantity.multiply(source.getUnitQuantity()));
            target.setUnit(source.getUnit());
            productionBomStructureMapper.insert(target);
            idMap.put(source.getId(), target.getId());
            lastProcessDemandedQuantity = target.getDemandedQuantity();
        }
        return orderBom;
    }
    private void clearProductionSnapshot(Long productionOrderId) {
        // 已产生领料记录后禁止重建,避免备料/投料依据与订单快照脱节。
        // 清理订单已生成的工艺与BOM快照数据
        boolean hasPickRecord = productionOrderPickRecordMapper.selectCount(
        // 查询并准备业务数据
                Wrappers.<ProductionOrderPickRecord>lambdaQuery()
                        .eq(ProductionOrderPickRecord::getProductionOrderId, productionOrderId)) > 0;
        // 参数与前置条件校验
        if (hasPickRecord) {
            throw new ServiceException("生产订单已存在领料记录,不能重新生成快照");
        }
        List<Long> taskIds = productionOperationTaskMapper.selectList(
                        Wrappers.<ProductionOperationTask>lambdaQuery()
                                .eq(ProductionOperationTask::getProductionOrderId, productionOrderId))
        // 遍历处理数据并组装结果
                .stream().map(ProductionOperationTask::getId).collect(Collectors.toList());
        if (!taskIds.isEmpty()) {
            // 已有报工记录说明订单已开工,此时不允许再重建快照。
@@ -378,6 +497,7 @@
    }
    private LambdaQueryWrapper<ProductionOrder> buildQueryWrapper(ProductionOrderDto dto) {
        // 按条件动态构建数据库查询条件
        ProductionOrder query = dto == null ? new ProductionOrder() : dto;
        return Wrappers.<ProductionOrder>lambdaQuery()
                .eq(query.getId() != null, ProductionOrder::getId, query.getId())
@@ -388,6 +508,7 @@
    }
    private String generateNextOrderNo() {
        // 生成下一个生产订单号
        String datePrefix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        String prefix = "SC" + datePrefix;
        ProductionOrder latestOrder = this.getOne(Wrappers.<ProductionOrder>lambdaQuery()
@@ -406,6 +527,7 @@
    }
    private String generateNextTaskNo() {
        // 生成下一个生产工单号
        String datePrefix = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        String prefix = "GD" + datePrefix;
        ProductionOperationTask lastTask = productionOperationTaskMapper.selectOne(
@@ -425,10 +547,12 @@
    }
    private BigDecimal defaultDecimal(BigDecimal value) {
        // 将空数量兜底为0,避免空指针异常
        return value == null ? BigDecimal.ZERO : value;
    }
    private void validateAndFillOrder(ProductionOrder productionOrder, ProductionOrder oldOrder) {
        // 校验订单参数并补齐默认值
        if (productionOrder == null) {
            throw new ServiceException("生产订单不能为空");
        }
@@ -461,7 +585,9 @@
    }
    private void fillFromProductionPlans(ProductionOrder productionOrder) {
        // 从关联生产计划回填订单关键字段
        List<Long> planIds = parsePlanIds(productionOrder.getProductionPlanIds());
        // 参数与前置条件校验
        if (planIds.isEmpty()) {
            return;
        }
@@ -470,6 +596,7 @@
        if (productionPlans.size() != planIds.size()) {
            throw new ServiceException("部分生产计划不存在");
        }
        // 遍历处理数据并组装结果
        Map<Long, ProductionPlan> planMap = productionPlans.stream()
                .collect(Collectors.toMap(ProductionPlan::getId, item -> item, (left, right) -> left));
        ProductionPlan mainPlan = planMap.get(planIds.get(0));
@@ -508,6 +635,7 @@
    }
    private void releaseProductionPlanIssueStatus(ProductionOrder productionOrder) {
        // 回退生产计划下发状态
        if (productionOrder == null) {
            return;
        }
@@ -520,6 +648,7 @@
    //生产订单删除,生产计划的已下发数量对应变更
    private void updatePlanIssuedFlag(List<Long> planIds, BigDecimal remainingAssignedQuantity) {
        // 更新计划下发标记和下发数量
        if (planIds == null || planIds.isEmpty()) {
            return;
        }
@@ -549,6 +678,7 @@
    }
    private BigDecimal resolveRemainingQuantity(ProductionPlan plan) {
        // 计算当前计划或记录的剩余数量
        if (plan == null) {
            return BigDecimal.ZERO;
        }
@@ -567,6 +697,7 @@
    }
    private int resolvePlanStatus(BigDecimal requiredQuantity, BigDecimal issuedQuantity) {
        // 根据需求量和下发量推导计划状态
        if (requiredQuantity == null || requiredQuantity.compareTo(BigDecimal.ZERO) <= 0) {
            return 0;
        }
@@ -577,6 +708,7 @@
    }
    private List<Long> parsePlanIds(String productionPlanIds) {
        // 将计划ID字符串解析为Long列表
        if (productionPlanIds == null || productionPlanIds.trim().isEmpty()) {
            return new ArrayList<>();
        }
@@ -593,6 +725,7 @@
    }
    private String formatPlanIds(List<Long> planIds) {
        // 将计划ID集合格式化为[1,2,3]字符串
        if (planIds == null || planIds.isEmpty()) {
            return null;
        }
@@ -603,6 +736,7 @@
    }
    private LocalDate resolvePlanCompleteDate(ProductionPlan productionPlan) {
        // 解析计划完成日期
        if (productionPlan == null) {
            return null;
        }
@@ -616,13 +750,16 @@
    }
    private int compareDecimal(BigDecimal left, BigDecimal right) {
        // 安全比较两个数量值大小
        return defaultDecimal(left).compareTo(defaultDecimal(right));
    }
    private void fillProductImages(List<ProductionOrderVo> records) {
        // 填充产品图片
        if (records == null || records.isEmpty()) {
            return;
        }
        // 遍历处理数据并组装结果
        List<Long> productModelIds = records.stream()
                .map(ProductionOrderVo::getProductModelId)
                .filter(Objects::nonNull)
@@ -632,6 +769,7 @@
            return;
        }
        // 查询并准备业务数据
        List<StorageAttachment> attachments = storageAttachmentMapper.selectList(
                Wrappers.<StorageAttachment>lambdaQuery()
                        .in(StorageAttachment::getRecordId, productModelIds)
@@ -674,6 +812,7 @@
    }
    private StorageBlobVO toStorageBlobVO(StorageBlob blob) {
        // 将存储文件对象转换为VO
        StorageBlobVO vo = BeanUtil.copyProperties(blob, StorageBlobVO.class);
        vo.setPreviewURL(fileUtil.buildSignedPreviewUrl(vo));
        vo.setDownloadURL(fileUtil.buildSignedDownloadUrl(vo));
@@ -681,43 +820,51 @@
    }
    @Override
    public ProductionOrderWorkOrderDetailVo getWorkOrderReportInspectDetail(Long productionOrderId) {
        if (productionOrderId == null) {
            throw new ServiceException("productionOrderId can not be null");
        }
    public ProductionOrderWorkOrderDetailVo getWorkOrderReportInspectDetail(ProductionOrderDto dto) {
        // 获取工单订单报工质检明细
        Long productionOrderId = resolveProductionOrderId(dto);
        ProductionOrderVo orderInfo = getProductionOrderInfo(productionOrderId);
        // 参数与前置条件校验
        if (orderInfo == null) {
            throw new ServiceException("production order not found");
            throw new ServiceException("生产订单不存在");
        }
        ProductionOrderWorkOrderDetailVo detailVo = new ProductionOrderWorkOrderDetailVo();
        detailVo.setProductionOrder(orderInfo);
        List<ProductionOperationTask> workOrderList = productionOperationTaskMapper.selectList(
                Wrappers.<ProductionOperationTask>lambdaQuery()
                        .eq(ProductionOperationTask::getProductionOrderId, productionOrderId)
                        .orderByAsc(ProductionOperationTask::getId));
        if (workOrderList == null || workOrderList.isEmpty()) {
        ProductionOperationTaskDto taskQuery = new ProductionOperationTaskDto();
        taskQuery.setProductionOrderId(productionOrderId);
        IPage<ProductionOperationTaskVo> workOrderPage = productionOperationTaskMapper.pageProductionOperationTask(
                new Page<ProductionOperationTaskVo>(1, -1), taskQuery);
        List<ProductionOperationTaskVo> workOrderList = workOrderPage == null || workOrderPage.getRecords() == null
                ? Collections.emptyList()
        // 遍历处理数据并组装结果
                : workOrderPage.getRecords().stream()
                .filter(Objects::nonNull)
                .sorted(Comparator.comparing(ProductionOperationTaskVo::getId, Comparator.nullsLast(Comparator.naturalOrder())))
                .toList();
        if (workOrderList.isEmpty()) {
            detailVo.setWorkOrderList(Collections.emptyList());
            return detailVo;
        }
        List<Long> workOrderIdList = workOrderList.stream()
                .map(ProductionOperationTask::getId)
                .map(ProductionOperationTaskVo::getId)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
        List<ProductionProductMain> reportMainList = workOrderIdList.isEmpty()
                ? Collections.emptyList()
        // 查询并准备业务数据
                : productionProductMainMapper.selectList(
                Wrappers.<ProductionProductMain>lambdaQuery()
                        .in(ProductionProductMain::getProductionOperationTaskId, workOrderIdList)
                        .orderByAsc(ProductionProductMain::getId));
        Map<Long, List<ProductionProductMain>> reportMainMap = new LinkedHashMap<>();
        Map<Long, List<ProductionProductMain>> reportMainByWorkOrderMap = new LinkedHashMap<>();
        for (ProductionProductMain reportMain : reportMainList) {
            if (reportMain == null || reportMain.getProductionOperationTaskId() == null) {
                continue;
            }
            reportMainMap.computeIfAbsent(reportMain.getProductionOperationTaskId(), k -> new ArrayList<>()).add(reportMain);
            reportMainByWorkOrderMap.computeIfAbsent(reportMain.getProductionOperationTaskId(), key -> new ArrayList<>()).add(reportMain);
        }
        List<Long> reportMainIdList = reportMainList.stream()
@@ -738,12 +885,10 @@
                if (reportOutput == null) {
                    continue;
                }
                Long reportMainId = reportOutput.getProductionProductMainId() != null
                        ? reportOutput.getProductionProductMainId()
                        : reportOutput.getProductMainId();
                if (reportMainId == null) {
                if (reportOutput.getProductionProductMainId() == null) {
                    continue;
                }
                Long reportMainId = reportOutput.getProductionProductMainId();
                reportOutputMap.computeIfAbsent(reportMainId, k -> new ArrayList<>()).add(reportOutput);
            }
@@ -766,7 +911,7 @@
                if (inspect == null || inspect.getProductMainId() == null) {
                    continue;
                }
                inspectMap.computeIfAbsent(inspect.getProductMainId(), k -> new ArrayList<>()).add(inspect);
                inspectMap.computeIfAbsent(inspect.getProductMainId(), key -> new ArrayList<>()).add(inspect);
            }
            List<Long> inspectIdList = inspectList.stream()
@@ -799,42 +944,46 @@
        }
        List<ProductionOrderWorkOrderDetailVo.WorkOrderDetail> workOrderDetailList = new ArrayList<>();
        for (ProductionOperationTask workOrder : workOrderList) {
        for (ProductionOperationTaskVo workOrder : workOrderList) {
            ProductionOrderWorkOrderDetailVo.WorkOrderDetail workOrderDetail = new ProductionOrderWorkOrderDetailVo.WorkOrderDetail();
            workOrderDetail.setWorkOrder(workOrder);
            List<ProductionProductMain> workOrderReportMainList = reportMainMap.get(workOrder.getId());
            if (workOrderReportMainList == null || workOrderReportMainList.isEmpty()) {
            List<ProductionProductMain> workOrderReportMainList = reportMainByWorkOrderMap.getOrDefault(workOrder.getId(), Collections.emptyList());
            if (workOrderReportMainList.isEmpty()) {
                workOrderDetail.setReportList(Collections.emptyList());
                workOrderDetail.setInspectList(Collections.emptyList());
                workOrderDetailList.add(workOrderDetail);
                continue;
            }
            List<ProductionOrderWorkOrderDetailVo.ReportDetail> reportDetailList = new ArrayList<>();
            List<ProductionOrderWorkOrderDetailVo.InspectDetail> inspectDetailList = new ArrayList<>();
            for (ProductionProductMain reportMain : workOrderReportMainList) {
                Long reportMainId = reportMain.getId();
                ProductionOrderWorkOrderDetailVo.ReportDetail reportDetail = new ProductionOrderWorkOrderDetailVo.ReportDetail();
                reportDetail.setReportMain(reportMain);
                reportDetail.setWorkHour(reportMain.getWorkHour());
                reportDetail.setReportOutputList(reportOutputMap.getOrDefault(reportMainId, Collections.emptyList()));
                reportDetail.setReportParamList(reportParamMap.getOrDefault(reportMainId, Collections.emptyList()));
                List<QualityInspect> reportInspectList = inspectMap.get(reportMainId);
                if (reportInspectList == null || reportInspectList.isEmpty()) {
                    reportDetail.setInspectList(Collections.emptyList());
                } else {
                    List<ProductionOrderWorkOrderDetailVo.InspectDetail> inspectDetailList = new ArrayList<>();
                    for (QualityInspect inspect : reportInspectList) {
                        ProductionOrderWorkOrderDetailVo.InspectDetail inspectDetail = new ProductionOrderWorkOrderDetailVo.InspectDetail();
                        inspectDetail.setInspect(inspect);
                        inspectDetail.setInspectParamList(inspectParamMap.getOrDefault(inspect.getId(), Collections.emptyList()));
                        inspectDetail.setInspectFileList(inspectFileMap.getOrDefault(inspect.getId(), Collections.emptyList()));
                        inspectDetailList.add(inspectDetail);
                    }
                    reportDetail.setInspectList(inspectDetailList);
                }
                reportDetailList.add(reportDetail);
                List<QualityInspect> reportInspectList = inspectMap.getOrDefault(reportMainId, Collections.emptyList());
                for (QualityInspect inspect : reportInspectList) {
                    ProductionOrderWorkOrderDetailVo.InspectDetail inspectDetail = new ProductionOrderWorkOrderDetailVo.InspectDetail();
                    inspectDetail.setReportId(reportMainId);
                    inspectDetail.setReportNo(reportMain.getProductNo());
                    inspectDetail.setReportMain(reportMain);
                    inspectDetail.setWorkHour(reportMain.getWorkHour());
                    inspectDetail.setInspect(inspect);
                    inspectDetail.setInspectParamList(inspectParamMap.getOrDefault(inspect.getId(), Collections.emptyList()));
                    inspectDetail.setInspectFileList(inspectFileMap.getOrDefault(inspect.getId(), Collections.emptyList()));
                    inspectDetailList.add(inspectDetail);
                }
            }
            workOrderDetail.setReportList(reportDetailList);
            workOrderDetail.setInspectList(inspectDetailList);
            workOrderDetailList.add(workOrderDetail);
        }
@@ -842,12 +991,35 @@
        return detailVo;
    }
    private Long resolveProductionOrderId(ProductionOrderDto dto) {
        // 从入参中解析生产订单ID并校验
        if (dto == null) {
            throw new ServiceException("请传入生产订单ID或生产订单号");
        }
        if (dto.getId() != null) {
            return dto.getId();
        }
        if (dto.getNpsNo() == null || dto.getNpsNo().trim().isEmpty()) {
            throw new ServiceException("请传入生产订单ID或生产订单号");
        }
        ProductionOrder productionOrder = baseMapper.selectOne(
                Wrappers.<ProductionOrder>lambdaQuery()
                        .eq(ProductionOrder::getNpsNo, dto.getNpsNo().trim())
                        .last("limit 1"));
        if (productionOrder == null || productionOrder.getId() == null) {
            throw new ServiceException("生产订单不存在");
        }
        return productionOrder.getId();
    }
    @Override
    public List<ProductionOrderPickVo> pick(Long productionOrderId) {
        // 查询订单领料、投料与退料明细
        if (productionOrderId == null) {
            return Collections.emptyList();
        }
        // 查询并准备业务数据
        ProductionOrderBom orderBom = productionOrderBomMapper.selectOne(
                Wrappers.<ProductionOrderBom>lambdaQuery()
                        .eq(ProductionOrderBom::getProductionOrderId, productionOrderId)
@@ -862,6 +1034,7 @@
            return Collections.emptyList();
        }
        // 遍历处理数据并组装结果
        List<Long> productModelIds = bomStructureList.stream()
                .map(ProductionBomStructureVo::getProductModelId)
                .filter(Objects::nonNull)
@@ -918,6 +1091,7 @@
    @Override
    public int updateOrder(ProductionOrderDto productionOrderDto) {
        // 更新生产订单主数据
        productionOrderDto.setStatus(5);
        return baseMapper.updateById(productionOrderDto);
    }