diff --git a/.gitignore b/.gitignore
index f41242f..836f5fc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,3 +27,7 @@
/ResourceManager/src/main/resources/bootstrap-test.yml
/WXEngine/src/main/resources/bootstrap-test.yml
/WXEngine/src/main/resources/application-test.yml
+/General/src/main/resources/application-test.yml
+/General/src/main/resources/bootstrap-test.yml
+/General/General.iml
+/General/target/
diff --git a/General/pom.xml b/General/pom.xml
new file mode 100644
index 0000000..fde595c
--- /dev/null
+++ b/General/pom.xml
@@ -0,0 +1,129 @@
+
+
+ 4.0.0
+
+ cn.crtech.cloud.general
+ General
+ 1.0.1
+
+
+
+ cn.crtech.cloud.dependencies
+ Dependencies
+ 1.0.1
+
+
+
+
+
+ 8
+ 8
+ 1.8
+ UTF-8
+
+ 1.0.1
+ 2.3.31
+
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+
+ org.apache.commons
+ commons-lang3
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.junit.vintage
+ junit-vintage-engine
+
+
+
+
+
+ junit
+ junit
+ test
+
+
+
+ org.springframework.boot
+ spring-boot-test
+
+
+
+ org.springframework
+ spring-test
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
+
+ io.lettuce
+ lettuce-core
+
+
+
+
+
+ redis.clients
+ jedis
+
+
+
+ org.springframework
+ spring-context
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-aop
+
+
+
+
+ cn.crtech.cloud.common
+ Common
+ ${common.version}
+
+
+
+
+ org.freemarker
+ freemarker
+ ${freemarker.version}
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+ true
+ -Dfile.encoding=UTF-8
+
+
+
+
+
diff --git a/General/src/main/java/cn/crtech/cloud/general/GeneralApplication.java b/General/src/main/java/cn/crtech/cloud/general/GeneralApplication.java
new file mode 100644
index 0000000..ed9a512
--- /dev/null
+++ b/General/src/main/java/cn/crtech/cloud/general/GeneralApplication.java
@@ -0,0 +1,17 @@
+package cn.crtech.cloud.general;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+import tk.mybatis.spring.annotation.MapperScan;
+
+@EnableDiscoveryClient
+@SpringBootApplication
+@EnableTransactionManagement
+@MapperScan("cn.crtech.cloud.general.mapper")
+public class GeneralApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(GeneralApplication.class, args);
+ }
+}
diff --git a/General/src/main/java/cn/crtech/cloud/general/annotation/DataSourceAnnotation.java b/General/src/main/java/cn/crtech/cloud/general/annotation/DataSourceAnnotation.java
new file mode 100644
index 0000000..680c4ce
--- /dev/null
+++ b/General/src/main/java/cn/crtech/cloud/general/annotation/DataSourceAnnotation.java
@@ -0,0 +1,17 @@
+package cn.crtech.cloud.general.annotation;
+
+import cn.crtech.cloud.general.config.DataSourceConstants;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface DataSourceAnnotation {
+ /**
+ * 数据源名称
+ */
+ String value() default DataSourceConstants.MIS_DATASOURCE;
+}
diff --git a/General/src/main/java/cn/crtech/cloud/general/config/DataSource.java b/General/src/main/java/cn/crtech/cloud/general/config/DataSource.java
new file mode 100644
index 0000000..dc9ed6f
--- /dev/null
+++ b/General/src/main/java/cn/crtech/cloud/general/config/DataSource.java
@@ -0,0 +1,10 @@
+package cn.crtech.cloud.general.config;
+
+import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
+
+public class DataSource extends AbstractRoutingDataSource {
+ @Override
+ protected Object determineCurrentLookupKey() {
+ return DataSourceContextHolder.getContextKey();
+ }
+}
diff --git a/General/src/main/java/cn/crtech/cloud/general/config/DataSourceAspect.java b/General/src/main/java/cn/crtech/cloud/general/config/DataSourceAspect.java
new file mode 100644
index 0000000..b6126ac
--- /dev/null
+++ b/General/src/main/java/cn/crtech/cloud/general/config/DataSourceAspect.java
@@ -0,0 +1,46 @@
+package cn.crtech.cloud.general.config;
+
+import cn.crtech.cloud.general.annotation.DataSourceAnnotation;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.stereotype.Component;
+
+import java.util.Objects;
+
+@Aspect
+@Component
+public class DataSourceAspect {
+ @Pointcut("@annotation(cn.crtech.cloud.general.annotation.DataSourceAnnotation)")
+ public void dataSourcePointCut() {
+ }
+
+ @Around("dataSourcePointCut()")
+ public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
+ String dsKey = getDSAnnotation(joinPoint).value();
+ DataSourceContextHolder.setContextKey(dsKey);
+ try {
+ return joinPoint.proceed();
+ } finally {
+ DataSourceContextHolder.removeContextKey();
+ }
+ }
+
+ /**
+ * 根据类或方法获取数据源注解
+ */
+ private DataSourceAnnotation getDSAnnotation(ProceedingJoinPoint joinPoint) {
+ Class> targetClass = joinPoint.getTarget().getClass();
+ DataSourceAnnotation dataSourceAnnotation = targetClass.getAnnotation(DataSourceAnnotation.class);
+ // 先判断类的注解,再判断方法注解
+ if (Objects.nonNull(dataSourceAnnotation)) {
+ return dataSourceAnnotation;
+ } else {
+ MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
+ return methodSignature.getMethod().getAnnotation(DataSourceAnnotation.class);
+ }
+ }
+}
+
diff --git a/General/src/main/java/cn/crtech/cloud/general/config/DataSourceConfig.java b/General/src/main/java/cn/crtech/cloud/general/config/DataSourceConfig.java
new file mode 100644
index 0000000..93e3097
--- /dev/null
+++ b/General/src/main/java/cn/crtech/cloud/general/config/DataSourceConfig.java
@@ -0,0 +1,71 @@
+package cn.crtech.cloud.general.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
+import tk.mybatis.spring.annotation.MapperScan;
+
+import javax.sql.DataSource;
+import java.util.HashMap;
+import java.util.Map;
+
+@Configuration
+@MapperScan(basePackages = "cn.crtech.cloud.general.mapper")
+@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
+public class DataSourceConfig {
+ @Value("${service.datasource.MIS.url}")
+ private String misUrl;
+ @Value("${service.datasource.MIS.username}")
+ private String misUserName;
+ @Value("${service.datasource.MIS.password}")
+ private String misPassWord;
+ @Value("${service.datasource.MIS.driver}")
+ private String misDriver;
+
+ @Bean(DataSourceConstants.MIS_DATASOURCE)
+ public DataSource misDataSource() {
+ DriverManagerDataSource dataSource = new DriverManagerDataSource();
+ dataSource.setDriverClassName(misDriver);
+ dataSource.setUrl(misUrl);
+ dataSource.setUsername(misUserName);
+ dataSource.setPassword(misPassWord);
+ return dataSource;
+ }
+
+ @Value("${service.datasource.TM.url}")
+ private String tmUrl;
+ @Value("${service.datasource.TM.username}")
+ private String tmUserName;
+ @Value("${service.datasource.TM.password}")
+ private String tmPassWord;
+ @Value("${service.datasource.TM.driver}")
+ private String tmDriver;
+
+ @Bean(DataSourceConstants.TM_DATASOURCE)
+ public DataSource tmDataSource() {
+ DriverManagerDataSource dataSource = new DriverManagerDataSource();
+ dataSource.setDriverClassName(tmDriver);
+ dataSource.setUrl(tmUrl);
+ dataSource.setUsername(tmUserName);
+ dataSource.setPassword(tmPassWord);
+ return dataSource;
+ }
+
+ @Bean
+ @Primary
+ public DataSource dataSource() {
+ Map