1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| public RestResponse<Map<String, Object>> trackTable(Map<String, Object> params) {
Map<String, Object> result = new HashMap<>(); result.put("header", getTableHeader()); List<TrackRow> rows = new ArrayList<>(); result.put("rows", rows);
String timeRange = params.get("time_range").toString(); String dateStart = params.get("start_date").toString(); String dateEnd;
String dateStartPre; String dateEndPre;
if ("month".equals(timeRange)) { dateEnd = DateUtil8.plusDays(DateUtil8.plusMonths(params.get("end_date").toString(), 1), -1); dateStartPre = DateUtil8.plusMonths(dateStart, -1); dateEndPre = DateUtil8.plusDays(dateStart, -1); } else { dateEnd = params.get("end_date").toString(); dateStartPre = DateUtil8.plusDays(dateStart, -7); dateEndPre = DateUtil8.plusDays(dateEnd, -7); } params.put("date_start", dateStart); params.put("date_end", dateEnd); prepareData(params);
Map<String, Map<String, List<Map<String, Object>>>> dataRevenue = revenueGrouped.get(); for (String key : dataRevenue.keySet()) {
List<TrackRow> list = new ArrayList<>(); for (String key2 : dataRevenue.get(key).keySet()) { TrackRow row = new TrackRow(); if ("0".equals(key)) { row.setTrackName(mrData.getGenre().get(key2).toString()); } else if ("1".equals(key)) { row.setTrackName(mrData.getRegion().get(key2).toString()); } else if ("2".equals(key)) { row.setTrackName("GOT");
}
double revenue = mrService.calculateRevenue(dataRevenue.get(key).get(key2), dateStart, dateEnd); double revenuePre = mrService.calculateRevenue(dataRevenue.get(key).get(key2), dateStartPre, dateEndPre);
row.setRevenue(revenue); row.setRevenueRatio(calRatio(revenue, revenuePre));
list.add(row); }
list = list.stream().sorted(Comparator.comparing(TrackRow::getRevenue).reversed()).collect(toList());
list.add(getTotal(list));
if ("2".equals(key.toString())) { rows.addAll(0, list); } else { rows.addAll(list); } } rows.add(getTotal(rows)); rows.get(rows.size() - 1).setTrackName("总计");
return RestResponse.success(result); }
|