refactor(系统): 资源id不存在可能导致整个任务停止了的潜在问题
This commit is contained in:
parent
d2419e0f33
commit
9e3799b5f2
|
@ -36,7 +36,7 @@ public class CleanHistoryJob {
|
||||||
/**
|
/**
|
||||||
* 清理变更历史 每天凌晨两点执行
|
* 清理变更历史 每天凌晨两点执行
|
||||||
*/
|
*/
|
||||||
@QuartzScheduled(cron = "0 0 2 * * ?")
|
@QuartzScheduled(cron = "0 34 13 * * ?")
|
||||||
public void cleanupLog() {
|
public void cleanupLog() {
|
||||||
LogUtils.info("clean up history start.");
|
LogUtils.info("clean up history start.");
|
||||||
SystemParameter parameter = systemParameterMapper.selectByPrimaryKey(ParamConstants.CleanConfig.OPERATION_HISTORY.getValue());
|
SystemParameter parameter = systemParameterMapper.selectByPrimaryKey(ParamConstants.CleanConfig.OPERATION_HISTORY.getValue());
|
||||||
|
@ -56,12 +56,16 @@ public class CleanHistoryJob {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doCleanupHistory(int limit) {
|
private void doCleanupHistory(int limit) {
|
||||||
|
try {
|
||||||
//变更历史处理
|
//变更历史处理
|
||||||
List<String> sourceIds = baseOperationHistoryMapper.selectSourceIds();
|
List<String> sourceIds = baseOperationHistoryMapper.selectSourceIds();
|
||||||
int size = 100;
|
int size = 100;
|
||||||
List<List<String>> batchList = splitList(sourceIds, size);
|
List<List<String>> batchList = splitList(sourceIds, size);
|
||||||
|
|
||||||
batchList.forEach(batch -> cleanupHistory(batch, limit));
|
batchList.forEach(batch -> cleanupHistory(batch, limit));
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<List<String>> splitList(List<String> list, int size) {
|
private List<List<String>> splitList(List<String> list, int size) {
|
||||||
|
@ -75,6 +79,7 @@ public class CleanHistoryJob {
|
||||||
public void cleanupHistory(List<String> batch, int limit) {
|
public void cleanupHistory(List<String> batch, int limit) {
|
||||||
batch.forEach(sourceId -> {
|
batch.forEach(sourceId -> {
|
||||||
List<Long> ids = baseOperationHistoryMapper.selectIdsBySourceId(sourceId, limit);
|
List<Long> ids = baseOperationHistoryMapper.selectIdsBySourceId(sourceId, limit);
|
||||||
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
baseOperationHistoryMapper.deleteByIds(sourceId, ids);
|
baseOperationHistoryMapper.deleteByIds(sourceId, ids);
|
||||||
List<Long> logIds = baseOperationLogMapper.selectIdByHistoryIds(ids);
|
List<Long> logIds = baseOperationLogMapper.selectIdByHistoryIds(ids);
|
||||||
ids.removeAll(logIds);
|
ids.removeAll(logIds);
|
||||||
|
@ -83,6 +88,7 @@ public class CleanHistoryJob {
|
||||||
blobExample.createCriteria().andIdIn(ids);
|
blobExample.createCriteria().andIdIn(ids);
|
||||||
operationLogBlobMapper.deleteByExample(blobExample);
|
operationLogBlobMapper.deleteByExample(blobExample);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue