huminmin
19 小时以前 2c2605a1297882bf88c3c86313ee37797854689b
src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
@@ -22,6 +22,7 @@
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.basic.pojo.SupplierManage;
import com.ruoyi.basic.utils.FileUtil;
import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.enums.ApprovalStatusEnum;
import com.ruoyi.common.enums.ReviewStatusEnum;
@@ -42,6 +43,7 @@
import com.ruoyi.purchase.dto.PurchaseLedgerDto;
import com.ruoyi.purchase.dto.PurchaseLedgerImportDto;
import com.ruoyi.purchase.dto.PurchaseLedgerProductImportDto;
import com.ruoyi.purchase.dto.PurchaseStockInDto;
import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
import com.ruoyi.purchase.pojo.PurchaseLedger;
import com.ruoyi.purchase.service.IPurchaseLedgerService;
@@ -116,6 +118,7 @@
    private final StockInRecordService stockInRecordService;
    private final StockUtils stockUtils;
    private final ApprovalTemplateMapper approvalTemplateMapper;
    private final StockUtils stockUtils;
    @Override
    public List<PurchaseLedger> selectPurchaseLedgerList(PurchaseLedger purchaseLedger) {
@@ -1051,6 +1054,84 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int manualStockIn(PurchaseStockInDto purchaseStockInDto) {
        if (purchaseStockInDto == null || purchaseStockInDto.getPurchaseLedgerId() == null) {
            throw new BaseException("采购台账ID不能为空");
        }
        if (CollectionUtils.isEmpty(purchaseStockInDto.getDetails())) {
            throw new BaseException("请选择至少一个产品进行入库");
        }
        // 查询采购台账
        PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(purchaseStockInDto.getPurchaseLedgerId());
        if (purchaseLedger == null) {
            throw new BaseException("采购台账不存在");
        }
        // 验证采购台账状态是否为已审批
        if (!"3".equals(String.valueOf(purchaseLedger.getApprovalStatus()))) {
            throw new BaseException("只有已审批通过的采购台账才能入库");
        }
        int count = 0;
        for (PurchaseStockInDto.StockInProductItem item : purchaseStockInDto.getDetails()) {
            if (item.getId() == null) {
                continue;
            }
            // 查询采购产品
            SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(item.getId());
            if (salesLedgerProduct == null) {
                throw new BaseException("采购产品不存在");
            }
            // 获取理论入库数量(前端传入的inboundQuantity)
            BigDecimal theoryStockInNum = item.getInboundQuantity();
            if (theoryStockInNum == null) {
                theoryStockInNum = salesLedgerProduct.getQuantity();
            }
            // 空值和非正数校验
            if (theoryStockInNum == null || theoryStockInNum.compareTo(BigDecimal.ZERO) <= 0) {
                throw new BaseException("理论入库数量必须大于0");
            }
            // 获取实际入库数量(前端传入的actualInboundQuantity)
            BigDecimal actualStockInNum = item.getActualInboundQuantity();
            if (actualStockInNum == null) {
                actualStockInNum = theoryStockInNum;
            }
            // 非正数校验
            if (actualStockInNum.compareTo(BigDecimal.ZERO) <= 0) {
                throw new BaseException("实际入库数量必须大于0");
            }
            // 获取是否含水和含水量
            Boolean isContainsWater = item.getIsContainsWater();
            BigDecimal waterContent = item.getWaterContent();
            if (waterContent == null) {
                waterContent = BigDecimal.ZERO;
            }
            // 调用StockUtils进行入库(带含水量信息)
            stockUtils.addStockWithBatchNo(
                    salesLedgerProduct.getProductModelId(),
                    actualStockInNum,
                    StockInQualifiedRecordTypeEnum.PURCHASE_STOCK_IN.getCode(),
                    purchaseLedger.getId(),
                    purchaseLedger.getPurchaseContractNumber() + "-" + salesLedgerProduct.getId(),
                    isContainsWater,
                    waterContent,
                    theoryStockInNum
            );
            count++;
        }
        return count;
    }
    /**
     * 下划线命名转驼峰命名
     */