| | |
| | | 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.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | |
| | | import com.ruoyi.other.mapper.TempFileMapper; |
| | | import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.project.system.domain.SysUser; |
| | | import com.ruoyi.project.system.mapper.SysUserMapper; |
| | | 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; |
| | |
| | | private final FileUtil fileUtil; |
| | | private final ApprovalInstanceService approvalInstanceService; |
| | | private final ApprovalTemplateMapper approvalTemplateMapper; |
| | | private final StockUtils stockUtils; |
| | | |
| | | @Override |
| | | public List<PurchaseLedger> selectPurchaseLedgerList(PurchaseLedger purchaseLedger) { |
| | |
| | | |
| | | } |
| | | |
| | | @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; |
| | | } |
| | | |
| | | // 计算差额 |
| | | BigDecimal difference = theoryStockInNum.subtract(actualStockInNum); |
| | | |
| | | // 调用StockUtils进行入库(带含水量信息) |
| | | stockUtils.addStockWithBatchNo( |
| | | salesLedgerProduct.getProductModelId(), |
| | | actualStockInNum, |
| | | StockInQualifiedRecordTypeEnum.PURCHASE_STOCK_IN.getCode(), |
| | | purchaseLedger.getId(), |
| | | purchaseLedger.getPurchaseContractNumber() + "-" + salesLedgerProduct.getId(), |
| | | isContainsWater, |
| | | waterContent, |
| | | theoryStockInNum |
| | | ); |
| | | |
| | | count++; |
| | | } |
| | | |
| | | return count; |
| | | } |
| | | |
| | | /** |
| | | * 下划线命名转驼峰命名 |
| | | */ |