sql拼接
parent
e363701cd6
commit
34c07a4d85
|
@ -17,4 +17,11 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-common-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package com.muyu;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.muyu.task.feign;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @PackageName:com.muyu.task.feign
|
||||
* @ClassName:dataValue
|
||||
* @Description:
|
||||
* @author: ¥陈思豪¥
|
||||
* @date: 2024/9/4 15:13
|
||||
*/
|
||||
//,fallback = TaskFeignFallback.class
|
||||
@FeignClient(name = "cloud-source")
|
||||
public interface DataValueFeign {
|
||||
|
||||
@PostMapping("/DataValue/findTableValue")
|
||||
public Result findTableValue(@RequestParam("basicId") Long basicId,@RequestParam("sql") String sql);
|
||||
|
||||
}
|
|
@ -72,6 +72,12 @@
|
|||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>cloud-task-remote</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<!-- XllJob定时任务 -->
|
||||
|
|
|
@ -2,8 +2,10 @@ package com.muyu;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableFeignClients
|
||||
public class TaskApplication {
|
||||
public static void main (String[] args) {
|
||||
SpringApplication.run(TaskApplication.class, args);
|
||||
|
|
|
@ -72,5 +72,16 @@ public class TaskController {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行任务
|
||||
*/
|
||||
@RequestMapping(path = "/executeTask/{taskId}", method = RequestMethod.POST)
|
||||
@Operation(summary = "对指定任务进行执行", description = "根据传来的id进行执行")
|
||||
public Result<String> executeTask(@PathVariable(name = "taskId") Integer taskId) {
|
||||
return Result.success(
|
||||
taskService.executeTask(taskId), "执行成功"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.muyu.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.domain.TaskOutputInfo;
|
||||
import com.muyu.mapper.TaskOutputMapper;
|
||||
import com.muyu.service.TaskOutputService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
@ -16,15 +18,16 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/taskOutPut")
|
||||
public class TaskOutPutController {
|
||||
public class TaskOutputController {
|
||||
|
||||
@Autowired
|
||||
private TaskOutputMapper taskOutPutMapper;
|
||||
private TaskOutputService taskOutputService;
|
||||
|
||||
//添加数据输出方法
|
||||
@RequestMapping(value = "addTaskOutPut")
|
||||
public void addTaskOutPut(@RequestBody TaskOutputInfo taskOutputInfo){
|
||||
int insert = taskOutPutMapper.insert(taskOutputInfo);
|
||||
@RequestMapping(value = "addTaskOutput")
|
||||
public Result<String> addTaskOutPut(@RequestBody TaskOutputInfo taskOutputInfo){
|
||||
return Result.success(null,
|
||||
taskOutputService.addTaskOutput(taskOutputInfo));
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.muyu.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.domain.TaskOutputInfo;
|
||||
|
||||
public interface TaskOutputService extends IService<TaskOutputInfo> {
|
||||
|
||||
String addTaskOutput(TaskOutputInfo taskOutputInfo);
|
||||
}
|
|
@ -21,4 +21,6 @@ public interface TaskService extends IService<TaskInfo> {
|
|||
String updById(TaskInfo taskInfo);
|
||||
|
||||
String deleteById(Integer id);
|
||||
|
||||
String executeTask(Integer taskId);
|
||||
}
|
||||
|
|
|
@ -48,15 +48,6 @@ public class TableInfoServiceImpl extends ServiceImpl<TableInfoMapper, TableInfo
|
|||
tableInfoCasRespDad.setChildren(tableInfoCasRespSon);
|
||||
tableInfo.setTableInfoList(list1);
|
||||
tableInfoCasResp.add(tableInfoCasRespDad);
|
||||
// LambdaQueryWrapper<TableInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||
// queryWrapper.eq(TableInfo::getParentId,0);
|
||||
// List<TableInfo> list = this.list(queryWrapper);
|
||||
// list.forEach(tableInfo -> {
|
||||
// LambdaQueryWrapper<TableInfo> queryWrapperC = new LambdaQueryWrapper<>();
|
||||
// queryWrapperC.eq(TableInfo::getParentId,tableInfo.getId());
|
||||
// List<TableInfo> list1 = this.list(queryWrapperC);
|
||||
// tableInfo.setTableInfoList(list1);
|
||||
// });
|
||||
|
||||
});
|
||||
return tableInfoCasResp;
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.domain.TaskOutputInfo;
|
||||
import com.muyu.mapper.TaskOutputMapper;
|
||||
import com.muyu.service.TaskOutputService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @PackageName:com.muyu.service.impl
|
||||
* @ClassName:TaskOutputServiceImpl
|
||||
* @Description:
|
||||
* @author: ¥陈思豪¥
|
||||
* @date: 2024/9/4 11:35
|
||||
*/
|
||||
@Service
|
||||
public class TaskOutputServiceImpl extends ServiceImpl<TaskOutputMapper, TaskOutputInfo> implements TaskOutputService {
|
||||
|
||||
@Autowired
|
||||
private TaskOutputMapper taskOutputMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public String addTaskOutput(TaskOutputInfo taskOutputInfo) {
|
||||
int insert = taskOutputMapper.insert(taskOutputInfo);
|
||||
if(insert<=0){
|
||||
return "添加失败";
|
||||
}
|
||||
return "添加成功";
|
||||
}
|
||||
}
|
|
@ -2,13 +2,24 @@ package com.muyu.service.impl;
|
|||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.domain.TaskInfo;
|
||||
import com.muyu.domain.TaskInputInfo;
|
||||
import com.muyu.domain.TaskJoinInfo;
|
||||
import com.muyu.domain.TaskOutputInfo;
|
||||
import com.muyu.domain.req.TaskInfoReq;
|
||||
import com.muyu.mapper.TaskMapper;
|
||||
import com.muyu.service.TaskInputService;
|
||||
import com.muyu.service.TaskJoinService;
|
||||
import com.muyu.service.TaskOutputService;
|
||||
import com.muyu.service.TaskService;
|
||||
import com.muyu.task.feign.DataValueFeign;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -19,9 +30,23 @@ import java.util.List;
|
|||
* @date: 2024/8/22 17:15
|
||||
*/
|
||||
@Service
|
||||
@Log4j2
|
||||
public class TaskServiceImpl extends ServiceImpl<TaskMapper, TaskInfo> implements TaskService {
|
||||
|
||||
@Autowired
|
||||
private TaskInputService taskInputService;
|
||||
|
||||
@Autowired
|
||||
private TaskMapper taskMapper;
|
||||
|
||||
@Autowired
|
||||
private TaskJoinService taskJoinService;
|
||||
|
||||
@Autowired
|
||||
private TaskOutputService taskOutputService;
|
||||
|
||||
@Autowired
|
||||
private DataValueFeign dataValue;
|
||||
|
||||
@Override
|
||||
public List<TaskInfo> selectList(TaskInfoReq taskInfoReq) {
|
||||
|
@ -70,4 +95,77 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, TaskInfo> implement
|
|||
return "success";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String executeTask(Integer taskId) {
|
||||
LambdaQueryWrapper<TaskInputInfo> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TaskInputInfo::getTaskId, taskId);
|
||||
List<TaskInputInfo> taskInputList = taskInputService.list(queryWrapper);
|
||||
if(taskInputList.isEmpty()){
|
||||
return "表节点没有进行相对应的选择,无法继续执行";
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<TaskOutputInfo> outputInfo = new LambdaQueryWrapper<>();
|
||||
outputInfo.eq(TaskOutputInfo::getTaskId, taskId);
|
||||
TaskOutputInfo serviceOne = taskOutputService.getOne(outputInfo);
|
||||
String[] outPutFileName = serviceOne.getLastFileName().split(",");
|
||||
HashMap<String, String> fieldAsNameMap = new HashMap<>();
|
||||
String sql = "";
|
||||
for (int i = 0; i < taskInputList.size(); i++) {
|
||||
String[] tableFieldList = taskInputList.get(i).getTableField().split(",");
|
||||
String[] tableAsFieldList = taskInputList.get(i).getTableAsField().split(",");
|
||||
for (int j = 0; j < tableAsFieldList.length; j++) {
|
||||
for (int o = 0; o < outPutFileName.length; o++) {
|
||||
if(tableAsFieldList[j].equals(outPutFileName[o])){
|
||||
sql += ","+taskInputList.get(i).getTableAsName() + "." + tableFieldList[j] +" " +
|
||||
tableAsFieldList[j] + " ";
|
||||
}
|
||||
}
|
||||
fieldAsNameMap.put(tableAsFieldList[j], tableFieldList[j]);
|
||||
// 规则
|
||||
// tableNameMap.put(tableFieldList[j], tableAsFieId[j]);
|
||||
}
|
||||
}
|
||||
|
||||
sql = sql.substring(1);
|
||||
sql = "select " + sql + " from ";
|
||||
LambdaQueryWrapper<TaskJoinInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(TaskJoinInfo::getTaskId, taskId);
|
||||
List<TaskJoinInfo> taskJoinInfos = taskJoinService.list(lambdaQueryWrapper);
|
||||
if(!taskJoinInfos.isEmpty()){
|
||||
for (TaskJoinInfo taskJoinInfo : taskJoinInfos) {
|
||||
//拿到左表id
|
||||
String leftId = taskJoinInfo.getLeftId();
|
||||
TaskInputInfo leftInput = taskInputService.findByNodeId(leftId);
|
||||
//拿到右表id
|
||||
String rightId = taskJoinInfo.getRightId();
|
||||
TaskInputInfo rightInput = taskInputService.findByNodeId(rightId);
|
||||
sql += leftInput.getTableName() + " " + leftInput.getTableAsName()+" " +
|
||||
taskJoinInfo.getJoinType() + " " + rightInput.getTableName() + " " +
|
||||
rightInput.getTableAsName() + " on " + leftInput.getTableAsName() + "." +
|
||||
fieldAsNameMap.get(taskJoinInfo.getLeftJoinField()) + "=" + rightInput.getTableAsName() + "." +
|
||||
fieldAsNameMap.get(taskJoinInfo.getRightJoinField()) + " ";
|
||||
|
||||
}
|
||||
}else{
|
||||
LambdaQueryWrapper<TaskInputInfo> selectOne = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(TaskInputInfo::getTaskId, taskId);
|
||||
TaskInputInfo taskInputInfo = taskInputService.getOne(selectOne);
|
||||
sql += taskInputInfo.getTableName() + " " + taskInputInfo.getTableAsName();
|
||||
}
|
||||
|
||||
System.out.println(sql);
|
||||
System.out.println(sql);
|
||||
System.out.println(sql);
|
||||
System.out.println(sql);
|
||||
System.out.println(sql);
|
||||
System.out.println(sql);
|
||||
log.info(sql);
|
||||
Result tableValue = dataValue.findTableValue(Long.valueOf(serviceOne.getBasicId()), sql);
|
||||
log.info(tableValue);
|
||||
Object data = tableValue.getData();
|
||||
System.out.println(data);
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@ nacos:
|
|||
# text cloud-2112
|
||||
# Spring
|
||||
spring:
|
||||
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
application:
|
||||
# 应用名称
|
||||
name: cloud-task
|
||||
|
@ -19,6 +20,12 @@ spring:
|
|||
# 环境配置
|
||||
active: dev
|
||||
cloud:
|
||||
openfeign:
|
||||
client:
|
||||
config:
|
||||
default:
|
||||
connectTimeout: 50000 # 连接超时时间,单位为毫秒
|
||||
readTimeout: 5000 # 读取超时时间,单位为毫秒
|
||||
nacos:
|
||||
discovery:
|
||||
# 服务注册地址
|
||||
|
|
Loading…
Reference in New Issue