清空缓存以确保每次任务和请求使用最新数据,避免缓存污染

This commit is contained in:
syruan 2025-11-14 14:00:06 +08:00
parent 3b51d2c52a
commit d3571c72bd
3 changed files with 26 additions and 2 deletions

View File

@ -96,6 +96,9 @@ public class IwsCostPushTask {
// --------- 定义结果集合 ------------------
List<SltInfoVo> gqjResultList = new ArrayList<>(list.size());
// 清空缓存确保每次定时任务都使用最新的数据避免缓存污染
sltAgreementInfoService.clearCache();
try {
// 批量处理减少单个查询
log.info("开始批量处理 {} 个协议的费用明细", list.size());
@ -286,6 +289,9 @@ public class IwsCostPushTask {
// --------- 定义结果集合 ------------------
List<SltInfoVo> gqjResultList = new ArrayList<>(list.size());
// 清空缓存确保每次定时任务都使用最新的数据避免缓存污染
sltAgreementInfoService.clearCache();
try {
// 批量处理减少单个查询
log.info("开始批量处理 {} 个协议的费用明细", list.size());

View File

@ -1577,6 +1577,9 @@ public class SltAgreementInfoController extends BaseController {
// --------- 定义返回集合 ------------------
List<SltInfoVo> dataList = new ArrayList<>(list.size());
// 清空缓存确保每次请求都使用最新的数据避免缓存污染
sltAgreementInfoService.clearCache();
// 批量处理减少单个查询
list.forEach(info -> {
try {
@ -1650,6 +1653,9 @@ public class SltAgreementInfoController extends BaseController {
// --------- 定义返回集合 ------------------
List<SltInfoVo> dataList = new ArrayList<>(list.size());
// 清空缓存确保每次请求都使用最新的数据避免缓存污染
sltAgreementInfoService.clearCache();
// 批量处理减少单个查询
list.forEach(info -> {
@ -1669,6 +1675,10 @@ public class SltAgreementInfoController extends BaseController {
}
});
// 清空缓存防止内存泄漏
sltAgreementInfoService.clearCache();
ExcelUtil<SltInfoVo> util = new ExcelUtil<>(SltInfoVo.class);
util.exportExcel(response, dataList, "导出未结算报表列表");
}

View File

@ -285,12 +285,20 @@ public class SltAgreementInfoServiceImpl implements ISltAgreementInfoService {
if (repairListCache.get() == null) {
System.err.println("批量查询结算信息列表 -- 未结算报表专用:开始执行一次性批量维修费用查询");
// 调用一次性批量维修费用查询
repairListCache.set(sltAgreementInfoMapper.getRepairDetailsListBatch(info, null));
// 创建一个新的查询对象只保留 agreementIds settlementType清空 agreementCode 避免 SQL 过滤条件污染
SltAgreementInfo batchQueryInfo = new SltAgreementInfo();
batchQueryInfo.setAgreementIds(info.getAgreementIds());
batchQueryInfo.setSettlementType(info.getSettlementType());
repairListCache.set(sltAgreementInfoMapper.getRepairDetailsListBatch(batchQueryInfo, null));
}
if (scrapListCache.get() == null) {
System.err.println("批量查询结算信息列表 -- 未结算报表专用:开始执行一次性批量报废费用查询");
// 调用一次性批量报废费用查询
scrapListCache.set(sltAgreementInfoMapper.getScrapDetailsListBatch(info));
// 创建一个新的查询对象只保留 agreementIds settlementType清空 agreementCode 避免 SQL 过滤条件污染
SltAgreementInfo batchQueryInfo = new SltAgreementInfo();
batchQueryInfo.setAgreementIds(info.getAgreementIds());
batchQueryInfo.setSettlementType(info.getSettlementType());
scrapListCache.set(sltAgreementInfoMapper.getScrapDetailsListBatch(batchQueryInfo));
}
// 查询租赁费用列表
List<SltAgreementInfo> leaseList = getLeaseBtachList(info);