| | |
| | | |
| | | 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; |
| | |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 校验盘点结果是否存在 |
| | | * |