新增任务测试执行方法

master
面包骑士 2024-09-05 15:06:58 +08:00
parent 5c00b49080
commit e9da4e7f99
6 changed files with 111 additions and 21 deletions

View File

@ -22,6 +22,7 @@ import java.util.List;
*/
@FeignClient(contextId = "RemoteDataSourceService",
value = ServiceNameConstants.SOURCE_SERVICE,
url = "http://10.0.2.1:19652/",
fallbackFactory = RemoteDataSourceFactory.class)
public interface RemoteDataSourceService {

View File

@ -110,11 +110,19 @@ public class TaskController extends BaseController
return success();
}
/**
*
*/
@PostMapping("/testExecute/{taskCode}")
public Result<String> testExecute(@PathVariable("taskCode") String taskCode) {
return success(taskService.testExecute(taskCode));
}
/**
*
*/
@PostMapping("/execute/{taskCode}")
public Result execute(@PathVariable("taskCode") String taskCode) {
public Result<String> execute(@PathVariable("taskCode") String taskCode) {
return success(taskService.execute(taskCode));
}

View File

@ -0,0 +1,21 @@
package com.muyu.quest.manager;
/**
* @Author:
* @Name: TaskManager
* @Description:
* @CreatedDate: 2024/9/4 7:44
* @FilePath: com.muyu.quest.manager
*/
/**
* @Author:
* @Name: TaskManager
* @Description:
* @CreatedDate: 2024/9/4 7:44
* @FilePath: com.muyu.quest.manager
*/
public class TaskManager {
}

View File

@ -45,4 +45,6 @@ public interface TaskService extends IService<Task> {
void removeBatch(List<Long> list);
String execute(String taskCode);
String testExecute(String taskCode);
}

View File

@ -152,36 +152,27 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>
List<Node> nodeListAll = nodeService.selectNodeList(new NodeReq().buildTaskCode(taskCode));
// 节点初始化
HashMap<String, List<Node>> nodeMap = NodeUtils.nodeInit(nodeListAll);
// 查询所有节点类型与其连接节点规范
List<NodeType> nodeTypeList = selectNodeTypeList();
/* 节点连接规范校验 */
NodeUtils.nodeCheck(nodeListAll,nodeTypeList);
NodeUtils.nodeCheck(nodeListAll,selectNodeTypeList());
// 开始节点处理
Node thisNode = nodeMap.get("start").get(0);
// 开始节点处理
while (true){
List<Node> nextNode = NodeUtils.getNextNode(thisNode, nodeListAll);
Set<String> nextNodeTypes = nextNode.stream().map(Node::getNodeType).collect(Collectors.toSet());
if (nextNode.isEmpty()){
throw new TaskException("任务执行失败,节点 "+thisNode+" 无后续节点");
}else if (nextNodeTypes.size()>1){
throw new TaskException("同级节点 "+nextNode+" 类型不同");
}else if (nextNode.stream().map(Node::getNodeNextCode).collect(Collectors.toSet()).size()>1){
throw new TaskException("同级节点 "+nextNode+" 下级节点不同");
}
thisNode = nextNode.get(0);
thisNode = NodeUtils.nodeCheck(thisNode, nodeListAll);
if (StringUtils.equals(thisNode.getNodeType(), "end")){
break;
}
// 查询当前节点所有配置信息
List<NodeDisposition> dispList = dispositionService
.selectNodeDispositionList(new NodeDisposition().buildNodeCode(thisNode.getNodeCode()));
if (dispList.isEmpty()){
throw new TaskException("节点 "+thisNode+" 配置为空");
}
// 根据情况拼接查询sql与新增sql
if(StringUtils.equals(thisNode.getNodeType(), "table")) {
// 如果表节点下一级为数据输出节点,即表示为单表查询,将 当前表结构处理为查询语句
Node newNode = NodeUtils.getNextNode(thisNode, nodeListAll).get(0);
if (StringUtils.equals(newNode.getNodeType(), "exportation")){
if (StringUtils.equals(NodeUtils.nodeCheck(thisNode, nodeListAll).getNodeType(), "exportation")){
findSql = NodeUtils.tableNode(dispList);
}
}else if (StringUtils.equals(thisNode.getNodeType(), "unite")){
@ -196,23 +187,72 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>
if (tableValue.getCode() != 200){
throw new TaskException(tableValue.getMsg());
}
System.out.println(tableValue);
List<DataModel> data = tableValue.getData();
System.out.println(data);
addSql = NodeUtils.nodeDispExportation(dispList, data);
}
}
log.info("任务执行完成,新增sql为: [{}]", addSql);
Result i = remoteDataSourceService.addTableValue(new DataValueModel(4L, addSql));
if (i.getCode() != 200){
throw new TaskException(i.getMsg());
Result resp = remoteDataSourceService.addTableValue(new DataValueModel(4L, addSql));
if (resp.getCode() != 200){
throw new TaskException(resp.getMsg());
}
return "执行成功";
}
@Override
public String testExecute(String taskCode) {
log.info("任务编码 {} 开始测试执行......",taskCode);
// 查询SQL语句
String findSql = "";
// 新增SQL语句
String addSql = "";
// 查询任务所有节点
List<Node> nodeListAll = nodeService.selectNodeList(new NodeReq().buildTaskCode(taskCode));
// 节点初始化
HashMap<String, List<Node>> nodeMap = NodeUtils.nodeInit(nodeListAll);
/* 节点连接规范校验 */
NodeUtils.nodeCheck(nodeListAll,selectNodeTypeList());
// 开始节点处理
Node thisNode = nodeMap.get("start").get(0);
// 开始节点处理
while (true){
thisNode = NodeUtils.nodeCheck(thisNode, nodeListAll);
if (StringUtils.equals(thisNode.getNodeType(), "end")){
break;
}
// 查询当前节点所有配置信息
List<NodeDisposition> dispList = dispositionService
.selectNodeDispositionList(new NodeDisposition().buildNodeCode(thisNode.getNodeCode()));
if (dispList.isEmpty()){
throw new TaskException("节点 "+thisNode+" 配置为空");
}
// 根据情况拼接查询sql与新增sql
if(StringUtils.equals(thisNode.getNodeType(), "table")) {
// 如果表节点下一级为数据输出节点,即表示为单表查询,将 当前表结构处理为查询语句
if (StringUtils.equals(NodeUtils.nodeCheck(thisNode, nodeListAll).getNodeType(), "exportation")){
findSql = NodeUtils.tableNode(dispList);
}
}else if (StringUtils.equals(thisNode.getNodeType(), "unite")){
findSql = NodeUtils.nodeDispUnite(dispList);
}else if (StringUtils.equals(thisNode.getNodeType(), "exportation")){
if (StringUtils.isEmpty(findSql)){
throw new TaskException("数据输出节点必须紧跟在数据输入/操作节点之后");
}
// 执行查询语句
log.info("任务执行查询阶段结束,查询sql为: [{}]", findSql);
Result<List<DataModel>> tableValue = remoteDataSourceService.findTableValue(new DataValueModel(4L, findSql));
if (tableValue.getCode() != 200){
throw new TaskException(tableValue.getMsg());
}
List<DataModel> data = tableValue.getData();
addSql = NodeUtils.nodeDispExportation(dispList, data);
}
}
return "执行成功,无异常";
}
}

View File

@ -132,6 +132,24 @@ public class NodeUtils {
});
}
/**
*
*/
public static Node nodeCheck(Node node, List<Node> nodes) {
List<Node> nextNode = NodeUtils.getNextNode(node, nodes);
Set<String> nextNodeTypes = nextNode.stream().map(Node::getNodeType).collect(Collectors.toSet());
if (nextNode.isEmpty()){
throw new TaskException("任务执行失败,节点 "+node+" 无后续节点");
}else if (nextNodeTypes.size()>1){
throw new TaskException("同级节点 "+nextNode+" 类型不同");
}else if (nextNode.stream().map(Node::getNodeNextCode).collect(Collectors.toSet()).size()>1){
throw new TaskException("同级节点 "+nextNode+" 下级节点不同");
}
return nextNode.get(0);
}
/**
*
* @param dispList