From 64b723009b176979a0c6d417b4d8cb76923f104d Mon Sep 17 00:00:00 2001 From: hanyuqing <1106611654@qq.com> Date: Sun, 31 Aug 2025 23:57:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-api/src/main/java/com/ruoyi/api/Websocket.java | 16 +++++----------- .../java/com/ruoyi/api/controller/DocApiController.java | 8 +++++--- .../com/ruoyi/system/service/impl/PythonService.java | 10 ++++++++++ 3 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PythonService.java diff --git a/ruoyi-api/src/main/java/com/ruoyi/api/Websocket.java b/ruoyi-api/src/main/java/com/ruoyi/api/Websocket.java index c249e6d..b4df415 100644 --- a/ruoyi-api/src/main/java/com/ruoyi/api/Websocket.java +++ b/ruoyi-api/src/main/java/com/ruoyi/api/Websocket.java @@ -4,6 +4,7 @@ package com.ruoyi.api; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.ruoyi.api.service.impl.BuildService; +import com.ruoyi.system.service.impl.PythonService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.socket.TextMessage; @@ -22,10 +23,13 @@ import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; import java.util.stream.Collectors; + @Component @Slf4j public class Websocket { @Autowired + static PythonService pythonService; + @Autowired public BuildService buildService; private static BuildService staticBuildService; // 静态引用 private static volatile WebSocketSession session; @@ -69,17 +73,7 @@ public class Websocket { @Override protected void handleTextMessage(WebSocketSession s, TextMessage message) throws Exception { log.info("📩 收到消息: {}", message.getPayload()); - String payload = message.getPayload(); - ObjectMapper mapper = new ObjectMapper(); - Map map = mapper.readValue(payload, new TypeReference>() {}); - if(map.get("code").equals("500")){ - System.out.println(map.get("message")); - } - if(map.get("code").equals("200")){ - if (map.get("function_name").equals("build")){ - staticBuildService.create(map); - } - } + pythonService.flag=false; } diff --git a/ruoyi-api/src/main/java/com/ruoyi/api/controller/DocApiController.java b/ruoyi-api/src/main/java/com/ruoyi/api/controller/DocApiController.java index 8270ded..d4833d6 100644 --- a/ruoyi-api/src/main/java/com/ruoyi/api/controller/DocApiController.java +++ b/ruoyi-api/src/main/java/com/ruoyi/api/controller/DocApiController.java @@ -20,6 +20,7 @@ import com.ruoyi.system.domain.ZhyDoc; import com.ruoyi.system.domain.ZhyUserselfDifficult; import com.ruoyi.system.mapper.Test1Mapper; import com.ruoyi.system.service.impl.LuceneUtil; +import com.ruoyi.system.service.impl.PythonService; import com.ruoyi.system.service.impl.WordSplitter; import org.apache.commons.text.similarity.CosineSimilarity; import org.springframework.beans.factory.annotation.Autowired; @@ -42,9 +43,8 @@ import com.ruoyi.api.util.PythonApiClient; @RequestMapping("/api/doc") public class DocApiController extends BaseController { - static boolean flag=false; - - static String url=""; + @Autowired + static PythonService pythonService; @Autowired LuceneUtil luceneUtil; @@ -1362,7 +1362,9 @@ public class DocApiController extends BaseController { map.put("keywords",keywords); map.put("searchItems",group0SearchItems); sendPython(map); + while (pythonService.flag){ + } } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PythonService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PythonService.java new file mode 100644 index 0000000..87c97c0 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PythonService.java @@ -0,0 +1,10 @@ +package com.ruoyi.system.service.impl; + +import org.springframework.stereotype.Service; + +@Service +public class PythonService { + public static boolean flag=false; + + public static String pythonMessage=""; +}