Browse Source

优化环境变量

test
smallchill 6 years ago
parent
commit
32782b7d15
  1. 46
      blade-common/src/main/java/org/springblade/common/constant/CommonConstant.java
  2. 7
      blade-common/src/main/java/org/springblade/common/launch/LauncherServiceImpl.java
  3. 2
      blade-service/blade-flow/src/main/java/org/springblade/flowable/business/controller/WorkController.java

46
blade-common/src/main/java/org/springblade/common/constant/CommonConstant.java

@ -16,6 +16,8 @@
*/
package org.springblade.common.constant;
import org.springblade.core.launch.constant.AppConstant;
/**
* 通用常量
*
@ -33,6 +35,11 @@ public interface CommonConstant {
*/
String NACOS_PROD_ADDR = "172.30.0.48:8848";
/**
* nacos test 地址
*/
String NACOS_TEST_ADDR = "172.30.0.48:8848";
/**
* sentinel dev 地址
*/
@ -43,6 +50,11 @@ public interface CommonConstant {
*/
String SENTINEL_PROD_ADDR = "172.30.0.58:8858";
/**
* sentinel test 地址
*/
String SENTINEL_TEST_ADDR = "172.30.0.58:8858";
/**
* sword 系统名
*/
@ -69,4 +81,38 @@ public interface CommonConstant {
*/
String DEFAULT_PASSWORD = "123456";
/**
* 动态获取nacos地址
*
* @param profile 环境变量
* @return addr
*/
static String nacosAddr(String profile) {
switch (profile) {
case (AppConstant.PROD_CODE):
return NACOS_PROD_ADDR;
case (AppConstant.TEST_CODE):
return NACOS_TEST_ADDR;
default:
return NACOS_DEV_ADDR;
}
}
/**
* 动态获取sentinel地址
*
* @param profile 环境变量
* @return addr
*/
static String sentinelAddr(String profile) {
switch (profile) {
case (AppConstant.PROD_CODE):
return SENTINEL_PROD_ADDR;
case (AppConstant.TEST_CODE):
return SENTINEL_TEST_ADDR;
default:
return SENTINEL_DEV_ADDR;
}
}
}

7
blade-common/src/main/java/org/springblade/common/launch/LauncherServiceImpl.java

@ -18,7 +18,6 @@ package org.springblade.common.launch;
import org.springblade.common.constant.CommonConstant;
import org.springblade.core.auto.service.AutoService;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.launch.service.LauncherService;
import org.springframework.boot.builder.SpringApplicationBuilder;
@ -35,9 +34,9 @@ public class LauncherServiceImpl implements LauncherService {
@Override
public void launcher(SpringApplicationBuilder builder, String appName, String profile, boolean isLocalDev) {
Properties props = System.getProperties();
props.setProperty("spring.cloud.nacos.discovery.server-addr", profile.equals(AppConstant.DEV_CDOE) ? CommonConstant.NACOS_DEV_ADDR : CommonConstant.NACOS_PROD_ADDR);
props.setProperty("spring.cloud.nacos.config.server-addr", profile.equals(AppConstant.DEV_CDOE) ? CommonConstant.NACOS_DEV_ADDR : CommonConstant.NACOS_PROD_ADDR);
props.setProperty("spring.cloud.sentinel.transport.dashboard", profile.equals(AppConstant.DEV_CDOE) ? CommonConstant.SENTINEL_DEV_ADDR : CommonConstant.SENTINEL_PROD_ADDR);
props.setProperty("spring.cloud.nacos.discovery.server-addr", CommonConstant.nacosAddr(profile));
props.setProperty("spring.cloud.nacos.config.server-addr", CommonConstant.nacosAddr(profile));
props.setProperty("spring.cloud.sentinel.transport.dashboard", CommonConstant.sentinelAddr(profile));
}
}

2
blade-service/blade-flow/src/main/java/org/springblade/flowable/business/controller/WorkController.java

@ -109,7 +109,7 @@ public class WorkController {
@PostMapping("claim-task")
@ApiOperation(value = "签收事务", notes = "传入流程信息", position = 6)
public R claimTask(@ApiParam("任务id") String taskId, BladeUser user) {
taskService.claim(taskId, String.valueOf(user.getUserId()));
taskService.claim(taskId, String.valueOf(user.getAccount()));
return R.success("签收事务成功");
}

Loading…
Cancel
Save