fix: 修复任务中心 ID 被重置问题
--bug=1048646 --user=赵勇 【任务中心】github#34056,任务中心中的系统即时任务ID重复,当前每天都会从100001编号重新开始编号 https://www.tapd.cn/55049933/s/1612658
This commit is contained in:
parent
c47d0cd198
commit
367e62e3da
|
@ -61,25 +61,37 @@ public class NumGenerator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanDeletedProjectResource(ApplicationNumScope value) {
|
private void cleanDeletedProjectResource(ApplicationNumScope scope) {
|
||||||
String suffix = "}:allocation";
|
final String SUFFIX = "}:allocation";
|
||||||
|
final int SCAN_COUNT = 1000;
|
||||||
|
|
||||||
ScanOptions options = ScanOptions.scanOptions().match("*_" + value.name()).count(1000).build();
|
ScanOptions options = ScanOptions.scanOptions()
|
||||||
try (
|
.match("*_" + scope.name())
|
||||||
Cursor<String> scan = stringRedisTemplate.scan(options)
|
.count(SCAN_COUNT)
|
||||||
) {
|
.build();
|
||||||
while (scan.hasNext()) {
|
|
||||||
String key = scan.next();
|
try (Cursor<String> cursor = stringRedisTemplate.scan(options)) {
|
||||||
if (StringUtils.contains(key, suffix)) {
|
cursor.forEachRemaining(key -> {
|
||||||
continue;
|
// 如果 key 包含特定后缀,跳过处理
|
||||||
|
if (StringUtils.contains(key, SUFFIX)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
Project project = projectMapper.selectByPrimaryKey(key.split("_")[0]);
|
|
||||||
if (project == null) {
|
// 提取 projectId 并跳过任务作用域的键
|
||||||
LogUtils.info("清理已经删除项目的num数据: " + key);
|
String projectId = key.split("_")[0];
|
||||||
|
if (StringUtils.equals(ApplicationNumScope.TASK.name(), projectId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查项目是否存在,删除已删除项目的相关数据
|
||||||
|
if (projectMapper.selectByPrimaryKey(projectId) == null) {
|
||||||
|
LogUtils.info("清理已经删除项目的 num 数据: {}", key);
|
||||||
stringRedisTemplate.delete(key);
|
stringRedisTemplate.delete(key);
|
||||||
stringRedisTemplate.delete("{" + key + suffix);
|
stringRedisTemplate.delete("{" + key + SUFFIX);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.error("清理已删除项目资源时发生错误", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue