Merge branch 'master' into cc_20251016_async
# Conflicts: # coolstore-partner-common/src/main/java/com/cool/store/executor/MdcTaskExecutor.java # coolstore-partner-service/src/main/java/com/cool/store/service/impl/MessageTemplateServiceImpl.java
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.cool.store.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 平台库数据源
|
||||
*/
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface PlatformDB {
|
||||
}
|
||||
@@ -211,5 +211,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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.cool.store.datasource;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据源上下文
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/9/4
|
||||
*/
|
||||
public class DataSourceContextHolder {
|
||||
private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();
|
||||
|
||||
public static void setDataSourceType(String dataSourceType) {
|
||||
contextHolder.set(dataSourceType);
|
||||
}
|
||||
|
||||
public static String getDataSourceType() {
|
||||
return contextHolder.get();
|
||||
}
|
||||
|
||||
public static void clearDataSourceType() {
|
||||
contextHolder.remove();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.cool.store.datasource;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jdbc.datasource.AbstractDataSource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 动态数据源
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/9/4
|
||||
*/
|
||||
@Component
|
||||
@Primary
|
||||
public class DynamicDataSource extends AbstractDataSource {
|
||||
|
||||
@Autowired
|
||||
private DataSource defaultDataSource;
|
||||
|
||||
@Autowired
|
||||
private DataSource platformDataSource;
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
DataSource currentDB = getCurrentDB();
|
||||
return currentDB.getConnection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection(String username, String password) throws SQLException {
|
||||
DataSource currentDB = getCurrentDB();
|
||||
Connection connection = currentDB.getConnection(username, password);
|
||||
connection.setCatalog(DataSourceContextHolder.getDataSourceType());
|
||||
return connection;
|
||||
}
|
||||
|
||||
protected DataSource getCurrentDB() {
|
||||
String dbName = DataSourceContextHolder.getDataSourceType();
|
||||
if (StringUtils.isBlank(dbName)) {
|
||||
return defaultDataSource;
|
||||
}
|
||||
return platformDataSource;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,6 +40,7 @@ public enum ErrorCodeEnum {
|
||||
LOGIN_ERROR(400004, "登录失败", null),
|
||||
ENTERPRISE_INIT(400006, "企业正在初始化,请稍后访问!",null),
|
||||
NOT_AUTH(400007, "暂无权限,请联系管理员!", null),
|
||||
REFRESH_TOKEN_INVALID(400008, "refresh token invalid", null),
|
||||
USER_FREEZE(1021019,"账号被冻结,请联系管理员",null),
|
||||
ENTERPRISE_NOT_EXIST(1021020,"企业不存在",null),
|
||||
USER_NOT_EXIST(1021021,"用户不存在",null),
|
||||
@@ -62,6 +63,11 @@ public enum ErrorCodeEnum {
|
||||
DATA_CONVERT_ERROR(400002, "日期转换异常!", null),
|
||||
PARENT_NODE_NOT_EXIST(400002, "父节点不存在", null),
|
||||
LOGIN_ERROR_MOBILE_ERROR(418, "登录失败 获取手机号失败!!", null),
|
||||
PASSWORD_ERROR_MAX_COUNT(1021084, "密码错误{0}次,今日账号已锁定",null),
|
||||
PASSWORD_MISSING(1021085, "密码不能为空!",null),
|
||||
IMPROVE_USER_INFO(1021086,"请联系管理员,完善用户信息!",null),
|
||||
PASSWORD_ERROR(1021087, "密码输入错误",null),
|
||||
PASSWORD_ERROR_MULTI(1021088, "密码错误{0}次,请使用验证码登录",null),
|
||||
//红圈通
|
||||
HQT_SHOP_DECORATION_ATTRIBUTES(1022000, "获取红圈通装修属性错误", null),
|
||||
HQT_PARAMS_ERROR(1022001, "构建红圈通请求参数错误", null),
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.cool.store.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 登录类型 枚举类
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/9/4
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum LoginTypeEnum {
|
||||
|
||||
PASSWORD("账号密码", "passwordLoginServiceImpl"),
|
||||
|
||||
;
|
||||
|
||||
private final String message;
|
||||
|
||||
private final String clazzName;
|
||||
}
|
||||
@@ -14,6 +14,7 @@ public enum MatterTypeEnum {
|
||||
SERVICE_PACKAGE(4,"服务包"),
|
||||
RESTOCK(5,"补货"),
|
||||
INVENTORY(6,"盘点"),
|
||||
REALTIME(7, "即时消息"),
|
||||
;
|
||||
|
||||
MatterTypeEnum(Integer code, String message) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -18,6 +18,7 @@ public enum SceneEnum {
|
||||
RESTOCK(35, "补货", "", MatterTypeEnum.LOGISTICS),
|
||||
INVENTORY(40, "盘点", "", MatterTypeEnum.LOGISTICS),
|
||||
|
||||
REALTIME(45, "即时消息", "", MatterTypeEnum.REALTIME),
|
||||
;
|
||||
|
||||
private Integer sceneCode;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* bean转换工具
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/3/6
|
||||
*/
|
||||
public class BeanUtil extends cn.hutool.core.bean.BeanUtil {
|
||||
|
||||
public static <T, R> List<R> toList(List<T> list, Class<R> clazz) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<R> result = new ArrayList<>(list.size());
|
||||
for (T t : list) {
|
||||
R r = toBean(t, clazz);
|
||||
result.add(r);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static <T, R> PageInfo<R> toPage(PageInfo<T> page, Class<R> clazz) {
|
||||
PageInfo<R> newPage = new PageInfo<>();
|
||||
newPage.setPages(page.getPages());
|
||||
newPage.setTotal(page.getTotal());
|
||||
newPage.setPageNum(page.getPageNum());
|
||||
newPage.setPageSize(page.getPageSize());
|
||||
List<R> list = toList(page.getList(), clazz);
|
||||
newPage.setList(list);
|
||||
return newPage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Spring上下文工具
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/9/4
|
||||
*/
|
||||
@Component
|
||||
public class SpringContextUtil implements ApplicationContextAware {
|
||||
private static ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
SpringContextUtil.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取bean
|
||||
* @param name beanName
|
||||
* @param clazz bean类型
|
||||
* @return bean
|
||||
*/
|
||||
public static <T> T getBean(String name, Class<T> clazz) {
|
||||
return applicationContext.getBean(name, clazz);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user