Commit d14d20ef35419cf5245bd306ec065aa85a53ea2b

Authored by 王飞
1 parent 74c56bb4

泊位周转率接口

src/main/java/com/zteits/irain/portal/vo/parkinglotcloudplatform/datastatistic/LineChartVO.java
... ... @@ -61,6 +61,8 @@ public class LineChartVO {
61 61 private String name;
62 62  
63 63 private List<Integer> data;
  64 +
  65 + private List<Double> doubleData;
64 66  
65 67 public String getName() {
66 68 return name;
... ... @@ -78,5 +80,13 @@ public class LineChartVO {
78 80 this.data = data;
79 81 }
80 82  
  83 + public List<Double> getDoubleData() {
  84 + return doubleData;
  85 + }
  86 +
  87 + public void setDoubleData(List<Double> doubleData) {
  88 + this.doubleData = doubleData;
  89 + }
  90 +
81 91 }
82 92 }
... ...
src/main/java/com/zteits/irain/portal/web/parkinglotcloudplatform/datastatistic/AnalysisController.java
1 1 package com.zteits.irain.portal.web.parkinglotcloudplatform.datastatistic;
2 2  
  3 +import java.sql.Timestamp;
3 4 import java.util.Calendar;
  5 +import java.util.Date;
4 6 import java.util.List;
5 7  
6 8 import org.slf4j.Logger;
... ... @@ -13,9 +15,11 @@ import org.springframework.web.bind.annotation.RequestBody;
13 15 import org.springframework.web.bind.annotation.RequestMapping;
14 16 import org.springframework.web.bind.annotation.ResponseBody;
15 17  
  18 +import com.clouds.common.utils.DateUtil;
16 19 import com.clouds.common.web.BizController;
17 20 import com.clouds.common.web.vo.BizResultVO;
18 21 import com.clouds.common.web.vo.EasyUIDataGridVO;
  22 +import com.google.common.collect.Lists;
19 23 import com.zteits.clouds.api.apibase.bean.BizResult;
20 24 import com.zteits.clouds.api.apibase.bean.PageBean;
21 25 import com.zteits.clouds.api.apibase.constants.ErrorType;
... ... @@ -24,6 +28,8 @@ import com.zteits.clouds.api.dto.clouds.param.BerthTurnOverQueryRequest;
24 28 import com.zteits.clouds.api.dto.park.dto.BerthTurnOverCountDTO;
25 29 import com.zteits.clouds.api.service.park.EqpBerthsService;
26 30 import com.zteits.irain.portal.constant.ParkConstant;
  31 +import com.zteits.irain.portal.vo.parkinglotcloudplatform.datastatistic.LineChartVO;
  32 +import com.zteits.irain.portal.vo.parkinglotcloudplatform.datastatistic.LineChartVO.SerieVO;
27 33  
28 34 import io.swagger.annotations.Api;
29 35 import io.swagger.annotations.ApiOperation;
... ... @@ -61,8 +67,12 @@ public class AnalysisController extends BizController {
61 67 @ApiOperation("泊位周转率-折线图")
62 68 @PostMapping("queryTurnOverForMap")
63 69 @ResponseBody
64   - public BizResultVO<List<BerthTurnOverCountDTO>> queryTurnOverForMap(@RequestBody BerthTurnOverQueryRequest
  70 + public BizResultVO<LineChartVO> queryTurnOverForMap(@RequestBody BerthTurnOverQueryRequest
65 71 requestObject) {
  72 + if (null == requestObject.getBeginTime() || null == requestObject.getEndTime()) {
  73 + throw new BizException(ErrorType.PARAMM_NULL, "开始时间和结束时间");
  74 + }
  75 + logger.info("根据停车场编号获取泊位周转率折线图");
66 76 requestObject.setSysCode(sysCode);
67 77 Calendar beginc = Calendar.getInstance();
68 78 beginc.setTime(requestObject.getBeginTime());
... ... @@ -76,6 +86,11 @@ public class AnalysisController extends BizController {
76 86 int endMonth = endc.get(Calendar.MONTH) + 1;
77 87 int endDay = endc.get(Calendar.DAY_OF_MONTH);
78 88  
  89 + String tableName = "tp_p_eqp_log"+endYear+""+endMonth;
  90 + if(endMonth < 10){
  91 + tableName = "tp_p_eqp_log"+endYear+"0"+endMonth;
  92 + }
  93 + requestObject.setTableName(tableName);
79 94 if (beginYear == endYear && beginMonth == endMonth && beginDay == endDay) {
80 95 // 2表示按每小时统计
81 96 requestObject.setTimeType(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR);
... ... @@ -83,8 +98,73 @@ public class AnalysisController extends BizController {
83 98 // 3表示按每天统计
84 99 requestObject.setTimeType(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY);
85 100 }
86   - BizResult<List<BerthTurnOverCountDTO>> respondObject = eqpBerthsService.queryBerthTurnOverForMap(requestObject);
87   - return new BizResultVO<>(respondObject);
  101 + BizResult<List<BerthTurnOverCountDTO>> respondObject = eqpBerthsService.
  102 + queryBerthTurnOverForMap(requestObject);
  103 + LineChartVO result = toLineChart(respondObject.getData(),requestObject);
  104 + return new BizResultVO<LineChartVO>().setData(result);
  105 + }
  106 +
  107 + private LineChartVO toLineChart(List<BerthTurnOverCountDTO> berthDto,BerthTurnOverQueryRequest request){
  108 + LineChartVO lineChartVO = new LineChartVO();
  109 + List<String> legendData = Lists.newArrayList();
  110 + List<String> xAxisData = Lists.newArrayList();
  111 + List<SerieVO> series = Lists.newArrayList();
  112 + List<Double> data = Lists.newArrayList();
  113 + Calendar endTime = Calendar.getInstance();
  114 + endTime.setTime(request.getEndTime());
  115 + Long dayDifference = DateUtil.getTimeDifference(new Timestamp(request.getEndTime().getTime()),
  116 + new Timestamp(request.getBeginTime().getTime()));
  117 +
  118 + if (request.getTimeType() == ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR ) {
  119 + // 1个小时为一个时间戳
  120 + int totaltimestampCount = endTime.get(Calendar.HOUR_OF_DAY);
  121 + for (int j = 0; j <= totaltimestampCount+1; j++) {
  122 + String hour = String.format("%02d", (j));
  123 + xAxisData.add(hour+":00");
  124 + data.add(0.0);
  125 + }
  126 + //dateType = "HH:mm";\
  127 + for (BerthTurnOverCountDTO dto : berthDto) {
  128 + Integer integer = Integer.valueOf(dto.getTurnDayTime().substring(11, 13));
  129 + data.set(integer, dto.getTurnOver());
  130 + }
  131 +
  132 + }else {
  133 + // 1天为一个时间戳
  134 + for (int i = 0; i <= dayDifference.intValue(); i++) {
  135 + Calendar tempDate = Calendar.getInstance();
  136 + tempDate.setTime(request.getBeginTime());
  137 + tempDate.add(Calendar.DAY_OF_MONTH, i);
  138 + int beginMonth = tempDate.get(Calendar.MONTH) + 1;
  139 + int beginDay = tempDate.get(Calendar.DAY_OF_MONTH);
  140 + String month = String.format("%02d", (beginMonth));
  141 + String day = String.format("%02d", (beginDay));
  142 + xAxisData.add(month + "-" + day);
  143 + data.add(0.0);
  144 + }
  145 + //dateType = "MM-dd";
  146 + for (int k=0;k<xAxisData.size();k++) {
  147 + for (BerthTurnOverCountDTO dto : berthDto) {
  148 + String str = dto.getTurnDayTime().substring(5, 10);
  149 + if(xAxisData.get(k).equals(str)){
  150 + data.set(k, dto.getTurnOver());
  151 + }
  152 + }
  153 +
  154 + }
  155 + }
  156 + SerieVO serieVO = new SerieVO();
  157 + serieVO.setName("周转率");
  158 + serieVO.setDoubleData(data);
  159 + series.add(serieVO);
  160 + /*for(int i=0;i<xAxisData.size();i++){
  161 +
  162 + }*/
  163 + legendData.add("周转率");
  164 + lineChartVO.setxAxisData(xAxisData);
  165 + lineChartVO.setSeries(series);
  166 + lineChartVO.setLegendData(legendData);
  167 + return lineChartVO;
88 168 }
89 169 /**
90 170 *
... ... @@ -102,6 +182,17 @@ public class AnalysisController extends BizController {
102 182 if (null == requestObject.getBeginTime() || null == requestObject.getEndTime()) {
103 183 throw new BizException(ErrorType.PARAMM_NULL, "开始时间和结束时间");
104 184 }
  185 + Calendar endc = Calendar.getInstance();
  186 + endc.setTime(requestObject.getEndTime());
  187 + int endYear = endc.get(Calendar.YEAR);
  188 + int endMonth = endc.get(Calendar.MONTH) + 1;
  189 + int endDay = endc.get(Calendar.DAY_OF_MONTH);
  190 +
  191 + String tableName = "tp_p_eqp_log"+endYear+""+endMonth;
  192 + if(endMonth < 10){
  193 + tableName = "tp_p_eqp_log"+endYear+"0"+endMonth;
  194 + }
  195 + requestObject.setTableName(tableName);
105 196 // 按每天统计
106 197 requestObject.setTimeType(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY);
107 198 BizResult<PageBean<BerthTurnOverCountDTO>> respondObject =
... ...