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();
|
//变更历史处理
|
||||||
int size = 100;
|
List<String> sourceIds = baseOperationHistoryMapper.selectSourceIds();
|
||||||
List<List<String>> batchList = splitList(sourceIds, size);
|
int size = 100;
|
||||||
|
List<List<String>> batchList = splitList(sourceIds, size);
|
||||||
|
batchList.forEach(batch -> cleanupHistory(batch, limit));
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtils.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
batchList.forEach(batch -> cleanupHistory(batch, limit));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<List<String>> splitList(List<String> list, int size) {
|
private List<List<String>> splitList(List<String> list, int size) {
|
||||||
|
@ -75,13 +79,15 @@ 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);
|
||||||
baseOperationHistoryMapper.deleteByIds(sourceId, ids);
|
|
||||||
List<Long> logIds = baseOperationLogMapper.selectIdByHistoryIds(ids);
|
|
||||||
ids.removeAll(logIds);
|
|
||||||
if (CollectionUtils.isNotEmpty(ids)) {
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
OperationLogBlobExample blobExample = new OperationLogBlobExample();
|
baseOperationHistoryMapper.deleteByIds(sourceId, ids);
|
||||||
blobExample.createCriteria().andIdIn(ids);
|
List<Long> logIds = baseOperationLogMapper.selectIdByHistoryIds(ids);
|
||||||
operationLogBlobMapper.deleteByExample(blobExample);
|
ids.removeAll(logIds);
|
||||||
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
|
OperationLogBlobExample blobExample = new OperationLogBlobExample();
|
||||||
|
blobExample.createCriteria().andIdIn(ids);
|
||||||
|
operationLogBlobMapper.deleteByExample(blobExample);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue