huminmin
6 小时以前 39e8f88af6d3c07c183cda4e7c1d1b1c850209f5
src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
@@ -13,6 +13,7 @@
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.enums.StockInventorySourceEnum;
import java.time.LocalDateTime;
import com.ruoyi.stock.dto.StockInRecordDto;
@@ -60,6 +61,9 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int add(StockInRecordDto stockInRecordDto) {
        if (stockInRecordDto.getCreateTime() == null) {
            stockInRecordDto.setCreateTime(LocalDateTime.now());
        }
        String no = OrderUtils.countTodayByCreateTime(stockInRecordMapper, "RK","inbound_batches", stockInRecordDto.getCreateTime() != null ? stockInRecordDto.getCreateTime() : LocalDateTime.now());
        stockInRecordDto.setInboundBatches(no);
        StockInRecord stockInRecord = new StockInRecord();
@@ -104,8 +108,8 @@
                    stockInRecordDto.setQualitity(stockInRecord.getStockInNum());
                    stockInventoryMapper.updateSubtractStockInventory(stockInRecordDto);
                }
            }else if (stockInRecord.getType().equals("1")) {
                String uninventoryType = resolveUninventoryTypeByInRecordType(stockInRecord.getRecordType());
            }else if (stockInRecord.getType().equals("1") || stockInRecord.getType().equals("2")) {
                String uninventoryType = resolveUninventoryTypeByInRecordType(stockInRecord.getType());
                LambdaQueryWrapper<StockUninventory> eq = new LambdaQueryWrapper<StockUninventory>()
                        .eq(StockUninventory::getProductModelId, stockInRecord.getProductModelId())
                        .eq(StockUninventory::getType, uninventoryType);
@@ -237,6 +241,12 @@
                throw new BaseException("只有待审批状态的记录才能审批,入库批次:" + stockInRecord.getInboundBatches());
            }
            // 兼容历史数据或上游漏传场景,审批时补齐来源,避免废品库存台账来源为空
            String resolvedSource = resolveStockSource(stockInRecord);
            if (StringUtils.isNotEmpty(resolvedSource)) {
                stockInRecord.setSource(resolvedSource);
            }
            // 获取审批时修改的入库数量,如果没有修改则使用原数量
            final BigDecimal finalStockInNum;
            if (item.getStockInNum() != null && item.getStockInNum().compareTo(BigDecimal.ZERO) > 0) {
@@ -278,9 +288,9 @@
                    } else {
                        stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
                    }
                } else if ("1".equals(stockInRecord.getType())) {
                } else if ("1".equals(stockInRecord.getType()) || "2".equals(stockInRecord.getType())) {
                    // 不合格入库 -> 先查库存,存在则更新,不存在则新增
                    String uninventoryType = resolveUninventoryTypeByInRecordType(stockInRecord.getRecordType());
                    String uninventoryType = resolveUninventoryTypeByInRecordType(stockInRecord.getType());
                    StockUninventory stockUninventory = getStockUninventory(stockInRecord.getProductModelId(), stockInRecord.getBatchNo(), uninventoryType);
                    StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
                    stockUninventoryDto.setProductModelId(stockInRecord.getProductModelId());
@@ -310,8 +320,8 @@
        return items.size();
    }
    private String resolveUninventoryTypeByInRecordType(String recordType) {
        if (StockInQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode().equals(recordType)) {
    private String resolveUninventoryTypeByInRecordType(String stockInType) {
        if ("2".equals(stockInType)) {
            return WASTE_TYPE;
        }
        return UNQUALIFIED_TYPE;
@@ -350,6 +360,23 @@
        return stockInventoryDto;
    }
    private String resolveStockSource(StockInRecord stockInRecord) {
        if (stockInRecord == null || StringUtils.isNotEmpty(stockInRecord.getSource())) {
            return stockInRecord == null ? null : stockInRecord.getSource();
        }
        if (StockInQualifiedRecordTypeEnum.DEFECTIVE_SCRAP.getCode().equals(stockInRecord.getRecordType())
                || StockInQualifiedRecordTypeEnum.PRODUCTION_SCRAP.getCode().equals(stockInRecord.getRecordType())) {
            if (StockInQualifiedRecordTypeEnum.DEFECTIVE_SCRAP.getCode().equals(stockInRecord.getRecordType())) {
                return StockInventorySourceEnum.DEFECTIVE_SCRAP.getCode();
            }
            return StockInventorySourceEnum.PROD_GENERATED.getCode();
        }
        if (StockInQualifiedRecordTypeEnum.RETURN_WASTE_IN.getCode().equals(stockInRecord.getRecordType())) {
            return StockInventorySourceEnum.RETURN_GENERATED.getCode();
        }
        return stockInRecord.getSource();
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int batchReAudit(List<Long> ids) {