Commit 1cc273a6 authored by suntao's avatar suntao

将用户名 密码等设置 设置在其中固定测试环境 ka1

parent 5ec65c50
...@@ -2,13 +2,14 @@ package cn.quantgroup.cashloanflowboss.api.role.repository; ...@@ -2,13 +2,14 @@ package cn.quantgroup.cashloanflowboss.api.role.repository;
import cn.quantgroup.cashloanflowboss.api.role.entity.Role; import cn.quantgroup.cashloanflowboss.api.role.entity.Role;
import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowBossDataSource; import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowBossDataSource;
import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowBossPubConfDataSource;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
/** /**
* Created by WeiWei on 2019/7/30. * Created by WeiWei on 2019/7/30.
*/ */
@CashLoanFlowBossDataSource @CashLoanFlowBossPubConfDataSource
@Repository @Repository
public interface RoleRepository extends JpaRepository<Role, Long> { public interface RoleRepository extends JpaRepository<Role, Long> {
} }
...@@ -2,6 +2,7 @@ package cn.quantgroup.cashloanflowboss.api.user.repository; ...@@ -2,6 +2,7 @@ package cn.quantgroup.cashloanflowboss.api.user.repository;
import cn.quantgroup.cashloanflowboss.api.user.entity.User; import cn.quantgroup.cashloanflowboss.api.user.entity.User;
import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowBossDataSource; import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowBossDataSource;
import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowBossPubConfDataSource;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -9,7 +10,7 @@ import org.springframework.stereotype.Repository; ...@@ -9,7 +10,7 @@ import org.springframework.stereotype.Repository;
/** /**
* Created by WeiWei on 2019/7/22. * Created by WeiWei on 2019/7/22.
*/ */
@CashLoanFlowBossDataSource @CashLoanFlowBossPubConfDataSource
@Repository @Repository
public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> { public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
......
package cn.quantgroup.cashloanflowboss.core.configuration.data; package cn.quantgroup.cashloanflowboss.core.configuration.data;
import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowBossPubConfDataSource; import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowBossPubConfDataSource;
import cn.quantgroup.cashloanflowboss.spi.apollo.service.ApolloSettingService;
import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
...@@ -19,12 +20,18 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; ...@@ -19,12 +20,18 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.util.Map;
@Configuration @Configuration
@EnableTransactionManagement @EnableTransactionManagement
@EnableJpaRepositories(basePackages = {"cn.quantgroup"}, entityManagerFactoryRef = "bossEntityManager", transactionManagerRef = "bossTransactionManager", includeFilters = @ComponentScan.Filter(CashLoanFlowBossPubConfDataSource.class)) @EnableJpaRepositories(basePackages = {"cn.quantgroup"}, entityManagerFactoryRef = "bossPubEntityManager", transactionManagerRef = "bossPubTransactionManager", includeFilters = @ComponentScan.Filter(CashLoanFlowBossPubConfDataSource.class))
public class CashLoanFlowBossPubConfDataSourceConfiguration { public class CashLoanFlowBossPubConfDataSourceConfiguration {
@Autowired
private ApolloSettingService apolloSettingService;
private String uniquename = "bossDSPub";
@Value("${data.boss.url}") @Value("${data.boss.url}")
private String jdbcUrl; private String jdbcUrl;
...@@ -34,16 +41,39 @@ public class CashLoanFlowBossPubConfDataSourceConfiguration { ...@@ -34,16 +41,39 @@ public class CashLoanFlowBossPubConfDataSourceConfiguration {
@Value("${data.boss.username}") @Value("${data.boss.username}")
private String user; private String user;
private String uniquename = "bossDSPub"; @Value("${spring.datasource.driverClassName}")
private String driverClassName;
@Value("${boss.user.setting.env}")
private String bossUserSettingEnv;
@Value("${data.boss.pool-size}") @Value("${data.boss.pool-size}")
private Integer poolSize; private Integer poolSize;
//@Primary @Value("${debug.model}")
private Boolean debugModel;
@Bean(name = "bossPubDataSource") @Bean(name = "bossPubDataSource")
@ConfigurationProperties(prefix = "data.boss.pub")
public DataSource createDataSource() { public DataSource createDataSource() {
DruidDataSource source = DruidDataSourceBuilder.create().build(); DruidDataSource source = DruidDataSourceBuilder.create().build();
source.setDriverClassName(driverClassName);
// 测试环境固定ka1 环境,线上环境跟去apollo配置获取
if (debugModel) {
Map<String, Object> paramsFromEOS = apolloSettingService.getParamsFromEOS(bossUserSettingEnv, "DB_SERVICE_HOST", "DB_SERVICE_PORT");
if (MapUtils.isEmpty(paramsFromEOS)) {
throw new RuntimeException("获取boss固定配置数据库失败,bossUserSettingEnv=" + bossUserSettingEnv);
}
String jdbcUrlFormat = "jdbc:mysql://%s:%s/cash_loan_flow_boss?useUnicode=true&characterEncoding=UTF8";
final String testJdbcUrl = String.format(jdbcUrlFormat, paramsFromEOS.get("DB_SERVICE_HOST").toString(), paramsFromEOS.get("DB_SERVICE_PORT").toString());
source.setUrl(testJdbcUrl);
} else {
source.setUrl(jdbcUrl);
}
source.setUsername(user);
source.setPassword(password);
source.setMaxActive(200); source.setMaxActive(200);
source.setMinIdle(10); source.setMinIdle(10);
source.setInitialSize(10); source.setInitialSize(10);
...@@ -58,8 +88,8 @@ public class CashLoanFlowBossPubConfDataSourceConfiguration { ...@@ -58,8 +88,8 @@ public class CashLoanFlowBossPubConfDataSourceConfiguration {
return source; return source;
} }
@Primary
@Bean(name = "bossEntityManager") @Bean(name = "bossPubEntityManager")
public LocalContainerEntityManagerFactoryBean entityManager(EntityManagerFactoryBuilder builder) { public LocalContainerEntityManagerFactoryBean entityManager(EntityManagerFactoryBuilder builder) {
return builder.dataSource(createDataSource()) return builder.dataSource(createDataSource())
...@@ -68,9 +98,9 @@ public class CashLoanFlowBossPubConfDataSourceConfiguration { ...@@ -68,9 +98,9 @@ public class CashLoanFlowBossPubConfDataSourceConfiguration {
.build(); .build();
} }
@Primary
@Bean(name = "bossTransactionManager") @Bean(name = "bossPubTransactionManager")
public PlatformTransactionManager transactionManager(@Qualifier("bossEntityManager") EntityManagerFactory entityManagerFactory) { public PlatformTransactionManager transactionManager(@Qualifier("bossPubEntityManager") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory); return new JpaTransactionManager(entityManagerFactory);
} }
......
...@@ -17,8 +17,8 @@ import java.io.File; ...@@ -17,8 +17,8 @@ import java.io.File;
* *
* @author: suntao * @author: suntao
*/ */
//@Component @Component
public class BossInit {// implements CommandLineRunner { public class BossInit implements CommandLineRunner {
@Value("${data.boss.url}") @Value("${data.boss.url}")
private String url; private String url;
...@@ -29,9 +29,9 @@ public class BossInit {// implements CommandLineRunner { ...@@ -29,9 +29,9 @@ public class BossInit {// implements CommandLineRunner {
@Value("${spring.datasource.driverClassName}") @Value("${spring.datasource.driverClassName}")
private String driverClassName; private String driverClassName;
//
// @Override @Override
// public void run(String... strings) { public void run(String... strings) {
// SQLExec sqlExec; // SQLExec sqlExec;
// try { // try {
// String[] sql = {"/sql/base_data.sql"}; // String[] sql = {"/sql/base_data.sql"};
...@@ -68,5 +68,5 @@ public class BossInit {// implements CommandLineRunner { ...@@ -68,5 +68,5 @@ public class BossInit {// implements CommandLineRunner {
// e.printStackTrace(); // e.printStackTrace();
// return ; // return ;
// } // }
// } }
} }
package cn.quantgroup.cashloanflowboss.spi.apollo.service;
import java.util.Map;
/**
* function:
* date: 2019/10/28
*
* @author: suntao
*/
public interface ApolloSettingService {
Map<String,Object> getParamsFromEOS(String namespace, String... keys);
}
package cn.quantgroup.cashloanflowboss.spi.apollo.service;
import cn.quantgroup.cashloanflowboss.spi.util.HttpService;
import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
/**
* function:
* date: 2019/10/28
*
* @author: suntao
*/
@Slf4j
@Service
public class ApolloSettingServiceImpl implements ApolloSettingService {
@Autowired
private HttpService httpService;
@Value("${eos.ips}")
private String eosIps;
@Override
public Map<String,Object> getParamsFromEOS(String namespace, String... keys){
Map<String, Object> result = new HashedMap(keys.length);
if (keys.length == 0) {
return result;
}
for (String eosIp : eosIps.split(",")) {
String response = null;
try{
Map<String, String> httpParam = new HashMap<>(2);
httpParam.put("namespace", namespace);
response = httpService.get("http://"+eosIp.trim()+"/api/apollo/env_vars", httpParam);
}catch (Exception e){
continue;
}
JSONObject json = JSON.parseObject(response);
if(json == null){
continue;
}
JSONObject details = json.getJSONObject("details");
if(details == null || details.isEmpty()){
continue;
}
for (String key : keys) {
result.put(key,details.get(key));
}
}
log.info("[getParamsFromEOS],result={}", JSONObject.toJSONString(result));
return result;
}
}
...@@ -186,7 +186,7 @@ public class HttpService { ...@@ -186,7 +186,7 @@ public class HttpService {
} }
String method = requestBuilder.getMethod(); String method = requestBuilder.getMethod();
LOGGER.info("{}, uri:[{}], headers:{}, parameters:{}", method, uri, headers, StringUtils.substring(JSONTools.serialize(parameters), 0, 5000)); //LOGGER.info("{}, uri:[{}], headers:{}, parameters:{}", method, uri, headers, StringUtils.substring(JSONTools.serialize(parameters), 0, 5000));
HttpEntity httpEntity = null; HttpEntity httpEntity = null;
CloseableHttpResponse httpResponse = null; CloseableHttpResponse httpResponse = null;
try { try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment