From d8c86797adaef6c416efae16586f350ae77bde4b Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期六, 12 九月 2026 12:43:08 +0800
Subject: [PATCH] feat: 库存入库/出库字段全链路、采购台账申请提交时间、储罐租客信息、油库储罐模块

---
 src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java |  113 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 102 insertions(+), 11 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 f0d1129..5a80184 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
@@ -6,6 +6,7 @@
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.alibaba.fastjson2.JSON;
 import com.ruoyi.approve.bean.dto.ApprovalInstanceDto;
 import com.ruoyi.approve.mapper.ApprovalTemplateMapper;
 import com.ruoyi.approve.pojo.ApprovalInstance;
@@ -15,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;
@@ -117,6 +120,7 @@
     private final StockInRecordService stockInRecordService;
     private final StockUtils stockUtils;
     private final ApprovalTemplateMapper approvalTemplateMapper;
+    private final OilDepotMapper oilDepotMapper;
 
     @Override
     public List<PurchaseLedger> selectPurchaseLedgerList(PurchaseLedger purchaseLedger) {
@@ -170,6 +174,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());
@@ -194,7 +206,7 @@
                 .last("limit 1")
         );
         if(Objects.isNull(oldApprovalInstance)){
-            addApproveByPurchase(loginUser, purchaseLedger);
+            addApproveByPurchase(loginUser, purchaseLedger, productList);
         }
         // 5. 杩佺Щ涓存椂鏂囦欢鍒版寮忕洰褰�
         fileUtil.saveStorageAttachment(ApplicationTypeEnum.FILE, RecordTypeEnum.PURCHASE_LEDGER, purchaseLedger.getId(), purchaseLedgerDto.getStorageBlobDTOS());
@@ -1016,7 +1028,12 @@
                     salesLedgerProductMapper.insert(salesLedgerProduct);
                 }
                 // 閲囪喘瀹℃牳
-                addApproveByPurchase(loginUser,salesLedger);
+                List<SalesLedgerProduct> snapshotProducts = salesLedgerProductMapper.selectList(
+                        new LambdaQueryWrapper<SalesLedgerProduct>()
+                                .eq(SalesLedgerProduct::getSalesLedgerId, salesLedger.getId())
+                                .eq(SalesLedgerProduct::getType, 2)
+                );
+                addApproveByPurchase(loginUser, salesLedger, snapshotProducts);
             }
 
             return AjaxResult.success("瀵煎叆鎴愬姛");
@@ -1028,21 +1045,91 @@
 
     @Override
     public PurchaseLedgerDto getPurchaseByCode(PurchaseLedgerDto purchaseLedgerDto) {
-        // 1. 鏌ヨ涓昏〃
-        PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectOne(new LambdaQueryWrapper<PurchaseLedger>()
-                .eq(PurchaseLedger::getPurchaseContractNumber, purchaseLedgerDto.getPurchaseContractNumber())
-                .last("LIMIT 1"));
-        if (purchaseLedger == null) {
-            throw new BaseException("閲囪喘鍙拌处涓嶅瓨鍦�");
+        PurchaseLedger purchaseLedger = null;
+        ApprovalInstance approvalSnapshotInstance = null;
+
+        // 1. 浼樺厛鎸夊綋鍓嶅鎵瑰疄渚嬫煡璇㈠揩鐓�
+        if (purchaseLedgerDto.getApprovalInstanceId() != null) {
+            approvalSnapshotInstance = approvalInstanceService.getById(purchaseLedgerDto.getApprovalInstanceId());
+            if (approvalSnapshotInstance != null && approvalSnapshotInstance.getBusinessId() != null) {
+                purchaseLedger = purchaseLedgerMapper.selectById(approvalSnapshotInstance.getBusinessId());
+            }
         }
 
-        // 2. 鏌ヨ瀛愯〃
+        // 2. 娌′紶瀹℃壒瀹炰緥ID鏃讹紝閫�鍥炲埌鎸夐噰璐悎鍚屽彿鏌ヨ
+        if (purchaseLedger == null) {
+            purchaseLedger = purchaseLedgerMapper.selectOne(new LambdaQueryWrapper<PurchaseLedger>()
+                    .eq(PurchaseLedger::getPurchaseContractNumber, purchaseLedgerDto.getPurchaseContractNumber())
+                    .last("LIMIT 1"));
+            if (purchaseLedger == null) {
+                throw new BaseException("閲囪喘鍙拌处涓嶅瓨鍦�");
+            }
+        }
+
+        // 3. 鏌ヨ褰撳墠閲囪喘鍗曞搴旂殑瀹℃壒蹇収
+        if (approvalSnapshotInstance == null) {
+            approvalSnapshotInstance = approvalInstanceService.getOne(new LambdaQueryWrapper<ApprovalInstance>()
+                    .eq(ApprovalInstance::getBusinessId, purchaseLedger.getId())
+                    .eq(ApprovalInstance::getBusinessType, 5L)
+                    .eq(ApprovalInstance::getDeleted, 0)
+                    .orderByDesc(ApprovalInstance::getId)
+                    .last("LIMIT 1"));
+        }
+
+        if (approvalSnapshotInstance != null && StringUtils.hasText(approvalSnapshotInstance.getFormConfig())) {
+            try {
+                PurchaseLedgerDto snapshot = JSON.parseObject(approvalSnapshotInstance.getFormConfig(), PurchaseLedgerDto.class);
+                if (snapshot != null) {
+                    snapshot.setId(purchaseLedger.getId());
+                    if (snapshot.getPurchaseContractNumber() == null) {
+                        snapshot.setPurchaseContractNumber(purchaseLedger.getPurchaseContractNumber());
+                    }
+                    if (snapshot.getSupplierId() == null) {
+                        snapshot.setSupplierId(purchaseLedger.getSupplierId());
+                    }
+                    if (snapshot.getSupplierName() == null) {
+                        snapshot.setSupplierName(purchaseLedger.getSupplierName());
+                    }
+                    if (snapshot.getSalesContractNo() == null) {
+                        snapshot.setSalesContractNo(purchaseLedger.getSalesContractNo());
+                    }
+                    if (snapshot.getSalesContractNoId() == null) {
+                        snapshot.setSalesContractNoId(purchaseLedger.getSalesLedgerId());
+                    }
+                    if (snapshot.getProjectName() == null) {
+                        snapshot.setProjectName(purchaseLedger.getProjectName());
+                    }
+                    if (snapshot.getEntryDate() == null) {
+                        snapshot.setEntryDate(purchaseLedger.getEntryDate());
+                    }
+                    if (snapshot.getExecutionDate() == null) {
+                        snapshot.setExecutionDate(purchaseLedger.getExecutionDate());
+                    }
+                    if (snapshot.getRemarks() == null) {
+                        snapshot.setRemarks(purchaseLedger.getRemarks());
+                    }
+                    if (snapshot.getRecorderId() == null) {
+                        snapshot.setRecorderId(purchaseLedger.getRecorderId());
+                    }
+                    if (snapshot.getRecorderName() == null) {
+                        snapshot.setRecorderName(purchaseLedger.getRecorderName());
+                    }
+                    snapshot.setProductData(snapshot.getProductData() == null ? Collections.emptyList() : snapshot.getProductData());
+                    snapshot.setHasChildren(CollectionUtils.isNotEmpty(snapshot.getProductData()));
+                    return snapshot;
+                }
+            } catch (Exception e) {
+                log.warn("瑙f瀽閲囪喘瀹℃壒蹇収澶辫触: {}", e.getMessage());
+            }
+        }
+
+        // 4. 鏌ヨ瀛愯〃
         LambdaQueryWrapper<SalesLedgerProduct> productWrapper = new LambdaQueryWrapper<>();
         productWrapper.eq(SalesLedgerProduct::getSalesLedgerId, purchaseLedger.getId())
                 .eq(SalesLedgerProduct::getType, 2);
         List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(productWrapper);
 
-        // 4. 杞崲 DTO
+        // 5. 杞崲 DTO
         PurchaseLedgerDto resultDto = new PurchaseLedgerDto();
         BeanUtils.copyProperties(purchaseLedger, resultDto);
         if (!products.isEmpty()) {
@@ -1052,7 +1139,7 @@
         return resultDto;
     }
 
-    public void addApproveByPurchase(LoginUser loginUser,PurchaseLedger purchaseLedger) {
+    public void addApproveByPurchase(LoginUser loginUser, PurchaseLedger purchaseLedger, List<SalesLedgerProduct> productList) {
         if (loginUser == null) {
             return;
         }
@@ -1077,6 +1164,10 @@
         approvalInstance.setTitle(purchaseLedger.getPurchaseContractNumber()+"瀹℃壒");
         approvalInstance.setApplicantName(loginUser.getNickName());
         approvalInstance.setApplyTime(LocalDateTime.now());
+        PurchaseLedgerDto snapshot = new PurchaseLedgerDto();
+        BeanUtils.copyProperties(purchaseLedger, snapshot);
+        snapshot.setProductData(productList == null ? Collections.emptyList() : new ArrayList<>(productList));
+        approvalInstance.setFormConfig(JSON.toJSONString(snapshot));
         approvalInstanceService.add(approvalInstance);
 
     }

--
Gitblit v1.9.3