Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
ocrCloudPlatForm
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ocr-cloud-platform
ocrCloudPlatForm
Commits
d4daf21b
Commit
d4daf21b
authored
Feb 01, 2024
by
黄明步
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
78d91a2e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
106 deletions
+26
-106
src/main/java/com/gxmailu/ocrCloudPlatform/constant/RedisConstant.java
+4
-0
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/ElasticSearchService.java
+14
-10
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/RetransmissionService.java
+7
-95
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/ServerInfoServiceImpl.java
+1
-1
No files found.
src/main/java/com/gxmailu/ocrCloudPlatform/constant/RedisConstant.java
View file @
d4daf21b
...
@@ -34,6 +34,10 @@ public class RedisConstant {
...
@@ -34,6 +34,10 @@ public class RedisConstant {
* redis key 能力配置信息
* redis key 能力配置信息
**/
**/
public
static
final
String
CONFIG_ABILITY_ALL
=
"configAbility:all"
;
public
static
final
String
CONFIG_ABILITY_ALL
=
"configAbility:all"
;
/**
* redis key 记录每个服务器识别时间超过10s的次数
**/
public
static
final
String
SLOW_CALL_COUNT
=
"slow-call:count:"
;
}
}
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/ElasticSearchService.java
View file @
d4daf21b
...
@@ -33,7 +33,6 @@ import com.gxmailu.ocrCloudPlatform.service.CourtService;
...
@@ -33,7 +33,6 @@ import com.gxmailu.ocrCloudPlatform.service.CourtService;
import
com.gxmailu.ocrCloudPlatform.utils.IpUtils
;
import
com.gxmailu.ocrCloudPlatform.utils.IpUtils
;
import
com.gxmailu.ocrCloudPlatform.vo.BrokenLineData
;
import
com.gxmailu.ocrCloudPlatform.vo.BrokenLineData
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.poi.ss.formula.functions.T
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -148,10 +147,6 @@ public class ElasticSearchService {
...
@@ -148,10 +147,6 @@ public class ElasticSearchService {
JSONObject
object
=
new
JSONObject
();
JSONObject
object
=
new
JSONObject
();
SearchResponse
<
Void
>
searchResponse
;
SearchResponse
<
Void
>
searchResponse
;
try
{
try
{
// 获取法院ip段
List
<
String
>
ipScopes
=
StrUtil
.
splitTrim
(
court
.
getIpScope
(),
"-"
);
List
<
String
>
ipRange
=
ipScopes
.
size
()
!=
2
?
Arrays
.
asList
(
"255.255.255.255"
,
"255.255.255.255"
)
:
IpUtils
.
getIPRange
(
ipScopes
.
get
(
0
),
ipScopes
.
get
(
1
),
3
);
searchResponse
=
client
.
search
(
srBuilder
->
srBuilder
searchResponse
=
client
.
search
(
srBuilder
->
srBuilder
.
index
(
APP_ABILITY_RECORD_INDEX
)
.
index
(
APP_ABILITY_RECORD_INDEX
)
.
query
(
queryBuilder
->
queryBuilder
.
bool
(
boolQuery
->
{
.
query
(
queryBuilder
->
queryBuilder
.
bool
(
boolQuery
->
{
...
@@ -160,11 +155,20 @@ public class ElasticSearchService {
...
@@ -160,11 +155,20 @@ public class ElasticSearchService {
.
field
(
"callTime"
)
.
field
(
"callTime"
)
.
gte
(
JsonData
.
of
(
start
.
toString
()))
.
gte
(
JsonData
.
of
(
start
.
toString
()))
.
lte
(
JsonData
.
of
(
end
.
toString
()))));
.
lte
(
JsonData
.
of
(
end
.
toString
()))));
// 多个ip前缀过滤
if
(
ObjUtil
.
isNotNull
(
court
))
{
boolQuery
.
must
(
mustQuery
->
mustQuery
.
bool
(
bq
->
{
// 获取法院ip段
ipRange
.
forEach
(
ip
->
bq
.
should
(
q
->
q
.
prefix
(
pq
->
pq
.
field
(
"ip.keyword"
).
value
(
ip
))));
List
<
String
>
ipScopes
=
StrUtil
.
splitTrim
(
court
.
getIpScope
(),
"-"
);
return
bq
;
try
{
}));
List
<
String
>
ipRange
=
ipScopes
.
size
()
!=
2
?
Arrays
.
asList
(
"255.255.255.255"
,
"255.255.255.255"
)
:
IpUtils
.
getIPRange
(
ipScopes
.
get
(
0
),
ipScopes
.
get
(
1
),
3
);
// 多个ip前缀过滤
boolQuery
.
must
(
mustQuery
->
mustQuery
.
bool
(
bq
->
{
ipRange
.
forEach
(
ip
->
bq
.
should
(
q
->
q
.
prefix
(
pq
->
pq
.
field
(
"ip.keyword"
).
value
(
ip
))));
return
bq
;
}));
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
}
return
boolQuery
;
return
boolQuery
;
}))
}))
// 总命中数,与hits.size()不同的是trackTotalHits不会限制10000
// 总命中数,与hits.size()不同的是trackTotalHits不会限制10000
...
...
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/RetransmissionService.java
View file @
d4daf21b
...
@@ -4,12 +4,14 @@ import cn.hutool.core.bean.BeanUtil;
...
@@ -4,12 +4,14 @@ import cn.hutool.core.bean.BeanUtil;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.io.IoUtil
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.ObjUtil
;
import
cn.hutool.core.util.ObjUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.extra.servlet.ServletUtil
;
import
cn.hutool.extra.servlet.ServletUtil
;
import
cn.hutool.http.*
;
import
cn.hutool.http.ContentType
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpResponse
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
...
@@ -69,8 +71,7 @@ public class RetransmissionService {
...
@@ -69,8 +71,7 @@ public class RetransmissionService {
private
AppAbilityRecord8Mapper
record8Mapper
;
private
AppAbilityRecord8Mapper
record8Mapper
;
@Autowired
@Autowired
private
AppAbilityRecord9Mapper
record9Mapper
;
private
AppAbilityRecord9Mapper
record9Mapper
;
@Autowired
private
AppAbilityRecordAllMapper
recordAllMapper
;
@Autowired
@Autowired
private
TmpRecordByTriggerMapper
tmpRecordByTriggerMapper
;
private
TmpRecordByTriggerMapper
tmpRecordByTriggerMapper
;
...
@@ -106,7 +107,6 @@ public class RetransmissionService {
...
@@ -106,7 +107,6 @@ public class RetransmissionService {
private
static
final
int
MAX_RETRIES
=
5
;
private
static
final
int
MAX_RETRIES
=
5
;
@PostConstruct
@PostConstruct
public
void
init
()
{
public
void
init
()
{
// 创建临时文件夹
// 创建临时文件夹
...
@@ -221,7 +221,6 @@ public class RetransmissionService {
...
@@ -221,7 +221,6 @@ public class RetransmissionService {
}
}
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
OcrResult
result
=
JSONUtil
.
toBean
(
res
,
OcrResult
.
class
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
this
.
setRequestToRedis
(
2
,
startTime
,
endTime
,
result
,
ocrServerAddress
,
request
);
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
(),
fileId
);
saveToAppAbilityRecordAll
(
result
,
request
,
ocrServerAddress
.
getIp
(),
fileId
);
return
result
;
return
result
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -236,13 +235,6 @@ public class RetransmissionService {
...
@@ -236,13 +235,6 @@ public class RetransmissionService {
}
}
public
Map
<
String
,
String
>
getHeaderMap
(
HttpServletRequest
request
)
{
public
Map
<
String
,
String
>
getHeaderMap
(
HttpServletRequest
request
)
{
// Map<String, String> headerMap = new HashMap<>();
// headerMap.put("Authorization", request.getHeader("Authorization"));
// headerMap.put("X-Timestamp", request.getHeader("X-Timestamp"));
// headerMap.put("X-Checksum", request.getHeader("X-Checksum"));
// headerMap.put("Accept", request.getHeader("Accept"));
// headerMap.put("User-Agent", request.getHeader("User-Agent"));
// return headerMap;
Map
<
String
,
String
>
map
=
new
HashMap
<>();
Map
<
String
,
String
>
map
=
new
HashMap
<>();
Enumeration
<
String
>
headerNames
=
request
.
getHeaderNames
();
Enumeration
<
String
>
headerNames
=
request
.
getHeaderNames
();
...
@@ -346,36 +338,6 @@ public class RetransmissionService {
...
@@ -346,36 +338,6 @@ public class RetransmissionService {
}
}
}
}
public
void
downloadDoubleDeckPdf
(
JSONObject
body
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
try
{
ServerInfo
ocrServerAddress
=
getServerAddressByRequestCount
();
if
(
ocrServerAddress
==
null
)
{
returnError
(
response
,
500
,
"OCR云平台未配置服务器信息"
);
return
;
}
String
ocrApi
=
"http://"
+
ocrServerAddress
.
getIp
()
+
":"
+
ocrServerAddress
.
getOcrPort
();
HttpResponse
httpResponse
=
HttpRequest
.
post
(
ocrApi
+
"/ofs/api/sync/v1/pdf"
)
.
headerMap
(
getHeaderMap
(
request
),
true
)
.
contentType
(
"application/json;charset=UTF-8"
)
.
setConnectionTimeout
(
10
*
1000
)
.
body
(
body
.
toJSONString
(
0
)).
execute
();
Map
<
String
,
List
<
String
>>
headers
=
httpResponse
.
headers
();
if
(!
headers
.
isEmpty
())
{
// 遍历赋值header
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry
:
headers
.
entrySet
())
{
response
.
setHeader
(
entry
.
getKey
(),
entry
.
getValue
().
get
(
0
));
}
}
// 赋值body
IoUtil
.
copy
(
httpResponse
.
bodyStream
(),
response
.
getOutputStream
());
}
catch
(
Exception
e
)
{
log
.
error
(
"OCR云平台接口异常"
,
e
);
returnError
(
response
,
500
,
"OCR云平台接口异常"
);
}
}
public
void
downloadPdfNew
(
JSONObject
body
,
HttpServletResponse
response
)
{
public
void
downloadPdfNew
(
JSONObject
body
,
HttpServletResponse
response
)
{
Long
id
=
body
.
getLong
(
"sid"
);
Long
id
=
body
.
getLong
(
"sid"
);
try
{
try
{
...
@@ -383,9 +345,8 @@ public class RetransmissionService {
...
@@ -383,9 +345,8 @@ public class RetransmissionService {
log
.
error
(
"请求体中缺少 'sid' 字段,无法进行后续处理"
);
log
.
error
(
"请求体中缺少 'sid' 字段,无法进行后续处理"
);
return
;
return
;
}
}
AppAbilityRecordAll
appAbilityRecordAll
=
elasticSearchService
.
getDocumentById
(
id
.
toString
());
AppAbilityRecordAll
appAbilityRecordAll
=
elasticSearchService
.
getDocumentById
(
id
.
toString
());
// 如果 appAbilityRecordAll 为空,或者相关字段为空,
则直接
查询数据库
// 如果 appAbilityRecordAll 为空,或者相关字段为空,
再次
查询数据库
if
(
appAbilityRecordAll
==
null
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getServerIp
())
if
(
appAbilityRecordAll
==
null
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getServerIp
())
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getDstUrl
())
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getDstUrl
())
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getPdf
()))
{
||
StrUtil
.
isBlank
(
appAbilityRecordAll
.
getPdf
()))
{
...
@@ -423,32 +384,6 @@ public class RetransmissionService {
...
@@ -423,32 +384,6 @@ public class RetransmissionService {
}
}
}
}
public
void
downloadDoubleDeckOfd
(
JSONObject
body
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
try
{
ServerInfo
ocrServerAddress
=
getServerAddressByRequestCount
();
if
(
ocrServerAddress
==
null
)
{
returnError
(
response
,
500
,
"OCR云平台未配置服务器信息"
);
return
;
}
String
ocrApi
=
"http://"
+
ocrServerAddress
.
getIp
()
+
":"
+
ocrServerAddress
.
getOcrPort
();
HttpResponse
httpResponse
=
HttpRequest
.
post
(
ocrApi
+
"/ofs/api/sync/v1/ofd"
)
.
headerMap
(
getHeaderMap
(
request
),
true
)
.
contentType
(
"application/json;charset=UTF-8"
)
.
setConnectionTimeout
(
10
*
1000
)
.
body
(
body
.
toJSONString
(
0
)).
execute
();
Map
<
String
,
List
<
String
>>
headers
=
httpResponse
.
headers
();
if
(!
headers
.
isEmpty
())
{
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry
:
headers
.
entrySet
())
{
response
.
setHeader
(
entry
.
getKey
(),
entry
.
getValue
().
get
(
0
));
}
}
IoUtil
.
copy
(
httpResponse
.
bodyStream
(),
response
.
getOutputStream
());
}
catch
(
Exception
e
)
{
log
.
error
(
"OCR云平台接口异常"
,
e
);
returnError
(
response
,
500
,
"OCR云平台接口异常"
);
}
}
public
void
downloadOfdNew
(
JSONObject
body
,
HttpServletResponse
response
)
{
public
void
downloadOfdNew
(
JSONObject
body
,
HttpServletResponse
response
)
{
Long
id
=
body
.
getLong
(
"sid"
);
Long
id
=
body
.
getLong
(
"sid"
);
...
@@ -854,29 +789,6 @@ public class RetransmissionService {
...
@@ -854,29 +789,6 @@ public class RetransmissionService {
mapper
.
updateById
(
record
);
mapper
.
updateById
(
record
);
// 保存到ES
// 保存到ES
elasticSearchService
.
recordDataImport
(
Collections
.
singletonList
(
record
));
elasticSearchService
.
recordDataImport
(
Collections
.
singletonList
(
record
));
// // log.info("修改id:{}的真实客户端请求ip结果:{}", id, mapper.updateById(record));
// AppAbilityRecordAll recordAll = recordAllMapper.selectById(id);
// if (recordAll == null) {
// recordAll = new AppAbilityRecordAll();
// BeanUtils.copyProperties(record, recordAll, AppAbilityRecordAll.class);
// recordAll.setCreatedTime(DateUtil.date());
// recordAll.setUpdatedTime(DateUtil.date());
// if (StrUtil.isEmpty(recordAll.getServerIp())) {
// recordAll.setServerIp(serverIp);
// }
// recordAllMapper.insert(recordAll);
// // log.info("添加id:{} 的数据到recordAll持久化保存结果:{}", recordAll.getId(), recordAllMapper.insert(recordAll));
// } else {
// AppAbilityRecordAll newRecordAll = new AppAbilityRecordAll();
// BeanUtils.copyProperties(record, newRecordAll, AppAbilityRecordAll.class);
// newRecordAll.setUpdatedTime(DateUtil.date());
// if (StrUtil.isEmpty(newRecordAll.getServerIp())) {
// newRecordAll.setServerIp(serverIp);
// }
// recordAllMapper.updateById(newRecordAll);
// // log.info("修改recordAll中id:{} 的数据结果:{}", newRecordAll.getId(), recordAllMapper.updateById(newRecordAll));
// }
}
}
...
@@ -991,7 +903,7 @@ public class RetransmissionService {
...
@@ -991,7 +903,7 @@ public class RetransmissionService {
})).
orElse
(
null
);
})).
orElse
(
null
);
}
}
// 如果没有选择到服务器,则从服务器列表中简单轮询选择一个服务器
,而不是随机选择
// 如果没有选择到服务器,则从服务器列表中简单轮询选择一个服务器
if
(
serverInfo
==
null
&&
CollUtil
.
isNotEmpty
(
ocrServerList
))
{
if
(
serverInfo
==
null
&&
CollUtil
.
isNotEmpty
(
ocrServerList
))
{
int
index
=
Math
.
abs
(
counter
.
getAndIncrement
())
%
ocrServerList
.
size
();
int
index
=
Math
.
abs
(
counter
.
getAndIncrement
())
%
ocrServerList
.
size
();
serverInfo
=
ocrServerList
.
get
(
index
);
serverInfo
=
ocrServerList
.
get
(
index
);
...
...
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/ServerInfoServiceImpl.java
View file @
d4daf21b
...
@@ -302,7 +302,7 @@ public class ServerInfoServiceImpl implements ServerInfoService {
...
@@ -302,7 +302,7 @@ public class ServerInfoServiceImpl implements ServerInfoService {
* @param serverInfo 服务器信息
* @param serverInfo 服务器信息
*/
*/
private
ServerVo
getTaskCount
(
ServerInfo
serverInfo
)
{
private
ServerVo
getTaskCount
(
ServerInfo
serverInfo
)
{
Object
count
=
redisService
.
getValue
(
"server-request-task-"
+
serverInfo
.
getIp
());
Object
count
=
redisService
.
getValue
(
RedisConstant
.
SERVER_REQUEST_TASK
+
serverInfo
.
getIp
());
ServerVo
ocrServerVo
=
new
ServerVo
();
ServerVo
ocrServerVo
=
new
ServerVo
();
BeanUtils
.
copyProperties
(
serverInfo
,
ocrServerVo
,
ServerVo
.
class
);
BeanUtils
.
copyProperties
(
serverInfo
,
ocrServerVo
,
ServerVo
.
class
);
ocrServerVo
.
setOcrTask
(
ObjUtil
.
isNull
(
count
)
?
0L
:
Long
.
parseLong
(
count
.
toString
()));
ocrServerVo
.
setOcrTask
(
ObjUtil
.
isNull
(
count
)
?
0L
:
Long
.
parseLong
(
count
.
toString
()));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment