# dwz table增加总计、小计

+关注继续查看

<select id="getDepositListBySelective" resultType="hashmap" parameterType="map">
COALESCE (d.BeginMoney, 0) AS beginmoney,
COALESCE (d.InMoney,0) AS inmoney ,

<select id="getDeposittotalListBySelective" resultType="hashmap" parameterType="map">
COALESCE (ROUND(SUM(d.BeginMoney),2), 0) AS beginmoney,
COALESCE (ROUND(SUM(d.InMoney),2),0) AS inmoney ,

List dailyDepositlist = listWithSumByTwoZero(
this.reportMapper.getDepositListBySelective(vo, vo.createRowBounds()),
this.reportMapper.getDeposittotalListBySelective(vo));

protected List listWithSumByTwoZero(List preList, List totalList) {
// 获取总计数据，获知那一列需要进行小记
Map totalMap = (Map) totalList.get(0);
// 获取总计的key
Iterator keySet = totalMap.keySet().iterator();
// 创建一行小计
Map subTotalMap = new HashMap();
// 统计小计需要计算的列
Map<String, BigDecimal> shouldSumMap = new HashMap<String, BigDecimal>();
List<String> shouldSumList = new ArrayList<String>();
// 初始化
while (keySet.hasNext()) {
String key = (String) keySet.next();
Object totalValue = totalMap.get(key);
if (totalValue.equals("总计：")) {
subTotalMap.put(key, "小计：");
}
// 如果当前列不需要统计
else if (totalValue.equals("")) {
subTotalMap.put(key, totalValue);
} else {
shouldSumMap.put(key, BigDecimal.ZERO);
subTotalMap.put(key, 0);
}
}
// 如果获取的list不为空
if (preList != null && preList.size() > 0) {
// 对需要统计小计的进行计算
for (int i = 0; i < preList.size(); i++) {
Map preMap = (Map) preList.get(i);
for (String key : shouldSumList) {
BigDecimal temp = shouldSumMap.get(key);
BigDecimal preDecimal = new BigDecimal(preMap.get(key).toString());
shouldSumMap.put(key, temp);
}
}
}
// 计算过的数据进行更新
for (String key : shouldSumMap.keySet()) {
subTotalMap.put(key, shouldSumMap.get(key));
}
return preList;
}

10486 0

11950 0

11778 0

12300 0

4573 0

7343 0
+关注

1084

0

《2021云上架构与运维峰会演讲合集》

《零基础CSS入门教程》

《零基础HTML入门教程》