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,8 +7,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 7 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
8 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; 8 import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
9 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.*; 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 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO; 10 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
13 import cn.iocoder.yudao.module.iot.service.device.IotDeviceService; 11 import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
14 import cn.iocoder.yudao.module.iot.service.device.message.IotDeviceMessageService; 12 import cn.iocoder.yudao.module.iot.service.device.message.IotDeviceMessageService;
@@ -158,15 +156,6 @@ public class IotDeviceController { @@ -158,15 +156,6 @@ public class IotDeviceController {
158 ExcelUtils.write(response, "设备导入模板.xls", "数据", IotDeviceImportExcelVO.class, list); 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 @GetMapping("/get-auth-info") 159 @GetMapping("/get-auth-info")
171 @Operation(summary = "获得设备连接信息") 160 @Operation(summary = "获得设备连接信息")
172 @PreAuthorize("@ss.hasPermission('iot:device:auth-info')") 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 POST {{baseUrl}}/iot/device/downstream 18 POST {{baseUrl}}/iot/device/downstream
3 Content-Type: application/json 19 Content-Type: application/json
4 -tenant-id: {{adminTenentId}} 20 +tenant-id: {{adminTenantId}}
5 Authorization: Bearer {{token}} 21 Authorization: Bearer {{token}}
6 22
7 { 23 {
@@ -13,7 +29,7 @@ Authorization: Bearer {{token}} @@ -13,7 +29,7 @@ Authorization: Bearer {{token}}
13 } 29 }
14 } 30 }
15 31
16 -### 请求 /iot/device/downstream 接口(属性设置) => 成功 32 +### 请求 /iot/device/downstream 接口(属性设置)=> 成功 TODO 芋艿:未更新为最新
17 POST {{baseUrl}}/iot/device/downstream 33 POST {{baseUrl}}/iot/device/downstream
18 Content-Type: application/json 34 Content-Type: application/json
19 tenant-id: {{adminTenantId}} 35 tenant-id: {{adminTenantId}}
@@ -28,10 +44,10 @@ Authorization: Bearer {{token}} @@ -28,10 +44,10 @@ Authorization: Bearer {{token}}
28 } 44 }
29 } 45 }
30 46
31 -### 请求 /iot/device/downstream 接口(属性获取) => 成功 47 +### 请求 /iot/device/downstream 接口(属性获取)=> 成功 TODO 芋艿:未更新为最新
32 POST {{baseUrl}}/iot/device/downstream 48 POST {{baseUrl}}/iot/device/downstream
33 Content-Type: application/json 49 Content-Type: application/json
34 -tenant-id: {{adminTenentId}} 50 +tenant-id: {{adminTenantId}}
35 Authorization: Bearer {{token}} 51 Authorization: Bearer {{token}}
36 52
37 { 53 {
@@ -41,10 +57,10 @@ Authorization: Bearer {{token}} @@ -41,10 +57,10 @@ Authorization: Bearer {{token}}
41 "data": ["xx", "yy"] 57 "data": ["xx", "yy"]
42 } 58 }
43 59
44 -### 请求 /iot/device/downstream 接口(配置设置) => 成功 60 +### 请求 /iot/device/downstream 接口(配置设置)=> 成功 TODO 芋艿:未更新为最新
45 POST {{baseUrl}}/iot/device/downstream 61 POST {{baseUrl}}/iot/device/downstream
46 Content-Type: application/json 62 Content-Type: application/json
47 -tenant-id: {{adminTenentId}} 63 +tenant-id: {{adminTenantId}}
48 Authorization: Bearer {{token}} 64 Authorization: Bearer {{token}}
49 65
50 { 66 {
@@ -53,10 +69,10 @@ Authorization: Bearer {{token}} @@ -53,10 +69,10 @@ Authorization: Bearer {{token}}
53 "identifier": "set" 69 "identifier": "set"
54 } 70 }
55 71
56 -### 请求 /iot/device/downstream 接口(OTA 升级) => 成功 72 +### 请求 /iot/device/downstream 接口(OTA 升级)=> 成功 TODO 芋艿:未更新为最新
57 POST {{baseUrl}}/iot/device/downstream 73 POST {{baseUrl}}/iot/device/downstream
58 Content-Type: application/json 74 Content-Type: application/json
59 -tenant-id: {{adminTenentId}} 75 +tenant-id: {{adminTenantId}}
60 Authorization: Bearer {{token}} 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,6 +5,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessageRespVO; 6 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessageRespVO;
7 import cn.iocoder.yudao.module.iot.controller.admin.device.vo.message.IotDeviceMessagePageReqVO; 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 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO; 10 import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceMessageDO;
9 import cn.iocoder.yudao.module.iot.service.device.message.IotDeviceMessageService; 11 import cn.iocoder.yudao.module.iot.service.device.message.IotDeviceMessageService;
10 import io.swagger.v3.oas.annotations.Operation; 12 import io.swagger.v3.oas.annotations.Operation;
@@ -13,9 +15,7 @@ import jakarta.annotation.Resource; @@ -13,9 +15,7 @@ import jakarta.annotation.Resource;
13 import jakarta.validation.Valid; 15 import jakarta.validation.Valid;
14 import org.springframework.security.access.prepost.PreAuthorize; 16 import org.springframework.security.access.prepost.PreAuthorize;
15 import org.springframework.validation.annotation.Validated; 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 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 20 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
21 21
@@ -36,4 +36,12 @@ public class IotDeviceMessageController { @@ -36,4 +36,12 @@ public class IotDeviceMessageController {
36 return success(BeanUtils.toBean(pageResult, IotDeviceMessageRespVO.class)); 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 \ No newline at end of file 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,10 +57,8 @@ public class IotDeviceLogServiceImpl implements IotDeviceLogService {
57 List<Map<String, Object>> list = deviceLogMapper.selectDeviceLogDownCountByHour(0L, startTime, endTime); 57 List<Map<String, Object>> list = deviceLogMapper.selectDeviceLogDownCountByHour(0L, startTime, endTime);
58 return list.stream() 58 return list.stream()
59 .map(map -> { 59 .map(map -> {
60 - // 从Timestamp获取时间戳  
61 Timestamp timestamp = (Timestamp) map.get("time"); 60 Timestamp timestamp = (Timestamp) map.get("time");
62 Long timeMillis = timestamp.getTime(); 61 Long timeMillis = timestamp.getTime();
63 - // 消息数量转换  
64 Integer count = ((Number) map.get("data")).intValue(); 62 Integer count = ((Number) map.get("data")).intValue();
65 return MapUtil.of(timeMillis, count); 63 return MapUtil.of(timeMillis, count);
66 }) 64 })