Commit 6a06f520fb43674f9d8b24c039532250088b1f5b

Authored by YunaiV
1 parent d346a8d2

feat:【IoT 物联网】调整设备模拟发送消息的接口

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;
7 7 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
8 8 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
9 9 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.*;
10   -import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessageSendReqVO;
11   -import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
12 10 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
13 11 import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
14 12 import cn.iocoder.yudao.module.iot.service.device.message.IotDeviceMessageService;
... ... @@ -158,15 +156,6 @@ public class IotDeviceController {
158 156 ExcelUtils.write(response, "设备导入模板.xls", "数据", IotDeviceImportExcelVO.class, list);
159 157 }
160 158  
161   - // TODO @芋艿:需要重构
162   - @PostMapping("/send-message")
163   - @Operation(summary = "发送消息", description = "可用于设备模拟")
164   - @PreAuthorize("@ss.hasPermission('iot:device:upstream')")
165   - public CommonResult<Boolean> upstreamDevice(@Valid @RequestBody IotDeviceMessageSendReqVO sendReqVO) {
166   - deviceMessageService.sendDeviceMessage(BeanUtils.toBean(sendReqVO, IotDeviceMessage.class));
167   - return success(true);
168   - }
169   -
170 159 @GetMapping("/get-auth-info")
171 160 @Operation(summary = "获得设备连接信息")
172 161 @PreAuthorize("@ss.hasPermission('iot:device:auth-info')")
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceController.http renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/IotDeviceMessageController.http
1   -### 请求 /iot/device/downstream 接口(服务调用) => 成功
  1 +### 请求 /iot/device/message/send 接口(属性上报)=> 成功
  2 +POST {{baseUrl}}/iot/device/message/send
  3 +Content-Type: application/json
  4 +tenant-id: {{adminTenantId}}
  5 +Authorization: Bearer {{token}}
  6 +
  7 +{
  8 + "deviceId": 25,
  9 + "method": "thing.property.post",
  10 + "params": {
  11 + "width": 1,
  12 + "height": "2",
  13 + "oneThree": "3"
  14 + }
  15 +}
  16 +
  17 +### 请求 /iot/device/downstream 接口(服务调用)=> 成功 TODO 芋艿:未更新为最新
2 18 POST {{baseUrl}}/iot/device/downstream
3 19 Content-Type: application/json
4   -tenant-id: {{adminTenentId}}
  20 +tenant-id: {{adminTenantId}}
5 21 Authorization: Bearer {{token}}
6 22  
7 23 {
... ... @@ -13,7 +29,7 @@ Authorization: Bearer {{token}}
13 29 }
14 30 }
15 31  
16   -### 请求 /iot/device/downstream 接口(属性设置) => 成功
  32 +### 请求 /iot/device/downstream 接口(属性设置)=> 成功 TODO 芋艿:未更新为最新
17 33 POST {{baseUrl}}/iot/device/downstream
18 34 Content-Type: application/json
19 35 tenant-id: {{adminTenantId}}
... ... @@ -28,10 +44,10 @@ Authorization: Bearer {{token}}
28 44 }
29 45 }
30 46  
31   -### 请求 /iot/device/downstream 接口(属性获取) => 成功
  47 +### 请求 /iot/device/downstream 接口(属性获取)=> 成功 TODO 芋艿:未更新为最新
32 48 POST {{baseUrl}}/iot/device/downstream
33 49 Content-Type: application/json
34   -tenant-id: {{adminTenentId}}
  50 +tenant-id: {{adminTenantId}}
35 51 Authorization: Bearer {{token}}
36 52  
37 53 {
... ... @@ -41,10 +57,10 @@ Authorization: Bearer {{token}}
41 57 "data": ["xx", "yy"]
42 58 }
43 59  
44   -### 请求 /iot/device/downstream 接口(配置设置) => 成功
  60 +### 请求 /iot/device/downstream 接口(配置设置)=> 成功 TODO 芋艿:未更新为最新
45 61 POST {{baseUrl}}/iot/device/downstream
46 62 Content-Type: application/json
47   -tenant-id: {{adminTenentId}}
  63 +tenant-id: {{adminTenantId}}
48 64 Authorization: Bearer {{token}}
49 65  
50 66 {
... ... @@ -53,10 +69,10 @@ Authorization: Bearer {{token}}
53 69 "identifier": "set"
54 70 }
55 71  
56   -### 请求 /iot/device/downstream 接口(OTA 升级) => 成功
  72 +### 请求 /iot/device/downstream 接口(OTA 升级)=> 成功 TODO 芋艿:未更新为最新
57 73 POST {{baseUrl}}/iot/device/downstream
58 74 Content-Type: application/json
59   -tenant-id: {{adminTenentId}}
  75 +tenant-id: {{adminTenantId}}
60 76 Authorization: Bearer {{token}}
61 77  
62 78 {
... ...
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;
5 5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 6 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessageRespVO;
7 7 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessagePageReqVO;
  8 +import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessageSendReqVO;
  9 +import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
8 10 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO;
9 11 import cn.iocoder.yudao.module.iot.service.device.message.IotDeviceMessageService;
10 12 import io.swagger.v3.oas.annotations.Operation;
... ... @@ -13,9 +15,7 @@ import jakarta.annotation.Resource;
13 15 import jakarta.validation.Valid;
14 16 import org.springframework.security.access.prepost.PreAuthorize;
15 17 import org.springframework.validation.annotation.Validated;
16   -import org.springframework.web.bind.annotation.GetMapping;
17   -import org.springframework.web.bind.annotation.RequestMapping;
18   -import org.springframework.web.bind.annotation.RestController;
  18 +import org.springframework.web.bind.annotation.*;
19 19  
20 20 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
21 21  
... ... @@ -36,4 +36,12 @@ public class IotDeviceMessageController {
36 36 return success(BeanUtils.toBean(pageResult, IotDeviceMessageRespVO.class));
37 37 }
38 38  
  39 + @PostMapping("/send")
  40 + @Operation(summary = "发送消息", description = "可用于设备模拟")
  41 + @PreAuthorize("@ss.hasPermission('iot:device:message-end')")
  42 + public CommonResult<Boolean> upstreamDevice(@Valid @RequestBody IotDeviceMessageSendReqVO sendReqVO) {
  43 + deviceMessageService.sendDeviceMessage(BeanUtils.toBean(sendReqVO, IotDeviceMessage.class));
  44 + return success(true);
  45 + }
  46 +
39 47 }
40 48 \ No newline at end of file
... ...
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 {
57 57 List<Map<String, Object>> list = deviceLogMapper.selectDeviceLogDownCountByHour(0L, startTime, endTime);
58 58 return list.stream()
59 59 .map(map -> {
60   - // 从Timestamp获取时间戳
61 60 Timestamp timestamp = (Timestamp) map.get("time");
62 61 Long timeMillis = timestamp.getTime();
63   - // 消息数量转换
64 62 Integer count = ((Number) map.get("data")).intValue();
65 63 return MapUtil.of(timeMillis, count);
66 64 })
... ...