Commit 27be2244363f35049f1c6c5a0454f897f4289ae0

Authored by atao
1 parent 339bbf05

提交controller

src/main/java/com/zteits/irain/portal/web/parkinglotcloudplatform/datastatistic/VehicleFlowStatisticController.java
... ... @@ -7,28 +7,15 @@ import java.util.Calendar;
7 7 import java.util.Date;
8 8 import java.util.List;
9 9 import java.util.Map;
10   -import java.util.Map.Entry;
11 10  
12 11 import javax.servlet.http.HttpServletRequest;
13 12 import javax.servlet.http.HttpServletResponse;
14 13 import javax.servlet.http.HttpSession;
15 14  
16   -import org.apache.poi.xssf.usermodel.XSSFSheet;
17   -import org.slf4j.Logger;
18   -import org.slf4j.LoggerFactory;
19   -import org.springframework.beans.factory.annotation.Autowired;
20   -import org.springframework.beans.factory.annotation.Value;
21   -import org.springframework.stereotype.Controller;
22   -import org.springframework.web.bind.annotation.GetMapping;
23   -import org.springframework.web.bind.annotation.PostMapping;
24   -import org.springframework.web.bind.annotation.RequestBody;
25   -import org.springframework.web.bind.annotation.RequestMapping;
26   -import org.springframework.web.bind.annotation.RequestParam;
27   -import org.springframework.web.bind.annotation.ResponseBody;
28   -
29 15 import com.alibaba.dubbo.common.utils.CollectionUtils;
30 16 import com.alibaba.fastjson.JSON;
31 17 import com.alibaba.fastjson.JSONObject;
  18 +
32 19 import com.clouds.common.entity.UserInfo;
33 20 import com.clouds.common.utils.DateUtil;
34 21 import com.clouds.common.utils.ResultUtils;
... ... @@ -49,367 +36,370 @@ import com.zteits.clouds.api.apibase.exception.BizException;
49 36 import com.zteits.clouds.api.dto.park.dto.ParkingLotUseStatisticDTO;
50 37 import com.zteits.clouds.api.dto.park.dto.ParkingLotUseStatisticMaxAndMinDTO;
51 38 import com.zteits.clouds.api.dto.park.param.ParkingLotUseStatisticForPageRequest;
52   -import com.zteits.clouds.api.dto.pay.param.TdCompanyParkQueryRequest;
53 39 import com.zteits.clouds.api.service.park.ParkingLotUseStatisticService;
54 40 import com.zteits.clouds.api.service.pay.TdCustCompanyService;
55 41 import com.zteits.irain.portal.constant.ParkConstant;
56   -import com.zteits.irain.portal.vo.parkinglotcloudplatform.datastatistic.BerthsAndFlowLineChartVO;
57 42 import com.zteits.irain.portal.vo.parkinglotcloudplatform.datastatistic.LineChartVO;
58 43 import com.zteits.irain.portal.vo.parkinglotcloudplatform.datastatistic.LineChartVO.SerieVO;
59   -
60 44 import io.swagger.annotations.Api;
61 45 import io.swagger.annotations.ApiOperation;
  46 +import org.apache.poi.xssf.usermodel.XSSFSheet;
  47 +import org.slf4j.Logger;
  48 +import org.slf4j.LoggerFactory;
  49 +import org.springframework.beans.factory.annotation.Autowired;
  50 +import org.springframework.beans.factory.annotation.Value;
  51 +import org.springframework.stereotype.Controller;
  52 +import org.springframework.web.bind.annotation.GetMapping;
  53 +import org.springframework.web.bind.annotation.PostMapping;
  54 +import org.springframework.web.bind.annotation.RequestBody;
  55 +import org.springframework.web.bind.annotation.RequestMapping;
  56 +import org.springframework.web.bind.annotation.RequestParam;
  57 +import org.springframework.web.bind.annotation.ResponseBody;
62 58  
63 59 /**
64   - *
65 60 * 停车场车流量数据统计 Copyright: Copyright (c) 2017 zteits
66   - *
  61 + *
67 62 * @ClassName: ParkingLotUseStatisticController.java
68 63 * @Description:
69 64 * @version: v1.0.0
70 65 * @author: langlw
71 66 * @date: 2017年6月14日 下午3:02:39 Modification History: Date Author Version
72   - * Description ---------------------------------------------------------*
73   - * 2017年6月14日 langlw v1.0.0 创建
  67 + * Description ---------------------------------------------------------*
  68 + * 2017年6月14日 langlw v1.0.0 创建
74 69 */
75 70 @Api(value = "停车场车流量数据统计", description = "停车场车流量数据统计")
76 71 @Controller
77 72 @RequestMapping(value = "/VehicleFlowStatistic")
78 73 public class VehicleFlowStatisticController extends BizController {
79   - private Logger logger = LoggerFactory.getLogger(VehicleFlowStatisticController.class);
80   -
81   - @Value("${project.syscode}")
82   - private String sysCode;
83   -
84   - @Autowired
85   - private ParkingLotUseStatisticService parkingLotStatisticService;
86   - @Autowired
87   - private HttpSession session;
88   - @Autowired
89   - private SessionCommUtil sessionCommUtil;
90   - @Autowired
91   - private TdCustCompanyService tdCustCompanyService;
92   -
93   - @ApiOperation("分页查询车流量数据统计车位总流量")
94   - @PostMapping("getVehicleFlowStatisticForPage")
95   - @ResponseBody
96   - public BizResultVO<EasyUIDataGridVO<ParkingLotUseStatisticDTO>> queryParkingLotUseStatisticForPage(
97   - @RequestBody ParkingLotUseStatisticForPageRequest request) throws Exception {
98   - if (null == request.getBeginTime() || null == request.getEndTime()) {
99   - throw new BizException(ErrorType.PARAMM_NULL, "开始时间和结束时间");
100   - }
101   - Calendar beginc = Calendar.getInstance();
102   - beginc.setTime(request.getBeginTime());
103   - int beginYear = beginc.get(Calendar.YEAR);
104   - int beginMonth = beginc.get(Calendar.MONTH) + 1;
105   - int beginDay = beginc.get(Calendar.DAY_OF_MONTH);
106   -
107   - Calendar endc = Calendar.getInstance();
108   - endc.setTime(request.getEndTime());
109   - int endYear = endc.get(Calendar.YEAR);
110   - int endMonth = endc.get(Calendar.MONTH) + 1;
111   - int endDay = endc.get(Calendar.DAY_OF_MONTH);
112   -
113   - if (beginYear == endYear && beginMonth == endMonth && beginDay == endDay) {
114   - // 2表示按每小时统计
115   - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR);
116   - } else {
117   - // 3表示按每天统计
118   - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY);
119   - }
120   -
121   - BizResult<PageBean<ParkingLotUseStatisticDTO>> bizResult = parkingLotStatisticService
122   - .queryParkingLotUseStatisticForPage(request);
123   - return returnJqGridData(bizResult, ParkingLotUseStatisticDTO.class);
124   - }
125   -
126   - @ApiOperation("查询车流量最大值与最小值")
127   - @PostMapping("getVehicleFlowMaxAndMin")
128   - @ResponseBody
129   - public BizResultVO<ParkingLotUseStatisticMaxAndMinDTO> QueryParkingLotUseStatisticMaxAndMin(
130   - @RequestBody ParkingLotUseStatisticForPageRequest request) {
131   - Calendar beginc = Calendar.getInstance();
132   - beginc.setTime(request.getBeginTime());
133   - int beginYear = beginc.get(Calendar.YEAR);
134   - int beginMonth = beginc.get(Calendar.MONTH) + 1;
135   - int beginDay = beginc.get(Calendar.DAY_OF_MONTH);
136   -
137   - Calendar endc = Calendar.getInstance();
138   - endc.setTime(request.getEndTime());
139   - int endYear = endc.get(Calendar.YEAR);
140   - int endMonth = endc.get(Calendar.MONTH) + 1;
141   - int endDay = endc.get(Calendar.DAY_OF_MONTH);
142   -
143   - if (beginYear == endYear && beginMonth == endMonth && beginDay == endDay) {
144   - // 2表示按每小时统计
145   - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR);
146   - } else {
147   - // 3表示按每天统计
148   - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY);
149   - }
150   - BizResult<ParkingLotUseStatisticMaxAndMinDTO> bizResult = parkingLotStatisticService
151   - .QueryVehicleFlowStatisticMaxAndMin(request);
152   - return new BizResultVO<>(bizResult);
153   - }
154   -
155   - @ApiOperation("导出车流量数据统计excel")
156   - @GetMapping("exportVehicleFlowStatisticExcel")
157   - public void excelParkingLotUseStatistic(@RequestParam String beginTime, @RequestParam String endTime,
158   - @RequestParam String plNos, HttpServletRequest requests, HttpServletResponse response) {
159   - ParkingLotUseStatisticForPageRequest request = new ParkingLotUseStatisticForPageRequest();
160   - request.setSysCode(sysCode);
161   - request.setBeginTime(DateUtil.to_date(beginTime, DateUtil.DATETIME_FORMAT));
162   - request.setEndTime(DateUtil.to_date(endTime, DateUtil.DATETIME_FORMAT));
163   - List<String> plNoslist = new ArrayList<>();
164   - plNoslist.add(plNos);
165   - request.setPlNos(plNoslist);
166   - request.setBaseRequest(new BaseInfo(1, 0));
167   - Calendar beginc = Calendar.getInstance();
168   - beginc.setTime(request.getBeginTime());
169   - int beginYear = beginc.get(Calendar.YEAR);
170   - int beginMonth = beginc.get(Calendar.MONTH) + 1;
171   - int beginDay = beginc.get(Calendar.DAY_OF_MONTH);
172   -
173   - Calendar endc = Calendar.getInstance();
174   - endc.setTime(request.getEndTime());
175   - int endYear = endc.get(Calendar.YEAR);
176   - int endMonth = endc.get(Calendar.MONTH) + 1;
177   - int endDay = endc.get(Calendar.DAY_OF_MONTH);
178   -
179   - if (beginYear == endYear && beginMonth == endMonth && beginDay == endDay) {
180   - // 2表示按每小时统计
181   - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR);
182   - } else {
183   - // 3表示按每天统计
184   - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY);
185   - }
186   - BizResult<PageBean<ParkingLotUseStatisticDTO>> bizResult = parkingLotStatisticService
187   - .queryParkingLotUseStatisticForPage(request);
188   - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
189   - SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
190   - String[] title = new String[] { "时间", "总车流量", "临时车流量", "固定车流量" };
191   - String sheetName = "车流量管理";
192   - String fileName = "车流量管理" + format2.format(new Date());
193   - // 1.创建excel信息
194   - XSSFSheet workSheet = ExcelUtil.createExcel(sheetName);
195   - // 2.设置excel表头和表体
196   - Layouter.buildReport(workSheet, title, 0, 0);
197   - // 3.填充数据
198   - List<Object[]> contentList = new ArrayList<Object[]>();
199   - List<ParkingLotUseStatisticDTO> list = new ArrayList<>();
200   - if (CollectionUtils.isNotEmpty(bizResult.getData().getDataList())) {
201   - list = bizResult.getData().getDataList();
202   - }
203   - for (ParkingLotUseStatisticDTO e : list) {
204   - Object[] obj = new Object[title.length];
205   - int index = 0;
206   - obj[index++] = format.format(e.getStatisticBeginTime());
207   - obj[index++] = e.getVehicleFlow();
208   - obj[index++] = e.getTmpVehicleFlow();
209   - obj[index++] = e.getFixVehicleFlow();
210   - contentList.add(obj);
211   - }
212   - ExcleFillDateManager fillUserManager = new ExcleFillDateManager();
213   - fillUserManager.fillSalesOrga(workSheet, title, contentList, 2);
214   - // 4.excel输出配置
215   - ExcelUtil.write(response, workSheet, fileName);
216   - }
217   -
218   - /**
219   - * 根据时间获取车流量折线图
220   - *
221   - * @param request
222   - * @return
223   - * @throws Exception
224   - */
225   - @ApiOperation("根据时间获取车流量折线图")
226   - @PostMapping("getVehicleFlowForLineChart")
227   - @ResponseBody
228   - public BizResultVO<LineChartVO> getVehicleFlowForLineChart(
229   - @RequestBody ParkingLotUseStatisticForPageRequest request) throws Exception {
230   -
231   - if (null == request.getBeginTime() || null == request.getEndTime()) {
232   - throw new BizException(ErrorType.PARAMM_NULL, "开始时间和结束时间");
233   - }
234   - // 2.调用接口查询当前登录人管辖的停车场名称
235   - UserInfo userInfo = sessionCommUtil.getUserInfo();
236   - List<String> plNos = new ArrayList<>();
237   - if (userInfo != null) {
238   - TdCompanyParkQueryRequest tdCompanyParkQueryRequest = new TdCompanyParkQueryRequest();
239   - tdCompanyParkQueryRequest.setCustIdList(userInfo.getOrgIds());
240   - tdCompanyParkQueryRequest.setSessionId(session.getId());
241   - tdCompanyParkQueryRequest.setSysCode(sysCode);
242   - BizResult<List<String>> bizResult = tdCustCompanyService.queryParkNoByCustIds(tdCompanyParkQueryRequest);
243   - // 拥有的停车场编号
244   - plNos = ResultUtils.getBizResultData(bizResult);
245   - }
246   - if (CollectionUtils.isEmpty(plNos)) {
247   - throw new BizException(ErrorType.PARK_LOT_NOT_EXISTS, "停车场plnos不存在");
248   - }
249   - request.setPlNos(plNos);
250   -
251   - logger.info("根据停车场编号获取该停车场今日车流量和车位折线图");
252   - Calendar beginTime = Calendar.getInstance();
253   - beginTime.setTime(request.getBeginTime());
254   - int year=beginTime.get(Calendar.YEAR);
255   - Calendar endTime = Calendar.getInstance();
256   - endTime.setTime(request.getEndTime());
257   -
258   - Long dayDifference = DateUtil.getTimeDifference(new Timestamp(request.getEndTime().getTime()),
259   - new Timestamp(request.getBeginTime().getTime()));
260   - List<String> xAxisData = Lists.newArrayList();
261   - request.setBaseRequest(new BaseInfo(1, 0));
262   - String dateType = "";
263   -
264   - if (dayDifference == 0L) {
265   - // 1小时为一个时间戳
266   - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR);
267   - int totaltimestampCount = endTime.get(Calendar.HOUR_OF_DAY);
268   - String day = "";
269   - String month = "";
270   - for (int i = 0; i < dayDifference.intValue(); i++) {
271   - beginTime.add(Calendar.DAY_OF_MONTH, 1);
272   - int beginMonth = beginTime.get(Calendar.MONTH) + 1;
273   - int beginDay = beginTime.get(Calendar.DAY_OF_MONTH);
274   - month = String.format("%02d", (beginMonth));
275   - day = String.format("%02d", (beginDay));
276   - for (int j = 0; j < totaltimestampCount; j++) {
277   - String hour = String.format("%02d", (j));
278   - xAxisData.add(year+"-"+month + "-" + day + " " + hour);
279   - }
280   - }
281   - dateType = "yyyy-MM-dd HH";
282   - LineChartVO vehicleFlows = getVehicleFlows(request, xAxisData, dateType);
283   - return new BizResultVO<LineChartVO>().setData(vehicleFlows);
284   -
285   - } else if (dayDifference <= 3L) {
286   - // 1小时为一个时间戳
287   - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR);
288   - int totaltimestampCount = endTime.get(Calendar.HOUR_OF_DAY);
289   - String day = "";
290   - String month = "";
291   - for (int i = 0; i < dayDifference.intValue(); i++) {
292   - beginTime.add(Calendar.DAY_OF_MONTH, 1);
293   - int beginMonth = beginTime.get(Calendar.MONTH) + 1;
294   - int beginDay = beginTime.get(Calendar.DAY_OF_MONTH);
295   - month = String.format("%02d", (beginMonth));
296   - day = String.format("%02d", (beginDay));
297   - for (int j = 0; j < totaltimestampCount; j++) {
298   - String hour = String.format("%02d", (j));
299   - xAxisData.add(year+"-"+month + "-" + day + " " + hour);
300   - }
301   - }
302   - dateType = "yyyy-MM-dd HH";
303   - LineChartVO vehicleFlows = getVehicleFlows(request, xAxisData, dateType);
304   - return new BizResultVO<LineChartVO>().setData(vehicleFlows);
305   -
306   - } else {
307   - // 1天为一个时间戳
308   - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY);
309   - for (int i = 0; i < dayDifference.intValue(); i++) {
310   - beginTime.add(Calendar.DAY_OF_MONTH, 1);
311   - int beginMonth = beginTime.get(Calendar.MONTH) + 1;
312   - int beginDay = beginTime.get(Calendar.DAY_OF_MONTH);
313   - String month = String.format("%02d", (beginMonth));
314   - String day = String.format("%02d", (beginDay));
315   - xAxisData.add(year+"-"+month + "-" + day);
316   -
317   - }
318   - dateType = "yyyy-MM-dd";
319   - LineChartVO vehicleFlows = getVehicleFlows(request, xAxisData, dateType);
320   - return new BizResultVO<LineChartVO>().setData(vehicleFlows);
321   -
322   - }
323   -
324   - }
325   -
326   - private LineChartVO getVehicleFlows(ParkingLotUseStatisticForPageRequest request, List<String> xAxisData,
327   - String dateType) {
328   - // 调用后场服务
329   - logger.info("调用DUBBO服务入参:" + JSON.toJSONString(request));
330   - BizResult<PageBean<ParkingLotUseStatisticDTO>> bizResult = parkingLotStatisticService
331   - .queryParkingLotUseStatisticForPage(request);
332   - PageBean<ParkingLotUseStatisticDTO> pageBean = ResultUtils.getBizResultData(bizResult);
333   - List<ParkingLotUseStatisticDTO> useStatisticDTOs = Lists.newArrayList();
334   - if (pageBean != null) {
335   - useStatisticDTOs = pageBean.getDataList();
336   - }
337   -
338   - // 保存固定车流量,时间戳和车流量对应关系
339   - Map<String, Integer> fixVehicleFlowMap = Maps.newHashMap();
340   - // 保存临时车流量,时间戳和车流量对应关系
341   - Map<String, Integer> tmpVehicleFlowMap = Maps.newHashMap();
342   - // 停车场编号和名称对应关系
343   - Map<String, String> parkNameMap = Maps.newHashMap();
344   - // 通过停车场,和统计时间分组
345   - // Map<String, Map<String, Double>> parkLotMap = Maps.newHashMap();
346   - if (!CollectionUtils.isEmpty(useStatisticDTOs)) {
347   - for (ParkingLotUseStatisticDTO statisticDTO : useStatisticDTOs) {
348   - String key = statisticDTO.getPlNo();
349   - parkNameMap.put(key, statisticDTO.getPlName());
350   - String statisBeginTime = DateUtil.getDateString(statisticDTO.getStatisticBeginTime(), dateType);
351   - // 保存固定车流量和临时车流量
352   - fixVehicleFlowMap.put(statisBeginTime,
353   - (fixVehicleFlowMap.get(statisBeginTime) == null ? 0 : fixVehicleFlowMap.get(statisBeginTime))
354   - + statisticDTO.getFixVehicleFlow());
355   - tmpVehicleFlowMap.put(statisBeginTime,
356   - (tmpVehicleFlowMap.get(statisBeginTime) == null ? 0 : tmpVehicleFlowMap.get(statisBeginTime))
357   - + statisticDTO.getTmpVehicleFlow());
358   - }
359   - }
360   -
361   - // 封装车流量统计
362   - LineChartVO vehicleFlows = new LineChartVO();
363   - List<String> vehicleFlows_legendData = Lists.newArrayList();
364   - vehicleFlows_legendData.add("临时车");
365   - vehicleFlows_legendData.add("固定车");
366   - vehicleFlows.setLegendData(vehicleFlows_legendData);
367   - vehicleFlows.setxAxisData(xAxisData);
368   - List<SerieVO> vehicleSeries = Lists.newArrayList();
369   - // 固定车
370   - SerieVO fixSerieVo = new SerieVO();
371   - fixSerieVo.setName("固定车");
372   - List<Integer> fixSerieVoData = Lists.newArrayList();
373   - // 临时车
374   - SerieVO tmpSerieVo = new SerieVO();
375   - tmpSerieVo.setName("临时车");
376   - List<Integer> tmpSerieVoData = Lists.newArrayList();
377   - // 保存上一次的临时车值,当某个时间点没有数据时,则保持和上次一致
378   - Integer lastfixFlow = 0;
379   - Integer lasttmpFlow = 0;
380   - for (String timestamp : xAxisData) {
381   -
382   - if (fixVehicleFlowMap.containsKey(timestamp)) {
383   - lastfixFlow = fixVehicleFlowMap.get(timestamp).intValue();
384   - } else {
385   - lastfixFlow = 0;
386   - }
387   - fixSerieVoData.add(lastfixFlow);
388   -
389   - if (tmpVehicleFlowMap.containsKey(timestamp)) {
390   - lasttmpFlow = tmpVehicleFlowMap.get(timestamp).intValue();
391   - } else {
392   - lasttmpFlow = 0;
393   - }
394   - tmpSerieVoData.add(lasttmpFlow);
395   - }
396   - fixSerieVo.setData(fixSerieVoData);
397   - vehicleSeries.add(fixSerieVo);
398   - tmpSerieVo.setData(tmpSerieVoData);
399   - vehicleSeries.add(tmpSerieVo);
400   -
401   - vehicleFlows.setSeries(vehicleSeries);
402   - return vehicleFlows;
403   - }
404   -
405   - public static void main(String[] args) {
406   - String json = "{\"id\":\"1\",\"platform\":\"android\",\"parameter\":{\"drid\":\"177277364\",\"sex\":\"1\",\"type\":\"2\",\"creatorname\":\"Mrw\",\"username\":\"jack\",\"pwd\":\"123456\",\"remark\":\"平板用户\",\"createtime\":\"2017-07-24 23:59:59\"}}";
407   - JSONObject object = (JSONObject) JSONObject.parse(json);
408   - System.out.println(object.get("id"));
409   - System.out.println(object.get("platform"));
410   - JSONObject parameter = (JSONObject) object.get("parameter");
411   - System.out.println(parameter.get("drid"));
412   - System.out.println(parameter.get("sex"));
413   - }
  74 + private Logger logger = LoggerFactory.getLogger(VehicleFlowStatisticController.class);
  75 +
  76 + @Value("${project.syscode}")
  77 + private String sysCode;
  78 +
  79 + @Autowired
  80 + private ParkingLotUseStatisticService parkingLotStatisticService;
  81 + @Autowired
  82 + private HttpSession session;
  83 + @Autowired
  84 + private SessionCommUtil sessionCommUtil;
  85 + @Autowired
  86 + private TdCustCompanyService tdCustCompanyService;
  87 +
  88 + @ApiOperation("分页查询车流量数据统计车位总流量")
  89 + @PostMapping("getVehicleFlowStatisticForPage")
  90 + @ResponseBody
  91 + public BizResultVO<EasyUIDataGridVO<ParkingLotUseStatisticDTO>> queryParkingLotUseStatisticForPage(
  92 + @RequestBody ParkingLotUseStatisticForPageRequest request) throws Exception {
  93 + if (null == request.getBeginTime() || null == request.getEndTime()) {
  94 + throw new BizException(ErrorType.PARAMM_NULL, "开始时间和结束时间");
  95 + }
  96 + Calendar beginc = Calendar.getInstance();
  97 + beginc.setTime(request.getBeginTime());
  98 + int beginYear = beginc.get(Calendar.YEAR);
  99 + int beginMonth = beginc.get(Calendar.MONTH) + 1;
  100 + int beginDay = beginc.get(Calendar.DAY_OF_MONTH);
  101 +
  102 + Calendar endc = Calendar.getInstance();
  103 + endc.setTime(request.getEndTime());
  104 + int endYear = endc.get(Calendar.YEAR);
  105 + int endMonth = endc.get(Calendar.MONTH) + 1;
  106 + int endDay = endc.get(Calendar.DAY_OF_MONTH);
  107 +
  108 + if (beginYear == endYear && beginMonth == endMonth && beginDay == endDay) {
  109 + // 2表示按每小时统计
  110 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR);
  111 + } else {
  112 + // 3表示按每天统计
  113 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY);
  114 + }
  115 +
  116 + BizResult<PageBean<ParkingLotUseStatisticDTO>> bizResult = parkingLotStatisticService
  117 + .queryParkingLotUseStatisticForPage(request);
  118 + return returnJqGridData(bizResult, ParkingLotUseStatisticDTO.class);
  119 + }
  120 +
  121 + @ApiOperation("查询车流量最大值与最小值")
  122 + @PostMapping("getVehicleFlowMaxAndMin")
  123 + @ResponseBody
  124 + public BizResultVO<ParkingLotUseStatisticMaxAndMinDTO> QueryParkingLotUseStatisticMaxAndMin(
  125 + @RequestBody ParkingLotUseStatisticForPageRequest request) {
  126 + Calendar beginc = Calendar.getInstance();
  127 + beginc.setTime(request.getBeginTime());
  128 + int beginYear = beginc.get(Calendar.YEAR);
  129 + int beginMonth = beginc.get(Calendar.MONTH) + 1;
  130 + int beginDay = beginc.get(Calendar.DAY_OF_MONTH);
  131 +
  132 + Calendar endc = Calendar.getInstance();
  133 + endc.setTime(request.getEndTime());
  134 + int endYear = endc.get(Calendar.YEAR);
  135 + int endMonth = endc.get(Calendar.MONTH) + 1;
  136 + int endDay = endc.get(Calendar.DAY_OF_MONTH);
  137 +
  138 + if (beginYear == endYear && beginMonth == endMonth && beginDay == endDay) {
  139 + // 2表示按每小时统计
  140 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR);
  141 + } else {
  142 + // 3表示按每天统计
  143 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY);
  144 + }
  145 + BizResult<ParkingLotUseStatisticMaxAndMinDTO> bizResult = parkingLotStatisticService
  146 + .QueryVehicleFlowStatisticMaxAndMin(request);
  147 + return new BizResultVO<>(bizResult);
  148 + }
  149 +
  150 + @ApiOperation("导出车流量数据统计excel")
  151 + @GetMapping("exportVehicleFlowStatisticExcel")
  152 + public void excelParkingLotUseStatistic(@RequestParam String beginTime, @RequestParam String endTime,
  153 + @RequestParam String plNos, HttpServletRequest requests, HttpServletResponse response) {
  154 + ParkingLotUseStatisticForPageRequest request = new ParkingLotUseStatisticForPageRequest();
  155 + request.setSysCode(sysCode);
  156 + request.setBeginTime(DateUtil.to_date(beginTime, DateUtil.DATETIME_FORMAT));
  157 + request.setEndTime(DateUtil.to_date(endTime, DateUtil.DATETIME_FORMAT));
  158 + List<String> plNoslist = new ArrayList<>();
  159 + plNoslist.add(plNos);
  160 + request.setPlNos(plNoslist);
  161 + request.setBaseRequest(new BaseInfo(1, 0));
  162 + Calendar beginc = Calendar.getInstance();
  163 + beginc.setTime(request.getBeginTime());
  164 + int beginYear = beginc.get(Calendar.YEAR);
  165 + int beginMonth = beginc.get(Calendar.MONTH) + 1;
  166 + int beginDay = beginc.get(Calendar.DAY_OF_MONTH);
  167 +
  168 + Calendar endc = Calendar.getInstance();
  169 + endc.setTime(request.getEndTime());
  170 + int endYear = endc.get(Calendar.YEAR);
  171 + int endMonth = endc.get(Calendar.MONTH) + 1;
  172 + int endDay = endc.get(Calendar.DAY_OF_MONTH);
  173 +
  174 + if (beginYear == endYear && beginMonth == endMonth && beginDay == endDay) {
  175 + // 2表示按每小时统计
  176 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR);
  177 + } else {
  178 + // 3表示按每天统计
  179 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY);
  180 + }
  181 + BizResult<PageBean<ParkingLotUseStatisticDTO>> bizResult = parkingLotStatisticService
  182 + .queryParkingLotUseStatisticForPage(request);
  183 + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  184 + SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
  185 + String[] title = new String[] {"时间", "总车流量", "临时车流量", "固定车流量"};
  186 + String sheetName = "车流量管理";
  187 + String fileName = "车流量管理" + format2.format(new Date());
  188 + // 1.创建excel信息
  189 + XSSFSheet workSheet = ExcelUtil.createExcel(sheetName);
  190 + // 2.设置excel表头和表体
  191 + Layouter.buildReport(workSheet, title, 0, 0);
  192 + // 3.填充数据
  193 + List<Object[]> contentList = new ArrayList<Object[]>();
  194 + List<ParkingLotUseStatisticDTO> list = new ArrayList<>();
  195 + if (CollectionUtils.isNotEmpty(bizResult.getData().getDataList())) {
  196 + list = bizResult.getData().getDataList();
  197 + }
  198 + for (ParkingLotUseStatisticDTO e : list) {
  199 + Object[] obj = new Object[title.length];
  200 + int index = 0;
  201 + obj[index++] = format.format(e.getStatisticBeginTime());
  202 + obj[index++] = e.getVehicleFlow();
  203 + obj[index++] = e.getTmpVehicleFlow();
  204 + obj[index++] = e.getFixVehicleFlow();
  205 + contentList.add(obj);
  206 + }
  207 + ExcleFillDateManager fillUserManager = new ExcleFillDateManager();
  208 + fillUserManager.fillSalesOrga(workSheet, title, contentList, 2);
  209 + // 4.excel输出配置
  210 + ExcelUtil.write(response, workSheet, fileName);
  211 + }
  212 +
  213 + /**
  214 + * 根据时间获取车流量折线图
  215 + *
  216 + * @param request
  217 + * @return
  218 + * @throws Exception
  219 + */
  220 + @ApiOperation("根据时间获取车流量折线图")
  221 + @PostMapping("getVehicleFlowForLineChart")
  222 + @ResponseBody
  223 + public BizResultVO<LineChartVO> getVehicleFlowForLineChart(
  224 + @RequestBody ParkingLotUseStatisticForPageRequest request) throws Exception {
  225 +
  226 + if (null == request.getBeginTime() || null == request.getEndTime()) {
  227 + throw new BizException(ErrorType.PARAMM_NULL, "开始时间和结束时间");
  228 + }
  229 + // 2.调用接口查询当前登录人管辖的停车场名称
  230 + UserInfo userInfo = sessionCommUtil.getUserInfo();
  231 + List<String> plNos = userInfo.getOrgIds();
  232 + if (CollectionUtils.isEmpty(plNos)) {
  233 + throw new BizException(ErrorType.PARK_LOT_NOT_EXISTS, "停车场plnos不存在");
  234 + }
  235 + request.setPlNos(plNos);
  236 +
  237 + logger.info("根据停车场编号获取该停车场今日车流量和车位折线图");
  238 + Calendar beginTime = Calendar.getInstance();
  239 + beginTime.setTime(request.getBeginTime());
  240 + int year = beginTime.get(Calendar.YEAR);
  241 + Calendar endTime = Calendar.getInstance();
  242 + endTime.setTime(request.getEndTime());
  243 +
  244 + Long dayDifference = DateUtil.getTimeDifference(new Timestamp(request.getEndTime().getTime()),
  245 + new Timestamp(request.getBeginTime().getTime()));
  246 + List<String> xAxisData = Lists.newArrayList();
  247 + request.setBaseRequest(new BaseInfo(1, 0));
  248 + String dateType = "";
  249 +
  250 + if (dayDifference == 0L) {
  251 + // 1小时为一个时间戳
  252 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR);
  253 + int totaltimestampCount = endTime.get(Calendar.HOUR_OF_DAY);
  254 + String day = "";
  255 + String month = "";
  256 +
  257 + int beginMonth = beginTime.get(Calendar.MONTH) + 1;
  258 + int beginDay = beginTime.get(Calendar.DAY_OF_MONTH);
  259 + month = String.format("%02d", (beginMonth));
  260 + day = String.format("%02d", (beginDay));
  261 + for (int j = 0; j < totaltimestampCount; j++) {
  262 + String hour = String.format("%02d", (j));
  263 + xAxisData.add(year + "-" + month + "-" + day + " " + hour);
  264 + }
  265 +
  266 + dateType = "yyyy-MM-dd HH";
  267 + LineChartVO vehicleFlows = getVehicleFlows(request, xAxisData, dateType);
  268 + return new BizResultVO<LineChartVO>().setData(vehicleFlows);
  269 +
  270 + } else if (dayDifference <= 3L) {
  271 + // 1小时为一个时间戳
  272 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR);
  273 + int totaltimestampCount = endTime.get(Calendar.HOUR_OF_DAY);
  274 + String day = "";
  275 + String month = "";
  276 + for (int i = 0; i <=dayDifference.intValue(); i++) {
  277 + Calendar tempDate = Calendar.getInstance();
  278 + tempDate .setTime(request.getBeginTime());
  279 + tempDate.add(Calendar.DAY_OF_MONTH, i);
  280 + int beginMonth = tempDate.get(Calendar.MONTH) + 1;
  281 + int beginDay = tempDate.get(Calendar.DAY_OF_MONTH);
  282 + month = String.format("%02d", (beginMonth));
  283 + day = String.format("%02d", (beginDay));
  284 + for (int j = 0; j < totaltimestampCount; j++) {
  285 + String hour = String.format("%02d", (j));
  286 + xAxisData.add(year + "-" + month + "-" + day + " " + hour);
  287 + }
  288 + }
  289 + dateType = "yyyy-MM-dd HH";
  290 + LineChartVO vehicleFlows = getVehicleFlows(request, xAxisData, dateType);
  291 + return new BizResultVO<LineChartVO>().setData(vehicleFlows);
  292 +
  293 + } else {
  294 + // 1天为一个时间戳
  295 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY);
  296 + for (int i = 0; i <=dayDifference.intValue(); i++) {
  297 + Calendar tempDate = Calendar.getInstance();
  298 + tempDate .setTime(request.getBeginTime());
  299 + tempDate.add(Calendar.DAY_OF_MONTH, i);
  300 + int beginMonth = tempDate.get(Calendar.MONTH) + 1;
  301 + int beginDay = tempDate.get(Calendar.DAY_OF_MONTH);
  302 + String month = String.format("%02d", (beginMonth));
  303 + String day = String.format("%02d", (beginDay));
  304 + xAxisData.add(year + "-" + month + "-" + day);
  305 +
  306 + }
  307 + dateType = "yyyy-MM-dd";
  308 + LineChartVO vehicleFlows = getVehicleFlows(request, xAxisData, dateType);
  309 + return new BizResultVO<LineChartVO>().setData(vehicleFlows);
  310 +
  311 + }
  312 +
  313 + }
  314 +
  315 + private LineChartVO getVehicleFlows(ParkingLotUseStatisticForPageRequest request, List<String> xAxisData,
  316 + String dateType) {
  317 + // 调用后场服务
  318 + logger.info("调用DUBBO服务入参:" + JSON.toJSONString(request));
  319 + BizResult<PageBean<ParkingLotUseStatisticDTO>> bizResult = parkingLotStatisticService
  320 + .queryParkingLotUseStatisticForPage(request);
  321 + PageBean<ParkingLotUseStatisticDTO> pageBean = ResultUtils.getBizResultData(bizResult);
  322 + List<ParkingLotUseStatisticDTO> useStatisticDTOs = Lists.newArrayList();
  323 + if (pageBean != null) {
  324 + useStatisticDTOs = pageBean.getDataList();
  325 + }
  326 +
  327 + // 保存固定车流量,时间戳和车流量对应关系
  328 + Map<String, Integer> fixVehicleFlowMap = Maps.newHashMap();
  329 + // 保存临时车流量,时间戳和车流量对应关系
  330 + Map<String, Integer> tmpVehicleFlowMap = Maps.newHashMap();
  331 + // 停车场编号和名称对应关系
  332 + Map<String, String> parkNameMap = Maps.newHashMap();
  333 + // 通过停车场,和统计时间分组
  334 + // Map<String, Map<String, Double>> parkLotMap = Maps.newHashMap();
  335 + if (!CollectionUtils.isEmpty(useStatisticDTOs)) {
  336 + for (ParkingLotUseStatisticDTO statisticDTO : useStatisticDTOs) {
  337 + String key = statisticDTO.getPlNo();
  338 + parkNameMap.put(key, statisticDTO.getPlName());
  339 + String statisBeginTime = DateUtil.getDateString(statisticDTO.getStatisticBeginTime(), dateType);
  340 + // 保存固定车流量和临时车流量
  341 + fixVehicleFlowMap.put(statisBeginTime,
  342 + (fixVehicleFlowMap.get(statisBeginTime) == null ? 0 : fixVehicleFlowMap.get(statisBeginTime))
  343 + + statisticDTO.getFixVehicleFlow());
  344 + tmpVehicleFlowMap.put(statisBeginTime,
  345 + (tmpVehicleFlowMap.get(statisBeginTime) == null ? 0 : tmpVehicleFlowMap.get(statisBeginTime))
  346 + + statisticDTO.getTmpVehicleFlow());
  347 + }
  348 + }
  349 +
  350 + // 封装车流量统计
  351 + LineChartVO vehicleFlows = new LineChartVO();
  352 + List<String> vehicleFlows_legendData = Lists.newArrayList();
  353 + vehicleFlows_legendData.add("临时车");
  354 + vehicleFlows_legendData.add("固定车");
  355 + vehicleFlows.setLegendData(vehicleFlows_legendData);
  356 + vehicleFlows.setxAxisData(xAxisData);
  357 + List<SerieVO> vehicleSeries = Lists.newArrayList();
  358 + // 固定车
  359 + SerieVO fixSerieVo = new SerieVO();
  360 + fixSerieVo.setName("固定车");
  361 + List<Integer> fixSerieVoData = Lists.newArrayList();
  362 + // 临时车
  363 + SerieVO tmpSerieVo = new SerieVO();
  364 + tmpSerieVo.setName("临时车");
  365 + List<Integer> tmpSerieVoData = Lists.newArrayList();
  366 + // 保存上一次的临时车值,当某个时间点没有数据时,则保持和上次一致
  367 + Integer lastfixFlow = 0;
  368 + Integer lasttmpFlow = 0;
  369 + for (String timestamp : xAxisData) {
  370 +
  371 + if (fixVehicleFlowMap.containsKey(timestamp)) {
  372 + lastfixFlow = fixVehicleFlowMap.get(timestamp).intValue();
  373 + } else {
  374 + lastfixFlow = 0;
  375 + }
  376 + fixSerieVoData.add(lastfixFlow);
  377 +
  378 + if (tmpVehicleFlowMap.containsKey(timestamp)) {
  379 + lasttmpFlow = tmpVehicleFlowMap.get(timestamp).intValue();
  380 + } else {
  381 + lasttmpFlow = 0;
  382 + }
  383 + tmpSerieVoData.add(lasttmpFlow);
  384 + }
  385 + fixSerieVo.setData(fixSerieVoData);
  386 + vehicleSeries.add(fixSerieVo);
  387 + tmpSerieVo.setData(tmpSerieVoData);
  388 + vehicleSeries.add(tmpSerieVo);
  389 +
  390 + vehicleFlows.setSeries(vehicleSeries);
  391 + return vehicleFlows;
  392 + }
  393 +
  394 + public static void main(String[] args) {
  395 + String json
  396 + = "{\"id\":\"1\",\"platform\":\"android\",\"parameter\":{\"drid\":\"177277364\",\"sex\":\"1\",\"type\":\"2\",\"creatorname\":\"Mrw\",\"username\":\"jack\",\"pwd\":\"123456\",\"remark\":\"平板用户\",\"createtime\":\"2017-07-24 23:59:59\"}}";
  397 + JSONObject object = (JSONObject)JSONObject.parse(json);
  398 + System.out.println(object.get("id"));
  399 + System.out.println(object.get("platform"));
  400 + JSONObject parameter = (JSONObject)object.get("parameter");
  401 + System.out.println(parameter.get("drid"));
  402 + System.out.println(parameter.get("sex"));
  403 + }
414 404  
415 405 }
... ...
src/main/java/com/zteits/irain/portal/web/parkinglotcloudplatform/parklotmanage/ParkLotManageController.java
... ... @@ -103,19 +103,9 @@ public class ParkLotManageController{
103 103  
104 104 private List<String> GetParkLotNosByCurrUser(String sysCode) throws Exception {
105 105 logger.info("根据登录人权限获取停车场列表");
106   - List<String> plNos = Lists.newArrayList();
107   - //2.调用接口查询当前登录人管辖的停车场名称
108 106 UserInfo userInfo = sessionCommUtil.getUserInfo();
109   - if(userInfo!=null){
110   - TdCompanyParkQueryRequest tdCompanyParkQueryRequest = new TdCompanyParkQueryRequest();
111   - tdCompanyParkQueryRequest.setCustIdList(userInfo.getOrgIds());
112   - tdCompanyParkQueryRequest.setSysCode(sysCode);
113   - tdCompanyParkQueryRequest.setSessionId(session.getId());
114   - BizResult<List<String>> bizResult = tdCustCompanyService.queryParkNoByCustIds(tdCompanyParkQueryRequest );
115   - plNos = ResultUtils.getBizResultData(bizResult);
116   - }else{
117   - throw new BizException(ErrorType.AUTH_TOKEN_NOT_EXISTS);
118   - }
  107 + List<String> plNos = userInfo.getOrgIds();
  108 +
119 109 return plNos;
120 110 }
121 111 }
... ...