企业同步
This commit is contained in:
@@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.jdbc.datasource.AbstractDataSource;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -27,10 +28,13 @@ public class DynamicDataSource extends AbstractDataSource {
|
||||
@Autowired
|
||||
private DynamicDataSourceServiceImpl dynamicDataSourceService;
|
||||
|
||||
@Value("${default.database.name:coolcollege_intelligent_config}")
|
||||
private String defaultDb;
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
String currentDbName = getCurrentDbName();
|
||||
if(CommonConstants.DEFAULT_DB.equals(currentDbName)){
|
||||
if(defaultDb.equals(currentDbName)){
|
||||
Connection connection = defaultDataSource.getConnection();
|
||||
connection.setCatalog(currentDbName);
|
||||
return connection;
|
||||
@@ -43,7 +47,7 @@ public class DynamicDataSource extends AbstractDataSource {
|
||||
@Override
|
||||
public Connection getConnection(String username, String password) throws SQLException {
|
||||
String currentDbName = getCurrentDbName();
|
||||
if(CommonConstants.DEFAULT_DB.equals(currentDbName)){
|
||||
if(defaultDb.equals(currentDbName)){
|
||||
Connection connection = defaultDataSource.getConnection();
|
||||
connection.setCatalog(currentDbName);
|
||||
return connection;
|
||||
@@ -97,7 +101,7 @@ public class DynamicDataSource extends AbstractDataSource {
|
||||
protected String getCurrentDbName() {
|
||||
String dbName = DataSourceContext.getDataSourceType();
|
||||
if (StringUtils.isBlank(dbName)) {
|
||||
dbName = CommonConstants.DEFAULT_DB;
|
||||
dbName = defaultDb;
|
||||
}
|
||||
return dbName;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.zaxxer.hikari.HikariDataSource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
@@ -33,17 +34,16 @@ public class DynamicDataSourceServiceImpl {
|
||||
|
||||
private static int defaultMaxPoolSize = 150;
|
||||
|
||||
private static String dbUrl = "jdbc:mysql://{0}:{1}/coolcollege_intelligent_config?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true";
|
||||
private static String dbUrl = "jdbc:mysql://{0}:{1}/{2}?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true";
|
||||
|
||||
@Autowired
|
||||
private RedisUtilPool redisUtilPool;
|
||||
|
||||
@Autowired
|
||||
private MyHikariConfig myHikariConfig;
|
||||
|
||||
@Autowired
|
||||
private EnterpriseConfigService enterpriseConfigService;
|
||||
|
||||
@Value("${default.database.name:coolcollege_intelligent_config}")
|
||||
private String defaultDb;
|
||||
/**
|
||||
* 数据库实例和数据源的映射
|
||||
*/
|
||||
@@ -71,7 +71,7 @@ public class DynamicDataSourceServiceImpl {
|
||||
* @return
|
||||
*/
|
||||
public String getDbServerByDbName(String dbName) {
|
||||
if(CommonConstants.DEFAULT_DB.equals(dbName)){
|
||||
if(defaultDb.equals(dbName)){
|
||||
return null;
|
||||
}
|
||||
String dbServerUrl = dbNameUrlServerMap.get(dbName);
|
||||
@@ -115,7 +115,7 @@ public class DynamicDataSourceServiceImpl {
|
||||
*/
|
||||
private DataSource buildDataSourceByConfig(DatasourceInfoDTO datasource) {
|
||||
HikariConfig hikariConfig = new HikariConfig();
|
||||
String url = MessageFormat.format(dbUrl, datasource.getDbServer(), String.valueOf(datasource.getDbPort()));
|
||||
String url = MessageFormat.format(dbUrl, datasource.getDbServer(), String.valueOf(datasource.getDbPort()), datasource.getDbName());
|
||||
hikariConfig.setDriverClassName(myHikariConfig.getDriverClassName());
|
||||
hikariConfig.setMinimumIdle(myHikariConfig.getMinimumIdle());
|
||||
hikariConfig.setMaximumPoolSize(myHikariConfig.getMaximumPoolSize());
|
||||
|
||||
@@ -5,14 +5,15 @@ import com.aliyun.oss.common.utils.BinaryUtil;
|
||||
import com.aliyun.oss.model.MatchMode;
|
||||
import com.aliyun.oss.model.PolicyConditions;
|
||||
import com.cool.store.response.ResponseResult;
|
||||
import com.cool.store.vo.oss.OssUploadConfigVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhangchenbiao
|
||||
@@ -25,24 +26,25 @@ import java.util.Map;
|
||||
@Slf4j
|
||||
public class OssClientController {
|
||||
|
||||
@Value("${oss.accessKeyId:null}")
|
||||
private String accessKeyId;
|
||||
@Value("${oss.accessKeySecret:null}")
|
||||
private String accessKeySecret;
|
||||
@Value("${oss.endpoint:null}")
|
||||
private String endpoint;
|
||||
@Value("${oss.bucket:null}")
|
||||
private String bucket;
|
||||
|
||||
@GetMapping("/getUploadFileConfig")
|
||||
public ResponseResult getUploadFileConfig(){
|
||||
// 请填写您的AccessKeyId。
|
||||
String accessId = "LTAI5tKSnAbkEbmT6CeBwNN3";
|
||||
// 请填写您的AccessKeySecret。
|
||||
String accessKey = "PbXOzUFwAvZ2K5zIawwa7NAJE2pFXS";
|
||||
// 请填写您的 endpoint。
|
||||
String endpoint = "oss-cn-shanghai.aliyuncs.com";
|
||||
// 请填写您的 bucketname 。
|
||||
String bucket = "vec-coolstore";
|
||||
public ResponseResult getUploadFileConfig(@RequestParam("enterpriseId")String enterpriseId){
|
||||
// host的格式为 bucketname.endpoint
|
||||
String host = "http://" + bucket + "." + endpoint;
|
||||
// callbackUrl为 上传回调服务器的URL,请将下面的IP和Port配置为您自己的真实信息。
|
||||
String dir = "user-dir-prefix/"; // 用户上传文件时指定的前缀。
|
||||
// 用户上传文件时指定的前缀。
|
||||
String dir = "partner/" + enterpriseId + "/";
|
||||
|
||||
OSSClient client = new OSSClient(endpoint, accessId, accessKey);
|
||||
OSSClient client = new OSSClient(endpoint, accessKeyId, accessKeySecret);
|
||||
try {
|
||||
long expireTime = 30;
|
||||
long expireTime = 300;
|
||||
long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
|
||||
Date expiration = new Date(expireEndTime);
|
||||
PolicyConditions policyConds = new PolicyConditions();
|
||||
@@ -51,15 +53,9 @@ public class OssClientController {
|
||||
String postPolicy = client.generatePostPolicy(expiration, policyConds);
|
||||
byte[] binaryData = postPolicy.getBytes("utf-8");
|
||||
String encodedPolicy = BinaryUtil.toBase64String(binaryData);
|
||||
String postSignature = client.calculatePostSignature(postPolicy);
|
||||
Map<String, String> respMap = new LinkedHashMap<String, String>();
|
||||
respMap.put("accessid", accessId);
|
||||
respMap.put("policy", encodedPolicy);
|
||||
respMap.put("signature", postSignature);
|
||||
respMap.put("dir", dir);
|
||||
respMap.put("host", host);
|
||||
respMap.put("expire", String.valueOf(expireEndTime / 1000));
|
||||
return ResponseResult.success(respMap);
|
||||
String signature = client.calculatePostSignature(postPolicy);
|
||||
OssUploadConfigVO result = new OssUploadConfigVO(accessKeyId, encodedPolicy, signature, dir, host, String.valueOf(expireEndTime / 1000));
|
||||
return ResponseResult.success(result);
|
||||
}catch (Exception e){
|
||||
log.info("exception", e);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#mysql config
|
||||
default.datasource.url=jdbc:mysql://dingpushcoolcollege.mysql.rds.aliyuncs.com:3306/coolcollege_intelligent_config?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true&serverTimezone=Asia/Shanghai
|
||||
default.datasource.username=coolstore
|
||||
default.datasource.password=CSCErYcXniNYm7bT
|
||||
default.datasource.url=jdbc:mysql://dingpushcoolcollege.mysql.rds.aliyuncs.com:3306/coolcollege_intelligent_hy?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true
|
||||
default.datasource.username=hsay
|
||||
default.datasource.password=Z3J7xBbgouMD
|
||||
|
||||
#redis
|
||||
spring.redis.host=tstore-coolcollege.redis.rds.aliyuncs.com
|
||||
@@ -41,3 +41,5 @@ rocketmq.secretKey=yuomDstRjSdihtN5zo8viDbWu8Z0ig
|
||||
rocketmq.nameSrvAdder=http://MQ_INST_1947409023213164_BX3sLZnA.cn-hangzhou.mq-internal.aliyuncs.com:8080
|
||||
rocketmq.topic=simple_message
|
||||
rocketmq.orderTopic=order_message
|
||||
|
||||
default.database.name=coolcollege_intelligent_hy
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
#mysql config
|
||||
default.datasource.url=jdbc:mysql://dingpushcoolcollege.mysql.rds.aliyuncs.com:3306/coolcollege_intelligent_config?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true
|
||||
#default.datasource.url=jdbc:mysql://dstore-coolcollege.mysql.rds.aliyuncs.com:3306/coolcollege_intelligent_config?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true&serverTimezone=Asia/Shanghai
|
||||
default.datasource.username=coolstore
|
||||
default.datasource.password=CSCErYcXniNYm7bT
|
||||
#default.datasource.url=jdbc:mysql://127.0.0.1:3306/coolcollege_intelligent_config?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true&serverTimezone=Asia/Shanghai
|
||||
#default.datasource.username=root
|
||||
#default.datasource.password=root
|
||||
default.datasource.url=jdbc:mysql://dingpushcoolcollege.mysql.rds.aliyuncs.com:3306/coolcollege_intelligent_hy?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true
|
||||
default.datasource.username=hsay
|
||||
default.datasource.password=Z3J7xBbgouMD
|
||||
|
||||
#redis
|
||||
spring.redis.host=tstore-coolcollege.redis.rds.aliyuncs.com
|
||||
@@ -44,4 +40,6 @@ rocketmq.accessKey=LTAI5t5ouXZuFgxJMbQea3b2
|
||||
rocketmq.secretKey=yuomDstRjSdihtN5zo8viDbWu8Z0ig
|
||||
rocketmq.nameSrvAdder=http://MQ_INST_1947409023213164_BX3sLZnA.cn-hangzhou.mq-internal.aliyuncs.com:8080
|
||||
rocketmq.topic=simple_message
|
||||
rocketmq.orderTopic=order_message
|
||||
rocketmq.orderTopic=order_message
|
||||
|
||||
default.database.name=coolcollege_intelligent_hy
|
||||
@@ -1,11 +1,7 @@
|
||||
#mysql config
|
||||
default.datasource.url=jdbc:mysql://dingpushcoolcollege.mysql.rds.aliyuncs.com:3306/coolcollege_intelligent_config?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true
|
||||
#default.datasource.url=jdbc:mysql://dstore-coolcollege.mysql.rds.aliyuncs.com:3306/coolcollege_intelligent_config?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true&serverTimezone=Asia/Shanghai
|
||||
default.datasource.username=coolstore
|
||||
default.datasource.password=CSCErYcXniNYm7bT
|
||||
#default.datasource.url=jdbc:mysql://127.0.0.1:3306/coolcollege_intelligent_config?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true&serverTimezone=Asia/Shanghai
|
||||
#default.datasource.username=root
|
||||
#default.datasource.password=root
|
||||
default.datasource.url=jdbc:mysql://dingpushcoolcollege.mysql.rds.aliyuncs.com:3306/coolcollege_intelligent_hy?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true
|
||||
default.datasource.username=hsay
|
||||
default.datasource.password=Z3J7xBbgouMD
|
||||
|
||||
#redis
|
||||
spring.redis.host=tstore-coolcollege.redis.rds.aliyuncs.com
|
||||
@@ -47,4 +43,12 @@ rocketmq.accessKey=zK2oVEz4G1ts23d2
|
||||
rocketmq.secretKey=0UstLCS0mh2ASgBh
|
||||
rocketmq.nameSrvAdder=http://rmq-cn-9lb38l1rx04.cn-hangzhou.rmq.aliyuncs.com:8080
|
||||
rocketmq.topic=simple_message
|
||||
rocketmq.orderTopic=order_message
|
||||
rocketmq.orderTopic=order_message
|
||||
|
||||
#oss配置
|
||||
oss.accessKeyId=LTAI5tKSnAbkEbmT6CeBwNN3
|
||||
oss.accessKeySecret=PbXOzUFwAvZ2K5zIawwa7NAJE2pFXS
|
||||
oss.endpoint=oss-cn-shanghai.aliyuncs.com
|
||||
oss.bucket=vec-coolstore
|
||||
|
||||
default.database.name=coolcollege_intelligent_hy
|
||||
@@ -1,7 +1,7 @@
|
||||
#mysql config
|
||||
default.datasource.url=jdbc:mysql://dingpushcoolcollege.mysql.rds.aliyuncs.com:3306/coolcollege_intelligent_config?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true&serverTimezone=Asia/Shanghai
|
||||
default.datasource.username=coolstore
|
||||
default.datasource.password=CSCErYcXniNYm7bT
|
||||
default.datasource.url=jdbc:mysql://dingpushcoolcollege.mysql.rds.aliyuncs.com:3306/coolcollege_intelligent_hy?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true
|
||||
default.datasource.username=hsay
|
||||
default.datasource.password=Z3J7xBbgouMD
|
||||
|
||||
#redis
|
||||
spring.redis.host=tstore-coolcollege.redis.rds.aliyuncs.com
|
||||
@@ -40,4 +40,6 @@ rocketmq.accessKey=LTAI5t5ouXZuFgxJMbQea3b2
|
||||
rocketmq.secretKey=yuomDstRjSdihtN5zo8viDbWu8Z0ig
|
||||
rocketmq.nameSrvAdder=http://MQ_INST_1947409023213164_BX3sLZnA.cn-hangzhou.mq-internal.aliyuncs.com:8080
|
||||
rocketmq.topic=simple_message
|
||||
rocketmq.orderTopic=order_message
|
||||
rocketmq.orderTopic=order_message
|
||||
|
||||
default.database.name=coolcollege_intelligent_hy
|
||||
Reference in New Issue
Block a user