From 5f73eb1fb9d04040fe6ba377d5ae582024429f2f Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期日, 20 九月 2026 14:15:02 +0800
Subject: [PATCH] feat(sales): 添加客户交易详情中的付款金额字段
---
src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java | 69 ++++++++++++++++++++++++++++++++++
1 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
index 7c25815..a81fca7 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
@@ -16,9 +16,11 @@
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;
@@ -35,6 +37,10 @@
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;
@@ -94,6 +100,11 @@
@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;
@@ -118,6 +129,9 @@
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) {
@@ -171,6 +185,14 @@
purchaseLedger.setSupplierName(supplierManage.getSupplierName());
purchaseLedger.setRecorderId(purchaseLedgerDto.getRecorderId());
+ // 閲囪喘娌瑰簱锛氭牴鎹补搴搃d鍥炲~娌瑰簱鍚嶇О
+ if (purchaseLedgerDto.getOilDepotId() != null) {
+ OilDepot oilDepot = oilDepotMapper.selectById(purchaseLedgerDto.getOilDepotId());
+ if (oilDepot != null) {
+ purchaseLedger.setOilDepotName(oilDepot.getDepotName());
+ }
+ }
+
purchaseLedger.setApprovalStatus(1);
// 瀹為檯鍚堝悓閲戦濮嬬粓绛変簬鍚堝悓閲戦
purchaseLedger.setNetContractAmount(purchaseLedger.getContractAmount());
@@ -179,6 +201,8 @@
purchaseLedger.setPurchaseContractNumber(generatePurchaseContractNo(purchaseLedger.getEntryDate()));
}
this.saveOrUpdate(purchaseLedger);
+ // 鍥炲啓涓婚敭锛屼緵璋冪敤鏂癸紙濡傞噰璐敵璇疯浆璁㈠崟锛夎幏鍙栨柊鐢熸垚鐨勯噰璐彴璐d
+ purchaseLedgerDto.setId(purchaseLedger.getId());
// 4. 澶勭悊瀛愯〃鏁版嵁
List<SalesLedgerProduct> productList = purchaseLedgerDto.getProductData();
@@ -695,6 +719,10 @@
salesLedgerProduct.setRegisterDate(localDateTime);
salesLedgerProductMapper.insert(salesLedgerProduct);
}
+ // 浠呮柊澧炴槑缁嗗洖鍐欏浠讹紝缂栬緫璧� update 鍒嗘敮澶╃劧涓嶉噸澶嶈鏁�
+ if (LEDGER_TYPE_PURCHASE.equals(ledgerType)) {
+ recordSparePartsInbound(insertList, purchaseLedger);
+ }
}
// 璁$畻鎬诲惈绋庨噾棰�
@@ -710,6 +738,47 @@
}
}
+ /**
+ * 閲囪喘鍙拌处鏂板鏄庣粏鎸夎鏍煎尮閰嶅浠讹細绱姞澶囦欢搴撳瓨骞惰涓�鏉″叆搴撴祦姘淬��
+ * 鏈淮鎶よ鏍肩殑澶囦欢涓嶅弬涓庯紝闈欓粯璺宠繃銆�
+ */
+ 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) {
--
Gitblit v1.9.3