Commit c923d477 by 黄明步

修复serverInfoMapper.selectList方法名重复导致更新服务器信息后更新redis失败报错的问题

parent cfe1aaf3
......@@ -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>
......
......@@ -22,7 +22,7 @@ public interface ServerInfoMapper extends BaseMapper<ServerInfo> {
int updateByPrimaryKey(ServerInfo record);
List<ServerInfo> selectList(ServerInfo serverInfo);
List<ServerInfo> selectListByAccessService(ServerInfo serverInfo);
List<ServerInfo> selectListByNetwork(Integer network);
}
......@@ -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-10 00:00:00";
private static String lastIndexTime = "2023-11-18 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,9 +148,14 @@ 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 -> {
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()
......@@ -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)) {
......
......@@ -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);
}
}
......
......@@ -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,15 +38,15 @@ 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
......
......@@ -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="selectListByAccessService" resultMap="BaseResultMap" parameterType="com.gxmailu.ocrCloudPlatform.entity.ServerInfo">
select
<include refid="Base_Column_List2"/>
from server_info
......
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(500);
Thread.sleep(1000);
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);
}
}
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