遍历填充没有订单的数据

 1 <select id="orderDetail" resultType="java.util.Map">
 2         SELECT
 3             DATE_FORMAT(o.create_time,'%Y-%m-%d') createTime,
 4             SUM(o.amount) amount,
 5             SUM(rep.money) money,
 6             SUM(arep.money) arepMoney
 7         FROM
 8           orders o
 9         LEFT JOIN
10           repayment rep
11         ON
12           o.no = rep.no
13         LEFT JOIN
14           applets_repayment arep
15         ON
16           o.no = arep.no
17         <where>
18             o.status
19             IN
20             <foreach collection="statusList" index="index" item="item"
21                      separator="," open="(" close=")">
22                 #{item}
23             </foreach>
24             AND
25               o.create_time
26             BETWEEN
27               #{startTime}
28             AND
29               #{endTime}
30             <if test="channel != null">
31                 AND o.channel = #{channel}
32             </if>
33         </where>
34         GROUP BY
35           DATE_FORMAT(create_time,'%Y-%m-%d')
36     </select>

 

 1 // 间段内的各个渠道订单成交额和实收金额
 2         amountList = ordersMapper.orderDetail(formatStartTime, formatEndTime, channel, statusList);
 3         List<Map<String, Object>> resultList = new ArrayList<>();
 4         Map<String, Object> resultMap = null;
 5         // 遍历填充没有订单的数据
 6         SimpleDateFormat sdformat = new SimpleDateFormat("yyyy-MM-dd");
 7         String startTimeFormat = sdformat.format(startTime);
 8         String endTimeFormat = sdformat.format(endTime);
 9         String tempTime = startTimeFormat;
10         // 遍历数据
11         while (tempTime.compareTo(endTimeFormat) <= 0) {
12             boolean flag = false;
13             for (Map<String, Object> map : amountList) {
14                 resultMap = new HashMap<>();
15                 BigDecimal arepMoney = (BigDecimal) map.get("arepMoney");
16                 if (arepMoney == null) {
17                     arepMoney = new BigDecimal(0);
18                 }
19                 BigDecimal money = (BigDecimal) map.get("money");
20                 if (money == null) {
21                     money = new BigDecimal(0);
22                 }
23                 BigDecimal amount = (BigDecimal) map.get("amount");
24                 if (amount == null) {
25                     amount = new BigDecimal(0);
26                 }
27                 if (tempTime.equals(map.get("createTime"))) {
28                     BigDecimal payMoney = money.add(arepMoney);
29                     resultMap.put("amount", amount);
30                     resultMap.put("payMoney", payMoney);
31                     resultMap.put("createTime", map.get("createTime"));
32                     resultList.add(resultMap);
33                     flag = true;
34                 }
35             }
36             if (flag == false) {
37                 resultMap.put("amount", 0);
38                 resultMap.put("payMoney", 0);
39                 resultMap.put("createTime", tempTime);
40                 resultList.add(resultMap);
41             }
42             Date parseTemp = null;
43             try {
44                 parseTemp = sdformat.parse(tempTime);
45             } catch (ParseException e) {
46                 e.printStackTrace();
47             }
48             tempTime = sdformat.format(parseTemp.getTime() + 3600 * 24 * 1000);
49         }

 

posted @ 2018-11-16 17:27  huohuohiahia  阅读(346)  评论(0编辑  收藏  举报