Merge branch 'dev.wei' of https://gitea.qinmian.online/a_bazu/cloud-server-8 into dev.wei
commit
10b63954a4
|
@ -123,5 +123,6 @@ public class SysLoginService {
|
||||||
throw new ServiceException(registerResult.getMsg());
|
throw new ServiceException(registerResult.getMsg());
|
||||||
}
|
}
|
||||||
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
|
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 47.116.173.119:8848
|
addr: 159.75.188.178:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: eight
|
namespace: eight
|
||||||
|
|
|
@ -11,6 +11,11 @@ public class SecurityConstants {
|
||||||
*/
|
*/
|
||||||
public static final String DETAILS_USER_ID = "user_id";
|
public static final String DETAILS_USER_ID = "user_id";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业ID字段
|
||||||
|
*/
|
||||||
|
public static final String DETAILS_FIRM_ID = "firm_id";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户名字段
|
* 用户名字段
|
||||||
*/
|
*/
|
||||||
|
@ -45,4 +50,6 @@ public class SecurityConstants {
|
||||||
* 角色权限
|
* 角色权限
|
||||||
*/
|
*/
|
||||||
public static final String ROLE_PERMISSION = "role_permission";
|
public static final String ROLE_PERMISSION = "role_permission";
|
||||||
|
|
||||||
|
public static final String SAAS_KEY = "ent_code";
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,4 +21,9 @@ public class TokenConstants {
|
||||||
*/
|
*/
|
||||||
public final static String SECRET = "abcdefghijklmnsalieopadfaqawefwerstuvwxyz";
|
public final static String SECRET = "abcdefghijklmnsalieopadfaqawefwerstuvwxyz";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token
|
||||||
|
*/
|
||||||
|
private static final String TOKEN = "token";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ package com.muyu.common.core.exception;
|
||||||
*
|
*
|
||||||
* @author muyu
|
* @author muyu
|
||||||
*/
|
*/
|
||||||
public final class ServiceException extends RuntimeException {
|
public class ServiceException extends RuntimeException {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>cloud-common-saas</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- 鉴权依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-security</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-datasource</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,98 @@
|
||||||
|
package com.muyu.cloud.common.many.datasource;
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
||||||
|
import com.muyu.cloud.common.many.datasource.constents.DatasourceContent;
|
||||||
|
import com.muyu.cloud.common.many.datasource.domain.model.DataSourceInfo;
|
||||||
|
import com.muyu.cloud.common.many.datasource.factory.DruidDataSourceFactory;
|
||||||
|
import com.muyu.cloud.common.many.datasource.role.DynamicDataSource;
|
||||||
|
import com.muyu.cloud.common.saas.domain.model.EntInfo;
|
||||||
|
import com.muyu.cloud.common.saas.exception.SaaSException;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.common.core.utils.SpringUtils;
|
||||||
|
import com.muyu.common.system.domain.SysUser;
|
||||||
|
import com.muyu.common.system.remote.RemoteUserService;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: DongZeLiang
|
||||||
|
* @date: 2024/6/3
|
||||||
|
* @Description: 多数据源
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
@Component
|
||||||
|
@AutoConfiguration(before = MybatisPlusAutoConfiguration.class)
|
||||||
|
public class ManyDataSource implements ApplicationRunner{
|
||||||
|
|
||||||
|
|
||||||
|
private List<EntInfo> dataSourceInfoList(){
|
||||||
|
RemoteUserService remoteUserService = SpringUtils.getBean(RemoteUserService.class);
|
||||||
|
Result<List<SysUser>> tableDataInfoResult = remoteUserService.companyList();
|
||||||
|
if (tableDataInfoResult==null){
|
||||||
|
throw new SaaSException("saas远调数据源错误");
|
||||||
|
}
|
||||||
|
List<SysUser> data = tableDataInfoResult.getData();
|
||||||
|
if (tableDataInfoResult.getCode() ==Result.SUCCESS && data !=null){
|
||||||
|
List<EntInfo> list = new ArrayList<>();
|
||||||
|
for (SysUser row : data) {
|
||||||
|
list.add(
|
||||||
|
EntInfo.builder()
|
||||||
|
.entCode(row.getDatabaseName())
|
||||||
|
.ip(DatasourceContent.IP)
|
||||||
|
.port(DatasourceContent.PORT)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}else {
|
||||||
|
log.error("远调数据源错误,远调数据为:{}", JSON.toJSONString(data));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
|
||||||
|
// 企业列表 企业CODE,端口,IP
|
||||||
|
Map<Object, Object> dataSourceMap = new HashMap<>();
|
||||||
|
dataSourceInfoList()
|
||||||
|
.stream()
|
||||||
|
.map(entInfo -> DataSourceInfo.hostAndPortBuild(entInfo.getEntCode(), entInfo.getIp(), entInfo.getPort()))
|
||||||
|
.forEach(dataSourceInfo -> {
|
||||||
|
dataSourceMap.put(dataSourceInfo.getKey(), druidDataSourceFactory.create(dataSourceInfo));
|
||||||
|
});
|
||||||
|
//设置动态数据源
|
||||||
|
DynamicDataSource dynamicDataSource = new DynamicDataSource();
|
||||||
|
// dynamicDataSource.setDefaultTargetDataSource(masterDataSource());
|
||||||
|
dynamicDataSource.setTargetDataSources(dataSourceMap);
|
||||||
|
//将数据源信息备份在defineTargetDataSources中
|
||||||
|
dynamicDataSource.setDefineTargetDataSources(dataSourceMap);
|
||||||
|
return dynamicDataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments args) {
|
||||||
|
DruidDataSourceFactory druidDataSourceFactory = SpringUtils.getBean(DruidDataSourceFactory.class);
|
||||||
|
DynamicDataSource dynamicDataSource = SpringUtils.getBean(DynamicDataSource.class);
|
||||||
|
for (EntInfo entInfo : dataSourceInfoList()) {
|
||||||
|
DataSourceInfo dataSourceInfo = DataSourceInfo.hostAndPortBuild(
|
||||||
|
entInfo.getEntCode(), entInfo.getIp(), entInfo.getPort()
|
||||||
|
);
|
||||||
|
DruidDataSource druidDataSource = druidDataSourceFactory.create(dataSourceInfo);
|
||||||
|
dynamicDataSource.put(dataSourceInfo.getKey(), druidDataSource);
|
||||||
|
log.info("存储数据连接池为:key:{}",dataSourceInfo.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package com.muyu.cloud.common.many.datasource.constents;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 数据源常量
|
||||||
|
* @Date 2023-8-1 上午 11:02
|
||||||
|
*/
|
||||||
|
public class DatasourceContent {
|
||||||
|
|
||||||
|
public final static String DATASOURCE_URL = "jdbc:mysql://{}:{}/{}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
|
||||||
|
|
||||||
|
public final static String USER_NAME = "root";
|
||||||
|
|
||||||
|
public final static String PASSWORD = "root";
|
||||||
|
|
||||||
|
public final static String IP = "159.75.188.178";
|
||||||
|
|
||||||
|
public final static Integer PORT = 3306;
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.muyu.cloud.common.many.datasource.domain.model;
|
||||||
|
|
||||||
|
import com.muyu.cloud.common.many.datasource.constents.DatasourceContent;
|
||||||
|
import com.muyu.common.core.utils.StringUtils;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 数据源实体类
|
||||||
|
* @Date 2023-8-1 上午 11:15
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DataSourceInfo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 键
|
||||||
|
*/
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地址
|
||||||
|
*/
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
|
||||||
|
public static DataSourceInfo hostAndPortBuild(String key, String host, Integer port) {
|
||||||
|
return DataSourceInfo.builder()
|
||||||
|
.key(key)
|
||||||
|
.url(StringUtils.format(DatasourceContent.DATASOURCE_URL, host, port, key))
|
||||||
|
.password(DatasourceContent.PASSWORD)
|
||||||
|
.userName(DatasourceContent.USER_NAME)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.muyu.cloud.common.many.datasource.factory;
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
import com.muyu.cloud.common.many.datasource.domain.model.DataSourceInfo;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: DongZeLiang
|
||||||
|
* @date: 2024/6/3
|
||||||
|
* @Description: Druid工厂
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
@Component
|
||||||
|
public class DruidDataSourceFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 根据传递的数据源信息测试数据库连接
|
||||||
|
* @Author Dongzl
|
||||||
|
*/
|
||||||
|
public DruidDataSource create(DataSourceInfo dataSourceInfo) {
|
||||||
|
DruidDataSource druidDataSource = new DruidDataSource();
|
||||||
|
druidDataSource.setUrl(dataSourceInfo.getUrl());
|
||||||
|
druidDataSource.setUsername(dataSourceInfo.getUserName());
|
||||||
|
druidDataSource.setPassword(dataSourceInfo.getPassword());
|
||||||
|
druidDataSource.setBreakAfterAcquireFailure(true);
|
||||||
|
druidDataSource.setConnectionErrorRetryAttempts(0);
|
||||||
|
try {
|
||||||
|
druidDataSource.getConnection(2000);
|
||||||
|
log.info("{} -> 数据源连接成功", dataSourceInfo.getKey());
|
||||||
|
return druidDataSource;
|
||||||
|
} catch (SQLException throwables) {
|
||||||
|
log.error("数据源 {} 连接失败,用户名:{},密码 {}",dataSourceInfo.getUrl(),dataSourceInfo.getUserName(),dataSourceInfo.getPassword());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.muyu.cloud.common.many.datasource.holder;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源切换处理
|
||||||
|
*
|
||||||
|
* @author Dongzl
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class DynamicDataSourceHolder {
|
||||||
|
/**
|
||||||
|
* 保存动态数据源名称
|
||||||
|
*/
|
||||||
|
private static final ThreadLocal<String> DYNAMIC_DATASOURCE_KEY = new ThreadLocal<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置/切换数据源,决定当前线程使用哪个数据源
|
||||||
|
*/
|
||||||
|
public static void setDynamicDataSourceKey(String key){
|
||||||
|
log.info("数据源切换为:{}",key);
|
||||||
|
DYNAMIC_DATASOURCE_KEY.set(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取动态数据源名称,默认使用mater数据源
|
||||||
|
*/
|
||||||
|
public static String getDynamicDataSourceKey(){
|
||||||
|
String key = DYNAMIC_DATASOURCE_KEY.get();
|
||||||
|
Assert.notNull(key, "请携带数据标识");
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除当前数据源
|
||||||
|
*/
|
||||||
|
public static void removeDynamicDataSourceKey(){
|
||||||
|
log.info("移除数据源:{}",DYNAMIC_DATASOURCE_KEY.get());
|
||||||
|
DYNAMIC_DATASOURCE_KEY.remove();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.muyu.cloud.common.many.datasource.role;
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
import com.muyu.cloud.common.many.datasource.holder.DynamicDataSourceHolder;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态数据源
|
||||||
|
* 调用AddDefineDataSource组件的addDefineDynamicDataSource()方法,获取原来targetdatasources的map,并将新的数据源信息添加到map中,并替换targetdatasources中的map
|
||||||
|
* 切换数据源时可以使用@DataSource(value = "数据源名称"),或者DynamicDataSourceContextHolder.setContextKey("数据源名称")
|
||||||
|
* @author Dongzl
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class DynamicDataSource extends AbstractRoutingDataSource {
|
||||||
|
/**
|
||||||
|
* 备份所有数据源信息
|
||||||
|
*/
|
||||||
|
private Map<Object, Object> defineTargetDataSources;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param key 键
|
||||||
|
* @return 存在结果 true存在 false不存在
|
||||||
|
*/
|
||||||
|
public boolean hashKey(String key){
|
||||||
|
return defineTargetDataSources.containsKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加数据库
|
||||||
|
* @param key 键
|
||||||
|
* @param value 数据源
|
||||||
|
*/
|
||||||
|
public void put(String key, DruidDataSource value) {
|
||||||
|
defineTargetDataSources.put(key, value);
|
||||||
|
this.afterPropertiesSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 决定当前线程使用哪个数据源
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Object determineCurrentLookupKey() {
|
||||||
|
return DynamicDataSourceHolder.getDynamicDataSourceKey();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.muyu.cloud.common.saas.contents;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: DongZeLiang
|
||||||
|
* @date: 2024/6/3
|
||||||
|
* @Description: SAAS常量
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public class SaaSConstant {
|
||||||
|
|
||||||
|
public final static String SAAS_KEY = "ent-code";
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.muyu.cloud.common.saas.domain.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: DongZeLiang
|
||||||
|
* @date: 2024/6/3
|
||||||
|
* @Description: 企业信息
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class EntInfo {
|
||||||
|
|
||||||
|
private String entCode;
|
||||||
|
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
private Integer port;
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.muyu.cloud.common.saas.exception;
|
||||||
|
|
||||||
|
|
||||||
|
import com.muyu.common.core.exception.ServiceException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: DongZeLiang
|
||||||
|
* @date: 2024/6/3
|
||||||
|
* @Description: SaaS异常类
|
||||||
|
* @Version: 1.0
|
||||||
|
*/
|
||||||
|
public class SaaSException extends ServiceException {
|
||||||
|
|
||||||
|
public SaaSException (String message, Integer code) {
|
||||||
|
super(message, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SaaSException (String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 空构造方法,避免反序列化问题
|
||||||
|
*/
|
||||||
|
public SaaSException () {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.muyu.cloud.common.saas.interceptor;
|
||||||
|
|
||||||
|
import com.muyu.cloud.common.many.datasource.holder.DynamicDataSourceHolder;
|
||||||
|
import com.muyu.cloud.common.many.datasource.role.DynamicDataSource;
|
||||||
|
import com.muyu.cloud.common.saas.contents.SaaSConstant;
|
||||||
|
import com.muyu.cloud.common.saas.exception.SaaSException;
|
||||||
|
import com.muyu.common.core.utils.ServletUtils;
|
||||||
|
import com.muyu.common.core.utils.SpringUtils;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.web.method.HandlerMethod;
|
||||||
|
import org.springframework.web.servlet.AsyncHandlerInterceptor;
|
||||||
|
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
|
public class SaaSInterceptor implements AsyncHandlerInterceptor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 之前
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean preHandle (HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
|
if (!(handler instanceof HandlerMethod)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String SaaSKey = ServletUtils.getHeader(request, SaaSConstant.SAAS_KEY);
|
||||||
|
if (SaaSKey == null) {
|
||||||
|
throw new SaaSException("SaaS非法访问");
|
||||||
|
}else {
|
||||||
|
DynamicDataSource dynamicDataSource = SpringUtils.getBean(DynamicDataSource.class);
|
||||||
|
if (!dynamicDataSource.hashKey(SaaSKey)){
|
||||||
|
throw new SaaSException("SaaS非法访问");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DynamicDataSourceHolder.setDynamicDataSourceKey(SaaSKey);
|
||||||
|
log.info("SaaS拦截器拦截到请求,设置数据源为:{}", SaaSKey);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 之后
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void afterConcurrentHandlingStarted (HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
|
DynamicDataSourceHolder.removeDynamicDataSourceKey();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.muyu.cloud.common.saas.interceptor;
|
||||||
|
|
||||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拦截器配置
|
||||||
|
*
|
||||||
|
* @author muyu
|
||||||
|
*/
|
||||||
|
public class WebMvcSaaSConfig implements WebMvcConfigurer {
|
||||||
|
/**
|
||||||
|
* 不需要拦截的地址
|
||||||
|
*/
|
||||||
|
public static final String[] excludeUrls = {"/login", "/logout", "/refresh"};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInterceptors (InterceptorRegistry registry) {
|
||||||
|
registry.addInterceptor(getHeaderInterceptor())
|
||||||
|
.addPathPatterns("/**")
|
||||||
|
.excludePathPatterns(excludeUrls)
|
||||||
|
.order(-10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义请求头拦截器
|
||||||
|
*/
|
||||||
|
public SaaSInterceptor getHeaderInterceptor () {
|
||||||
|
return new SaaSInterceptor();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
com.muyu.cloud.common.saas.interceptor.WebMvcSaaSConfig
|
||||||
|
com.muyu.cloud.common.many.datasource.ManyDataSource
|
||||||
|
com.muyu.cloud.common.many.datasource.factory.DruidDataSourceFactory
|
|
@ -55,11 +55,13 @@ public class TokenService {
|
||||||
claimsMap.put(SecurityConstants.USER_KEY, token);
|
claimsMap.put(SecurityConstants.USER_KEY, token);
|
||||||
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
|
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
|
||||||
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
|
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
|
||||||
|
claimsMap.put(SecurityConstants.SAAS_KEY,loginUser.getSysUser().getDatabaseName());
|
||||||
|
|
||||||
// 接口返回信息
|
// 接口返回信息
|
||||||
Map<String, Object> rspMap = new HashMap<String, Object>();
|
Map<String, Object> rspMap = new HashMap<String, Object>();
|
||||||
rspMap.put("access_token", JwtUtils.createToken(claimsMap));
|
rspMap.put("access_token", JwtUtils.createToken(claimsMap));
|
||||||
rspMap.put("expires_in", expireTime);
|
rspMap.put("expires_in", expireTime);
|
||||||
|
|
||||||
return rspMap;
|
return rspMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.muyu.common.system.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张腾
|
||||||
|
* @Package:com.muyu.common.system.domain
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:DatasourceInfo
|
||||||
|
* @Date:2024/9/18 19:25
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DatasourceInfo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 键
|
||||||
|
*/
|
||||||
|
private String key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地址
|
||||||
|
*/
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
package com.muyu.common.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张腾
|
||||||
|
* @Package:com.muyu.common.system.domain
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:SysFirm
|
||||||
|
* @Date:2024/9/18 19:04
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName(value = "sys_firm",autoResultMap = true)
|
||||||
|
public class SysFirm extends BaseEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*自增主键
|
||||||
|
*/
|
||||||
|
@TableId(value = "id",type = IdType.AUTO)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*统一社会信用代码
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "统一社会信用代码不能为空")
|
||||||
|
private String firmCreditCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*企业营业执照
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "请上传对应的营业执照")
|
||||||
|
private String firmImages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*企业名称
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "企业名称不能为空")
|
||||||
|
private String firmName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*企业LOGO
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "请上传企业logo")
|
||||||
|
private String firmLogo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*企业法人
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "企业法人不能为空")
|
||||||
|
private String firmLegalPerson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*联系电话
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "请输入联系电话")
|
||||||
|
private String firmPhone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*联系邮箱
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "请输入联系邮箱")
|
||||||
|
private String firmEmail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*联系网址
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "联系网址不能为空")
|
||||||
|
private String firmWebsite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*企业地址
|
||||||
|
*/
|
||||||
|
@NotBlank(message = "企业地址不能为空")
|
||||||
|
private String firmAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*企业描述
|
||||||
|
*/
|
||||||
|
private String firmDesc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属数据库
|
||||||
|
*/
|
||||||
|
private String databaseName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*启用状态(1.开业 2.停业 3.休业)
|
||||||
|
*/
|
||||||
|
private Integer state;
|
||||||
|
}
|
|
@ -83,6 +83,16 @@ public class SysUser extends BaseEntity {
|
||||||
*/
|
*/
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业ID
|
||||||
|
*/
|
||||||
|
private Integer firmId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所属数据库
|
||||||
|
*/
|
||||||
|
private String databaseName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 帐号状态(0正常 1停用)
|
* 帐号状态(0正常 1停用)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -9,6 +9,8 @@ import com.muyu.common.system.domain.LoginUser;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户服务
|
* 用户服务
|
||||||
*
|
*
|
||||||
|
@ -37,4 +39,7 @@ public interface RemoteUserService {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/user/register")
|
@PostMapping("/user/register")
|
||||||
public Result<Boolean> registerUserInfo (@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
public Result<Boolean> registerUserInfo (@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||||
|
|
||||||
|
@GetMapping("/user/companyList")
|
||||||
|
public Result<List<SysUser>> companyList ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户服务降级处理
|
* 用户服务降级处理
|
||||||
*
|
*
|
||||||
|
@ -31,6 +33,11 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
||||||
public Result<Boolean> registerUserInfo (SysUser sysUser, String source) {
|
public Result<Boolean> registerUserInfo (SysUser sysUser, String source) {
|
||||||
return Result.error("注册用户失败:" + throwable.getMessage());
|
return Result.error("注册用户失败:" + throwable.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<List<SysUser>> companyList() {
|
||||||
|
return Result.error("发现用户失败:" + throwable.getMessage());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
<module>cloud-common-system</module>
|
<module>cloud-common-system</module>
|
||||||
<module>cloud-common-xxl</module>
|
<module>cloud-common-xxl</module>
|
||||||
<module>cloud-common-rabbit</module>
|
<module>cloud-common-rabbit</module>
|
||||||
|
<module>cloud-common-saas</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>cloud-common</artifactId>
|
<artifactId>cloud-common</artifactId>
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class ValidateCodeServiceImpl implements ValidateCodeService {
|
||||||
CaptchaCodeResp.CaptchaCodeRespBuilder respBuilder = CaptchaCodeResp.builder()
|
CaptchaCodeResp.CaptchaCodeRespBuilder respBuilder = CaptchaCodeResp.builder()
|
||||||
.captchaEnabled(captchaEnabled);
|
.captchaEnabled(captchaEnabled);
|
||||||
if (!captchaEnabled) {
|
if (!captchaEnabled) {
|
||||||
return Result.success(respBuilder);
|
return Result.success(respBuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存验证码信息
|
// 保存验证码信息
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 47.116.173.119:8848
|
addr: 159.75.188.178:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: eight
|
namespace: eight
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 47.116.173.119:8848
|
addr: 159.75.188.178:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: eight
|
namespace: eight
|
||||||
|
|
|
@ -65,11 +65,6 @@
|
||||||
<artifactId>cloud-common-api-doc</artifactId>
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- XllJob定时任务 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-xxl</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代码生成
|
* 代码生成
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 47.116.173.119:8848
|
addr: 159.75.188.178:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: eight
|
namespace: eight
|
||||||
|
|
|
@ -71,15 +71,14 @@
|
||||||
<artifactId>cloud-common-api-doc</artifactId>
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- XllJob定时任务 -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-xxl</artifactId>
|
<artifactId>cloud-common-rabbit</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-rabbit</artifactId>
|
<artifactId>cloud-common-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.system;
|
||||||
|
|
||||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.muyu.system.config;
|
||||||
|
|
||||||
|
import com.muyu.system.interceptor.DataSourceInterceptor;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张腾
|
||||||
|
* @Package:com.muyu.system.config
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:WebConfig
|
||||||
|
* @Date:2024/9/18 19:51
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class WebConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInterceptors(InterceptorRegistry registry) {
|
||||||
|
registry.addInterceptor(new DataSourceInterceptor())
|
||||||
|
.addPathPatterns("/**")
|
||||||
|
.excludePathPatterns("/");
|
||||||
|
}
|
||||||
|
}
|
|
@ -114,6 +114,12 @@ public class SysUserController extends BaseController {
|
||||||
return Result.success(sysUserVo);
|
return Result.success(sysUserVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/companyList")
|
||||||
|
public Result<List<SysUser>> list(){
|
||||||
|
List<SysUser> list = userService.companyList();
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册用户信息
|
* 注册用户信息
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.muyu.system.holder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张腾
|
||||||
|
* @Package:com.muyu.system.holder
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:DataSourcceContextHolder
|
||||||
|
* @Date:2024/9/18 19:45
|
||||||
|
*/
|
||||||
|
public class DataSourceContextHolder {
|
||||||
|
private static final ThreadLocal<String> DYNAMIC_DATASOURCE_KEY = new ThreadLocal<>();
|
||||||
|
|
||||||
|
public static void setDatasourceMsg(String datasourceKey){
|
||||||
|
DYNAMIC_DATASOURCE_KEY.set(datasourceKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDatasourceMsg(){
|
||||||
|
return DYNAMIC_DATASOURCE_KEY.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearDataSourceKey(){
|
||||||
|
DYNAMIC_DATASOURCE_KEY.remove();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.muyu.system.interceptor;
|
||||||
|
|
||||||
|
import com.muyu.system.holder.DataSourceContextHolder;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张腾
|
||||||
|
* @Package:com.muyu.system.interceptor
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:DataSourceInterceptor
|
||||||
|
* @Date:2024/9/18 19:40
|
||||||
|
*/
|
||||||
|
public class DataSourceInterceptor implements HandlerInterceptor {
|
||||||
|
@Override
|
||||||
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||||
|
//从请求当中获取数据源标识符
|
||||||
|
String database = request.getParameter("database");
|
||||||
|
if (null != database){
|
||||||
|
DataSourceContextHolder.setDatasourceMsg(database);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||||
|
//请求完成之后进行清理操作
|
||||||
|
DataSourceContextHolder.clearDataSourceKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||||
|
//请求完成之后进行清理操作
|
||||||
|
DataSourceContextHolder.clearDataSourceKey();
|
||||||
|
}
|
||||||
|
}
|
|
@ -139,4 +139,7 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public SysUser checkEmailUnique (String email);
|
public SysUser checkEmailUnique (String email);
|
||||||
|
|
||||||
|
List<SysUser> companyList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,4 +225,7 @@ public interface SysUserService extends IService<SysUser> {
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public String importUser (List<SysUser> userList, Boolean isUpdateSupport, String operName);
|
public String importUser (List<SysUser> userList, Boolean isUpdateSupport, String operName);
|
||||||
|
|
||||||
|
List<SysUser> companyList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -500,4 +500,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||||
return successMsg.toString();
|
return successMsg.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysUser> companyList() {
|
||||||
|
return userMapper.companyList();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 47.116.173.119:8848
|
addr: 159.75.188.178:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: eight
|
namespace: eight
|
||||||
|
|
|
@ -183,6 +183,9 @@
|
||||||
and del_flag = '0'
|
and del_flag = '0'
|
||||||
limit 1
|
limit 1
|
||||||
</select>
|
</select>
|
||||||
|
<select id="companyList" resultType="com.muyu.common.system.domain.SysUser">
|
||||||
|
select * from sys_user where sys_user.database_name != ''
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="insertUser" parameterType="com.muyu.common.system.domain.SysUser" useGeneratedKeys="true" keyProperty="userId">
|
<insert id="insertUser" parameterType="com.muyu.common.system.domain.SysUser" useGeneratedKeys="true" keyProperty="userId">
|
||||||
insert into sys_user(
|
insert into sys_user(
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-modules</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>cloud-test</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<!-- SpringCloud Alibaba Nacos -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SpringCloud Alibaba Nacos Config -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SpringCloud Alibaba Sentinel -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- SpringBoot Actuator -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Mysql Connector -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- MuYu Common DataSource -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-datasource</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- MuYu Common DataScope -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-datascope</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- MuYu Common Log -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-log</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 接口模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.muyu.test;
|
||||||
|
|
||||||
|
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张腾
|
||||||
|
* @Package:com.muyu.test
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:TestApplication
|
||||||
|
* @Date:2024/9/20 19:16
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableMyFeignClients
|
||||||
|
public class TestApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(TestApplication.class,args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.muyu.test.controller;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.test.domain.User;
|
||||||
|
import com.muyu.test.service.UserService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张腾
|
||||||
|
* @Package:com.muyu.test.controller
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:UserController
|
||||||
|
* @Date:2024/9/20 19:14
|
||||||
|
*/
|
||||||
|
@RestController("/admin")
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@GetMapping("/selectAll")
|
||||||
|
public Result<List<User>> selectAll(){
|
||||||
|
List<User> list = userService.list();
|
||||||
|
list.forEach(System.out::println);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.muyu.test.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张腾
|
||||||
|
* @Package:com.muyu.test.domain
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:User
|
||||||
|
* @Date:2024/9/20 19:11
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@TableName(value = "user",autoResultMap = true)
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
@TableId(value = "user_id")
|
||||||
|
private Integer userId;
|
||||||
|
|
||||||
|
private String userName;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.muyu.test.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.muyu.test.domain.User;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张腾
|
||||||
|
* @Package:com.muyu.test.mapper
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:UserMapper
|
||||||
|
* @Date:2024/9/20 19:13
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface UserMapper extends BaseMapper<User> {
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.muyu.test.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.muyu.test.domain.User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张腾
|
||||||
|
* @Package:com.muyu.test.service
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:UserService
|
||||||
|
* @Date:2024/9/20 19:13
|
||||||
|
*/
|
||||||
|
public interface UserService extends IService<User> {
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.muyu.test.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.muyu.test.domain.User;
|
||||||
|
import com.muyu.test.mapper.UserMapper;
|
||||||
|
import com.muyu.test.service.UserService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:张腾
|
||||||
|
* @Package:com.muyu.test.service.impl
|
||||||
|
* @Project:cloud-server-8
|
||||||
|
* @name:UserServiceImpl
|
||||||
|
* @Date:2024/9/20 19:14
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class UserServiceImpl
|
||||||
|
extends ServiceImpl<UserMapper, User> implements UserService {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -12,6 +12,7 @@
|
||||||
<module>cloud-modules-system</module>
|
<module>cloud-modules-system</module>
|
||||||
<module>cloud-modules-gen</module>
|
<module>cloud-modules-gen</module>
|
||||||
<module>cloud-modules-file</module>
|
<module>cloud-modules-file</module>
|
||||||
|
<module>cloud-test</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<artifactId>cloud-modules</artifactId>
|
<artifactId>cloud-modules</artifactId>
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 47.116.173.119:8848
|
addr: 159.75.188.178:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: eight
|
namespace: eight
|
||||||
|
|
Loading…
Reference in New Issue