Browse Source

脚本任务

zxm
hanyuqing 7 months ago
parent
commit
b8136b84d9
  1. 12
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ZhyTaskController.java
  2. 59
      ruoyi-api/src/main/java/com/ruoyi/api/controller/DocApiController.java
  3. 2
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/ZhyTaskMapper.java
  4. 4
      ruoyi-system/src/main/resources/mapper/system/ZhyTaskMapper.xml
  5. 6
      ruoyi-ui/src/api/system/task.js
  6. 42
      ruoyi-ui/src/views/system/create/index.vue

12
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ZhyTaskController.java

@ -7,6 +7,8 @@ import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ZhyTask;
import com.ruoyi.system.mapper.ZhyArticleMapper;
import com.ruoyi.system.mapper.ZhyTaskMapper;
import com.ruoyi.system.service.IZhyTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
@ -27,6 +29,8 @@ public class ZhyTaskController extends BaseController
{
@Autowired
private IZhyTaskService zhyTaskService;
@Autowired
private ZhyTaskMapper zhyTaskMapper;
/**
* 查询任务列表
@ -63,6 +67,14 @@ public class ZhyTaskController extends BaseController
return success(zhyTaskService.selectZhyTaskById(id));
}
@PreAuthorize("@ss.hasPermi('system:task:query')")
@GetMapping( "/getIsTask")
public int getIsTask()
{
int num=zhyTaskMapper.selectZhyTaskListByStatus().size();
return num;
}
/**
* 新增任务
*/

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

@ -1261,7 +1261,11 @@ public class DocApiController extends BaseController {
List<ZhyTaskInfo> taskInfos=zhyTaskInfoMapper.selectZhyTaskInfoByTaskId(task.getId());
for(int i=0;i<taskInfos.size();i++){
ZhyTaskInfo info=taskInfos.get(i);
webSocketService.sendToUser("123","正在抓取‘"+info.getName1()+"数据");
Map map1=new HashMap();
map1.put("type","message");
map1.put("msg","正在抓取'"+info.getName1()+"'数据");
webSocketService.sendToUser("123",gson.toJson(map1));
goPython(info,searchItems);
}
task.setStatus(1);
@ -1329,11 +1333,11 @@ public class DocApiController extends BaseController {
@GetMapping("/proceed/{taskId}")
public void proceed(HttpServletRequest request,@PathVariable("taskId")Long taskId) throws JsonProcessingException, InterruptedException {
Gson gson = new Gson();
ZhyTask task=zhyTaskService.selectZhyTaskById(taskId);
System.out.println("111111111111111");
if(!task.getUserCommand().equals("")){
if(task.getType()==0){
Gson gson = new Gson();
Type typeData = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> data = gson.fromJson(task.getUserCommand(), typeData);
// 存储结果:group -> type -> List<Long>(ID 列表)
@ -1400,7 +1404,10 @@ public class DocApiController extends BaseController {
List<ZhyTaskInfo> taskInfos1=zhyTaskInfoMapper.selectZhyTaskInfoByTaskIdAndStatus(taskId,0);
for(int i=0;i<taskInfos.size();i++){
ZhyTaskInfo info=taskInfos.get(i);
webSocketService.sendToUser("123","正在抓取‘"+info.getName1()+"-"+info.getName2()+"’数据");
Map map1=new HashMap();
map1.put("type","message");
map1.put("msg","正在抓取'"+info.getName1()+"-"+info.getName2()+"'数据");
webSocketService.sendToUser("123",gson.toJson(map1));
if(info.getGroupId()==0l){
goPython(info,group0SearchItems);
}
@ -1414,7 +1421,10 @@ public class DocApiController extends BaseController {
}
for(int i=0;i<taskInfos1.size();i++){
ZhyTaskInfo info=taskInfos1.get(i);
webSocketService.sendToUser("123","正在抓取‘"+info.getName1()+"-"+info.getName2()+"’数据");
Map map1=new HashMap();
map1.put("type","message");
map1.put("msg","正在抓取'"+info.getName1()+"-"+info.getName2()+"'数据");
webSocketService.sendToUser("123",gson.toJson(map1));
if(info.getGroupId()==0l){
goPython(info,group0SearchItems);
}
@ -1427,7 +1437,6 @@ public class DocApiController extends BaseController {
}
}else if(task.getType()==1){
Gson gson = new Gson();
Type typeData = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> data = gson.fromJson(task.getUserCommand(), typeData);
List<Map<String, Object>> searchItems = new ArrayList<>();
@ -1442,17 +1451,27 @@ public class DocApiController extends BaseController {
List<ZhyTaskInfo> taskInfos1=zhyTaskInfoMapper.selectZhyTaskInfoByTaskIdAndStatus(taskId,0);
for(int i=0;i<taskInfos.size();i++){
ZhyTaskInfo info=taskInfos.get(i);
webSocketService.sendToUser("123","正在抓取‘"+info.getName1()+"数据");
Map map1=new HashMap();
map1.put("type","message");
map1.put("msg","正在抓取'"+info.getName1()+"'数据");
webSocketService.sendToUser("123",gson.toJson(map1));
goPython(info,searchItems);
}
for(int i=0;i<taskInfos1.size();i++){
ZhyTaskInfo info=taskInfos1.get(i);
webSocketService.sendToUser("123","正在抓取‘"+info.getName1()+"数据");
Map map1=new HashMap();
map1.put("type","message");
map1.put("msg","正在抓取'"+info.getName1()+"'数据");
webSocketService.sendToUser("123",gson.toJson(map1));
goPython(info,searchItems);
}
}
task.setStatus(1);
zhyTaskService.updateZhyTask(task);
Map map1=new HashMap();
map1.put("type","message");
map1.put("msg","构建完成");
webSocketService.sendToUser("123",gson.toJson(map1));
}
}
@ -1731,9 +1750,15 @@ public class DocApiController extends BaseController {
for(int i=0;i<taskInfos.size();i++){
ZhyTaskInfo info=taskInfos.get(i);
if(info.getName2()!=null){
webSocketService.sendToUser("123","正在抓取‘"+info.getName1()+"-"+info.getName2()+"’数据");
Map map1=new HashMap();
map1.put("type","message");
map1.put("msg","正在抓取'"+info.getName1()+"-"+info.getName2()+"'数据");
webSocketService.sendToUser("123",gson.toJson(map1));
}else{
webSocketService.sendToUser("123","正在抓取‘"+info.getName1()+"数据");
Map map1=new HashMap();
map1.put("type","message");
map1.put("msg","正在抓取'"+info.getName1()+"'数据");
webSocketService.sendToUser("123",gson.toJson(map1));
}
if(info.getGroupId()==0l){
goPython(info,group0SearchItems);
@ -1748,6 +1773,10 @@ public class DocApiController extends BaseController {
}
task.setStatus(1);
zhyTaskService.updateZhyTask(task);
Map map1=new HashMap();
map1.put("type","message");
map1.put("msg","构建完成");
webSocketService.sendToUser("123",gson.toJson(map1));
//构建定时图谱
//定时去跑这个脚本
//获取所有的节点信息,包括名称、group分组
@ -1806,7 +1835,7 @@ public void goPython(ZhyTaskInfo info, List<Map<String, Object>> searchItems)
}
int maxRetries = 3; // 最大重试次数,避免无限重试
int retryCount = 0;
Gson gson = new Gson();
while (retryCount <= maxRetries) {
try {
// 构建请求数据
@ -1855,9 +1884,15 @@ public void goPython(ZhyTaskInfo info, List<Map<String, Object>> searchItems)
if ("build".equals(functionName)) {
System.out.println("执行 build 逻辑...");
if(info.getName2()!=null){
webSocketService.sendToUser("123","正在构建‘"+info.getName1()+"-"+info.getName2()+"’图谱");
Map map1=new HashMap();
map1.put("type","message");
map1.put("msg","正在构建'"+info.getName1()+"-"+info.getName2()+"'图谱");
webSocketService.sendToUser("123",gson.toJson(map1));
}else{
webSocketService.sendToUser("123","正在构建‘"+info.getName1()+"图谱");
Map map1=new HashMap();
map1.put("type","message");
map1.put("msg","正在构建'"+info.getName1()+"'图谱");
webSocketService.sendToUser("123",gson.toJson(map1));
}
staticBuildService.create(objMap);

2
ruoyi-system/src/main/java/com/ruoyi/system/mapper/ZhyTaskMapper.java

@ -27,6 +27,8 @@ public interface ZhyTaskMapper
*/
public List<ZhyTask> selectZhyTaskList(ZhyTask zhyTask);
public List<ZhyTask> selectZhyTaskListByStatus();
/**
* 新增任务
*

4
ruoyi-system/src/main/resources/mapper/system/ZhyTaskMapper.xml

@ -29,6 +29,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectZhyTaskVo"/>
where id = #{id}
</select>
<select id="selectZhyTaskListByStatus" resultMap="ZhyTaskResult">
<include refid="selectZhyTaskVo"/>
where status=0
</select>
<insert id="insertZhyTask" parameterType="ZhyTask" useGeneratedKeys="true" keyProperty="id">
insert into zhy_task

6
ruoyi-ui/src/api/system/task.js

@ -16,6 +16,12 @@ export function getTask(id) {
method: 'get'
})
}
export function getIsTask() {
return request({
url: '/system/task/getIsTask',
method: 'get'
})
}
// 新增任务
export function addTask(data) {

42
ruoyi-ui/src/views/system/create/index.vue

@ -1,5 +1,8 @@
<template>
<div class="rightInfo" >
<div class="rightInfo" v-loading="loading"
:element-loading-text="taskInfoTip.msg"
element-loading-spinner="el-icon-loading"
element-loading-background="rgba(0, 0, 0, 0.8)">
<el-menu
:default-active="activeIndex"
class="menu-container"
@ -224,7 +227,7 @@
:visible.sync="dialogVisible"
width="30%"
:before-close="handleClose">
<span>{{messages}}</span>
<span>{{taskInfoTip}}</span>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false"> </el-button>
<el-button type="primary" @click="dialogVisible = false"> </el-button>
@ -236,6 +239,7 @@
import {buildSmall, buildTwo, getTitle, getTitleByGroup, getTitleBySamll} from "../../../api/doc";
import {getIsTask} from "../../../api/system/task";
export default {
data() {
@ -311,6 +315,9 @@ export default {
messages:[],
input:[],
activeIndex:"1",
taskNum:0,
taskInfoTip:"",
loading: false
};
},
@ -445,7 +452,7 @@ export default {
//
// })
// },
build(){
async build(){
let data={
group0:{
selected:this.selected1,
@ -460,9 +467,18 @@ export default {
searchItems:this.searchItems3
},
}
buildTwo(data).then(res=>{
await getIsTask().then(async res=>{
this.taskNum=res;
if(this.taskNum>0){
this.$message.error('上次构建还未完成');
}else{
await buildTwo(data).then(res=>{
this.dialogVisible=true
})
}
})
},
build1(){
let data={
@ -589,6 +605,12 @@ export default {
console.log(key)
console.log("111111111111111111")
console.log(this.activeIndex)
},
getIsTask(){
getIsTask().then(res=>{
this.taskNum=res;
})
}
},
mounted() {
@ -605,6 +627,18 @@ export default {
//
this.socket.addEventListener('message', (event) => {
console.log('收到消息:', event.data);
// this.dialogVisible=true
this.taskInfoTip=JSON.parse(event.data);
// const loading = this.$loading({
// lock: true,
// text: this.taskInfoTip,
// spinner: 'el-icon-loading',
// background: 'rgba(0, 0, 0, 0.7)'
// });
if(this.taskInfoTip.type=="message"){
this.loading=true
}
console.log(this.taskInfoTip.type)
this.messages.push(event.data);
});

Loading…
Cancel
Save