新增任务测试执行方法
parent
5c00b49080
commit
e9da4e7f99
|
@ -22,6 +22,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@FeignClient(contextId = "RemoteDataSourceService",
|
@FeignClient(contextId = "RemoteDataSourceService",
|
||||||
value = ServiceNameConstants.SOURCE_SERVICE,
|
value = ServiceNameConstants.SOURCE_SERVICE,
|
||||||
|
url = "http://10.0.2.1:19652/",
|
||||||
fallbackFactory = RemoteDataSourceFactory.class)
|
fallbackFactory = RemoteDataSourceFactory.class)
|
||||||
public interface RemoteDataSourceService {
|
public interface RemoteDataSourceService {
|
||||||
|
|
||||||
|
|
|
@ -110,11 +110,19 @@ public class TaskController extends BaseController
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试任务
|
||||||
|
*/
|
||||||
|
@PostMapping("/testExecute/{taskCode}")
|
||||||
|
public Result<String> testExecute(@PathVariable("taskCode") String taskCode) {
|
||||||
|
return success(taskService.testExecute(taskCode));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 执行任务
|
* 执行任务
|
||||||
*/
|
*/
|
||||||
@PostMapping("/execute/{taskCode}")
|
@PostMapping("/execute/{taskCode}")
|
||||||
public Result execute(@PathVariable("taskCode") String taskCode) {
|
public Result<String> execute(@PathVariable("taskCode") String taskCode) {
|
||||||
return success(taskService.execute(taskCode));
|
return success(taskService.execute(taskCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
}
|
|
@ -45,4 +45,6 @@ public interface TaskService extends IService<Task> {
|
||||||
void removeBatch(List<Long> list);
|
void removeBatch(List<Long> list);
|
||||||
|
|
||||||
String execute(String taskCode);
|
String execute(String taskCode);
|
||||||
|
|
||||||
|
String testExecute(String taskCode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,36 +152,27 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>
|
||||||
List<Node> nodeListAll = nodeService.selectNodeList(new NodeReq().buildTaskCode(taskCode));
|
List<Node> nodeListAll = nodeService.selectNodeList(new NodeReq().buildTaskCode(taskCode));
|
||||||
// 节点初始化
|
// 节点初始化
|
||||||
HashMap<String, List<Node>> nodeMap = NodeUtils.nodeInit(nodeListAll);
|
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);
|
Node thisNode = nodeMap.get("start").get(0);
|
||||||
// 开始节点处理
|
// 开始节点处理
|
||||||
while (true){
|
while (true){
|
||||||
List<Node> nextNode = NodeUtils.getNextNode(thisNode, nodeListAll);
|
thisNode = NodeUtils.nodeCheck(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);
|
|
||||||
if (StringUtils.equals(thisNode.getNodeType(), "end")){
|
if (StringUtils.equals(thisNode.getNodeType(), "end")){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// 查询当前节点所有配置信息
|
// 查询当前节点所有配置信息
|
||||||
List<NodeDisposition> dispList = dispositionService
|
List<NodeDisposition> dispList = dispositionService
|
||||||
.selectNodeDispositionList(new NodeDisposition().buildNodeCode(thisNode.getNodeCode()));
|
.selectNodeDispositionList(new NodeDisposition().buildNodeCode(thisNode.getNodeCode()));
|
||||||
|
if (dispList.isEmpty()){
|
||||||
|
throw new TaskException("节点 "+thisNode+" 配置为空");
|
||||||
|
}
|
||||||
// 根据情况拼接查询sql与新增sql
|
// 根据情况拼接查询sql与新增sql
|
||||||
if(StringUtils.equals(thisNode.getNodeType(), "table")) {
|
if(StringUtils.equals(thisNode.getNodeType(), "table")) {
|
||||||
// 如果表节点下一级为数据输出节点,即表示为单表查询,将 当前表结构处理为查询语句
|
// 如果表节点下一级为数据输出节点,即表示为单表查询,将 当前表结构处理为查询语句
|
||||||
Node newNode = NodeUtils.getNextNode(thisNode, nodeListAll).get(0);
|
if (StringUtils.equals(NodeUtils.nodeCheck(thisNode, nodeListAll).getNodeType(), "exportation")){
|
||||||
if (StringUtils.equals(newNode.getNodeType(), "exportation")){
|
|
||||||
findSql = NodeUtils.tableNode(dispList);
|
findSql = NodeUtils.tableNode(dispList);
|
||||||
}
|
}
|
||||||
}else if (StringUtils.equals(thisNode.getNodeType(), "unite")){
|
}else if (StringUtils.equals(thisNode.getNodeType(), "unite")){
|
||||||
|
@ -196,23 +187,72 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>
|
||||||
if (tableValue.getCode() != 200){
|
if (tableValue.getCode() != 200){
|
||||||
throw new TaskException(tableValue.getMsg());
|
throw new TaskException(tableValue.getMsg());
|
||||||
}
|
}
|
||||||
System.out.println(tableValue);
|
|
||||||
List<DataModel> data = tableValue.getData();
|
List<DataModel> data = tableValue.getData();
|
||||||
System.out.println(data);
|
|
||||||
addSql = NodeUtils.nodeDispExportation(dispList, data);
|
addSql = NodeUtils.nodeDispExportation(dispList, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("任务执行完成,新增sql为: [{}]", addSql);
|
log.info("任务执行完成,新增sql为: [{}]", addSql);
|
||||||
Result i = remoteDataSourceService.addTableValue(new DataValueModel(4L, addSql));
|
Result resp = remoteDataSourceService.addTableValue(new DataValueModel(4L, addSql));
|
||||||
if (i.getCode() != 200){
|
if (resp.getCode() != 200){
|
||||||
throw new TaskException(i.getMsg());
|
throw new TaskException(resp.getMsg());
|
||||||
}
|
}
|
||||||
return "执行成功";
|
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 "执行成功,无异常";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 节点全部配置信息
|
* @param dispList 节点全部配置信息
|
||||||
|
|
Loading…
Reference in New Issue