BerthManageServiceImpl.java
15 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
package com.zteits.park.biz;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import org.apache.commons.collections4.CollectionUtils;
import com.alibaba.fastjson.JSON;
import com.clouds.common.cache.park.ParkingLotGeoCacheUtil;
import com.clouds.common.utils.BeanValidatorsUtils;
import com.clouds.common.utils.ListCopyUtil;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.google.common.collect.Lists;
import com.xiaoleilu.hutool.util.CollectionUtil;
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.constants.LonLatTypeEnum;
import com.zteits.clouds.api.apibase.constants.PDAErrorEnum;
import com.zteits.clouds.api.apibase.exception.BizException;
import com.zteits.clouds.api.dto.order.parkorder.param.ParkOrderUpdateCarNumberReq;
import com.zteits.clouds.api.dto.park.dto.BerthsDTO;
import com.zteits.clouds.api.dto.park.dto.ParkOccupancyRateDTO;
import com.zteits.clouds.api.dto.park.dto.ParkingLotDTO;
import com.zteits.clouds.api.dto.park.param.BatchSaveBerthInfoRequest;
import com.zteits.clouds.api.dto.park.param.ChangeBerthAreaRequest;
import com.zteits.clouds.api.dto.park.param.CheckUniqueForBerthNoRequest;
import com.zteits.clouds.api.dto.park.param.DeleteBerthsRequest;
import com.zteits.clouds.api.dto.park.param.QueryBerthForPageRequest;
import com.zteits.clouds.api.dto.park.param.QueryParkLotInfoByPkNoRequest;
import com.zteits.clouds.api.dto.park.param.SaveUpdateBerthInfoRequest;
import com.zteits.clouds.api.service.park.BerthManageService;
import com.zteits.clouds.api.service.park.ParkingLotQueryService;
import com.zteits.park.biz.business.ParkLotQueryBizService;
import com.zteits.park.constant.ParkConstant;
import com.zteits.park.dao.BerthsDao;
import com.zteits.park.dao.ParkInOutRecordDao;
import com.zteits.park.dao.ParkingLotGeoDao;
import com.zteits.park.dao.TpPRegionAreaDao;
import com.zteits.park.domain.ParkingLotGeo;
import com.zteits.park.domain.TpPBerths;
import com.zteits.park.domain.TpPBerthsDO;
import com.zteits.park.domain.TpPRegionArea;
import com.zteits.park.pagepager.PageBeanUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Point;
@Service("com.zteits.park.biz.BerthManageServiceImpl")
public class BerthManageServiceImpl implements BerthManageService {
private static final Logger logger = LoggerFactory.getLogger(BerthManageServiceImpl.class);
@Autowired
private BerthsDao berthsDao;
@Autowired
private ParkingLotQueryService parkingLotQueryService;
@Autowired
private ParkingLotGeoDao parkingLotGeoDao;
@Autowired
private TpPRegionAreaDao tpPRegionAreaDao;
@Autowired
private ParkLotQueryBizService parkLotQueryBizService;
@Autowired
private ParkInOutRecordDao parkInOutRecordDao;
@Override
public BizResult<PageBean<BerthsDTO>> queryBerthByBerth(QueryBerthForPageRequest request) {
logger.info("通过车位对象分页查询车位信息入参:" + JSON.toJSONString(request));
if (null == request) {
throw new BizException(ErrorType.PARAMM_NULL, "请求对象不能为空");
}
PageInfo<TpPBerthsDO> pageInfo = berthsDao.queryBerthByBerth(request, request.getBaseRequest().getPageNum(),
request.getBaseRequest().getPageSize());
PageBean<BerthsDTO> pageBean = new PageBean<BerthsDTO>();
PageBeanUtil.copyProperties(pageInfo, pageBean, BerthsDTO.class);
if (pageBean == null || CollectionUtil.isEmpty(pageBean.getDataList())) {
return new BizResult<PageBean<BerthsDTO>>(pageBean);
}
List<String> plNos = pageBean.getDataList().stream().map(item -> item.getPlNo()).collect(Collectors.toList());
List<ParkingLotDTO> parkingLotDTOs = parkLotQueryBizService.QueryParkingLotByPkNos(plNos);
if (CollectionUtils.isEmpty(parkingLotDTOs)) {
return new BizResult<PageBean<BerthsDTO>>(pageBean);
}
//经纬度查询标志 null或true-查询; false-不查询
if (request.getLonAndLatFlag() != null && !request.getLonAndLatFlag()) {
for (ParkingLotDTO parkingLotDTO : parkingLotDTOs) {
String plName = parkingLotDTO.getPlName();
for (BerthsDTO berthsDTO : pageBean.getDataList()) {
if ((parkingLotDTO.getPlNo()).equals(berthsDTO.getPlNo())) {
berthsDTO.setPlName(plName);
}
}
}
return new BizResult<PageBean<BerthsDTO>>(pageBean);
} else {
//因为车位目前没有经纬度,故先放置停车场经纬度
for (ParkingLotDTO parkingLotDTO : parkingLotDTOs) {
String plName = parkingLotDTO.getPlName();
List<Point> points = ParkingLotGeoCacheUtil.queryPointByPlNo(LonLatTypeEnum.LON_LAT_TYPE_1,
parkingLotDTO.getPlNo());
BigDecimal latId = new BigDecimal(0);
BigDecimal lonId = new BigDecimal(0);
if (CollectionUtil.isNotEmpty(points) && points.get(0) != null) {
lonId = new BigDecimal(points.get(0).getX());
latId = new BigDecimal(points.get(0).getY());
}
for (BerthsDTO berthsDTO : pageBean.getDataList()) {
if ((parkingLotDTO.getPlNo()).equals(berthsDTO.getPlNo())) {
berthsDTO.setPlName(plName);
berthsDTO.setLonId(lonId);
berthsDTO.setLatId(latId);
}
}
}
}
//单个的停车场
// String plNo = pageBean.getDataList().stream().findFirst().get().getPlNo();
// ParkingLotDTO parkingLotDTO = parkLotQueryBizService.QueryParkingLotByPkNo(plNo);
// if(parkingLotDTO==null){
// return new BizResult<PageBean<BerthsDTO>>(pageBean);
// }
// String plName=parkingLotDTO.getPlName();
// List<Point> points = ParkingLotGeoCacheUtil.queryPointByPlNo(LonLatTypeEnum.LON_LAT_TYPE_1, plNo);
// BigDecimal latId=new BigDecimal(0);
// BigDecimal lonId=new BigDecimal(0);
// if(CollectionUtil.isNotEmpty(points) && points.get(0)!=null){
// lonId = new BigDecimal(points.get(0).getX());
// latId = new BigDecimal(points.get(0).getY());
// }
// for (BerthsDTO berthsDTO : pageBean.getDataList()) {
// berthsDTO.setPlName(plName);
// berthsDTO.setLonId(lonId);
// berthsDTO.setLatId(latId);
// }
return new BizResult<PageBean<BerthsDTO>>(pageBean);
}
@Override
public BizResult<List<ParkOccupancyRateDTO>> queryParkOccupancyRate(QueryBerthForPageRequest request) {
String plName = "";
BigDecimal latId = new BigDecimal(0);
BigDecimal lonId = new BigDecimal(0);
Map<String, Object> map = new HashMap<String, Object>();
List<ParkOccupancyRateDTO> list = berthsDao.queryParkOccupancyRate(request.getPlNo(),
request.getParkAreaCode());
if (CollectionUtils.isEmpty(list)) {
return new BizResult<List<ParkOccupancyRateDTO>>(list);
}
for (ParkOccupancyRateDTO dto : list) {
String plNo = dto.getPlNo();
if (!map.containsKey(plNo)) {
map.put(dto.getPlNo(), dto);
QueryParkLotInfoByPkNoRequest pkRequest = new QueryParkLotInfoByPkNoRequest();
pkRequest.setSysCode(request.getSysCode());
pkRequest.setPklNo(dto.getPlNo());
BizResult<ParkingLotDTO> result = parkingLotQueryService.QueryParkingLotByPkNo(pkRequest);
if (null != result.getData()) {
plName = result.getData().getPlName();
}
List<String> pklNos = Lists.newArrayList();
pklNos.add(dto.getPlNo());
Map<String, List<ParkingLotGeo>> geolist = parkingLotGeoDao.queryParkingLotGeoListByParkNos(pklNos,
ParkConstant.ParkingLotGeo.GeoType.TYPE_PARKINGLOT, LonLatTypeEnum.LON_LAT_TYPE_1.value());
if (geolist != null && CollectionUtils.isNotEmpty(geolist.get(dto.getPlNo()))) {
if (geolist.get(dto.getPlNo()).size() > 0) {
latId = geolist.get(dto.getPlNo()).get(0).getLatId();
lonId = geolist.get(dto.getPlNo()).get(0).getLonId();
}
}
}
List<String> parkAreaCodes = Lists.newArrayList();
parkAreaCodes.add(StringUtil.isEmpty(dto.getParkAreaCode()) ? "" : dto.getParkAreaCode());
Map<String, TpPRegionArea> map2 = tpPRegionAreaDao.queryTpPRegionAreaByParkAreaCodes(parkAreaCodes);
TpPRegionArea tpPRegionArea = map2.get(dto.getParkAreaCode());
if (null != tpPRegionArea) {
dto.setParkAreaName(tpPRegionArea.getParkAreaName());
}
dto.setLatId(latId);
dto.setLonId(lonId);
dto.setPlName(plName);
}
return new BizResult<List<ParkOccupancyRateDTO>>(list);
}
@Override
public BizResult<Boolean> updateBerthById(SaveUpdateBerthInfoRequest request) {
logger.info("修改停车场泊位信息入参:" + JSON.toJSONString(request));
if (request.getId() == null) {
throw new BizException(ErrorType.PARAMM_NULL, "泊位ID");
}
TpPBerths tpPBerths = new TpPBerths();
BeanUtils.copyProperties(request, tpPBerths);
Boolean result = berthsDao.updateBerthInfoById(tpPBerths);
return new BizResult<Boolean>(result);
}
@Override
public BizResult<Boolean> updateBerthBusiInfoStatus(DeleteBerthsRequest request) {
logger.info("修改停车场泊位信息入参:" + JSON.toJSONString(request));
if (CollectionUtils.isEmpty(request.getIds())) {
throw new BizException(ErrorType.PARAMM_NULL, "泊位ID");
}
Boolean result = berthsDao.updateBerthBusiInfoStatus(request);
return new BizResult<Boolean>(result);
}
@Override
public BizResult<Boolean> batDeleteBerths(DeleteBerthsRequest request) {
logger.info("删除停车场泊位信息入参:" + JSON.toJSONString(request));
BeanValidatorsUtils.validateWithException(request);
Boolean result = berthsDao.batDeleteBerthsById(request.getIds(), request.getOpId(), request.getPlNo());
return new BizResult<Boolean>(result);
}
@Override
public BizResult<Boolean> saveBerthInfo(SaveUpdateBerthInfoRequest request) {
logger.info("begin保存停车场泊位信息入参:" + JSON.toJSONString(request));
if (StringUtil.isEmpty(request.getBerthNo())) {
logger.info("泊位编号为空!");
throw new BizException(ErrorType.PARAMM_NULL, "泊位编号");
}
if (StringUtil.isEmpty(request.getPlNo())) {
logger.info("停车场编号为空!");
throw new BizException(ErrorType.PARAMM_NULL, "停车场编号");
}
TpPBerths berths = new TpPBerths();
BeanUtils.copyProperties(request, berths);
berths.setCreateTime(new Date());
/**新增泊位信息表.*/
Integer result = berthsDao.insertBerthInfo(berths);
logger.info("begin保存停车场泊位信息,结果={}", result > 0);
return new BizResult<Boolean>(result > 0);
}
@Override
public BizResult<List<BerthsDTO>> queryBerthsByPlNo(QueryParkLotInfoByPkNoRequest queryParkLotInfoByPkNoRequest) {
List<BerthsDTO> rsList = Lists.newArrayList();
List<TpPBerths> list = berthsDao.queryBerthsByPlNo(queryParkLotInfoByPkNoRequest.getPklNo());
if (CollectionUtil.isNotEmpty(list)) {
for (TpPBerths tpPBerths : list) {
BerthsDTO dto = new BerthsDTO();
BeanUtils.copyProperties(tpPBerths, dto);
rsList.add(dto);
}
}
return new BizResult<List<BerthsDTO>>(rsList);
}
@Override
public BizResult<List<String>> getBerthInfoForNoBindEqpByPlNo(QueryParkLotInfoByPkNoRequest request) {
logger.info("根据停车场查询泊位信息入参:" + JSON.toJSONString(request));
String plNo = request.getPklNo();
//根据停车场查询未绑定地磁的泊位编号
List<TpPBerths> berthList = berthsDao.getBerthNoBindGeoByPlNo(plNo);
List<String> berthNoList = Optional.ofNullable(berthList).orElse(new ArrayList<>()).stream().map(
berth -> berth.getBerthNo()).collect(Collectors.toList());
return new BizResult<List<String>>(berthNoList);
}
/**
* 校验泊位编码的唯一性.<br/>
*
* @param request
* @return 2018年1月5日 wangfs.<br/>
*/
@Override
public BizResult<Boolean> checkUniqueForBerthNo(CheckUniqueForBerthNoRequest request) {
BeanValidatorsUtils.validateWithException(request);
int flg = berthsDao.checkUniqueForBerthNo(request);
return new BizResult<Boolean>(flg > 0);
}
@Override
public BizResult<Boolean> changeBerthArea(ChangeBerthAreaRequest request) {
BeanValidatorsUtils.validateWithException(request);
berthsDao.changeBerthArea(request.getIds(), request.getParkAreaCode(), request.getOpId());
return new BizResult<Boolean>(true);
}
/**
* 批量保存泊位信息.<br/>
*
* @param request
* @return 2018年1月6日 wangfs.<br/>
*/
@Override
public BizResult<Boolean> batchSaveBerthInfo(BatchSaveBerthInfoRequest request) {
if (request == null || CollectionUtils.isEmpty(request.getListBerthInfo())) {
logger.info("泊位list为空!");
throw new BizException(PDAErrorEnum.PARAMM_NULL, "泊位list");
}
List<TpPBerths> list = new ArrayList<>();
ListCopyUtil.listCopyProperties(request.getListBerthInfo(), list, TpPBerths.class);
/**1.批量保存泊位信息.*/
int batchInsertCount = berthsDao.batchSaveBerthInfo(list);
return new BizResult<Boolean>(batchInsertCount > 0);
}
@Override
public BizResult<Boolean> updateCarNumberByBerthNo(ParkOrderUpdateCarNumberReq req) {
try {
Integer num = parkInOutRecordDao.updateParkInOutRecordCarNumberByOrderId(req);
} catch (Exception e) {
logger.error("更新进出场记录车牌号异常", e);
}
try {
Boolean flag = berthsDao.updateCarNumberByBerthNo(req);
} catch (Exception e) {
logger.error("更新泊位车牌号异常", e);
}
return new BizResult<>(true);
}
}