feat():模拟车辆基础模板

master
Saisai Liu 2024-05-30 19:02:37 +08:00
parent bd3d964663
commit 525a4eeb5a
7 changed files with 22 additions and 63 deletions

View File

@ -99,6 +99,7 @@
<version>5.1.8</version> <version>5.1.8</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -1,55 +0,0 @@
// This file is auto-generated, don't edit it. Thanks.
package com.muyu.controller;
import com.aliyun.tea.*;
public class Sample {
/**
* 使AK&SKClient
* @return Client
* @throws Exception
*/
public static com.aliyun.ecs20140526.Client createClient() throws Exception {
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
// 建议使用更安全的 STS 方式更多鉴权访问方式请参见https://help.aliyun.com/document_detail/378657.html。
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
.setAccessKeyId("LTAI5tKaz3hHJ8pkgF7iem8b")
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
.setAccessKeySecret("CApa5sl414bKC8GwD8uBtINuT26Ocj");
// Endpoint 请参考 https://api.aliyun.com/product/Ecs
config.endpoint = "ecs.cn-zhangjiakou.aliyuncs.com";
return new com.aliyun.ecs20140526.Client(config);
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.ecs20140526.Client client = Sample.createClient();
com.aliyun.ecs20140526.models.RunInstancesRequest runInstancesRequest = new com.aliyun.ecs20140526.models.RunInstancesRequest()
.setRegionId("cn-zhangjiakou")
.setLaunchTemplateName("basic_model")
.setLaunchTemplateId("lt-8vb71bkyjwcqmcd98ah4");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
// 复制代码运行请自行打印 API 的返回值
client.runInstancesWithOptions(runInstancesRequest, 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);
}
System.out.println("实例创建成功");
}
}

View File

@ -2,11 +2,15 @@ package com.muyu.controller;
import com.muyu.common.Result; import com.muyu.common.Result;
import com.muyu.domain.model.MqttServerModel; import com.muyu.domain.model.MqttServerModel;
import com.muyu.vehicle.api.ClientAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
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;
import java.util.UUID;
/** /**
* @author DongZl * @author DongZl
* @description: 线 * @description: 线
@ -16,6 +20,9 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/verify") @RequestMapping("/verify")
public class VerifyController { public class VerifyController {
@Autowired
private ClientAdmin admin;
@Value("${mqtt.server.host}") @Value("${mqtt.server.host}")
private String broker; private String broker;
@ -24,16 +31,18 @@ public class VerifyController {
private String topic; private String topic;
/** /**
* 线 * 线
* @return test * @return test
*/ */
@PostMapping("/vehicleConnection") @PostMapping("/vehicleConnection")
public Result<MqttServerModel> vehicleConnection(){ public Result<MqttServerModel> vehicleConnection(){
// this.broker = "tcp://"+admin.getIp();
return Result.success( return Result.success(
MqttServerModel.builder() MqttServerModel.builder()
.broker(broker) .broker(broker)
.topic(topic) .topic(UUID.randomUUID().toString())
.build() .build()
); );
} }

View File

@ -46,6 +46,7 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
@Autowired @Autowired
private ClientAdmin clientAdmin; private ClientAdmin clientAdmin;
/** /**
* *
* *
@ -132,7 +133,6 @@ public class VehicleInstanceServiceImpl implements VehicleInstanceService {
/** /**
* *
*
* @param vin vin * @param vin vin
*/ */
@Override @Override

View File

@ -36,6 +36,7 @@ import static com.muyu.common.SystemConstant.*;
* @version 1.0 * @version 1.0
* @description * @description
* @date 2023/11/16 * @date 2023/11/16
*
*/ */
@Data @Data
@Log4j2 @Log4j2

View File

@ -8,15 +8,17 @@ import com.muyu.domain.model.MqttServerModel;
import com.muyu.vehicle.api.req.VehicleConnectionReq; import com.muyu.vehicle.api.req.VehicleConnectionReq;
/** /**
* @author DongZl * @author Saisai Liu
* @description: * @description:
* @Date 2023-11-28 10:20 * @Date 2023-11-28 10:20
*/ */
@BaseRequest( @BaseRequest(baseURL = "${adminHost}")
baseURL = "${adminHost}"
)
public interface ClientAdmin { public interface ClientAdmin {
@Post("${adminTopicUri}") @Post("${adminTopicUri}")
public Result<MqttServerModel> vehicleConnection(@JSONBody VehicleConnectionReq vehicleConnectionReq); public Result<MqttServerModel> vehicleConnection(@JSONBody VehicleConnectionReq vehicleConnectionReq);
//
// @Post("/fluxmq/getIp")
// public String getIp();
} }

View File

@ -89,5 +89,6 @@ mqtt:
host: tcp://39.98.45.160:1883 host: tcp://39.98.45.160:1883
topic: test1 topic: test1
admin: admin:
host: http://127.0.0.1:${server.port} host: http://127.0.0.1:8081
topic-uri: /verify/vehicleConnection topic-uri: /fluxmq/getIp