feat:多数据源表远程调用,添加企业远程调用工厂
commit
ade0db3637
1
pom.xml
1
pom.xml
|
@ -221,6 +221,7 @@
|
|||
<module>zhiLian-business/zhiLian-data-service</module>
|
||||
<module>zhiLian-cloud-datasource</module>
|
||||
<module>zhiLian-cloud-datasource/zhiLian-datasource-service</module>
|
||||
<module>zhiLian-common/zhiLian-common-business</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
|
|
@ -25,6 +25,11 @@
|
|||
<artifactId>mybatis-plus-join</artifactId>
|
||||
<version>1.2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zhiLian</groupId>
|
||||
<artifactId>zhiLian-common-business</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package com.zhiLian.business.Job;
|
||||
|
||||
|
||||
import com.zhiLian.business.domain.Entinfo;
|
||||
|
||||
import com.zhiLian.business.service.impl.EntinfoServiceImpl;
|
||||
import com.zhiLian.common.business.domain.Entinfo;
|
||||
import com.zhiLian.common.redis.service.RedisService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -28,6 +29,7 @@ public class ManyJob {
|
|||
@Autowired
|
||||
private EntinfoServiceImpl entinfoService;
|
||||
|
||||
|
||||
// @Scheduled(cron = "*/10 * * * * *") // 每10分钟执行一次
|
||||
public void manyJob(){
|
||||
redisService.deleteObject("entinfo");
|
||||
|
|
|
@ -1,22 +1,19 @@
|
|||
package com.zhiLian.business.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.zhiLian.business.domain.Cart;
|
||||
import com.zhiLian.business.domain.CartVo;
|
||||
import com.zhiLian.business.domain.Entinfo;
|
||||
import com.zhiLian.business.service.IEntinfoService;
|
||||
import com.zhiLian.business.service.PlusService;
|
||||
import com.zhiLian.business.service.impl.PlusServiceImpl;
|
||||
import com.zhiLian.common.business.domain.Entinfo;
|
||||
import com.zhiLian.common.core.domain.Result;
|
||||
import com.zhiLian.common.core.utils.poi.ExcelUtil;
|
||||
import com.zhiLian.common.core.web.controller.BaseController;
|
||||
import com.zhiLian.common.core.web.page.TableDataInfo;
|
||||
import com.zhiLian.common.log.annotation.Log;
|
||||
import com.zhiLian.common.log.enums.BusinessType;
|
||||
import com.zhiLian.common.security.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
@ -62,7 +59,7 @@ public class EntinfoController extends BaseController
|
|||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@GetMapping("ListAll")
|
||||
@GetMapping("listAll")
|
||||
public List<Entinfo> listAll(){
|
||||
List<Entinfo> list = entinfoService.list();
|
||||
return list;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package com.zhiLian.business.feign;
|
||||
|
||||
|
||||
import com.zhiLian.business.domain.Entinfo;
|
||||
|
||||
import com.zhiLian.common.business.domain.Entinfo;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
|
@ -16,6 +17,6 @@ import java.util.List;
|
|||
*/
|
||||
@FeignClient(value = "zhiLian-business-service")
|
||||
public interface EntInfoFeign {
|
||||
@GetMapping("ListAll")
|
||||
@GetMapping("/entinfo/listAll")
|
||||
public List<Entinfo> listAll();
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package com.zhiLian.business.mapper;
|
|||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zhiLian.business.domain.Entinfo;
|
||||
import com.zhiLian.common.business.domain.Entinfo;
|
||||
|
||||
/**
|
||||
* 多数据源Mapper接口
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package com.zhiLian.business.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zhiLian.business.domain.Business;
|
||||
import com.zhiLian.business.domain.Entinfo;
|
||||
import com.zhiLian.common.business.domain.Entinfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -4,13 +4,12 @@ package com.zhiLian.business.service.impl;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import com.zhiLian.business.config.RabbitmqConfig;
|
||||
import com.zhiLian.business.domain.Business;
|
||||
|
||||
import com.zhiLian.business.domain.Entinfo;
|
||||
import com.zhiLian.business.mapper.BusinessMapper;
|
||||
//import com.zhiLian.business.remote.factory.RemoteUserLoginFactory;
|
||||
import com.zhiLian.business.service.IBusinessService;
|
||||
import com.zhiLian.common.business.domain.Entinfo;
|
||||
import com.zhiLian.common.core.domain.Result;
|
||||
import com.zhiLian.common.core.utils.DateUtils;
|
||||
import com.zhiLian.common.redis.service.RedisService;
|
||||
|
@ -18,24 +17,18 @@ import com.zhiLian.common.security.utils.SecurityUtils;
|
|||
import com.zhiLian.common.system.domain.LoginUser;
|
||||
import com.zhiLian.common.system.domain.SysUser;
|
||||
import com.zhiLian.common.system.remote.RemoteUserService;
|
||||
import org.apache.catalina.User;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 企业Service业务层处理
|
||||
|
@ -160,6 +153,7 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
|
|||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* http URL 链接
|
||||
* @param business
|
||||
|
@ -196,12 +190,12 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
|
|||
new InputStreamReader(httpConn.getInputStream()));
|
||||
String resultData = br.readLine();
|
||||
System.out.println("从服务端返回结果: " + resultData);
|
||||
|
||||
// 7.关闭HttpURLConnection连接
|
||||
httpConn.disconnect();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Entinfo build = Entinfo.builder()
|
||||
.entCode("test_" + business.getId())
|
||||
.ip("192.168.120.128")
|
||||
|
|
|
@ -3,10 +3,9 @@ package com.zhiLian.business.service.impl;
|
|||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zhiLian.business.domain.Business;
|
||||
import com.zhiLian.business.domain.Entinfo;
|
||||
import com.zhiLian.business.mapper.EntinfoMapper;
|
||||
import com.zhiLian.business.service.IEntinfoService;
|
||||
import com.zhiLian.common.business.domain.Entinfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ spring:
|
|||
password: guest
|
||||
virtualHost: /
|
||||
port: 5672
|
||||
host: 111.229.102.61
|
||||
host: 43.142.12.243
|
||||
listener:
|
||||
simple:
|
||||
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
|
||||
|
|
|
@ -4,7 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zhiLian.business.mapper.EntinfoMapper">
|
||||
|
||||
<resultMap type="com.zhiLian.business.domain.Entinfo" id="EntinfoResult">
|
||||
<resultMap type="com.zhiLian.common.business.domain.Entinfo" id="EntinfoResult">
|
||||
<result property="entCode" column="ent_code" />
|
||||
<result property="ip" column="ip" />
|
||||
<result property="port" column="port" />
|
||||
|
@ -15,7 +15,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
select ent_code, ip, port, id from entinfo
|
||||
</sql>
|
||||
|
||||
<select id="selectEntinfoList" parameterType="com.zhiLian.business.domain.Entinfo" resultMap="EntinfoResult">
|
||||
<select id="selectEntinfoList" parameterType="com.zhiLian.common.business.domain.Entinfo" resultMap="EntinfoResult">
|
||||
<include refid="selectEntinfoVo"/>
|
||||
<where>
|
||||
<if test="entCode != null and entCode != ''"> and ent_code = #{entCode}</if>
|
||||
|
@ -28,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<include refid="selectEntinfoVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
<select id="selectEntinfo" resultType="com.zhiLian.business.domain.Entinfo">
|
||||
<select id="selectEntinfo" resultType="com.zhiLian.common.business.domain.Entinfo">
|
||||
<include refid="selectEntinfoVo"/>
|
||||
<where>
|
||||
<if test="entCode != null and entCode != ''"> and ent_code = #{entCode}</if>
|
||||
|
@ -37,7 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insertEntinfo" parameterType="com.zhiLian.business.domain.Entinfo" useGeneratedKeys="true" keyProperty="id">
|
||||
<insert id="insertEntinfo" parameterType="com.zhiLian.common.business.domain.Entinfo" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into entinfo
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="entCode != null">ent_code,</if>
|
||||
|
@ -51,7 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateEntinfo" parameterType="com.zhiLian.business.domain.Entinfo">
|
||||
<update id="updateEntinfo" parameterType="com.zhiLian.common.business.domain.Entinfo">
|
||||
update entinfo
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="entCode != null">ent_code = #{entCode},</if>
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<?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.zhiLian</groupId>
|
||||
<artifactId>zhiLian-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>zhiLian-common-business</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>
|
||||
<!-- ZhiLian Common Core-->
|
||||
<dependency>
|
||||
<groupId>com.zhiLian</groupId>
|
||||
<artifactId>zhiLian-common-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -1,4 +1,4 @@
|
|||
package com.zhiLian.business.domain;
|
||||
package com.zhiLian.common.business.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zhiLian.common.core.annotation.Excel;
|
|
@ -0,0 +1,22 @@
|
|||
package com.zhiLian.common.business.remote;
|
||||
|
||||
import com.zhiLian.common.business.domain.Entinfo;
|
||||
import com.zhiLian.common.business.remote.factory.RemoteBusinessFallbackFactory;
|
||||
import com.zhiLian.common.core.constant.ServiceNameConstants;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户服务
|
||||
*
|
||||
* @author zhiLian
|
||||
*/
|
||||
@FeignClient(contextId = "remoteBusinessService", value = ServiceNameConstants.SYSTEM_BUSINESS, fallbackFactory = RemoteBusinessFallbackFactory.class)
|
||||
public interface RemoteBusinessService {
|
||||
|
||||
|
||||
@GetMapping("/entinfo/listAll")
|
||||
public List<Entinfo> listAll();
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.zhiLian.common.business.remote.factory;
|
||||
|
||||
import com.zhiLian.common.business.domain.Entinfo;
|
||||
import com.zhiLian.common.business.remote.RemoteBusinessService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户服务降级处理
|
||||
*
|
||||
* @author zhiLian
|
||||
*/
|
||||
@Component
|
||||
public class RemoteBusinessFallbackFactory implements FallbackFactory<RemoteBusinessService> {
|
||||
private static final Logger log = LoggerFactory.getLogger(RemoteBusinessFallbackFactory.class);
|
||||
|
||||
@Override
|
||||
public RemoteBusinessService create (Throwable throwable) {
|
||||
log.error("用户服务调用失败:{}", throwable.getMessage());
|
||||
return new RemoteBusinessService(){
|
||||
|
||||
|
||||
@Override
|
||||
public List<Entinfo> listAll() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
com.zhiLian.common.business.remote.factory.RemoteBusinessFallbackFactory
|
|
@ -15,6 +15,7 @@ public class ServiceNameConstants {
|
|||
* 系统模块的serviceid
|
||||
*/
|
||||
public static final String SYSTEM_SERVICE = "zhiLian-system";
|
||||
public static final String SYSTEM_BUSINESS = "zhiLian-business";
|
||||
|
||||
/**
|
||||
* 文件服务的serviceid
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
package com.zhiLian.common.core.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zhiLian.common.core.annotation.Excel;
|
||||
import com.zhiLian.common.core.web.domain.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 多数据源对象 entinfo
|
||||
*
|
||||
* @author muyu
|
||||
* @date 2024-06-06
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("entinfo")
|
||||
public class Entinfo extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 数据源key */
|
||||
@Excel(name = "数据源key")
|
||||
private String entCode;
|
||||
|
||||
/** 数据源ip */
|
||||
@Excel(name = "数据源ip")
|
||||
private String ip;
|
||||
|
||||
/** 数据源端口 */
|
||||
@Excel(name = "数据源端口")
|
||||
private Integer port;
|
||||
|
||||
/** 数据源ID */
|
||||
private Long id;
|
||||
|
||||
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package com.zhiLian.common.system.remote;
|
||||
|
||||
import com.zhiLian.common.core.constant.ServiceNameConstants;
|
||||
import com.zhiLian.common.core.domain.Entinfo;
|
||||
import com.zhiLian.common.core.domain.Result;
|
||||
import com.zhiLian.common.system.domain.SysFile;
|
||||
import com.zhiLian.common.system.remote.factory.RemoteFileFallbackFactory;
|
||||
|
@ -34,8 +33,7 @@ public interface RemoteFileService {
|
|||
|
||||
@GetMapping(value = "/{id}")
|
||||
public Result getInfo(@PathVariable("id") Long id);
|
||||
@GetMapping("ListAll")
|
||||
public List<Entinfo> listAll();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.zhiLian.common.system.remote.factory;
|
||||
|
||||
import com.zhiLian.common.core.domain.Entinfo;
|
||||
import com.zhiLian.common.core.domain.Result;
|
||||
import com.zhiLian.common.system.remote.RemoteFileService;
|
||||
import com.zhiLian.common.system.domain.SysFile;
|
||||
|
@ -35,10 +34,7 @@ public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileServ
|
|||
return Result.error("获取失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Entinfo> listAll() {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,6 @@ public class GenController extends BaseController {
|
|||
List<GenTable> list = genTableService.selectDbTableList(genTable);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据表字段列表
|
||||
*/
|
||||
|
|
|
@ -20,7 +20,11 @@
|
|||
zhiLian-vehicle-service业务系统模块
|
||||
</description>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zhiLian</groupId>
|
||||
<artifactId>zhiLian-common-business</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zhiLian</groupId>
|
||||
<artifactId>zhiLian-common-system</artifactId>
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.zhiLian.common.swagger.annotation.EnableCustomSwagger2;
|
|||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
|
@ -21,7 +22,6 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||
@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@SpringBootApplication(exclude = {DynamicDataSourceAutoConfiguration.class, DataSourceAutoConfiguration.class })
|
||||
@EnableScheduling
|
||||
public class ZhiLianVehicleApplication {
|
||||
public static void main (String[] args) {
|
||||
SpringApplication.run(ZhiLianVehicleApplication.class, args);
|
||||
|
|
|
@ -4,13 +4,13 @@ package com.zhiLian.vehicle.datasource;
|
|||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.zhiLian.common.business.domain.Entinfo;
|
||||
import com.zhiLian.common.business.remote.RemoteBusinessService;
|
||||
import com.zhiLian.common.core.utils.SpringUtils;
|
||||
import com.zhiLian.common.redis.service.RedisService;
|
||||
import com.zhiLian.common.system.remote.RemoteFileService;
|
||||
import com.zhiLian.vehicle.datasource.config.factory.DruidDataSourceFactory;
|
||||
import com.zhiLian.vehicle.datasource.config.role.DynamicDataSource;
|
||||
import com.zhiLian.vehicle.datasource.domain.DataSourceInfo;
|
||||
import com.zhiLian.vehicle.datasource.domain.Entinfo;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
|
@ -21,10 +21,8 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -42,38 +40,33 @@ public class ManyDataSource {
|
|||
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String,String> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private RemoteBusinessService remoteBusinessService;
|
||||
|
||||
// @Autowired
|
||||
// private RemoteFileService remoteFileService;
|
||||
// private EntInfoFeign entInfoFeign;
|
||||
|
||||
|
||||
//调用注解 添加队列名称
|
||||
@RabbitListener(queuesToDeclare = {@Queue(name = "zhiLian-vehicle-exchange")})
|
||||
public void smsConfig(String msg, Message message, Channel channel){
|
||||
//获取消息的ID
|
||||
// @PostConstruct
|
||||
// public void init() {
|
||||
// new Thread(() -> {
|
||||
// try {
|
||||
// Thread.sleep(10000);
|
||||
// } catch (InterruptedException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
//
|
||||
// }).start();
|
||||
// }
|
||||
|
||||
//调用注解 添加队列名称
|
||||
@RabbitListener(queuesToDeclare = {@Queue(name = "zhiLian-vehicle-exchange")})
|
||||
public void smsConfig(String msg, Message message, Channel channel){
|
||||
//获取消息的ID
|
||||
String messageId = message.getMessageProperties().getMessageId();
|
||||
try {
|
||||
//添加消息id到redis set集合中 添加成功返回1 表示未消费 添加失败返回0 表示已消费
|
||||
|
@ -103,7 +96,6 @@ public class ManyDataSource {
|
|||
private void druidData(String msg) {
|
||||
Entinfo entinfo1 = JSON.parseObject(msg, Entinfo.class);
|
||||
log.info("消息为:{}",entinfo1);
|
||||
|
||||
DruidDataSourceFactory druidDataSourceFactory = SpringUtils.getBean(DruidDataSourceFactory.class);
|
||||
DynamicDataSource dynamicDataSource = SpringUtils.getBean(DynamicDataSource.class);
|
||||
DataSourceInfo dataSourceInfo = DataSourceInfo.hostAndPortBuild(entinfo1.getEntCode(), entinfo1.getIp(), entinfo1.getPort());
|
||||
|
@ -120,14 +112,19 @@ public class ManyDataSource {
|
|||
.port(3306)
|
||||
.build());
|
||||
}};
|
||||
// List<com.zhiLian.common.core.domain.Entinfo> entinfos = remoteFileService.listAll();
|
||||
// databaseNameList.a(entinfos)
|
||||
List<String> entinfo = redisTemplate.opsForList().range("entinfo", 0, -1);
|
||||
List<Entinfo> list = remoteBusinessService.listAll();
|
||||
databaseNameList.addAll(list);
|
||||
|
||||
// List<String> entinfo = redisTemplate.opsForList().range("entinfo", 0, -1);
|
||||
// entinfo.forEach(string -> {
|
||||
// Entinfo entInfo = JSON.parseObject(String.valueOf(string), Entinfo.class);
|
||||
// databaseNameList.add(entInfo);
|
||||
// });
|
||||
|
||||
// List<Entinfo> entinfos = entInfoFeign.listAll();
|
||||
// databaseNameList.addAll(entinfos);
|
||||
|
||||
|
||||
entinfo.forEach(string -> {
|
||||
Entinfo entInfo = JSON.parseObject(string, Entinfo.class);
|
||||
databaseNameList.add(entInfo);
|
||||
});
|
||||
// if(SecurityUtils.getLoginUser() == null){
|
||||
// return databaseNameList;
|
||||
// }else{
|
||||
|
|
|
@ -27,6 +27,7 @@ public class DynamicDataSource extends AbstractRoutingDataSource {
|
|||
*/
|
||||
private Map<Object, Object> defineTargetDataSources;
|
||||
|
||||
|
||||
/**
|
||||
* 决定当前线程使用哪个数据源
|
||||
*/
|
||||
|
@ -35,6 +36,7 @@ public class DynamicDataSource extends AbstractRoutingDataSource {
|
|||
return DynamicDataSourceHolder.getDynamicDataSourceKey();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加数据库
|
||||
* @param key 键
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
package com.zhiLian.vehicle.datasource.domain;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.zhiLian.common.core.annotation.Excel;
|
||||
import com.zhiLian.common.core.web.domain.BaseEntity;
|
||||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* BingRui.Hou
|
||||
*
|
||||
* @Description 描述
|
||||
* EntInfo
|
||||
* @Date 2024/06/04 14:34
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Entinfo extends BaseEntity implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 数据源key */
|
||||
@Excel(name = "数据源key")
|
||||
private String entCode;
|
||||
|
||||
/** 数据源ip */
|
||||
@Excel(name = "数据源ip")
|
||||
private String ip;
|
||||
|
||||
/** 数据源端口 */
|
||||
@Excel(name = "数据源端口")
|
||||
private Integer port;
|
||||
|
||||
/** 数据源ID */
|
||||
private Long id;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
//package com.zhiLian.vehicle.datasource.feign;
|
||||
//
|
||||
//
|
||||
//import com.zhiLian.common.business.Entinfo;
|
||||
//import org.springframework.cloud.openfeign.FeignClient;
|
||||
//import org.springframework.web.bind.annotation.GetMapping;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// * BingRui.Hou
|
||||
// *
|
||||
// * @Description 描述
|
||||
// * @ClassName EntInfoFeign
|
||||
// * @Date 2024/06/07 17:25
|
||||
// */
|
||||
//@FeignClient(value = "zhiLian-business-service")
|
||||
//public interface EntInfoFeign {
|
||||
// @GetMapping("/entinfo/listAll")
|
||||
// public List<Entinfo> listAll();
|
||||
//}
|
|
@ -9,7 +9,7 @@ spring:
|
|||
password: guest
|
||||
virtualHost: /
|
||||
port: 5672
|
||||
host: 111.229.102.61
|
||||
host: 43.142.12.243
|
||||
listener:
|
||||
simple:
|
||||
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
|
||||
|
|
Loading…
Reference in New Issue