init
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.cool.store.service;
|
||||
|
||||
|
||||
import com.cool.store.model.entity.EnterpriseConfigDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface EnterpriseConfigService {
|
||||
|
||||
EnterpriseConfigDO selectByEnterpriseId(String enterpriseId);
|
||||
|
||||
/**
|
||||
* 根据dbName获取dbServer
|
||||
* @param dbName
|
||||
* @return
|
||||
*/
|
||||
EnterpriseConfigDO getDbInfoByDbName(String dbName);
|
||||
|
||||
/**
|
||||
* 获取dbServer
|
||||
* @return
|
||||
*/
|
||||
List<EnterpriseConfigDO> getDistinctDbServer();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.cool.store.service.config.redis;
|
||||
|
||||
import com.cool.store.model.utils.RedisUtilPool;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
import redis.clients.jedis.ShardedJedisPool;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName RedisUtilConfig
|
||||
* @Description 用一句话描述什么
|
||||
*/
|
||||
@Component
|
||||
public class RedisUtilConfig {
|
||||
|
||||
@Value("${redis.host.uri}")
|
||||
private String REDIS_HOST_URI;
|
||||
|
||||
@Bean
|
||||
public RedisUtilPool redisUtilPool() {
|
||||
|
||||
RedisUtilPool redisUtil = new RedisUtilPool();
|
||||
|
||||
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
||||
jedisPoolConfig.setMaxTotal(1024);
|
||||
jedisPoolConfig.setMaxIdle(200);
|
||||
jedisPoolConfig.setMaxWaitMillis(1000);
|
||||
jedisPoolConfig.setTestOnBorrow(false);
|
||||
|
||||
List<JedisShardInfo> shards = new ArrayList<>();
|
||||
JedisShardInfo jedisShardInfo = new JedisShardInfo(REDIS_HOST_URI);
|
||||
shards.add(jedisShardInfo);
|
||||
redisUtil.setShardedJedisPool(new ShardedJedisPool(jedisPoolConfig, shards));
|
||||
return redisUtil;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.cool.store.service.context;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
@Data
|
||||
public class CurrentUser {
|
||||
|
||||
private String userId;
|
||||
|
||||
private String enterpriseId;
|
||||
|
||||
private String dingCorpId;
|
||||
|
||||
private String appType;
|
||||
|
||||
private String accessToken;
|
||||
|
||||
/**
|
||||
* 员工角色
|
||||
*/
|
||||
private String roleIds;
|
||||
|
||||
private String dbName;
|
||||
|
||||
/**
|
||||
* 钉钉管理员和数智门店无关
|
||||
*/
|
||||
private Boolean isAdmin;
|
||||
|
||||
/**
|
||||
* 角色权限
|
||||
*/
|
||||
private String roleAuth;
|
||||
|
||||
private String mainCorpId;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.cool.store.service.context;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DataSourceContext {
|
||||
|
||||
private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();
|
||||
|
||||
private static List<String> dataSourceIds = new ArrayList<>();
|
||||
|
||||
public static void setDataSourceType(String dataSourceType) {
|
||||
CONTEXT_HOLDER.set(dataSourceType);
|
||||
}
|
||||
|
||||
public static String getDataSourceType() {
|
||||
return CONTEXT_HOLDER.get();
|
||||
}
|
||||
|
||||
public static void clearDataSourceType() {
|
||||
CONTEXT_HOLDER.remove();
|
||||
}
|
||||
|
||||
public static boolean containsDataSource(String dsId) {
|
||||
return dataSourceIds.contains(dsId);
|
||||
}
|
||||
|
||||
public static void setDataSourceIds(List<String> dids){
|
||||
dataSourceIds = dids;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.cool.store.service.context;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class UserContext {
|
||||
|
||||
private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();
|
||||
|
||||
public static CurrentUser getUser() {
|
||||
String userStr = contextHolder.get();
|
||||
if (StringUtils.isNotBlank(userStr)) {
|
||||
return JSON.parseObject(userStr, CurrentUser.class);
|
||||
}
|
||||
return new CurrentUser();
|
||||
}
|
||||
|
||||
public static void setUser(String user) {
|
||||
contextHolder.set(user);
|
||||
}
|
||||
|
||||
public static void removeUser(){
|
||||
contextHolder.remove();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.cool.store.service.impl;
|
||||
|
||||
import com.cool.store.dao.EnterpriseConfigDAO;
|
||||
import com.cool.store.model.entity.EnterpriseConfigDO;
|
||||
import com.cool.store.service.EnterpriseConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName EnterpriseConfigServiceImpl
|
||||
* @Description 用一句话描述什么
|
||||
*/
|
||||
@Service(value = "enterpriseConfigService")
|
||||
@Slf4j
|
||||
public class EnterpriseConfigServiceImpl implements EnterpriseConfigService {
|
||||
|
||||
@Resource
|
||||
private EnterpriseConfigDAO enterpriseConfigDAO;
|
||||
|
||||
@Override
|
||||
public EnterpriseConfigDO selectByEnterpriseId(String enterpriseId) {
|
||||
return enterpriseConfigDAO.selectByEnterpriseId(enterpriseId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnterpriseConfigDO getDbInfoByDbName(String dbName) {
|
||||
return enterpriseConfigDAO.getDbInfoByDbName(dbName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EnterpriseConfigDO> getDistinctDbServer() {
|
||||
return enterpriseConfigDAO.getDistinctDbServer();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.cool.store.service.utils;
|
||||
|
||||
import com.cool.store.service.context.DataSourceContext;
|
||||
import com.cool.store.service.context.UserContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Slf4j
|
||||
public class DataSourceHelper {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataSourceHelper.class);
|
||||
|
||||
/**
|
||||
* @param
|
||||
* @return void
|
||||
* @throws
|
||||
* @Title changeToMy
|
||||
* @Description 切换到自己的数据库
|
||||
*/
|
||||
public static void changeToMy() {
|
||||
DataSourceContext.clearDataSourceType();
|
||||
String dbName = UserContext.getUser().getDbName();
|
||||
DataSourceContext.setDataSourceType(dbName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param datasource
|
||||
* @return void
|
||||
* @throws
|
||||
* @Title changeToSpecificDataSource
|
||||
* @Description 切换到指定的数据库
|
||||
*/
|
||||
public static void changeToSpecificDataSource(String datasource) {
|
||||
DataSourceContext.clearDataSourceType();
|
||||
String dbName = datasource;
|
||||
DataSourceContext.setDataSourceType(dbName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param
|
||||
* @return void
|
||||
* @throws
|
||||
* @Title reset
|
||||
* @Description 重置链接到主库
|
||||
*/
|
||||
public static void reset() {
|
||||
DataSourceContext.clearDataSourceType();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user