From 7488018d52edaafcd4e541c5fdeada8dd2e47b11 Mon Sep 17 00:00:00 2001
From: chenhj <1263187585@qq.com>
Date: 星期一, 22 十二月 2025 16:49:18 +0800
Subject: [PATCH] Merge branch 'jtwy' of http://114.132.189.42:9002/r/product-inventory-management-after into jtwy

---
 src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java |   68 ++++++++++++++++++++++++++++-----
 1 files changed, 57 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 0650ce8..9f9123f 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,10 @@
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.account.pojo.AccountExpense;
+import com.ruoyi.account.pojo.AccountIncome;
+import com.ruoyi.account.service.AccountExpenseService;
+import com.ruoyi.account.service.AccountIncomeService;
 import com.ruoyi.basic.mapper.ProductMapper;
 import com.ruoyi.basic.mapper.ProductModelMapper;
 import com.ruoyi.basic.mapper.SupplierManageMapper;
@@ -23,9 +27,11 @@
 import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.system.mapper.SysUserMapper;
 import com.ruoyi.purchase.dto.PurchaseLedgerDto;
+import com.ruoyi.purchase.mapper.PaymentRegistrationMapper;
 import com.ruoyi.purchase.mapper.ProductRecordMapper;
 import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
 import com.ruoyi.purchase.mapper.TicketRegistrationMapper;
+import com.ruoyi.purchase.pojo.PaymentRegistration;
 import com.ruoyi.purchase.pojo.ProductRecord;
 import com.ruoyi.purchase.pojo.PurchaseLedger;
 import com.ruoyi.purchase.pojo.TicketRegistration;
@@ -68,7 +74,7 @@
 @RequiredArgsConstructor
 @Slf4j
 public class PurchaseLedgerServiceImpl extends ServiceImpl<PurchaseLedgerMapper, PurchaseLedger> implements IPurchaseLedgerService {
-
+    private final AccountExpenseService accountExpenseService;
     private final PurchaseLedgerMapper purchaseLedgerMapper;
 
     private final SalesLedgerMapper salesLedgerMapper;
@@ -89,6 +95,8 @@
     private final TicketRegistrationMapper ticketRegistrationMapper;
 
     private final ProductRecordMapper productRecordMapper;
+
+    private final PaymentRegistrationMapper paymentRegistrationMapper;
 
     private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
 
@@ -123,17 +131,47 @@
         if(ObjectUtils.isNotEmpty(loginUser) && null != loginUser.getTenantId()) {
             purchaseLedger.setTenantId(loginUser.getTenantId());
         }
-        purchaseLedger.setSalesContractNo(ObjectUtils.isNotEmpty(salesLedger) ? salesLedger.getSalesContractNo() : null);
+        purchaseLedger.setSalesContractNo(ObjectUtils.isNotEmpty(salesLedger) ? salesLedger.getSalesContractNo() : "");
+        purchaseLedger.setSalesLedgerId(ObjectUtils.isNotEmpty(salesLedger) ? salesLedger.getId() : -1);
         purchaseLedger.setSupplierName(supplierManage.getSupplierName());
         purchaseLedger.setRecorderId(purchaseLedgerDto.getRecorderId());
         purchaseLedger.setRecorderName(sysUser.getNickName());
         purchaseLedger.setPhoneNumber(sysUser.getPhonenumber());
+        // 2. 澶勭悊璐︽埛鏀跺叆
+        AccountExpense accountExpense = new AccountExpense();
+        accountExpense.setExpenseDate(purchaseLedger.getEntryDate());
+        accountExpense.setExpenseType("0");
+        accountExpense.setSupplierName(purchaseLedger.getSupplierName());
+        accountExpense.setExpenseMoney(purchaseLedger.getContractAmount());
+        accountExpense.setExpenseDescribed("閲囪喘鍚堝悓锛�" + purchaseLedger.getPurchaseContractNumber());
+        accountExpense.setExpenseMethod("0");
+        accountExpense.setInvoiceNumber(purchaseLedger.getPurchaseContractNumber());
+        accountExpense.setInputTime(new Date());
+        accountExpense.setInputUser(loginUser.getNickName());
+
 
         // 3. 鏂板鎴栨洿鏂颁富琛�
         if (purchaseLedger.getId() == null) {
             purchaseLedgerMapper.insert(purchaseLedger);
+//            accountIncomeService.save(accountIncome);
+            accountExpenseService.save(accountExpense);
         } else {
             purchaseLedgerMapper.updateById(purchaseLedger);
+            PurchaseLedger purchaseLedgerDB = purchaseLedgerMapper.selectById(purchaseLedger.getId());
+            List<AccountExpense> accountExpenseDBs = accountExpenseService.getByInvoiceNumberList(purchaseLedger.getPurchaseContractNumber());
+            if (!CollectionUtils.isEmpty(accountExpenseDBs)) {
+                accountExpenseDBs.forEach(accountExpenseDB -> {
+                   accountExpenseDB.setExpenseDate(purchaseLedgerDB.getEntryDate());
+                   accountExpenseDB.setExpenseType("0");
+                   accountExpenseDB.setSupplierName(purchaseLedgerDB.getSupplierName());
+                   accountExpenseDB.setExpenseMoney(purchaseLedgerDB.getContractAmount());
+                   accountExpenseDB.setExpenseDescribed("閲囪喘鍚堝悓锛�" + purchaseLedgerDB.getPurchaseContractNumber());
+                   accountExpenseDB.setExpenseMethod("0");
+                   accountExpenseDB.setInvoiceNumber(purchaseLedgerDB.getPurchaseContractNumber());
+                   accountExpenseService.updateById(accountExpenseDB);
+               });
+            }
+
         }
 
         // 4. 澶勭悊瀛愯〃鏁版嵁
@@ -276,12 +314,15 @@
 
             try {
                 // 鎵ц鏂囦欢杩佺Щ锛堜娇鐢ㄥ師瀛愭搷浣滅‘淇濆畨鍏ㄦ�э級
-                Files.move(
-                        Paths.get(tempFile.getTempPath()),
-                        formalFilePath,
-                        StandardCopyOption.REPLACE_EXISTING,
-                        StandardCopyOption.ATOMIC_MOVE
-                );
+//                Files.move(
+//                        Paths.get(tempFile.getTempPath()),
+//                        formalFilePath,
+//                        StandardCopyOption.REPLACE_EXISTING,
+//                        StandardCopyOption.ATOMIC_MOVE
+//                );
+                // 鍘熷瓙绉诲姩澶辫触锛屼娇鐢ㄥ鍒�+鍒犻櫎
+                Files.copy(Paths.get(tempFile.getTempPath()), formalFilePath, StandardCopyOption.REPLACE_EXISTING);
+                Files.deleteIfExists(Paths.get(tempFile.getTempPath()));
                 log.info("鏂囦欢杩佺Щ鎴愬姛: {} -> {}", tempFile.getTempPath(), formalFilePath);
 
                 // 鏇存柊鏂囦欢璁板綍锛堝叧鑱斿埌涓氬姟ID锛�
@@ -317,12 +358,16 @@
         salesLedgerProductMapper.delete(queryWrapper);
         // 鎵归噺鍒犻櫎鍏宠仈鐨勯噰璐彴璐︾殑鏉ョエ鐧昏
         LambdaQueryWrapper<TicketRegistration> ticketRegistrationLambdaQueryWrapper = new LambdaQueryWrapper<>();
-        ticketRegistrationLambdaQueryWrapper.in(TicketRegistration::getSalesLedgerId,ids);
+        ticketRegistrationLambdaQueryWrapper.in(TicketRegistration::getPurchaseLedgerId,ids);
         ticketRegistrationMapper.delete(ticketRegistrationLambdaQueryWrapper);
         // 鎵归噺鍒犻櫎鍏宠仈鐨勯噰璐彴璐︾殑鏉ョエ鐧昏璁板綍
         LambdaQueryWrapper<ProductRecord> productRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
         productRecordLambdaQueryWrapper.in(ProductRecord::getPurchaseLedgerId,ids);
         productRecordMapper.delete(productRecordLambdaQueryWrapper);
+        // 鎵归噺鍒犻櫎浠樻鐧昏
+        LambdaQueryWrapper<PaymentRegistration> paymentRegistrationLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        paymentRegistrationLambdaQueryWrapper.in(PaymentRegistration::getPurchaseLedgerId,ids);
+        paymentRegistrationMapper.delete(paymentRegistrationLambdaQueryWrapper);
         // 鎵归噺鍒犻櫎閲囪喘鍙拌处
         return purchaseLedgerMapper.deleteBatchIds(Arrays.asList(ids));
     }
@@ -343,7 +388,8 @@
 
         // 3.鏌ヨ涓婁紶鏂囦欢
         LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>();
-        salesLedgerFileWrapper.eq(CommonFile::getCommonId, purchaseLedger.getId());
+        salesLedgerFileWrapper.eq(CommonFile::getCommonId, purchaseLedger.getId())
+                .eq(CommonFile::getType, FileNameType.PURCHASE.getValue());
         List<CommonFile> salesLedgerFiles = commonFileMapper.selectList(salesLedgerFileWrapper);
 
         // 4. 杞崲 DTO
@@ -439,7 +485,7 @@
     public IPage<PurchaseLedgerDto> selectPurchaseLedgerListPage(IPage ipage, PurchaseLedgerDto purchaseLedger) {
         IPage<PurchaseLedgerDto> purchaseLedgerDtoIPage = purchaseLedgerMapper.selectPurchaseLedgerListPage(ipage, purchaseLedger);
         purchaseLedgerDtoIPage.getRecords().forEach(purchaseLedgerDto -> {
-            List<CommonFile> commonFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>().eq(CommonFile::getCommonId, purchaseLedgerDto.getId()).eq(CommonFile::getType, FileNameType.PURCHASELEDGER.getValue()));
+            List<CommonFile> commonFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>().eq(CommonFile::getCommonId, purchaseLedgerDto.getId()).eq(CommonFile::getType, FileNameType.PURCHASE.getValue()));
             purchaseLedgerDto.setSalesLedgerFiles(commonFiles);
         });
         return purchaseLedgerDtoIPage;

--
Gitblit v1.9.3