| | |
| | | import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl; |
| | | import com.ruoyi.basic.enums.ApplicationTypeEnum; |
| | | import com.ruoyi.basic.enums.RecordTypeEnum; |
| | | import com.ruoyi.basic.mapper.OilDepotMapper; |
| | | import com.ruoyi.basic.mapper.ProductMapper; |
| | | import com.ruoyi.basic.mapper.ProductModelMapper; |
| | | import com.ruoyi.basic.mapper.SupplierManageMapper; |
| | | import com.ruoyi.basic.pojo.OilDepot; |
| | | import com.ruoyi.basic.pojo.Product; |
| | | import com.ruoyi.basic.pojo.ProductModel; |
| | | import com.ruoyi.basic.pojo.SupplierManage; |
| | |
| | | import com.ruoyi.framework.security.LoginUser; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.measuringinstrumentledger.mapper.SparePartsMapper; |
| | | import com.ruoyi.measuringinstrumentledger.pojo.SpareParts; |
| | | import com.ruoyi.measuringinstrumentledger.pojo.SparePartsRecord; |
| | | import com.ruoyi.measuringinstrumentledger.service.SparePartsRecordService; |
| | | import com.ruoyi.other.mapper.TempFileMapper; |
| | | import com.ruoyi.procurementrecord.mapper.ProcurementRecordMapper; |
| | | import com.ruoyi.procurementrecord.pojo.ProcurementRecordStorage; |
| | |
| | | @RequiredArgsConstructor |
| | | public class PurchaseLedgerServiceImpl extends ServiceImpl<PurchaseLedgerMapper, PurchaseLedger> implements IPurchaseLedgerService { |
| | | |
| | | /** |
| | | * 明细类型:采购(sales_ledger_product.type)。仅采购明细才回写备件库存 |
| | | */ |
| | | private static final Integer LEDGER_TYPE_PURCHASE = 2; |
| | | |
| | | private final PurchaseLedgerMapper purchaseLedgerMapper; |
| | | private final SalesLedgerMapper salesLedgerMapper; |
| | | private final SalesLedgerProductMapper salesLedgerProductMapper; |
| | |
| | | private final StockInRecordService stockInRecordService; |
| | | private final StockUtils stockUtils; |
| | | private final ApprovalTemplateMapper approvalTemplateMapper; |
| | | private final OilDepotMapper oilDepotMapper; |
| | | private final SparePartsMapper sparePartsMapper; |
| | | private final SparePartsRecordService sparePartsRecordService; |
| | | |
| | | @Override |
| | | public List<PurchaseLedger> selectPurchaseLedgerList(PurchaseLedger purchaseLedger) { |
| | |
| | | purchaseLedger.setSupplierName(supplierManage.getSupplierName()); |
| | | purchaseLedger.setRecorderId(purchaseLedgerDto.getRecorderId()); |
| | | |
| | | // 采购油库:根据油库id回填油库名称 |
| | | if (purchaseLedgerDto.getOilDepotId() != null) { |
| | | OilDepot oilDepot = oilDepotMapper.selectById(purchaseLedgerDto.getOilDepotId()); |
| | | if (oilDepot != null) { |
| | | purchaseLedger.setOilDepotName(oilDepot.getDepotName()); |
| | | } |
| | | } |
| | | |
| | | purchaseLedger.setApprovalStatus(1); |
| | | // 实际合同金额始终等于合同金额 |
| | | purchaseLedger.setNetContractAmount(purchaseLedger.getContractAmount()); |
| | |
| | | purchaseLedger.setPurchaseContractNumber(generatePurchaseContractNo(purchaseLedger.getEntryDate())); |
| | | } |
| | | this.saveOrUpdate(purchaseLedger); |
| | | // 回写主键,供调用方(如采购申请转订单)获取新生成的采购台账id |
| | | purchaseLedgerDto.setId(purchaseLedger.getId()); |
| | | |
| | | // 4. 处理子表数据 |
| | | List<SalesLedgerProduct> productList = purchaseLedgerDto.getProductData(); |
| | |
| | | salesLedgerProduct.setRegisterDate(localDateTime); |
| | | salesLedgerProductMapper.insert(salesLedgerProduct); |
| | | } |
| | | // 仅新增明细回写备件,编辑走 update 分支天然不重复计数 |
| | | if (LEDGER_TYPE_PURCHASE.equals(ledgerType)) { |
| | | recordSparePartsInbound(insertList, purchaseLedger); |
| | | } |
| | | } |
| | | |
| | | // 计算总含税金额 |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 采购台账新增明细按规格匹配备件:累加备件库存并记一条入库流水。 |
| | | * 未维护规格的备件不参与,静默跳过。 |
| | | */ |
| | | private void recordSparePartsInbound(List<SalesLedgerProduct> insertList, PurchaseLedger purchaseLedger) { |
| | | List<Long> modelIds = insertList.stream() |
| | | .map(SalesLedgerProduct::getProductModelId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | if (modelIds.isEmpty()) { |
| | | return; |
| | | } |
| | | List<SpareParts> sparePartsList = sparePartsMapper.selectList(new LambdaQueryWrapper<SpareParts>() |
| | | .in(SpareParts::getProductModelId, modelIds)); |
| | | if (CollectionUtils.isEmpty(sparePartsList)) { |
| | | return; |
| | | } |
| | | Map<Long, SpareParts> sparePartsByModelId = sparePartsList.stream() |
| | | .collect(Collectors.toMap(SpareParts::getProductModelId, s -> s, (a, b) -> a)); |
| | | for (SalesLedgerProduct product : insertList) { |
| | | SpareParts spareParts = sparePartsByModelId.get(product.getProductModelId()); |
| | | if (spareParts == null || product.getQuantity() == null |
| | | || product.getQuantity().compareTo(BigDecimal.ZERO) <= 0) { |
| | | continue; |
| | | } |
| | | BigDecimal quantity = product.getQuantity(); |
| | | spareParts.setQuantity((spareParts.getQuantity() == null ? BigDecimal.ZERO : spareParts.getQuantity()).add(quantity)); |
| | | sparePartsMapper.updateById(spareParts); |
| | | |
| | | SparePartsRecord record = new SparePartsRecord(); |
| | | record.setSparePartsId(spareParts.getId()); |
| | | record.setDirection(1); |
| | | record.setQuantity(quantity); |
| | | record.setSourceType(1); |
| | | record.setSourceId(purchaseLedger.getId()); |
| | | record.setSourceNo(purchaseLedger.getPurchaseContractNumber()); |
| | | sparePartsRecordService.save(record); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int deletePurchaseLedgerByIds(Long[] ids) { |