Commit 3b4ba159 by 黄明步

druid

parent 718b32b8
......@@ -20,6 +20,7 @@
<java.version>8</java.version>
<spring-cloud.version>Hoxton.SR11</spring-cloud.version>
<elasticsearch.version>8.9.1</elasticsearch.version>
<alibaba.druid.version>1.1.22</alibaba.druid.version>
</properties>
<dependencyManagement>
<dependencies>
......@@ -189,6 +190,13 @@
<artifactId>jakarta.json-api</artifactId>
<version>2.0.1</version>
</dependency>
<!-- druid数据源驱动 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${alibaba.druid.version}</version>
</dependency>
</dependencies>
<build>
......
......@@ -38,7 +38,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -167,7 +166,7 @@ public class RetransmissionService {
paramMap.put("fileId", fileId);
// 不能直接传 MultipartFile,另存一份临时文件,请求完毕后删除。
// 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 {
file.transferTo(tempFile);
} catch (IOException e) {
......@@ -200,7 +199,7 @@ public class RetransmissionService {
// Assert.hasText(res, "请求接口返回为空");
if (StringUtils.isEmpty(res)) {
this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request);
return new OcrResult("-1", "请求失败", null, null);
return new OcrResult("007500", "识别失败,请重试", null, DateUtil.current());
}
FileUtil.del(tempFile);
OcrResult result = JSONUtil.toBean(res, OcrResult.class);
......@@ -216,7 +215,7 @@ public class RetransmissionService {
paramMap.put("fileId", fileId);
// 不能直接传 MultipartFile,另存一份临时文件,请求完毕后删除。
// 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 {
file.transferTo(tempFile);
} catch (IOException e) {
......@@ -246,7 +245,7 @@ public class RetransmissionService {
if (StringUtils.isEmpty(res)) {
this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request);
return new OcrResult("-1", "请求失败", null, null);
return new OcrResult("007500", "识别失败,请重试", null, DateUtil.current());
}
FileUtil.del(tempFile);
OcrResult result = JSONUtil.toBean(res, OcrResult.class);
......@@ -260,14 +259,11 @@ public class RetransmissionService {
public void downloadDoubleDeckPdf(JSONObject body, HttpServletRequest request, HttpServletResponse response) {
try {
// ServerInfo ocrServerAddress = getOcrServerAddress();
ServerInfo ocrServerAddress = getServerAddressByRequestCount();
if (ocrServerAddress == null) {
returnError(response, 500, "OCR云平台未配置服务器信息");
return;
}
// setActiveServer(ocrServerAddress.getIp());
addServerRequestCount(ocrServerAddress.getIp(), 1);
String ocrApi = "http://" + ocrServerAddress.getIp() + ":" + ocrServerAddress.getOcrPort();
HttpResponse httpResponse = HttpRequest.post(ocrApi + "/ofs/api/sync/v1/pdf")
.header("Authorization", request.getHeader("Authorization"))
......@@ -283,7 +279,6 @@ public class RetransmissionService {
response.setHeader(entry.getKey(), entry.getValue().get(0));
}
}
addServerRequestCount(ocrServerAddress.getIp(), -1);
// 赋值body
IoUtil.copy(httpResponse.bodyStream(), response.getOutputStream());
} catch (IOException e) {
......@@ -329,14 +324,11 @@ public class RetransmissionService {
public void downloadDoubleDeckOfd(JSONObject body, HttpServletRequest request, HttpServletResponse response) {
try {
// ServerInfo ocrServerAddress = getOcrServerAddress();
ServerInfo ocrServerAddress = getServerAddressByRequestCount();
if (ocrServerAddress == null) {
returnError(response, 500, "OCR云平台未配置服务器信息");
return;
}
// setActiveServer(ocrServerAddress.getIp());
addServerRequestCount(ocrServerAddress.getIp(), 1);
String ocrApi = "http://" + ocrServerAddress.getIp() + ":" + ocrServerAddress.getOcrPort();
HttpResponse httpResponse = HttpRequest.post(ocrApi + "/ofs/api/sync/v1/ofd")
.header("Authorization", request.getHeader("Authorization"))
......@@ -350,7 +342,6 @@ public class RetransmissionService {
response.setHeader(entry.getKey(), entry.getValue().get(0));
}
}
addServerRequestCount(ocrServerAddress.getIp(), -1);
IoUtil.copy(httpResponse.bodyStream(), response.getOutputStream());
} catch (Exception e) {
log.error("OCR云平台接口异常", e);
......@@ -397,7 +388,7 @@ public class RetransmissionService {
public OcrResult fullTextRecognition(String fileId, MultipartFile file, HttpServletRequest request) {
HashMap<String, Object> paramMap = new HashMap<>();
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 {
file.transferTo(tempFile);
} catch (IOException e) {
......@@ -429,7 +420,7 @@ public class RetransmissionService {
// Assert.hasText(res, "请求接口返回为空");
if (StringUtils.isEmpty(res)) {
this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request);
return new OcrResult("-1", "请求失败", null, null);
return new OcrResult("007500", "识别失败,请重试", null, DateUtil.current());
}
FileUtil.del(tempFile);
OcrResult result = JSONUtil.toBean(res, OcrResult.class);
......@@ -443,7 +434,7 @@ public class RetransmissionService {
public OcrResult fullTextRecognitionV2(String fileId, MultipartFile file, HttpServletRequest request) {
HashMap<String, Object> paramMap = new HashMap<>();
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 {
file.transferTo(tempFile);
} catch (IOException e) {
......@@ -475,7 +466,7 @@ public class RetransmissionService {
// Assert.hasText(res, "请求接口返回为空");
if (StringUtils.isEmpty(res)) {
this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request);
return new OcrResult("-1", "请求失败", null, null);
return new OcrResult("007500", "识别失败,请重试", null, DateUtil.current());
}
FileUtil.del(tempFile);
OcrResult result = JSONUtil.toBean(res, OcrResult.class);
......@@ -489,7 +480,7 @@ public class RetransmissionService {
public OcrResult cardRecognition(Integer code, String fileId, MultipartFile file, HttpServletRequest request) {
HashMap<String, Object> paramMap = new HashMap<>();
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 {
file.transferTo(tempFile);
} catch (IOException e) {
......@@ -520,7 +511,7 @@ public class RetransmissionService {
// Assert.hasText(res, "请求接口返回为空");
if (StringUtils.isEmpty(res)) {
this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request);
return new OcrResult("-1", "请求失败", null, null);
return new OcrResult("007500", "识别失败,请重试", null, DateUtil.current());
}
FileUtil.del(tempFile);
OcrResult result = JSONUtil.toBean(res, OcrResult.class);
......@@ -565,7 +556,7 @@ public class RetransmissionService {
// Assert.hasText(res, "请求接口返回为空");
if (StringUtils.isEmpty(res)) {
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);
......@@ -579,7 +570,7 @@ public class RetransmissionService {
public OcrResult formatRestoration(String fileId, MultipartFile file, HttpServletRequest request) {
HashMap<String, Object> paramMap = new HashMap<>();
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 {
file.transferTo(tempFile);
} catch (IOException e) {
......@@ -609,7 +600,7 @@ public class RetransmissionService {
if (StringUtils.isEmpty(res)) {
this.setRequestToRedis(2, startTime, endTime, null, ocrServerAddress, request);
return new OcrResult("-1", "请求失败", null, null);
return new OcrResult("007500", "识别失败,请重试", null, DateUtil.current());
}
FileUtil.del(tempFile);
......
......@@ -24,7 +24,7 @@ public class OcrResult {
}
public static OcrResult error(String message) {
return new OcrResult("500", message, "", DateUtil.current());
return new OcrResult("007500", message, "", DateUtil.current());
}
......
spring:
datasource:
username: root
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
druid:
db-type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: Docimax@123
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:
cluster:
nodes:
......
spring:
datasource:
username: root
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://147.1.5.77:3306/yuntu_ofs?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
# redis:
# cluster:
# nodes:
# - 147.1.5.79:6379
# - 147.1.5.79:6389
# - 147.1.5.80:6379
# - 147.1.5.80:6389
# - 147.1.5.81:6379
# - 147.1.5.81:6389
# database: 0
# password: Docimax
# jedis:
# pool:
# max-active: 128
# max-wait: 60s
# max-idle: 64
# min-idle: 0
# timeout: 5000
druid:
db-type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: Dk2019!23456
url: jdbc:mysql://119.45.183.210:13308/ocr_cloud?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:
host: 127.0.0.1
port: 6379
......@@ -36,9 +47,6 @@ spring:
max-idle: 64
min-idle: 0
timeout: 5000
#eureka:
# client:
# enabled: false
ocr:
api: http://147.2.4.2:9001
......
spring:
profiles:
active: 147prod
active: dev
servlet:
multipart:
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