Browse Source

自动脚本

zxm
hanyuqing 7 months ago
parent
commit
e60ca772fd
  1. 2
      ruoyi-api/src/main/java/com/ruoyi/api/Websocket.java
  2. 119
      ruoyi-api/src/main/java/com/ruoyi/api/controller/DocApiController.java
  3. 15
      ruoyi-api/src/main/java/com/ruoyi/api/service/impl/BuildService.java
  4. 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PythonService.java

2
ruoyi-api/src/main/java/com/ruoyi/api/Websocket.java

@ -74,7 +74,7 @@ public class Websocket {
protected void handleTextMessage(WebSocketSession s, TextMessage message) throws Exception {
log.info("📩 收到消息: {}", message.getPayload());
pythonService.flag=false;
pythonService.pythonMessage=message.getPayload();
}

119
ruoyi-api/src/main/java/com/ruoyi/api/controller/DocApiController.java

@ -2,6 +2,7 @@ package com.ruoyi.api.controller;
import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.ruoyi.api.Websocket;
@ -39,10 +40,12 @@ import java.util.stream.Collectors;
import com.ruoyi.api.util.PythonApiClient;
@RestController
@RequestMapping("/api/doc")
public class DocApiController extends BaseController {
@Autowired
BuildService staticBuildService;
@Autowired
static PythonService pythonService;
@Autowired
@ -1241,7 +1244,7 @@ public class DocApiController extends BaseController {
}
@PostMapping("/buildTwo")
public void buildTwo(HttpServletRequest request,@RequestBody Map<String, Object> data) {
public void buildTwo(HttpServletRequest request,@RequestBody Map<String, Object> data) throws JsonProcessingException {
System.out.println(data);
// 存储结果:group -> type -> List<Long>(ID 列表)
@ -1330,6 +1333,7 @@ public class DocApiController extends BaseController {
List<Map<String, Object>> group2SearchItems = searchItemsMap.get("group2");
// 直接获取,即使 key 不存在也不会报错
//获取第一组的数据节点
//group0
List<Long> group0_type1 = getIdsByGroupAndType(groupedResult, "group0", 1);
List<Long> group0_type2 = getIdsByGroupAndType(groupedResult, "group0", 2);
List<Long> group0_type3 = getIdsByGroupAndType(groupedResult, "group0", 3);
@ -1357,29 +1361,78 @@ public class DocApiController extends BaseController {
ZhyDoc doc2=g02.get(j);
//websocket python
//websocket vue
String[] keywords = new String[]{doc1.getDocTitle(), doc2.getDocTitle()};
Map map =new HashMap();
map.put("keywords",keywords);
map.put("searchItems",group0SearchItems);
sendPython(map);
while (pythonService.flag){
goPython(doc1.getDocTitle(),doc2.getDocTitle(),group0SearchItems);
}
}
for(int i=0;i<g02.size();i++){
ZhyDoc doc1=g02.get(i);
for(int j=0;j<g03.size();j++){
ZhyDoc doc2=g03.get(j);
//websocket python
//websocket vue
goPython(doc1.getDocTitle(),doc2.getDocTitle(),group0SearchItems);
}
}
for(int i=0;i<g03.size();i++){
ZhyDoc doc1=g03.get(i);
for(int j=0;j<g04.size();j++){
ZhyDoc doc2=g04.get(j);
//websocket python
//websocket vue
goPython(doc1.getDocTitle(),doc2.getDocTitle(),group0SearchItems);
}
}
//group1
List<Long> group1_type1 = getIdsByGroupAndType(groupedResult, "group1", 1);
List<Long> group2_type1 = getIdsByGroupAndType(groupedResult, "group2", 1);
System.out.println("group0_type1 = " + group0_type1); // [79804]
System.out.println("group1_type1 = " + group1_type1); // [79824]
System.out.println("group2_type1 = " + group2_type1); // [79812]
List<Long> group1_type2 = getIdsByGroupAndType(groupedResult, "group1", 2);
List<Long> group1_type3 = getIdsByGroupAndType(groupedResult, "group1", 3);
List<Long> group1_type4 = getIdsByGroupAndType(groupedResult, "group1", 4);
List<ZhyDoc> g11=new ArrayList<>();
List<ZhyDoc> g12=new ArrayList<>();
List<ZhyDoc> g13=new ArrayList<>();
List<ZhyDoc> g14=new ArrayList<>();
if(group1_type1.size()>0){
g11=test1Mapper.selectDocByIds(group1_type1);
}
if(group1_type2.size()>0){
g12=test1Mapper.selectDocByIds(group1_type2);
}
if(group1_type3.size()>0){
g13=test1Mapper.selectDocByIds(group1_type3);
}
if(group1_type4.size()>0){
g14=test1Mapper.selectDocByIds(group1_type4);
}
for(int i=0;i<g11.size();i++){
ZhyDoc doc1=g11.get(i);
for(int j=0;j<g12.size();j++){
ZhyDoc doc2=g12.get(j);
//websocket python
//websocket vue
goPython(doc1.getDocTitle(),doc2.getDocTitle(),group1SearchItems);
}
}
for(int i=0;i<g12.size();i++){
ZhyDoc doc1=g12.get(i);
for(int j=0;j<g13.size();j++){
ZhyDoc doc2=g13.get(j);
//websocket python
//websocket vue
goPython(doc1.getDocTitle(),doc2.getDocTitle(),group1SearchItems);
}
}
for(int i=0;i<g13.size();i++){
ZhyDoc doc1=g13.get(i);
for(int j=0;j<g14.size();j++){
ZhyDoc doc2=g14.get(j);
//websocket python
//websocket vue
goPython(doc1.getDocTitle(),doc2.getDocTitle(),group1SearchItems);
}
}
System.out.println(group0SearchItems+"0");
System.out.println(group1SearchItems+"1");
System.out.println(group2SearchItems+"2");
//构建定时图谱
//定时去跑这个脚本
//获取所有的节点信息,包括名称、group分组
@ -1397,6 +1450,36 @@ public class DocApiController extends BaseController {
//如果中途嘎了java等待,然后20分钟去访问mysql时间最后一条数据
}
public void goPython(String title1,String title2,List<Map<String, Object>> searchItems) throws JsonProcessingException {
String[] keywords = new String[]{title1, title2};
Map map =new HashMap();
map.put("keywords",keywords);
map.put("searchItems",searchItems);
sendPython(map);
while (pythonService.flag){
}
pythonService.flag=false;
System.out.println("22222222222222222222");
System.out.println(pythonService.pythonMessage);
String payload=pythonService.pythonMessage;
ObjectMapper mapper=new ObjectMapper();
Map<String,String> objMap =mapper.readValue(payload, new TypeReference<Map<String, String>>() {});
if(objMap.get("code").equals("500")){
System.out.println(objMap.get("message"));
}
if(objMap.get("code").equals("200")){
if (objMap.get("function_name").equals("build")){
System.out.println("1111111111111");
System.out.println(objMap);
staticBuildService.create(objMap);
}
if (objMap.get("function_name").equals("none")){
// staticBuildService.create(objMap);
System.out.println("没有数据");
}
}
}
public List<Long> getIdsByGroupAndType(
Map<String, Map<Object, List<Long>>> result,

15
ruoyi-api/src/main/java/com/ruoyi/api/service/impl/BuildService.java

@ -277,21 +277,6 @@ public class BuildService {
return result.toArray(new String[0]);
}
public static void main(String[] args) {
// 已知的本地根目录
String basePath = "D:\\project\\gyx\\tupudata\\results";
// 假设这是从 CSV 读取的论文标题
String title = "基于深度学习的图像识别";
// 生成文件名:01_标题.txt(你可以根据序号动态生成)
String filename = "01_" + title + ".txt";
// 拼接完整路径
File file = new File(basePath, filename);
System.out.println("文件路径: " + file.getAbsolutePath());
}
}

2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PythonService.java

@ -4,7 +4,7 @@ import org.springframework.stereotype.Service;
@Service
public class PythonService {
public static boolean flag=false;
public static boolean flag=true;
public static String pythonMessage="";
}

Loading…
Cancel
Save