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
f1c5a835
Commit
f1c5a835
authored
May 29, 2024
by
黄明步
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加识别错误超过次数则停用逻辑
parent
4e830ef5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
4 deletions
+53
-4
src/main/java/com/gxmailu/ocrCloudPlatform/constant/RedisConstant.java
+5
-0
src/main/java/com/gxmailu/ocrCloudPlatform/controller/AppAbilityRecordAllController.java
+5
-3
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/RetransmissionService.java
+43
-1
No files found.
src/main/java/com/gxmailu/ocrCloudPlatform/constant/RedisConstant.java
View file @
f1c5a835
...
...
@@ -48,5 +48,10 @@ public class RedisConstant {
*/
public
static
final
String
SERVER_MONITORING
=
"server:monitoring"
;
/**
* redis key 记录每个服务器错误的次数
**/
public
static
final
String
SERVER_ERROR_COUNT
=
"server-error:count:"
;
}
src/main/java/com/gxmailu/ocrCloudPlatform/controller/AppAbilityRecordAllController.java
View file @
f1c5a835
package
com
.
gxmailu
.
ocrCloudPlatform
.
controller
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.date.DateTime
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.IdUtil
;
...
...
@@ -18,11 +19,11 @@ import com.gxmailu.ocrCloudPlatform.entity.*;
import
com.gxmailu.ocrCloudPlatform.excel.handler.ExcelFillCellMergeStrategy
;
import
com.gxmailu.ocrCloudPlatform.excel.model.CallRecordModel
;
import
com.gxmailu.ocrCloudPlatform.excel.utils.ExcelStyleUtils
;
import
com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecord8Mapper
;
import
com.gxmailu.ocrCloudPlatform.mapper.ConfigAbilityMapper
;
import
com.gxmailu.ocrCloudPlatform.mapper.ConfigApplicationMapper
;
import
com.gxmailu.ocrCloudPlatform.service.AppAbilityRecordAllService
;
import
com.gxmailu.ocrCloudPlatform.service.OaCallRecordService
;
import
com.gxmailu.ocrCloudPlatform.service.impl.ElasticSearchService
;
import
com.gxmailu.ocrCloudPlatform.vo.AppAbilityRecordVo
;
import
com.gxmailu.ocrCloudPlatform.vo.Result
;
import
io.swagger.annotations.Api
;
...
...
@@ -67,7 +68,7 @@ public class AppAbilityRecordAllController {
private
ConfigAbilityMapper
configAbilityMapper
;
@Autowired
private
AppAbilityRecord8Mapper
record8Mapper
;
private
ElasticSearchService
elasticSearchService
;
/**
* 导出应用调用记录
...
...
@@ -360,7 +361,8 @@ public class AppAbilityRecordAllController {
record
.
setCallTime
(
DateUtil
.
date
());
record
.
setFileCount
(
1
);
record8Mapper
.
insert
(
record
);
elasticSearchService
.
recordDataImport
(
CollUtil
.
newArrayList
(
record
));
return
Result
.
success
(
"成功"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"执行失败"
,
e
);
...
...
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/RetransmissionService.java
View file @
f1c5a835
...
...
@@ -148,6 +148,29 @@ public class RetransmissionService {
}
}
@Async
public
void
recordErrors
(
String
ip
)
{
String
key
=
RedisConstant
.
SERVER_ERROR_COUNT
+
ip
;
if
(
redisService
.
exists
(
key
))
{
redisService
.
incr
(
key
,
1
);
}
else
{
redisService
.
set
(
key
,
1
,
1
,
TimeUnit
.
MINUTES
);
}
// 判断识别错误的次数是否大于3次,若大于则移除服务器2分钟
long
count
;
Object
o
=
redisService
.
get
(
key
);
if
(
ObjUtil
.
isNotNull
(
o
))
{
count
=
Long
.
parseLong
(
o
.
toString
());
if
(
count
>=
3
)
{
Object
object
=
redisService
.
getValue
(
RedisConstant
.
OCR_SERVER_LIST
);
List
<
ServerInfo
>
serverInfos
=
JSONArray
.
parseArray
(
object
.
toString
(),
ServerInfo
.
class
);
serverInfos
=
serverInfos
.
stream
().
filter
(
serverInfo
->
!
serverInfo
.
getIp
().
equals
(
ip
)).
collect
(
Collectors
.
toList
());
redisService
.
set
(
RedisConstant
.
OCR_SERVER_LIST
,
serverInfos
,
2
,
TimeUnit
.
MINUTES
);
redisService
.
delete
(
key
);
}
}
}
public
OcrResult
getClientOcrTask
()
{
List
<
Object
>
result
=
redisService
.
getList
(
"clientOcrTask"
);
List
<
JSONObject
>
jsonList
=
JSONArray
.
parseArray
(
result
.
toString
(),
JSONObject
.
class
);
...
...
@@ -187,9 +210,18 @@ public class RetransmissionService {
json
.
set
(
"endTime"
,
DateUtil
.
format
(
DateUtil
.
date
(
endTime
),
"yyyy-MM-dd HH:mm:ss.SSS"
));
json
.
set
(
"time"
,
(
Double
.
parseDouble
(
String
.
valueOf
((
endTime
-
startTime
)))
/
Double
.
parseDouble
(
"1000.00"
))
+
"秒"
);
if
(
ocrResult
!=
null
)
{
json
.
set
(
"code"
,
ocrResult
.
getCode
());
String
code
=
ocrResult
.
getCode
();
json
.
set
(
"code"
,
code
);
json
.
set
(
"message"
,
ocrResult
.
getMessage
());
if
(
"007500"
.
equals
(
code
))
{
// 记录错误次数
recordErrors
(
ocrServerAddress
.
getIp
());
}
}
else
{
// 记录错误次数
recordErrors
(
ocrServerAddress
.
getIp
());
}
redisService
.
set
(
"clientOcrTask-"
+
ocrServerAddress
.
getIp
()
+
"-"
+
ServletUtil
.
getClientIP
(
request
)
+
"-"
+
startTime
,
json
,
...
...
@@ -247,6 +279,8 @@ public class RetransmissionService {
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
retryCount
++;
log
.
error
(
"OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}"
,
fileId
,
ocrServerAddress
.
getIp
(),
retryCount
,
e
);
// 记录错误次数
recordErrors
(
ocrServerAddress
.
getIp
());
}
}
...
...
@@ -353,6 +387,8 @@ public class RetransmissionService {
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
retryCount
++;
log
.
error
(
"OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}"
,
fileId
,
ocrServerAddress
.
getIp
(),
retryCount
,
e
);
// 记录错误次数
recordErrors
(
ocrServerAddress
.
getIp
());
}
}
...
...
@@ -520,6 +556,8 @@ public class RetransmissionService {
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
retryCount
++;
log
.
error
(
"OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}"
,
fileId
,
ocrServerAddress
.
getIp
(),
retryCount
,
e
);
// 记录错误次数
recordErrors
(
ocrServerAddress
.
getIp
());
}
}
...
...
@@ -593,6 +631,8 @@ public class RetransmissionService {
addServerRequestCount
(
ocrServerAddress
.
getIp
(),
-
1
);
retryCount
++;
log
.
error
(
"OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}"
,
fileId
,
ocrServerAddress
.
getIp
(),
retryCount
);
// 记录错误次数
recordErrors
(
ocrServerAddress
.
getIp
());
}
}
...
...
@@ -660,6 +700,8 @@ public class RetransmissionService {
return
result
;
}
catch
(
Exception
e
)
{
log
.
error
(
"OCR云平台接口异常, fileId={}, serverIp={}"
,
fileId
,
ocrServerAddress
.
getIp
(),
e
);
// 记录错误次数
recordErrors
(
ocrServerAddress
.
getIp
());
return
new
OcrResult
(
"007500"
,
"识别失败,请重试"
,
null
,
DateUtil
.
date
());
}
finally
{
FileUtil
.
del
(
tempSaveDir
);
...
...
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