接受到vin 用户名 时间戳 随机数 拼接存库
parent
b318c0e30b
commit
f5d6b5c00d
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 106.54.193.225:8848
|
addr: 47.116.173.119:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: one-saas
|
namespace: one-saas
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 106.54.193.225:8848
|
addr: 47.116.173.119:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: one-saas
|
namespace: one-saas
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 106.54.193.225:8848
|
addr: 47.116.173.119:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: one
|
namespace: one
|
||||||
|
|
|
@ -67,28 +67,28 @@
|
||||||
<artifactId>cloud-common-datascope</artifactId>
|
<artifactId>cloud-common-datascope</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- MuYu Common Log -->
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>com.muyu</groupId>-->
|
|
||||||
<!-- <artifactId>cloud-common-log</artifactId>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
|
|
||||||
<!-- 接口模块 -->
|
<!-- 接口模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-api-doc</artifactId>
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- <!– XllJob定时任务 –>-->
|
<!-- http协议 -->
|
||||||
<!-- <dependency>-->
|
<dependency>
|
||||||
<!-- <groupId>com.muyu</groupId>-->
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<!-- <artifactId>cloud-common-xxl</artifactId>-->
|
<artifactId>httpcore</artifactId>
|
||||||
<!-- </dependency>-->
|
<version>4.4.12</version>
|
||||||
|
</dependency>
|
||||||
<!-- <dependency>-->
|
<dependency>
|
||||||
<!-- <groupId>com.muyu</groupId>-->
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<!-- <artifactId>cloud-common-rabbit</artifactId>-->
|
<artifactId>httpclient</artifactId>
|
||||||
<!-- </dependency>-->
|
<version>4.5.13</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- mq-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.aliyun</groupId>
|
<groupId>com.aliyun</groupId>
|
||||||
<artifactId>ecs20140526</artifactId>
|
<artifactId>ecs20140526</artifactId>
|
||||||
|
|
|
@ -1,89 +0,0 @@
|
||||||
package com.muyu.cargateway.cargatewaytest;
|
|
||||||
|
|
||||||
import com.aliyun.ecs20140526.Client;
|
|
||||||
import com.aliyun.ecs20140526.models.*;
|
|
||||||
import com.aliyun.tea.TeaException;
|
|
||||||
import com.aliyun.teaopenapi.models.Config;
|
|
||||||
import com.aliyun.teautil.models.RuntimeOptions;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ Tool:IntelliJ IDEA
|
|
||||||
* @ Author:CHX
|
|
||||||
* @ Date:2024-09-28-21:20
|
|
||||||
* @ Version:1.0
|
|
||||||
* @ Description:删除实例
|
|
||||||
* @author Lenovo
|
|
||||||
*/
|
|
||||||
@Log4j2
|
|
||||||
@Component
|
|
||||||
public class DeleteSample implements DisposableBean {
|
|
||||||
|
|
||||||
public static Client createClient() throws Exception {
|
|
||||||
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
|
||||||
Config config = new Config()
|
|
||||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
|
||||||
.setAccessKeyId("LTAI5tDH3FyRx4PRr6anx2TL")
|
|
||||||
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
|
||||||
.setAccessKeySecret("xdQnX2tDattY50raNkUWmHzE2tondP");
|
|
||||||
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
|
||||||
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
|
|
||||||
return new Client(config);
|
|
||||||
}
|
|
||||||
public static void deleteSample() throws Exception {
|
|
||||||
Client client = DeleteSample.createClient();
|
|
||||||
DescribeInstancesRequest attributeRequest = new DescribeInstancesRequest();
|
|
||||||
attributeRequest.setRegionId("cn-shanghai");
|
|
||||||
|
|
||||||
RuntimeOptions runtimeOptions = new RuntimeOptions();
|
|
||||||
|
|
||||||
DescribeInstancesResponse instancesWithOptions = client.describeInstancesWithOptions(attributeRequest, runtimeOptions);
|
|
||||||
ArrayList<String> list = new ArrayList<>();
|
|
||||||
DescribeInstancesResponseBody body = instancesWithOptions.getBody();
|
|
||||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : body.instances.instance) {
|
|
||||||
list.add(instance.getInstanceId());
|
|
||||||
}
|
|
||||||
log.info("list:"+list);
|
|
||||||
DeleteInstancesRequest deleteInstancesRequest = new DeleteInstancesRequest();
|
|
||||||
deleteInstancesRequest.setRegionId("cn-shanghai")
|
|
||||||
.setDryRun(false)
|
|
||||||
.setForce(true)
|
|
||||||
.setTerminateSubscription(true)
|
|
||||||
.setInstanceId(list);
|
|
||||||
|
|
||||||
RuntimeOptions runtime = new RuntimeOptions();
|
|
||||||
try{
|
|
||||||
client.deleteInstancesWithOptions(deleteInstancesRequest, runtime);
|
|
||||||
}catch (TeaException error) {
|
|
||||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
|
||||||
// 错误 message
|
|
||||||
System.out.println(error.getMessage());
|
|
||||||
// 诊断地址
|
|
||||||
System.out.println(error.getData().get("Recommend"));
|
|
||||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
|
||||||
} catch (Exception _error) {
|
|
||||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
|
||||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
|
||||||
// 错误 message
|
|
||||||
System.out.println(error.getMessage());
|
|
||||||
// 诊断地址
|
|
||||||
System.out.println(error.getData().get("Recommend"));
|
|
||||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void destroy(){
|
|
||||||
try {
|
|
||||||
log.info("删除实例方法");
|
|
||||||
deleteSample();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.info("删除实例失败");
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
log.info("删除实例成功");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
package com.muyu.cargateway.config;
|
||||||
|
|
||||||
|
import org.springframework.amqp.core.Binding;
|
||||||
|
import org.springframework.amqp.core.BindingBuilder;
|
||||||
|
import org.springframework.amqp.core.Exchange;
|
||||||
|
import org.springframework.amqp.core.ExchangeBuilder;
|
||||||
|
import org.springframework.amqp.core.Queue;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ Tool:IntelliJ IDEA
|
||||||
|
* @ Author:CHX
|
||||||
|
* @ Date:2024-10-04-15:13
|
||||||
|
* @ Version:1.0
|
||||||
|
* @ Description:rabbitmq配置类
|
||||||
|
* @author Lenovo
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class RabbitmqConfig {
|
||||||
|
// 日志
|
||||||
|
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";
|
||||||
|
/**
|
||||||
|
* 路由key
|
||||||
|
*/
|
||||||
|
public static final String ROUTINGKEY_EMAIL = "inform.#.email.#";
|
||||||
|
/**
|
||||||
|
* 路由key
|
||||||
|
*/
|
||||||
|
public static final String ROUTINGKEY_SMS = "inform.#.sms.#";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 声明交换机,做持久化
|
||||||
|
*/
|
||||||
|
@Bean(EXCHANGE_TOPICS_INFORM)
|
||||||
|
public Exchange exchangeTopicsInform() {
|
||||||
|
try {
|
||||||
|
Exchange exchange = ExchangeBuilder.topicExchange(EXCHANGE_TOPICS_INFORM).durable(true).build();
|
||||||
|
logger.info("创建的交换机为: {}", EXCHANGE_TOPICS_INFORM);
|
||||||
|
return exchange;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("创建该: {} 交换机失败", EXCHANGE_TOPICS_INFORM, e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 声明QUEUE_INFORM_EMAIL队列
|
||||||
|
@Bean(QUEUE_INFORM_EMAIL)
|
||||||
|
public Queue queueInformEmail() {
|
||||||
|
try {
|
||||||
|
Queue queue = new Queue(QUEUE_INFORM_EMAIL);
|
||||||
|
logger.info("创建的对列为: {}", QUEUE_INFORM_EMAIL);
|
||||||
|
return queue;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("创建该: {} 队列失败", QUEUE_INFORM_EMAIL, e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 声明QUEUE_INFORM_SMS队列
|
||||||
|
@Bean(QUEUE_INFORM_SMS)
|
||||||
|
public Queue queueInformSms() {
|
||||||
|
try {
|
||||||
|
Queue queue = new Queue(QUEUE_INFORM_SMS);
|
||||||
|
logger.info("创建的对列为: {}", QUEUE_INFORM_SMS);
|
||||||
|
return queue;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("创建该: {} 队列失败", QUEUE_INFORM_SMS, e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//ROUTINGKEY_EMAIL队列绑定交换机,指定routingKey
|
||||||
|
@Bean
|
||||||
|
public Binding bindingQueueInformEmail(@Qualifier(QUEUE_INFORM_EMAIL) Queue queue,
|
||||||
|
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange){
|
||||||
|
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_EMAIL).noargs();
|
||||||
|
}
|
||||||
|
//ROUTINGKEY_SMS队列绑定交换机,指定routingKey
|
||||||
|
@Bean
|
||||||
|
public Binding bindingRoutingKeySms(@Qualifier(QUEUE_INFORM_SMS) Queue queue,
|
||||||
|
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange){
|
||||||
|
return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SMS).noargs();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.muyu.cargateway.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||||
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ Tool:IntelliJ IDEA
|
||||||
|
* @ Author:CHX
|
||||||
|
* @ Date:2024-10-04-15:12
|
||||||
|
* @ Version:1.0
|
||||||
|
* @ Description:Redis配置类
|
||||||
|
* @author Lenovo
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class RedisConfig {
|
||||||
|
@Bean
|
||||||
|
public RedisTemplate<String,String> redisTemplate(RedisConnectionFactory redisConnectionFactory){
|
||||||
|
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
|
||||||
|
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||||
|
|
||||||
|
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<Object>(Object.class));
|
||||||
|
|
||||||
|
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setHashValueSerializer(new StringRedisSerializer());
|
||||||
|
return redisTemplate;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package com.muyu.cargateway.config;
|
||||||
|
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||||
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ Tool:IntelliJ IDEA
|
||||||
|
* @ Author:CHX
|
||||||
|
* @ Date:2024-10-04-15:08
|
||||||
|
* @ Version:1.0
|
||||||
|
* @ Description:rest配置类
|
||||||
|
* @author Lenovo
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
@Configuration
|
||||||
|
public class RestTemplateConfig {
|
||||||
|
@Bean
|
||||||
|
public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
|
||||||
|
return new RestTemplate(factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建并配置客户端HTTP请求工厂实例。
|
||||||
|
* 注意:这里设置了连接和读取数据的超时时间,分别设为15秒和5秒。
|
||||||
|
* 这些值可以根据实际网络状况和应用需求进行调整。
|
||||||
|
*
|
||||||
|
* @return 配置好的客户端请求工厂对象
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
|
||||||
|
try {
|
||||||
|
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||||
|
// 设置读取超时时间为5秒
|
||||||
|
factory.setReadTimeout(5000);
|
||||||
|
// 设置连接超时时间为15秒
|
||||||
|
factory.setConnectTimeout(15000);
|
||||||
|
return factory;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 处理创建工厂或设置超时时间时可能出现的异常
|
||||||
|
log.info("创建工厂失败: " + e.getMessage());
|
||||||
|
throw new RuntimeException("初始化HTTP请求失败", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,13 @@
|
||||||
package com.muyu.cargateway.controller;
|
package com.muyu.cargateway.controller;
|
||||||
|
|
||||||
|
import com.muyu.cargateway.domain.req.VehicleConnectionReq;
|
||||||
import com.muyu.cargateway.service.CarOneClickOperationService;
|
import com.muyu.cargateway.service.CarOneClickOperationService;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@ -13,15 +16,26 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
* @ 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
|
* @author Lenovo
|
||||||
*/
|
*/
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/car/oneClick")
|
@RequestMapping("/vehicleGateway")
|
||||||
|
@Tag(name = "连接车辆控制层")
|
||||||
public class CarOneClickOperationController {
|
public class CarOneClickOperationController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private CarOneClickOperationService carOneClickOperationService;
|
private CarOneClickOperationService carOneClickOperationService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取http连接的参数
|
||||||
|
* @param vehicleConnectionReq
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/receiveMsg/connect")
|
||||||
|
public Result receiveMsg(@RequestBody VehicleConnectionReq vehicleConnectionReq){
|
||||||
|
log.info("=======>"+vehicleConnectionReq);
|
||||||
|
carOneClickOperationService.getConnect(vehicleConnectionReq);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
package com.muyu.cargateway.controller;
|
|
||||||
|
|
||||||
import com.muyu.cargateway.service.CarOneClickOperationService;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
|
||||||
import org.eclipse.paho.client.mqttv3.*;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ Tool:IntelliJ IDEA
|
|
||||||
* @ Author:CHX
|
|
||||||
* @ Date:2024-09-27-20:08
|
|
||||||
* @ Version:1.0
|
|
||||||
* @ Description:fluxmq连接测试类
|
|
||||||
* @author Lenovo
|
|
||||||
*/
|
|
||||||
@Log4j2
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/testCarGateway")
|
|
||||||
public class TestController {
|
|
||||||
@PostMapping("/testCarConnect")
|
|
||||||
public void testCarConnect() {
|
|
||||||
String topic="carOneClick";
|
|
||||||
String message="{\"carId\":\"123456789\",\"operation\":\"turnOn\"}";;
|
|
||||||
String broker="tcp://106.54.193.225:1883";
|
|
||||||
String clientId="javaSample";
|
|
||||||
int qos=1;
|
|
||||||
|
|
||||||
try {
|
|
||||||
MqttClient mqttClient =new MqttClient(broker, clientId);
|
|
||||||
MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
|
|
||||||
mqttConnectOptions.setCleanSession(true);
|
|
||||||
log.info("连接成功"+broker);
|
|
||||||
mqttClient.connect(mqttConnectOptions);
|
|
||||||
|
|
||||||
mqttClient.subscribe(topic,0);
|
|
||||||
mqttClient.setCallback(new MqttCallback() {
|
|
||||||
@Override
|
|
||||||
public void connectionLost(Throwable throwable) {
|
|
||||||
log.info("连接丢失");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
|
||||||
log.info(new String(mqttMessage.getPayload()));
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
|
||||||
//发布完成时调用
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (MqttException e) {
|
|
||||||
log.info("连接失败"+e.getReasonCode());
|
|
||||||
log.info("信息"+e.getMessage());
|
|
||||||
log.info("异常"+e);
|
|
||||||
log.info("异常信息"+e.getLocalizedMessage());
|
|
||||||
log.info("异常类型"+e.getClass());
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,8 +15,17 @@ import lombok.NoArgsConstructor;
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class Instance {
|
public class AliInstance {
|
||||||
|
/**
|
||||||
|
*实例ID
|
||||||
|
*/
|
||||||
private String instanceId;
|
private String instanceId;
|
||||||
|
/**
|
||||||
|
* 实例IP
|
||||||
|
*/
|
||||||
private String ipAddress;
|
private String ipAddress;
|
||||||
|
/**
|
||||||
|
* 实例状态
|
||||||
|
*/
|
||||||
private String status;
|
private String status;
|
||||||
}
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.muyu.cargateway.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ Tool:IntelliJ IDEA
|
||||||
|
* @ Author:CHX
|
||||||
|
* @ Date:2024-10-04-15:16
|
||||||
|
* @ Version:1.0
|
||||||
|
* @ Description:车辆服务器
|
||||||
|
* @author Lenovo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ConnectWeight {
|
||||||
|
/**
|
||||||
|
* 车辆服务器IP
|
||||||
|
*/
|
||||||
|
private String carServerIp;
|
||||||
|
/**
|
||||||
|
* 权重值
|
||||||
|
*/
|
||||||
|
private Integer weightValue;
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
package com.muyu.cargateway.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;
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.muyu.cargateway.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ Tool:IntelliJ IDEA
|
||||||
|
* @ Author:CHX
|
||||||
|
* @ Date:2024-10-06-11:05
|
||||||
|
* @ Version:1.0
|
||||||
|
* @ Description:车辆鉴权的参数
|
||||||
|
* @author Lenovo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class VehicleConnection {
|
||||||
|
/**
|
||||||
|
* 车辆VIN
|
||||||
|
*/
|
||||||
|
private String vehicleVin;
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private String timestamp;
|
||||||
|
|
||||||
|
private String nonce;
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.muyu.cargateway.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ Tool:IntelliJ IDEA
|
||||||
|
* @ Author:CHX
|
||||||
|
* @ Date:2024-10-03-10:10
|
||||||
|
* @ Version:1.0
|
||||||
|
* @ Description:车辆vin
|
||||||
|
* @author Lenovo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class VinIp {
|
||||||
|
/**
|
||||||
|
* 车辆的vin
|
||||||
|
*/
|
||||||
|
String vin;
|
||||||
|
/**
|
||||||
|
* 车辆的ip
|
||||||
|
*/
|
||||||
|
String ip;
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.muyu.cargateway.domain.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ Tool:IntelliJ IDEA
|
||||||
|
* @ Author:CHX
|
||||||
|
* @ Date:2024-10-03-10:12
|
||||||
|
* @ Version:1.0
|
||||||
|
* @ Description:Mqtt服务模型
|
||||||
|
* @author Lenovo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class MqttServerModel {
|
||||||
|
/**
|
||||||
|
* Mqtt服务节点
|
||||||
|
*/
|
||||||
|
private String broker;
|
||||||
|
/**
|
||||||
|
* MQTT订阅主题
|
||||||
|
*/
|
||||||
|
private String topic;
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.muyu.cargateway.domain.req;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ Tool:IntelliJ IDEA
|
||||||
|
* @ Author:CHX
|
||||||
|
* @ Date:2024-10-03-10:04
|
||||||
|
* @ Version:1.0
|
||||||
|
* @ Description:车辆获取连接地址
|
||||||
|
* @author Lenovo
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class VehicleConnectionReq {
|
||||||
|
/**
|
||||||
|
* 车辆VIN
|
||||||
|
*/
|
||||||
|
private String vehicleVin;
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String username;
|
||||||
|
/**
|
||||||
|
* 时间戳
|
||||||
|
*/
|
||||||
|
private String timestamp;
|
||||||
|
/**
|
||||||
|
* 随机数
|
||||||
|
*/
|
||||||
|
private String nonce;
|
||||||
|
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import com.aliyun.tea.TeaException;
|
||||||
import com.aliyun.teaopenapi.models.Config;
|
import com.aliyun.teaopenapi.models.Config;
|
||||||
import com.aliyun.teautil.Common;
|
import com.aliyun.teautil.Common;
|
||||||
import com.aliyun.teautil.models.RuntimeOptions;
|
import com.aliyun.teautil.models.RuntimeOptions;
|
||||||
|
import com.muyu.cargateway.domain.AliInstance;
|
||||||
import com.muyu.common.redis.service.RedisService;
|
import com.muyu.common.redis.service.RedisService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -13,7 +14,6 @@ import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -31,8 +31,6 @@ import java.util.List;
|
||||||
@Component
|
@Component
|
||||||
public class Sample implements ApplicationRunner , DisposableBean {
|
public class Sample implements ApplicationRunner , DisposableBean {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private StringRedisTemplate redisTemplate;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
|
@ -69,7 +67,7 @@ public class Sample implements ApplicationRunner , DisposableBean {
|
||||||
// 设置地域ID
|
// 设置地域ID
|
||||||
.setRegionId("cn-shanghai")
|
.setRegionId("cn-shanghai")
|
||||||
// 设置镜像ID
|
// 设置镜像ID
|
||||||
.setImageId("m-uf63y73rquw4ub9znymf")
|
.setImageId("m-uf6ih0vnl5f51pquns11")
|
||||||
// 设置实例规格类型
|
// 设置实例规格类型
|
||||||
.setInstanceType("ecs.t6-c1m1.large")
|
.setInstanceType("ecs.t6-c1m1.large")
|
||||||
// 设置安全组ID
|
// 设置安全组ID
|
||||||
|
@ -98,65 +96,68 @@ public class Sample implements ApplicationRunner , DisposableBean {
|
||||||
|
|
||||||
// 复制代码运行请自行打印 API 的返回值
|
// 复制代码运行请自行打印 API 的返回值
|
||||||
RunInstancesResponse runInstancesResponse = client.runInstancesWithOptions(runInstancesRequest, runtimeOptions);
|
RunInstancesResponse runInstancesResponse = client.runInstancesWithOptions(runInstancesRequest, runtimeOptions);
|
||||||
log.info("==================实例创建成功");
|
log.info("实例创建成功: {}", runInstancesResponse.getBody().getInstanceIdSets().instanceIdSet);
|
||||||
RunInstancesResponseBody body = runInstancesResponse.getBody();
|
RunInstancesResponseBody body = runInstancesResponse.getBody();
|
||||||
RunInstancesResponseBody.RunInstancesResponseBodyInstanceIdSets instanceIdSets = body.getInstanceIdSets();
|
RunInstancesResponseBody.RunInstancesResponseBodyInstanceIdSets instanceIdSets = body.getInstanceIdSets();
|
||||||
|
|
||||||
|
List<AliInstance> instanceList = new ArrayList<>();
|
||||||
List<String> instanceIds = new ArrayList<>();
|
List<String> instanceIds = new ArrayList<>();
|
||||||
|
//遍历实例ID
|
||||||
for (String string : instanceIdSets.instanceIdSet) {
|
for (String string : instanceIdSets.instanceIdSet) {
|
||||||
instanceIds.add(string);
|
instanceIds.add(string);
|
||||||
}
|
}
|
||||||
|
// 在获取实例详细信息时,确保获取所有必要的信息
|
||||||
|
DescribeInstancesResponse describeInstancesResponse = getInstances(client);
|
||||||
|
List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> instances = describeInstancesResponse.getBody().getInstances().getInstance();
|
||||||
|
|
||||||
|
List<AliInstance> aliInstances = new ArrayList<>();
|
||||||
|
instanceIds = new ArrayList<>();
|
||||||
|
|
||||||
DescribeInstancesResponse describeInstancesResponse = getStrings(client);
|
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : instances) {
|
||||||
log.info("====>实例ID"+instanceIds);
|
|
||||||
List<DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance> instancesInstances = describeInstancesResponse.getBody().getInstances().getInstance();
|
|
||||||
for (DescribeInstancesResponseBody.DescribeInstancesResponseBodyInstancesInstance instance : instancesInstances) {
|
|
||||||
String instanceId = instance.getInstanceId();
|
String instanceId = instance.getInstanceId();
|
||||||
String ipAddress = instance.getPublicIpAddress().getIpAddress().get(0);
|
String ipAddress = instance.getPublicIpAddress().getIpAddress().get(0);
|
||||||
String status = instance.getStatus();
|
String status = instance.getStatus();
|
||||||
log.info("==================获取到的实例ID为"+instanceId+" IP为"+ipAddress+" 状态为"+status);
|
log.info("获取到的实例ID为{} IP为{} 状态为{}", instanceId, ipAddress, status);
|
||||||
|
aliInstances.add(new AliInstance(instanceId, ipAddress, status));
|
||||||
instanceIds.add(instanceId);
|
instanceIds.add(instanceId);
|
||||||
instanceIds.add(ipAddress);
|
|
||||||
instanceIds.add(status);
|
|
||||||
}
|
}
|
||||||
|
//实例信息集合(实例id,ip 状态) 存储在redis中
|
||||||
|
redisService.setCacheList("instanceList", aliInstances);
|
||||||
// for (String string : stringArrayList) {
|
// 实例ID集合 存储在redis中
|
||||||
// log.info("==================获取到的实例ID为"+string);
|
redisService.setCacheList("instanceIds", instanceIds);
|
||||||
// }
|
|
||||||
// redisTemplate.opsForList().rightPush("instanceId",String.valueOf(stringArrayList));
|
|
||||||
// log.info("==================redis存储成功");
|
|
||||||
// List<String> instanceId = redisTemplate.opsForList().range("instanceId", 0, -1);
|
|
||||||
// for (String string : instanceId) {
|
|
||||||
// log.info("==================redis获取实例ID成功"+string);
|
|
||||||
// }
|
|
||||||
|
|
||||||
} catch (TeaException error) {
|
} catch (TeaException error) {
|
||||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||||
// 错误 message
|
// 错误 message
|
||||||
System.out.println(error.getMessage());
|
log.info(error.getMessage());
|
||||||
// 诊断地址
|
// 诊断地址
|
||||||
System.out.println(error.getData().get("Recommend"));
|
log.info(error.getData().get("Recommend"));
|
||||||
com.aliyun.teautil.Common.assertAsString(error.message);
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||||
} catch (Exception _error) {
|
} catch (Exception _error) {
|
||||||
TeaException error = new TeaException(_error.getMessage(), _error);
|
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||||
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||||
// 错误 message
|
// 错误 message
|
||||||
System.out.println(error.getMessage());
|
log.info(error.getMessage());
|
||||||
// 诊断地址
|
// 诊断地址
|
||||||
System.out.println(error.getData().get("Recommend"));
|
log.info(error.getData().get("Recommend"));
|
||||||
Common.assertAsString(error.message);
|
Common.assertAsString(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询实例的详细信息
|
* 获取实例ID
|
||||||
|
* @param client
|
||||||
|
* @return string类型的实例ID集合
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void selectInstance(){
|
@NotNull
|
||||||
|
private DescribeInstancesResponse getInstances(Client client) throws Exception {
|
||||||
|
DescribeInstancesRequest request = new DescribeInstancesRequest();
|
||||||
|
request.setInstanceName("server-mqtt");
|
||||||
|
request.setRegionId("cn-shanghai");
|
||||||
|
|
||||||
|
RuntimeOptions runtimeOptions = new RuntimeOptions();
|
||||||
|
return client.describeInstancesWithOptions(request, runtimeOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除创建的实例
|
* 删除创建的实例
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
@ -202,24 +203,6 @@ public class Sample implements ApplicationRunner , DisposableBean {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取实例ID
|
|
||||||
* @param client
|
|
||||||
* @return string类型的实例ID集合
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
private DescribeInstancesResponse getStrings(Client client) throws Exception {
|
|
||||||
DescribeInstancesRequest attributeRequest = new DescribeInstancesRequest();
|
|
||||||
attributeRequest.setInstanceName("server-mqtt");
|
|
||||||
attributeRequest.setRegionId("cn-shanghai");
|
|
||||||
|
|
||||||
RuntimeOptions runtimeOptions = new RuntimeOptions();
|
|
||||||
|
|
||||||
DescribeInstancesResponse instancesWithOptions = client.describeInstancesWithOptions(attributeRequest, runtimeOptions);
|
|
||||||
return instancesWithOptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args){
|
public void run(ApplicationArguments args){
|
||||||
try {
|
try {
|
||||||
|
@ -236,6 +219,7 @@ public class Sample implements ApplicationRunner , DisposableBean {
|
||||||
public void destroy(){
|
public void destroy(){
|
||||||
try {
|
try {
|
||||||
log.info("删除实例方法");
|
log.info("删除实例方法");
|
||||||
|
Thread.sleep(100000);
|
||||||
deleteSample();
|
deleteSample();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("删除实例失败");
|
log.info("删除实例失败");
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.muyu.cargateway.mapper;
|
package com.muyu.cargateway.mapper;
|
||||||
|
|
||||||
|
import com.muyu.cargateway.domain.VehicleConnection;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,4 +13,5 @@ import org.apache.ibatis.annotations.Mapper;
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface CarOneClickOperationMapper {
|
public interface CarOneClickOperationMapper {
|
||||||
|
void addConnect(VehicleConnection vehicleConnection);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.muyu.cargateway.service;
|
package com.muyu.cargateway.service;
|
||||||
|
|
||||||
|
import com.muyu.cargateway.domain.req.VehicleConnectionReq;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ Tool:IntelliJ IDEA
|
* @ Tool:IntelliJ IDEA
|
||||||
* @ Author:CHX
|
* @ Author:CHX
|
||||||
|
@ -10,5 +12,10 @@ package com.muyu.cargateway.service;
|
||||||
*/
|
*/
|
||||||
public interface CarOneClickOperationService {
|
public interface CarOneClickOperationService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取连接
|
||||||
|
* @param vehicleConnectionReq 车辆连接请求参数
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
void getConnect(VehicleConnectionReq vehicleConnectionReq);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
package com.muyu.cargateway.service.Impl;
|
package com.muyu.cargateway.service.Impl;
|
||||||
|
|
||||||
|
import com.muyu.cargateway.domain.VehicleConnection;
|
||||||
|
import com.muyu.cargateway.domain.req.VehicleConnectionReq;
|
||||||
|
import com.muyu.cargateway.mapper.CarOneClickOperationMapper;
|
||||||
import com.muyu.cargateway.service.CarOneClickOperationService;
|
import com.muyu.cargateway.service.CarOneClickOperationService;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,8 +17,31 @@ import org.springframework.stereotype.Service;
|
||||||
* @ Description:车辆一键操作业务实现层
|
* @ Description:车辆一键操作业务实现层
|
||||||
* @author Lenovo
|
* @author Lenovo
|
||||||
*/
|
*/
|
||||||
|
@Log4j2
|
||||||
@Service
|
@Service
|
||||||
public class CarOneClickOperationServiceImpl implements CarOneClickOperationService {
|
public class CarOneClickOperationServiceImpl implements CarOneClickOperationService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CarOneClickOperationMapper carOneClickOperationMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取连接信息
|
||||||
|
* @param vehicleConnectionReq 车辆连接请求参数
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void getConnect(VehicleConnectionReq vehicleConnectionReq) {
|
||||||
|
log.info("车辆连接请求:{}",vehicleConnectionReq.toString());
|
||||||
|
// 发送消息
|
||||||
|
rabbitTemplate.convertAndSend("exchange_topics_inform","",vehicleConnectionReq.getVehicleVin());
|
||||||
|
|
||||||
|
VehicleConnection vehicleConnection = new VehicleConnection();
|
||||||
|
vehicleConnection.setVehicleVin(vehicleConnectionReq.getVehicleVin());
|
||||||
|
vehicleConnection.setUsername(vehicleConnectionReq.getUsername());
|
||||||
|
vehicleConnection.setPassword(vehicleConnectionReq.getVehicleVin()+vehicleConnectionReq.getTimestamp()+vehicleConnectionReq.getNonce());
|
||||||
|
carOneClickOperationMapper.addConnect(vehicleConnection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,135 @@
|
||||||
|
package com.muyu.cargateway.utils;
|
||||||
|
|
||||||
|
import com.aliyun.ecs20140526.Client;
|
||||||
|
import com.aliyun.ecs20140526.models.DeleteInstanceRequest;
|
||||||
|
import com.aliyun.ecs20140526.models.DescribeInstancesRequest;
|
||||||
|
import com.aliyun.ecs20140526.models.DescribeInstancesResponse;
|
||||||
|
import com.aliyun.ecs20140526.models.RunInstancesRequest;
|
||||||
|
import com.aliyun.tea.TeaException;
|
||||||
|
import com.aliyun.teaopenapi.models.Config;
|
||||||
|
import com.aliyun.teautil.Common;
|
||||||
|
import com.aliyun.teautil.models.RuntimeOptions;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ Tool:IntelliJ IDEA
|
||||||
|
* @ Author:CHX
|
||||||
|
* @ Date:2024-10-02-16:04
|
||||||
|
* @ Version:1.0
|
||||||
|
* @ Description:ecs实例工具类
|
||||||
|
* @author Lenovo
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
public class ECSTool {
|
||||||
|
|
||||||
|
public static final String ACCESS_KEY_ID = "LTAI5tDH3FyRx4PRr6anx2TL";
|
||||||
|
public static final String ACCESS_KEY_SECRET = "xdQnX2tDattY50raNkUWmHzE2tondP";
|
||||||
|
|
||||||
|
public static Client createClient() throws Exception {
|
||||||
|
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
||||||
|
Config config = new Config()
|
||||||
|
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
||||||
|
.setAccessKeyId(ACCESS_KEY_ID)
|
||||||
|
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
||||||
|
.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||||
|
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
|
||||||
|
config.endpoint = "ecs-cn-hangzhou.aliyuncs.com";
|
||||||
|
return new Client(config);
|
||||||
|
}
|
||||||
|
public static void runEcsInstance(String regionId, String launchTemplateId) throws Exception {
|
||||||
|
Client client = ECSTool.createClient();
|
||||||
|
RunInstancesRequest request = new RunInstancesRequest();
|
||||||
|
request.setRegionId(regionId)
|
||||||
|
.setLaunchTemplateId(launchTemplateId);
|
||||||
|
RuntimeOptions runtimeOptions = new RuntimeOptions();
|
||||||
|
try{
|
||||||
|
client.runInstancesWithOptions(request, runtimeOptions);
|
||||||
|
}catch (Exception error){
|
||||||
|
// 处理API调用过程中出现的异常
|
||||||
|
System.out.println(error.getMessage());
|
||||||
|
if (error instanceof TeaException) {
|
||||||
|
// 处理特定类型的异常,如TeaException
|
||||||
|
TeaException teaError = (TeaException) error;
|
||||||
|
// 打印诊断推荐链接
|
||||||
|
System.out.println(teaError.getData().get("Recommend"));
|
||||||
|
// 断言错误信息
|
||||||
|
com.aliyun.teautil.Common.assertAsString(teaError.getMessage());
|
||||||
|
} else {
|
||||||
|
// 处理其他类型的异常
|
||||||
|
System.out.println(error.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*销毁实例
|
||||||
|
*/
|
||||||
|
public static void runEcsRemove(String instanceId) throws Exception {
|
||||||
|
Client client = ECSTool.createClient();
|
||||||
|
DeleteInstanceRequest deleteInstancesRequest = new DeleteInstanceRequest();
|
||||||
|
deleteInstancesRequest.setInstanceId(instanceId);
|
||||||
|
RuntimeOptions runtimeOptions = new RuntimeOptions();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 复制代码运行请自行打印 API 的返回值
|
||||||
|
client.deleteInstanceWithOptions(deleteInstancesRequest, runtimeOptions);
|
||||||
|
} catch (TeaException error) {
|
||||||
|
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||||
|
// 错误 message
|
||||||
|
System.out.println(error.getMessage());
|
||||||
|
// 诊断地址
|
||||||
|
System.out.println(error.getData().get("Recommend"));
|
||||||
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||||
|
} catch (Exception _error) {
|
||||||
|
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||||
|
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||||
|
// 错误 message
|
||||||
|
System.out.println(error.getMessage());
|
||||||
|
// 诊断地址
|
||||||
|
System.out.println(error.getData().get("Recommend"));
|
||||||
|
com.aliyun.teautil.Common.assertAsString(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询实例列表
|
||||||
|
* @param regionId 地域ID
|
||||||
|
*/
|
||||||
|
public static List<String> findInstance(String regionId) throws Exception {
|
||||||
|
Client client = ECSTool.createClient();
|
||||||
|
DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
|
||||||
|
describeInstancesRequest.setRegionId(regionId);
|
||||||
|
RuntimeOptions runtimeOptions = new RuntimeOptions();
|
||||||
|
List<String> stringArrayList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
DescribeInstancesResponse response = client.describeInstancesWithOptions(describeInstancesRequest, runtimeOptions);
|
||||||
|
List<List<String>> ipListList = response.getBody().instances.getInstance().stream().map(instance -> instance.publicIpAddress.ipAddress).collect(Collectors.toList());
|
||||||
|
for (List<String> strings : ipListList) {
|
||||||
|
for (String ip : strings) {
|
||||||
|
stringArrayList.add(ip);
|
||||||
|
}
|
||||||
|
return stringArrayList;
|
||||||
|
}
|
||||||
|
} catch (TeaException error) {
|
||||||
|
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||||
|
// 错误 message
|
||||||
|
System.out.println(error.getMessage());
|
||||||
|
// 诊断地址
|
||||||
|
System.out.println(error.getData().get("Recommend"));
|
||||||
|
Common.assertAsString(error.message);
|
||||||
|
} catch (Exception _error) {
|
||||||
|
TeaException error = new TeaException(_error.getMessage(), _error);
|
||||||
|
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
||||||
|
// 错误 message
|
||||||
|
System.out.println(error.getMessage());
|
||||||
|
// 诊断地址
|
||||||
|
System.out.println(error.getData().get("Recommend"));
|
||||||
|
Common.assertAsString(error.message);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
# Tomcat
|
# Tomcat
|
||||||
server:
|
server:
|
||||||
port: 9702
|
port: 12900
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
|
@ -19,7 +19,7 @@ spring:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
application:
|
application:
|
||||||
# 应用名称
|
# 应用名称
|
||||||
name: cloud-breakdown
|
name: cloud-car-gateway
|
||||||
profiles:
|
profiles:
|
||||||
# 环境配置
|
# 环境配置
|
||||||
active: dev
|
active: dev
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?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.cargateway.mapper.CarOneClickOperationMapper">
|
||||||
|
|
||||||
|
|
||||||
|
<insert id="addConnect">
|
||||||
|
insert into car_one_click_operation
|
||||||
|
(vehicle_vin,user_name,password)
|
||||||
|
values
|
||||||
|
(#{vehicleVin},#{username},#{password})
|
||||||
|
</insert>
|
||||||
|
</mapper>
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 106.54.193.225:8848
|
addr: 47.116.173.119:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: public
|
namespace: public
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 106.54.193.225:8848
|
addr: 47.116.173.119:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: one
|
namespace: one
|
||||||
|
|
|
@ -4,7 +4,7 @@ server:
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
addr: 106.54.193.225:8848
|
addr: 47.116.173.119:8848
|
||||||
user-name: nacos
|
user-name: nacos
|
||||||
password: nacos
|
password: nacos
|
||||||
namespace: one-saas
|
namespace: one-saas
|
||||||
|
|
Loading…
Reference in New Issue