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();
@@ -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) {
@@ -290,7 +300,6 @@
                    stockUninventoryDto.setManufacturerId(stockInRecord.getManufacturerId());
                    stockUninventoryDto.setSource(stockInRecord.getSource());
                    stockUninventoryDto.setType(uninventoryType);
                    stockUninventoryDto.setSource(stockInRecord.getSource());
                    if (stockUninventory == null) {
                        stockUninventoryMapper.insert(new StockUninventory() {{
                            setProductModelId(stockInRecord.getProductModelId());
@@ -351,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) {