优化代码第三次
parent
6b571dfddc
commit
35fa5b2ed9
|
@ -7,20 +7,21 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-10-07-21:51
|
* @ Date:2024-10-07-21:51
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:删除实例方法
|
* @ Description:删除实例方法
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@Component
|
@Component
|
||||||
public class DeleteSample implements DisposableBean {
|
public class DeleteSample implements DisposableBean {
|
||||||
@Autowired
|
@Autowired
|
||||||
private AliYunEcsService aliYunEcsService;
|
private AliYunEcsService aliYunEcsService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
try {
|
try {
|
||||||
log.info("===开始执行删除实例方法");
|
log.info("===开始执行删除实例方法");
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@Component
|
@Component
|
||||||
public class Sample implements ApplicationRunner{
|
public class Sample implements ApplicationRunner {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AliYunEcsService aliYunEcsService;
|
private AliYunEcsService aliYunEcsService;
|
||||||
|
@ -46,7 +46,7 @@ public class Sample implements ApplicationRunner{
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
List<AliInstance> aliInstances = aliYunEcsService.selectInstance(list);
|
List<AliInstance> aliInstances = aliYunEcsService.selectInstance(list);
|
||||||
log.info("================查询实例信息成功:{}",aliInstances);
|
log.info("================查询实例信息成功:{}", aliInstances);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
|
|
|
@ -7,12 +7,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-09-17-15:00
|
* @ Date:2024-09-17-15:00
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:故障启动类
|
* @ Description:故障启动类
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@EnableCustomConfig
|
@EnableCustomConfig
|
||||||
|
|
|
@ -19,29 +19,49 @@ import org.springframework.context.annotation.Configuration;
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@Configuration
|
@Configuration
|
||||||
public class RabbitmqConfig {
|
public class RabbitmqConfig {
|
||||||
// 日志
|
/**
|
||||||
|
* 日志
|
||||||
|
*/
|
||||||
private static final Logger logger = LoggerFactory.getLogger(RabbitmqConfig.class);
|
private static final Logger logger = LoggerFactory.getLogger(RabbitmqConfig.class);
|
||||||
|
|
||||||
/**
|
|
||||||
* 队列
|
|
||||||
*/
|
|
||||||
public static final String QUEUE_INFORM_EMAIL = "queue_inform_email";
|
|
||||||
/**
|
|
||||||
* 队列
|
|
||||||
*/
|
|
||||||
public static final String QUEUE_INFORM_SMS = "queue_inform_sms";
|
|
||||||
/**
|
/**
|
||||||
* 交换机
|
* 交换机
|
||||||
*/
|
*/
|
||||||
public static final String EXCHANGE_TOPICS_INFORM = "exchange_topics_inform";
|
public static final String EXCHANGE_TOPICS_INFORM = "exchange_topics_inform";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 路由key
|
* 队列 车辆上线给事件系统发送vin
|
||||||
|
*/
|
||||||
|
public static final String QUEUE_INFORM_EMAIL = "queue_inform_email";
|
||||||
|
/**
|
||||||
|
* 队列 协议解析
|
||||||
|
*/
|
||||||
|
public static final String QUEUE_INFORM_SMS = "queue_inform_sms";
|
||||||
|
/**
|
||||||
|
* 队列 车辆下线给事件系统发送vin
|
||||||
|
*/
|
||||||
|
public static final String QUEUE_INFORM_SEND = "queue_inform_send";
|
||||||
|
/**
|
||||||
|
* 队列 saas系统
|
||||||
|
*/
|
||||||
|
public static final String QUEUE_INFORM_SAAS = "queue_inform_saas";
|
||||||
|
/**
|
||||||
|
* 路由key 车辆上线给事件系统
|
||||||
*/
|
*/
|
||||||
public static final String ROUTINGKEY_EMAIL = "inform.#.email.#";
|
public static final String ROUTINGKEY_EMAIL = "inform.#.email.#";
|
||||||
/**
|
/**
|
||||||
* 路由key
|
* 路由key 协议解析
|
||||||
*/
|
*/
|
||||||
public static final String ROUTINGKEY_SMS = "inform.#.sms.#";
|
public static final String ROUTINGKEY_SMS = "inform.#.sms.#";
|
||||||
|
/**
|
||||||
|
* 路由key 车辆下线给事件系统
|
||||||
|
*/
|
||||||
|
public static final String ROUTINGKEY_SEND = "inform.#.send.#";
|
||||||
|
/**
|
||||||
|
* 路由key saas系统
|
||||||
|
*/
|
||||||
|
public static final String ROUTINGKEY_SAAS = "inform.#.saas.#";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 声明交换机,做持久化
|
* 声明交换机,做持久化
|
||||||
|
@ -58,7 +78,9 @@ public class RabbitmqConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 声明QUEUE_INFORM_EMAIL队列
|
/**
|
||||||
|
* 声明QUEUE_INFORM_EMAIL 队列
|
||||||
|
*/
|
||||||
@Bean(QUEUE_INFORM_EMAIL)
|
@Bean(QUEUE_INFORM_EMAIL)
|
||||||
public Queue queueInformEmail() {
|
public Queue queueInformEmail() {
|
||||||
try {
|
try {
|
||||||
|
@ -71,7 +93,9 @@ public class RabbitmqConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 声明QUEUE_INFORM_SMS队列
|
/**
|
||||||
|
* 声明QUEUE_INFORM_SMS 队列
|
||||||
|
*/
|
||||||
@Bean(QUEUE_INFORM_SMS)
|
@Bean(QUEUE_INFORM_SMS)
|
||||||
public Queue queueInformSms() {
|
public Queue queueInformSms() {
|
||||||
try {
|
try {
|
||||||
|
@ -84,17 +108,82 @@ public class RabbitmqConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//ROUTINGKEY_EMAIL队列绑定交换机,指定routingKey
|
/**
|
||||||
|
* QUEUE_INFORM_SEND 队列
|
||||||
|
*/
|
||||||
|
@Bean(QUEUE_INFORM_SEND)
|
||||||
|
public Queue queueInformSend() {
|
||||||
|
try {
|
||||||
|
Queue queue = new Queue(QUEUE_INFORM_SEND);
|
||||||
|
log.info("创建的队列为: {}", QUEUE_INFORM_SEND);
|
||||||
|
return queue;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("创建该: {} 队列失败", QUEUE_INFORM_SEND, e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QUEUE_INFORM_SAAS 队列
|
||||||
|
*/
|
||||||
|
@Bean(QUEUE_INFORM_SAAS)
|
||||||
|
public Queue queueInformSaas() {
|
||||||
|
try {
|
||||||
|
Queue queue = new Queue(QUEUE_INFORM_SAAS);
|
||||||
|
log.info("创建的队列为: {}", QUEUE_INFORM_SAAS);
|
||||||
|
return queue;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("创建该: {} 队列失败", QUEUE_INFORM_SAAS, e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QUEUE_INFORM_EMAIL队列绑定交换机,指定routingKey ROUTINGKEY_EMAIL
|
||||||
|
*
|
||||||
|
* @param queue QUEUE_INFORM_EMAIL
|
||||||
|
* @param exchange EXCHANGE_TOPICS_INFORM
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public Binding bindingQueueInformEmail(@Qualifier(QUEUE_INFORM_EMAIL) Queue queue,
|
public Binding bindingQueueInformEmail(@Qualifier(QUEUE_INFORM_EMAIL) Queue queue,
|
||||||
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
|
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
|
||||||
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_EMAIL).noargs();
|
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_EMAIL).noargs();
|
||||||
}
|
}
|
||||||
|
|
||||||
//ROUTINGKEY_SMS队列绑定交换机,指定routingKey
|
/**
|
||||||
|
* QUEUE_INFORM_SMS 队列绑定交换机,指定routingKey ROUTINGKEY_SMS
|
||||||
|
*
|
||||||
|
* @param queue QUEUE_INFORM_SMS
|
||||||
|
* @param exchange EXCHANGE_TOPICS_INFORM
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public Binding bindingRoutingKeySms(@Qualifier(QUEUE_INFORM_SMS) Queue queue,
|
public Binding bindingRoutingKeySms(@Qualifier(QUEUE_INFORM_SMS) Queue queue,
|
||||||
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
|
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
|
||||||
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SMS).noargs();
|
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SMS).noargs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QUEUE_INFORM_SEND队列绑定交换机,指定routingKey ROUTINGKEY_SEND
|
||||||
|
*
|
||||||
|
* @param queue QUEUE_INFORM_SEND
|
||||||
|
* @param exchange EXCHANGE_TOPICS_INFORM
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public Binding bindingRoutingKeySend(@Qualifier(QUEUE_INFORM_SEND) Queue queue,
|
||||||
|
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
|
||||||
|
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SEND).noargs();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QUEUE_INFORM_SAAS队列绑定交换机,指定routingKey ROUTINGKEY_SAAS
|
||||||
|
*
|
||||||
|
* @param queue QUEUE_INFORM_SAAS
|
||||||
|
* @param exchange EXCHANGE_TOPICS_INFORM
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public Binding bindingRoutingKeySaas(@Qualifier(QUEUE_INFORM_SAAS) Queue queue,
|
||||||
|
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange) {
|
||||||
|
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SAAS).noargs();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,29 +13,30 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-09-26-20:14
|
* @ Date:2024-09-26-20:14
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:车辆
|
* @ Description:车辆
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/vehicleGateway")
|
@RequestMapping("/vehicleGateway")
|
||||||
@Tag(name = "连接车辆控制层")
|
@Tag(name = "连接车辆控制层")
|
||||||
public class CarOneClickOperationController {
|
public class CarOneClickOperationController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private CarOneClickOperationService carOneClickOperationService;
|
private CarOneClickOperationService carOneClickOperationService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取http连接的参数
|
* 获取http连接的参数
|
||||||
|
*
|
||||||
* @param vehicleConnectionReq
|
* @param vehicleConnectionReq
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/receiveMsg/connect")
|
@PostMapping("/receiveMsg/connect")
|
||||||
public Result<MqttServerModel> receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){
|
public Result<MqttServerModel> receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq) {
|
||||||
log.info(">"+vehicleConnectionReq);
|
log.info("======================" + vehicleConnectionReq);
|
||||||
return carOneClickOperationService.getConnect(vehicleConnectionReq);
|
return carOneClickOperationService.getConnect(vehicleConnectionReq);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,12 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-09-30-9:33
|
* @ Date:2024-09-30-9:33
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:
|
* @ Description:
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
|
@ -19,7 +19,7 @@ import lombok.NoArgsConstructor;
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class AliInstance {
|
public class AliInstance {
|
||||||
/**
|
/**
|
||||||
*实例ID
|
* 实例ID
|
||||||
*/
|
*/
|
||||||
private String instanceId;
|
private String instanceId;
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,12 +5,12 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-09-28-16:37
|
* @ Date:2024-09-28-16:37
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:创建实例的配置
|
* @ Description:创建实例的配置
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
|
|
@ -5,12 +5,12 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-10-04-15:16
|
* @ Date:2024-10-04-15:16
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:车辆服务器
|
* @ Description:车辆服务器
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
|
|
@ -1,93 +0,0 @@
|
||||||
package com.muyu.car.gateway.domain;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 返回状态码
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
public class HttpStatus {
|
|
||||||
/**
|
|
||||||
* 操作成功
|
|
||||||
*/
|
|
||||||
public static final int SUCCESS = 200;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 对象创建成功
|
|
||||||
*/
|
|
||||||
public static final int CREATED = 201;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 请求已经被接受
|
|
||||||
*/
|
|
||||||
public static final int ACCEPTED = 202;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 操作已经执行成功,但是没有返回数据
|
|
||||||
*/
|
|
||||||
public static final int NO_CONTENT = 204;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 资源已被移除
|
|
||||||
*/
|
|
||||||
public static final int MOVED_PERM = 301;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 重定向
|
|
||||||
*/
|
|
||||||
public static final int SEE_OTHER = 303;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 资源没有被修改
|
|
||||||
*/
|
|
||||||
public static final int NOT_MODIFIED = 304;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 参数列表错误(缺少,格式不匹配)
|
|
||||||
*/
|
|
||||||
public static final int BAD_REQUEST = 400;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 未授权
|
|
||||||
*/
|
|
||||||
public static final int UNAUTHORIZED = 401;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 访问受限,授权过期
|
|
||||||
*/
|
|
||||||
public static final int FORBIDDEN = 403;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 资源,服务未找到
|
|
||||||
*/
|
|
||||||
public static final int NOT_FOUND = 404;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 不允许的http方法
|
|
||||||
*/
|
|
||||||
public static final int BAD_METHOD = 405;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 资源冲突,或者资源被锁
|
|
||||||
*/
|
|
||||||
public static final int CONFLICT = 409;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 不支持的数据,媒体类型
|
|
||||||
*/
|
|
||||||
public static final int UNSUPPORTED_TYPE = 415;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统内部错误
|
|
||||||
*/
|
|
||||||
public static final int ERROR = 500;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 接口未实现
|
|
||||||
*/
|
|
||||||
public static final int NOT_IMPLEMENTED = 501;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统警告消息
|
|
||||||
*/
|
|
||||||
public static final int WARN = 601;
|
|
||||||
}
|
|
|
@ -9,23 +9,23 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-09-27-20:56
|
* @ Date:2024-09-27-20:56
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:服务器配置
|
* @ Description:服务器配置
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@TableName(value="server_config")
|
@TableName(value = "server_config")
|
||||||
public class ServerConfig {
|
public class ServerConfig {
|
||||||
/**
|
/**
|
||||||
* 主键
|
* 主键
|
||||||
*/
|
*/
|
||||||
@TableId(value = "id",type = IdType.AUTO)
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
/**
|
/**
|
||||||
* 租户id
|
* 租户id
|
||||||
|
|
|
@ -5,12 +5,12 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-10-06-11:05
|
* @ Date:2024-10-06-11:05
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:车辆鉴权的参数
|
* @ Description:车辆鉴权的参数
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
|
|
@ -5,12 +5,12 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-10-03-10:10
|
* @ Date:2024-10-03-10:10
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:车辆vin
|
* @ Description:车辆vin
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
|
|
@ -6,12 +6,12 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-10-03-10:12
|
* @ Date:2024-10-03-10:12
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:Mqtt服务模型
|
* @ Description:Mqtt服务模型
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
|
|
|
@ -6,12 +6,12 @@ import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-10-03-10:04
|
* @ Date:2024-10-03-10:04
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:车辆获取连接地址
|
* @ Description:车辆获取连接地址
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
|
|
|
@ -6,12 +6,12 @@ import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-09-26-15:53
|
* @ Date:2024-09-26-15:53
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:调用Ali服务器配置实体类
|
* @ Description:调用Ali服务器配置实体类
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@SuperBuilder
|
@SuperBuilder
|
||||||
|
@ -21,7 +21,7 @@ public class AliServerConfig {
|
||||||
/**
|
/**
|
||||||
* 主键
|
* 主键
|
||||||
*/
|
*/
|
||||||
private Long id;
|
private Long id;
|
||||||
/**
|
/**
|
||||||
* 地域id (实例所属的地域ID)
|
* 地域id (实例所属的地域ID)
|
||||||
*/
|
*/
|
||||||
|
@ -29,7 +29,7 @@ public class AliServerConfig {
|
||||||
/**
|
/**
|
||||||
* 镜像id
|
* 镜像id
|
||||||
*/
|
*/
|
||||||
private String imageId;
|
private String imageId;
|
||||||
/**
|
/**
|
||||||
* 实例规格 (实例的资源规格)
|
* 实例规格 (实例的资源规格)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -6,12 +6,12 @@ import org.apache.ibatis.annotations.Mapper;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-09-26-20:15
|
* @ Date:2024-09-26-20:15
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:车辆一键操作持久层
|
* @ Description:车辆一键操作持久层
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface CarOneClickOperationMapper {
|
public interface CarOneClickOperationMapper {
|
||||||
|
|
|
@ -5,17 +5,18 @@ import com.muyu.car.gateway.domain.req.VehicleConnectionReq;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-09-26-20:15
|
* @ Date:2024-09-26-20:15
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:车辆一键操作业务层
|
* @ Description:车辆一键操作业务层
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
public interface CarOneClickOperationService {
|
public interface CarOneClickOperationService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取连接
|
* 获取连接
|
||||||
|
*
|
||||||
* @param vehicleConnectionReq 车辆连接请求参数
|
* @param vehicleConnectionReq 车辆连接请求参数
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -12,7 +12,6 @@ import com.muyu.common.redis.service.RedisService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.HashOperations;
|
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@ -22,12 +21,12 @@ import static com.muyu.car.gateway.config.RabbitmqConfig.EXCHANGE_TOPICS_INFORM;
|
||||||
import static com.muyu.car.gateway.config.RabbitmqConfig.ROUTINGKEY_SMS;
|
import static com.muyu.car.gateway.config.RabbitmqConfig.ROUTINGKEY_SMS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @author Lenovo
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
* @ Date:2024-09-26-20:16
|
* @ Date:2024-09-26-20:16
|
||||||
* @ Version:1.0
|
* @ Version:1.0
|
||||||
* @ Description:车辆一键操作业务实现层
|
* @ Description:车辆一键操作业务实现层
|
||||||
* @author Lenovo
|
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@Service
|
@Service
|
||||||
|
@ -44,16 +43,13 @@ public class CarOneClickOperationServiceImpl implements CarOneClickOperationServ
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取连接信息
|
* 获取连接信息
|
||||||
|
*
|
||||||
* @param vehicleConnectionReq 车辆连接请求参数
|
* @param vehicleConnectionReq 车辆连接请求参数
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result<MqttServerModel> getConnect(VehicleConnectionReq vehicleConnectionReq) {
|
public Result<MqttServerModel> getConnect(VehicleConnectionReq vehicleConnectionReq) {
|
||||||
log.info("车辆连接请求:{}",vehicleConnectionReq.toString());
|
log.info("车辆连接请求:{}", vehicleConnectionReq.toString());
|
||||||
|
|
||||||
// // 使用交换机发送消息 给事件系统发
|
|
||||||
// rabbitTemplate.convertAndSend("exchange_topics_inform","inform.#.email.#",vehicleConnectionReq.getVehicleVin());
|
|
||||||
// log.info("发送消息成功:{}",vehicleConnectionReq.getVehicleVin());
|
|
||||||
|
|
||||||
VehicleConnection vehicleConnection = new VehicleConnection();
|
VehicleConnection vehicleConnection = new VehicleConnection();
|
||||||
//车辆vin
|
//车辆vin
|
||||||
|
@ -61,23 +57,22 @@ public class CarOneClickOperationServiceImpl implements CarOneClickOperationServ
|
||||||
//用户名
|
//用户名
|
||||||
vehicleConnection.setUsername(vehicleConnectionReq.getUsername());
|
vehicleConnection.setUsername(vehicleConnectionReq.getUsername());
|
||||||
//密码(vin+时间戳+随机数)
|
//密码(vin+时间戳+随机数)
|
||||||
vehicleConnection.setPassword(vehicleConnectionReq.getVehicleVin()+vehicleConnectionReq.getTimestamp()+vehicleConnectionReq.getNonce());
|
vehicleConnection.setPassword(vehicleConnectionReq.getVehicleVin() + vehicleConnectionReq.getTimestamp() + vehicleConnectionReq.getNonce());
|
||||||
//查询有没有这辆车的vin码
|
//查询有没有这辆车的vin码
|
||||||
List<String> selectVehicle = carOneClickOperationMapper.selectByVehicleVin(vehicleConnectionReq.getVehicleVin());
|
List<String> selectVehicle = carOneClickOperationMapper.selectByVehicleVin(vehicleConnectionReq.getVehicleVin());
|
||||||
|
|
||||||
if(selectVehicle.isEmpty()){
|
if (selectVehicle.isEmpty()) {
|
||||||
//添加连接信息
|
//添加连接信息
|
||||||
carOneClickOperationMapper.addConnect(vehicleConnection);
|
carOneClickOperationMapper.addConnect(vehicleConnection);
|
||||||
log.info("车辆上线成功");
|
log.info("车辆上线成功");
|
||||||
}else {
|
} else {
|
||||||
throw new RuntimeException("车辆无法重复上线");
|
throw new RuntimeException("车辆无法重复上线");
|
||||||
|
|
||||||
}
|
}
|
||||||
//先判断vin码
|
//先判断vin码
|
||||||
HashOperations<String, String, String> hashOps = redisTemplate.opsForHash();
|
if (redisService.hasKey(vehicleConnectionReq.getVehicleVin())) {
|
||||||
String vinIp = hashOps.get("oneVinIp", vehicleConnectionReq.getVehicleVin());
|
log.error("=============车辆:{}已经绑定过了", vehicleConnectionReq.getVehicleVin());
|
||||||
if(vinIp!=null){
|
throw new RuntimeException("=============车辆已经绑定过了");
|
||||||
throw new RuntimeException("车辆绑定ip失败,已经存在");
|
|
||||||
}
|
}
|
||||||
MqttProperties mqttProperties = new MqttProperties();
|
MqttProperties mqttProperties = new MqttProperties();
|
||||||
List<VehicleConnection> vehicleVin = selectByVehicleVin(vehicleConnectionReq.getVehicleVin());
|
List<VehicleConnection> vehicleVin = selectByVehicleVin(vehicleConnectionReq.getVehicleVin());
|
||||||
|
@ -89,43 +84,44 @@ public class CarOneClickOperationServiceImpl implements CarOneClickOperationServ
|
||||||
mqttProperties.setTopic("vehicle");
|
mqttProperties.setTopic("vehicle");
|
||||||
mqttProperties.setQos(0);
|
mqttProperties.setQos(0);
|
||||||
//判断redis有没有count键
|
//判断redis有没有count键
|
||||||
if(redisTemplate.hasKey("oneCount")){
|
if (redisTemplate.hasKey("oneCount")) {
|
||||||
//取出count
|
//取出count
|
||||||
Integer count = Integer.valueOf(redisTemplate.opsForValue().get("oneCount"));
|
Integer count = Integer.valueOf(redisTemplate.opsForValue().get("oneCount"));
|
||||||
if(count == 1){
|
if (count == 1) {
|
||||||
redisTemplate.opsForValue().set("oneCount",String.valueOf(0));
|
redisTemplate.opsForValue().set("oneCount", String.valueOf(0));
|
||||||
}else {
|
} else {
|
||||||
redisTemplate.opsForValue().set("oneCount",String.valueOf(count+1));
|
redisTemplate.opsForValue().set("oneCount", String.valueOf(count + 1));
|
||||||
}
|
}
|
||||||
//根据游标count获取服务IP
|
//根据游标count获取服务IP
|
||||||
// String ip = redisTemplate.opsForList().index("ipList", count);
|
// String ip = redisTemplate.opsForList().index("ipList", count);
|
||||||
Object ipList = redisService.redisTemplate.opsForList().index("oneIpList", count);
|
Object ipList = redisService.redisTemplate.opsForList().index("oneIpList", count);
|
||||||
|
|
||||||
log.info("=========================oneIpList:"+ipList);
|
log.info("=========================oneIpList:" + ipList);
|
||||||
//关联车辆和服务
|
//关联车辆和服务
|
||||||
this.addIpAddress(new VinIp(vehicleConnectionReq.getVehicleVin(),ipList.toString()));
|
this.addIpAddress(new VinIp(vehicleConnectionReq.getVehicleVin(), ipList.toString()));
|
||||||
//响应信息
|
//响应信息
|
||||||
log.info("车辆:{}",vehicleConnectionReq.getVehicleVin()+"绑定成功:{}",ipList);
|
log.info("车辆:{}", vehicleConnectionReq.getVehicleVin() + "绑定成功:{}", ipList);
|
||||||
mqttProperties.setBroker("tcp://"+ipList+":1883");
|
mqttProperties.setBroker("tcp://" + ipList + ":1883");
|
||||||
// 使用交换机发送消息
|
// 使用交换机发送消息
|
||||||
rabbitTemplate.convertAndSend(EXCHANGE_TOPICS_INFORM,ROUTINGKEY_SMS,mqttProperties);
|
rabbitTemplate.convertAndSend(EXCHANGE_TOPICS_INFORM, ROUTINGKEY_SMS, mqttProperties);
|
||||||
log.info("============================发送消息成功:{}",mqttProperties);
|
log.info("============================发送消息成功:{}", mqttProperties);
|
||||||
return Result.success(new MqttServerModel("tcp://"+ipList+":1883","vehicle"));
|
return Result.success(new MqttServerModel("tcp://" + ipList + ":1883", "vehicle"));
|
||||||
}else {
|
} else {
|
||||||
redisTemplate.opsForValue().set("oneCount",String.valueOf(0));
|
redisTemplate.opsForValue().set("oneCount", String.valueOf(0));
|
||||||
//根据游标count获取服务器Ip
|
//根据游标count获取服务器Ip
|
||||||
Object ipList = redisService.redisTemplate.opsForList().index("oneIpList", 0);
|
Object ipList = redisService.redisTemplate.opsForList().index("oneIpList", 0);
|
||||||
//关联车辆和服务
|
//关联车辆和服务
|
||||||
this.addIpAddress(new VinIp(vehicleConnectionReq.getVehicleVin(),ipList.toString()));
|
this.addIpAddress(new VinIp(vehicleConnectionReq.getVehicleVin(), ipList.toString()));
|
||||||
//响应信息
|
//响应信息
|
||||||
log.info("车辆:{}",vehicleConnectionReq.getVehicleVin(),"与:{}绑定成功",ipList);
|
log.info("车辆:{}", vehicleConnectionReq.getVehicleVin(), "与:{}绑定成功", ipList);
|
||||||
mqttProperties.setBroker("tcp://"+ipList+":1883");
|
mqttProperties.setBroker("tcp://" + ipList + ":1883");
|
||||||
// 使用交换机发送消息
|
// 使用交换机发送消息
|
||||||
rabbitTemplate.convertAndSend(EXCHANGE_TOPICS_INFORM,ROUTINGKEY_SMS,mqttProperties);
|
rabbitTemplate.convertAndSend(EXCHANGE_TOPICS_INFORM, ROUTINGKEY_SMS, mqttProperties);
|
||||||
log.info("============================发送消息成功:{}",mqttProperties);
|
log.info("============================发送消息成功:{}", mqttProperties);
|
||||||
return Result.success(new MqttServerModel("tcp://"+ipList+":1883","vehicle"));
|
return Result.success(new MqttServerModel("tcp://" + ipList + ":1883", "vehicle"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加车辆绑定IP地址存入redis中
|
* 添加车辆绑定IP地址存入redis中
|
||||||
*/
|
*/
|
||||||
|
@ -133,15 +129,16 @@ public class CarOneClickOperationServiceImpl implements CarOneClickOperationServ
|
||||||
if (vinIp == null || vinIp.getVin() == null || vinIp.getVin().isEmpty() || vinIp.getIp() == null || vinIp.getIp().isEmpty()) {
|
if (vinIp == null || vinIp.getVin() == null || vinIp.getVin().isEmpty() || vinIp.getIp() == null || vinIp.getIp().isEmpty()) {
|
||||||
throw new IllegalArgumentException("vin 或 ip 不能为空或无效");
|
throw new IllegalArgumentException("vin 或 ip 不能为空或无效");
|
||||||
}
|
}
|
||||||
redisTemplate.opsForHash().put("oneVinIp", vinIp.getVin(), vinIp.getIp());
|
redisService.setCacheObject(vinIp.getVin(), vinIp.getIp());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询车辆绑定的服务器信息
|
* 查询车辆绑定的服务器信息
|
||||||
|
*
|
||||||
* @param vehicleVin 车辆vin码集合
|
* @param vehicleVin 车辆vin码集合
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<VehicleConnection> selectByVehicleVin(String vehicleVin) {
|
public List<VehicleConnection> selectByVehicleVin(String vehicleVin) {
|
||||||
return carOneClickOperationMapper.getMqttServerModel(vehicleVin);
|
return carOneClickOperationMapper.getMqttServerModel(vehicleVin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Tomcat
|
# Tomcat
|
||||||
server:
|
server:
|
||||||
port: 12900
|
port: 10099
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
|
@ -27,10 +27,10 @@ spring:
|
||||||
publisher-returns: true #确认消息已发送到队列(Queue)
|
publisher-returns: true #确认消息已发送到队列(Queue)
|
||||||
amqp:
|
amqp:
|
||||||
deserialization:
|
deserialization:
|
||||||
trust:
|
trust:
|
||||||
all: true
|
all: true
|
||||||
main:
|
main:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
|
|
||||||
application:
|
application:
|
||||||
# 应用名称
|
# 应用名称
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!DOCTYPE mapper
|
<!DOCTYPE mapper
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.muyu.car.gateway.mapper.CarOneClickOperationMapper">
|
<mapper namespace="com.muyu.car.gateway.mapper.CarOneClickOperationMapper">
|
||||||
|
|
||||||
|
|
||||||
<insert id="addConnect">
|
<insert id="addConnect">
|
||||||
insert into car_one_click_operation
|
insert into car_one_click_operation
|
||||||
(vehicle_vin,user_name,password)
|
(vin, user_name, password)
|
||||||
values
|
values (#{vehicleVin}, #{username}, #{password})
|
||||||
(#{vehicleVin},#{username},#{password})
|
|
||||||
</insert>
|
</insert>
|
||||||
<select id="selectByVehicleVin" resultType="java.lang.String">
|
<select id="selectByVehicleVin" resultType="java.lang.String">
|
||||||
select vehicle_vin from car_one_click_operation where vehicle_vin = #{vehicleVin}
|
select vin
|
||||||
|
from car_one_click_operation
|
||||||
|
where vin = #{vehicleVin}
|
||||||
</select>
|
</select>
|
||||||
<select id="getMqttServerModel" resultType="com.muyu.car.gateway.domain.VehicleConnection">
|
<select id="getMqttServerModel" resultType="com.muyu.car.gateway.domain.VehicleConnection">
|
||||||
select
|
select vin vehicleVin,
|
||||||
vehicle_vin,user_name,password
|
user_name,
|
||||||
from
|
password
|
||||||
car_one_click_operation
|
from car_one_click_operation
|
||||||
where
|
where vin = #{vehicleVin}
|
||||||
vehicle_vin = #{vehicleVin}
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class WarnLogs {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
.append("id", getId())
|
.append("id", getId())
|
||||||
.append("vin", getVin())
|
.append("vin", getVehicleVin())
|
||||||
.append("warnRuleId", getWarnRuleId())
|
.append("warnRuleId", getWarnRuleId())
|
||||||
.append("startTime", getStartTime())
|
.append("startTime", getStartTime())
|
||||||
.append("endTime", getEndTime())
|
.append("endTime", getEndTime())
|
||||||
|
|
Loading…
Reference in New Issue