huminmin
2 天以前 286581ef6495f7bb18135bb66affcb2f51488ecd
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;
@@ -60,6 +62,7 @@
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.service.impl.CommonFileServiceImpl;
import com.ruoyi.stock.dto.StockInRecordDto;
import com.ruoyi.stock.pojo.StockInRecord;
import com.ruoyi.stock.service.StockInRecordService;
import lombok.RequiredArgsConstructor;
@@ -609,7 +612,14 @@
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
        if (!pendingIds.isEmpty()) {
            stockInRecordService.batchApprove(pendingIds, ReviewStatusEnum.APPROVED.getCode());
            List<StockInRecordDto.StockInRecordApproveItemDto> approveItems = pendingIds.stream()
                    .map(id -> {
                        StockInRecordDto.StockInRecordApproveItemDto item = new StockInRecordDto.StockInRecordApproveItemDto();
                        item.setId(id);
                        return item;
                    })
                    .collect(Collectors.toList());
            stockInRecordService.batchApprove(ReviewStatusEnum.APPROVED.getCode(), approveItems);
        }
    }
@@ -1051,6 +1061,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;
    }
    /**
     * 下划线命名转驼峰命名
     */