Compare commits

...

4 Commits

Author SHA1 Message Date
yewj 20514d1e76 代码备份 4 months ago
yewj 0b50dafd8e Merge branch 'dev_2.5_scan' into dev_2.5_mutiscan
# Conflicts:
#	src/main/java/com/glxp/api/task/SyncHeartService.java
4 months ago
qiuyt c4d5c0c92c 获取关联关系所有码 4 months ago
chenhc 4ce7bcb950 feat: 同步任务和线程池参数的自定义配置 4 months ago

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

@ -76,7 +76,7 @@ public class IoCollectOrderCodeManController extends BaseController {
* @return
*/
@PostMapping("/udiwms/ioSplit/collect/order/tagCode")
@CusRedissonAnnotation(cacheName = RedissonCacheKey.PRESCRIBE_ADD_CODE, key = {"#addTagCodeReqeust.billNo", "#addTagCodeReqeust.code"},waitTime = 1,leaseTime = 5, timeOutMsg = "扫码重复提交")
@CusRedissonAnnotation(cacheName = RedissonCacheKey.PRESCRIBE_ADD_CODE, key = {"#addTagCodeReqeust.billNo", "#addTagCodeReqeust.code"}, waitTime = 1, leaseTime = 6, timeOutMsg = "扫码重复提交")
public BaseResponse prescribeTagCode(@RequestBody @Valid AddTagCodeReqeust addTagCodeReqeust,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
@ -133,7 +133,7 @@ public class IoCollectOrderCodeManController extends BaseController {
* @return
*/
@PostMapping("/udiwms/ioSplit/collect/order/batchAddCode")
@CusRedissonAnnotation(cacheName = RedissonCacheKey.PRESCRIBE_BATCH_CODE, key = {"#addTagCodeReqeust.prescribeNum", "#addTagCodeReqeust.codeList", "#addTagCodeReqeust.code"}, timeOutMsg = "重复扫码")
@CusRedissonAnnotation(cacheName = RedissonCacheKey.PRESCRIBE_BATCH_CODE, key = {"#addTagCodeReqeust.billNo", "#addTagCodeReqeust.codeList", "#addTagCodeReqeust.code"}, leaseTime = 6, timeOutMsg = "扫码重复提交")
public BaseResponse batchAddCode(@RequestBody @Valid AddTagCodeReqeust addTagCodeReqeust,
BindingResult bindingResult) {
if (bindingResult.hasErrors()) {

@ -151,11 +151,11 @@ public class IoCollectOrderCodeManService extends ServiceImpl<IoCollectOrderCode
SysWorkplaceDocumentEntity sysWorkplaceDocumentEntity = sysWorkplaceDocumentService.findByWorkplaceCode(workPlace.getWorkplaceId(), addTagCodeReqeust.getBusType());
IoCollectOrderBiz collectOrderBiz = null;
IoCollectOrder collectOrder = null;
try {
Thread.sleep(3*1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// try {
// Thread.sleep(3*1000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
//1.校验UDI码完整性
String code = addTagCodeReqeust.getCode();
if (StringUtils.isBlank(code)) throw new JsonException(ResultEnum.DATA_ERROR.getMessage());

@ -149,17 +149,14 @@ public class RelCodeDetailService extends ServiceImpl<RelCodeDetailMapper, RelCo
* @return
*/
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.add(relCodeDetail);
fetchAllChildren(code, list);
if (CollUtil.isEmpty(list)) {
RelCodeDetail relCodeDetail = new RelCodeDetail();
relCodeDetail.setCurCode(code);
list.add(relCodeDetail);
}
return list;
}

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

@ -25,17 +25,20 @@ public class SyncHeartService {
private SyncDataSetDao syncDataSetDao;
public void syncProcess() {
//查询数据同步设置
pushData();
pushOrder();
// pullData();
}
public void pushData() {
SyncDataSetEntity syncDataSetEntity = syncDataSetDao.selectSet();
if (!syncDataSetEntity.isDownstreamEnable()) {
return;
}
//查询数据同步设置
pushData(syncDataSetEntity);
pushOrder(syncDataSetEntity);
pullData(syncDataSetEntity);
}
public void pushData(SyncDataSetEntity syncDataSetEntity) {
//定时上传最近更新基础数据至上游轮询时间
long timeInterval1 = syncDataSetEntity.getSyncTime() * 6 * 1000L;
long curTime1 = System.currentTimeMillis();
@ -48,7 +51,7 @@ public class SyncHeartService {
if (curTime1 - lastTime1 > timeInterval1) {
Arrays.stream(BasicExportTypeEnum.values()).forEach(i -> {
try {
heartService.pushData(syncDataSetEntity, null, i);
heartService.pushData(syncDataSetEntity, null, i);
} catch (Exception e) {
log.error(ExceptionUtils.getStackTrace(e));
e.printStackTrace();
@ -75,11 +78,8 @@ public class SyncHeartService {
});
}
public void pushOrder() {
SyncDataSetEntity syncDataSetEntity = syncDataSetDao.selectSet();
if (!syncDataSetEntity.isDownstreamEnable()) {
return;
}
public void pushOrder(SyncDataSetEntity syncDataSetEntity) {
//定时上传最近更新单据数据至上游轮询时间
long timeInterval2 = syncDataSetEntity.getOrderSyncTime() * 6 * 1000L;
long curTime2 = System.currentTimeMillis();
@ -100,23 +100,43 @@ public class SyncHeartService {
}
}
public void pullData() {
try {
heartService.dlAllOrder();
} catch (Exception e) {
e.printStackTrace();
log.error(ExceptionUtils.getStackTrace(e));
public void pullData(SyncDataSetEntity syncDataSetEntity) {
if (syncDataSetEntity == null) {
syncDataSetEntity = syncDataSetDao.selectSet();
if (!syncDataSetEntity.isDownstreamEnable()) {
return;
}
}
try {
heartService.dlAllDiProducts();
} catch (Exception e) {
e.printStackTrace();
log.error(ExceptionUtils.getStackTrace(e));
//定时下载上游最近更新数据轮询时间
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);
}
Arrays.stream(BasicExportTypeEnum.values()).forEach(i -> {
heartService.pullData(i);
});
redisUtil.set("SPS_SYNC_DOWNLOAD_DATA", System.currentTimeMillis());
if (curTime - lastTime > timeInterval) {
try {
heartService.dlAllOrder();
} 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() {
log.info("数据同步心跳--");
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_LOGO:
#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 # 大流量场景适当延长

@ -5281,6 +5281,8 @@ CALL Pro_Temp_ColumnWork('basic_corp', 'aliEntId',
'varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT ''阿里供应商ID''',
1);
CALL Modify_index('io_order', 'action,invCode', 'idex_order_query', 'BTREE');
CALL Modify_index('io_order', 'mainAction', 'idex_order_query_mainAction', 'BTREE');
@ -5552,4 +5554,15 @@ CREATE TABLE IF NOT EXISTS `inv_product_record` (
INDEX `idx_productId`(`productId` ASC) USING BTREE,
INDEX `idx_orderId`(`orderId` ASC) USING BTREE,
INDEX `idx_createTime`(`createTime` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 8 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '库存流水表' ROW_FORMAT = DYNAMIC;
) ENGINE = InnoDB AUTO_INCREMENT = 8 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '库存流水表' ROW_FORMAT = DYNAMIC;
CALL Pro_Temp_ColumnWork('io_collect_order_origin', 'summaryNo',
'varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT ''汇总单号''',
1);
CALL Pro_Temp_ColumnWork('io_collect_order', 'summaryNo',
'varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT ''汇总单号''',
1);
CALL Pro_Temp_ColumnWork('io_collect_order_backup', 'summaryNo',
'varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT ''汇总单号''',
1);
Loading…
Cancel
Save