ParkingRunningStatisticServiceImpl.java
10.8 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package com.zteits.park.biz;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.apache.commons.collections4.CollectionUtils;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.xiaoleilu.hutool.date.DateField;
import com.xiaoleilu.hutool.date.DateTime;
import com.xiaoleilu.hutool.date.DateUtil;
import com.zteits.clouds.api.apibase.bean.BizResult;
import com.zteits.clouds.api.apibase.bean.PageBean;
import com.zteits.clouds.api.apibase.constants.ErrorType;
import com.zteits.clouds.api.apibase.exception.BizException;
import com.zteits.clouds.api.dto.clouds.dto.TurnoverRatioDTO;
import com.zteits.clouds.api.dto.park.dto.ParkingRunningStatisticDTO;
import com.zteits.clouds.api.dto.park.dto.TodayVehicleFlowOccupyRateAndTurnOverDTO;
import com.zteits.clouds.api.dto.park.param.CommonPlnosQueryRequest;
import com.zteits.clouds.api.dto.park.param.ParkingLotUseStatisticForPageRequest;
import com.zteits.clouds.api.dto.park.param.ParkingRunningStatisticForPageRequest;
import com.zteits.clouds.api.service.park.ParkingRunningStatisticService;
import com.zteits.park.constant.ParkConstant.ParkingRunningStatistic.TimeCycle;
import com.zteits.park.dao.ParkingRunningStatisticDao;
import com.zteits.park.domain.ParkingRunningStatistic;
import com.zteits.park.pagepager.PageBeanUtil;
@Service("com.zteits.park.biz.ParkingRunningStatisticServiceImpl")
public class ParkingRunningStatisticServiceImpl implements ParkingRunningStatisticService {
private static final Logger logger=LoggerFactory.getLogger(ParkingRunningStatisticServiceImpl.class);
@Autowired
private ParkingRunningStatisticDao parkingRunningStatisticDao;
@Override
public BizResult<List<ParkingRunningStatisticDTO>> queryCarFlowChartByDayOrMonth(
ParkingRunningStatisticForPageRequest request) {
logger.info("开始调用按日/月查询车流量图表数据接口request={}",JSONObject.toJSONString(request));
List<ParkingRunningStatisticDTO> list = parkingRunningStatisticDao.queryCarFlowChartByDayOrMonth(request);
logger.info("调用按日/月查询车流量图表数据接口返回result={}",JSONObject.toJSONString(list));
return new BizResult<List<ParkingRunningStatisticDTO>>(list);
}
@Override
public BizResult<PageBean<ParkingRunningStatisticDTO>> queryCarFlowByTimeTypeForList(
ParkingRunningStatisticForPageRequest request) {
logger.info("开始调用按天查询车流量列表详情接口request={}",JSONObject.toJSONString(request));
if (request.getBaseRequest() == null) {
throw new BizException(ErrorType.PARAMM_NULL, "分页参数为空");
}
if(request.getBeginTime() == null){
throw new BizException(ErrorType.PARAMM_NULL, "开始时间为空");
}
if(request.getEndTime() == null){
throw new BizException(ErrorType.PARAMM_NULL, "结束时间为空");
}
if(CollectionUtils.isEmpty(request.getPlNos())){
throw new BizException(ErrorType.PARAMM_NULL, "停车场编号为空");
}
PageBean<ParkingRunningStatisticDTO> pageBean = new PageBean<>();
PageInfo<ParkingRunningStatisticDTO> pageInfo = parkingRunningStatisticDao.queryCarFlowByTimeTypeForList(request);
if(null != pageInfo){
PageBeanUtil.copyProperties(pageInfo, pageBean, ParkingRunningStatisticDTO.class);
}
logger.info("调用按天查询车流量列表详情接口返回result={}",JSONObject.toJSONString(pageBean));
return new BizResult<>(pageBean);
}
@Override
public BizResult<PageBean<TurnoverRatioDTO>> queryTurnoverRatioForTable(ParkingRunningStatisticForPageRequest request) {
logger.info("开始调用查询周转率列表详情接口request={}",JSONObject.toJSONString(request));
if(request.getBeginTime() == null){
throw new BizException(ErrorType.PARAMM_NULL, "开始时间为空");
}
if(request.getEndTime() == null){
throw new BizException(ErrorType.PARAMM_NULL, "结束时间为空");
}
if(CollectionUtils.isEmpty(request.getPlNos())){
throw new BizException(ErrorType.PARAMM_NULL, "停车场编号为空");
}
PageBean<TurnoverRatioDTO> pageBean = new PageBean<>();
PageInfo<TurnoverRatioDTO> pageInfo = parkingRunningStatisticDao.queryTurnoverRatioForTable(request);
if(null != pageInfo){
PageBeanUtil.copyProperties(pageInfo, pageBean, TurnoverRatioDTO.class);
}
logger.info("调用查询周转率列表详情返回result={}",JSONObject.toJSONString(pageBean));
return new BizResult<>(pageBean);
}
@Override
public BizResult<PageBean<TurnoverRatioDTO>> queryTurnoverRatioChart(ParkingRunningStatisticForPageRequest request) {
logger.info("开始调用查询周转率图表接口request={}",JSONObject.toJSONString(request));
if(request.getBeginTime() == null){
throw new BizException(ErrorType.PARAMM_NULL, "开始时间为空");
}
if(request.getEndTime() == null){
throw new BizException(ErrorType.PARAMM_NULL, "结束时间为空");
}
if(CollectionUtils.isEmpty(request.getPlNos())){
throw new BizException(ErrorType.PARAMM_NULL, "停车场编号为空");
}
PageBean<TurnoverRatioDTO> pageBean = new PageBean<>();
PageInfo<TurnoverRatioDTO> pageInfo = parkingRunningStatisticDao.queryTurnoverRatioChart(request);
if(null != pageInfo){
PageBeanUtil.copyProperties(pageInfo, pageBean, TurnoverRatioDTO.class);
}
logger.info("调用查询周转率图表返回result={}",JSONObject.toJSONString(pageBean));
return new BizResult<>(pageBean);
}
@Override
public BizResult<List<TodayVehicleFlowOccupyRateAndTurnOverDTO>> queryTodayVehicleFlowOccupyRateAndTurnOver(
CommonPlnosQueryRequest request) {
if(CollectionUtils.isEmpty(request.getPlNos())){
throw new BizException(ErrorType.PARAMM_NULL, "停车场编号为空");
}
DateTime beginTime = null;
DateTime endTime = null;
//查询类型 1-当前时间往前推24小时;2-0点到当前时间 默认为0点到当前时间
if(StringUtils.isBlank(request.getQueryType()) || "2".equals(request.getQueryType())){
beginTime = new DateTime().setField(DateField.HOUR_OF_DAY, 0).setField(DateField.MINUTE, 0)
.setField(DateField.SECOND, 0);
endTime = new DateTime().setField(DateField.HOUR_OF_DAY, 23).setField(DateField.MINUTE, 59)
.setField(DateField.SECOND, 59);
}
//当前时间往前推24小时
else{
endTime = new DateTime().setField(DateField.MINUTE, 0).setField(DateField.SECOND, 0);
beginTime = new DateTime(endTime.getTime()-24*60*60*1000);
}
List<TodayVehicleFlowOccupyRateAndTurnOverDTO> result = parkingRunningStatisticDao
.queryTodayVehicleFlowOccupyRateAndTurnOver(beginTime, endTime, TimeCycle.PER1HOUR,
request.getPlNos());
result = fixTodayVehicleFlowOccupyRateAndTurnOverData(result);
return new BizResult<>(result);
}
private List<TodayVehicleFlowOccupyRateAndTurnOverDTO> fixTodayVehicleFlowOccupyRateAndTurnOverData(
List<TodayVehicleFlowOccupyRateAndTurnOverDTO> datas) {
List<TodayVehicleFlowOccupyRateAndTurnOverDTO> realDatas = new ArrayList<>();
Map<Integer, TodayVehicleFlowOccupyRateAndTurnOverDTO> dataMap
= initTodayVehicleFlowOccupyRateAndTurnOverDTOToMap(
datas);
for (int i = 0; i <= 23; i++) {
TodayVehicleFlowOccupyRateAndTurnOverDTO realDTO = null;
if (dataMap.containsKey(i)) {
realDTO = dataMap.get(i);
} else {
realDTO = new TodayVehicleFlowOccupyRateAndTurnOverDTO();
realDTO.setHour(i);
realDTO.setAvgOccupyRate(0.0);
realDTO.setAvgTurnoverRate(0.0);
realDTO.setInCount(0);
realDTO.setOutCount(0);
}
realDatas.add(realDTO);
}
return realDatas;
}
private Map<Integer, TodayVehicleFlowOccupyRateAndTurnOverDTO> initTodayVehicleFlowOccupyRateAndTurnOverDTOToMap(
List<TodayVehicleFlowOccupyRateAndTurnOverDTO> datas) {
Map<Integer, TodayVehicleFlowOccupyRateAndTurnOverDTO> map = new HashMap<>();
for (TodayVehicleFlowOccupyRateAndTurnOverDTO dto : datas) {
map.put(dto.getHour(), dto);
}
return map;
}
@Override
public BizResult<List<TodayVehicleFlowOccupyRateAndTurnOverDTO>> queryCurrentOccupyRateAndTurnOver(
CommonPlnosQueryRequest request) {
if(CollectionUtils.isEmpty(request.getPlNos())){
throw new BizException(ErrorType.PARAMM_NULL, "停车场编号为空");
}
//设置天开始、结束时间
Date beginTime =DateUtil.offsetMinute(new Date(),-10);
Date endTime =new Date();
List<TodayVehicleFlowOccupyRateAndTurnOverDTO> result = parkingRunningStatisticDao
.queryCurrentOccupyRateAndTurnOver(beginTime, endTime, TimeCycle.PER10MINUTE,
request.getPlNos());
if(CollectionUtils.isEmpty(result)){//再往前推10分钟
beginTime =DateUtil.offsetMinute(new Date(),-20);
endTime =DateUtil.offsetMinute(new Date(),-10);
result = parkingRunningStatisticDao.queryCurrentOccupyRateAndTurnOver(
beginTime, endTime, TimeCycle.PER10MINUTE,request.getPlNos());
}
return new BizResult<>(result);
}
@Override
public BizResult<PageBean<ParkingRunningStatisticDTO>> queryParkingLotUseStatisticForPage(
ParkingLotUseStatisticForPageRequest request) {
if (request.getBaseRequest() == null) {
throw new BizException(ErrorType.PARAMM_NULL, "分页参数为空");
}
PageInfo<ParkingRunningStatistic> pageInfo = parkingRunningStatisticDao.queryParkingLotUseStatisticForPage(
request.getBeginTime(), request.getEndTime(), request.getQueryKind(), request.getPlNos(),
request.getBaseRequest().getPageNum(), request.getBaseRequest().getPageSize());
PageBean<ParkingRunningStatisticDTO> pageBean = new PageBean<ParkingRunningStatisticDTO>();
if (pageInfo != null) {
PageBeanUtil.copyProperties(pageInfo, pageBean, ParkingRunningStatisticDTO.class);
}
return new BizResult<PageBean<ParkingRunningStatisticDTO>>(pageBean);
}
}