fix:即时通知通过STOMP下发

This commit is contained in:
wangff
2025-09-08 14:00:48 +08:00
parent eacc3c6f8d
commit d8cbb78c5d
19 changed files with 390 additions and 33 deletions

View File

@@ -201,5 +201,23 @@ public class CommonConstants {
public static final String WX_SELF_AUTH_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
/**
* 密码最大错误次数
*/
public static final int MAX_ERROR_PASSWORD_COUNT = 5;
/**
* 用户密码
*/
public static final String USER_AUTH_KEY = "user_auth_key";
/**
* accessToken有效期单位秒
*/
public static final int ACTION_TOKEN_EXPIRE = 24 * 60 * 60;
/**
* refreshToken有效期单位秒
*/
public static final int REFRESH_TOKEN_EXPIRE = 30 * 24 * 60 * 60;
}

View File

@@ -14,6 +14,7 @@ public enum MatterTypeEnum {
SERVICE_PACKAGE(4,"服务包"),
RESTOCK(5,"补货"),
INVENTORY(6,"盘点"),
REALTIME(7, "即时消息"),
;
MatterTypeEnum(Integer code, String message) {

View File

@@ -16,7 +16,7 @@ public enum ModuleCodeEnum {
DISH(3,"菜品",Arrays.asList(MatterTypeEnum.NOTICE)),
FRANCHISE(4,"加盟",Arrays.asList(MatterTypeEnum.NOTICE)),
//其他(投诉与客户服务、临时通知)
OTHER(5,"其他",Arrays.asList(MatterTypeEnum.NOTICE)),
OTHER(5,"其他",Arrays.asList(MatterTypeEnum.NOTICE, MatterTypeEnum.REALTIME)),
;
ModuleCodeEnum(Integer code, String message,List<MatterTypeEnum> matterTypeEnums) {

View File

@@ -18,6 +18,7 @@ public enum SceneEnum {
RESTOCK(35, "补货", "", MatterTypeEnum.LOGISTICS),
INVENTORY(40, "盘点", "", MatterTypeEnum.LOGISTICS),
REALTIME(45, "即时消息", "", MatterTypeEnum.REALTIME),
;
private Integer sceneCode;

View File

@@ -0,0 +1,96 @@
package com.cool.store.executor;
import com.cool.store.constants.CommonConstants;
import com.cool.store.utils.UUIDUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
/**
* @author zhangchenbiao
* @FileName: MdcTaskExecutor
* @Description:
* @date 2021-11-02 21:00
*/
public class MdcTaskExecutor extends ThreadPoolTaskExecutor {
private Logger log = LoggerFactory.getLogger(MdcTaskExecutor.class);
@Override
public <T> Future<T> submit(Callable<T> task) {
Map<String, String> context = MDC.getCopyOfContextMap();
return super.submit(() -> {
T result;
if (context != null) {
//将父线程的MDC内容传给子线程
MDC.setContextMap(context);
}
//直接给子线程设置MDC
setTraceIdIfAbsent();
try {
//执行任务
result = task.call();
} finally {
log.info("ThreadMonitor:{}info:ExecutedTasks->{},totalTask->{}, RunningTasks->{}, PendingTasks->{},corePoolSize-{},currentPoolSize->{},LargestPoolSize->{}",
this.getThreadNamePrefix(),this.getThreadPoolExecutor().getCompletedTaskCount(),this.getThreadPoolExecutor().getTaskCount(),
this.getActiveCount(),this.getThreadPoolExecutor().getQueue().size(),this.getCorePoolSize(),
this.getPoolSize(),this.getThreadPoolExecutor().getLargestPoolSize());
try {
MDC.clear();
} catch (Exception e) {
log.warn("MDC clear exception", e);
}
}
return result;
});
}
@Override
public void execute(Runnable task) {
log.info("mdc thread pool task executor execute");
Map<String, String> context = MDC.getCopyOfContextMap();
super.execute(() -> {
if (context != null) {
//将父线程的MDC内容传给子线程
MDC.setContextMap(context);
}
//直接给子线程设置MDC
setTraceIdIfAbsent();
try {
//执行任务
task.run();
} finally {
log.info("ThreadMonitor:{}info:ExecutedTasks->{},totalTask->{}, RunningTasks->{}, PendingTasks->{},corePoolSize-{},currentPoolSize->{},LargestPoolSize->{}",
this.getThreadNamePrefix(),this.getThreadPoolExecutor().getCompletedTaskCount(),this.getThreadPoolExecutor().getTaskCount(),
this.getActiveCount(),this.getThreadPoolExecutor().getQueue().size(),this.getCorePoolSize(),
this.getPoolSize(),this.getThreadPoolExecutor().getLargestPoolSize());
try {
MDC.clear();
} catch (Exception e) {
log.warn("MDC clear exception", e);
}
}
});
}
public static void setTraceIdIfAbsent() {
String key = CommonConstants.REQUEST_ID;
String value = UUIDUtils.get32UUID();
String k = MDC.get(key);
if (StringUtils.isBlank(value)) {
value = UUID.randomUUID().toString().replace("-", "");
}
if (StringUtils.isBlank(k)) {
MDC.put(key, value);
}
}
}

View File

@@ -0,0 +1,45 @@
package com.cool.store.executor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ThreadPoolExecutor;
/**
* <p>
* 线程池配置类
* </p>
*
* @author wangff
* @since 2025/9/5
*/
@Configuration
public class ThreadPoolTaskConfig {
/**
* 通用线程池
*/
@Bean
public TaskExecutor generalThreadPool() {
int cores = Runtime.getRuntime().availableProcessors();
ThreadPoolTaskExecutor executor = new MdcTaskExecutor();
// 核心线程数目
executor.setCorePoolSize(cores*2);
// 指定最大线程数
executor.setMaxPoolSize(200);
// 队列中最大的数目
executor.setQueueCapacity(5000);
// 线程名称前缀
executor.setThreadNamePrefix("generalThreadPool_");
// 对拒绝task的处理策略
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// 线程空闲后的最大存活时间
executor.setKeepAliveSeconds(60);
// 加载
executor.initialize();
return executor;
}
}