3 天以前 b852254d90e7d1955db31db154193ec8ee84d8b3
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/stocktaking/task/MesWmStockTakingTaskResultServiceImpl.java
@@ -14,6 +14,8 @@
import org.springframework.validation.annotation.Validated;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WM_STOCK_TAKING_TASK_LINE_ALREADY_TAKEN;
@@ -22,7 +24,7 @@
/**
 * MES 盘点结果 Service 实现类
 *
 * @author 芋道源码
 * @author 超级管理员
 */
@Service
@Validated
@@ -126,6 +128,34 @@
        stockTakingTaskResultMapper.deleteByTaskId(taskId);
    }
    @Override
    public List<MesWmStockTakingTaskResultDO> getStockTakingTaskResultListByTaskId(Long taskId) {
        return stockTakingTaskResultMapper.selectListByTaskId(taskId);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void upsertResultForImport(MesWmStockTakingTaskLineDO line, BigDecimal takingQuantity) {
        // 1. 查询该任务下是否已存在该行的盘点结果
        MesWmStockTakingTaskResultDO existing = stockTakingTaskResultMapper.selectListByTaskId(line.getTaskId()).stream()
                .filter(result -> Objects.equals(result.getLineId(), line.getId()))
                .findFirst().orElse(null);
        if (existing != null) {
            // 2. 已存在:覆盖实盘数量(重复导入以最后一次为准)
            existing.setTakingQuantity(takingQuantity);
            stockTakingTaskResultMapper.updateById(existing);
            return;
        }
        // 3. 不存在:按盘点行维度新建,账面数量取行账面数量,保证核销差额口径一致
        MesWmStockTakingTaskResultDO result = MesWmStockTakingTaskResultDO.builder()
                .taskId(line.getTaskId()).lineId(line.getId()).materialStockId(line.getMaterialStockId())
                .itemId(line.getItemId()).batchId(line.getBatchId()).batchCode(line.getBatchCode())
                .warehouseId(line.getWarehouseId()).locationId(line.getLocationId()).areaId(line.getAreaId())
                .quantity(line.getQuantity()).takingQuantity(takingQuantity)
                .build();
        stockTakingTaskResultMapper.insert(result);
    }
    /**
     * 校验盘点结果是否存在
     *