提交 7bbd06b7 authored 作者: linzhenjie's avatar linzhenjie

mqtt订阅修改

上级 eda1077f
......@@ -19,10 +19,7 @@ import tech.glinfo.enbao.modules.sh.service.ShProductService;
import javax.annotation.Resource;
import javax.jms.Topic;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Slf4j
@Service
......@@ -55,9 +52,11 @@ public class MqttService {
for (ShInstructionParsingEntity cmd : cmds) {
String hex = msg.substring(length, length + cmd.getLength());
String hex1;
if (cmd.getType() == 1 || cmd.getType() == 2) {
if (cmd.getType() == 1) {//整数
hex1 = String.valueOf(Integer.valueOf(hex, 16));
}else {
} else if(cmd.getType() == 2) {//字符串
hex1 = hex;
} else {//有符号整数
hex1 = ByteUtils.signHex2IntString(hex);
}
map.put(cmd.getName(), hex1);
......@@ -80,7 +79,7 @@ public class MqttService {
ShDeviceEntity shDevice = new ShDeviceEntity();
shDevice.setUserId(Integer.valueOf(userId[0]));
shDevice.setOnlineStatus(2);//在线
shDevice.setMac(mac);
shDevice.setMac("GL"+mac);
shDevice.setFamilyId(Integer.valueOf(userId[1]));
shDevice.setNumbering(topics[1]);
shDevice.setName(product.getName());
......@@ -100,6 +99,14 @@ public class MqttService {
mapList.add(map1);
jmsTemplate.convertAndSend(socketioTopic, JSON.toJSONString(new MapUtils().put("deviceId", "onlineStatus").put("list", mapList)));
}
//更新设备状态为在线
new Thread(() -> {
ShDeviceEntity deviceEntity = new ShDeviceEntity();
deviceEntity.setId(device.getId());
deviceEntity.setOnlineStatus(2);
deviceEntity.setOnlineTime(new Date());
otherShDeviceService.updateById(deviceEntity);
}).start();
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论