change - 添加获取用户数据源API接口
parent
7983b99959
commit
4d7e4aae1a
@ -0,0 +1,40 @@
|
||||
package com.mesnac.ems.config;
|
||||
|
||||
import com.baomidou.dynamic.datasource.creator.DataSourceProperty;
|
||||
import com.mesnac.common.core.constant.SecurityConstants;
|
||||
import com.mesnac.common.core.domain.R;
|
||||
import com.mesnac.common.datasource.creator.DynamicDatasourceCreator;
|
||||
import com.mesnac.system.api.RemoteUserService;
|
||||
import com.mesnac.system.api.domain.SysUser;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class DynamicDatasource {
|
||||
@Resource
|
||||
private DynamicDatasourceCreator dynamicDatasourceCreator;
|
||||
|
||||
@Resource
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setUserId(1L);
|
||||
R<List<Map<String, String>>> dateSources = remoteUserService.getPoolNameList(sysUser, SecurityConstants.INNER);
|
||||
for (Map<String, String> dateSource : dateSources.getData()) {
|
||||
DataSourceProperty sdp = new DataSourceProperty();
|
||||
sdp.setUrl(dateSource.get("url"));
|
||||
sdp.setUsername(dateSource.get("userName"));
|
||||
sdp.setPassword(dateSource.get("password"));
|
||||
sdp.setDriverClassName(dateSource.get("driveClassName"));
|
||||
sdp.setPoolName(dateSource.get("poolName"));// 这是数据源的key
|
||||
sdp.setLazy(false);
|
||||
dynamicDatasourceCreator.createDynamicDataSource(sdp);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue