From f8b236340b16d9dfe2ca88407343ac01f34f3cbf Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期四, 21 五月 2026 15:09:42 +0800
Subject: [PATCH] Merge branch 'dev_New_pro' into dev_New_pro_财务
---
src/main/java/com/ruoyi/ai/service/PurchaseAiService.java | 110 ++++++++++++++++++++++++++----------------------------
1 files changed, 53 insertions(+), 57 deletions(-)
diff --git a/src/main/java/com/ruoyi/ai/service/PurchaseAiService.java b/src/main/java/com/ruoyi/ai/service/PurchaseAiService.java
index a4a0dc7..cbc936c 100644
--- a/src/main/java/com/ruoyi/ai/service/PurchaseAiService.java
+++ b/src/main/java/com/ruoyi/ai/service/PurchaseAiService.java
@@ -18,16 +18,20 @@
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;
-import com.ruoyi.purchase.service.IPaymentRegistrationService;
import com.ruoyi.purchase.service.IPurchaseLedgerService;
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;
@@ -42,12 +46,21 @@
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
-import java.nio.file.Files;
+import java.util.Base64;
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 {
@@ -67,7 +80,6 @@
private final AiFileTextExtractor aiFileTextExtractor;
private final ObjectMapper objectMapper;
private final IPurchaseLedgerService purchaseLedgerService;
- private final IPaymentRegistrationService paymentRegistrationService;
private final PurchaseReturnOrdersService purchaseReturnOrdersService;
private final StorageBlobService storageBlobService;
private final SupplierManageMapper supplierManageMapper;
@@ -81,7 +93,6 @@
AiFileTextExtractor aiFileTextExtractor,
ObjectMapper objectMapper,
IPurchaseLedgerService purchaseLedgerService,
- IPaymentRegistrationService paymentRegistrationService,
PurchaseReturnOrdersService purchaseReturnOrdersService,
StorageBlobService storageBlobService,
SupplierManageMapper supplierManageMapper,
@@ -94,7 +105,6 @@
this.aiFileTextExtractor = aiFileTextExtractor;
this.objectMapper = objectMapper;
this.purchaseLedgerService = purchaseLedgerService;
- this.paymentRegistrationService = paymentRegistrationService;
this.purchaseReturnOrdersService = purchaseReturnOrdersService;
this.storageBlobService = storageBlobService;
this.supplierManageMapper = supplierManageMapper;
@@ -206,24 +216,23 @@
.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 {
String businessType = request.getBusinessType().trim();
return switch (businessType) {
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));
}
}
@@ -523,8 +532,8 @@
杈撳嚭瑕佹眰:
1. 鍙緭鍑哄悎娉� JSON锛屼笉瑕� Markdown锛屼笉瑕侀澶栬В閲娿��
2. JSON 椤跺眰瀛楁鍥哄畾涓�:
- - ok: boolean
- - businessType: purchase_ledger | payment_registration | purchase_return_order | unknown
+ - success: boolean
+ - businessType: purchase_ledger | purchase_return_order | unknown
- action: confirm_required
- description: 涓枃璇存槑
- confidence: 0鍒�1鐨勫皬鏁�
@@ -549,7 +558,7 @@
entryDateStart, entryDateEnd, id, purchaseContractNumber, supplierId, supplierName, isWhite, recorderId, recorderName, salesContractNo, salesContractNoId, projectName, entryDate, executionDate, remarks, attachmentMaterials, createdAt, updatedAt, salesLedgerId, hasChildren, Type, productData, tempFileIds, SalesLedgerFiles, phoneNumber, businessPersonId, productId, productModelId, invoiceNumber, invoiceAmount, ticketRegistrationId, contractAmount, receiptPaymentAmount, unReceiptPaymentAmount, type, paymentMethod, approvalStatus, templateName
- productData 姣忔潯浜у搧鍙娇鐢ㄨ繖浜� SalesLedgerProduct 瀛楁鍚�:
productCategory, specificationModel, unit, quantity, taxRate, taxInclusiveUnitPrice, taxInclusiveTotalPrice, taxExclusiveTotalPrice, invoiceType, productId, productModelId, isChecked, type
- 4. 濡傛灉鍙垽鏂负浠樻鐧昏锛宐usinessType 浣跨敤 payment_registration锛宲ayload.records 涓轰粯娆剧櫥璁版暟缁勶紝瀛楁灏介噺鍖呭惈 purchaseLedgerId銆乻alesLedgerProductId銆乧urrentPaymentAmount銆乸aymentMethod銆乸aymentDate銆�
+ 4. 濡傛灉鍙垽鏂负浠樻鐧昏锛宐usinessType 浣跨敤 payload.records 涓轰粯娆剧櫥璁版暟缁勶紝瀛楁灏介噺鍖呭惈 purchaseLedgerId銆乻alesLedgerProductId銆乧urrentPaymentAmount銆乸aymentMethod銆乸aymentDate銆�
5. 濡傛灉鍙垽鏂负閲囪喘閫�璐э紝businessType 浣跨敤 purchase_return_order锛宲ayload 鎸� PurchaseReturnOrderDto 缁勭粐锛屾槑缁嗘斁 purchaseReturnOrderProductsDtos銆�
6. 缂哄皯涓氬姟澶勭悊蹇呴』瀛楁鏃讹紝涓嶈缂栭�� ID锛屾妸瀛楁鏀惧叆 missingFields锛屽苟浠嶈繑鍥炲彲纭鐨勮崏绋挎暟鎹��
7. 鎵�鏈変腑鏂囧唴瀹圭洿鎺ヤ繚鐣欙紝涓嶈杞箟鎴� Unicode銆�
@@ -559,33 +568,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"));
@@ -593,11 +602,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;
}
@@ -607,7 +616,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;
}
@@ -622,7 +631,7 @@
item.put("result", result);
results.add(item);
}
- return R.ok( results,"閲囪喘鍙拌处宸叉壒閲忓鐞�");
+ return AjaxResult.success("閲囪喘鍙拌处宸叉壒閲忓鐞�", results);
}
private List<SalesLedgerProduct> matchProductsForLedger(Map<String, Object> ledgerMap,
@@ -828,7 +837,7 @@
}
}
- private R validatePurchaseProducts(List<SalesLedgerProduct> products, int ledgerIndex) {
+ private AjaxResult validatePurchaseProducts(List<SalesLedgerProduct> products, int ledgerIndex) {
if (products == null || products.isEmpty()) {
return null;
}
@@ -836,34 +845,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;
}
@@ -1034,40 +1043,27 @@
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) {
- Object recordsValue = payload.get("records");
- List<PaymentRegistration> records;
- if (recordsValue == null) {
- records = Collections.singletonList(objectMapper.convertValue(payload, PaymentRegistration.class));
- } else {
- records = objectMapper.convertValue(recordsValue, new TypeReference<List<PaymentRegistration>>() {
- });
- }
- int result = paymentRegistrationService.insertPaymentRegistration(records);
- return R.ok( 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