新增手动/定时清理无用任务
parent
3696f53e31
commit
8657218617
|
@ -143,7 +143,7 @@ public class NodeController extends BaseController {
|
|||
*/
|
||||
@PostMapping("/batch/{taskCode}")
|
||||
@Transactional
|
||||
public Result<Integer> batch(@Validated @RequestBody ArrayList<Node> nodeList,@PathVariable("taskCode") String taskCode) {
|
||||
public Result<Integer> batch(@Validated @RequestBody ArrayList<Node> nodeList,@PathVariable("taskCode") String[] taskCode) {
|
||||
// 批量删除
|
||||
nodeService.batchDelect(taskCode);
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ public class NodeDispositionController extends BaseController
|
|||
@Transactional
|
||||
public Result<Integer> batch(
|
||||
@Validated @RequestBody ArrayList<NodeDisposition> dispList,
|
||||
@PathVariable("nodeCode") String nodeCode){
|
||||
@PathVariable("nodeCode") String[] nodeCode){
|
||||
// 根据节点编码删除
|
||||
nodeDispositionService.batchDelect(nodeCode);
|
||||
// 批量新增
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.muyu.quest.domain.Task;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import com.muyu.quest.job.TaskJob;
|
||||
import com.muyu.quest.req.TaskReq;
|
||||
import com.muyu.quest.resp.TaskResp;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
@ -38,6 +39,8 @@ public class TaskController extends BaseController
|
|||
{
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
@Resource
|
||||
private TaskJob taskJob;
|
||||
|
||||
/**
|
||||
* 查询任务列表
|
||||
|
@ -115,4 +118,13 @@ public class TaskController extends BaseController
|
|||
return success(taskService.execute(taskCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动清理无用任务数据
|
||||
*/
|
||||
@PostMapping("/clearTask")
|
||||
public Result clearTask() {
|
||||
taskJob.clearTask();
|
||||
return success();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
package com.muyu.quest.job;
|
||||
|
||||
/**
|
||||
* @Author: 胡杨
|
||||
* @Name: TaskJob
|
||||
* @Description: 任务定时任务
|
||||
* @CreatedDate: 2024/9/4 下午2:37
|
||||
* @FilePath: com.muyu.quest.job
|
||||
*/
|
||||
|
||||
|
||||
import com.muyu.quest.domain.Node;
|
||||
import com.muyu.quest.domain.NodeDisposition;
|
||||
import com.muyu.quest.req.NodeReq;
|
||||
import com.muyu.quest.req.TaskReq;
|
||||
import com.muyu.quest.resp.TaskResp;
|
||||
import com.muyu.quest.service.INodeDispositionService;
|
||||
import com.muyu.quest.service.INodeService;
|
||||
import com.muyu.quest.service.TaskService;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: 胡杨
|
||||
* @Name: TaskJob
|
||||
* @Description: 任务定时任务
|
||||
* @CreatedDate: 2024/9/4 下午2:37
|
||||
* @FilePath: com.muyu.quest.job
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class TaskJob {
|
||||
|
||||
@Resource
|
||||
private TaskService taskService;
|
||||
@Resource
|
||||
private INodeService nodeService;
|
||||
@Resource
|
||||
private INodeDispositionService nodeDispositionService;
|
||||
|
||||
// 定时清理过期任务与其相关数据
|
||||
@XxlJob(value = "clearTask")
|
||||
public void clearTask() {
|
||||
List<TaskResp> tasks = taskService.selectTaskList(new TaskReq());
|
||||
List<Node> nodes = nodeService.selectNodeList(new NodeReq());
|
||||
List<NodeDisposition> dispositions = nodeDispositionService.selectNodeDispositionList(new NodeDisposition());
|
||||
|
||||
// 查询节点表存在但任务表不存在的任务编码
|
||||
List<String> notContainsTaskCodeList = nodes.
|
||||
stream().
|
||||
map(Node::getTaskCode).
|
||||
filter(nodeTaskCode -> !tasks.
|
||||
stream().
|
||||
map(TaskResp::getTaskCode).
|
||||
toList().contains(nodeTaskCode)).
|
||||
toList();
|
||||
// 删除相关节点表数据
|
||||
if (!notContainsTaskCodeList.isEmpty()) {
|
||||
nodeService.batchDelect(notContainsTaskCodeList.toArray(new String[0]));
|
||||
}
|
||||
// 查询配置表存在但节点表不存在的节点编码
|
||||
List<String> notContainsNodeCodeList = dispositions.
|
||||
stream().
|
||||
map(NodeDisposition::getNodeCode).
|
||||
filter(nodeDispositionNodeCode -> !nodes.
|
||||
stream().
|
||||
map(Node::getNodeCode).
|
||||
toList().contains(nodeDispositionNodeCode)).
|
||||
toList();
|
||||
// 删除相关配置表数据
|
||||
if (!notContainsNodeCodeList.isEmpty()) {
|
||||
nodeDispositionService.batchDelect(notContainsNodeCodeList.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -36,5 +36,5 @@ public interface INodeDispositionService extends IService<NodeDisposition> {
|
|||
|
||||
Boolean checkDispUnique(NodeDisposition disp);
|
||||
|
||||
void batchDelect(String nodeCode);
|
||||
void batchDelect(String[] nodeCode);
|
||||
}
|
||||
|
|
|
@ -37,5 +37,5 @@ public interface INodeService extends IService<Node> {
|
|||
|
||||
List<Node> selectNodeByIds(Long[] ids);
|
||||
|
||||
void batchDelect(String taskCode);
|
||||
void batchDelect(String[] taskCode);
|
||||
}
|
||||
|
|
|
@ -83,9 +83,9 @@ public class NodeDispositionServiceImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public void batchDelect(String nodeCode) {
|
||||
public void batchDelect(String[] nodeCode) {
|
||||
LambdaQueryWrapper<NodeDisposition> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(NodeDisposition::getNodeCode, nodeCode);
|
||||
queryWrapper.in(NodeDisposition::getNodeCode, nodeCode);
|
||||
this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
|
|
|
@ -91,9 +91,9 @@ public class NodeServiceImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public void batchDelect(String taskCode) {
|
||||
public void batchDelect(String[] taskCode) {
|
||||
LambdaQueryWrapper<Node> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(Node::getTaskCode,taskCode);
|
||||
queryWrapper.in(Node::getTaskCode,taskCode);
|
||||
this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
|
|
|
@ -256,10 +256,10 @@ public class NodeUtils {
|
|||
String dbTable = "`" + db.getDispDesc() + "`." + db.getDispValue();
|
||||
// 根据表结构拼接新增字段
|
||||
List<NodeDisposition> fieldList = dispMap.get("toFields");
|
||||
// 获取新增语句前半段
|
||||
// 拼接新增语句的表与字段
|
||||
String join = StringUtils.join(fieldList.stream().map(NodeDisposition::getDispValue).toArray(), ",");
|
||||
StringBuilder insSql = new StringBuilder("INSERT INTO " + dbTable + "( " + join + " ) VALUES ");
|
||||
// 获取查询字段
|
||||
// 整理需新增数据
|
||||
List<HashMap<String, String>> dataList1 = new ArrayList<>();
|
||||
HashMap<String, String> dataMap = new HashMap<>();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
|
@ -269,16 +269,15 @@ public class NodeUtils {
|
|||
}
|
||||
dataMap.put(data.get(i).getKey(), data.get(i).getValue().toString());
|
||||
}
|
||||
dataList1.forEach(map -> insSql.append(
|
||||
"( " +
|
||||
StringUtils.join(
|
||||
// 拼接新增语句的值
|
||||
dataList1.forEach(map -> insSql.append("( ").
|
||||
append(StringUtils.join(
|
||||
fieldList.
|
||||
stream().
|
||||
map(field -> map.get(field.getDispDesc())).
|
||||
map(field -> "'" + field + "'").
|
||||
toArray(),
|
||||
",") +
|
||||
" ),"));
|
||||
",")).append(" ),"));
|
||||
return insSql.deleteCharAt(insSql.length() - 1).toString();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue