demo

demo

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()) {

// 临时保存国内/海外/GOT的子项
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)) {
// GOT
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())) {
// GOT 放在前面
rows.addAll(0, list);
} else {
rows.addAll(list);
}
}
// 处理总计
// 这里注意,rows已经包含了合计,需要在getTotal中过滤下
rows.add(getTotal(rows));
rows.get(rows.size() - 1).setTrackName("总计");

return RestResponse.success(result);
}

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×