Merge branch 'dev_2.5_scan' into dev_2.5_mutiscan

# Conflicts:
#	src/main/java/com/glxp/api/task/SyncHeartService.java
dev_2.5_csconfilt
yewj 3 months ago
commit 0b50dafd8e

@ -1,5 +1,6 @@
package com.glxp.api.config; package com.glxp.api.config;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
@ -11,30 +12,65 @@ import java.util.concurrent.ThreadPoolExecutor;
/** /**
* 线 * 线
*/ */
@Configuration
@EnableAsync @EnableAsync
@Configuration
@EnableConfigurationProperties(ThreadPoolConfigProperties.class)
public class TaskPoolConfig { public class TaskPoolConfig {
// @Bean(name = "taskExecutor")
// @Primary
// public ThreadPoolTaskExecutor taskExecutor() {
// // 获取当前主机的cpu核心数
// int threadCount = Runtime.getRuntime().availableProcessors();
// ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
// //核心池的大小
// taskExecutor.setCorePoolSize(threadCount);
// //线程池最大线程数
// taskExecutor.setMaxPoolSize(threadCount * 2);
// //队列最大长度
// taskExecutor.setQueueCapacity(200);
// //线程空闲时间
// taskExecutor.setKeepAliveSeconds(60);
// //配置线程前缀
// taskExecutor.setThreadNamePrefix("custom_executor");
// //配置拒绝策略
// taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// //执行初始化
// taskExecutor.initialize();
// return taskExecutor;
// }
@Bean(name = "taskExecutor") @Bean(name = "taskExecutor")
@Primary @Primary
public ThreadPoolTaskExecutor taskExecutor() { public ThreadPoolTaskExecutor taskExecutor(ThreadPoolConfigProperties properties) {
// 获取当前主机的cpu核心数 // 动态获取CPU核心数
int threadCount = Runtime.getRuntime().availableProcessors(); final int cpuCores = Runtime.getRuntime().availableProcessors();
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
//核心池的大小 // 核心线程数配置优先默认CPU核心数
taskExecutor.setCorePoolSize(threadCount); taskExecutor.setCorePoolSize(
//线程池最大线程数 properties.getCorePoolSize() != null ?
taskExecutor.setMaxPoolSize(threadCount * 2); properties.getCorePoolSize() : cpuCores
//队列最大长度 );
taskExecutor.setQueueCapacity(200);
//线程空闲时间 // 最大线程数配置优先默认CPU核心数*2
taskExecutor.setKeepAliveSeconds(60); taskExecutor.setMaxPoolSize(
//配置线程前缀 properties.getMaxPoolSize() != null ?
taskExecutor.setThreadNamePrefix("custom_executor"); properties.getMaxPoolSize() : cpuCores * 2
//配置拒绝策略 );
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
//执行初始化 // 其他固定配置项
taskExecutor.setQueueCapacity(properties.getQueueCapacity());
taskExecutor.setKeepAliveSeconds(properties.getKeepAliveSeconds());
taskExecutor.setThreadNamePrefix(properties.getThreadNamePrefix());
// 拒绝策略保持原样
taskExecutor.setRejectedExecutionHandler(
new ThreadPoolExecutor.CallerRunsPolicy()
);
taskExecutor.initialize(); taskExecutor.initialize();
return taskExecutor; return taskExecutor;
} }
} }

@ -0,0 +1,36 @@
package com.glxp.api.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
// 1. 创建配置类建议放在config包下
@ConfigurationProperties(prefix = "thread.pool")
@Data
public class ThreadPoolConfigProperties {
/**
* 线CPU
*/
private Integer corePoolSize;
/**
* 线CPU*2
*/
private Integer maxPoolSize;
/**
* 200
*/
private int queueCapacity = 200;
/**
* 线60
*/
private int keepAliveSeconds = 60;
/**
* 线"custom_executor_"
*/
private String threadNamePrefix = "custom_executor_";
}

@ -149,17 +149,14 @@ public class RelCodeDetailService extends ServiceImpl<RelCodeDetailMapper, RelCo
* @return * @return
*/ */
public List<RelCodeDetail> getAllNext(String code) { public List<RelCodeDetail> getAllNext(String code) {
RelCodeDetail relCodeDetail = this.baseMapper.selectOne(
new LambdaQueryWrapper<RelCodeDetail>().eq(RelCodeDetail::getCurCode, code)
);
if(Objects.isNull(relCodeDetail)){
relCodeDetail = new RelCodeDetail();
relCodeDetail.setCurCode(code);
}
List<RelCodeDetail> list = new ArrayList<>(); List<RelCodeDetail> list = new ArrayList<>();
list.add(relCodeDetail);
fetchAllChildren(code, list); fetchAllChildren(code, list);
if (CollUtil.isEmpty(list)) {
RelCodeDetail relCodeDetail = new RelCodeDetail();
relCodeDetail.setCurCode(code);
list.add(relCodeDetail);
}
return list; return list;
} }

@ -65,7 +65,7 @@ public class WebSocketComponent implements CommandLineRunner {
} }
} }
if (message.equals(SocketMsgType.DL_ALL_DATA)) { if (message.equals(SocketMsgType.DL_ALL_DATA)) {
heartTaskService.pullData(); heartTaskService.pullData(null);
} }
if (message.contains(SocketMsgType.STAT_DATA)) { if (message.contains(SocketMsgType.STAT_DATA)) {
cn.hutool.json.JSONObject obj = JSONUtil.parseObj(message); cn.hutool.json.JSONObject obj = JSONUtil.parseObj(message);

@ -25,17 +25,20 @@ public class SyncHeartService {
private SyncDataSetDao syncDataSetDao; private SyncDataSetDao syncDataSetDao;
public void syncProcess() { public void syncProcess() {
//查询数据同步设置
pushData();
pushOrder();
// pullData();
}
public void pushData() {
SyncDataSetEntity syncDataSetEntity = syncDataSetDao.selectSet(); SyncDataSetEntity syncDataSetEntity = syncDataSetDao.selectSet();
if (!syncDataSetEntity.isDownstreamEnable()) { if (!syncDataSetEntity.isDownstreamEnable()) {
return; return;
} }
//查询数据同步设置
pushData(syncDataSetEntity);
pushOrder(syncDataSetEntity);
pullData(syncDataSetEntity);
}
public void pushData(SyncDataSetEntity syncDataSetEntity) {
//定时上传最近更新基础数据至上游轮询时间 //定时上传最近更新基础数据至上游轮询时间
long timeInterval1 = syncDataSetEntity.getSyncTime() * 6 * 1000L; long timeInterval1 = syncDataSetEntity.getSyncTime() * 6 * 1000L;
long curTime1 = System.currentTimeMillis(); long curTime1 = System.currentTimeMillis();
@ -100,23 +103,43 @@ public class SyncHeartService {
} }
} }
public void pullData() { public void pullData(SyncDataSetEntity syncDataSetEntity) {
try {
heartService.dlAllOrder(); if (syncDataSetEntity == null) {
} catch (Exception e) { syncDataSetEntity = syncDataSetDao.selectSet();
e.printStackTrace(); if (!syncDataSetEntity.isDownstreamEnable()) {
log.error(ExceptionUtils.getStackTrace(e)); return;
}
} }
try {
heartService.dlAllDiProducts(); //定时下载上游最近更新数据轮询时间
} catch (Exception e) { long timeInterval = syncDataSetEntity.getSyncDownloadTime() * 6 * 100;
e.printStackTrace(); long curTime = System.currentTimeMillis();
log.error(ExceptionUtils.getStackTrace(e)); Long lastTime = (Long) redisUtil.get("SPS_SYNC_DOWNLOAD_DATA");
if (lastTime == null) {
lastTime = System.currentTimeMillis();
redisUtil.set("SPS_SYNC_DOWNLOAD_DATA", lastTime);
} }
Arrays.stream(BasicExportTypeEnum.values()).forEach(i -> { if (curTime - lastTime > timeInterval) {
heartService.pullData(i); try {
}); heartService.dlAllOrder();
redisUtil.set("SPS_SYNC_DOWNLOAD_DATA", System.currentTimeMillis()); } catch (Exception e) {
e.printStackTrace();
log.error(ExceptionUtils.getStackTrace(e));
}
try {
heartService.dlAllDiProducts();
} catch (Exception e) {
e.printStackTrace();
log.error(ExceptionUtils.getStackTrace(e));
}
Arrays.stream(BasicExportTypeEnum.values()).forEach(i -> {
heartService.pullData(i);
});
redisUtil.set("SPS_SYNC_DOWNLOAD_DATA", System.currentTimeMillis());
}
} }
} }

@ -50,26 +50,7 @@ public class SyncHeartTask implements SchedulingConfigurer {
private void process() { private void process() {
log.info("数据同步心跳--");
syncHeartService.syncProcess(); syncHeartService.syncProcess();
SyncDataSetEntity syncDataSetEntity = syncDataSetDao.selectSet();
if (!syncDataSetEntity.isDownstreamEnable()) {
return;
}
//定时下载上游最近更新数据轮询时间
long timeInterval = syncDataSetEntity.getSyncDownloadTime() * 6 * 100;
long curTime = System.currentTimeMillis();
Long lastTime = (Long) redisUtil.get("SPS_SYNC_DOWNLOAD_DATA");
if (lastTime == null) {
lastTime = System.currentTimeMillis();
redisUtil.set("SPS_SYNC_DOWNLOAD_DATA", lastTime);
}
if (curTime - lastTime > timeInterval) {
syncHeartService.pullData();
}
} }

@ -41,3 +41,13 @@ WEB_SUB_TITLE: 医院UDI管理系统
WEB_VERSION: WEB_VERSION:
WEB_LOGO: WEB_LOGO:
#http://127.0.0.1:9991/udiwms/image/getImage?type=image1&name=dima.jpg #http://127.0.0.1:9991/udiwms/image/getImage?type=image1&name=dima.jpg
# 生产环境推荐配置8核CPU示例
thread:
pool:
core-pool-size: 8 # 与CPU核心一致
max-pool-size: 16 # 核心数*2
queue-capacity: 1000 # 根据业务负载调整
keep-alive-seconds: 160 # 大流量场景适当延长

Loading…
Cancel
Save