TRX 1 год назад
Родитель
Сommit
1a7f26b9e3

+ 11 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/mqtt/DevicePingInfoService.java

@@ -13,6 +13,7 @@ import com.zhongshu.iot.server.core.domain.ExecuteAnnotationService;
 import com.zhongshu.iot.server.core.domain.ExecuteAnnotationServiceMethod;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.DeviceInfo;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.DevicePingInfo;
+import com.zhongshu.iot.server.core.domain.iot.mqtt.GateWay2Device;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.GateWayInfo;
 import com.zhongshu.iot.server.core.service.base.CommonService;
 import com.zhongshu.iot.server.core.service.base.SuperService;
@@ -64,6 +65,7 @@ public class DevicePingInfoService extends SuperService {
     public ResultContent<Object> devicePing(String dataStr) {
         DevicePingInfoParam param = JSONUtil.toBean(dataStr, DevicePingInfoParam.class);
         String deviceId = param.getDeviceId();
+        log.info("devicePing 设备在线处理:{}", deviceId);
         DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
         if (ObjectUtils.isNotEmpty(deviceInfo)) {
             Long time = System.currentTimeMillis();
@@ -73,6 +75,13 @@ public class DevicePingInfoService extends SuperService {
             standardData.put("onLineState", OnLineState.OnLine);
             commonService.updateData(standardData, DeviceInfo.class.getSimpleName());
 
+            Map<String, Object> whereMap = new HashMap<String, Object>();
+            whereMap.put("deviceId", deviceId);
+
+            Map<String, Object> dataMap = new HashMap<String, Object>();
+            dataMap.put("state", OnLineState.OnLine);
+            commonService.updateData(whereMap, dataMap, GateWay2Device.class.getSimpleName());
+
             // ping记录
             DevicePingInfo devicePingInfo = new DevicePingInfo();
             devicePingInfo.setPingType(deviceInfo.getDeviceType().name());
@@ -103,10 +112,12 @@ public class DevicePingInfoService extends SuperService {
         if (StringUtils.isNotEmpty(param.getDeviceId())) {
             devicePing(dataStr);
         } else {
+            log.info("ping 网关在线处理:{}", param.getGateWayId());
             GateWayInfo gateWayInfo = gateWayInfoDao.findTopByGateWayId(param.getGateWayId());
             if (ObjectUtils.isNotEmpty(gateWayInfo)) {
                 Map<String, Object> where = new HashMap<>();
                 where.put("gateWayId", gateWayInfo.getGateWayId());
+
                 Map<String, Object> standardData = new HashMap<>();
                 standardData.put("onLineState", OnLineState.OnLine);
                 standardData.put("lastOnlineTime", System.currentTimeMillis());