From 11502c7f9f26edda0733c43a17b5b773ee8447e4 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期三, 20 五月 2026 16:47:47 +0800
Subject: [PATCH] refactor(account): 财务模块更新

---
 src/main/java/com/ruoyi/ai/service/PurchaseAiService.java |   92 +++++++++++++++++++++++++++-------------------
 1 files changed, 54 insertions(+), 38 deletions(-)

diff --git a/src/main/java/com/ruoyi/ai/service/PurchaseAiService.java b/src/main/java/com/ruoyi/ai/service/PurchaseAiService.java
index 616aa6c..0f24d64 100644
--- a/src/main/java/com/ruoyi/ai/service/PurchaseAiService.java
+++ b/src/main/java/com/ruoyi/ai/service/PurchaseAiService.java
@@ -17,7 +17,7 @@
 import com.ruoyi.basic.service.StorageBlobService;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.framework.security.LoginUser;
-import com.ruoyi.framework.web.domain.R;
+import com.ruoyi.framework.web.domain.AjaxResult;
 import com.ruoyi.purchase.dto.PurchaseLedgerDto;
 import com.ruoyi.purchase.dto.PurchaseReturnOrderDto;
 import com.ruoyi.purchase.pojo.PaymentRegistration;
@@ -26,7 +26,13 @@
 import com.ruoyi.purchase.service.PurchaseReturnOrdersService;
 import com.ruoyi.sales.pojo.SalesLedgerProduct;
 import dev.langchain4j.data.image.Image;
-import dev.langchain4j.data.message.*;
+import dev.langchain4j.data.message.AiMessage;
+import dev.langchain4j.data.message.ChatMessage;
+import dev.langchain4j.data.message.Content;
+import dev.langchain4j.data.message.ImageContent;
+import dev.langchain4j.data.message.SystemMessage;
+import dev.langchain4j.data.message.TextContent;
+import dev.langchain4j.data.message.UserMessage;
 import dev.langchain4j.model.chat.StreamingChatLanguageModel;
 import dev.langchain4j.model.chat.response.ChatResponse;
 import dev.langchain4j.model.chat.response.StreamingChatResponseHandler;
@@ -41,12 +47,22 @@
 import java.io.InputStream;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.nio.file.Files;
+import java.util.Base64;
+import java.util.Arrays;
 import java.time.LocalDate;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeParseException;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.UUID;
+import java.nio.file.Files;
 
 @Service
 public class PurchaseAiService {
@@ -193,12 +209,12 @@
                 .doOnError(ex -> aiChatSessionService.refreshSessionStats(finalMemoryId, loginUser));
     }
 
-    public R confirmAnalyzeResult(PurchaseAiConfirmRequest request) {
+    public AjaxResult confirmAnalyzeResult(PurchaseAiConfirmRequest request) {
         if (request == null || !StringUtils.hasText(request.getBusinessType())) {
-            return R.fail("businessType涓嶈兘涓虹┖");
+            return AjaxResult.error("businessType涓嶈兘涓虹┖");
         }
         if (request.getPayload() == null || request.getPayload().isEmpty()) {
-            return R.fail("payload涓嶈兘涓虹┖");
+            return AjaxResult.error("payload涓嶈兘涓虹┖");
         }
 
         try {
@@ -207,10 +223,10 @@
                 case "purchase_ledger" -> processPurchaseLedger(request.getPayload());
                 case "payment_registration" -> processPaymentRegistration(request.getPayload());
                 case "purchase_return_order" -> processPurchaseReturnOrder(request.getPayload());
-                default -> R.fail("鏆備笉鏀寔璇ヤ笟鍔$被鍨�: " + businessType);
+                default -> AjaxResult.error("鏆備笉鏀寔璇ヤ笟鍔$被鍨�: " + businessType);
             };
         } catch (Exception ex) {
-            return R.fail(toCustomerMessage(ex));
+            return AjaxResult.error(toCustomerMessage(ex));
         }
     }
 
@@ -465,7 +481,7 @@
                 杈撳嚭瑕佹眰:
                 1. 鍙緭鍑哄悎娉� JSON锛屼笉瑕� Markdown锛屼笉瑕侀澶栬В閲娿��
                 2. JSON 椤跺眰瀛楁鍥哄畾涓�:
-                   - ok: boolean
+                   - success: boolean
                    - businessType: purchase_ledger | payment_registration | purchase_return_order | unknown
                    - action: confirm_required
                    - description: 涓枃璇存槑
@@ -501,33 +517,33 @@
                 """.formatted(message, fileContent);
     }
 
-    private R processPurchaseLedger(Map<String, Object> payload) throws Exception {
+    private AjaxResult processPurchaseLedger(Map<String, Object> payload) throws Exception {
         if (payload.containsKey("purchaseLedgers")) {
             return processPurchaseLedgerBatch(payload);
         }
 
         Map<String, Object> normalizedPayload = normalizePurchaseLedgerMap(payload);
         PurchaseLedgerDto dto = objectMapper.convertValue(normalizedPayload, PurchaseLedgerDto.class);
-        R ledgerResult = validatePurchaseLedger(dto, 0);
+        AjaxResult ledgerResult = validatePurchaseLedger(dto, 0);
         if (ledgerResult != null) {
             return ledgerResult;
         }
-        R supplierResult = fillSupplierIdByName(dto);
+        AjaxResult supplierResult = fillSupplierIdByName(dto);
         if (supplierResult != null) {
             return supplierResult;
         }
-        R productResult = validatePurchaseProducts(dto.getProductData(), 0);
+        AjaxResult productResult = validatePurchaseProducts(dto.getProductData(), 0);
         if (productResult != null) {
             return productResult;
         }
         int result = purchaseLedgerService.addOrEditPurchase(dto);
-        return R.ok( result,"閲囪喘鍙拌处宸插鐞�");
+        return AjaxResult.success("閲囪喘鍙拌处宸插鐞�", result);
     }
 
-    private R processPurchaseLedgerBatch(Map<String, Object> payload) throws Exception {
+    private AjaxResult processPurchaseLedgerBatch(Map<String, Object> payload) throws Exception {
         List<Map<String, Object>> purchaseLedgers = toMapList(payload.get("purchaseLedgers"));
         if (purchaseLedgers.isEmpty()) {
-            return R.fail("purchaseLedgers涓嶈兘涓虹┖");
+            return AjaxResult.error("purchaseLedgers涓嶈兘涓虹┖");
         }
 
         List<Map<String, Object>> topLevelProductData = toMapList(payload.get("productData"));
@@ -535,11 +551,11 @@
         for (int i = 0; i < purchaseLedgers.size(); i++) {
             Map<String, Object> ledgerMap = normalizePurchaseLedgerMap(purchaseLedgers.get(i));
             PurchaseLedgerDto dto = objectMapper.convertValue(ledgerMap, PurchaseLedgerDto.class);
-            R ledgerResult = validatePurchaseLedger(dto, i);
+            AjaxResult ledgerResult = validatePurchaseLedger(dto, i);
             if (ledgerResult != null) {
                 return ledgerResult;
             }
-            R supplierResult = fillSupplierIdByName(dto);
+            AjaxResult supplierResult = fillSupplierIdByName(dto);
             if (supplierResult != null) {
                 return supplierResult;
             }
@@ -549,7 +565,7 @@
                 products = matchProductsForLedger(ledgerMap, dto, topLevelProductData, purchaseLedgers.size() == 1);
                 dto.setProductData(products);
             }
-            R productResult = validatePurchaseProducts(products, i);
+            AjaxResult productResult = validatePurchaseProducts(products, i);
             if (productResult != null) {
                 return productResult;
             }
@@ -564,7 +580,7 @@
             item.put("result", result);
             results.add(item);
         }
-        return R.ok( results,"閲囪喘鍙拌处宸叉壒閲忓鐞�");
+        return AjaxResult.success("閲囪喘鍙拌处宸叉壒閲忓鐞�", results);
     }
 
     private List<SalesLedgerProduct> matchProductsForLedger(Map<String, Object> ledgerMap,
@@ -770,7 +786,7 @@
         }
     }
 
-    private R validatePurchaseProducts(List<SalesLedgerProduct> products, int ledgerIndex) {
+    private AjaxResult validatePurchaseProducts(List<SalesLedgerProduct> products, int ledgerIndex) {
         if (products == null || products.isEmpty()) {
             return null;
         }
@@ -778,34 +794,34 @@
             SalesLedgerProduct product = products.get(i);
             String prefix = "绗�" + (ledgerIndex + 1) + "涓噰璐彴璐︾殑绗�" + (i + 1) + "鏉′骇鍝�";
             if (!StringUtils.hasText(product.getProductCategory())) {
-                return R.fail(prefix + "缂哄皯浜у搧鍚嶇О锛岃琛ュ厖鍚庡啀纭");
+                return AjaxResult.error(prefix + "缂哄皯浜у搧鍚嶇О锛岃琛ュ厖鍚庡啀纭");
             }
             if (!StringUtils.hasText(product.getSpecificationModel())) {
-                return R.fail(prefix + "缂哄皯瑙勬牸鍨嬪彿锛岃琛ュ厖鍚庡啀纭");
+                return AjaxResult.error(prefix + "缂哄皯瑙勬牸鍨嬪彿锛岃琛ュ厖鍚庡啀纭");
             }
             if (!StringUtils.hasText(product.getUnit())) {
-                return R.fail(prefix + "缂哄皯鍗曚綅锛岃琛ュ厖鍚庡啀纭");
+                return AjaxResult.error(prefix + "缂哄皯鍗曚綅锛岃琛ュ厖鍚庡啀纭");
             }
             if (product.getQuantity() == null) {
-                return R.fail(prefix + "缂哄皯鏁伴噺");
+                return AjaxResult.error(prefix + "缂哄皯鏁伴噺");
             }
             if (product.getTaxInclusiveUnitPrice() == null) {
-                return R.fail(prefix + "缂哄皯鍚◣鍗曚环锛岃琛ュ厖鍚庡啀纭");
+                return AjaxResult.error(prefix + "缂哄皯鍚◣鍗曚环锛岃琛ュ厖鍚庡啀纭");
             }
             if (product.getTaxInclusiveTotalPrice() == null) {
-                return R.fail(prefix + "缂哄皯鍚◣鎬讳环锛岃琛ュ厖鍚庡啀纭");
+                return AjaxResult.error(prefix + "缂哄皯鍚◣鎬讳环锛岃琛ュ厖鍚庡啀纭");
             }
         }
         return null;
     }
 
-    private R validatePurchaseLedger(PurchaseLedgerDto dto, int ledgerIndex) {
+    private AjaxResult validatePurchaseLedger(PurchaseLedgerDto dto, int ledgerIndex) {
         String prefix = "绗�" + (ledgerIndex + 1) + "涓噰璐彴璐�";
         if (!StringUtils.hasText(dto.getPurchaseContractNumber())) {
-            return R.fail(prefix + "缂哄皯閲囪喘鍚堝悓鍙凤紝璇疯ˉ鍏呭悗鍐嶇‘璁�");
+            return AjaxResult.error(prefix + "缂哄皯閲囪喘鍚堝悓鍙凤紝璇疯ˉ鍏呭悗鍐嶇‘璁�");
         }
         if (dto.getSupplierId() == null && !StringUtils.hasText(dto.getSupplierName())) {
-            return R.fail(prefix + "缂哄皯渚涘簲鍟嗗悕绉帮紝璇疯ˉ鍏呭悗鍐嶇‘璁�");
+            return AjaxResult.error(prefix + "缂哄皯渚涘簲鍟嗗悕绉帮紝璇疯ˉ鍏呭悗鍐嶇‘璁�");
         }
         return null;
     }
@@ -976,25 +992,25 @@
         return "澶勭悊澶辫触锛�" + message;
     }
 
-    private R fillSupplierIdByName(PurchaseLedgerDto dto) {
+    private AjaxResult fillSupplierIdByName(PurchaseLedgerDto dto) {
         if (dto.getSupplierId() != null) {
             return null;
         }
         if (!StringUtils.hasText(dto.getSupplierName())) {
-            return R.fail("渚涘簲鍟咺D涓嶈兘涓虹┖锛涙湭璇嗗埆鍒颁緵搴斿晢鍚嶇О锛屾棤娉曡嚜鍔ㄥ尮閰嶄緵搴斿晢ID");
+            return AjaxResult.error("渚涘簲鍟咺D涓嶈兘涓虹┖锛涙湭璇嗗埆鍒颁緵搴斿晢鍚嶇О锛屾棤娉曡嚜鍔ㄥ尮閰嶄緵搴斿晢ID");
         }
 
         SupplierManage supplier = supplierManageMapper.selectOne(new LambdaQueryWrapper<SupplierManage>()
                 .eq(SupplierManage::getSupplierName, dto.getSupplierName().trim())
                 .last("limit 1"));
         if (supplier == null) {
-            return R.fail("鏈壘鍒颁緵搴斿晢锛�" + dto.getSupplierName() + "锛岃鍏堢淮鎶や緵搴斿晢鎴栨墜鍔ㄩ�夋嫨渚涘簲鍟咺D");
+            return AjaxResult.error("鏈壘鍒颁緵搴斿晢锛�" + dto.getSupplierName() + "锛岃鍏堢淮鎶や緵搴斿晢鎴栨墜鍔ㄩ�夋嫨渚涘簲鍟咺D");
         }
         dto.setSupplierId(supplier.getId());
         return null;
     }
 
-    private R processPaymentRegistration(Map<String, Object> payload) {
+    private AjaxResult processPaymentRegistration(Map<String, Object> payload) {
         Object recordsValue = payload.get("records");
         List<PaymentRegistration> records;
         if (recordsValue == null) {
@@ -1004,12 +1020,12 @@
             });
         }
         int result = paymentRegistrationService.insertPaymentRegistration(records);
-        return R.ok( result,"浠樻鐧昏宸插鐞�");
+        return AjaxResult.success("浠樻鐧昏宸插鐞�", result);
     }
 
-    private R processPurchaseReturnOrder(Map<String, Object> payload) {
+    private AjaxResult processPurchaseReturnOrder(Map<String, Object> payload) {
         PurchaseReturnOrderDto dto = objectMapper.convertValue(payload, PurchaseReturnOrderDto.class);
         Boolean result = purchaseReturnOrdersService.add(dto);
-        return R.ok( result,"閲囪喘閫�璐у崟宸插鐞�");
+        return AjaxResult.success("閲囪喘閫�璐у崟宸插鐞�", result);
     }
 }

--
Gitblit v1.9.3