【功能新增】IoT:验证通过独立、内嵌模式的调用
This commit is contained in:
@@ -124,7 +124,7 @@
|
||||
<!-- 其他依赖项 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<!-- PF4J Spring 集成 -->
|
||||
<dependency>
|
||||
|
@@ -1,13 +1,26 @@
|
||||
package cn.iocoder.yudao.module.iot;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
// TODO @haohao:建议包名:cn.iocoder.yudao.module.iot.plugin.${pluginName},例如说 http。然后子包如下:
|
||||
// config:方配置类,以及 HttpVertxPlugin 初始化
|
||||
// service:放 HttpVertxHandler 逻辑;
|
||||
@SpringBootApplication
|
||||
public class HttpPluginSpringbootApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(HttpPluginSpringbootApplication.class, args);
|
||||
// SpringApplication.run(HttpPluginSpringbootApplication.class, args);
|
||||
SpringApplication application = new SpringApplication(HttpPluginSpringbootApplication.class);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
application.run(args);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// TODO @haohao:如下是 sdk 的包:cn.iocoder.yudao.module.iot.plugin.sdk
|
||||
// 1. api 包:实现 DeviceDataApi 接口,通过 resttemplate 调用
|
||||
// 2. config 包:初始化 DeviceDataApi 等等
|
||||
|
||||
// 3. 其中 resttemplate 调用的后端地址,通过每个服务的 application.yaml 进行注入。
|
@@ -1,23 +1,59 @@
|
||||
package cn.iocoder.yudao.module.iot.config;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.DeviceDataCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.IotDeviceEventReportReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.IotDeviceStatusUpdateReqDTO;
|
||||
import org.pf4j.DefaultPluginManager;
|
||||
import org.pf4j.PluginWrapper;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
// TODO 芋艿:临时实现;
|
||||
@Configuration
|
||||
public class TestConfiguration {
|
||||
|
||||
// @Resource
|
||||
// private RestTemplate restTemplate;
|
||||
|
||||
// TODO 芋艿:这里,后续看看怎么创建好点
|
||||
@Bean
|
||||
public DeviceDataApi deviceDataApi() {
|
||||
public RestTemplate restTemplate() {
|
||||
return new RestTemplateBuilder().build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DeviceDataApi deviceDataApi(RestTemplate restTemplate) {
|
||||
return new DeviceDataApi() {
|
||||
|
||||
@Override
|
||||
public void saveDeviceData(DeviceDataCreateReqDTO createDTO) {
|
||||
System.out.println("saveDeviceData");
|
||||
public CommonResult<Boolean> updateDeviceStatus(IotDeviceStatusUpdateReqDTO updateReqDTO) {
|
||||
// TODO haohao:待实现
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> reportDeviceEventData(IotDeviceEventReportReqDTO reportReqDTO) {
|
||||
// TODO haohao:待实现
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> reportDevicePropertyData(IotDevicePropertyReportReqDTO reportReqDTO) {
|
||||
// TODO haohao:待完整实现
|
||||
String url = "http://127.0.0.1:48080/rpc-api/iot/device-data/report-property";
|
||||
try {
|
||||
restTemplate.postForObject(url, reportReqDTO, CommonResult.class);
|
||||
return success(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return CommonResult.error(400, "error");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
@@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.iot.service;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.DeviceDataCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.IotDevicePropertyReportReqDTO;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.ext.web.RequestBody;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
@@ -46,12 +46,12 @@ public class HttpVertxHandler implements Handler<RoutingContext> {
|
||||
|
||||
try {
|
||||
// 调用主程序的接口保存数据
|
||||
DeviceDataCreateReqDTO createDTO = DeviceDataCreateReqDTO.builder()
|
||||
IotDevicePropertyReportReqDTO createDTO = IotDevicePropertyReportReqDTO.builder()
|
||||
.productKey(productKey)
|
||||
.deviceName(deviceName)
|
||||
.message(jsonData.toString())
|
||||
.params(jsonData) // TODO 芋艿:这块要优化
|
||||
.build();
|
||||
deviceDataApi.saveDeviceData(createDTO);
|
||||
deviceDataApi.reportDevicePropertyData(createDTO);
|
||||
|
||||
// 构造成功响应内容
|
||||
JSONObject successRes = createResponseJson(
|
||||
|
Reference in New Issue
Block a user