From 0ffdf00009b0bede0859fa33deddefb55c075a7b Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期日, 01 二月 2026 16:42:36 +0800
Subject: [PATCH] feat:优化增加任务同步接口,允许前端手动控制同步
---
ruoyi-system/src/main/java/com/ruoyi/system/utils/TencentOCRUtil.java | 79 +++++++++++++++++++++++++++++++++++++--
1 files changed, 74 insertions(+), 5 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/utils/TencentOCRUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/utils/TencentOCRUtil.java
index 6597b02..2f0ea18 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/utils/TencentOCRUtil.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/utils/TencentOCRUtil.java
@@ -18,10 +18,8 @@
import org.springframework.stereotype.Component;
import java.io.File;
-import java.util.Base64;
+import java.util.*;
import java.nio.file.Files;
-import java.util.HashMap;
-import java.util.Map;
/**
* 鑵捐浜慜CR宸ュ叿绫�
@@ -222,7 +220,7 @@
// {"鎮h�呯鍚嶏紙鎵嬪嵃锛�", "绛惧瓧浜鸿韩浠借瘉鍙风爜", "鏃ユ湡", "鑱旂郴鐢佃瘽", "鏈汉", "绛惧瓧浜轰笌鎮h�呭叧绯�"}
req.setItemNames(itemNames != null ? itemNames : new String[]{"鎮h�呭鍚�", "鎬у埆", "骞撮緞", "韬唤璇佸彿", "璇婃柇", "闇�鏀粯杞繍璐圭敤", "琛岀▼", "寮�濮嬫椂闂�", "缁撴潫鏃堕棿", "瀹跺睘绛惧悕"});
req.setOutputLanguage("cn");
- req.setReturnFullText(false);
+ req.setReturnFullText(true);
req.setItemNamesShowMode(false);
ExtractDocMultiResponse resp = client.ExtractDocMulti(req);
@@ -295,7 +293,42 @@
}
}
}
-
+ //灏� WordList
+ List<String> wordListResult = new ArrayList<>();
+ if (responseData.containsKey("WordList") && responseData.getJSONArray("WordList") != null){
+ JSONArray wordList = responseData.getJSONArray("WordList");
+ for (int i = 0; i < wordList.size(); i++) {
+ JSONObject word = wordList.getJSONObject(i);
+ // {
+ // "Coord": {
+ // "LeftBottom": {
+ // "X": 472,
+ // "Y": 1500
+ // },
+ // "LeftTop": {
+ // "X": 467,
+ // "Y": 1420
+ // },
+ // "RightBottom": {
+ // "X": 636,
+ // "Y": 1490
+ // },
+ // "RightTop": {
+ // "X": 631,
+ // "Y": 1410
+ // }
+ // },
+ // "DetectedText": "琛岀▼:"
+ // }
+ String detectedText = word.getString("DetectedText");
+ wordListResult.add(detectedText);
+ }
+ }
+ //鎴戜滑浠巜ordListResult涓绋�:鍚庨潰锛岄渶瑕佹敮浠樿浆杩愯垂鐢�:涔嬮棿鐨勬枃瀛�
+ String content = extractContentFromWordList(wordListResult, "琛岀▼:", "闇�鏀粯杞繍璐圭敤:");
+ log.info("鎻愬彇鍒拌绋�: {}", content);
+ resultMap.put("琛岀▼", content);
+
log.info("鎵嬪啓浣撹瘑鍒彁鍙栧埌 {} 涓瓧娈�", resultMap.size());
return resultMap;
@@ -306,6 +339,42 @@
}
}
+ private static String extractContentFromWordList(List<String> wordListResult, String s, String s1) {
+ //鎻愬彇s鍜宻1涔嬮棿鐨勫唴瀹�
+ //濡傛灉word涓彧鏈変竴鎴�-鎴�->锛岀粺涓�澶勭悊鎴�->
+
+
+ int startIndex = -1;
+ int endIndex = -1;
+
+ for (int i = 0; i < wordListResult.size(); i++) {
+ String word = wordListResult.get(i);
+ if (word.contains(s)) {
+ startIndex = i;
+ }
+
+ if (word.contains(s1)) {
+ endIndex = i;
+ }
+ }
+ if (startIndex == -1 || endIndex == -1 || startIndex >= endIndex) {
+ return "";
+ }
+ List<String> w=wordListResult.subList(startIndex + 1, endIndex);
+ Boolean findAle=false;
+ List<String> result=new ArrayList<>();
+ for(String word:w){
+ if (!findAle && (word.equals("-") || word.equals("->") || word.equals("鈫�") || word.equals("涓�") || word.equals("=>")) ){
+ findAle = true;
+ word = word.replace("-", "鈫�")
+ .replace("涓�", "鈫�")
+ .replace("=>", "鈫�");
+ }
+ result.add(word);
+ };
+ return String.join("", result);
+ }
+
/**
* 韬唤璇佽瘑鍒�
* @param imagePath 鍥剧墖璺緞
--
Gitblit v1.9.1