commit 58f358e038b3992601f1983bab4d0959176b7fe4
Author: ytChen <1650611030@qq.com>
Date: Tue Mar 5 15:42:27 2024 +0800
初始化
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
new file mode 100644
index 0000000..2df0afb
--- /dev/null
+++ b/.idea/dataSources.xml
@@ -0,0 +1,17 @@
+
+
+
+
+ mysql.8
+ true
+ com.mysql.cj.jdbc.Driver
+ jdbc:mysql://localhost:3306
+
+
+
+
+
+ $ProjectFileDir$
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..4bfbfc0
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..dc13fb0
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/mybatisx/templates.xml b/.idea/mybatisx/templates.xml
new file mode 100644
index 0000000..d1678bb
--- /dev/null
+++ b/.idea/mybatisx/templates.xml
@@ -0,0 +1,87 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/hoe-admin/admin-boot/pom.xml b/hoe-admin/admin-boot/pom.xml
new file mode 100644
index 0000000..d28b45c
--- /dev/null
+++ b/hoe-admin/admin-boot/pom.xml
@@ -0,0 +1,94 @@
+
+
+ 4.0.0
+
+ com.recovery
+ hoe-admin
+ 1.0.0
+
+
+ admin-boot
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-bootstrap
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-loadbalancer
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+
+
+
+
+ com.nimbusds
+ nimbus-jose-jwt
+
+
+
+ com.recovery
+ common-redis
+ ${hoe-version}
+
+
+ com.recovery
+ common-mybatis-plus
+ ${hoe-version}
+
+
+ com.recovery
+ common-web
+ ${hoe-version}
+
+
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ com.spotify
+ docker-maven-plugin
+
+
+
+
\ No newline at end of file
diff --git a/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/AdminApp.java b/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/AdminApp.java
new file mode 100644
index 0000000..d930c1d
--- /dev/null
+++ b/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/AdminApp.java
@@ -0,0 +1,22 @@
+package com.recovery.admin.boot;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.context.annotation.ComponentScan;
+
+@SpringBootApplication
+@EnableDiscoveryClient
+@RefreshScope
+@EnableFeignClients
+@ComponentScan(basePackages = {"com.recovery.admin.boot","com.recovery.common.base"})
+@MapperScan("com.recovery.admin.boot.mapper")
+public class AdminApp {
+ public static void main(String[] args) {
+ SpringApplication.run(AdminApp.class, args);
+ }
+}
+
diff --git a/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/aspect/WebLogAspect.java b/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/aspect/WebLogAspect.java
new file mode 100644
index 0000000..7dc2273
--- /dev/null
+++ b/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/aspect/WebLogAspect.java
@@ -0,0 +1,81 @@
+package com.recovery.admin.boot.aspect;
+
+
+import com.recovery.common.base.util.HspHostUtil;
+
+import com.recovery.common.base.utils.RedisUtils;
+import lombok.extern.slf4j.Slf4j;
+import com.recovery.common.base.ds.*;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.After;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.annotation.Order;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.net.URL;
+
+/**
+ * Web层日志切面
+ *
+ * @author RyanWang
+ * @version 1.0.0
+ * @date 16/5/17 上午10:42.
+ */
+@Aspect
+@Order(0)
+@Slf4j
+@Component
+public class WebLogAspect {
+ @Resource
+ private StringRedisTemplate stringRedisTemplate;
+//
+ @Pointcut("execution(public * com.recovery.admin.boot.controller..*.*(..)) || execution(public * com.recovery.admin.boot.rest.*.*(..))")
+ public void webLog(){}
+
+ @Before("webLog()")
+ public void doBefore(JoinPoint joinPoint) throws Throwable {
+
+ // 接收到请求,记录请求内容
+ ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ //获取请求的域名
+ HttpServletRequest request = attributes.getRequest();
+ // 根据域名获取网站信息
+ StringBuffer urlBuf = request.getRequestURL();
+ URL url = new URL(urlBuf.toString());
+ String path = url.getPath();
+ HttpServletResponse response = (HttpServletResponse)attributes.getResponse();
+ String hospitalHost = request.getHeader("hospitalHost");
+// if(StringUtils.isEmpty(hospitalHost)){
+// return;
+// }
+
+ //切割获取访问目标模块
+ String[] split = path.split("/");
+ String module = split[0];
+ System.out.println(RedisUtils.getDBInfoByHostAndModule(stringRedisTemplate,hospitalHost,"admin"));
+ //根据域名和请求的模块名查询目标数据库
+ HttpSession session = request.getSession();
+ /**
+ * 切换为动态数据源实例
+ */
+ HspHostUtil.switchDB(hospitalHost,"admin",stringRedisTemplate);
+
+ }
+ //执行完切面后,将线程共享中的数据源名称清空
+ @After("webLog()")
+ public void after(JoinPoint joinPoint){
+ DataSourceContextHolder.clearDBType();
+ }
+}
+
diff --git a/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/config/CorsConfig.java b/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/config/CorsConfig.java
new file mode 100644
index 0000000..d424881
--- /dev/null
+++ b/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/config/CorsConfig.java
@@ -0,0 +1,36 @@
+package com.recovery.admin.boot.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+
+//跨越请求配置类
+@Configuration
+public class CorsConfig {
+
+ private CorsConfiguration buildConfig() {
+ CorsConfiguration corsConfiguration = new CorsConfiguration();
+ // 你需要跨域的地址 注意这里的 127.0.0.1 != localhost
+ // * 表示对所有的地址都可以访问
+ corsConfiguration.addAllowedOrigin("*"); // 1
+ // 跨域的请求头
+ corsConfiguration.addAllowedHeader("*"); // 2
+ // 跨域的请求方法
+ corsConfiguration.addAllowedMethod("*"); // 3
+ //加上了这一句,大致意思是可以携带 cookie
+ //最终的结果是可以 在跨域请求的时候获取同一个 session
+ corsConfiguration.setAllowCredentials(true);
+ return corsConfiguration;
+ }
+ @Bean
+ public CorsFilter corsFilter() {
+
+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
+ //配置 可以访问的地址
+ source.registerCorsConfiguration("/**", buildConfig());
+ return new CorsFilter(source);
+ }
+
+}
diff --git a/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/config/InterceptConfig.java b/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/config/InterceptConfig.java
new file mode 100644
index 0000000..092ef34
--- /dev/null
+++ b/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/config/InterceptConfig.java
@@ -0,0 +1,25 @@
+package com.recovery.admin.boot.config;
+
+
+import com.recovery.admin.boot.interceptor.JwtInterceptor;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+
+@Configuration
+public class InterceptConfig implements WebMvcConfigurer {
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ //添加拦截器
+ registry.addInterceptor(new JwtInterceptor())
+ //拦截的路径 需要进行token验证的路径
+ .addPathPatterns("/**")
+ //放行的路径
+ .excludePathPatterns("/api/rest/users/getUserByUsername")
+ .excludePathPatterns("/api/user/sendMsg")
+ .excludePathPatterns("/api/user/loginPhone")
+ //放行swagger 测试验证
+ .excludePathPatterns("/api/user/get");
+ }
+}
diff --git a/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/config/ds/DataSourceConfig.java b/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/config/ds/DataSourceConfig.java
new file mode 100644
index 0000000..2d17563
--- /dev/null
+++ b/hoe-admin/admin-boot/src/main/java/com/recovery/admin/boot/config/ds/DataSourceConfig.java
@@ -0,0 +1,96 @@
+package com.recovery.admin.boot.config.ds;
+
+import com.alibaba.druid.pool.DruidDataSource;
+
+import com.recovery.common.base.ds.DynamicDataSource;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.mybatis.spring.SqlSessionFactoryBean;
+import org.mybatis.spring.SqlSessionTemplate;
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+
+import javax.sql.DataSource;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by YHYR on 2017-12-25
+ */
+@Slf4j
+@Configuration
+@MapperScan(basePackages = DataSourceConfig.PACKAGE, sqlSessionFactoryRef = "commonSqlSessionFactory")
+public class DataSourceConfig {
+
+ // 精确到模块目录,以便跟其他数据源隔离
+ static final String PACKAGE = "com.recovery.admin.boot.mapper";
+ static final String MAPPER_LOCATION = "classpath:mapper/*.xml";
+
+ @Value("${master.datasource.url}")
+ private String masterDBUrl;
+
+ @Value("${master.datasource.username}")
+ private String masterDBUser;
+
+ @Value("${master.datasource.password}")
+ private String masterDBPassword;
+
+ @Value("${master.datasource.driverClassName}")
+ private String masterDBDreiverName;
+
+
+ @Bean(name = "commonDataSource")
+ @Primary
+ public DynamicDataSource dynamicDataSource(){
+ DynamicDataSource dynamicDataSource = DynamicDataSource.getInstance();
+
+ DruidDataSource masterDataSource = new DruidDataSource();
+ try {
+ masterDataSource.setUrl(masterDBUrl);
+ masterDataSource.setUsername(masterDBUser);
+ masterDataSource.setPassword(masterDBPassword);
+ masterDataSource.setDriverClassName(masterDBDreiverName);
+ }catch (Exception e){
+ log.error(e.getMessage());
+ }
+
+ Map