From ed8c7a5effd0d423ce1118b680ecdca6fe732609 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 02 七月 2025 16:43:13 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.11.205:9000/r/P2022036_Service

---
 src/main/java/com/lf/server/service/all/ScheduleService.java |  108 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 91 insertions(+), 17 deletions(-)

diff --git a/src/main/java/com/lf/server/service/all/ScheduleService.java b/src/main/java/com/lf/server/service/all/ScheduleService.java
index 5db8120..ec263b0 100644
--- a/src/main/java/com/lf/server/service/all/ScheduleService.java
+++ b/src/main/java/com/lf/server/service/all/ScheduleService.java
@@ -1,10 +1,14 @@
 package com.lf.server.service.all;
 
 import com.lf.server.entity.all.RedisCacheKey;
+import com.lf.server.entity.sys.LoginEntity;
+import com.lf.server.entity.sys.OperateEntity;
 import com.lf.server.entity.sys.ResEntity;
 import com.lf.server.entity.sys.UserEntity;
 import com.lf.server.helper.FileHelper;
 import com.lf.server.helper.StringHelper;
+import com.lf.server.service.sys.LoginService;
+import com.lf.server.service.sys.OperateService;
 import com.lf.server.service.sys.ResService;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -37,15 +41,18 @@
     private ResService resService;
 
     @Autowired
+    private LoginService loginService;
+
+    @Autowired
+    private OperateService operateService;
+
+    @Autowired
     private RedisTemplate<String, Object> redisTemplate;
 
     private static final Log log = LogFactory.getLog(ScheduleService.class);
 
     /**
      * 鏌ヨ鏈嶅姟鍣ㄧ姸鎬�
-     *
-     * @return
-     * @throws InterruptedException
      */
     public JSONObject selectServerStatus() throws InterruptedException {
         JSONObject json = new JSONObject();
@@ -57,9 +64,6 @@
 
     /**
      * 鏌ヨCpu淇℃伅
-     *
-     * @return
-     * @throws InterruptedException
      */
     public JSONObject selectCpuInfo() throws InterruptedException {
         SystemInfo systemInfo = new SystemInfo();
@@ -91,8 +95,6 @@
 
     /**
      * 鏌ヨ鍐呭瓨淇℃伅
-     *
-     * @return
      */
     public JSONObject selectMemInfo() {
         JSONObject map = new JSONObject();
@@ -114,8 +116,6 @@
 
     /**
      * 鏌ヨ鍦ㄧ嚎鐢ㄦ埛
-     *
-     * @return
      */
     public List<JSONObject> selectOnlineUsers() {
         List<JSONObject> list = new ArrayList<JSONObject>();
@@ -123,7 +123,7 @@
         Set<String> keys = redisTemplate.keys(RedisCacheKey.signUserKey("*"));
         for (String key : keys) {
             Object obj = redisTemplate.opsForValue().get(key);
-            if (obj != null && obj instanceof UserEntity) {
+            if (obj instanceof UserEntity) {
                 UserEntity ue = (UserEntity) obj;
 
                 JSONObject map = new JSONObject();
@@ -139,18 +139,32 @@
     }
 
     /**
+     * 缁熻鍦ㄧ嚎鐢ㄦ埛鏁�
+     */
+    public int countOnlineUsers() {
+        Set<String> keys = redisTemplate.keys(RedisCacheKey.signUserKey("*"));
+
+        return null == keys ? 0 : keys.size();
+    }
+
+    /**
      * 鏌ヨ鏈嶅姟璧勬簮鐘舵��
-     *
-     * @return
      */
     public List<ResEntity> selectResStatus() {
-        List<ResEntity> list = new ArrayList<ResEntity>();
-
         List<ResEntity> resList = resService.selectResAll();
+
+        return testResStatus(resList);
+    }
+
+    /**
+     * 娴嬭瘯璧勬簮鐘舵��
+     */
+    private List<ResEntity> testResStatus(List<ResEntity> resList) {
+        List<ResEntity> list = new ArrayList<ResEntity>();
         for (ResEntity re : resList) {
             Socket socket = new Socket();
             try {
-                if (StringHelper.isEmpty(re.getServer())){
+                if (StringHelper.isEmpty(re.getServer())) {
                     list.add(re);
                     continue;
                 }
@@ -161,7 +175,7 @@
                 // Ping閫氬湴鍧�
                 socket.connect(add, 2000);
             } catch (Exception e) {
-                log.error(e.getMessage());
+                // log.error(e.getMessage())
                 list.add(re);
             } finally {
                 try {
@@ -174,4 +188,64 @@
 
         return list;
     }
+
+    /**
+     * 缁熻鏈嶅姟璧勬簮鐘舵��
+     */
+    public JSONObject countResStatus() {
+        List<ResEntity> resList = resService.selectResAll();
+        List<ResEntity> unableList = testResStatus(resList);
+
+        JSONObject jsonObject = new JSONObject();
+
+        // 璧勬簮鍙敤
+        jsonObject.put("resAbleCount", resList.size() - unableList.size());
+        // 璧勬簮涓嶅彲鐢�
+        jsonObject.put("resUnableCount", unableList.size());
+
+        return jsonObject;
+    }
+
+    /**
+     * 璧勬簮鎿嶄綔鐘舵��
+     */
+    public JSONObject operateCount() {
+        List<OperateEntity> list = operateService.operateCount();
+        JSONObject jsonObject = new JSONObject();
+        if (list.isEmpty()) {
+            return null;
+        } else {
+            List<JSONObject> lister = new ArrayList<JSONObject>();
+            for (OperateEntity key : list) {
+                JSONObject map = new JSONObject();
+                map.put("count", key.getCount());
+                map.put("modular2", key.getModular2());
+                lister.add(map);
+            }
+            jsonObject.put("operateCount", lister);
+            return jsonObject;
+        }
+    }
+
+    /**
+     * 鐢ㄦ埛鐧诲綍鐘舵��
+     */
+    public JSONObject userLoginCount() {
+        List<LoginEntity> list = loginService.selectLoginCounts();
+        if (list == null || list.isEmpty()) {
+            return null;
+        }
+
+        JSONObject jsonObject = new JSONObject();
+        List<JSONObject> lister = new ArrayList<JSONObject>();
+        for (LoginEntity key : list) {
+            JSONObject map = new JSONObject();
+            map.put("count", key.getCount());
+            map.put("optime", key.getOptime());
+            lister.add(map);
+        }
+        jsonObject.put("userLoginCount", lister);
+
+        return jsonObject;
+    }
 }

--
Gitblit v1.9.3