<if test='dateType=="1"'>
select sum(operation_balance) yValue,xname from (select user_id, operation_balance,DATE_FORMAT(create_date,'%Y')as xname from
user_wallet_record where transaction_type in('35','36','37','38') ) as vv
where user_id=#{userId,jdbcType=VARCHAR}
GROUP BY xname,user_id
</if>
<if test='dateType=="2"'>
select sum(operation_balance) yValue,xname from (select user_id, operation_balance,DATE_FORMAT(create_date,'%m')as xname from
user_wallet_record where transaction_type in('35','36','37','38')
and create_date >= #{StartDate} and create_date <![CDATA[<= ]]> #{EndDate}
) as vv where user_id=#{userId,jdbcType=VARCHAR}
GROUP BY xname,user_id
</if>
if ("1".equals(dateType)) {
listChart = this.userInfoMapper.ListChart(userId, dateType, null, null);
Map<String, String> stationStatisticalMap = listChart.stream().collect(Collectors.toMap(UserChartVo::getXName, UserChartVo::getYValue));
int aq = Integer.parseInt(listChart.get(0).getXName());
int ao = Integer.parseInt(listChart.get(listChart.size() - 1).getXName());
for (int i = aq; i <= ao; i++) {
String value = stationStatisticalMap.get(i + "");
if (stationStatisticalMap.keySet().equals(value)) {
continue;
} else if (StringUtils.isBlank(value)) {
listChart.add(new UserChartVo(userId, i + "", 0 + ""));
}
}
// 进行排序
listChart.sort(Comparator.comparingInt(o -> Integer.parseInt(o.getXName())));
效果如下:
if ("2".equals(dateType)) {
StartDate = DateUtils.getCurrentDateFormat("yyyy" + "-" + "0" + 1 + "-01" + " 00:00:01");
Integer max = DateUtils.getDaysByYearMonth(12);
EndDate = DateUtils.getCurrentDateFormat("yyyy" + "-" + 12 + "-" + max + " 23:59:59");
listChart = this.userInfoMapper.ListChart(userId, dateType, StartDate, EndDate);
Map<String, String> stationStatisticalMap = listChart.stream().collect(Collectors.toMap(UserChartVo::getXName, UserChartVo::getYValue));
int len = 00;
len = DateUtils.getYearMonth(new Date());
for (int i = 1; i <= len; i++) {
String value = stationStatisticalMap.get("0" + i + "");
if (stationStatisticalMap.keySet().equals(value)) {
continue;
} else if (StringUtils.isBlank(value)) {
listChart.add(new UserChartVo(userId, "0" + i + "", 0 + ""));
}
}
// 进行排序
listChart.sort(Comparator.comparingInt(o -> Integer.parseInt(o.getXName())));
}
效果如下: