|
|
@@ -105,24 +105,24 @@ public class LiveRewardRecordServiceImpl implements ILiveRewardRecordService {
|
|
|
public R statistics(LiveRewardRecordVo param) {
|
|
|
SimpleDateFormat dayFormat = new SimpleDateFormat("yyyy-MM");
|
|
|
List<LiveRewardRecord> liveRewardRecords;
|
|
|
+ if(param.getCompanyId() == null) param.setCompanyId(0L);
|
|
|
if (param.getCompanyId() == 0L) {
|
|
|
liveRewardRecords = baseMapper.selectLiveRewardRecordListByStep(param.getStep());
|
|
|
} else {
|
|
|
liveRewardRecords = baseMapper.selectLiveRewardRecordListByCompanyId(param.getStep(), param.getCompanyId());
|
|
|
}
|
|
|
- Map<String, Map<String, BigDecimal>> monthLiveMap = liveRewardRecords.stream()
|
|
|
- // 第一层:按liveId分组
|
|
|
+ Map<Long, Map<String, BigDecimal>> monthLiveMap = liveRewardRecords.stream()
|
|
|
.collect(Collectors.groupingBy(
|
|
|
- LiveRewardRecord::getLiveName,
|
|
|
- // 第二层:在每个liveId分组内按天统计
|
|
|
+ LiveRewardRecord::getLiveId,
|
|
|
Collectors.groupingBy(
|
|
|
record -> dayFormat.format(record.getCreateTime()),
|
|
|
Collectors.reducing(BigDecimal.ZERO, LiveRewardRecord::getNum, BigDecimal::add)
|
|
|
)
|
|
|
));
|
|
|
+ Map<Long, LiveRewardRecord> compnayNameMap = liveRewardRecords.stream().collect(Collectors.toMap(LiveRewardRecord::getLiveId, item -> item,(existing, replacement) -> replacement ));
|
|
|
// 1. 生成完整的时间序列(天或月)
|
|
|
List<String> timeSeries = generateMonthTimeSeries(param.getStep(), dayFormat);
|
|
|
- List<LiveRewardRecordVo> dayLiveList = formatNestedMap(monthLiveMap, timeSeries);
|
|
|
+ List<LiveRewardRecordVo> dayLiveList = formatNestedMap(monthLiveMap, timeSeries,compnayNameMap);
|
|
|
return R.ok().put("data", dayLiveList).put("timeSeries",timeSeries);
|
|
|
}
|
|
|
|
|
|
@@ -133,17 +133,22 @@ public class LiveRewardRecordServiceImpl implements ILiveRewardRecordService {
|
|
|
|
|
|
|
|
|
// 将嵌套Map(liveId -> 时间->数值)转换为List<LiveTimeData>(每个liveId对应完整时间序列)
|
|
|
- private List<LiveRewardRecordVo> formatNestedMap(Map<String, Map<String, BigDecimal>> nestedMap, List<String> timeSeries) {
|
|
|
+ private List<LiveRewardRecordVo> formatNestedMap(Map<Long, Map<String, BigDecimal>> nestedMap, List<String> timeSeries,Map<Long, LiveRewardRecord> compnayNameMap) {
|
|
|
return nestedMap.entrySet().stream()
|
|
|
.map(entry -> {
|
|
|
- String key = entry.getKey();
|
|
|
- Map<String, BigDecimal> timeDataMap = entry.getValue();
|
|
|
- // 为当前liveId生成完整时间序列的数值列表(缺失补0)
|
|
|
- List<BigDecimal> dataList = timeSeries.stream()
|
|
|
- .map(time -> timeDataMap.getOrDefault(time, BigDecimal.ZERO))
|
|
|
- .collect(Collectors.toList());
|
|
|
- return new LiveRewardRecordVo(key, dataList);
|
|
|
+ Long liveId = entry.getKey();
|
|
|
+ LiveRewardRecord liveRewardRecord = compnayNameMap.get(liveId);
|
|
|
+ if (liveRewardRecord != null) {
|
|
|
+ Map<String, BigDecimal> timeDataMap = entry.getValue();
|
|
|
+ // 为当前liveId生成完整时间序列的数值列表(缺失补0)
|
|
|
+ List<BigDecimal> dataList = timeSeries.stream()
|
|
|
+ .map(time -> timeDataMap.getOrDefault(time, BigDecimal.ZERO))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return new LiveRewardRecordVo(liveRewardRecord.getLiveName(), dataList,liveRewardRecord.getCompanyName());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
})
|
|
|
+ .filter(Objects::nonNull)
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
// 生成从start到end的所有月份(yyyy-MM)
|