3 天以前 b852254d90e7d1955db31db154193ec8ee84d8b3
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/stocktaking/task/MesWmStockTakingTaskLineServiceImpl.java
@@ -21,6 +21,7 @@
import cn.iocoder.yudao.module.mes.service.wm.materialstock.MesWmMaterialStockService;
import cn.iocoder.yudao.module.mes.service.wm.stocktaking.plan.MesWmStockTakingPlanParamService;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -52,6 +53,10 @@
    private MesWmMaterialStockService materialStockService;
    @Resource
    private MesWmStockTakingTaskService stockTakingTaskService;
    // 与 ResultService 相互引用(ResultServiceImpl 已注入 LineService),须用 @Lazy 打破循环
    @Lazy
    @Resource
    private MesWmStockTakingTaskResultService stockTakingTaskResultService;
    @Resource
    private cn.iocoder.yudao.module.mdm.api.item.MdmItemApi mdmItemApi;
@@ -74,7 +79,8 @@
        // 3. 批量生成明细行
        List<MesWmStockTakingTaskLineDO> lines = convertList(stocks, stock -> MesWmStockTakingTaskLineDO.builder()
                .taskId(task.getId()).materialStockId(stock.getId()).itemId(stock.getItemId())
                .batchId(stock.getBatchId()).quantity(stock.getQuantity()).takingQuantity(BigDecimal.ZERO)
                .batchId(stock.getBatchId()).batchCode(stock.getBatchCode())
                .quantity(stock.getQuantity()).takingQuantity(BigDecimal.ZERO)
                .warehouseId(stock.getWarehouseId()).locationId(stock.getLocationId()).areaId(stock.getAreaId())
                .status(MesWmStockTakingTaskLineStatusEnum.LOSS.getStatus()).build());
        stockTakingTaskLineMapper.insertBatch(lines);
@@ -244,6 +250,8 @@
        if (CollUtil.isEmpty(list)) {
            return respVO;
        }
        // 0. 校验盘点任务处于盘点中状态(与人工录入盘点结果口径一致,仅盘点中可导入)
        stockTakingTaskService.validateStockTakingTaskExistsAndApproving(taskId);
        // 1. 获取盘点任务行
        List<MesWmStockTakingTaskLineDO> lines = stockTakingTaskLineMapper.selectListByTaskId(taskId);
        if (CollUtil.isEmpty(lines)) {
@@ -283,6 +291,8 @@
                continue;
            }
            updateStockTakingTaskLineTakingQuantity(matched.getId(), row.getTakingQuantity());
            // 同步写盘点结果,保证差异核销来源(task_result)一致
            stockTakingTaskResultService.upsertResultForImport(matched, row.getTakingQuantity());
            respVO.setSuccessCount(respVO.getSuccessCount() + 1);
        }
        return respVO;