From 6a06f520fb43674f9d8b24c039532250088b1f5b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 14 Jun 2025 14:37:49 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E3=80=90IoT=20=E7=89=A9=E8=81=94?= =?UTF-8?q?=E7=BD=91=E3=80=91=E8=B0=83=E6=95=B4=E8=AE=BE=E5=A4=87=E6=A8=A1?= =?UTF-8?q?=E6=8B=9F=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/device/IotDeviceController.java | 11 ------ ...r.http => IotDeviceMessageController.http} | 34 ++++++++++++++----- .../device/IotDeviceMessageController.java | 14 ++++++-- .../property/IotDeviceLogServiceImpl.java | 2 -- 4 files changed, 36 insertions(+), 25 deletions(-) rename yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/{IotDeviceController.http => IotDeviceMessageController.http} (55%) diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java index e4d84381a9..60ae9eb87f 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.java @@ -7,8 +7,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.*; -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessageSendReqVO; -import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; import cn.iocoder.yudao.module.iot.service.device.message.IotDeviceMessageService; @@ -158,15 +156,6 @@ public class IotDeviceController { ExcelUtils.write(response, "设备导入模板.xls", "数据", IotDeviceImportExcelVO.class, list); } - // TODO @芋艿:需要重构 - @PostMapping("/send-message") - @Operation(summary = "发送消息", description = "可用于设备模拟") - @PreAuthorize("@ss.hasPermission('iot:device:upstream')") - public CommonResult upstreamDevice(@Valid @RequestBody IotDeviceMessageSendReqVO sendReqVO) { - deviceMessageService.sendDeviceMessage(BeanUtils.toBean(sendReqVO, IotDeviceMessage.class)); - return success(true); - } - @GetMapping("/get-auth-info") @Operation(summary = "获得设备连接信息") @PreAuthorize("@ss.hasPermission('iot:device:auth-info')") diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.http b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceMessageController.http similarity index 55% rename from yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.http rename to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceMessageController.http index 193b9fce6c..fa0b4fde08 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.http +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceMessageController.http @@ -1,7 +1,23 @@ -### 请求 /iot/device/downstream 接口(服务调用) => 成功 +### 请求 /iot/device/message/send 接口(属性上报)=> 成功 +POST {{baseUrl}}/iot/device/message/send +Content-Type: application/json +tenant-id: {{adminTenantId}} +Authorization: Bearer {{token}} + +{ + "deviceId": 25, + "method": "thing.property.post", + "params": { + "width": 1, + "height": "2", + "oneThree": "3" + } +} + +### 请求 /iot/device/downstream 接口(服务调用)=> 成功 TODO 芋艿:未更新为最新 POST {{baseUrl}}/iot/device/downstream Content-Type: application/json -tenant-id: {{adminTenentId}} +tenant-id: {{adminTenantId}} Authorization: Bearer {{token}} { @@ -13,7 +29,7 @@ Authorization: Bearer {{token}} } } -### 请求 /iot/device/downstream 接口(属性设置) => 成功 +### 请求 /iot/device/downstream 接口(属性设置)=> 成功 TODO 芋艿:未更新为最新 POST {{baseUrl}}/iot/device/downstream Content-Type: application/json tenant-id: {{adminTenantId}} @@ -28,10 +44,10 @@ Authorization: Bearer {{token}} } } -### 请求 /iot/device/downstream 接口(属性获取) => 成功 +### 请求 /iot/device/downstream 接口(属性获取)=> 成功 TODO 芋艿:未更新为最新 POST {{baseUrl}}/iot/device/downstream Content-Type: application/json -tenant-id: {{adminTenentId}} +tenant-id: {{adminTenantId}} Authorization: Bearer {{token}} { @@ -41,10 +57,10 @@ Authorization: Bearer {{token}} "data": ["xx", "yy"] } -### 请求 /iot/device/downstream 接口(配置设置) => 成功 +### 请求 /iot/device/downstream 接口(配置设置)=> 成功 TODO 芋艿:未更新为最新 POST {{baseUrl}}/iot/device/downstream Content-Type: application/json -tenant-id: {{adminTenentId}} +tenant-id: {{adminTenantId}} Authorization: Bearer {{token}} { @@ -53,10 +69,10 @@ Authorization: Bearer {{token}} "identifier": "set" } -### 请求 /iot/device/downstream 接口(OTA 升级) => 成功 +### 请求 /iot/device/downstream 接口(OTA 升级)=> 成功 TODO 芋艿:未更新为最新 POST {{baseUrl}}/iot/device/downstream Content-Type: application/json -tenant-id: {{adminTenentId}} +tenant-id: {{adminTenantId}} Authorization: Bearer {{token}} { diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceMessageController.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceMessageController.java index 7e8d7b451b..d869527e58 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceMessageController.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceMessageController.java @@ -5,6 +5,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessageRespVO; import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessagePageReqVO; +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessageSendReqVO; +import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage; import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO; import cn.iocoder.yudao.module.iot.service.device.message.IotDeviceMessageService; import io.swagger.v3.oas.annotations.Operation; @@ -13,9 +15,7 @@ import jakarta.annotation.Resource; import jakarta.validation.Valid; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -36,4 +36,12 @@ public class IotDeviceMessageController { return success(BeanUtils.toBean(pageResult, IotDeviceMessageRespVO.class)); } + @PostMapping("/send") + @Operation(summary = "发送消息", description = "可用于设备模拟") + @PreAuthorize("@ss.hasPermission('iot:device:message-end')") + public CommonResult upstreamDevice(@Valid @RequestBody IotDeviceMessageSendReqVO sendReqVO) { + deviceMessageService.sendDeviceMessage(BeanUtils.toBean(sendReqVO, IotDeviceMessage.class)); + return success(true); + } + } \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/property/IotDeviceLogServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/property/IotDeviceLogServiceImpl.java index b1da79c438..311a3bb988 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/property/IotDeviceLogServiceImpl.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/property/IotDeviceLogServiceImpl.java @@ -57,10 +57,8 @@ public class IotDeviceLogServiceImpl implements IotDeviceLogService { List> list = deviceLogMapper.selectDeviceLogDownCountByHour(0L, startTime, endTime); return list.stream() .map(map -> { - // 从Timestamp获取时间戳 Timestamp timestamp = (Timestamp) map.get("time"); Long timeMillis = timestamp.getTime(); - // 消息数量转换 Integer count = ((Number) map.get("data")).intValue(); return MapUtil.of(timeMillis, count); })