Browse Source

首页 查询检测系统 在线离线 1:在线 2:离线

sunhh 1 year ago
parent
commit
3c09c3fcfd

+ 4 - 0
business-service/src/main/java/com/ozs/mapper/MonitorSystemMapper.java

@@ -2,6 +2,8 @@ package com.ozs.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ozs.entity.MonitorSystem;
+import com.ozs.entity.vo.AlarmHeartbeatLog;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 import java.util.Map;
@@ -55,5 +57,7 @@ public interface MonitorSystemMapper extends BaseMapper<MonitorSystem> {
     Map<String, Object> monitorSystemCount();
 
     List<MonitorSystem> monitorSystemList();
+
+    AlarmHeartbeatLog selectAlarmHeartbeatLogByClientId(@Param("clientId") String clientId);
 }
 

+ 31 - 4
business-service/src/main/java/com/ozs/service/impl/MonitorSystemServiceImpl.java

@@ -9,7 +9,9 @@ import com.ozs.common.utils.StringUtils;
 import com.ozs.common.utils.bean.BeanUtils;
 import com.ozs.common.utils.stateSecrets.SM4Utils;
 import com.ozs.entity.MonitorSystem;
+import com.ozs.entity.SkynetHeartbeatLog;
 import com.ozs.entity.SvcAddress;
+import com.ozs.entity.vo.AlarmHeartbeatLog;
 import com.ozs.entity.vo.MonitorSystemVo;
 import com.ozs.mapper.MonitorSystemMapper;
 import com.ozs.mapper.SvcAddressMapper;
@@ -19,9 +21,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.ObjectUtils;
 
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -178,9 +178,36 @@ public class MonitorSystemServiceImpl extends ServiceImpl<MonitorSystemMapper, M
 
     @Override
     public Map<String, Object> monitorSystem() {
-        Map<String, Object> mapCount = monitorSystemMapper.monitorSystemCount();
+        // Map<String, Object> mapCount = monitorSystemMapper.monitorSystemCount();
+        Map<String, Object> mapCount = new HashMap<>();
         List<MonitorSystem> monitorSystemList = monitorSystemMapper.monitorSystemList();
+        int offlineMonitor = 0;
+        int onlineMonitor = 0;
+        for (MonitorSystem monitorSystem : monitorSystemList) {
+            if (!StringUtils.isEmptySunhh(monitorSystem) && !StringUtils.isEmptySunhh(monitorSystem.getClientId())) {
+                AlarmHeartbeatLog alarmHeartbeatLog = monitorSystemMapper.selectAlarmHeartbeatLogByClientId(monitorSystem.getClientId());
+                if (StringUtils.isEmptySunhh(alarmHeartbeatLog)) {
+                    offlineMonitor++;
+                    monitorSystem.setStatus(2);
+                } else {
+                    long timeNow = new Date().getTime();
+                    long createTime = alarmHeartbeatLog.getCreateTime().getTime();
+                    long thereHourMillis = 60 * 60 * 1000 * 3;
+                    long timeNew = timeNow - thereHourMillis;
+                    if (timeNew <= createTime) {
+                        onlineMonitor++;
+                        monitorSystem.setStatus(1);
+                    } else {
+                        offlineMonitor++;
+                        monitorSystem.setStatus(2);
+                    }
+                }
+            }
+        }
         mapCount.put("monitorSystemList", monitorSystemList);
+        mapCount.put("countAllMonitor", monitorSystemList.size());
+        mapCount.put("offlineMonitor", offlineMonitor);
+        mapCount.put("onlineMonitor", onlineMonitor);
         return mapCount;
     }
 }

+ 4 - 0
business-service/src/main/resources/mapper/MonitorSystemMapper.xml

@@ -80,4 +80,8 @@
             SELECT count(id) countAlarm, SOURCE FROM msg_alarm where IS_RELEASE = 2 GROUP BY SOURCE
         ) b ON a.CLIENT_ID = b.SOURCE
     </select>
+
+    <select id="selectAlarmHeartbeatLogByClientId" resultType="com.ozs.entity.vo.AlarmHeartbeatLog" parameterType="java.lang.String">
+        select /*+ GROUP_OPT_FLAG(1)*/ id, client_id, max(create_time) as createTime from alarm_heartbeat_log where client_id = #{clientId}
+    </select>
 </mapper>