ParkingLotGeoDaoImpl.java
6.6 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
package com.zteits.park.dao.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Point;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import com.clouds.common.cache.park.ParkingLotGeoCacheUtil;
import com.clouds.common.utils.ListPageHelper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.zteits.clouds.api.apibase.constants.DataStatusEnum;
import com.zteits.clouds.api.apibase.constants.LonLatTypeEnum;
import com.zteits.clouds.api.dto.park.param.ParkingLotGeoForPageRequest;
import com.zteits.park.dao.ParkingLotGeoDao;
import com.zteits.park.domain.Coordinate;
import com.zteits.park.domain.ParkingLotGeo;
import com.zteits.park.domain.ParkingLotGeoExample;
import com.zteits.park.mapper.ParkingLotGeoMapper;
import com.zteits.park.mapper.smapper.ParkingLotGeoSMapper;
/**
* Copyright: Copyright (c) 2017 zteits
*
* @ClassName: ParkingLotGeoDaoImpl.java
* @Description:
* @version: v1.0.0
* @author: langlw
* @date: 2017年6月1日 上午9:55:00
* Modification History:
* Date Author Version Description
* ---------------------------------------------------------*
* 2017年6月1日 langlw v1.0.0 创建
*/
@Component
public class ParkingLotGeoDaoImpl implements ParkingLotGeoDao {
@Autowired
private ParkingLotGeoMapper parkingLotGeoMapper;
@Autowired
private ParkingLotGeoSMapper parkingLotGeoSMapper;
@Override
public PageInfo<ParkingLotGeo> queryParkingLotGeoForPage(ParkingLotGeoForPageRequest request) {
// 1.设置分页信息
PageHelper.startPage(request.getBaseRequest().getPageNum(), request.getBaseRequest().getPageSize());
//2.查询数据
ParkingLotGeo parkingLotGeo = new ParkingLotGeo();
BeanUtils.copyProperties(request, parkingLotGeo);
List<ParkingLotGeo> list = parkingLotGeoSMapper.queryParkingLotGeoForList(parkingLotGeo);
return new PageInfo<ParkingLotGeo>(list);
}
@Override
public ParkingLotGeo queryParkingLotGeoByPrimaryKey(Long geoId) {
return parkingLotGeoMapper.selectByPrimaryKey(geoId);
}
@Transactional
@Override
public Long saveOrModifyParkingLotGeo(ParkingLotGeo parkingLotGeo) {
parkingLotGeo.setModifyTime(new Date());
Long flg = null;
if (null == parkingLotGeo.getGeoId()) {
parkingLotGeo.setCreateTime(new Date());
parkingLotGeo.setDataStatus(1);
int flgNum = parkingLotGeoMapper.insertSelective(parkingLotGeo);
if(flgNum > 0){
flg = 1L;
}
} else {
int flgNum = parkingLotGeoMapper.updateByPrimaryKeySelective(parkingLotGeo);
if(flgNum > 0){
flg = 1L;
}
}
//把ID返回去--白取id,因为没有放值
return flg;
}
@Override
public List<ParkingLotGeo> queryParkingLotGeoByExample(ParkingLotGeoExample record) {
return parkingLotGeoMapper.selectByExample(record);
}
@Override
public Boolean deleteParkingLotGeoByPlNos(List<String> plNos,Long opId) {
ParkingLotGeoExample exampleGeo = new ParkingLotGeoExample();
ParkingLotGeo recordGeo = new ParkingLotGeo();
recordGeo.setDataStatus(DataStatusEnum.DATA_STATUS_NO_VALID.value());
recordGeo.setModifyTime(new Date());
recordGeo.setModifyOp(opId);
exampleGeo.createCriteria().andPlNoIn(plNos);
parkingLotGeoMapper.updateByExampleSelective(recordGeo, exampleGeo);
/**删除redis中的经纬度.*/
plNos.forEach(plNo->{
ParkingLotGeoCacheUtil.deletePointByPlNo(LonLatTypeEnum.LON_LAT_TYPE_1, plNo);
ParkingLotGeoCacheUtil.deletePointByPlNo(LonLatTypeEnum.LON_LAT_TYPE_3, plNo);
});
return true;
}
@Override
public Boolean batchSaveParkingLotGeo(List<ParkingLotGeo> lotGeos) {
if (CollectionUtils.isEmpty(lotGeos)) { return true; }
int savenum = parkingLotGeoSMapper.batchSaveParkingLotGeo(lotGeos);
return savenum > 0 ? true : false;
}
@Override
public Coordinate queryParkingLotGeoByParkNo(String pklNo,Integer lonLatType) {
Coordinate coordinate = new Coordinate();
List<Point> points = Lists.newArrayList();
if(lonLatType == LonLatTypeEnum.LON_LAT_TYPE_1.value()){
points = ParkingLotGeoCacheUtil.queryPointByPlNo(LonLatTypeEnum.LON_LAT_TYPE_1, pklNo);
}else{
points = ParkingLotGeoCacheUtil.queryPointByPlNo(LonLatTypeEnum.LON_LAT_TYPE_3, pklNo);
}
if(CollectionUtils.isEmpty(points) || points.get(0) == null){
//查询数据库
List<ParkingLotGeo> parkingLotGeos = parkingLotGeoSMapper.queryParkingLotGeoByParkNo(pklNo,null,lonLatType);
if(!CollectionUtils.isEmpty(parkingLotGeos)){
ParkingLotGeo parkingLotGeo = parkingLotGeos.get(0);
coordinate.setId(pklNo);
if(parkingLotGeo!=null && parkingLotGeo.getLonId()!=null && parkingLotGeo.getLatId()!=null){
coordinate.setLon(parkingLotGeo.getLonId().doubleValue());
coordinate.setLat(parkingLotGeo.getLatId().doubleValue());
}
else{
coordinate.setLon(0.0);
coordinate.setLat(0.0);
}
}
}else{
coordinate.setId(pklNo);
coordinate.setLon(points.get(0).getX());
coordinate.setLat(points.get(0).getY());
}
return coordinate;
}
@Override
public Map<String,List<ParkingLotGeo>> queryParkingLotGeoListByParkNos(List<String> pklNos, Integer geoType,Integer lonLatType) {
List<ParkingLotGeo> list = new ArrayList<ParkingLotGeo>();
ListPageHelper<String> pageInfo = new ListPageHelper<String>(pklNos, 500);
for (int i = 1; i <= pageInfo.getTotalPages(); i++) {
List<ParkingLotGeo> ll = parkingLotGeoSMapper.queryParkingLotGeoListByParkNos(pklNos, geoType,lonLatType);
if (!CollectionUtils.isEmpty(ll)) {
list.addAll(ll);
}
}
if(CollectionUtils.isEmpty(list)){
return new HashMap<>();
}
Map<String, List<ParkingLotGeo>> map = list.stream().collect(Collectors.groupingBy(ParkingLotGeo::getPlNo));
return map;
}
}