Selaa lähdekoodia

增加自定义启动类,读取公共配置文件

liweifan 3 vuotta sitten
vanhempi
commit
39d7ac8544
17 muutettua tiedostoa jossa 463 lisäystä ja 182 poistoa
  1. 1 1
      cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/AdminFeignService.java
  2. 1 1
      cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/CmsFeignService.java
  3. 1 1
      cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/MallAdminFeignService.java
  4. 1 1
      cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/MallPortalFeignService.java
  5. 10 10
      cooleshow-common/src/main/java/com/yonge/cooleshow/common/constant/AppConstant.java
  6. 82 0
      cooleshow-common/src/main/java/com/yonge/cooleshow/common/constant/LauncherConstant.java
  7. 6 10
      cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/AdminApplication.java
  8. 1 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/support/PageUtil.java
  9. 0 129
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/support/SqlKeyword.java
  10. 4 7
      cooleshow-user/user-student/src/main/java/com/yonge/cooleshow/student/StudentApplication.java
  11. 4 6
      cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/TeacherApplication.java
  12. 72 0
      toolset/toolset-base/src/main/java/com/yonge/toolset/base/BaseApplication.java
  13. 25 0
      toolset/toolset-base/src/main/java/com/yonge/toolset/base/constant/BaseAppConstant.java
  14. 53 0
      toolset/toolset-base/src/main/java/com/yonge/toolset/base/constant/NacosConstant.java
  15. 175 0
      toolset/toolset-base/src/main/java/com/yonge/toolset/base/util/INetUtil.java
  16. 27 0
      toolset/toolset-base/src/main/java/com/yonge/toolset/base/util/PropsUtil.java
  17. 0 16
      toolset/toolset-mybatis/src/main/resources/base-mybatis.yml

+ 1 - 1
cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/AdminFeignService.java

@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.PostMapping;
  * @author liujunchi
  * @date 2022-05-06
  */
-@FeignClient(name = AppConstant.APPLICATION_ADMIN_SERVER, configuration = FeignConfiguration.class,
+@FeignClient(name = AppConstant.APPLICATION_ADMIN, configuration = FeignConfiguration.class,
              fallback = AdminFeignServiceFallback.class)
 public interface AdminFeignService {
     /***

+ 1 - 1
cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/CmsFeignService.java

@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.GetMapping;
  * @date 2022-04-29
  */
 
-@FeignClient(name = AppConstant.APPLICATION_CMS_SERVER, configuration = FeignConfiguration.class, fallback = CmsFeignServiceFallback.class)
+@FeignClient(name = AppConstant.APPLICATION_CMS, configuration = FeignConfiguration.class, fallback = CmsFeignServiceFallback.class)
 public interface CmsFeignService {
 
     /**

+ 1 - 1
cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/MallAdminFeignService.java

@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import java.util.List;
 import java.util.Map;
 
-@FeignClient(name = AppConstant.APPLICATION_MALL_ADMIN_SERVER, configuration = FeignConfiguration.class,
+@FeignClient(name = AppConstant.APPLICATION_MALL_ADMIN, configuration = FeignConfiguration.class,
         fallback = MallAdminFeignServiceFallback.class)
 public interface MallAdminFeignService {
 

+ 1 - 1
cooleshow-api/src/main/java/com/yonge/cooleshow/api/feign/MallPortalFeignService.java

@@ -6,7 +6,7 @@ import com.yonge.toolset.feign.config.FeignConfiguration;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.GetMapping;
 
-@FeignClient(name = AppConstant.APPLICATION_MALL_PORTAL_SERVER, configuration = FeignConfiguration.class,
+@FeignClient(name = AppConstant.APPLICATION_MALL_PORTAL, configuration = FeignConfiguration.class,
         fallback = MallPortalFeignServiceFallback.class)
 public interface MallPortalFeignService {
 

+ 10 - 10
cooleshow-common/src/main/java/com/yonge/cooleshow/common/constant/AppConstant.java

@@ -8,42 +8,42 @@ public interface AppConstant {
     /**
      * 网关
      */
-    String APPLICATION_GATEWAY_WEB_SERVER = "gateway-web-server";
+    String APPLICATION_GATEWAY_WEB = "gateway-web";
     /**
      * 鉴权
      */
-    String APPLICATION_AUTH_SERVER = "auth-server";
+    String APPLICATION_AUTH = "auth";
     /**
      * 定时任务
      */
-    String APPLICATION_TASK_SERVER = "task-server";
+    String APPLICATION_TASK = "task";
     /**
      * 管理端
      */
-    String APPLICATION_ADMIN_SERVER = "admin-server";
+    String APPLICATION_ADMIN = "admin";
     /**
      * 老师端
      */
-    String APPLICATION_TEACHER_SERVER = "teacher-server";
+    String APPLICATION_TEACHER = "teacher";
     /**
      * 学生端
      */
-    String APPLICATION_STUDENT_SERVER = "student-server";
+    String APPLICATION_STUDENT = "student";
     /**
      * CMS
      */
-    String APPLICATION_CMS_SERVER= "cms-server";
+    String APPLICATION_CMS= "cms";
     /**
      * 商城管理端
      */
-    String APPLICATION_MALL_ADMIN_SERVER = "mall-admin-server";
+    String APPLICATION_MALL_ADMIN = "mall-admin";
     /**
      * 商城门户
      */
-    String APPLICATION_MALL_PORTAL_SERVER = "mall-portal-server";
+    String APPLICATION_MALL_PORTAL = "mall-portal";
     /**
      * WEBSOCKET
      */
-    String APPLICATION_WEBSOCKET_SERVER = "websocket-server";
+    String APPLICATION_WEBSOCKET = "websocket";
 
 }

+ 82 - 0
cooleshow-common/src/main/java/com/yonge/cooleshow/common/constant/LauncherConstant.java

@@ -0,0 +1,82 @@
+package com.yonge.cooleshow.common.constant;
+
+
+import com.yonge.toolset.base.constant.BaseAppConstant;
+
+/**
+ * 启动常量
+ *
+ */
+public interface LauncherConstant {
+	/**
+	 * nacos local 地址
+	 */
+	String NACOS_LOCAL_ADDR = "47.114.1.200:8848";
+	/**
+	 * nacos dev 地址
+	 */
+	String NACOS_DEV_ADDR = "47.114.1.200:8848";
+	/**
+	 * nacos test 地址
+	 */
+	String NACOS_TEST_ADDR = "";
+	/**
+	 * nacos prod 地址
+	 */
+	String NACOS_PROD_ADDR = "";
+
+	/**
+	 * nacos local 命名空间
+	 */
+	String NACOS_LOCAL_NAMESPACE = "a71fb65c-d5d9-42c3-bbde-3586d19178f0";
+
+	/**
+	 * nacos dev 命名空间
+	 */
+	String NACOS_DEV_NAMESPACE = "6f8374a9-598f-4889-bb17-476070ffb8de";
+	/**
+	 * nacos test 命名空间
+	 */
+	String NACOS_TEST_NAMESPACE = "";
+	/**
+	 * nacos prod 命名空间
+	 */
+	String NACOS_PROD_NAMESPACE = "";
+
+	/**
+	 * 动态获取nacos地址
+	 *
+	 * @param profile 环境变量
+	 * @return addr
+	 */
+	static String nacosAddr(String profile) {
+		switch (profile) {
+			case (BaseAppConstant.PROD_CODE):
+				return NACOS_PROD_ADDR;
+			case (BaseAppConstant.TEST_CODE):
+				return NACOS_TEST_ADDR;
+			case (BaseAppConstant.LOCAL_CODE):
+				return NACOS_LOCAL_ADDR;
+			default:
+				return NACOS_DEV_ADDR;
+		}
+	}
+	/**
+	 * 动态获取nacos命名空间
+	 *
+	 * @param profile 环境变量
+	 * @return addr
+	 */
+	static String nacosNamespace(String profile) {
+		switch (profile) {
+			case (BaseAppConstant.PROD_CODE):
+				return NACOS_PROD_NAMESPACE;
+			case (BaseAppConstant.TEST_CODE):
+				return NACOS_TEST_NAMESPACE;
+			case (BaseAppConstant.LOCAL_CODE):
+				return NACOS_LOCAL_NAMESPACE;
+			default:
+				return NACOS_DEV_NAMESPACE;
+		}
+	}
+}

+ 6 - 10
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/AdminApplication.java

@@ -1,5 +1,7 @@
 package com.yonge.cooleshow.admin;
 
+import com.yonge.cooleshow.common.constant.AppConstant;
+import com.yonge.toolset.base.BaseApplication;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -14,17 +16,11 @@ import com.spring4all.swagger.EnableSwagger2Doc;
 @EnableDiscoveryClient
 @EnableFeignClients("com.yonge.cooleshow")
 @MapperScan(basePackages = {"com.yonge.cooleshow.biz.dal.dao", "com.yonge.toolset.payment.core.dao"})
-@ComponentScan(basePackages = {
-		"com.yonge.cooleshow.admin", "com.yonge.cooleshow.auth", "com.yonge.cooleshow.biz",
-		"com.yonge.cooleshow.common", "com.yonge.cooleshow.common.security",
-		"com.yonge.toolset.log", "com.yonge.toolset.thirdparty", "com.yonge.toolset.payment"
-})
+@ComponentScan(basePackages = {"com.yonge.cooleshow", "com.yonge.toolset"})
 @Configuration
 @EnableSwagger2Doc
 public class AdminApplication {
-
-	public static void main(String[] args) {
-        SpringApplication.run(AdminApplication.class, args);
-	}
-	
+    public static void main(String[] args) {
+        BaseApplication.run(AppConstant.APPLICATION_ADMIN, AdminApplication.class, args);
+    }
 }

+ 1 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/support/PageUtil.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.yonge.toolset.base.page.PageInfo;
 import com.yonge.toolset.base.page.QueryInfo;
+import com.yonge.toolset.mybatis.support.SqlKeyword;
 import com.yonge.toolset.utils.string.StringUtil;
 import org.springframework.beans.BeanUtils;
 

+ 0 - 129
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/support/SqlKeyword.java

@@ -1,129 +0,0 @@
-package com.yonge.cooleshow.biz.dal.support;
-
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.toolkit.StringPool;
-import com.yonge.toolset.utils.date.DateUtil;
-import com.yonge.toolset.utils.obj.ObjectUtil;
-import com.yonge.toolset.utils.string.StringUtil;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-import org.springframework.util.CollectionUtils;
-
-import java.util.Map;
-
-/**
- * 定义常用的 sql关键字
- *
- * @author Chill
- */
-@Component
-public class SqlKeyword {
-	private final static String SQL_REGEX = "'|%|--|insert|delete|select|count|group|union|drop|truncate|alter|grant|execute|exec|xp_cmdshell|call|declare|sql";
-
-	private static final String EQUAL = "_equal";
-	private static final String NOT_EQUAL = "_notequal";
-	private static final String LIKE = "_like";
-	private static final String LIKE_LEFT = "_likeleft";
-	private static final String LIKE_RIGHT = "_likeright";
-	private static final String NOT_LIKE = "_notlike";
-	private static final String GE = "_ge";
-	private static final String LE = "_le";
-	private static final String GT = "_gt";
-	private static final String LT = "_lt";
-	private static final String DATE_GE = "_datege";
-	private static final String DATE_GT = "_dategt";
-	private static final String DATE_EQUAL = "_dateequal";
-	private static final String DATE_LT = "_datelt";
-	private static final String DATE_LE = "_datele";
-	private static final String IS_NULL = "_null";
-	private static final String NOT_NULL = "_notnull";
-	private static final String IGNORE = "_ignore";
-	//是否转驼峰
-	static public Boolean underline;
-
-	/**
-	 * 条件构造器
-	 *
-	 * @param query 查询字段
-	 * @param qw    查询包装类
-	 */
-	public static void buildCondition(Map<String, Object> query, QueryWrapper<?> qw) {
-		if (CollectionUtils.isEmpty(query)) {
-			return;
-		}
-		query.forEach((k, v) -> {
-			if (ObjectUtil.hasEmpty(k, v) || k.endsWith(IGNORE)) {
-				return;
-			}
-			if (k.endsWith(EQUAL)) {
-				qw.eq(getColumn(k, EQUAL), v);
-			} else if (k.endsWith(NOT_EQUAL)) {
-				qw.ne(getColumn(k, NOT_EQUAL), v);
-			} else if (k.endsWith(LIKE_LEFT)) {
-				qw.likeLeft(getColumn(k, LIKE_LEFT), v);
-			} else if (k.endsWith(LIKE_RIGHT)) {
-				qw.likeRight(getColumn(k, LIKE_RIGHT), v);
-			} else if (k.endsWith(NOT_LIKE)) {
-				qw.notLike(getColumn(k, NOT_LIKE), v);
-			} else if (k.endsWith(GE)) {
-				qw.ge(getColumn(k, GE), v);
-			} else if (k.endsWith(LE)) {
-				qw.le(getColumn(k, LE), v);
-			} else if (k.endsWith(GT)) {
-				qw.gt(getColumn(k, GT), v);
-			} else if (k.endsWith(LT)) {
-				qw.lt(getColumn(k, LT), v);
-			} else if (k.endsWith(DATE_GE)) {
-				qw.ge(getColumn(k, DATE_GE), DateUtil.parse(String.valueOf(v), DateUtil.EXPANDED_DATE_TIME_FORMAT));
-			} else if (k.endsWith(DATE_GT)) {
-				qw.gt(getColumn(k, DATE_GT), DateUtil.parse(String.valueOf(v), DateUtil.EXPANDED_DATE_TIME_FORMAT));
-			} else if (k.endsWith(DATE_EQUAL)) {
-				qw.eq(getColumn(k, DATE_EQUAL), DateUtil.parse(String.valueOf(v), DateUtil.EXPANDED_DATE_TIME_FORMAT));
-			} else if (k.endsWith(DATE_LE)) {
-				qw.le(getColumn(k, DATE_LE), DateUtil.parse(String.valueOf(v), DateUtil.EXPANDED_DATE_TIME_FORMAT));
-			} else if (k.endsWith(DATE_LT)) {
-				qw.lt(getColumn(k, DATE_LT), DateUtil.parse(String.valueOf(v), DateUtil.EXPANDED_DATE_TIME_FORMAT));
-			} else if (k.endsWith(IS_NULL)) {
-				qw.isNull(getColumn(k, IS_NULL));
-			} else if (k.endsWith(NOT_NULL)) {
-				qw.isNotNull(getColumn(k, NOT_NULL));
-			} else {
-				qw.like(getColumn(k, LIKE), v);
-			}
-		});
-	}
-
-	/**
-	 * 获取数据库字段
-	 *
-	 * @param column  字段名
-	 * @param keyword 关键字
-	 * @return
-	 */
-	private static String getColumn(String column, String keyword) {
-		if(underline){
-			return StringUtil.humpToUnderline(StringUtil.removeSuffix(column, keyword));
-		}else{
-			return StringUtil.removeSuffix(column, keyword);
-		}
-	}
-
-	/**
-	 * 把SQL关键字替换为空字符串
-	 *
-	 * @param param 关键字
-	 * @return string
-	 */
-	public static String filter(String param) {
-		if (param == null) {
-			return null;
-		}
-		return param.replaceAll("(?i)" + SQL_REGEX, StringPool.EMPTY);
-	}
-
-	@Value("${spring.datasource.table-underline}")
-	public void setUnderline(Boolean underline) {
-		SqlKeyword.underline = underline;
-	}
-
-}

+ 4 - 7
cooleshow-user/user-student/src/main/java/com/yonge/cooleshow/student/StudentApplication.java

@@ -1,6 +1,8 @@
 package com.yonge.cooleshow.student;
 
 import com.spring4all.swagger.EnableSwagger2Doc;
+import com.yonge.cooleshow.common.constant.AppConstant;
+import com.yonge.toolset.base.BaseApplication;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -17,16 +19,11 @@ import org.springframework.context.annotation.Configuration;
 @EnableDiscoveryClient
 @EnableFeignClients("com.yonge.cooleshow")
 @MapperScan(basePackages = {"com.yonge.cooleshow.biz.dal.dao", "com.yonge.toolset.payment.core.dao"})
-@ComponentScan(basePackages = {
-        "com.yonge.cooleshow.student", "com.yonge.cooleshow.auth", "com.yonge.cooleshow.biz",
-        "com.yonge.cooleshow.common", "com.yonge.cooleshow.common.security",
-        "com.yonge.toolset.log", "com.yonge.toolset.thirdparty", "com.yonge.toolset.payment"
-})
+@ComponentScan(basePackages = {"com.yonge.cooleshow", "com.yonge.toolset"})
 @Configuration
 @EnableSwagger2Doc
 public class StudentApplication {
     public static void main(String[] args) {
-        SpringApplication.run(StudentApplication.class, args);
+        BaseApplication.run(AppConstant.APPLICATION_STUDENT, StudentApplication.class, args);
     }
-
 }

+ 4 - 6
cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/TeacherApplication.java

@@ -1,6 +1,8 @@
 package com.yonge.cooleshow.teacher;
 
 import com.spring4all.swagger.EnableSwagger2Doc;
+import com.yonge.cooleshow.common.constant.AppConstant;
+import com.yonge.toolset.base.BaseApplication;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -17,16 +19,12 @@ import org.springframework.context.annotation.Configuration;
 @EnableDiscoveryClient
 @EnableFeignClients("com.yonge.cooleshow")
 @MapperScan(basePackages = {"com.yonge.cooleshow.biz.dal.dao", "com.yonge.toolset.payment.core.dao"})
-@ComponentScan(basePackages = {
-        "com.yonge.cooleshow.teacher", "com.yonge.cooleshow.auth", "com.yonge.cooleshow.biz",
-        "com.yonge.cooleshow.common", "com.yonge.cooleshow.common.security",
-        "com.yonge.toolset.log", "com.yonge.toolset.thirdparty", "com.yonge.toolset.payment"
-})
+@ComponentScan(basePackages = {"com.yonge.cooleshow","com.yonge.toolset"})
 @Configuration
 @EnableSwagger2Doc
 public class TeacherApplication {
     public static void main(String[] args) {
-        SpringApplication.run(TeacherApplication.class, args);
+        BaseApplication.run(AppConstant.APPLICATION_TEACHER, TeacherApplication.class, args);
     }
 
 }

+ 72 - 0
toolset/toolset-base/src/main/java/com/yonge/toolset/base/BaseApplication.java

@@ -0,0 +1,72 @@
+package com.yonge.toolset.base;
+
+import com.yonge.toolset.base.constant.BaseAppConstant;
+import com.yonge.toolset.base.constant.NacosConstant;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.*;
+import org.springframework.util.Assert;
+import org.springframework.util.StringUtils;
+
+import java.util.*;
+import java.util.function.Function;
+
+/**
+ * 项目启动器
+ *
+ */
+public class BaseApplication {
+
+	public static ConfigurableApplicationContext run(String appName, Class source, String... args) {
+		SpringApplicationBuilder builder = createSpringApplicationBuilder(appName, source, args);
+		return builder.run(args);
+	}
+
+	public static SpringApplicationBuilder createSpringApplicationBuilder(String appName, Class source, String... args) {
+		Assert.hasText(appName, "[appName]服务名不能为空");
+		// 读取环境变量,使用spring boot的规则
+		ConfigurableEnvironment environment = new StandardEnvironment();
+		MutablePropertySources propertySources = environment.getPropertySources();
+		propertySources.addFirst(new SimpleCommandLinePropertySource(args));
+		propertySources.addLast(new MapPropertySource(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, environment.getSystemProperties()));
+		propertySources.addLast(new SystemEnvironmentPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, environment.getSystemEnvironment()));
+		// 获取配置的环境变量
+		String[] activeProfiles = environment.getActiveProfiles();
+		// 判断环境:dev、test、prod
+		List<String> profiles = Arrays.asList(activeProfiles);
+		// 预设的环境
+		List<String> presetProfiles = new ArrayList<>(Arrays.asList(BaseAppConstant.DEV_CODE, BaseAppConstant.TEST_CODE, BaseAppConstant.PROD_CODE));
+		// 交集
+		presetProfiles.retainAll(profiles);
+		// 当前使用
+		List<String> activeProfileList = new ArrayList<>(profiles);
+		Function<Object[], String> joinFun = StringUtils::arrayToCommaDelimitedString;
+		SpringApplicationBuilder builder = new SpringApplicationBuilder(source);
+		String profile;
+		if (activeProfileList.isEmpty()) {
+			// 默认dev开发
+			profile = BaseAppConstant.DEV_CODE;
+			activeProfileList.add(profile);
+			builder.profiles(profile);
+		} else if (activeProfileList.size() == 1) {
+			profile = activeProfileList.get(0);
+		} else {
+			// 同时存在dev、test、prod环境时
+			throw new RuntimeException("同时存在环境变量:[" + StringUtils.arrayToCommaDelimitedString(activeProfiles) + "]");
+		}
+		String startJarPath = BaseApplication.class.getResource("/").getPath().split("!")[0];
+		String activePros = joinFun.apply(activeProfileList.toArray());
+		System.out.println(String.format("----启动中,读取到的环境变量:[%s],jar地址:[%s]----", activePros, startJarPath));
+		Properties props = System.getProperties();
+
+		props.setProperty("spring.application.name", appName);
+		props.setProperty("spring.profiles.active", profile);
+		props.setProperty("spring.main.allow-bean-definition-overriding", "true");
+		props.setProperty("spring.sleuth.sampler.percentage", "1.0");
+		props.setProperty("spring.cloud.nacos.config.shared-dataids", NacosConstant.sharedDataIds(profile));
+		props.setProperty("spring.cloud.nacos.config.file-extension", NacosConstant.NACOS_CONFIG_FORMAT);
+		return builder;
+	}
+
+
+}

+ 25 - 0
toolset/toolset-base/src/main/java/com/yonge/toolset/base/constant/BaseAppConstant.java

@@ -0,0 +1,25 @@
+package com.yonge.toolset.base.constant;
+
+/**
+ * 系统常量
+ *
+ * @author Chill
+ */
+public interface BaseAppConstant {
+	/**
+	 * 本地环境
+	 */
+	String LOCAL_CODE = "local";
+	/**
+	 * 开发环境
+	 */
+	String DEV_CODE = "dev";
+	/**
+	 * 生产环境
+	 */
+	String PROD_CODE = "prod";
+	/**
+	 * 测试环境
+	 */
+	String TEST_CODE = "test";
+}

+ 53 - 0
toolset/toolset-base/src/main/java/com/yonge/toolset/base/constant/NacosConstant.java

@@ -0,0 +1,53 @@
+package com.yonge.toolset.base.constant;
+
+/**
+ * Nacos常量.
+ *
+ * @author Chill
+ */
+public interface NacosConstant {
+
+	/**
+	 * nacos 配置前缀
+	 */
+	String NACOS_CONFIG_PREFIX = "base";
+
+	/**
+	 * nacos 配置文件类型
+	 */
+	String NACOS_CONFIG_FORMAT = "yaml";
+
+	/**
+	 * 构建服务对应的 dataId
+	 *
+	 * @param appName 服务名
+	 * @param profile 环境变量
+	 * @return dataId
+	 */
+	static String dataId(String appName, String profile) {
+		return dataId(appName, profile, NACOS_CONFIG_FORMAT);
+	}
+
+	/**
+	 * 构建服务对应的 dataId
+	 *
+	 * @param appName 服务名
+	 * @param profile 环境变量
+	 * @param format  文件类型
+	 * @return dataId
+	 */
+	static String dataId(String appName, String profile, String format) {
+		return appName + "-" + profile + "." + format;
+	}
+
+	/**
+	 * 服务默认加载的配置
+	 *
+	 * @param profile 环境变量
+	 * @return sharedDataIds
+	 */
+	static String sharedDataIds(String profile) {
+		return NACOS_CONFIG_PREFIX + "." + NACOS_CONFIG_FORMAT + "," + NACOS_CONFIG_PREFIX + "-" + profile + "." + NACOS_CONFIG_FORMAT;
+	}
+
+}

+ 175 - 0
toolset/toolset-base/src/main/java/com/yonge/toolset/base/util/INetUtil.java

@@ -0,0 +1,175 @@
+package com.yonge.toolset.base.util;
+
+import org.springframework.util.StringUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.ServerSocket;
+import java.net.UnknownHostException;
+import java.util.Enumeration;
+
+/**
+ * INet 相关工具
+ *
+ * @author L.cm
+ */
+public class INetUtil {
+	public static final String LOCAL_HOST = "127.0.0.1";
+
+	/**
+	 * 获取 服务器 hostname
+	 *
+	 * @return hostname
+	 */
+	public static String getHostName() {
+		String hostname;
+		try {
+			InetAddress address = InetAddress.getLocalHost();
+			// force a best effort reverse DNS lookup
+			hostname = address.getHostName();
+			if (StringUtils.isEmpty(hostname)) {
+				hostname = address.toString();
+			}
+		} catch (UnknownHostException ignore) {
+			hostname = LOCAL_HOST;
+		}
+		return hostname;
+	}
+
+	/**
+	 * 获取 服务器 HostIp
+	 *
+	 * @return HostIp
+	 */
+	public static String getHostIp() {
+		String hostAddress;
+		try {
+			InetAddress address = INetUtil.getLocalHostLANAddress();
+			// force a best effort reverse DNS lookup
+			hostAddress = address.getHostAddress();
+			if (StringUtils.isEmpty(hostAddress)) {
+				hostAddress = address.toString();
+			}
+		} catch (UnknownHostException ignore) {
+			hostAddress = LOCAL_HOST;
+		}
+		return hostAddress;
+	}
+
+	/**
+	 * https://stackoverflow.com/questions/9481865/getting-the-ip-address-of-the-current-machine-using-java
+	 *
+	 * <p>
+	 * Returns an <code>InetAddress</code> object encapsulating what is most likely the machine's LAN IP address.
+	 * <p/>
+	 * This method is intended for use as a replacement of JDK method <code>InetAddress.getLocalHost</code>, because
+	 * that method is ambiguous on Linux systems. Linux systems enumerate the loopback network interface the same
+	 * way as regular LAN network interfaces, but the JDK <code>InetAddress.getLocalHost</code> method does not
+	 * specify the algorithm used to select the address returned under such circumstances, and will often return the
+	 * loopback address, which is not valid for network communication. Details
+	 * <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4665037">here</a>.
+	 * <p/>
+	 * This method will scan all IP addresses on all network interfaces on the host machine to determine the IP address
+	 * most likely to be the machine's LAN address. If the machine has multiple IP addresses, this method will prefer
+	 * a site-local IP address (e.g. 192.168.x.x or 10.10.x.x, usually IPv4) if the machine has one (and will return the
+	 * first site-local address if the machine has more than one), but if the machine does not hold a site-local
+	 * address, this method will return simply the first non-loopback address found (IPv4 or IPv6).
+	 * <p/>
+	 * If this method cannot find a non-loopback address using this selection algorithm, it will fall back to
+	 * calling and returning the result of JDK method <code>InetAddress.getLocalHost</code>.
+	 * <p/>
+	 *
+	 * @throws UnknownHostException If the LAN address of the machine cannot be found.
+	 */
+	private static InetAddress getLocalHostLANAddress() throws UnknownHostException {
+		try {
+			InetAddress candidateAddress = null;
+			// Iterate all NICs (network interface cards)...
+			for (Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); ifaces.hasMoreElements(); ) {
+				NetworkInterface iface = (NetworkInterface) ifaces.nextElement();
+				// Iterate all IP addresses assigned to each card...
+				for (Enumeration inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements(); ) {
+					InetAddress inetAddr = (InetAddress) inetAddrs.nextElement();
+					if (!inetAddr.isLoopbackAddress()) {
+
+						if (inetAddr.isSiteLocalAddress()) {
+							// Found non-loopback site-local address. Return it immediately...
+							return inetAddr;
+						} else if (candidateAddress == null) {
+							// Found non-loopback address, but not necessarily site-local.
+							// Store it as a candidate to be returned if site-local address is not subsequently found...
+							candidateAddress = inetAddr;
+							// Note that we don't repeatedly assign non-loopback non-site-local addresses as candidates,
+							// only the first. For subsequent iterations, candidate will be non-null.
+						}
+					}
+				}
+			}
+			if (candidateAddress != null) {
+				// We did not find a site-local address, but we found some other non-loopback address.
+				// Server might have a non-site-local address assigned to its NIC (or it might be running
+				// IPv6 which deprecates the "site-local" concept).
+				// Return this non-loopback candidate address...
+				return candidateAddress;
+			}
+			// At this point, we did not find a non-loopback address.
+			// Fall back to returning whatever InetAddress.getLocalHost() returns...
+			InetAddress jdkSuppliedAddress = InetAddress.getLocalHost();
+			if (jdkSuppliedAddress == null) {
+				throw new UnknownHostException("The JDK InetAddress.getLocalHost() method unexpectedly returned null.");
+			}
+			return jdkSuppliedAddress;
+		} catch (Exception e) {
+			UnknownHostException unknownHostException = new UnknownHostException("Failed to determine LAN address: " + e);
+			unknownHostException.initCause(e);
+			throw unknownHostException;
+		}
+	}
+
+	/**
+	 * 尝试端口时候被占用
+	 *
+	 * @param port 端口号
+	 * @return 没有被占用:true,被占用:false
+	 */
+	public static boolean tryPort(int port) {
+		try (ServerSocket ignore = new ServerSocket(port)) {
+			return true;
+		} catch (Exception e) {
+			return false;
+		}
+	}
+
+
+	public static String getIpAddr(HttpServletRequest request) {
+		String ip = null;
+		try {
+			ip = request.getHeader("x-forwarded-for");
+			if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
+				ip = request.getHeader("Proxy-Client-IP");
+			}
+			if (StringUtils.isEmpty(ip) || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+				ip = request.getHeader("WL-Proxy-Client-IP");
+			}
+			if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
+				ip = request.getHeader("HTTP_CLIENT_IP");
+			}
+			if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
+				ip = request.getHeader("HTTP_X_FORWARDED_FOR");
+			}
+			if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
+				ip = request.getRemoteAddr();
+			}
+		} catch (Exception e) {
+			return null;
+		}
+		// 使用代理,则获取第一个IP地址
+		if (StringUtils.isEmpty(ip) && ip.length() > 15) {
+			if (ip.indexOf(",") > 0) {
+				ip = ip.substring(0, ip.indexOf(","));
+			}
+		}
+		return ip;
+	}
+}

+ 27 - 0
toolset/toolset-base/src/main/java/com/yonge/toolset/base/util/PropsUtil.java

@@ -0,0 +1,27 @@
+package com.yonge.toolset.base.util;
+
+import org.springframework.util.StringUtils;
+
+import java.util.Properties;
+
+/**
+ * 配置工具类
+ *
+ * @author Chill
+ */
+public class PropsUtil {
+
+	/**
+	 * 设置配置值,已存在则跳过
+	 *
+	 * @param props property
+	 * @param key   key
+	 * @param value value
+	 */
+	public static void setProperty(Properties props, String key, String value) {
+		if (StringUtils.isEmpty(props.getProperty(key))) {
+			props.setProperty(key, value);
+		}
+	}
+
+}

+ 0 - 16
toolset/toolset-mybatis/src/main/resources/base-mybatis.yml

@@ -1,16 +0,0 @@
-mybatis:
-  mapperLocations: classpath:config/mybatis/*.xml
-#mybatis-plus配置
-mybatis-plus:
-  configuration:
-    map-underscore-to-camel-case: true
-    auto-mapping-behavior: full
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
-  type-enums-package: com.yonge.**.enums
-  global-config:
-    # 逻辑删除配置
-    db-config:
-      # 删除前
-      logic-not-delete-value: 1
-      # 删除后
-      logic-delete-value: 0