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/controller/OCRController.java | 35 +++++++++++++++--------------------
1 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/OCRController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/OCRController.java
index d370b89..57da753 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/OCRController.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/OCRController.java
@@ -4,6 +4,7 @@
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.file.FileUploadUtils;
+import com.ruoyi.common.utils.image.ImageCompressUtil;
import com.ruoyi.system.utils.AliOCRUtil;
import com.ruoyi.system.utils.BaiduOCRUtil;
import com.ruoyi.system.utils.TencentOCRUtil;
@@ -55,11 +56,8 @@
return error("涓嶆敮鎸佺殑璇嗗埆绫诲瀷: " + type + ", 鏀寔鐨勭被鍨�: " + String.join(",", SUPPORTED_TYPES));
}
- // 淇濆瓨涓存椂鏂囦欢
- String tempDir = System.getProperty("java.io.tmpdir");
- String originalFilename = file.getOriginalFilename();
- File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + originalFilename);
- file.transferTo(tempFile);
+ // 鏅鸿兘鍘嬬缉鍥剧墖锛堣嚜鍔ㄥ鐞嗚秴杩�3MB鐨勫浘鐗囷級
+ File tempFile = ImageCompressUtil.compressForOCR(file);
// 鏍规嵁鎻愪緵鍟嗚皟鐢ㄤ笉鍚岀殑OCR鏈嶅姟
JSONObject ocrResult;
@@ -92,7 +90,10 @@
// 鏋勫缓杩斿洖缁撴灉
Map<String, Object> result = new HashMap<>();
result.put("ocrResult", ocrResult);
- result.put("fileName", originalFilename);
+ result.put("fileName", file.getOriginalFilename());
+ result.put("originalSize", file.getSize());
+ result.put("processedSize", tempFile.length());
+ result.put("compressed", file.getSize() > tempFile.length());
result.put("type", type);
result.put("provider", provider);
@@ -263,11 +264,8 @@
return error("涓婁紶鍥剧墖涓嶈兘涓虹┖");
}
- // 淇濆瓨涓存椂鏂囦欢
- String tempDir = System.getProperty("java.io.tmpdir");
- String originalFilename = file.getOriginalFilename();
- File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + originalFilename);
- file.transferTo(tempFile);
+ // 鏅鸿兘鍘嬬缉鍥剧墖锛堣嚜鍔ㄥ鐞嗚秴杩�3MB鐨勫浘鐗囷級
+ File tempFile = ImageCompressUtil.compressForOCR(file);
// 璋冪敤鑵捐浜戞墜鍐欎綋璇嗗埆
Map<String, String> resultMap = TencentOCRUtil.handwritingRecognizeWith(tempFile.getAbsolutePath(), itemNames);
@@ -282,7 +280,7 @@
// 鏋勫缓杩斿洖缁撴灉
Map<String, Object> result = new HashMap<>();
- result.put("fileName", originalFilename);
+ result.put("fileName", file.getOriginalFilename());
result.put("type", "HandWriting");
result.put("provider", "tencent");
result.put("fields", resultMap);
@@ -356,11 +354,8 @@
}
try {
- // 淇濆瓨涓存椂鏂囦欢
- String tempDir = System.getProperty("java.io.tmpdir");
- String originalFilename = file.getOriginalFilename();
- File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + originalFilename);
- file.transferTo(tempFile);
+ // 鏅鸿兘鍘嬬缉鍥剧墖锛堣嚜鍔ㄥ鐞嗚秴杩�3MB鐨勫浘鐗囷級
+ File tempFile = ImageCompressUtil.compressForOCR(file);
// 璋冪敤鑵捐浜戞墜鍐欎綋璇嗗埆
Map<String, String> resultMap = TencentOCRUtil.handwritingRecognizeWith(tempFile.getAbsolutePath(), itemNames);
@@ -371,8 +366,8 @@
// 妫�鏌ユ槸鍚︽湁閿欒
if (resultMap.containsKey("error")) {
failCount++;
- errorMessages.append(originalFilename).append(":").append(resultMap.get("error")).append("; ");
- logger.warn("鍥剧墖 {} 璇嗗埆澶辫触: {}", originalFilename, resultMap.get("error"));
+ errorMessages.append(file.getOriginalFilename()).append(":").append(resultMap.get("error")).append("; ");
+ logger.warn("鍥剧墖 {} 璇嗗埆澶辫触: {}", file.getOriginalFilename(), resultMap.get("error"));
} else {
// 鍚堝苟璇嗗埆缁撴灉锛堝鏋渒ey宸插瓨鍦紝涓嶈鐩栵級
for (Map.Entry<String, String> entry : resultMap.entrySet()) {
@@ -381,7 +376,7 @@
}
}
successCount++;
- logger.info("鍥剧墖 {} 璇嗗埆鎴愬姛锛屾彁鍙� {} 涓瓧娈�", originalFilename, resultMap.size());
+ logger.info("鍥剧墖 {} 璇嗗埆鎴愬姛锛屾彁鍙� {} 涓瓧娈�", file.getOriginalFilename(), resultMap.size());
}
} catch (Exception e) {
failCount++;
--
Gitblit v1.9.1