Kaynağa Gözat

伊宁版本更新:
a.新增sse服务器代码逻辑:全局以会话id为key存储各自会话的通讯链接,心跳包以及登出指令都以当前会话id为基础单位发送指令
b.修改伊宁mainView首页,增加跳转参数clientId用以sse通讯
c.新增sse请求地址获取接口
d.增加weblog前端日志接口

1037015548@qq.com 1 gün önce
ebeveyn
işleme
e074566bf3

+ 14 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SseServlet.java

@@ -36,6 +36,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.*;
 import java.nio.charset.Charset;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.Timer;
 import java.util.TimerTask;
 import java.util.concurrent.ConcurrentHashMap;
@@ -136,6 +137,19 @@ public class SseServlet extends BaseController {
         log.info("建立链接成功:clientId:"+clientId);
     }
 
+    @PostMapping("/sse/weblog")
+    @ResponseBody
+    @CrossOrigin(origins = "*") // 允许所有来源
+    protected void doGetLog(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+        response.setContentType("text/event-stream");
+        response.setCharacterEncoding("UTF-8");
+        response.setHeader("Cache-Control", "no-cache");
+        response.setHeader("Connection", "keep-alive");
+
+        String body = getJsonBodyStr(request);
+        log.info(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))+":"+body);
+    }
+
     @PostMapping("/sse/logout")
     @ResponseBody
     protected AjaxResult logout(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

+ 1 - 1
ruoyi-admin/src/main/resources/static/ruoyi/index.js

@@ -27,7 +27,7 @@ function resetTimer() {
 function logoutUser() {
     // 调用后端接口退出会话
     ifExit = true;
-    quitSystem();
+    // quitSystem();
     window.open("/logout",'_self');
     alert("登录过期");
     // layer.open({

+ 1 - 0
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ShiroConfig.java

@@ -310,6 +310,7 @@ public class ShiroConfig
         filterChainDefinitionMap.put("/loginApp", "anon,captchaValidate");
         filterChainDefinitionMap.put("/upApp", "anon,captchaValidate");
         filterChainDefinitionMap.put("/sse/subscribe", "anon,captchaValidate");
+        filterChainDefinitionMap.put("/sse/weblog", "anon,captchaValidate");
 //        filterChainDefinitionMap.put("/sse/logout", "anon,captchaValidate");
         filterChainDefinitionMap.put("/sse/geturl", "anon,captchaValidate");
         // 注册相关