jingyuanchao 10 hónapja
szülő
commit
53314cc402

+ 18 - 32
soc-modules/soc-modules-host/src/main/java/com/xunmei/host/server/service/impl/IotServerInfoServiceImpl.java

@@ -36,7 +36,6 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -182,9 +181,9 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
                 if (ObjectUtil.isNotEmpty(s)) {
                     list = JSON.parseArray(s, String.class);
                 }
-                LogUtils.SOCKET_CONNECT_STATUS_CHECK.info("获取{}系统在线的WS链接:{}",instance.getIp(), JacksonUtils.toJSONString(list));
+                LogUtils.SOCKET_CONNECT_STATUS_CHECK.info("获取{}系统在线的WS链接:{}", instance.getIp(), JacksonUtils.toJSONString(list));
             } catch (RestClientException e) {
-                LogUtils.SOCKET_CONNECT_STATUS_CHECK.info("获取{}系统在线的WS链接,发生异常:{}",instance.getIp(), e);
+                LogUtils.SOCKET_CONNECT_STATUS_CHECK.info("获取{}系统在线的WS链接,发生异常:{}", instance.getIp(), e);
                 throw new RuntimeException(e);
             }
             if (list == null) {
@@ -197,39 +196,26 @@ public class IotServerInfoServiceImpl extends ServiceImpl<IotServerInfoMapper, I
 
     @Transactional(rollbackFor = Exception.class)
     public void updateWsOnlineStatus(List<String> onlineIotCode) {
-        //获取当前在线的WS
-        final List<IotServerInfo> infoList = selectOnlineServer(null);
+        final Date date = new Date();
+        //将所有实例的WS链接状态修改为离线
+        final LambdaUpdateWrapper<IotServerInfo> wrapper = new LambdaUpdateWrapper<IotServerInfo>();
+        wrapper.set(IotServerInfo::getIotStatus, IotServerConnectStatus.OFFLINE.getIdx());
+        wrapper.set(IotServerInfo::getUpdateTime, date);
+        wrapper.set(IotServerInfo::getLastConnectTime, date);
+        baseMapper.update(null, wrapper);
+
         if (ObjectUtil.isEmpty(onlineIotCode)) {
-            final LambdaUpdateWrapper<IotServerInfo> wrapper = new LambdaUpdateWrapper<IotServerInfo>();
-            wrapper.set(IotServerInfo::getIotStatus, IotServerConnectStatus.OFFLINE.getIdx());
-            wrapper.set(IotServerInfo::getUpdateTime, new Date());
-            wrapper.set(IotServerInfo::getLastConnectTime, new Date());
-            baseMapper.update(null, wrapper);
-            LogUtils.SOCKET_CONNECT_STATUS_CHECK.info("检测WS链接状态时,发现没有在线的链接,修改所有链接为离线");
+            LogUtils.SOCKET_CONNECT_STATUS_CHECK.info("检测WS链接状态时,无任何链接在线,修改所有链接为离线状态");
             return;
         }
 
-        //获取唯一标识
-        final List<String> collect = infoList.stream().map(IotServerInfo::getIotCode).collect(Collectors.toList());
-        //如果数据库中标识为当前在线的WS链接 并不存在于从所有实例汇总到的在线的WS链接中 则更新为离线
-        final List<String> offlineIotCode = collect.stream().filter(item -> !onlineIotCode.contains(item)).collect(Collectors.toList());
-        if (ObjectUtil.isNotEmpty(offlineIotCode)) {
-            final LambdaUpdateWrapper<IotServerInfo> wrapper = new LambdaUpdateWrapper<IotServerInfo>();
-            wrapper.in(IotServerInfo::getIotCode, offlineIotCode);
-            wrapper.set(IotServerInfo::getIotStatus, IotServerConnectStatus.OFFLINE.getIdx());
-            wrapper.set(IotServerInfo::getUpdateTime, new Date());
-            wrapper.set(IotServerInfo::getLastConnectTime, new Date());
-            baseMapper.update(null, wrapper);
-            LogUtils.SOCKET_CONNECT_STATUS_CHECK.info("发现存在数据库与实际链接状态不一致的WS链接,已修改为离线:{}", offlineIotCode);
-        }
-
         //将从所有实例汇总到的在线的WS链接更新检测时间
-        final LambdaUpdateWrapper<IotServerInfo> wrapper = new LambdaUpdateWrapper<IotServerInfo>();
-        wrapper.set(IotServerInfo::getIotStatus, IotServerConnectStatus.CONNECTED.getIdx());
-        wrapper.set(IotServerInfo::getUpdateTime, new Date());
-        wrapper.set(IotServerInfo::getLastConnectTime, new Date());
-        wrapper.in(IotServerInfo::getIotCode, onlineIotCode);
-        baseMapper.update(null, wrapper);
-        LogUtils.SOCKET_CONNECT_STATUS_CHECK.info("修改在线的WS连接的检测时间:{}", JacksonUtils.toJSONString(onlineIotCode));
+        final LambdaUpdateWrapper<IotServerInfo> onlineWrapper = new LambdaUpdateWrapper<IotServerInfo>();
+        onlineWrapper.set(IotServerInfo::getIotStatus, IotServerConnectStatus.CONNECTED.getIdx());
+        onlineWrapper.set(IotServerInfo::getUpdateTime, date);
+        onlineWrapper.set(IotServerInfo::getLastConnectTime, date);
+        onlineWrapper.in(IotServerInfo::getIotCode, onlineIotCode);
+        baseMapper.update(null, onlineWrapper);
+        LogUtils.SOCKET_CONNECT_STATUS_CHECK.info("修改在线连接的检测时间:{}", JacksonUtils.toJSONString(onlineIotCode));
     }
 }

+ 2 - 1
soc-modules/soc-modules-iot/src/main/resources/mapper/IotAlarmSubsystemMapper.xml

@@ -6,7 +6,8 @@
         SELECT
             s.`name` AS deviceName,
             s.`status` AS subSystemStatus,
-            '报警控制器' AS deviceTypeName
+            '报警控制器' AS deviceTypeName,
+            s.enable as enableStatus
         FROM
             iot_alarm_subsystem s
         WHERE

+ 2 - 2
soc-modules/soc-modules-iot/src/main/resources/mapper/IotDeviceInfoMapper.xml

@@ -45,7 +45,7 @@
     </select>
     <select id="getDetailById" resultType="com.xunmei.iot.vo.deviceInfo.DeviceDetailInfoVo">
         SELECT
-            d.*,
+            d.*,d.enable as enableStatus,
             (select device_name from iot_device_info i where i.device_code = d.host_code and i.iot_token = d.iot_token) as parentName,
             o.affiliated_area AS firstOrgName,
             o.affiliated_bank AS secondOrgName,
@@ -61,7 +61,7 @@
     </select>
     <select id="getChildrenInfoList" resultType="com.xunmei.iot.vo.deviceInfo.DeviceDetailInfoVo">
         SELECT
-            d.*,
+            d.*,d.enable as enableStatus,
             o.affiliated_area AS firstOrgName,
             o.affiliated_bank AS secondOrgName,
             o.short_name AS orgName