package com.changhong.epc.config.datasource;
|
|
import com.changhong.epc.constter.system.DataSourceKey;
|
import com.iemsoft.framework.cloud.config.mybatis.MapperConfig;
|
import com.iemsoft.framework.cloud.core.thread.Keys;
|
import com.iemsoft.framework.cloud.core.thread.ThreadData;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.ibatis.mapping.MappedStatement;
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.core.env.Environment;
|
import tk.mybatis.spring.mapper.MapperScannerConfigurer;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
@Configuration
|
@AutoConfigureAfter(DataSourceConfig.class)
|
@Slf4j
|
public class MybatisConfig extends MapperConfig implements DataSourceKey{
|
|
/**
|
* 多数据源改成单数据源
|
* @author WangYX
|
*
|
*/
|
private static Map<String, String> DATA_SOURCE = new HashMap<>();
|
|
static{
|
DATA_SOURCE.put("^com[.]changhong[.]epc[.][^.]+[.]mapper[.]centen.+", ADMIN_DATA_SOURCE);
|
}
|
|
private static void setDataSource(MappedStatement ms, String id) {
|
for(Map.Entry<String, String> entry : DATA_SOURCE.entrySet()){
|
if(id.matches(entry.getKey())){
|
ThreadData.set(Keys.DATA_SOURCE, entry.getValue());
|
break;
|
}
|
}
|
}
|
|
@Override
|
public MapperScannerConfigurer mapperScannerConfigurer(Environment environment) {
|
log.debug(environment.getProperty(getBasePackageKey()));
|
return super.mapperScannerConfigurer(environment);
|
}
|
|
}
|