修复数据为空时无法执行的问题

master
面包骑士 2024-09-06 16:37:03 +08:00
parent ea4585909a
commit de0e7d69af
3 changed files with 12 additions and 8 deletions

View File

@ -137,7 +137,7 @@ public final class TaskManager {
synchronized (taskQueue) {
while (isRunning && taskQueue.isEmpty()) {// 队列为空
try {
taskQueue.wait(1000);
taskQueue.wait(50);
} catch (InterruptedException e) {
e.printStackTrace();
}

View File

@ -137,7 +137,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>
}
/**
*
* //TODO 执行任务
* sql
* @param taskCode
* @return
@ -156,10 +156,10 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>
// 划分线程 每次查询1000条
int threadNum = count / 1000 + 1;
log.info("任务 {} 总共需要 {} 条数据, 划分为线程{}条",taskCode,count,threadNum);
Runnable[] tasks = new Runnable[threadNum];
for (int i = 0; i < threadNum; i++) {
int index = i+1;
tasks[i] = () -> {
// 添加进入任务队列
taskManager.execute(() -> {
// 获取新SQL 并执行
String sql = findSql + " LIMIT 1000 OFFSET "+(index-1)*1000;
log.info("任务 {} 开始执行第 {} 线程,查询SQL: {}",taskCode,index, sql);
@ -169,10 +169,9 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>
if (addResult.getCode() != 200){
throw new TaskException(addResult.getMsg());
}
};
});
}
// 添加进入任务队列
taskManager.execute(tasks);
return "执行成功";
}

View File

@ -304,9 +304,14 @@ public class NodeUtils {
List<HashMap<String, String>> dataList1 = new ArrayList<>();
for (List<DataModel> datum : data) {
HashMap<String, String> dataMap = new HashMap<>();
datum.forEach(dataModel -> dataMap.put(dataModel.getKey(), dataModel.getValue().toString()));
datum.forEach(dataModel -> {
// 检查 getValue 是否为空
String value = dataModel.getValue() != null ? dataModel.getValue().toString() : null;
dataMap.put(dataModel.getKey(), value);
});
dataList1.add(dataMap);
}
System.out.println(dataList1);
// 拼接新增语句的值
dataList1.forEach(map -> insSql.append("( ").
append(StringUtils.join(