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

This commit is contained in:
YunaiV 2025-06-14 14:37:49 +08:00
parent d346a8d2ae
commit 6a06f520fb
4 changed files with 36 additions and 25 deletions

View File

@ -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<Boolean> 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')")

View File

@ -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}}
{

View File

@ -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<Boolean> upstreamDevice(@Valid @RequestBody IotDeviceMessageSendReqVO sendReqVO) {
deviceMessageService.sendDeviceMessage(BeanUtils.toBean(sendReqVO, IotDeviceMessage.class));
return success(true);
}
}

View File

@ -57,10 +57,8 @@ public class IotDeviceLogServiceImpl implements IotDeviceLogService {
List<Map<String, Object>> 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);
})