feat commit

注册节点注册功能
server_2024_3_26_liyuan
玉安君 2024-04-01 19:33:58 +08:00
parent bda7de379f
commit 5b2adca1e4
28 changed files with 1252 additions and 39 deletions

View File

@ -36,6 +36,7 @@
<poi.version>4.1.2</poi.version>
<transmittable-thread-local.version>2.14.3</transmittable-thread-local.version>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<mqttv3.version>1.2.5</mqttv3.version>
</properties>
<!-- 依赖声明 -->
@ -236,6 +237,13 @@
<version>${zhilian.version}</version>
</dependency>
<!--mqtt版本管理-->
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>${mqttv3.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -1,14 +1,14 @@
package com.zhilian.common.redis.service;
import io.lettuce.core.output.DoubleListOutput;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundSetOperations;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.core.*;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* spring redis
@ -27,7 +27,7 @@ public class RedisService {
* @param key
* @param value
*/
public <T> void setCacheObject (final String key, final T value) {
public <T> void setCacheObject(final String key, final T value) {
redisTemplate.opsForValue().set(key, value);
}
@ -39,7 +39,7 @@ public class RedisService {
* @param timeout
* @param timeUnit
*/
public <T> void setCacheObject (final String key, final T value, final Long timeout, final TimeUnit timeUnit) {
public <T> void setCacheObject(final String key, final T value, final Long timeout, final TimeUnit timeUnit) {
redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
}
@ -48,10 +48,9 @@ public class RedisService {
*
* @param key Redis
* @param timeout
*
* @return true=false=
*/
public boolean expire (final String key, final long timeout) {
public boolean expire(final String key, final long timeout) {
return expire(key, timeout, TimeUnit.SECONDS);
}
@ -61,10 +60,9 @@ public class RedisService {
* @param key Redis
* @param timeout
* @param unit
*
* @return true=false=
*/
public boolean expire (final String key, final long timeout, final TimeUnit unit) {
public boolean expire(final String key, final long timeout, final TimeUnit unit) {
return redisTemplate.expire(key, timeout, unit);
}
@ -72,10 +70,9 @@ public class RedisService {
*
*
* @param key Redis
*
* @return
*/
public long getExpire (final String key) {
public long getExpire(final String key) {
return redisTemplate.getExpire(key);
}
@ -83,10 +80,9 @@ public class RedisService {
* key
*
* @param key
*
* @return true false
*/
public Boolean hasKey (String key) {
public Boolean hasKey(String key) {
return redisTemplate.hasKey(key);
}
@ -94,10 +90,9 @@ public class RedisService {
*
*
* @param key
*
* @return
*/
public <T> T getCacheObject (final String key) {
public <T> T getCacheObject(final String key) {
ValueOperations<String, T> operation = redisTemplate.opsForValue();
return operation.get(key);
}
@ -107,7 +102,7 @@ public class RedisService {
*
* @param key
*/
public boolean deleteObject (final String key) {
public boolean deleteObject(final String key) {
return redisTemplate.delete(key);
}
@ -115,10 +110,9 @@ public class RedisService {
*
*
* @param collection
*
* @return
*/
public boolean deleteObject (final Collection collection) {
public boolean deleteObject(final Collection collection) {
return redisTemplate.delete(collection) > 0;
}
@ -127,10 +121,9 @@ public class RedisService {
*
* @param key
* @param dataList List
*
* @return
*/
public <T> long setCacheList (final String key, final List<T> dataList) {
public <T> long setCacheList(final String key, final List<T> dataList) {
Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
return count == null ? 0 : count;
}
@ -139,10 +132,9 @@ public class RedisService {
* list
*
* @param key
*
* @return
*/
public <T> List<T> getCacheList (final String key) {
public <T> List<T> getCacheList(final String key) {
return redisTemplate.opsForList().range(key, 0, -1);
}
@ -151,10 +143,9 @@ public class RedisService {
*
* @param key
* @param dataSet
*
* @return
*/
public <T> BoundSetOperations<String, T> setCacheSet (final String key, final Set<T> dataSet) {
public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet) {
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
Iterator<T> it = dataSet.iterator();
while (it.hasNext()) {
@ -167,10 +158,9 @@ public class RedisService {
* set
*
* @param key
*
* @return
*/
public <T> Set<T> getCacheSet (final String key) {
public <T> Set<T> getCacheSet(final String key) {
return redisTemplate.opsForSet().members(key);
}
@ -180,7 +170,7 @@ public class RedisService {
* @param key
* @param dataMap
*/
public <T> void setCacheMap (final String key, final Map<String, T> dataMap) {
public <T> void setCacheMap(final String key, final Map<String, T> dataMap) {
if (dataMap != null) {
redisTemplate.opsForHash().putAll(key, dataMap);
}
@ -190,10 +180,9 @@ public class RedisService {
* Map
*
* @param key
*
* @return
*/
public <T> Map<String, T> getCacheMap (final String key) {
public <T> Map<String, T> getCacheMap(final String key) {
return redisTemplate.opsForHash().entries(key);
}
@ -204,7 +193,7 @@ public class RedisService {
* @param hKey Hash
* @param value
*/
public <T> void setCacheMapValue (final String key, final String hKey, final T value) {
public <T> void setCacheMapValue(final String key, final String hKey, final T value) {
redisTemplate.opsForHash().put(key, hKey, value);
}
@ -213,10 +202,9 @@ public class RedisService {
*
* @param key Redis
* @param hKey Hash
*
* @return Hash
*/
public <T> T getCacheMapValue (final String key, final String hKey) {
public <T> T getCacheMapValue(final String key, final String hKey) {
HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
return opsForHash.get(key, hKey);
}
@ -226,10 +214,9 @@ public class RedisService {
*
* @param key Redis
* @param hKeys Hash
*
* @return Hash
*/
public <T> List<T> getMultiCacheMapValue (final String key, final Collection<Object> hKeys) {
public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys) {
return redisTemplate.opsForHash().multiGet(key, hKeys);
}
@ -238,21 +225,155 @@ public class RedisService {
*
* @param key Redis
* @param hKey Hash
*
* @return
*/
public boolean deleteCacheMapValue (final String key, final String hKey) {
public boolean deleteCacheMapValue(final String key, final String hKey) {
return redisTemplate.opsForHash().delete(key, hKey) > 0;
}
/**
* Zset
*
* @param zkey ZSet
* @param value
* @param score
*/
public <T> void setCacheZsetValue(final String zkey, final T value, final Double score) {
redisTemplate.opsForZSet().add(zkey, value, score);
}
/**
* Zset
*
* @param zkey zSet
* @param map => T Double
*/
public <T> void setCacheZsetBatchValue(final String zkey, final Map<T, Double> map) {
Set<DefaultTypedTuple> collect = map.entrySet().stream()
.map(item -> {
return new DefaultTypedTuple(item.getKey(), item.getValue());
})
.collect(Collectors.toSet());
redisTemplate.opsForZSet().add(zkey, collect);
}
/**
* Zset
*
* @param zkey
* @return size
*/
public Long getCacheZsetSize(String zkey) {
return redisTemplate.opsForZSet().size(zkey);
}
/**
*
*
* @param zkey
* @param value
* @param <T>
* @return score
*/
public <T> Double getCacheZsetScore(final String zkey, final T value) {
return redisTemplate.opsForZSet().score(zkey, value);
}
/**
*
*
* @param zkey
* @param start
* @param end
* @return
*/
public <T> Set<Double> getCacheZsetScoreBatch(final String zkey, final Long start, final Long end) {
return redisTemplate.opsForZSet().range(zkey, start, end);
}
/**
*
* @param zkey
* @param start
* @param end
* @return
*/
public <T> Set<HashMap<Object, Double>> getCacheZsetScoreWithDataBatch(final String zkey, final Long start, final Long end) {
Set<ZSetOperations.TypedTuple<Object>> rangeSet = redisTemplate.opsForZSet().range(zkey, start, end);
Set<HashMap<Object, Double>> collect = rangeSet.stream().
map(item -> {
HashMap<Object, Double> objectDoubleHashMap = new HashMap<Object, Double>();
objectDoubleHashMap.put(item.getValue(), item.getScore());
return objectDoubleHashMap;
})
.collect(Collectors.toSet());
return collect;
}
/**
*
* @param zkey
* @param value
* @param delta
* @param <T>
*/
public <T> Double incrementScore(final String zkey, final T value, final Double delta){
return redisTemplate.opsForZSet().incrementScore(zkey,value,delta);
}
/**
*
* @param zkey
* @param values
* @return
* @param <T>
*/
public <T> Long removeCacheZsetBatch(final String zkey,final T... values){
return redisTemplate.opsForZSet().remove(zkey,values);
}
/**
* ,
* @param zkey
* @param start
* @param end
* @return
*/
public Set<Double> reverseRange(final String zkey,final Long start,final Long end){
return redisTemplate.opsForZSet().reverseRange(zkey,start,end);
}
/**
*
* @param zkey
* @param min
* @param max
* @return
*/
public Set<Double> rangeByScore(final String zkey,final Double min,final Double max){
return redisTemplate.opsForZSet().rangeByScore(zkey,min,max);
}
/**
*
* @param zkey
* @return
*/
public Map<Object, Double> getCacheZsetMin(final String zkey){
ZSetOperations.TypedTuple typedTuple = redisTemplate.opsForZSet().popMin(zkey);
return new HashMap<Object,Double>(){{put(typedTuple.getValue(),typedTuple.getScore());}};
}
/**
*
*
* @param pattern
*
* @return
*/
public Collection<String> keys (final String pattern) {
public Collection<String> keys(final String pattern) {
return redisTemplate.keys(pattern);
}
}

View File

@ -0,0 +1,19 @@
package com.zhilian.business;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @BelongsProject: smart-cloud-server
* @BelongsPackage: com.zhilian.business
* @Author: LiYuan
* @CreateTime: 2024-03-31 10:13
* @Description: TODO
* @Version: 1.0
*/
@SpringBootApplication
public class ZhilianBusinessApplication {
public static void main(String[] args) {
SpringApplication.run(ZhilianBusinessApplication.class);
}
}

View File

@ -0,0 +1,19 @@
package com.zhilian.manager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @BelongsProject: smart-cloud-server
* @BelongsPackage: com.zhilian.manager
* @Author: LiYuan
* @CreateTime: 2024-03-31 10:17
* @Description: TODO
* @Version: 1.0
*/
@SpringBootApplication
public class ZhilianMagagerApplication {
public static void main(String[] args) {
SpringApplication.run(ZhilianMagagerApplication.class,args);
}
}

View File

@ -78,6 +78,18 @@
<artifactId>zhilian-common-swagger</artifactId>
</dependency>
<!--rabbitMQ服务-->
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-test</artifactId>
</dependency>
<!-- mqttx依赖-->
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,23 @@
package com.zhilian.online;
import com.zhilian.common.security.annotation.EnableCustomConfig;
import com.zhilian.common.security.annotation.EnableMyFeignClients;
import com.zhilian.common.swagger.annotation.EnableCustomSwagger2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @version:
* @Author: LiYuan
* @description: 线
* @date: 2024/3/29 20:36
*/
@EnableCustomConfig
@EnableCustomSwagger2
@EnableMyFeignClients
@SpringBootApplication
public class ZhiLianOnlineApplication {
public static void main(String[] args) {
SpringApplication.run(ZhiLianOnlineApplication.class,args);
}
}

View File

@ -0,0 +1,107 @@
package com.zhilian.online.config;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.*;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
* @BelongsProject: smart-cloud-server
* @BelongsPackage: com.zhilian.online.config
* @Author: LiYuan
* @CreateTime: 2024-03-31 09:45
* @Description: TODO
* @Version: 1.0
*/
@Component
@Slf4j
public class MqttxConfig {
/**
*
*/
@Value("${mqtt.server.broker}")
private String broker;
/**
*
*/
@Value("${mqtt.server.topic}")
private String topic;
/**
* ID
*/
@Value("${mqtt.server.clientId}")
private String clientId;
/**
*
*/
@Value("${mqtt.server.username}")
private String username;
/**
*
*/
@Value("${mqtt.server.password}")
private String password;
/**
* qos
*/
@Value("${mqtt.server.qos}")
private Integer qos;
@PostConstruct
public void initMqtt() {
log.info("mqttx连接中......");
try {
MqttClient mqttClient = new MqttClient(broker, clientId, new MemoryPersistence());
MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
mqttConnectOptions.setUserName(username);
mqttConnectOptions.setPassword(password.toCharArray());
//链接超时
mqttConnectOptions.setConnectionTimeout(60);
//心跳检测
mqttConnectOptions.setKeepAliveInterval(60);
mqttClient.connect(mqttConnectOptions);
log.info("mqtt{}服务连接成功", broker);
//回调
mqttClient.setCallback(new MqttCallback() {
@Override
public void connectionLost(Throwable throwable) {
log.error("连接断开{}", throwable.getMessage());
}
@Override
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
log.info("消息到达,接受消息主题{},接受消息Qos{},接受消息内容{}", topic, mqttMessage.getQos(), new String(mqttMessage.getPayload()));
}
@Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
log.info("消息{}发送成功" + iMqttDeliveryToken.isComplete());
}
});
mqttClient.subscribe(topic,qos);
} catch (MqttException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,164 @@
package com.zhilian.online.config;/**
* @version:
* @Author: LiYuan
* @description:
* @date: 2024/3/30 19:33
*/
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* @BelongsProject: smart-cloud-server
* @BelongsPackage: com.zhilian.online.config
* @Author: LiYuan
* @CreateTime: 2024-03-30 19:33
* @Description: RabbitMQ
* @Version: 1.0
*/
@Configuration
@Slf4j
public class RabbitConfig {
/**
*
*/
public static final String DELAY_QUEUE_NAME = "delay_queue";
/**
*
*/
public static final String DELAY_EXCHANGE_NAME = "delay_exchange";
/**
*
*/
public static final String DELAY_ROUTING_KEY = "delay_routing";
/**
*
*/
public static final String DEAD_QUEUE_NAME = "dead_queue";
/**
*
*/
public static final String DEAD_EXCHANGE_NAME = "dead_exchange";
/**
*
*/
public static final String DEAD_ROUTING_KEY = "dead_routing";
/**
*
*
* @return Queue
*/
@Bean
Queue deadQueue() {
log.info("死信队列创建成功");
return new Queue(DEAD_QUEUE_NAME, true, false, false);
}
/**
*
*
* @return DirectExchange
*/
@Bean
DirectExchange deadExchange() {
log.info("死信交换机创建成功");
return new DirectExchange(DEAD_EXCHANGE_NAME, true, false);
}
/**
*
*
* @return Binding
*/
@Bean
Binding deadBinding() {
log.info("死信通道建立成功");
return BindingBuilder.bind(deadQueue())
.to(deadExchange())
.with(DEAD_ROUTING_KEY);
}
/**
*
*
* @return Queue
*/
@Bean
Queue delayQueue() {
Map<String, Object> map = new HashMap<>();
//设置消息过期时间为30秒
map.put("x-message-ttl", 1000 * 30);
//设置消息过期后存储的死信交换机
map.put("x-dead-letter-exchange", DEAD_EXCHANGE_NAME);
//设置死信路由键
map.put("x-dead-letter-routing-key", DEAD_ROUTING_KEY);
log.info("延迟队列创建成功");
return new Queue(DELAY_QUEUE_NAME, true, false, false, map);
}
/**
*
*
* @return DirectExchange
*/
@Bean
DirectExchange delayExchange() {
log.info("延迟交换机创建成功");
return new DirectExchange(DELAY_EXCHANGE_NAME, true, false);
}
/**
*
*
* @return
*/
@Bean
Binding delayBinding() {
log.info("延迟通道创建成功");
return BindingBuilder.bind(deadQueue())
.to(delayExchange())
.with(DELAY_ROUTING_KEY);
}
/**
* RabbitMq
* @param connectionFactory
* @return
*/
// @Bean
// public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory){
// RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
// rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
// return rabbitTemplate;
// }
// @Bean
// public MessageConverter jsonMessageConverter(){
// return new Jackson2JsonMessageConverter();
// }
}

View File

@ -0,0 +1,32 @@
package com.zhilian.online.constans;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @BelongsProject: smart-cloud-server
* @BelongsPackage: com.zhilian.online.constans
* @Author: LiYuan
* @CreateTime: 2024-03-31 09:35
* @Description: 线
* @Version: 1.0
*/
@Data
public class OnlineConstants {
/**
*
*/
public static final String ONLINE_TOKEN_PREFIX = "online_token:";
/**
*
*/
public static final Long ONLINE_TOKEN_EXPIRE = 60L;
/**
*
*/
public static final String NODE_LOAD_PREFIX = "node_load";
}

View File

@ -0,0 +1,39 @@
package com.zhilian.online.consumer;
import com.alibaba.fastjson.JSON;
import com.zhilian.online.config.RabbitConfig;
import com.zhilian.online.domain.req.GatherRegReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
/**
* @BelongsProject: smart-cloud-server
* @BelongsPackage: com.zhilian.online.consumer
* @Author: LiYuan
* @CreateTime: 2024-03-30 19:57
* @Description:
* @Version: 1.0
*/
@Component
@Slf4j
public class DeadQueueConsumer {
/**
* ,线
*/
@RabbitListener(queues = RabbitConfig.DEAD_QUEUE_NAME)
public void SecureOnline(String gatherRegReqMsg) {
GatherRegReq gatherRegReq = JSON.parseObject(gatherRegReqMsg, GatherRegReq.class);
log.info("开始检查节点{}的上线状态......",
gatherRegReq.getClientId());
log.info("节点上线成功");
log.info("节点上线失败");
}
}

View File

@ -0,0 +1,32 @@
package com.zhilian.online.controller;
import com.zhilian.common.core.domain.Result;
import com.zhilian.online.service.OnlineGatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @version:
* @Author: LiYuan
* @description:
* @date: 2024/3/29 20:46
*/
@RestController
@RequestMapping("/gather")
public class OnlineGatherController {
/**
*
*/
@Autowired
private OnlineGatherService onlineGatherService;
}

View File

@ -0,0 +1,83 @@
package com.zhilian.online.controller;
import com.alibaba.fastjson2.JSON;
import com.zhilian.common.core.domain.Result;
import com.zhilian.common.core.utils.ip.IpUtils;
import com.zhilian.common.core.web.controller.BaseController;
import com.zhilian.online.domain.Gather;
import com.zhilian.online.domain.req.GatherRegReq;
import com.zhilian.online.service.OnlineLoadCenterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
/**
* @version:
* @Author: LiYuan
* @description: Controller
* @date: 2024/3/29 20:40
*/
@RestController
@RequestMapping("/load/center")
@Slf4j
public class OnlineLoadCenterController extends BaseController {
/**
*
*/
@Autowired
private HttpServletRequest request;
/**
*
*/
@Autowired
private OnlineLoadCenterService onlineLoadCenterService;
/**
* @description: ,访
* @author: LiYuan
* @param: vehicle
* @return: Result<OnlineAccount>
**/
@GetMapping("/applyForReg")
public Result<String> applyForReg(){
log.info("申请注册令牌");
return onlineLoadCenterService.applyForReg();
}
/**
* @description:
* @author: LiYuan
* @param: Gather
* @return: Result
**/
@PostMapping("/regGather")
public Result regGather(@Validated Gather gather){
String ipAddr = IpUtils.getIpAddr(request);
gather.setIpAddress(ipAddr);
log.info("节点{}正在上线",gather);
return onlineLoadCenterService.regGather(gather);
}
/**
* 线
* @return null
*/
public Result getConnectionOption(){
return null;
}
}

View File

@ -0,0 +1,49 @@
package com.zhilian.online.controller;/**
* @version:
* @Author: LiYuan
* @description:
* @date: 2024/3/30 11:18
*/
import com.zhilian.common.core.domain.Result;
import com.zhilian.online.domain.model.MqttServerModel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @BelongsProject: smart-cloud-server
* @BelongsPackage: com.zhilian.online.controller
* @Author: LiYuan
* @CreateTime: 2024-03-30 11:18
* @Description: 线
* @Version: 1.0
*/
@RestController
@RequestMapping("/verify")
public class OnlineVerifyController {
/**
* mqtt
*/
@Value("${mqtt.server.broker}")
private String broker;
/**
*
*/
@Value("${mqtt.server.topic}")
private String topic;
@PostMapping("/vehicleConnection")
public Result<MqttServerModel> vehicleConnection() {
return Result.success(
MqttServerModel.builder()
.broker(broker)
.topic(topic)
.build()
);
}
}

View File

@ -0,0 +1,72 @@
package com.zhilian.online.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.zhilian.common.core.web.domain.BaseEntity;
import lombok.*;
import org.bouncycastle.util.IPAddress;
import javax.validation.constraints.NotBlank;
/**
* @BelongsProject: smart-cloud-server
* @BelongsPackage: com.zhilian.online.domain
* @Author: LiYuan
* @CreateTime: 2024-03-31 08:58
* @Description:
* @Version: 1.0
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Gather extends BaseEntity {
/**
* ID
*/
@TableId(type = IdType.INPUT)
private String clientId;
// /**
// * 收集节点登录令牌
// */
// @NotBlank
// private String token;
/**
* broker
*/
@NotBlank
private String broker;
/**
* username
*/
private String username;
/**
* password
*/
private String password;
/**
* qos
*/
private Integer qos;
/**
* topic
*/
@NotBlank
private String topic;
/**
* ip
*/
private String ipAddress;
}

View File

@ -0,0 +1,37 @@
//package com.zhilian.online.domain;/**
// * @version:
// * @Author: LiYuan
// * @description:
// * @date: 2024/3/29 21:44
// */
//
//import com.baomidou.mybatisplus.annotation.IdType;
//import com.baomidou.mybatisplus.annotation.TableId;
//import com.baomidou.mybatisplus.annotation.TableName;
//import com.zhilian.common.core.web.domain.BaseEntity;
//import lombok.*;
//
//import javax.validation.constraints.NotBlank;
//import javax.validation.constraints.NotNull;
//import java.util.Date;
//
///**
// *@BelongsProject: smart-cloud-server
// *@BelongsPackage: com.zhilian.online.domain
// *@Author: LiYuan
// *@CreateTime: 2024-03-29 21:44
// *@Description: 汽车类,测试使用
// *@Version: 1.0
// */
//@Data
////@AllArgsConstructor
////@NoArgsConstructor
//@Builder
//@ToString
//@EqualsAndHashCode(callSuper = true)
//@TableName("vehicle")
//public class Vehicle extends BaseEntity {
//
//
//
//}

View File

@ -0,0 +1,70 @@
package com.zhilian.online.domain;/**
* @version:
* @Author: LiYuan
* @description:
* @date: 2024/3/29 21:49
*/
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zhilian.common.core.web.domain.BaseEntity;
import lombok.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;
/**
*@BelongsProject: smart-cloud-server
*@BelongsPackage: com.zhilian.online.domain
*@Author: LiYuan
*@CreateTime: 2024-03-29 21:49
*@Description:
*@Version: 1.0
*/
@Data
@AllArgsConstructor
@NotBlank
@ToString
@EqualsAndHashCode(callSuper = true)
@TableName("vehicle_account")
public class VehicleAccount extends BaseEntity{
/**
* VIN
*/
@TableId(type = IdType.INPUT)
private String vin;
/**
*
*/
@NotNull
private Date applyTime;
/**
*
*/
@NotBlank
private String applyCode;
/**
*
*/
private String username;
/**
*
*/
private String password;
/**
* id
*/
private String clientId;
}

View File

@ -0,0 +1,37 @@
package com.zhilian.online.domain.model;/**
* @version:
* @Author: LiYuan
* @description:
* @date: 2024/3/30 11:19
*/
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
*@BelongsProject: smart-cloud-server
*@BelongsPackage: com.zhilian.online.domain.model
*@Author: LiYuan
*@CreateTime: 2024-03-30 11:19
*@Description: Mqtt
*@Version: 1.0
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MqttServerModel {
/**
* Mqtt
*/
private String broker;
/**
* Mqtt
*/
private String topic;
}

View File

@ -0,0 +1,34 @@
package com.zhilian.online.domain.req;
import lombok.*;
import javax.validation.constraints.NotBlank;
/**
* @BelongsProject: smart-cloud-server
* @BelongsPackage: com.zhilian.online.domain.req
* @Author: LiYuan
* @CreateTime: 2024-03-31 09:03
* @Description:
* @Version: 1.0
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Builder
public class GatherRegReq {
/**
* ID
*/
@NotBlank
private String clientId;
/**
*
*/
private String token;
}

View File

@ -0,0 +1,17 @@
package com.zhilian.online.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @version:
* @Author: LiYuan
* @description:
* @date: 2024/3/29 20:48
*/
@Mapper
public interface OnlineGatherMapper{
}

View File

@ -0,0 +1,18 @@
package com.zhilian.online.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhilian.online.domain.VehicleAccount;
import org.apache.ibatis.annotations.Mapper;
/**
* @version:
* @Author: LiYuan
* @description:
* @date: 2024/3/29 20:45
*/
@Mapper
public interface OnlineLoadCenterMapper extends BaseMapper<VehicleAccount> {
}

View File

@ -0,0 +1,14 @@
package com.zhilian.online.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zhilian.common.core.domain.Result;
/**
* @version:
* @Author: LiYuan
* @description: Service
* @date: 2024/3/29 20:48
*/
public interface OnlineGatherService{
}

View File

@ -0,0 +1,32 @@
package com.zhilian.online.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zhilian.common.core.domain.Result;
import com.zhilian.online.domain.Gather;
import com.zhilian.online.domain.VehicleAccount;
import com.zhilian.online.domain.req.GatherRegReq;
/**
* @version:
* @Author: LiYuan
* @description:
* @date: 2024/3/29 20:42
*/
public interface OnlineLoadCenterService extends IService<VehicleAccount> {
/**
* @description: ,访
* @author: LiYuan
* @param: vehicle
* @return: Result<OnlineAccount>
**/
Result<String> applyForReg();
/**
* @description: 使
* @author: LiYuan
* @param:
* @return: Result
**/
Result regGather(Gather gather);
}

View File

@ -0,0 +1,22 @@
package com.zhilian.online.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhilian.common.core.domain.Result;
import com.zhilian.online.mapper.OnlineGatherMapper;
import com.zhilian.online.service.OnlineGatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @version:
* @Author: LiYuan
* @description:
* @date: 2024/3/29 20:48
*/
@Service
public class OnlineGatherServiceImpl implements OnlineGatherService {
@Autowired
private OnlineGatherMapper onlineGatherMapper;
}

View File

@ -0,0 +1,96 @@
package com.zhilian.online.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhilian.common.core.domain.Result;
import com.zhilian.common.core.utils.uuid.IdUtils;
import com.zhilian.common.redis.service.RedisService;
import com.zhilian.online.config.RabbitConfig;
import com.zhilian.online.constans.OnlineConstants;
import com.zhilian.online.domain.Gather;
import com.zhilian.online.domain.VehicleAccount;
import com.zhilian.online.domain.req.GatherRegReq;
import com.zhilian.online.mapper.OnlineLoadCenterMapper;
import com.zhilian.online.service.OnlineLoadCenterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
/**
* @version 1.0
* @Author LiYuan
* @description
* @date 2024/3/29 20:42
*/
@Service
@Slf4j
public class OnlineLoadCenterServiceImpl extends ServiceImpl<OnlineLoadCenterMapper, VehicleAccount> implements OnlineLoadCenterService {
/**
*
*/
@Autowired
private OnlineLoadCenterMapper onlineLoadCenterMapper;
/**
* Redis
*/
@Autowired
private RedisService redisService;
/**
* RabbitMQ
*/
@Autowired
private RabbitTemplate rabbitTemplate;
/**
* @description: , 访
* @author: LiYuan
* @param: vehicle
* @return: Result<OnlineAccount>
**/
@Override
public Result<String> applyForReg() {
//生成一次性令牌
String token = IdUtils.fastSimpleUUID();
//将令牌信息缓存到Redis中
redisService.setCacheObject(OnlineConstants.ONLINE_TOKEN_PREFIX , token, OnlineConstants.ONLINE_TOKEN_EXPIRE, TimeUnit.MINUTES);
//将账户信息返回客户端
return Result.success(token);
}
/**
* @description: 线
* @author: LiYuan
* @param: Gather
* @return: Result
**/
@Override
public Result regGather(Gather gather) {
// //判断登录令牌是否过期,一致
// if (redisService.hasKey(OnlineConstants.ONLINE_TOKEN_PREFIX + gather.getClientId())) {
// return Result.error("令牌已过期");
// }
//为该节点创建负载均衡缓存
if (redisService.hasKey(OnlineConstants.ONLINE_TOKEN_PREFIX + gather.getClientId())) {
redisService.deleteObject(OnlineConstants.ONLINE_TOKEN_PREFIX + gather.getClientId());
}
redisService.setCacheZsetValue(OnlineConstants.ONLINE_TOKEN_PREFIX + gather.getClientId(), gather, 0.0);
// //向RabbitMQ||RocketMQ发送30s延迟消息,确保后续节点上线
// rabbitTemplate.convertAndSend(RabbitConfig.DELAY_EXCHANGE_NAME, RabbitConfig.DELAY_ROUTING_KEY, JSON.toJSONString(gather));
return Result.success("节点上线");
}
}

View File

@ -1,2 +1,25 @@
Spring Boot Version: ${spring-boot.version}
Spring Application Name: ${spring.application.name}
/*
* God Bless No Bugs!
*
* _ooOoo_
* o8888888o
* 88" . "88
* (| -_- |)
* O\ = /O
* ____/`---'\____
* .' \\| |// `.
* / \\||| : |||// \
* / _||||| -:- |||||- \
* | | \\\ - /// | |
* | \_| ''\---/'' | |
* \ .-\__ `-` ___/-. /
* ___`. .' /--.--\ `. . __
* ."" '< `.___\_<|>_/___.' >'"".
* | | : `- \`.;`\ _ /`;.`/ - ` : | |
* \ \ `-. \_ __\ /__ _/ .-` / /
* ======`-.____`-.___\_____/___.-`____.-'======
* `=---='
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*/

View File

@ -0,0 +1,7 @@
<?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.zhilian.online.mapper.OnlineGatherMapper">
</mapper>

View File

@ -0,0 +1,7 @@
<?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.zhilian.online.mapper.OnlineLoadCenterMapper">
</mapper>

View File

@ -0,0 +1,19 @@
package com.zhilian.resolver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @BelongsProject: smart-cloud-server
* @BelongsPackage: com.zhilian.resolver
* @Author: LiYuan
* @CreateTime: 2024-03-31 10:11
* @Description: TODO
* @Version: 1.0
*/
@SpringBootApplication
public class ZhilianResolverApplication {
public static void main(String[] args) {
SpringApplication.run(ZhilianResolverApplication.class,args);
}
}