bihuisong 1 年之前
父節點
當前提交
6dee4b3be2

+ 6 - 6
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SecurityController.java

@@ -61,12 +61,12 @@ public class SecurityController {
     @ResponseBody
     public AjaxResult getToken(@RequestBody TokenRequest form) {
         //解密密码字符串
-//        String privateKey = redisService.getCacheObject("remoteSecretKey");
-//        try {
-//            RsaUtil.decrypt(form.getUsername(), privateKey);
-//        } catch (Exception e) {
-//            return AjaxResult.error("获取token失败").put("data", null).put("code",40002);
-//        }
+        String privateKey = redisService.getCacheObject("remoteSecretKey");
+        try {
+            RsaUtil.decrypt(form.getUsername(), privateKey);
+        } catch (Exception e) {
+            return AjaxResult.error("获取token失败").put("data", null).put("code",40002);
+        }
         SysUser user = userService.selectUserByLoginName(form.getUsername());
         String token = JwtUtils.createToken(form.getUsername(), user.getPassword());
         try {

+ 0 - 28
ruoyi-admin/src/main/java/com/ruoyi/web/controller/visual/PageDataViewController.java

@@ -1,28 +0,0 @@
-package com.ruoyi.web.controller.visual;
-
-
-import com.ruoyi.common.core.domain.Result;
-import com.ruoyi.system.service.IWebsiteAvailabilityMonitorService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-
-@RestController
-@RequestMapping("/view/")
-public class PageDataViewController {
-
-    @Autowired
-    private IWebsiteAvailabilityMonitorService websiteAvailabilityMonitorService;
-
-
-    /**
-     * 网站可用性实时监测
-     */
-    @PostMapping("getWebsiteAvailabilityMonitor")
-    @ResponseBody
-    public Result<?> getWebsiteAvailabilityMonitor() {
-        return Result.ok(websiteAvailabilityMonitorService.selectWebsiteAvailabilityMonitorList());
-    }
-
-
-}

二進制
ruoyi-admin/src/main/resources/static/favicon.ico


二進制
ruoyi-admin/src/main/resources/static/img/login-background.jpg


二進制
ruoyi-admin/src/main/resources/static/img/pay.png


二進制
ruoyi-admin/src/main/resources/static/img/profile.jpg


二進制
ruoyi-admin/src/main/resources/static/img/qr_code.png


+ 109 - 22
ruoyi-admin/src/main/resources/static/js/socket.js

@@ -1,32 +1,119 @@
-// 创建 WebSocket 对象并连接到服务器
-var socket = new WebSocket("ws://127.0.0.1:16006/ws");
+function WebSocketWithHeartbeat(url) {
+    this.url = url;
+    this.websocket = null;
+    this.heartbeatInterval = 3000; // 心跳间隔时间(毫秒)
+    this.reconnectInterval = 1000; // 重新连接间隔时间(毫秒)
+    this.heartbeatTimer = null;
 
-// 当与服务器成功建立连接时触发该事件
-socket.onopen = function() {
-    console.log("已经与服务器建立了连接。");
+    this.onOpen = null; // 连接打开时的回调函数
+    this.onMessage = null; // 收到消息时的回调函数
+    this.onClose = null; // 连接关闭时的回调函数
+    this.onError = null; // 发生错误时的回调函数
+
+    this.connect();
+}
+
+WebSocketWithHeartbeat.prototype.connect = function() {
+    this.websocket = new WebSocket(this.url);
+
+    this.websocket.onopen = () => {
+        console.log('WebSocket 连接已打开');
+
+        if (typeof this.onOpen === 'function') {
+            this.onOpen();
+        }
+
+        this.startHeartbeat();
+    };
+
+    this.websocket.onmessage = (event) => {
+        console.log('收到消息:', event.data);
+
+        if (typeof this.onMessage === 'function') {
+            this.onMessage(event.data);
+        }
+    };
+
+    this.websocket.onclose = (event) => {
+        console.log('WebSocket 连接已关闭');
+
+        if (typeof this.onClose === 'function') {
+            this.onClose();
+        }
+
+        this.stopHeartbeat();
+
+        setTimeout(() => {
+            this.connect();
+        }, this.reconnectInterval);
+    };
+
+    this.websocket.onerror = (error) => {
+        console.error('WebSocket 错误:', error);
+
+        if (typeof this.onError === 'function') {
+            this.onError(error);
+        }
+    };
+};
+
+WebSocketWithHeartbeat.prototype.startHeartbeat = function() {
+    this.stopHeartbeat(); // 先停止之前的心跳计时器
+
+    this.heartbeatTimer = setInterval(() => {
+        this.sendHeartbeat();
+    }, this.heartbeatInterval);
 };
 
-// 当收到来自服务器的消息时触发该事件
-socket.onmessage = function(event) {
-    var message = event.data; // 获取从服务器传输过来的数据
-    console.log("收到服务器的消息:", message);
+WebSocketWithHeartbeat.prototype.stopHeartbeat = function() {
+    if (this.heartbeatTimer) {
+        clearInterval(this.heartbeatTimer);
+        this.heartbeatTimer = null;
+    }
 };
 
-// 当与服务器断开连接时触发该事件
-socket.onclose = function() {
-    console.log("与服务器的连接已关闭。");
+WebSocketWithHeartbeat.prototype.sendHeartbeat = function() {
+    var heartbeatMessage = 'heartbeat';
+
+    if (this.websocket.readyState === WebSocket.OPEN) {
+        this.websocket.send(heartbeatMessage);
+    }
 };
 
-// 向服务器发送消息
-function sendMessageToServer(message) {
-    if (socket.readyState === WebSocket.OPEN) {
-        socket.send(message);
+WebSocketWithHeartbeat.prototype.send = function(message) {
+    if (this.websocket.readyState === WebSocket.OPEN) {
+        this.websocket.send(message);
     } else {
-        console.error("无法发送消息,因为与服务器的连接未打开或已关闭。");
+        console.error('WebSocket 连接未打开');
     }
-}
+};
+
+WebSocketWithHeartbeat.prototype.close = function() {
+    if (this.websocket) {
+        this.websocket.close();
+    }
+};
+
+// 示例用法
+const socket = new WebSocketWithHeartbeat('ws://127.0.0.1:16006/ws');
+
+socket.onOpen = function() {
+    console.log('连接已打开');
+    // 可以在这里执行一些初始化操作或发送初始消息
+};
+
+socket.onMessage = function(data) {
+    console.log('收到消息:', data);
+    // 处理接收到的消息
+};
+
+socket.onClose = function() {
+    console.log('连接已关闭');
+};
+
+socket.onError = function(error) {
+    console.error('WebSocket 错误:', error);
+};
 
-// 关闭与服务器的连接
-function closeConnectionWithServer() {
-    socket.close();
-}
+// 发送消息
+socket.send('Hello, WebSocket!');

+ 23 - 23
ruoyi-admin/src/main/resources/templates/index.html

@@ -26,7 +26,7 @@
         </div>
         <a th:href="@{/index}">
             <li class="logo hidden-xs">
-                <span class="logo-lg">RuoYi</span>
+                <span class="logo-lg">吉林监测可视化管理</span>
             </li>
          </a>
         <div class="sidebar-collapse">
@@ -349,30 +349,30 @@ $(function() {
 	}
 	
 	/* 初始密码提示 */
-	if([[${isDefaultModifyPwd}]]) {
-		layer.confirm("您的密码还是初始密码,请修改密码!", {
-			icon: 0,
-			title: "安全提示",
-			btn: ['确认'	, '取消'],
-			offset: ['30%']
-		}, function (index) {
-			resetPwd();
-			layer.close(index);
-		});
-	}
+	// if([[${isDefaultModifyPwd}]]) {
+	// 	layer.confirm("您的密码还是初始密码,请修改密码!", {
+	// 		icon: 0,
+	// 		title: "安全提示",
+	// 		btn: ['确认'	, '取消'],
+	// 		offset: ['30%']
+	// 	}, function (index) {
+	// 		resetPwd();
+	// 		layer.close(index);
+	// 	});
+	// }
 	
 	/* 过期密码提示 */
-	if([[${isPasswordExpired}]]) {
-		layer.confirm("您的密码已过期,请尽快修改密码!", {
-			icon: 0,
-			title: "安全提示",
-			btn: ['确认'	, '取消'],
-			offset: ['30%']
-		}, function (index) {
-			resetPwd();
-			layer.close(index);
-		});
-	}
+	// if([[${isPasswordExpired}]]) {
+	// 	layer.confirm("您的密码已过期,请尽快修改密码!", {
+	// 		icon: 0,
+	// 		title: "安全提示",
+	// 		btn: ['确认'	, '取消'],
+	// 		offset: ['30%']
+	// 	}, function (index) {
+	// 		resetPwd();
+	// 		layer.close(index);
+	// 	});
+	// }
 	$("[data-toggle='tooltip']").tooltip();
 });
 </script>

+ 1 - 24
ruoyi-admin/src/main/resources/templates/login.html

@@ -23,27 +23,9 @@
 <body class="signin">
     <div class="signinpanel">
         <div class="row">
-            <div class="col-sm-7">
-                <div class="signin-info">
-                    <div class="logopanel m-b">
-                        <h1><img alt="[ 若依 ]" src="../static/ruoyi.png" th:src="@{/ruoyi.png}"></h1>
-                    </div>
-                    <div class="m-b"></div>
-                    <h4>欢迎使用 <strong>若依 后台管理系统</strong></h4>
-                    <ul class="m-b">
-                        <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> SpringBoot</li>
-                        <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> Mybatis</li>
-                        <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> Shiro</li>
-                        <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> Thymeleaf</li>
-                        <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> Bootstrap</li>
-                    </ul>
-                    <strong th:if="${isAllowRegister}">还没有账号? <a th:href="@{/register}">立即注册&raquo;</a></strong>
-                </div>
-            </div>
-            <div class="col-sm-5">
+            <div class="col-sm-5"  style="margin-left: 200px">
                 <form id="signupForm" autocomplete="off">
                     <h4 class="no-margins">登录:</h4>
-                    <p class="m-t-md">你若不离不弃,我必生死相依</p>
                     <input type="text"     name="username" class="form-control uname"     placeholder="用户名" value="admin"    />
                     <input type="password" name="password" class="form-control pword"     placeholder="密码"   value="admin123" />
 					<div class="row m-t" th:if="${captchaEnabled==true}">
@@ -63,11 +45,6 @@
                 </form>
             </div>
         </div>
-        <div class="signup-footer">
-            <div class="pull-left">
-                Copyright © 2018-2023 ruoyi.vip All Rights Reserved. <br>
-            </div>
-        </div>
     </div>
 <script th:inline="javascript"> var ctx = [[@{/}]]; var captchaType = [[${captchaType}]]; var captchaEnabled = [[${captchaEnabled}]];</script>
 <!--[if lte IE 8]><script>window.location.href=ctx+'html/ie.html';</script><![endif]-->

文件差異過大導致無法顯示
+ 0 - 1680
ruoyi-admin/src/main/resources/templates/main.html


+ 0 - 5
ruoyi-framework/pom.xml

@@ -77,11 +77,6 @@
             <artifactId>ruoyi-system</artifactId>
         </dependency>
 
-        <!-- SpringBoot Websocket -->
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-websocket</artifactId>
-        </dependency>
     </dependencies>
 
 </project>

+ 5 - 0
ruoyi-system/pom.xml

@@ -23,6 +23,11 @@
             <artifactId>ruoyi-common</artifactId>
         </dependency>
 
+        <!-- SpringBoot Websocket -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-websocket</artifactId>
+        </dependency>
     </dependencies>
 
 </project>

+ 4 - 3
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WebsiteAvailabilityMonitorServiceImpl.java

@@ -1,10 +1,11 @@
 package com.ruoyi.system.service.impl;
 
-import com.ruoyi.system.domain.UnableToAccessWebsiteListToday;
-import com.ruoyi.system.domain.WebSiteTenDaysHits;
+
+import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.system.domain.WebsiteAvailabilityMonitor;
 import com.ruoyi.system.mapper.WebsiteAvailabilityMonitorMapper;
 import com.ruoyi.system.service.IWebsiteAvailabilityMonitorService;
+import com.ruoyi.websocket.WebSocketUsers;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
@@ -15,12 +16,12 @@ import java.util.List;
 @Service
 public class WebsiteAvailabilityMonitorServiceImpl implements IWebsiteAvailabilityMonitorService {
 
-
     @Autowired
     private WebsiteAvailabilityMonitorMapper websiteAvailabilityMonitorMapper;
 
     @Override
     public List<WebsiteAvailabilityMonitor> selectWebsiteAvailabilityMonitorList() {
+        WebSocketUsers.sendMessageToUsersByText(JSONObject.toJSONString(websiteAvailabilityMonitorMapper.selectWebsiteAvailabilityMonitorList()));
         return websiteAvailabilityMonitorMapper.selectWebsiteAvailabilityMonitorList();
     }
 

+ 1 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/SemaphoreUtils.java

@@ -1,4 +1,4 @@
-package com.ruoyi.framework.websocket;
+package com.ruoyi.websocket;
 
 import java.util.concurrent.Semaphore;
 import org.slf4j.Logger;

+ 5 - 6
ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketConfig.java

@@ -1,20 +1,19 @@
-package com.ruoyi.framework.websocket;
+package com.ruoyi.websocket;
 
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.socket.server.standard.ServerEndpointExporter;
 
+
 /**
  * websocket 配置
- * 
+ *
  * @author ruoyi
  */
 @Configuration
-public class WebSocketConfig
-{
+public class WebSocketConfig {
     @Bean
-    public ServerEndpointExporter serverEndpointExporter()
-    {
+    public ServerEndpointExporter serverEndpointExporter() {
         return new ServerEndpointExporter();
     }
 }

+ 1 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketServer.java

@@ -1,4 +1,4 @@
-package com.ruoyi.framework.websocket;
+package com.ruoyi.websocket;
 
 import java.util.concurrent.Semaphore;
 import javax.websocket.OnClose;

+ 26 - 45
ruoyi-framework/src/main/java/com/ruoyi/framework/websocket/WebSocketUsers.java

@@ -1,4 +1,4 @@
-package com.ruoyi.framework.websocket;
+package com.ruoyi.websocket;
 
 import java.io.IOException;
 import java.util.Collection;
@@ -6,16 +6,18 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import javax.websocket.Session;
+
+import lombok.extern.slf4j.Slf4j;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * websocket 客户端用户集
- * 
+ *
  * @author ruoyi
  */
-public class WebSocketUsers
-{
+@Slf4j
+public class WebSocketUsers {
     /**
      * WebSocketUsers 日志控制器
      */
@@ -29,11 +31,10 @@ public class WebSocketUsers
     /**
      * 存储用户
      *
-     * @param key 唯一键
+     * @param key     唯一键
      * @param session 用户信息
      */
-    public static void put(String key, Session session)
-    {
+    public static void put(String key, Session session) {
         USERS.put(key, session);
     }
 
@@ -41,28 +42,21 @@ public class WebSocketUsers
      * 移除用户
      *
      * @param session 用户信息
-     *
      * @return 移除结果
      */
-    public static boolean remove(Session session)
-    {
+    public static boolean remove(Session session) {
         String key = null;
         boolean flag = USERS.containsValue(session);
-        if (flag)
-        {
+        if (flag) {
             Set<Map.Entry<String, Session>> entries = USERS.entrySet();
-            for (Map.Entry<String, Session> entry : entries)
-            {
+            for (Map.Entry<String, Session> entry : entries) {
                 Session value = entry.getValue();
-                if (value.equals(session))
-                {
+                if (value.equals(session)) {
                     key = entry.getKey();
                     break;
                 }
             }
-        }
-        else
-        {
+        } else {
             return true;
         }
         return remove(key);
@@ -73,18 +67,14 @@ public class WebSocketUsers
      *
      * @param key 键
      */
-    public static boolean remove(String key)
-    {
+    public static boolean remove(String key) {
         LOGGER.info("\n 正在移出用户 - {}", key);
         Session remove = USERS.remove(key);
-        if (remove != null)
-        {
+        if (remove != null) {
             boolean containsValue = USERS.containsValue(remove);
             LOGGER.info("\n 移出结果 - {}", containsValue ? "失败" : "成功");
             return containsValue;
-        }
-        else
-        {
+        } else {
             return true;
         }
     }
@@ -94,8 +84,7 @@ public class WebSocketUsers
      *
      * @return 返回用户集合
      */
-    public static Map<String, Session> getUsers()
-    {
+    public static Map<String, Session> getUsers() {
         return USERS;
     }
 
@@ -104,12 +93,11 @@ public class WebSocketUsers
      *
      * @param message 消息内容
      */
-    public static void sendMessageToUsersByText(String message)
-    {
+    public static void sendMessageToUsersByText(String message) {
         Collection<Session> values = USERS.values();
-        for (Session value : values)
-        {
+        for (Session value : values) {
             sendMessageToUserByText(value, message);
+            log.info("message:{}", message);
         }
     }
 
@@ -117,23 +105,16 @@ public class WebSocketUsers
      * 发送文本消息
      *
      * @param userName 自己的用户名
-     * @param message 消息内容
+     * @param message  消息内容
      */
-    public static void sendMessageToUserByText(Session session, String message)
-    {
-        if (session != null)
-        {
-            try
-            {
+    public static void sendMessageToUserByText(Session session, String message) {
+        if (session != null) {
+            try {
                 session.getBasicRemote().sendText(message);
-            }
-            catch (IOException e)
-            {
+            } catch (IOException e) {
                 LOGGER.error("\n[发送消息异常]", e);
             }
-        }
-        else
-        {
+        } else {
             LOGGER.info("\n[你已离线]");
         }
     }