fix:新增平台库数据源

feat:新增账密登录接口
This commit is contained in:
wangff
2025-09-04 14:19:08 +08:00
parent 5d1f424d5b
commit 435b24be48
23 changed files with 562 additions and 4 deletions

View File

@@ -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 {
}

View File

@@ -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();
}
}

View File

@@ -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;
}
}

View File

@@ -62,6 +62,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),

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}