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
c923d477
Commit
c923d477
authored
Dec 19, 2023
by
黄明步
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复serverInfoMapper.selectList方法名重复导致更新服务器信息后更新redis失败报错的问题
parent
cfe1aaf3
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
31 deletions
+64
-31
pom.xml
+6
-0
src/main/java/com/gxmailu/ocrCloudPlatform/mapper/ServerInfoMapper.java
+1
-1
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/ElasticSearchService.java
+19
-12
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/ServerInfoServiceImpl.java
+12
-4
src/main/resources/application-147prod.yml
+9
-9
src/main/resources/mybatis/mappers/ServerInfoMapper.xml
+1
-1
src/test/java/com/gxmailu/ocrCloudPlatform/RetransmissionServiceTest.java
+16
-4
No files found.
pom.xml
View file @
c923d477
...
...
@@ -197,6 +197,12 @@
<artifactId>
druid-spring-boot-starter
</artifactId>
<version>
${alibaba.druid.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/gxmailu/ocrCloudPlatform/mapper/ServerInfoMapper.java
View file @
c923d477
...
...
@@ -22,7 +22,7 @@ public interface ServerInfoMapper extends BaseMapper<ServerInfo> {
int
updateByPrimaryKey
(
ServerInfo
record
);
List
<
ServerInfo
>
selectList
(
ServerInfo
serverInfo
);
List
<
ServerInfo
>
selectList
ByAccessService
(
ServerInfo
serverInfo
);
List
<
ServerInfo
>
selectListByNetwork
(
Integer
network
);
}
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/ElasticSearchService.java
View file @
c923d477
...
...
@@ -17,13 +17,10 @@ import co.elastic.clients.json.JsonData;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll
;
import
com.gxmailu.ocrCloudPlatform.entity.Court
;
import
com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecord3Mapper
;
import
com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecord4Mapper
;
import
com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecordAllMapper
;
import
com.gxmailu.ocrCloudPlatform.mapper.*
;
import
com.gxmailu.ocrCloudPlatform.vo.BrokenLineData
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
...
...
@@ -46,7 +43,7 @@ public class ElasticSearchService {
private
static
final
Map
<
Character
,
String
>
SPECIAL_CHARACTERS_MAP
=
new
HashMap
<>();
private
static
String
lastIndexTime
=
"2023-11-1
0 00
:00:00"
;
private
static
String
lastIndexTime
=
"2023-11-1
8 07
:00:00"
;
@Resource
private
AppAbilityRecordAllMapper
recordAllMapper
;
...
...
@@ -54,6 +51,10 @@ public class ElasticSearchService {
private
AppAbilityRecord4Mapper
record4Mapper
;
@Resource
private
AppAbilityRecord3Mapper
record3Mapper
;
@Resource
private
AppAbilityRecord5Mapper
record5Mapper
;
@Resource
private
AppAbilityRecord7Mapper
record7Mapper
;
static
{
SPECIAL_CHARACTERS_MAP
.
put
(
'['
,
"\\["
);
...
...
@@ -122,7 +123,7 @@ public class ElasticSearchService {
.
field
(
"callTime"
)
.
gte
(
JsonData
.
of
(
start
.
toString
()))
.
lt
(
JsonData
.
of
(
end
.
toString
()))));
// 法院查询
// 法院
ip前缀
查询
if
(
ObjUtil
.
isNotNull
(
court
)
&&
StrUtil
.
isNotBlank
(
court
.
getIpScope
()))
{
boolQuery
.
must
(
mustQuery
->
mustQuery
.
prefix
(
pq
->
pq
.
field
(
"ip"
).
value
(
court
.
getIpScope
())));
}
...
...
@@ -147,10 +148,15 @@ public class ElasticSearchService {
public
Object
getCourtUseSum
(
List
<
Court
>
courtList
)
{
JSONArray
array
=
new
JSONArray
();
try
{
SearchResponse
<
Void
>
searchResponse
=
client
.
search
(
srBuilder
->
srBuilder
.
index
(
APP_ABILITY_RECORD_INDEX
).
query
(
queryBuilder
->
queryBuilder
.
bool
(
boolQuery
->
{
courtList
.
forEach
(
court
->
boolQuery
.
should
(
q
->
q
.
prefix
(
pq
->
pq
.
field
(
"ip.keyword"
).
value
(
court
.
getIpScope
()))));
return
boolQuery
;
})).
aggregations
(
"count"
,
agg
->
agg
.
terms
(
TermsAggregation
.
of
(
s
->
s
.
field
(
"ip.keyword"
)))).
trackTotalHits
(
tb
->
tb
.
enabled
(
true
)),
Void
.
class
);
SearchResponse
<
Void
>
searchResponse
=
client
.
search
(
srBuilder
->
srBuilder
.
index
(
APP_ABILITY_RECORD_INDEX
)
// 使用bool查询
.
query
(
queryBuilder
->
queryBuilder
.
bool
(
boolQuery
->
{
// 遍历法院列表,对每一个法院ip进行前缀查询
courtList
.
forEach
(
court
->
boolQuery
.
should
(
q
->
q
.
prefix
(
pq
->
pq
.
field
(
"ip.keyword"
).
value
(
court
.
getIpScope
()))));
return
boolQuery
;
// 对ip进行聚合查询
})).
aggregations
(
"count"
,
agg
->
agg
.
terms
(
TermsAggregation
.
of
(
s
->
s
.
field
(
"ip.keyword"
)))).
trackTotalHits
(
tb
->
tb
.
enabled
(
true
)),
Void
.
class
);
StringTermsAggregate
stringTermsAggregate
=
searchResponse
.
aggregations
()
.
get
(
"count"
)
...
...
@@ -198,11 +204,13 @@ public class ElasticSearchService {
try
{
DateTime
finalDateTime
=
dateTime
;
SearchResponse
<
Void
>
search
=
client
.
search
(
srBuilder
->
srBuilder
.
index
(
APP_ABILITY_RECORD_INDEX
).
query
(
queryBuilder
->
queryBuilder
.
bool
(
boolQuery
->
{
// 日期范围查询
boolQuery
.
must
(
q
->
q
.
range
(
rangeQueryBuilder
->
rangeQueryBuilder
.
field
(
"callTime"
)
.
gte
(
JsonData
.
of
(
DateUtil
.
beginOfDay
(
finalDateTime
)))
.
lt
(
JsonData
.
of
(
DateUtil
.
endOfDay
(
finalDateTime
)))));
return
boolQuery
;
// 聚合查询,按每一分钟为间隔查询每分钟的调用量
})).
aggregations
(
"record"
,
agg
->
agg
.
dateHistogram
(
DateHistogramAggregation
.
of
(
s
->
s
.
field
(
"callTime"
)
.
calendarInterval
(
CalendarInterval
.
Minute
)))).
trackTotalHits
(
tb
->
tb
.
enabled
(
true
)),
Void
.
class
);
List
<
DateHistogramBucket
>
bucketList
=
search
.
aggregations
().
get
(
"record"
).
dateHistogram
().
buckets
().
array
();
...
...
@@ -220,14 +228,13 @@ public class ElasticSearchService {
}
@Scheduled
(
fixedDelayString
=
"10000"
)
//
@Scheduled(fixedDelayString = "10000")
private
void
dataImport
()
{
String
startTime
=
lastIndexTime
;
String
endTime
=
""
;
while
(!
DateUtil
.
parse
(
startTime
,
"yyyy-MM-dd HH:mm:ss"
).
after
(
new
Date
()))
{
endTime
=
DateUtil
.
offsetHour
(
DateUtil
.
parse
(
startTime
,
"yyyy-MM-dd HH:mm:ss"
),
2
).
toString
(
"yyyy-MM-dd HH:mm:ss"
);
List
<
AppAbilityRecordAll
>
documentList
=
recordAllMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
AppAbilityRecordAll
.
class
).
between
(
AppAbilityRecordAll:
:
getCallTime
,
startTime
,
endTime
));
// List<AppAbilityRecord3> documentList = record3Mapper.selectList(Wrappers.lambdaQuery(AppAbilityRecord3.class).between(AppAbilityRecord3::getCallTime, startTime, endTime));
documentList
=
documentList
.
stream
().
sorted
(
Comparator
.
comparing
(
AppAbilityRecordAll:
:
getCallTime
)).
collect
(
Collectors
.
toList
());
if
(
CollUtil
.
isNotEmpty
(
documentList
))
{
...
...
src/main/java/com/gxmailu/ocrCloudPlatform/service/impl/ServerInfoServiceImpl.java
View file @
c923d477
...
...
@@ -147,7 +147,8 @@ public class ServerInfoServiceImpl implements ServerInfoService {
// return serverInfoMapper.selectList(new ServerInfo(true));
Object
object
=
redisService
.
getValue
(
"ocrServerList"
);
if
(
object
==
null
)
{
List
<
ServerInfo
>
serverInfos
=
serverInfoMapper
.
selectList
(
new
ServerInfo
(
true
));
List
<
ServerInfo
>
serverInfos
=
serverInfoMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
ServerInfo
.
class
)
.
eq
(
ServerInfo:
:
getAccessService
,
true
));
redisService
.
set
(
"ocrServerList"
,
serverInfos
);
return
serverInfos
;
}
else
{
...
...
@@ -275,15 +276,22 @@ public class ServerInfoServiceImpl implements ServerInfoService {
}
private
void
setServerRedis
()
{
new
Thread
(
new
Runnable
()
{
Thread
newThread
=
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
//修改成功后,查询整个列表并设置进redis
List
<
ServerInfo
>
serverList
=
serverInfoMapper
.
selectList
(
Wrappers
.
lambdaQuery
(
ServerInfo
.
class
)
.
eq
(
ServerInfo:
:
getAccessService
,
true
));
.
eq
(
ServerInfo:
:
getAccessService
,
true
));
redisService
.
set
(
"ocrServerList"
,
serverList
);
}
}).
start
();
});
newThread
.
start
();
// 等待新线程执行完成
try
{
newThread
.
join
();
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"重新设置OCR服务器列表到Redis发生错误:"
,
e
);
}
}
...
...
src/main/resources/application-147prod.yml
View file @
c923d477
...
...
@@ -5,7 +5,7 @@ spring:
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
url
:
jdbc:mysql://147.
2.4.15:4417
/yuntu_ofs?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
initial-size
:
3
# 初始化时建立物理连接的个数
min-idle
:
5
# 最小连接池数量
max-active
:
200
# 最大连接池数量
...
...
@@ -38,21 +38,21 @@ spring:
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
-
147.
2.4.15
:6379
-
147.
2.4.15:6380
-
147.
2.4.16
:6379
-
147.
2.4.16:6380
-
147.
2.4.17
:6379
-
147.
2.4.17:6380
database
:
0
password
:
Docimax
jedis
:
lettuce
:
pool
:
max-active
:
128
max-wait
:
60s
max-idle
:
64
min-idle
:
0
timeout
:
5000
timeout
:
5000
eureka
:
client
:
...
...
src/main/resources/mybatis/mappers/ServerInfoMapper.xml
View file @
c923d477
...
...
@@ -27,7 +27,7 @@
, `name`, ip, ocr_port, username, access_service, created_time,
created_by, updated_time, updated_by,network
</sql>
<select
id=
"selectList"
resultMap=
"BaseResultMap"
parameterType=
"com.gxmailu.ocrCloudPlatform.entity.ServerInfo"
>
<select
id=
"selectList
ByAccessService
"
resultMap=
"BaseResultMap"
parameterType=
"com.gxmailu.ocrCloudPlatform.entity.ServerInfo"
>
select
<include
refid=
"Base_Column_List2"
/>
from server_info
...
...
src/test/java/com/gxmailu/ocrCloudPlatform/RetransmissionServiceTest.java
View file @
c923d477
package
com
.
gxmailu
.
ocrCloudPlatform
;
import
com.gxmailu.ocrCloudPlatform.entity.ServerInfo
;
import
com.gxmailu.ocrCloudPlatform.mapper.ServerInfoMapper
;
import
com.gxmailu.ocrCloudPlatform.service.ServerInfoService
;
import
com.gxmailu.ocrCloudPlatform.service.impl.RedisService
;
import
com.gxmailu.ocrCloudPlatform.service.impl.RetransmissionService
;
import
com.gxmailu.ocrCloudPlatform.vo.Result
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
...
...
@@ -29,9 +29,11 @@ class RetransmissionServiceTest {
@Autowired
private
RetransmissionService
retransmissionService
;
@Autowired
private
ServerInfoMapper
serverInfoMapper
;
@BeforeEach
//
@BeforeEach
void
setUp
()
{
ServerInfo
serverInfo1
=
new
ServerInfo
();
ServerInfo
serverInfo2
=
new
ServerInfo
();
...
...
@@ -125,7 +127,7 @@ class RetransmissionServiceTest {
ServerInfo
serverInfo
=
retransmissionService
.
getServerAddressByRequestCount
();
Thread
thread
=
new
Thread
(()
->
{
try
{
// Thread.sleep(5
00);
Thread
.
sleep
(
10
00
);
retransmissionService
.
addServerRequestCount
(
serverInfo
.
getIp
(),
1
);
// redisService.incr("server-request-task-" + serverInfo.getIp(), 1);
// retransmissionService.setActiveServer(serverInfo.getIp());
...
...
@@ -135,11 +137,21 @@ class RetransmissionServiceTest {
});
thread
.
start
();
thread
.
join
();
//
log.info("线程{}获取到IP: {} 请求量:{}", thread.getName(), serverInfo.getIp(), redisService.getValue("server-request-task-" + serverInfo.getIp()));
log
.
info
(
"线程{}获取到IP: {} 请求量:{}"
,
thread
.
getName
(),
serverInfo
.
getIp
(),
redisService
.
getValue
(
"server-request-task-"
+
serverInfo
.
getIp
()));
}
log
.
info
(
"耗时:{}"
,
System
.
currentTimeMillis
()
-
st
);
serverInfoService
.
getCacheList
().
forEach
(
serverInfo
->
{
log
.
info
(
"IP: {} 请求量:{}"
,
serverInfo
.
getIp
(),
redisService
.
getValue
(
"server-request-task-"
+
serverInfo
.
getIp
()));
});
}
@Test
public
void
updateTest
()
{
ServerInfo
serverInfo
=
new
ServerInfo
();
serverInfo
.
setAccessService
(
true
);
serverInfo
.
setServerId
(
2
);
Result
result
=
serverInfoService
.
updateServer
(
serverInfo
);
System
.
out
.
println
(
result
);
}
}
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