2 天以前 69dc6b16ef04bdfbfa65f77c169c0847dc7e65c2
src/main/java/com/ruoyi/production/service/impl/ProductionOrderPickServiceImpl.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.production.bean.dto.ProductionOrderPickDto;
@@ -18,6 +19,7 @@
import com.ruoyi.stock.dto.StockInventoryDto;
import com.ruoyi.stock.mapper.StockInventoryMapper;
import com.ruoyi.stock.pojo.StockInventory;
import com.ruoyi.stock.service.StockInventoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -39,10 +41,14 @@
@RequiredArgsConstructor
public class ProductionOrderPickServiceImpl extends ServiceImpl<ProductionOrderPickMapper, ProductionOrderPick> implements ProductionOrderPickService {
    private static final byte PICK_TYPE_NORMAL = 1;
    private static final byte PICK_TYPE_FEEDING = 2;
    private final ProductionOrderMapper productionOrderMapper;
    private final ProductionOperationTaskMapper productionOperationTaskMapper;
    private final ProductionOrderPickRecordMapper productionOrderPickRecordMapper;
    private final StockInventoryMapper stockInventoryMapper;
    private final StockInventoryService stockInventoryService;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -56,7 +62,7 @@
            List<String> batchNoList = resolveBatchNoList(resolvedDto);
            String inventoryBatchNo = pickInventoryBatchNo(batchNoList);
            String storedBatchNo = formatBatchNoStorage(batchNoList);
            subtractInventory(resolvedDto.getProductModelId(), inventoryBatchNo, resolvedDto.getPickQuantity(), rowNo);
            subtractInventory(resolvedDto.getProductModelId(), storedBatchNo, resolvedDto.getPickQuantity(), rowNo);
            ProductionOrderPick orderPick = new ProductionOrderPick();
            orderPick.setProductionOrderId(resolvedDto.getProductionOrderId());
@@ -68,6 +74,7 @@
            orderPick.setTechnologyOperationId(resolvedDto.getTechnologyOperationId());
            orderPick.setDemandedQuantity(resolvedDto.getDemandedQuantity());
            orderPick.setBom(resolvedDto.getBom());
            orderPick.setReturned(false);
            baseMapper.insert(orderPick);
            insertPickRecord(orderPick.getId(),
@@ -79,7 +86,8 @@
                    BigDecimal.ZERO,
                    resolvedDto.getPickQuantity(),
                    resolvedDto.getPickType(),
                    resolvedDto.getRemark());
                    resolvedDto.getRemark(),
                    resolvedDto.getFeedingReason());
        }
        return true;
    }
@@ -105,6 +113,15 @@
        Map<Long, ProductionOrderPick> existingPickMap = existingPickList.stream()
                .filter(item -> item.getId() != null)
                .collect(Collectors.toMap(ProductionOrderPick::getId, Function.identity(), (a, b) -> a));
        if (isFeedingRequest(dto)) {
            processFeedingPickItems(dto, existingPickMap, productionOrderId);
            return true;
        }
        if (isReturnRequest(dto)) {
            processReturnPickItems(dto, existingPickMap, productionOrderId);
            return true;
        }
        processDeletePickIds(dto, existingPickMap, productionOrderId);
@@ -174,7 +191,8 @@
                    oldQuantity,
                    BigDecimal.ZERO,
                    rootDto.getPickType(),
                    rootDto.getRemark());
                    rootDto.getRemark(),
                    rootDto.getFeedingReason());
            existingPickMap.remove(deleteId);
        }
    }
@@ -191,7 +209,7 @@
                .filter(item -> item.getId() != null)
                .filter(item -> Objects.equals(item.getProductionOrderId(), productionOrderId))
                .filter(item -> !keepPickIdSet.contains(item.getId()))
                .collect(Collectors.toList());
                .toList();
        for (ProductionOrderPick missingPick : missingPickList) {
            String oldBatchNo = resolveInventoryBatchNoFromStored(missingPick.getBatchNo());
            BigDecimal oldQuantity = defaultDecimal(missingPick.getQuantity());
@@ -209,7 +227,8 @@
                    oldQuantity,
                    BigDecimal.ZERO,
                    rootDto.getPickType(),
                    rootDto.getRemark());
                    rootDto.getRemark(),
                    rootDto.getFeedingReason());
            existingPickMap.remove(missingPick.getId());
        }
    }
@@ -218,7 +237,7 @@
        List<String> batchNoList = resolveBatchNoList(dto);
        String inventoryBatchNo = pickInventoryBatchNo(batchNoList);
        String storedBatchNo = formatBatchNoStorage(batchNoList);
        subtractInventory(dto.getProductModelId(), inventoryBatchNo, dto.getPickQuantity(), rowNo);
        subtractInventory(dto.getProductModelId(), storedBatchNo, dto.getPickQuantity(), rowNo);
        ProductionOrderPick orderPick = new ProductionOrderPick();
        orderPick.setProductionOrderId(dto.getProductionOrderId());
@@ -230,6 +249,7 @@
        orderPick.setTechnologyOperationId(dto.getTechnologyOperationId());
        orderPick.setDemandedQuantity(dto.getDemandedQuantity());
        orderPick.setBom(dto.getBom());
        orderPick.setReturned(false);
        baseMapper.insert(orderPick);
        insertPickRecord(orderPick.getId(),
@@ -241,7 +261,111 @@
                BigDecimal.ZERO,
                dto.getPickQuantity(),
                dto.getPickType(),
                dto.getRemark());
                dto.getRemark(),
                dto.getFeedingReason());
    }
    private void processFeedingPickItems(ProductionOrderPickDto rootDto,
                                         Map<Long, ProductionOrderPick> existingPickMap,
                                         Long productionOrderId) {
        List<ProductionOrderPickDto> pickItems = resolveUpdateItems(rootDto);
        for (int i = 0; i < pickItems.size(); i++) {
            int rowNo = i + 1;
            ProductionOrderPickDto resolvedDto = mergeDto(rootDto, pickItems.get(i));
            if (isEmptyUpdateItem(resolvedDto)) {
                continue;
            }
            if (!isFeedingPick(resolvedDto)) {
                throw new ServiceException("补料请求中的领料类型必须全部为2");
            }
            if (resolvedDto.getProductionOrderId() == null) {
                resolvedDto.setProductionOrderId(productionOrderId);
            }
            validateFeedingParam(resolvedDto, rowNo);
            ProductionOrderPick oldPick = existingPickMap.get(resolvedDto.getId());
            if (oldPick == null || !Objects.equals(oldPick.getProductionOrderId(), productionOrderId)) {
                throw new ServiceException("第" + rowNo + "条领料记录不存在或不属于当前订单");
            }
            addFeedingPick(resolvedDto, oldPick, rowNo);
        }
    }
    private void addFeedingPick(ProductionOrderPickDto dto, ProductionOrderPick oldPick, int rowNo) {
        if (dto.getProductModelId() != null && !Objects.equals(dto.getProductModelId(), oldPick.getProductModelId())) {
            throw new ServiceException("第" + rowNo + "条补料产品规格与领料记录不一致");
        }
        Long productModelId = oldPick.getProductModelId();
        List<String> batchNoList = resolveBatchNoList(dto);
        String inventoryBatchNo = batchNoList.isEmpty()
                ? resolveInventoryBatchNoFromStored(oldPick.getBatchNo())
                : formatBatchNoStorage(batchNoList);
        BigDecimal feedingQuantity = dto.getFeedingQuantity();
        subtractInventory(productModelId, inventoryBatchNo, feedingQuantity, rowNo);
        BigDecimal beforeFeedingQty = sumFeedingQuantity(dto.getProductionOrderId(), oldPick.getId());
        BigDecimal afterFeedingQty = beforeFeedingQty.add(feedingQuantity);
        insertPickRecord(oldPick.getId(),
                dto.getProductionOrderId(),
                dto.getProductionOperationTaskId(),
                productModelId,
                inventoryBatchNo,
                feedingQuantity,
                beforeFeedingQty,
                afterFeedingQty,
                PICK_TYPE_FEEDING,
                dto.getRemark(),
                dto.getFeedingReason());
        ProductionOrderPick updatePick = new ProductionOrderPick();
        updatePick.setId(oldPick.getId());
        updatePick.setFeedingQty(afterFeedingQty);
        updatePick.setActualQty(calculateActualQty(oldPick, afterFeedingQty));
        int affected = baseMapper.updateById(updatePick);
        if (affected <= 0) {
            throw new ServiceException("第" + rowNo + "条补料总量更新失败");
        }
        oldPick.setFeedingQty(afterFeedingQty);
        oldPick.setActualQty(updatePick.getActualQty());
    }
    private void processReturnPickItems(ProductionOrderPickDto rootDto,
                                        Map<Long, ProductionOrderPick> existingPickMap,
                                        Long productionOrderId) {
        List<ProductionOrderPickDto> pickItems = resolveUpdateItems(rootDto);
        for (int i = 0; i < pickItems.size(); i++) {
            int rowNo = i + 1;
            ProductionOrderPickDto resolvedDto = mergeDto(rootDto, pickItems.get(i));
            if (isEmptyUpdateItem(resolvedDto)) {
                continue;
            }
            if (resolvedDto.getProductionOrderId() == null) {
                resolvedDto.setProductionOrderId(productionOrderId);
            }
            validateReturnParam(resolvedDto, rowNo);
            ProductionOrderPick oldPick = existingPickMap.get(resolvedDto.getId());
            if (oldPick == null || !Objects.equals(oldPick.getProductionOrderId(), productionOrderId)) {
                throw new ServiceException("第" + rowNo + "条领料记录不存在或不属于当前订单");
            }
            updateReturnPick(resolvedDto, oldPick, rowNo);
        }
    }
    private void updateReturnPick(ProductionOrderPickDto dto, ProductionOrderPick oldPick, int rowNo) {
        ProductionOrderPick updatePick = new ProductionOrderPick();
        updatePick.setId(oldPick.getId());
        updatePick.setReturnQty(dto.getReturnQty());
        updatePick.setActualQty(dto.getActualQty());
        updatePick.setReturned(true);
        int affected = baseMapper.updateById(updatePick);
        if (affected <= 0) {
            throw new ServiceException("第" + rowNo + "条退料信息更新失败");
        }
        oldPick.setReturnQty(updatePick.getReturnQty());
        oldPick.setActualQty(updatePick.getActualQty());
        oldPick.setReturned(true);
    }
    private void updateExistingPick(ProductionOrderPickDto dto,
@@ -267,13 +391,13 @@
        if (sameStockKey) {
            BigDecimal delta = newQuantity.subtract(oldQuantity);
            if (delta.compareTo(BigDecimal.ZERO) > 0) {
                subtractInventory(newProductModelId, newBatchNo, delta, rowNo);
                subtractInventory(newProductModelId, newStoredBatchNo, delta, rowNo);
            } else if (delta.compareTo(BigDecimal.ZERO) < 0) {
                addInventory(oldProductModelId, oldBatchNo, delta.abs());
            }
        } else {
            addInventory(oldProductModelId, oldBatchNo, oldQuantity);
            subtractInventory(newProductModelId, newBatchNo, newQuantity, rowNo);
            subtractInventory(newProductModelId, newStoredBatchNo, newQuantity, rowNo);
        }
        oldPick.setProductModelId(newProductModelId);
@@ -304,7 +428,8 @@
                    oldQuantity,
                    newQuantity,
                    dto.getPickType(),
                    dto.getRemark());
                    dto.getRemark(),
                    dto.getFeedingReason());
        }
    }
@@ -317,7 +442,8 @@
                                  BigDecimal beforeQuantity,
                                  BigDecimal afterQuantity,
                                  Byte pickType,
                                  String remark) {
                                  String remark,
                                  String feedingReason) {
        ProductionOrderPickRecord pickRecord = new ProductionOrderPickRecord();
        pickRecord.setPickId(pickId);
        pickRecord.setProductionOrderId(productionOrderId);
@@ -327,28 +453,68 @@
        pickRecord.setPickQuantity(defaultDecimal(pickQuantity));
        pickRecord.setBeforeQuantity(defaultDecimal(beforeQuantity));
        pickRecord.setAfterQuantity(defaultDecimal(afterQuantity));
        pickRecord.setPickType(pickType == null ? (byte) 1 : pickType);
        pickRecord.setPickType(pickType == null ? PICK_TYPE_NORMAL : pickType);
        pickRecord.setRemark(remark);
        pickRecord.setFeedingReason(feedingReason);
        productionOrderPickRecordMapper.insert(pickRecord);
    }
    private void subtractInventory(Long productModelId, String batchNo, BigDecimal quantity, int rowNo) {
        StockInventory stockInventory = stockInventoryMapper.selectOne(buildStockWrapper(productModelId, batchNo));
        if (stockInventory == null) {
            throw new ServiceException("第" + rowNo + "条领料对应库存不存在");
        BigDecimal deductQuantity = defaultDecimal(quantity);
        if (deductQuantity.compareTo(BigDecimal.ZERO) <= 0) {
            return;
        }
        BigDecimal availableQuantity = defaultDecimal(stockInventory.getQualitity())
                .subtract(defaultDecimal(stockInventory.getLockedQuantity()));
        if (quantity.compareTo(availableQuantity) > 0) {
            throw new ServiceException("第" + rowNo + "条领料可用库存不足");
        List<String> batchNoList = parseBatchNoValue(batchNo);
        if (batchNoList.isEmpty()) {
            batchNoList = Collections.singletonList(null);
        }
        StockInventoryDto stockInventoryDto = new StockInventoryDto();
        stockInventoryDto.setProductModelId(productModelId);
        stockInventoryDto.setBatchNo(batchNo);
        stockInventoryDto.setQualitity(quantity);
        int affected = stockInventoryMapper.updateSubtractStockInventory(stockInventoryDto);
        if (affected <= 0) {
            throw new ServiceException("第" + rowNo + "条领料扣减库存失败");
        Map<String, BigDecimal> availableQuantityMap = new LinkedHashMap<>();
        BigDecimal totalAvailableQuantity = BigDecimal.ZERO;
        for (String currentBatchNo : batchNoList) {
            StockInventory stockInventory = stockInventoryMapper.selectOne(buildStockWrapper(productModelId, currentBatchNo));
            BigDecimal availableQuantity = BigDecimal.ZERO;
            if (stockInventory != null) {
                availableQuantity = defaultDecimal(stockInventory.getQualitity())
                        .subtract(defaultDecimal(stockInventory.getLockedQuantity()));
                if (availableQuantity.compareTo(BigDecimal.ZERO) < 0) {
                    availableQuantity = BigDecimal.ZERO;
                }
            }
            availableQuantityMap.put(currentBatchNo, availableQuantity);
            totalAvailableQuantity = totalAvailableQuantity.add(availableQuantity);
        }
        if (deductQuantity.compareTo(totalAvailableQuantity) > 0) {
            BigDecimal shortQuantity = deductQuantity.subtract(totalAvailableQuantity);
            throw new ServiceException("领料可用库存不足,可用库存为" + formatQuantity(totalAvailableQuantity)
                    + ",还差" + formatQuantity(shortQuantity));
        }
        BigDecimal remainingQuantity = deductQuantity;
        for (Map.Entry<String, BigDecimal> entry : availableQuantityMap.entrySet()) {
            if (remainingQuantity.compareTo(BigDecimal.ZERO) <= 0) {
                break;
            }
            BigDecimal availableQuantity = defaultDecimal(entry.getValue());
            if (availableQuantity.compareTo(BigDecimal.ZERO) <= 0) {
                continue;
            }
            BigDecimal currentDeductQuantity = remainingQuantity.min(availableQuantity);
            StockInventoryDto stockInventoryDto = new StockInventoryDto();
            stockInventoryDto.setProductModelId(productModelId);
            stockInventoryDto.setBatchNo(entry.getKey());
            stockInventoryDto.setQualitity(currentDeductQuantity);
            int affected = stockInventoryMapper.updateSubtractStockInventory(stockInventoryDto);
            if (affected <= 0) {
                throw new ServiceException("第" + rowNo + "条领料扣减库存失败");
            }
            remainingQuantity = remainingQuantity.subtract(currentDeductQuantity);
        }
        if (remainingQuantity.compareTo(BigDecimal.ZERO) > 0) {
            throw new ServiceException("第" + rowNo + "条领料扣减库存失败,剩余待扣减数量为" + formatQuantity(remainingQuantity));
        }
    }
@@ -357,25 +523,13 @@
        if (addQuantity.compareTo(BigDecimal.ZERO) <= 0) {
            return;
        }
        StockInventory stockInventory = stockInventoryMapper.selectOne(buildStockWrapper(productModelId, batchNo));
        if (stockInventory == null) {
            StockInventory newStockInventory = new StockInventory();
            newStockInventory.setProductModelId(productModelId);
            newStockInventory.setBatchNo(batchNo);
            newStockInventory.setQualitity(addQuantity);
            newStockInventory.setLockedQuantity(BigDecimal.ZERO);
            newStockInventory.setVersion(1);
            stockInventoryMapper.insert(newStockInventory);
            return;
        }
        StockInventoryDto stockInventoryDto = new StockInventoryDto();
        stockInventoryDto.setProductModelId(productModelId);
        stockInventoryDto.setBatchNo(batchNo);
        stockInventoryDto.setQualitity(addQuantity);
        int affected = stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
        if (affected <= 0) {
            throw new ServiceException("库存回退失败,产品规格ID=" + productModelId);
        }
        stockInventoryDto.setRecordType(String.valueOf(StockInQualifiedRecordTypeEnum.PICK_RETURN_IN.getCode()));
        stockInventoryDto.setRecordId(0L);
        stockInventoryService.addStockInRecordOnly(stockInventoryDto);
    }
    private List<ProductionOrderPickDto> resolvePickItems(ProductionOrderPickDto dto) {
@@ -405,6 +559,11 @@
                && StringUtils.isEmpty(dto.getBatchNo())
                && (dto.getBatchNoList() == null || dto.getBatchNoList().isEmpty())
                && dto.getPickType() == null
                && dto.getFeedingQuantity() == null
                && StringUtils.isEmpty(dto.getFeedingReason())
                && dto.getReturnQty() == null
                && dto.getActualQty() == null
                && dto.getReturned() == null
                && dto.getProductionOperationTaskId() == null
                && dto.getTechnologyOperationId() == null
                && StringUtils.isEmpty(dto.getOperationName())
@@ -440,10 +599,15 @@
            merged.setPickQuantity(itemDto.getPickQuantity());
            merged.setPickType(itemDto.getPickType());
            merged.setRemark(itemDto.getRemark());
            merged.setFeedingReason(itemDto.getFeedingReason());
            merged.setFeedingQuantity(itemDto.getFeedingQuantity());
            merged.setTechnologyOperationId(itemDto.getTechnologyOperationId());
            merged.setOperationName(itemDto.getOperationName());
            merged.setDemandedQuantity(itemDto.getDemandedQuantity());
            merged.setBom(itemDto.getBom());
            merged.setReturnQty(itemDto.getReturnQty());
            merged.setActualQty(itemDto.getActualQty());
            merged.setReturned(itemDto.getReturned());
        }
        if (merged.getId() == null) {
            merged.setId(rootDto.getId());
@@ -472,6 +636,12 @@
        if (merged.getRemark() == null) {
            merged.setRemark(rootDto.getRemark());
        }
        if (merged.getFeedingReason() == null) {
            merged.setFeedingReason(rootDto.getFeedingReason());
        }
        if (merged.getFeedingQuantity() == null) {
            merged.setFeedingQuantity(rootDto.getFeedingQuantity());
        }
        if (merged.getTechnologyOperationId() == null) {
            merged.setTechnologyOperationId(rootDto.getTechnologyOperationId());
        }
@@ -484,6 +654,15 @@
        if (merged.getBom() == null) {
            merged.setBom(rootDto.getBom());
        }
        if (merged.getReturnQty() == null) {
            merged.setReturnQty(rootDto.getReturnQty());
        }
        if (merged.getActualQty() == null) {
            merged.setActualQty(rootDto.getActualQty());
        }
        if (merged.getReturned() == null) {
            merged.setReturned(rootDto.getReturned());
        }
        return merged;
    }
@@ -494,12 +673,92 @@
        if (dto.getProductModelId() == null) {
            throw new ServiceException("第" + rowNo + "条产品规格ID不能为空");
        }
        if (dto.getPickQuantity() == null || dto.getPickQuantity().compareTo(BigDecimal.ZERO) <= 0) {
            throw new ServiceException("第" + rowNo + "条领料数量必须大于0");
        if (dto.getPickQuantity() == null || dto.getPickQuantity().compareTo(BigDecimal.ZERO) < 0) {
            throw new ServiceException("第" + rowNo + "条领料数量不能小于0");
        }
        if (dto.getPickType() != null && dto.getPickType() != 1 && dto.getPickType() != 2) {
        if (dto.getPickType() != null && dto.getPickType() != PICK_TYPE_NORMAL && dto.getPickType() != PICK_TYPE_FEEDING) {
            throw new ServiceException("第" + rowNo + "条领料类型只能是1或2");
        }
    }
    private void validateFeedingParam(ProductionOrderPickDto dto, int rowNo) {
        if (dto.getProductionOrderId() == null) {
            throw new ServiceException("第" + rowNo + "条生产订单ID不能为空");
        }
        if (dto.getId() == null) {
            throw new ServiceException("第" + rowNo + "条领料ID不能为空");
        }
        if (dto.getFeedingQuantity() == null || dto.getFeedingQuantity().compareTo(BigDecimal.ZERO) < 0) {
            throw new ServiceException("第" + rowNo + "条本次补料数量不能小于0");
        }
        if (!isFeedingPick(dto)) {
            throw new ServiceException("第" + rowNo + "条补料类型必须为2");
        }
    }
    private void validateReturnParam(ProductionOrderPickDto dto, int rowNo) {
        if (dto.getProductionOrderId() == null) {
            throw new ServiceException("第" + rowNo + "条生产订单ID不能为空");
        }
        if (dto.getId() == null) {
            throw new ServiceException("第" + rowNo + "条领料ID不能为空");
        }
        if (dto.getReturnQty() == null || dto.getReturnQty().compareTo(BigDecimal.ZERO) < 0) {
            throw new ServiceException("第" + rowNo + "条退料数量不能为空且不能小于0");
        }
        if (dto.getActualQty() == null || dto.getActualQty().compareTo(BigDecimal.ZERO) < 0) {
            throw new ServiceException("第" + rowNo + "条实际数量不能为空且不能小于0");
        }
    }
    private boolean isFeedingRequest(ProductionOrderPickDto dto) {
        if (isFeedingPick(dto)) {
            return true;
        }
        if (dto.getPickList() == null || dto.getPickList().isEmpty()) {
            return false;
        }
        return dto.getPickList().stream()
                .filter(Objects::nonNull)
                .anyMatch(this::isFeedingPick);
    }
    private boolean isFeedingPick(ProductionOrderPickDto dto) {
        return dto != null && Objects.equals(dto.getPickType(), PICK_TYPE_FEEDING);
    }
    private boolean isReturnRequest(ProductionOrderPickDto dto) {
        if (isReturnPick(dto)) {
            return true;
        }
        if (dto.getPickList() == null || dto.getPickList().isEmpty()) {
            return false;
        }
        return dto.getPickList().stream()
                .filter(Objects::nonNull)
                .anyMatch(this::isReturnPick);
    }
    private boolean isReturnPick(ProductionOrderPickDto dto) {
        return dto != null && Boolean.TRUE.equals(dto.getReturned());
    }
    private BigDecimal sumFeedingQuantity(Long productionOrderId, Long pickId) {
        List<ProductionOrderPickRecord> feedingRecords = productionOrderPickRecordMapper.selectList(
                Wrappers.<ProductionOrderPickRecord>lambdaQuery()
                        .eq(ProductionOrderPickRecord::getProductionOrderId, productionOrderId)
                        .eq(ProductionOrderPickRecord::getPickId, pickId)
                        .eq(ProductionOrderPickRecord::getPickType, PICK_TYPE_FEEDING));
        return feedingRecords.stream()
                .map(ProductionOrderPickRecord::getPickQuantity)
                .map(this::defaultDecimal)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
    }
    private BigDecimal calculateActualQty(ProductionOrderPick pick, BigDecimal feedingQty) {
        return defaultDecimal(pick.getQuantity())
                .add(defaultDecimal(feedingQty))
                .subtract(defaultDecimal(pick.getReturnQty()));
    }
    private String normalizeBatchNo(String batchNo) {
@@ -653,5 +912,8 @@
    private BigDecimal defaultDecimal(BigDecimal value) {
        return value == null ? BigDecimal.ZERO : value;
    }
}
    private String formatQuantity(BigDecimal value) {
        return defaultDecimal(value).stripTrailingZeros().toPlainString();
    }
}