【功能新增】IoT:OTA 升级的下行消息的实现
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
package cn.iocoder.yudao.module.iot.plugin.common.downstream;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDeviceConfigSetReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDevicePropertyGetReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDevicePropertySetReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDeviceServiceInvokeReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.*;
|
||||
|
||||
/**
|
||||
* IoT 设备下行处理器
|
||||
@@ -47,4 +44,12 @@ public interface IotDeviceDownstreamHandler {
|
||||
*/
|
||||
CommonResult<Boolean> setDeviceConfig(IotDeviceConfigSetReqDTO setReqDTO);
|
||||
|
||||
/**
|
||||
* 升级设备 OTA
|
||||
*
|
||||
* @param upgradeReqDTO 升级设备 OTA 的请求
|
||||
* @return 是否成功
|
||||
*/
|
||||
CommonResult<Boolean> upgradeDeviceOta(IotDeviceOtaUpgradeReqDTO upgradeReqDTO);
|
||||
|
||||
}
|
||||
|
@@ -1,10 +1,7 @@
|
||||
package cn.iocoder.yudao.module.iot.plugin.common.downstream;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.plugin.common.config.IotPluginCommonProperties;
|
||||
import cn.iocoder.yudao.module.iot.plugin.common.downstream.router.IotDeviceConfigSetVertxHandler;
|
||||
import cn.iocoder.yudao.module.iot.plugin.common.downstream.router.IotDevicePropertyGetVertxHandler;
|
||||
import cn.iocoder.yudao.module.iot.plugin.common.downstream.router.IotDevicePropertySetVertxHandler;
|
||||
import cn.iocoder.yudao.module.iot.plugin.common.downstream.router.IotDeviceServiceInvokeVertxHandler;
|
||||
import cn.iocoder.yudao.module.iot.plugin.common.downstream.router.*;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.http.HttpServer;
|
||||
import io.vertx.ext.web.Router;
|
||||
@@ -39,6 +36,8 @@ public class IotDeviceDownstreamServer {
|
||||
.handler(new IotDevicePropertyGetVertxHandler(deviceDownstreamHandler));
|
||||
router.post(IotDeviceConfigSetVertxHandler.PATH)
|
||||
.handler(new IotDeviceConfigSetVertxHandler(deviceDownstreamHandler));
|
||||
router.post(IotDeviceOtaUpgradeVertxHandler.PATH)
|
||||
.handler(new IotDeviceOtaUpgradeVertxHandler(deviceDownstreamHandler));
|
||||
// 创建 HttpServer 实例
|
||||
this.server = vertx.createHttpServer().requestHandler(router);
|
||||
}
|
||||
|
@@ -0,0 +1,60 @@
|
||||
package cn.iocoder.yudao.module.iot.plugin.common.downstream.router;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDeviceOtaUpgradeReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler;
|
||||
import cn.iocoder.yudao.module.iot.plugin.common.util.IotPluginCommonUtils;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST;
|
||||
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class IotDeviceOtaUpgradeVertxHandler implements Handler<RoutingContext> {
|
||||
|
||||
public static final String PATH = "/ota/:productKey/:deviceName/upgrade";
|
||||
|
||||
private final IotDeviceDownstreamHandler deviceDownstreamHandler;
|
||||
|
||||
@Override
|
||||
public void handle(RoutingContext routingContext) {
|
||||
// 1. 解析参数
|
||||
IotDeviceOtaUpgradeReqDTO reqDTO;
|
||||
try {
|
||||
String productKey = routingContext.pathParam("productKey");
|
||||
String deviceName = routingContext.pathParam("deviceName");
|
||||
JsonObject body = routingContext.body().asJsonObject();
|
||||
String requestId = body.getString("requestId");
|
||||
Long firmwareId = body.getLong("firmwareId");
|
||||
String version = body.getString("version");
|
||||
String signMethod = body.getString("signMethod");
|
||||
String fileSign = body.getString("fileSign");
|
||||
Long fileSize = body.getLong("fileSize");
|
||||
String fileUrl = body.getString("fileUrl");
|
||||
String information = body.getString("information");
|
||||
reqDTO = ((IotDeviceOtaUpgradeReqDTO) new IotDeviceOtaUpgradeReqDTO()
|
||||
.setRequestId(requestId).setProductKey(productKey).setDeviceName(deviceName))
|
||||
.setFirmwareId(firmwareId).setVersion(version)
|
||||
.setSignMethod(signMethod).setFileSign(fileSign).setFileSize(fileSize).setFileUrl(fileUrl)
|
||||
.setInformation(information);
|
||||
} catch (Exception e) {
|
||||
log.error("[handle][路径参数({}) 解析参数失败]", routingContext.pathParams(), e);
|
||||
IotPluginCommonUtils.writeJson(routingContext, CommonResult.error(BAD_REQUEST));
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 调用处理器
|
||||
try {
|
||||
CommonResult<Boolean> result = deviceDownstreamHandler.upgradeDeviceOta(reqDTO);
|
||||
IotPluginCommonUtils.writeJson(routingContext, result);
|
||||
} catch (Exception e) {
|
||||
log.error("[handle][请求参数({}) OTA 升级异常]", reqDTO, e);
|
||||
IotPluginCommonUtils.writeJson(routingContext, CommonResult.error(INTERNAL_SERVER_ERROR));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,10 +1,7 @@
|
||||
package cn.iocoder.yudao.module.iot.plugin.http.downstream;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDeviceConfigSetReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDevicePropertyGetReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDevicePropertySetReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.IotDeviceServiceInvokeReqDTO;
|
||||
import cn.iocoder.yudao.module.iot.api.device.dto.control.downstream.*;
|
||||
import cn.iocoder.yudao.module.iot.plugin.common.downstream.IotDeviceDownstreamHandler;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants.NOT_IMPLEMENTED;
|
||||
@@ -39,4 +36,9 @@ public class IotDeviceDownstreamHandlerImpl implements IotDeviceDownstreamHandle
|
||||
return CommonResult.error(NOT_IMPLEMENTED.getCode(), "HTTP 不支持设置设备属性");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> upgradeDeviceOta(IotDeviceOtaUpgradeReqDTO upgradeReqDTO) {
|
||||
return CommonResult.error(NOT_IMPLEMENTED.getCode(), "HTTP 不支持设置设备属性");
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user