fix(iot): 优化设备控制指令发送功能
- 将设备信息获取方式改为使用 detail 方法,提高代码复用性 -增加对参数为空的校验,避免发送空命令 -
This commit is contained in:
parent
741eb73137
commit
36f4f8abde
@ -195,7 +195,7 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
|
||||
|
||||
@Override
|
||||
public String send(Long deviceId, Integer qos, JSONObject paras) throws JSONException {
|
||||
Device device = deviceRepo.selectOne(new LambdaQueryWrapper<Device>().eq(Device::getId, deviceId));
|
||||
DeviceVo device = detail(deviceId);
|
||||
JSONObject payloadJson = new JSONObject();
|
||||
payloadJson.put("mid", 641);
|
||||
payloadJson.put("serviceId", "runParamsCommand");
|
||||
@ -205,6 +205,9 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceRepository, Device> imp
|
||||
payloadJson.put("msgType", "cloudReq");
|
||||
String payload = payloadJson.toString();
|
||||
String topic = "/r1/devices/" + device.getClientId() + "/datas";
|
||||
if (paras.isEmpty()) {
|
||||
throw new JSONException("参数不能为空");
|
||||
}
|
||||
try {
|
||||
mqttSender.sendMsg(topic, qos, payload);
|
||||
} catch (Exception e) {
|
||||
|
Loading…
Reference in New Issue
Block a user