Commit 3b4ba159 by 黄明步

druid

parent 718b32b8
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
<java.version>8</java.version> <java.version>8</java.version>
<spring-cloud.version>Hoxton.SR11</spring-cloud.version> <spring-cloud.version>Hoxton.SR11</spring-cloud.version>
<elasticsearch.version>8.9.1</elasticsearch.version> <elasticsearch.version>8.9.1</elasticsearch.version>
<alibaba.druid.version>1.1.22</alibaba.druid.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
...@@ -189,6 +190,13 @@ ...@@ -189,6 +190,13 @@
<artifactId>jakarta.json-api</artifactId> <artifactId>jakarta.json-api</artifactId>
<version>2.0.1</version> <version>2.0.1</version>
</dependency> </dependency>
<!-- druid数据源驱动 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${alibaba.druid.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -38,7 +38,6 @@ import javax.servlet.http.HttpServletRequest; ...@@ -38,7 +38,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
...@@ -167,7 +166,7 @@ public class RetransmissionService { ...@@ -167,7 +166,7 @@ public class RetransmissionService {
paramMap.put("fileId", fileId); paramMap.put("fileId", fileId);
// 不能直接传 MultipartFile,另存一份临时文件,请求完毕后删除。 // 不能直接传 MultipartFile,另存一份临时文件,请求完毕后删除。
// File tempFile = new File("C:\\Users\\Administrator\\Desktop\\test", System.currentTimeMillis() +"_"+ file.getOriginalFilename()); // File tempFile = new File("C:\\Users\\Administrator\\Desktop\\test", System.currentTimeMillis() +"_"+ file.getOriginalFilename());
File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + file.getOriginalFilename()); File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + FileUtil.getName(file.getOriginalFilename()));
try { try {
file.transferTo(tempFile); file.transferTo(tempFile);
} catch (IOException e) { } catch (IOException e) {
...@@ -200,7 +199,7 @@ public class RetransmissionService { ...@@ -200,7 +199,7 @@ public class RetransmissionService {
// Assert.hasText(res, "请求接口返回为空"); // Assert.hasText(res, "请求接口返回为空");
if (StringUtils.isEmpty(res)) { if (StringUtils.isEmpty(res)) {
this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request); this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request);
return new OcrResult("-1", "请求失败", null, null); return new OcrResult("007500", "识别失败,请重试", null, DateUtil.current());
} }
FileUtil.del(tempFile); FileUtil.del(tempFile);
OcrResult result = JSONUtil.toBean(res, OcrResult.class); OcrResult result = JSONUtil.toBean(res, OcrResult.class);
...@@ -216,7 +215,7 @@ public class RetransmissionService { ...@@ -216,7 +215,7 @@ public class RetransmissionService {
paramMap.put("fileId", fileId); paramMap.put("fileId", fileId);
// 不能直接传 MultipartFile,另存一份临时文件,请求完毕后删除。 // 不能直接传 MultipartFile,另存一份临时文件,请求完毕后删除。
// File tempFile = new File("C:\\Users\\Administrator\\Desktop\\test", System.currentTimeMillis() +"_"+ file.getOriginalFilename()); // File tempFile = new File("C:\\Users\\Administrator\\Desktop\\test", System.currentTimeMillis() +"_"+ file.getOriginalFilename());
File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + file.getOriginalFilename()); File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + FileUtil.getName(file.getOriginalFilename()));
try { try {
file.transferTo(tempFile); file.transferTo(tempFile);
} catch (IOException e) { } catch (IOException e) {
...@@ -246,7 +245,7 @@ public class RetransmissionService { ...@@ -246,7 +245,7 @@ public class RetransmissionService {
if (StringUtils.isEmpty(res)) { if (StringUtils.isEmpty(res)) {
this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request); this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request);
return new OcrResult("-1", "请求失败", null, null); return new OcrResult("007500", "识别失败,请重试", null, DateUtil.current());
} }
FileUtil.del(tempFile); FileUtil.del(tempFile);
OcrResult result = JSONUtil.toBean(res, OcrResult.class); OcrResult result = JSONUtil.toBean(res, OcrResult.class);
...@@ -260,14 +259,11 @@ public class RetransmissionService { ...@@ -260,14 +259,11 @@ public class RetransmissionService {
public void downloadDoubleDeckPdf(JSONObject body, HttpServletRequest request, HttpServletResponse response) { public void downloadDoubleDeckPdf(JSONObject body, HttpServletRequest request, HttpServletResponse response) {
try { try {
// ServerInfo ocrServerAddress = getOcrServerAddress();
ServerInfo ocrServerAddress = getServerAddressByRequestCount(); ServerInfo ocrServerAddress = getServerAddressByRequestCount();
if (ocrServerAddress == null) { if (ocrServerAddress == null) {
returnError(response, 500, "OCR云平台未配置服务器信息"); returnError(response, 500, "OCR云平台未配置服务器信息");
return; return;
} }
// setActiveServer(ocrServerAddress.getIp());
addServerRequestCount(ocrServerAddress.getIp(), 1);
String ocrApi = "http://" + ocrServerAddress.getIp() + ":" + ocrServerAddress.getOcrPort(); String ocrApi = "http://" + ocrServerAddress.getIp() + ":" + ocrServerAddress.getOcrPort();
HttpResponse httpResponse = HttpRequest.post(ocrApi + "/ofs/api/sync/v1/pdf") HttpResponse httpResponse = HttpRequest.post(ocrApi + "/ofs/api/sync/v1/pdf")
.header("Authorization", request.getHeader("Authorization")) .header("Authorization", request.getHeader("Authorization"))
...@@ -283,7 +279,6 @@ public class RetransmissionService { ...@@ -283,7 +279,6 @@ public class RetransmissionService {
response.setHeader(entry.getKey(), entry.getValue().get(0)); response.setHeader(entry.getKey(), entry.getValue().get(0));
} }
} }
addServerRequestCount(ocrServerAddress.getIp(), -1);
// 赋值body // 赋值body
IoUtil.copy(httpResponse.bodyStream(), response.getOutputStream()); IoUtil.copy(httpResponse.bodyStream(), response.getOutputStream());
} catch (IOException e) { } catch (IOException e) {
...@@ -329,14 +324,11 @@ public class RetransmissionService { ...@@ -329,14 +324,11 @@ public class RetransmissionService {
public void downloadDoubleDeckOfd(JSONObject body, HttpServletRequest request, HttpServletResponse response) { public void downloadDoubleDeckOfd(JSONObject body, HttpServletRequest request, HttpServletResponse response) {
try { try {
// ServerInfo ocrServerAddress = getOcrServerAddress();
ServerInfo ocrServerAddress = getServerAddressByRequestCount(); ServerInfo ocrServerAddress = getServerAddressByRequestCount();
if (ocrServerAddress == null) { if (ocrServerAddress == null) {
returnError(response, 500, "OCR云平台未配置服务器信息"); returnError(response, 500, "OCR云平台未配置服务器信息");
return; return;
} }
// setActiveServer(ocrServerAddress.getIp());
addServerRequestCount(ocrServerAddress.getIp(), 1);
String ocrApi = "http://" + ocrServerAddress.getIp() + ":" + ocrServerAddress.getOcrPort(); String ocrApi = "http://" + ocrServerAddress.getIp() + ":" + ocrServerAddress.getOcrPort();
HttpResponse httpResponse = HttpRequest.post(ocrApi + "/ofs/api/sync/v1/ofd") HttpResponse httpResponse = HttpRequest.post(ocrApi + "/ofs/api/sync/v1/ofd")
.header("Authorization", request.getHeader("Authorization")) .header("Authorization", request.getHeader("Authorization"))
...@@ -350,7 +342,6 @@ public class RetransmissionService { ...@@ -350,7 +342,6 @@ public class RetransmissionService {
response.setHeader(entry.getKey(), entry.getValue().get(0)); response.setHeader(entry.getKey(), entry.getValue().get(0));
} }
} }
addServerRequestCount(ocrServerAddress.getIp(), -1);
IoUtil.copy(httpResponse.bodyStream(), response.getOutputStream()); IoUtil.copy(httpResponse.bodyStream(), response.getOutputStream());
} catch (Exception e) { } catch (Exception e) {
log.error("OCR云平台接口异常", e); log.error("OCR云平台接口异常", e);
...@@ -397,7 +388,7 @@ public class RetransmissionService { ...@@ -397,7 +388,7 @@ public class RetransmissionService {
public OcrResult fullTextRecognition(String fileId, MultipartFile file, HttpServletRequest request) { public OcrResult fullTextRecognition(String fileId, MultipartFile file, HttpServletRequest request) {
HashMap<String, Object> paramMap = new HashMap<>(); HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("fileId", fileId); paramMap.put("fileId", fileId);
File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + file.getOriginalFilename()); File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + FileUtil.getName(file.getOriginalFilename()));
try { try {
file.transferTo(tempFile); file.transferTo(tempFile);
} catch (IOException e) { } catch (IOException e) {
...@@ -429,7 +420,7 @@ public class RetransmissionService { ...@@ -429,7 +420,7 @@ public class RetransmissionService {
// Assert.hasText(res, "请求接口返回为空"); // Assert.hasText(res, "请求接口返回为空");
if (StringUtils.isEmpty(res)) { if (StringUtils.isEmpty(res)) {
this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request); this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request);
return new OcrResult("-1", "请求失败", null, null); return new OcrResult("007500", "识别失败,请重试", null, DateUtil.current());
} }
FileUtil.del(tempFile); FileUtil.del(tempFile);
OcrResult result = JSONUtil.toBean(res, OcrResult.class); OcrResult result = JSONUtil.toBean(res, OcrResult.class);
...@@ -443,7 +434,7 @@ public class RetransmissionService { ...@@ -443,7 +434,7 @@ public class RetransmissionService {
public OcrResult fullTextRecognitionV2(String fileId, MultipartFile file, HttpServletRequest request) { public OcrResult fullTextRecognitionV2(String fileId, MultipartFile file, HttpServletRequest request) {
HashMap<String, Object> paramMap = new HashMap<>(); HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("fileId", fileId); paramMap.put("fileId", fileId);
File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + file.getOriginalFilename()); File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + FileUtil.getName(file.getOriginalFilename()));
try { try {
file.transferTo(tempFile); file.transferTo(tempFile);
} catch (IOException e) { } catch (IOException e) {
...@@ -475,7 +466,7 @@ public class RetransmissionService { ...@@ -475,7 +466,7 @@ public class RetransmissionService {
// Assert.hasText(res, "请求接口返回为空"); // Assert.hasText(res, "请求接口返回为空");
if (StringUtils.isEmpty(res)) { if (StringUtils.isEmpty(res)) {
this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request); this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request);
return new OcrResult("-1", "请求失败", null, null); return new OcrResult("007500", "识别失败,请重试", null, DateUtil.current());
} }
FileUtil.del(tempFile); FileUtil.del(tempFile);
OcrResult result = JSONUtil.toBean(res, OcrResult.class); OcrResult result = JSONUtil.toBean(res, OcrResult.class);
...@@ -489,7 +480,7 @@ public class RetransmissionService { ...@@ -489,7 +480,7 @@ public class RetransmissionService {
public OcrResult cardRecognition(Integer code, String fileId, MultipartFile file, HttpServletRequest request) { public OcrResult cardRecognition(Integer code, String fileId, MultipartFile file, HttpServletRequest request) {
HashMap<String, Object> paramMap = new HashMap<>(); HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("fileId", fileId); paramMap.put("fileId", fileId);
File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + file.getOriginalFilename()); File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + FileUtil.getName(file.getOriginalFilename()));
try { try {
file.transferTo(tempFile); file.transferTo(tempFile);
} catch (IOException e) { } catch (IOException e) {
...@@ -520,7 +511,7 @@ public class RetransmissionService { ...@@ -520,7 +511,7 @@ public class RetransmissionService {
// Assert.hasText(res, "请求接口返回为空"); // Assert.hasText(res, "请求接口返回为空");
if (StringUtils.isEmpty(res)) { if (StringUtils.isEmpty(res)) {
this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request); this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request);
return new OcrResult("-1", "请求失败", null, null); return new OcrResult("007500", "识别失败,请重试", null, DateUtil.current());
} }
FileUtil.del(tempFile); FileUtil.del(tempFile);
OcrResult result = JSONUtil.toBean(res, OcrResult.class); OcrResult result = JSONUtil.toBean(res, OcrResult.class);
...@@ -565,7 +556,7 @@ public class RetransmissionService { ...@@ -565,7 +556,7 @@ public class RetransmissionService {
// Assert.hasText(res, "请求接口返回为空"); // Assert.hasText(res, "请求接口返回为空");
if (StringUtils.isEmpty(res)) { if (StringUtils.isEmpty(res)) {
this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request); this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request);
return new OcrResult("-1", "请求失败", null, null); return new OcrResult("007500", "识别失败,请重试", null, DateUtil.current());
} }
OcrResult result = JSONUtil.toBean(res, OcrResult.class); OcrResult result = JSONUtil.toBean(res, OcrResult.class);
...@@ -579,7 +570,7 @@ public class RetransmissionService { ...@@ -579,7 +570,7 @@ public class RetransmissionService {
public OcrResult formatRestoration(String fileId, MultipartFile file, HttpServletRequest request) { public OcrResult formatRestoration(String fileId, MultipartFile file, HttpServletRequest request) {
HashMap<String, Object> paramMap = new HashMap<>(); HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("fileId", fileId); paramMap.put("fileId", fileId);
File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + file.getOriginalFilename()); File tempFile = new File(tempDir, System.currentTimeMillis() + "_" + FileUtil.getName(file.getOriginalFilename()));
try { try {
file.transferTo(tempFile); file.transferTo(tempFile);
} catch (IOException e) { } catch (IOException e) {
...@@ -609,7 +600,7 @@ public class RetransmissionService { ...@@ -609,7 +600,7 @@ public class RetransmissionService {
if (StringUtils.isEmpty(res)) { if (StringUtils.isEmpty(res)) {
this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request); this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request);
return new OcrResult("-1", "请求失败", null, null); return new OcrResult("007500", "识别失败,请重试", null, DateUtil.current());
} }
FileUtil.del(tempFile); FileUtil.del(tempFile);
......
...@@ -24,7 +24,7 @@ public class OcrResult { ...@@ -24,7 +24,7 @@ public class OcrResult {
} }
public static OcrResult error(String message) { public static OcrResult error(String message) {
return new OcrResult("500", message, "", DateUtil.current()); return new OcrResult("007500", message, "", DateUtil.current());
} }
......
spring: spring:
datasource: datasource:
druid:
db-type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root username: root
password: Docimax@123 password: Docimax@123
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://147.1.5.77:3306/yuntu_ofs?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai url: jdbc:mysql://147.1.5.77:3306/yuntu_ofs?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
initial-size: 3 # 初始化时建立物理连接的个数
min-idle: 5 # 最小连接池数量
max-active: 200 # 最大连接池数量
max-wait: 5000 # 获取连接时最大等待时间,单位毫秒
time-between-eviction-runs-millis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
min-evictable-idle-time-millis: 100000 # 连接保持空闲而不被驱逐的最小时间
max-evictable-idle-time-millis: 300000 # 连接保持空闲而不被驱逐的最大时间
test-while-idle: true
test-on-borrow: false
test-on-return: false
validation-query: select 1
webStatFilter:
enabled: true
#安全配置
stat-view-servlet:
enabled: true
url-pattern: /druid/*
reset-enable: false
login-username: admin
login-password: GXfy!2023
filter:
stat:
enabled: true
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: true
wall:
config:
multi-statement-allow: true
redis: redis:
cluster: cluster:
nodes: nodes:
......
spring: spring:
datasource: datasource:
druid:
db-type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root username: root
password: Dk2019!23456 password: Dk2019!23456
# password: Docimax@123
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://119.45.183.210:13308/ocr_cloud?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai url: jdbc:mysql://119.45.183.210:13308/ocr_cloud?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
# url: jdbc:mysql://147.1.5.77:3306/yuntu_ofs?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai initial-size: 3 # 初始化时建立物理连接的个数
# redis: min-idle: 5 # 最小连接池数量
# cluster: max-active: 200 # 最大连接池数量
# nodes: max-wait: 5000 # 获取连接时最大等待时间,单位毫秒
# - 147.1.5.79:6379 time-between-eviction-runs-millis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
# - 147.1.5.79:6389 min-evictable-idle-time-millis: 100000 # 连接保持空闲而不被驱逐的最小时间
# - 147.1.5.80:6379 max-evictable-idle-time-millis: 300000 # 连接保持空闲而不被驱逐的最大时间
# - 147.1.5.80:6389 test-while-idle: true
# - 147.1.5.81:6379 test-on-borrow: false
# - 147.1.5.81:6389 test-on-return: false
# database: 0 validation-query: select 1
# password: Docimax webStatFilter:
# jedis: enabled: true
# pool: #安全配置
# max-active: 128 stat-view-servlet:
# max-wait: 60s enabled: true
# max-idle: 64 url-pattern: /druid/*
# min-idle: 0 reset-enable: false
# timeout: 5000 login-username: admin
login-password: GXfy!2023
filter:
stat:
enabled: true
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: true
wall:
config:
multi-statement-allow: true
redis: redis:
host: 127.0.0.1 host: 127.0.0.1
port: 6379 port: 6379
...@@ -36,9 +47,6 @@ spring: ...@@ -36,9 +47,6 @@ spring:
max-idle: 64 max-idle: 64
min-idle: 0 min-idle: 0
timeout: 5000 timeout: 5000
#eureka:
# client:
# enabled: false
ocr: ocr:
api: http://147.2.4.2:9001 api: http://147.2.4.2:9001
......
spring: spring:
profiles: profiles:
active: 147prod active: dev
servlet: servlet:
multipart: multipart:
max-file-size: 1024MB max-file-size: 1024MB
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment