Commit 7ffc0d30 by 崔彦峰

refactor(daily-report): 优化日报数据查询逻辑支持多条记录处理

- 将单条记录查询改为批量查询,提高数据获取效率
- 新增 querySubmittedRecordsByDate 方法支持查询指定日期的所有提交记录
- 修改多个方法的实现逻辑,从只处理最新一条记录改为处理全部记录
- 添加 collectNegotiationRows 方法统一处理多条记录的数据收集逻辑
- 优化子表数据映射查询,支持多条记录的批量处理
- 修复原逻辑中只取最新一条记录可能遗漏历史数据的问题
1 parent 7f52bbf1
......@@ -114,14 +114,17 @@ public class DailyReportDataService {
return null;
}
DailyReportRecord latestRecord = queryLatestSubmittedRecord(merchantId, DailyReportTemplateTypeEnum.DISCUSSION.getValue(), reportDate);
if (latestRecord == null) {
List<DailyReportRecord> recordList = querySubmittedRecordsByDate(merchantId, DailyReportTemplateTypeEnum.DISCUSSION.getValue(), reportDate);
if (CollectionUtils.isEmpty(recordList)) {
log.info("queryNegotiationData no record found, merchantId:{}, reportDate:{}", merchantId, reportDate);
return null;
}
Map<Integer, List<DailyReportSubformData>> subformDataMap = querySubformDataMap(Collections.singletonList(latestRecord.getId()));
List<Map<String, String>> negotiationRows = buildNegotiationRows(latestRecord, subformDataMap);
DailyReportRecord latestRecord = recordList.get(recordList.size() - 1);
Map<Integer, List<DailyReportSubformData>> subformDataMap = querySubformDataMap(recordList.stream()
.map(DailyReportRecord::getId)
.collect(Collectors.toList()));
List<Map<String, String>> negotiationRows = collectNegotiationRows(recordList, record -> buildNegotiationRows(record, subformDataMap));
if (CollectionUtils.isEmpty(negotiationRows)) {
log.info("queryNegotiationData no rows found, merchantId:{}, reportDate:{}", merchantId, reportDate);
return null;
......@@ -205,14 +208,17 @@ public class DailyReportDataService {
return Collections.emptyList();
}
DailyReportRecord latestRecord = queryLatestSubmittedRecord(merchantId, DailyReportTemplateTypeEnum.DISCUSSION.getValue(), reportDate);
if (latestRecord == null) {
List<DailyReportRecord> recordList = querySubmittedRecordsByDate(merchantId, DailyReportTemplateTypeEnum.DISCUSSION.getValue(), reportDate);
if (CollectionUtils.isEmpty(recordList)) {
log.info("queryExtendedWarrantyNegotiationRows no record found, merchantId:{}, reportDate:{}", merchantId, reportDate);
return Collections.emptyList();
}
Map<Integer, List<DailyReportSubformData>> subformDataMap = querySubformDataMap(Collections.singletonList(latestRecord.getId()));
List<Map<String, String>> negotiationRows = buildExtendedWarrantyNegotiationRows(latestRecord, subformDataMap);
Map<Integer, List<DailyReportSubformData>> subformDataMap = querySubformDataMap(recordList.stream()
.map(DailyReportRecord::getId)
.collect(Collectors.toList()));
List<Map<String, String>> negotiationRows = collectNegotiationRows(recordList,
record -> buildExtendedWarrantyNegotiationRows(record, subformDataMap));
if (CollectionUtils.isEmpty(negotiationRows)) {
log.info("queryExtendedWarrantyNegotiationRows no rows found, merchantId:{}, reportDate:{}", merchantId, reportDate);
return Collections.emptyList();
......@@ -231,14 +237,17 @@ public class DailyReportDataService {
return Collections.emptyList();
}
DailyReportRecord latestRecord = queryLatestSubmittedRecord(merchantId, DailyReportTemplateTypeEnum.DISCUSSION.getValue(), reportDate);
if (latestRecord == null) {
List<DailyReportRecord> recordList = querySubmittedRecordsByDate(merchantId, DailyReportTemplateTypeEnum.DISCUSSION.getValue(), reportDate);
if (CollectionUtils.isEmpty(recordList)) {
log.info("queryExtendedWarrantyLanTuNegotiationRows no record found, merchantId:{}, reportDate:{}", merchantId, reportDate);
return Collections.emptyList();
}
Map<Integer, List<DailyReportSubformData>> subformDataMap = querySubformDataMap(Collections.singletonList(latestRecord.getId()));
List<Map<String, String>> negotiationRows = buildExtendedWarrantyLanTuNegotiationRows(latestRecord, subformDataMap);
Map<Integer, List<DailyReportSubformData>> subformDataMap = querySubformDataMap(recordList.stream()
.map(DailyReportRecord::getId)
.collect(Collectors.toList()));
List<Map<String, String>> negotiationRows = collectNegotiationRows(recordList,
record -> buildExtendedWarrantyLanTuNegotiationRows(record, subformDataMap));
if (CollectionUtils.isEmpty(negotiationRows)) {
log.info("queryExtendedWarrantyLanTuNegotiationRows no rows found, merchantId:{}, reportDate:{}", merchantId, reportDate);
return Collections.emptyList();
......@@ -287,14 +296,17 @@ public class DailyReportDataService {
return Collections.emptyList();
}
DailyReportRecord latestRecord = queryLatestSubmittedRecord(merchantId, DailyReportTemplateTypeEnum.DISCUSSION.getValue(), reportDate);
if (latestRecord == null) {
List<DailyReportRecord> recordList = querySubmittedRecordsByDate(merchantId, DailyReportTemplateTypeEnum.DISCUSSION.getValue(), reportDate);
if (CollectionUtils.isEmpty(recordList)) {
log.info("queryExtendedWarrantyOtherNegotiationRows no record found, merchantId:{}, reportDate:{}", merchantId, reportDate);
return Collections.emptyList();
}
Map<Integer, List<DailyReportSubformData>> subformDataMap = querySubformDataMap(Collections.singletonList(latestRecord.getId()));
List<Map<String, String>> negotiationRows = buildExtendedWarrantyOtherNegotiationRows(latestRecord, subformDataMap);
Map<Integer, List<DailyReportSubformData>> subformDataMap = querySubformDataMap(recordList.stream()
.map(DailyReportRecord::getId)
.collect(Collectors.toList()));
List<Map<String, String>> negotiationRows = collectNegotiationRows(recordList,
record -> buildExtendedWarrantyOtherNegotiationRows(record, subformDataMap));
if (CollectionUtils.isEmpty(negotiationRows)) {
log.info("queryExtendedWarrantyOtherNegotiationRows no rows found, merchantId:{}, reportDate:{}", merchantId, reportDate);
return Collections.emptyList();
......@@ -362,6 +374,21 @@ public class DailyReportDataService {
}
/**
* 查询指定日期下当天所有已提交的日报记录
*/
private List<DailyReportRecord> querySubmittedRecordsByDate(Integer merchantId, Byte templateType, String reportDate) {
Example example = new Example(DailyReportRecord.class);
example.createCriteria()
.andEqualTo("deletedFlag", DeleteFlagEnum.N.getValue())
.andEqualTo("merchantId", merchantId)
.andEqualTo("templateType", templateType)
.andEqualTo("reportStatus", (byte) 1)
.andEqualTo("reportDate", reportDate);
example.setOrderByClause("id asc");
return dailyReportRecordMapper.selectByExample(example);
}
/**
* 今日汇总
*/
private LightChangeDailyReportData.DailyReportSummary buildTodaySummary(Integer recordId,
......@@ -1395,6 +1422,22 @@ public class DailyReportDataService {
return result;
}
private List<Map<String, String>> collectNegotiationRows(List<DailyReportRecord> recordList,
java.util.function.Function<DailyReportRecord, List<Map<String, String>>> rowBuilder) {
if (CollectionUtils.isEmpty(recordList) || rowBuilder == null) {
return Collections.emptyList();
}
List<Map<String, String>> result = new ArrayList<>();
for (DailyReportRecord record : recordList) {
List<Map<String, String>> rows = rowBuilder.apply(record);
if (CollectionUtils.isEmpty(rows)) {
continue;
}
result.addAll(rows);
}
return result;
}
private Map<String, String> buildSalesRow(String merchantName, String reportDate, String staffName,
Map<String, String> todayRow, List<Map<String, String>> monthRows) {
Map<String, String> row = new LinkedHashMap<>();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!