PassengerStatisticController.java
3.84 KB
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
79
80
81
82
83
84
85
86
package com.bsth.controller.report;
import com.bsth.controller.BaseController;
import com.bsth.entity.report.PassengerStatistic;
import com.bsth.service.report.PassengerStatisticService;
import com.bsth.service.report.ReportService;
import com.bsth.util.ReportUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;
import java.util.*;
@RestController
@RequestMapping("/api/passenger-statistic")
public class PassengerStatisticController extends BaseController<PassengerStatistic, Integer> {
@Autowired
private PassengerStatisticService passengerStatisticService;
private ObjectMapper mapper = new ObjectMapper();
@RequestMapping(value = "/groupByStation",method = RequestMethod.GET)
public List<PassengerStatistic> groupByStation(PassengerStatistic passengerStatistic) {
return passengerStatisticService.groupByStation(passengerStatistic);
}
@RequestMapping(value = "/groupByStation/export",method = RequestMethod.GET)
public Map<String, Object> groupByStationExport(PassengerStatistic passengerStatistic) {
List<Iterator<?>> iterators = new ArrayList<>();
ReportUtils reportUtils = new ReportUtils();
List<PassengerStatistic> list = passengerStatisticService.groupByStation(passengerStatistic);
List<Map<String, Object>> maps = new ArrayList<>();
int count = 1;
for (PassengerStatistic ps : list) {
Map<String, Object> map = mapper.convertValue(ps, Map.class);
map.put("i", count++);
maps.add(map);
}
try {
iterators.add(maps.iterator());
String path = this.getClass().getResource("/").getPath() + "static/pages/forms";
reportUtils.excelReplace(iterators, new Object[] { new HashMap<>() }, String.format("%s/mould/passenger-statistic-station.xls", path),
String.format("%s/export/%s至%s-客流统计(站点).xls", path, passengerStatistic.getRqBegin(), passengerStatistic.getRqEnd()));
} catch (Exception e) {
e.printStackTrace();
}
return new HashMap<>();
}
@RequestMapping(value = "/groupByVehicle",method = RequestMethod.GET)
public List<PassengerStatistic> groupByVehicle(PassengerStatistic passengerStatistic) {
return passengerStatisticService.groupByVehicle(passengerStatistic);
}
@RequestMapping(value = "/groupByVehicle/export",method = RequestMethod.GET)
public Map<String, Object> groupByVehicleExport(PassengerStatistic passengerStatistic) {
List<Iterator<?>> iterators = new ArrayList<>();
ReportUtils reportUtils = new ReportUtils();
List<PassengerStatistic> list = passengerStatisticService.groupByVehicle(passengerStatistic);
List<Map<String, Object>> maps = new ArrayList<>();
int count = 1;
for (PassengerStatistic ps : list) {
Map<String, Object> map = mapper.convertValue(ps, Map.class);
map.put("i", count++);
maps.add(map);
}
try {
iterators.add(maps.iterator());
String path = this.getClass().getResource("/").getPath() + "static/pages/forms";
reportUtils.excelReplace(iterators, new Object[] { new HashMap<>() }, String.format("%s/mould/passenger-statistic-vehicle.xls", path),
String.format("%s/export/%s至%s-客流统计(车辆).xls", path, passengerStatistic.getRqBegin(), passengerStatistic.getRqEnd()));
} catch (Exception e) {
e.printStackTrace();
}
return new HashMap<>();
}
}