Commit 70874a67 by 林永健

refactor(report): 重构数据报告生成逻辑并添加历史数据处理功能

- 提取数据报告生成方法到独立的私有方法中
- 在月报快照任务完成后调用历史数据处理方法
- 实现handlerHistoryData方法处理generate_status=1的历史异常数据
- 修正业务快照查询的SQL条件顺序和空值判断逻辑
- 更新测试类添加历史数据处理测试方法和周报快照任务测试用例
1 parent c1f2d2ab
......@@ -49,6 +49,8 @@ public class DataReportMonthlySnapshotJob implements SimpleJob {
} else {
log.error("数据报告月报快照生成任务执行失败,periodKey:{}", periodKey);
}
dataReportSnapshotService.handlerHistoryData();
} catch (Exception e) {
log.error("数据报告月报快照生成任务执行异常", e);
throw e; // 重新抛出异常,让ElasticJob框架处理重试
......
......@@ -480,4 +480,34 @@ public class DataReportSnapshotService {
return "{}";
}
}
/**
* 处理历史异常的报告数据
*/
public void handlerHistoryData() {
Example example = new Example(DataReportBusinessSnapshot.class);
example.createCriteria()
.andEqualTo("generateStatus", 1)
.andEqualTo("deletedFlag", "N");
List<DataReportBusinessSnapshot> unSuccessData = businessSnapshotMapper.selectByExample(example);
if (CollectionUtils.isEmpty(unSuccessData)) {
return;
}
List<Integer> ids = unSuccessData.stream().map(DataReportBusinessSnapshot::getId).collect(Collectors.toList());
log.info("处理历史 generate_status=1 的数据,共{}条, id:{}", unSuccessData.size(), ids);
unSuccessData.stream().collect(Collectors.groupingBy(p -> p.getReportType() + "_" + p.getPeriodKey())).forEach((key, value) -> {
log.info("处理历史数据,key={}, size={}", key, value.size());
for (DataReportBusinessSnapshot item : value) {
DataReportGenerateReq req = new DataReportGenerateReq();
req.setReportType(item.getReportType());
req.setPeriodKey(item.getPeriodKey());
req.setPeriodStart(item.getPeriodStart());
req.setPeriodEnd(item.getPeriodEnd());
req.setOperator("SYNC");
thiz.generateSnapshot(req, item.getBusinessType());
}
});
log.info("处理历史数据完成");
}
}
\ No newline at end of file
......@@ -30,10 +30,12 @@
SELECT
<include refid="Base_Column_List"/>
FROM dj_data_report_business_snapshot
WHERE report_type = #{reportType}
WHERE deleted_flag = 'N'
AND report_type = #{reportType}
AND period_key = #{periodKey}
AND business_type = #{businessType}
AND deleted_flag = 'N'
<if test="businessType != null">
AND business_type = #{businessType}
</if>
<if test="generateStatus != null">
AND generate_status = #{generateStatus}
</if>
......
......@@ -47,6 +47,11 @@ public class DataReportSnapshotServiceTest extends BaseRemoteTest {
}
@Test
public void handlerHistoryDataTest() {
dataReportSnapshotService.handlerHistoryData();
}
@Test
public void dataReportAiTextSummarySubmitJobTest() {
dataReportAiTextSummarySubmitJob.execute(null);
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!