text(测试使用mq初始化多数据源)
parent
d2b6292163
commit
4de52d3810
|
@ -24,5 +24,6 @@ public class ServiceNameConstants {
|
||||||
* 文件服务的serviceid
|
* 文件服务的serviceid
|
||||||
*/
|
*/
|
||||||
public static final String FILE_SERVICE = "ruoyi-file";
|
public static final String FILE_SERVICE = "ruoyi-file";
|
||||||
|
public static final String MANY_ENTERPRISE = "ruoyi-many";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,6 @@ public class ManyDataSource {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Primary
|
@Primary
|
||||||
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
|
public DynamicDataSource dynamicDataSource(DruidDataSourceFactory druidDataSourceFactory) {
|
||||||
|
@ -69,6 +68,7 @@ public class ManyDataSource {
|
||||||
.forEach(dataSourceInfo -> {
|
.forEach(dataSourceInfo -> {
|
||||||
dataSourceMap.put(dataSourceInfo.getKey(), druidDataSourceFactory.create(dataSourceInfo));
|
dataSourceMap.put(dataSourceInfo.getKey(), druidDataSourceFactory.create(dataSourceInfo));
|
||||||
});
|
});
|
||||||
|
|
||||||
//设置动态数据源
|
//设置动态数据源
|
||||||
DynamicDataSource dynamicDataSource = new DynamicDataSource();
|
DynamicDataSource dynamicDataSource = new DynamicDataSource();
|
||||||
// dynamicDataSource.setDefaultTargetDataSource(masterDataSource());
|
// dynamicDataSource.setDefaultTargetDataSource(masterDataSource());
|
||||||
|
|
|
@ -7,7 +7,7 @@ package com.muyu.clw.common.many.datasource.constents;
|
||||||
*/
|
*/
|
||||||
public class DatasourceContent {
|
public class DatasourceContent {
|
||||||
|
|
||||||
public final static String DATASOURCE_URL = "jdbc:mysql://{}:{}/car?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
|
public final static String DATASOURCE_URL = "jdbc:mysql://{}:{}/car?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&failOverReadOnly=false";
|
||||||
|
|
||||||
public final static String USER_NAME = "root";
|
public final static String USER_NAME = "root";
|
||||||
|
|
||||||
|
|
|
@ -29,13 +29,8 @@ public class DruidDataSourceFactory {
|
||||||
druidDataSource.setPassword(dataSourceInfo.getPassword());
|
druidDataSource.setPassword(dataSourceInfo.getPassword());
|
||||||
druidDataSource.setBreakAfterAcquireFailure(true);
|
druidDataSource.setBreakAfterAcquireFailure(true);
|
||||||
druidDataSource.setConnectionErrorRetryAttempts(0);
|
druidDataSource.setConnectionErrorRetryAttempts(0);
|
||||||
try {
|
druidDataSource.setMaxActive(20); // 设置最大活动连接数为 20
|
||||||
druidDataSource.getConnection(2000);
|
log.info( "{}->数据源连接成功", dataSourceInfo.getKey());
|
||||||
log.info("{} -> 数据源连接成功", dataSourceInfo.getKey());
|
|
||||||
return druidDataSource;
|
return druidDataSource;
|
||||||
} catch (SQLException throwables) {
|
|
||||||
log.error("数据源 {} 连接失败,用户名:{},密码 {}",dataSourceInfo.getUrl(),dataSourceInfo.getUserName(),dataSourceInfo.getPassword());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -20,6 +21,7 @@ import java.util.Map;
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@Log4j2
|
||||||
public class DynamicDataSource extends AbstractRoutingDataSource {
|
public class DynamicDataSource extends AbstractRoutingDataSource {
|
||||||
//备份所有数据源信息,备份的是个 指针 !!!
|
//备份所有数据源信息,备份的是个 指针 !!!
|
||||||
private Map<Object, Object> defineTargetDataSources;
|
private Map<Object, Object> defineTargetDataSources;
|
||||||
|
@ -40,6 +42,7 @@ public class DynamicDataSource extends AbstractRoutingDataSource {
|
||||||
*/
|
*/
|
||||||
public void put(String key, DruidDataSource value) {
|
public void put(String key, DruidDataSource value) {
|
||||||
defineTargetDataSources.put(key, value);
|
defineTargetDataSources.put(key, value);
|
||||||
|
log.info("都有哪些数据:{}",defineTargetDataSources);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 决定当前线程使用哪个数据源
|
* 决定当前线程使用哪个数据源
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
com.muyu.common.system.remote.factory.RemoteUserFallbackFactory
|
|
||||||
com.muyu.common.system.remote.factory.RemoteLogFallbackFactory
|
|
||||||
com.muyu.common.system.remote.factory.RemoteFileFallbackFactory
|
com.muyu.common.system.remote.factory.RemoteFileFallbackFactory
|
||||||
|
com.muyu.common.system.remote.factory.RemoteLogFallbackFactory
|
||||||
|
com.muyu.common.system.remote.factory.RemoteUserFallbackFactory
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.muyu.domain;
|
package com.muyu.domain;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
@ -26,7 +27,7 @@ import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@TableName("enterprise")
|
@TableName("enterprise")
|
||||||
public class Enterprise extends BaseEntity
|
public class Enterprise extends BaseEntity implements Serializable
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
|
@ -107,5 +107,9 @@
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>muyu-common-system</artifactId>
|
<artifactId>muyu-common-system</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -11,8 +11,7 @@ import com.muyu.domain.Enterprise;
|
||||||
* @author wan
|
* @author wan
|
||||||
* @date 2024-05-31
|
* @date 2024-05-31
|
||||||
*/
|
*/
|
||||||
public interface EnterpriseMapper extends BaseMapper<Enterprise>
|
public interface EnterpriseMapper extends BaseMapper<Enterprise> {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* 查询企业列表
|
* 查询企业列表
|
||||||
*
|
*
|
||||||
|
|
|
@ -6,7 +6,9 @@ import java.net.http.HttpRequest;
|
||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
@ -17,6 +19,7 @@ import com.muyu.common.system.domain.SysUser;
|
||||||
import com.muyu.common.system.remote.RemoteUserService;
|
import com.muyu.common.system.remote.RemoteUserService;
|
||||||
import com.muyu.domain.vo.EnterpriseReq;
|
import com.muyu.domain.vo.EnterpriseReq;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -192,8 +195,11 @@ public class EnterpriseServiceImpl extends ServiceImpl<EnterpriseMapper,Enterpri
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
public static void getHttp(Enterprise enterprise) throws Exception {
|
|
||||||
|
public void getHttp(Enterprise enterprise) throws Exception {
|
||||||
// 创建HttpClient实例
|
// 创建HttpClient实例
|
||||||
HttpClient httpClient = HttpClient.newHttpClient();
|
HttpClient httpClient = HttpClient.newHttpClient();
|
||||||
|
|
||||||
|
@ -220,5 +226,14 @@ public class EnterpriseServiceImpl extends ServiceImpl<EnterpriseMapper,Enterpri
|
||||||
String responseBody = response.body();
|
String responseBody = response.body();
|
||||||
log.info("状态码:{}",statusCode);
|
log.info("状态码:{}",statusCode);
|
||||||
log.info("响应:{}",responseBody);
|
log.info("响应:{}",responseBody);
|
||||||
|
|
||||||
|
|
||||||
|
if (statusCode == 200) {
|
||||||
|
rabbitTemplate.convertAndSend("text1",JSON.toJSONString(enterprise),message -> {
|
||||||
|
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||||
|
return message;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
com.muyu.common.system.remote.factory.RemoteUserFallbackFactory
|
||||||
|
com.muyu.common.system.remote.factory.RemoteLogFallbackFactory
|
||||||
|
com.muyu.common.system.remote.factory.RemoteFileFallbackFactory
|
|
@ -4,6 +4,17 @@ server:
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
rabbitmq:
|
||||||
|
username: guest
|
||||||
|
password: guest
|
||||||
|
virtualHost: /
|
||||||
|
port: 5672
|
||||||
|
host: 101.34.243.166
|
||||||
|
listener:
|
||||||
|
simple:
|
||||||
|
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
|
||||||
|
publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange)
|
||||||
|
publisher-returns: true #确认消息已发送到队列(Queue)
|
||||||
application:
|
application:
|
||||||
# 应用名称
|
# 应用名称
|
||||||
name: ruoyi-company
|
name: ruoyi-company
|
||||||
|
|
|
@ -8,9 +8,11 @@ import com.muyu.common.core.annotation.Excel;
|
||||||
import com.muyu.common.core.web.domain.BaseEntity;
|
import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,12 +21,13 @@ import java.util.Date;
|
||||||
* @author wan
|
* @author wan
|
||||||
* @date 2024-05-31
|
* @date 2024-05-31
|
||||||
*/
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
@SuperBuilder
|
@SuperBuilder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@TableName("enterprise")
|
@TableName("enterprise")
|
||||||
public class Enterprise extends BaseEntity
|
public class Enterprise extends BaseEntity implements Serializable
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@ -74,25 +77,20 @@ public class Enterprise extends BaseEntity
|
||||||
@Excel(name = "企业入驻平台时期", width = 30, dateFormat = "yyyy-MM-dd")
|
@Excel(name = "企业入驻平台时期", width = 30, dateFormat = "yyyy-MM-dd")
|
||||||
private Date registrationDate;
|
private Date registrationDate;
|
||||||
|
|
||||||
/** 企业认证id */
|
|
||||||
@Excel(name = "企业认证id")
|
|
||||||
private Long certificationId;
|
|
||||||
|
|
||||||
/** 认证时间 */
|
/** 认证时间 */
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
@Excel(name = "认证时间", width = 30, dateFormat = "yyyy-MM-dd")
|
@Excel(name = "认证时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||||
private Date authenticationDate;
|
private Date authenticationDate;
|
||||||
|
|
||||||
|
/** 审核状态 */
|
||||||
|
@Excel(name = "审核状态")
|
||||||
|
private Integer examineStatus;
|
||||||
|
|
||||||
/** 服务级别 */
|
/** 服务级别 */
|
||||||
@Excel(name = "服务级别")
|
@Excel(name = "服务级别")
|
||||||
private Integer serviceLevel;
|
private Integer serviceLevel;
|
||||||
|
|
||||||
/** 开通服务id */
|
/** 开通服务级别*/
|
||||||
@Excel(name = "开通服务id")
|
@Excel(name = "开通服务级别")
|
||||||
private Long openServerId;
|
private String openServerId;
|
||||||
|
|
||||||
/** 增值服务id */
|
|
||||||
@Excel(name = "增值服务id")
|
|
||||||
private Long addServerId;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?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>clw-server</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
<relativePath>../../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>muyu-modules-many-remote</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>muyu-common-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>muyu-modules-many-common</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.muyu.remote;
|
||||||
|
|
||||||
|
import com.muyu.remote.factory.RemoteManyEnterpriseFallbackFactory;
|
||||||
|
import com.muyu.common.core.constant.ServiceNameConstants;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.domain.Enterprise;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 远程调用 多数据数据
|
||||||
|
*
|
||||||
|
* @author AnNan.Wang
|
||||||
|
* @ClassName: RemoteManyEnterpriseService
|
||||||
|
* @createTime: 2024/6/10 14:33
|
||||||
|
*/
|
||||||
|
@FeignClient(
|
||||||
|
contextId = "remoteManyEnterpriseService",
|
||||||
|
value = ServiceNameConstants.MANY_ENTERPRISE,
|
||||||
|
fallbackFactory = RemoteManyEnterpriseFallbackFactory.class
|
||||||
|
)
|
||||||
|
public interface RemoteManyEnterpriseService {
|
||||||
|
|
||||||
|
@PostMapping("/manyEnterprise/manyEnterpriseAdd")
|
||||||
|
public Result<String> manyEnterpriseAdd(@RequestBody Enterprise enterprise,@RequestHeader("ent_code")String key);
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.muyu.remote.factory;
|
||||||
|
|
||||||
|
|
||||||
|
import com.muyu.domain.Enterprise;
|
||||||
|
import com.muyu.remote.RemoteManyEnterpriseService;
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户服务降级处理
|
||||||
|
*
|
||||||
|
* @author muyu
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class RemoteManyEnterpriseFallbackFactory implements FallbackFactory<RemoteManyEnterpriseService> {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(RemoteManyEnterpriseFallbackFactory.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RemoteManyEnterpriseService create (Throwable throwable) {
|
||||||
|
log.error("多数据源调用失败:{}", throwable.getMessage());
|
||||||
|
return new RemoteManyEnterpriseService() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<String> manyEnterpriseAdd(Enterprise enterprise,String key) {
|
||||||
|
return Result.error("Enterprise多数据源调用失败:{}",throwable.getMessage());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
com.muyu.remote.factory.RemoteManyEnterpriseFallbackFactory
|
|
@ -84,12 +84,6 @@
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>muyu-modules-many-common</artifactId>
|
|
||||||
<version>3.6.3</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>muyu-common-core</artifactId>
|
<artifactId>muyu-common-core</artifactId>
|
||||||
|
@ -120,5 +114,13 @@
|
||||||
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
||||||
<version>4.3.0</version>
|
<version>4.3.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.amqp</groupId>
|
||||||
|
<artifactId>spring-rabbit</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>muyu-modules-many-remote</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -28,4 +28,11 @@ public class ManyEnterpriseController {
|
||||||
manyEnterpriseService.AllList(headerValue)
|
manyEnterpriseService.AllList(headerValue)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @PostMapping("/manyEnterpriseAdd")
|
||||||
|
// public Result<String> manyEnterpriseAdd(@RequestBody Enterprise enterprise,@RequestHeader("ent_code")String key){
|
||||||
|
// return Result.success(
|
||||||
|
// manyEnterpriseService.manyEnterpriseAdd(enterprise,key)
|
||||||
|
// );
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.muyu.authentication.mapper;
|
package com.muyu.authentication.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.many.domain.Enterprise;
|
import com.muyu.many.domain.Enterprise ;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mapper 实现层
|
* mapper 实现层
|
||||||
|
@ -11,4 +11,5 @@ import com.muyu.many.domain.Enterprise;
|
||||||
* @createTime: 2024/6/6 15:52
|
* @createTime: 2024/6/6 15:52
|
||||||
*/
|
*/
|
||||||
public interface ManyEnterpriseMapper extends BaseMapper<Enterprise> {
|
public interface ManyEnterpriseMapper extends BaseMapper<Enterprise> {
|
||||||
|
int enterpriseInsert(Enterprise enterprise);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.muyu.authentication.rabbitmq;
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.muyu.authentication.controller.ManyEnterpriseController;
|
||||||
|
|
||||||
|
import com.muyu.authentication.service.impl.ManyEnterpriseServiceImpl;
|
||||||
|
import com.muyu.clw.common.many.datasource.domain.model.DataSourceInfo;
|
||||||
|
import com.muyu.clw.common.many.datasource.factory.DruidDataSourceFactory;
|
||||||
|
import com.muyu.clw.common.many.datasource.role.DynamicDataSource;
|
||||||
|
import com.muyu.common.core.utils.SpringUtils;
|
||||||
|
import com.muyu.many.domain.Enterprise ;
|
||||||
|
import com.muyu.remote.RemoteManyEnterpriseService;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
|
@Component
|
||||||
|
public class MessageConsumer {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ManyEnterpriseServiceImpl manyEnterpriseService;
|
||||||
|
|
||||||
|
@RabbitListener(queues = "text1")
|
||||||
|
public void receiveMessage(String message) {
|
||||||
|
// 在这里处理接收到的消息,并将其写入MySQL数据库
|
||||||
|
log.info("message:{}",message);
|
||||||
|
DruidDataSourceFactory dataSourceFactory = SpringUtils.getBean(DruidDataSourceFactory.class);
|
||||||
|
DynamicDataSource druidDataSource = SpringUtils.getBean(DynamicDataSource.class);
|
||||||
|
|
||||||
|
Enterprise parse = JSON.parseObject(message, Enterprise.class);
|
||||||
|
String substring = parse.getContactPhone().substring(parse.getContactPhone().length() - 4);
|
||||||
|
String host="123.56.102.11";
|
||||||
|
Integer post= Math.toIntExact(3306 + parse.getId());
|
||||||
|
String key="ent_" + substring;
|
||||||
|
log.info("parse:{}",parse);
|
||||||
|
|
||||||
|
DataSourceInfo dataSourceInfo = DataSourceInfo.hostAndPortBuild(key, host, post);
|
||||||
|
|
||||||
|
DruidDataSource dataSource = dataSourceFactory.create(dataSourceInfo);
|
||||||
|
|
||||||
|
druidDataSource.put(key,dataSource);
|
||||||
|
|
||||||
|
new Thread(()->{
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
manyEnterpriseService.manyEnterpriseAdd(parse,key);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package com.muyu.authentication.service;
|
package com.muyu.authentication.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.muyu.many.domain.Enterprise;
|
import com.muyu.many.domain.Enterprise ;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -13,4 +13,7 @@ import java.util.List;
|
||||||
|
|
||||||
public interface ManyEnterpriseService extends IService<Enterprise> {
|
public interface ManyEnterpriseService extends IService<Enterprise> {
|
||||||
List<Enterprise> AllList(String headerValue);
|
List<Enterprise> AllList(String headerValue);
|
||||||
|
|
||||||
|
// String manyEnterpriseAdd(Enterprise enterprise,String key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,9 @@ package com.muyu.authentication.service.impl;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.muyu.authentication.mapper.ManyEnterpriseMapper;
|
import com.muyu.authentication.mapper.ManyEnterpriseMapper;
|
||||||
import com.muyu.authentication.service.ManyEnterpriseService;
|
import com.muyu.authentication.service.ManyEnterpriseService;
|
||||||
import com.muyu.clw.common.many.datasource.ManyDataSource;
|
|
||||||
import com.muyu.clw.common.many.datasource.factory.DruidDataSourceFactory;
|
|
||||||
import com.muyu.clw.common.many.datasource.holder.DynamicDataSourceHolder;
|
import com.muyu.clw.common.many.datasource.holder.DynamicDataSourceHolder;
|
||||||
import com.muyu.clw.common.saas.domain.model.EntInfo;
|
import com.muyu.many.domain.Enterprise ;
|
||||||
import com.muyu.many.domain.Enterprise;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@ -20,7 +18,7 @@ import java.util.List;
|
||||||
* @Author AnNan.Wang
|
* @Author AnNan.Wang
|
||||||
* @Date 2024/6/6 15:28
|
* @Date 2024/6/6 15:28
|
||||||
*/
|
*/
|
||||||
|
@Log4j2
|
||||||
@Service
|
@Service
|
||||||
public class ManyEnterpriseServiceImpl extends ServiceImpl<ManyEnterpriseMapper, Enterprise>
|
public class ManyEnterpriseServiceImpl extends ServiceImpl<ManyEnterpriseMapper, Enterprise>
|
||||||
implements ManyEnterpriseService {
|
implements ManyEnterpriseService {
|
||||||
|
@ -38,4 +36,18 @@ public class ManyEnterpriseServiceImpl extends ServiceImpl<ManyEnterpriseMapper,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String manyEnterpriseAdd(Enterprise enterprise,String key) {
|
||||||
|
log.info("enterprise等于:{}",enterprise);
|
||||||
|
DynamicDataSourceHolder.setDynamicDataSourceKey(key);
|
||||||
|
int insert = manyEnterpriseMapper.enterpriseInsert(enterprise);
|
||||||
|
log.info("insert等于:{}",insert);
|
||||||
|
DynamicDataSourceHolder.removeDynamicDataSourceKey();
|
||||||
|
if (insert > 0) {
|
||||||
|
return "初始成功";
|
||||||
|
}else {
|
||||||
|
return "初始失败";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
com.muyu.authentication.rabbitmq.MessageConsumer
|
|
@ -1,9 +1,19 @@
|
||||||
# Tomcat
|
# Tomcat
|
||||||
server:
|
server:
|
||||||
port: 9403
|
port: 9403
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
|
rabbitmq:
|
||||||
|
username: guest
|
||||||
|
password: guest
|
||||||
|
virtualHost: /
|
||||||
|
port: 5672
|
||||||
|
host: 101.34.243.166
|
||||||
|
listener:
|
||||||
|
simple:
|
||||||
|
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
|
||||||
|
publisher-confirm-type: correlated #确认消息已发送到交换机(Exchange)
|
||||||
|
publisher-returns: true #确
|
||||||
application:
|
application:
|
||||||
# 应用名称
|
# 应用名称
|
||||||
name: ruoyi-many
|
name: ruoyi-many
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.muyu.authentication.mapper.ManyEnterpriseMapper">
|
||||||
|
|
||||||
|
<insert id="enterpriseInsert">
|
||||||
|
INSERT INTO enterprise
|
||||||
|
(`enterprise_name`, `legal_person`, `business_license_number`, `establishment_date`, `business_scope`, `address`, `contact_phone`, `email`, `status`, `registration_date`, `authentication_date`, `examine_status`, `service_level`, `open_server_id`)
|
||||||
|
VALUES
|
||||||
|
(#{enterpriseName}, #{legalPerson}, #{businessLicenseNumber}, #{establishmentDate}, #{businessScope}, #{address}, #{contactPhone}, #{email},#{status},#{registrationDate},#{authenticationDate},#{examineStatus},#{serviceLevel},#{openServerId});
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
|
@ -15,6 +15,7 @@
|
||||||
<modules>
|
<modules>
|
||||||
<module>muyu-modules-many-common</module>
|
<module>muyu-modules-many-common</module>
|
||||||
<module>muyu-modules-many-server</module>
|
<module>muyu-modules-many-server</module>
|
||||||
|
<module>muyu-modules-many-remote</module>
|
||||||
</modules>
|
</modules>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
|
Loading…
Reference in New Issue