fix: 节点执行日志
This commit is contained in:
parent
5ab48c7048
commit
f7fccb4c95
@ -2,6 +2,7 @@ package com.cmvr.web.controller.test;
|
|||||||
|
|
||||||
import com.cmvr.common.core.controller.BaseController;
|
import com.cmvr.common.core.controller.BaseController;
|
||||||
import com.cmvr.common.core.page.TableDataInfo;
|
import com.cmvr.common.core.page.TableDataInfo;
|
||||||
|
import com.cmvr.test.model.domain.TeNodeInst;
|
||||||
import com.cmvr.test.model.vo.TeQueryTaskInstVO;
|
import com.cmvr.test.model.vo.TeQueryTaskInstVO;
|
||||||
import com.cmvr.test.model.vo.TeTaskInstVO;
|
import com.cmvr.test.model.vo.TeTaskInstVO;
|
||||||
import com.cmvr.test.service.ITeTaskInstService;
|
import com.cmvr.test.service.ITeTaskInstService;
|
||||||
@ -11,6 +12,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -32,4 +34,12 @@ public class TeTaskInstController extends BaseController {
|
|||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("查询节点执行日志")
|
||||||
|
@GetMapping("/detail")
|
||||||
|
public TableDataInfo detail(@RequestParam String instId) {
|
||||||
|
startPage();
|
||||||
|
List<TeNodeInst> list = teTaskInstService.detail(instId);
|
||||||
|
return getDataTable(list);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -2,6 +2,7 @@ package com.cmvr.test.service;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.cmvr.test.enums.TaskStatusEnum;
|
import com.cmvr.test.enums.TaskStatusEnum;
|
||||||
|
import com.cmvr.test.model.domain.TeNodeInst;
|
||||||
import com.cmvr.test.model.domain.TeTaskInst;
|
import com.cmvr.test.model.domain.TeTaskInst;
|
||||||
import com.cmvr.test.model.vo.TeQueryTaskInstVO;
|
import com.cmvr.test.model.vo.TeQueryTaskInstVO;
|
||||||
import com.cmvr.test.model.vo.TeTaskInstVO;
|
import com.cmvr.test.model.vo.TeTaskInstVO;
|
||||||
@ -26,24 +27,6 @@ public interface ITeTaskInstService extends IService<TeTaskInst> {
|
|||||||
*/
|
*/
|
||||||
public boolean updateStatus(String instId, TaskStatusEnum taskStatusEnum);
|
public boolean updateStatus(String instId, TaskStatusEnum taskStatusEnum);
|
||||||
|
|
||||||
/* *//**
|
List<TeNodeInst> detail(String instId);
|
||||||
* 暂停任务
|
|
||||||
*//*
|
|
||||||
public void pauseTask(String instId);
|
|
||||||
|
|
||||||
*//**
|
|
||||||
* 终止任务
|
|
||||||
*//*
|
|
||||||
public void stopTask(String instId);
|
|
||||||
|
|
||||||
*//**
|
|
||||||
* 继续任务
|
|
||||||
*//*
|
|
||||||
public void resumeTask(String instId);
|
|
||||||
|
|
||||||
*//**
|
|
||||||
* 获取任务上下文信息
|
|
||||||
*//*
|
|
||||||
public TaskContext getTaskContext(String instId);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,19 @@
|
|||||||
package com.cmvr.test.service.impl;
|
package com.cmvr.test.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.cmvr.common.utils.StringUtils;
|
import com.cmvr.common.utils.StringUtils;
|
||||||
import com.cmvr.test.enums.RunModeEnum;
|
import com.cmvr.test.enums.RunModeEnum;
|
||||||
import com.cmvr.test.enums.TaskStatusEnum;
|
import com.cmvr.test.enums.TaskStatusEnum;
|
||||||
import com.cmvr.test.mapper.TeTaskInstMapper;
|
import com.cmvr.test.mapper.TeTaskInstMapper;
|
||||||
|
import com.cmvr.test.model.domain.TeNodeInst;
|
||||||
import com.cmvr.test.model.domain.TeTaskConfigInfo;
|
import com.cmvr.test.model.domain.TeTaskConfigInfo;
|
||||||
import com.cmvr.test.model.domain.TeTaskInst;
|
import com.cmvr.test.model.domain.TeTaskInst;
|
||||||
import com.cmvr.test.model.vo.TeQueryTaskInstVO;
|
import com.cmvr.test.model.vo.TeQueryTaskInstVO;
|
||||||
import com.cmvr.test.model.vo.TeTaskInstVO;
|
import com.cmvr.test.model.vo.TeTaskInstVO;
|
||||||
|
import com.cmvr.test.service.ITeNodeInstService;
|
||||||
import com.cmvr.test.service.ITeTaskInstService;
|
import com.cmvr.test.service.ITeTaskInstService;
|
||||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -28,6 +32,8 @@ import java.util.List;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class TeTaskInstServiceImpl extends ServiceImpl<TeTaskInstMapper, TeTaskInst> implements ITeTaskInstService {
|
public class TeTaskInstServiceImpl extends ServiceImpl<TeTaskInstMapper, TeTaskInst> implements ITeTaskInstService {
|
||||||
|
|
||||||
|
private final ITeNodeInstService teNodeInstService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询任务实例列表
|
* 查询任务实例列表
|
||||||
*/
|
*/
|
||||||
@ -50,103 +56,6 @@ public class TeTaskInstServiceImpl extends ServiceImpl<TeTaskInstMapper, TeTaskI
|
|||||||
return this.baseMapper.selectJoinList(TeTaskInstVO.class, queryWrapper);
|
return this.baseMapper.selectJoinList(TeTaskInstVO.class, queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@Override
|
|
||||||
public void pauseTask(String instId) {
|
|
||||||
// todo 调用 edge 暂停接口
|
|
||||||
|
|
||||||
TaskContext ctx = taskInstHolder.getContext(instId);
|
|
||||||
if (ctx == null || ctx.isStopped()) {
|
|
||||||
throw new GlobalException("任务不存在或已终止,无法暂停");
|
|
||||||
}
|
|
||||||
if (ctx.isPaused()) {
|
|
||||||
throw new GlobalException("任务已处于暂停状态");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<FlowNodePath> nodePaths = ctx.getActiveNodeInfo();
|
|
||||||
if (CollUtil.isEmpty(nodePaths)) {
|
|
||||||
throw new GlobalException("当前任务节点路径信息缺失,无法暂停");
|
|
||||||
}
|
|
||||||
|
|
||||||
FlowNodePath flowNodePath = nodePaths.get(0);
|
|
||||||
|
|
||||||
// 调用 Node-RED 停止当前流程
|
|
||||||
String stopUrl = StrUtil.format(nodeRedProperties.getStopProcess(), flowNodePath.getCurrentNodeId());
|
|
||||||
CallAPIUtil.doPostJson(stopUrl, null, null);
|
|
||||||
|
|
||||||
// 统一记录日志 + 设置上下文状态 + 数据库状态
|
|
||||||
taskInstHolder.markPaused(instId, ctx.getTaskId(), ctx.getItemId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stopTask(String instId) {
|
|
||||||
// todo调用edge
|
|
||||||
|
|
||||||
TaskContext ctx = taskInstHolder.getContext(instId);
|
|
||||||
if (ctx == null) {
|
|
||||||
throw new GlobalException("任务不存在");
|
|
||||||
}
|
|
||||||
if (ctx.isStopped()) {
|
|
||||||
throw new GlobalException("任务已终止,无需重复操作");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<FlowNodePath> nodePaths = ctx.getActiveNodeInfo();
|
|
||||||
if (CollUtil.isEmpty(nodePaths)) {
|
|
||||||
throw new GlobalException("当前任务节点路径信息缺失,无法终止");
|
|
||||||
}
|
|
||||||
|
|
||||||
FlowNodePath flowNodePath = nodePaths.get(0);
|
|
||||||
|
|
||||||
// 调用 Node-RED 停止当前流程
|
|
||||||
String stopUrl = StrUtil.format(nodeRedProperties.getStopProcess(), flowNodePath.getCurrentNodeId());
|
|
||||||
CallAPIUtil.doPostJson(stopUrl, null, null);
|
|
||||||
|
|
||||||
// 统一记录日志 + 设置上下文状态 + 数据库状态
|
|
||||||
taskInstHolder.markStopped(instId, ctx.getTaskId(), ctx.getItemId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resumeTask(String instId) {
|
|
||||||
TaskContext ctx = taskInstHolder.getContext(instId);
|
|
||||||
if (ctx == null) {
|
|
||||||
throw new GlobalException("任务不存在");
|
|
||||||
}
|
|
||||||
if (!ctx.isPaused()) {
|
|
||||||
throw new GlobalException("当前任务未处于暂停状态,无法继续运行");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<FlowNodePath> nodePaths = ctx.getActiveNodeInfo();
|
|
||||||
if (CollUtil.isEmpty(nodePaths)) {
|
|
||||||
throw new GlobalException("当前任务节点路径信息缺失,无法暂停");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 先处理统一状态
|
|
||||||
// 统一记录日志 + 设置上下文状态 + 数据库状态
|
|
||||||
taskInstHolder.markResumed(instId, ctx.getTaskId(), ctx.getItemId());
|
|
||||||
|
|
||||||
// 循环调用 Node-RED 的 resume 接口
|
|
||||||
for (FlowNodePath nodePath : nodePaths) {
|
|
||||||
String resumeUrl = StrUtil.format(nodeRedProperties.getStartProcess(), nodePath.getCurrentNodeId());
|
|
||||||
TeTaskRunMessageVO msg = new TeTaskRunMessageVO();
|
|
||||||
msg.setInstId(instId);
|
|
||||||
msg.setTaskId(ctx.getTaskId());
|
|
||||||
msg.setItemId(ctx.getItemId());
|
|
||||||
msg.setTerminalId(ctx.getTerminalId());
|
|
||||||
msg.setNodeId(nodePath.getCurrentNodeId());
|
|
||||||
msg.setNodeType(nodePath.getCurrentNodeType());
|
|
||||||
msg.setParams(JSONObject.parseObject(nodePath.getCurrentParams()));
|
|
||||||
msg.setStatus(TaskStatusEnum.RUNNING.name());
|
|
||||||
CallAPIUtil.doPostJson(resumeUrl, null, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TaskContext getTaskContext(String instId) {
|
|
||||||
return taskInstHolder.getContext(instId);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateStatus(String instId, TaskStatusEnum taskStatusEnum) {
|
public boolean updateStatus(String instId, TaskStatusEnum taskStatusEnum) {
|
||||||
return this.update(
|
return this.update(
|
||||||
@ -155,4 +64,12 @@ public class TeTaskInstServiceImpl extends ServiceImpl<TeTaskInstMapper, TeTaskI
|
|||||||
.set(TeTaskInst::getStatus, taskStatusEnum.getCode())
|
.set(TeTaskInst::getStatus, taskStatusEnum.getCode())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TeNodeInst> detail(String instId) {
|
||||||
|
LambdaQueryWrapper<TeNodeInst> wrapper = Wrappers.lambdaQuery(TeNodeInst.class);
|
||||||
|
wrapper.eq(TeNodeInst::getInstId, instId)
|
||||||
|
.orderByAsc(TeNodeInst::getId);
|
||||||
|
return teNodeInstService.list(wrapper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user