RemoteGpsBsService.java
6.4 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
package cn.com.glsx.stdinterface.modules.remote;
import cn.com.glsx.devicemonitor.api.dto.request.GpsBsFirstBatchRequest;
import cn.com.glsx.devicemonitor.api.dto.response.GpsBsData;
import cn.com.glsx.devicemonitor.api.enums.DeviceTypeRelationEnum;
import cn.com.glsx.devicemonitor.api.feign.GpsBsFeignService;
import cn.com.glsx.stdinterface.modules.entity.Device;
import cn.com.glsx.stdinterface.modules.entity.VehicleDevice;
import cn.com.glsx.stdinterface.modules.mapper.DeviceMapper;
import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper;
import cn.com.glsx.stdinterface.modules.service.VehicleDeviceService;
import cn.hutool.core.date.DateUtil;
import com.glsx.plat.common.utils.StringUtils;
import com.glsx.plat.core.web.R;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* GpsBsService 服务的处理层
*
* @author yll
*/
@Slf4j
@Service
public class RemoteGpsBsService {
@Autowired
private GpsBsFeignService gpsBsFeignService;
@Autowired
private DeviceMapper deviceMapper;
@Autowired
private VehicleDeviceMapper vehicleDeviceMapper;
/**
* 通过经纬度获取地址
*
* @param lng 经度
* @param lat 纬度
* @return 地址
*/
public String getAddressByLngAndLat(String lng, String lat) {
if (StringUtils.isEmpty(lng) || StringUtils.isEmpty(lat)) {
return "";
}
R<String> addressR = gpsBsFeignService.getAddressByLngAndLat(lng, lat);
String address = addressR.getData(String.class);
if (StringUtils.isNullOrEmpty(address)) {
address = "";
}
return address;
}
/**
* 根据设备号获取定位信息
*
* @param snList 设备号集合
* @return
*/
public Map<String, GpsBsData> getLastGpsBsMapBySns(List<String> snList) {
List<Device> deviceList = deviceMapper.selectBySns(snList);
//注意这里过滤了设备类型为空的数据,如果设备不在线,要检查设备类型数据是否同步或设置
Map<String, Integer> snsMap = deviceList.stream().filter(m -> m.getDeviceType() != null).collect(Collectors.toMap(Device::getSn, Device::getDeviceType, (o, n) -> n));
R<List<GpsBsData>> listR = gpsBsFeignService.getLastGpsBsBySns(snsMap);
List<GpsBsData> gpsBsDataList = listR.getDataList(new TypeToken<List<GpsBsData>>() {
}.getType());
Map<String, GpsBsData> gpsBsDataMap = Maps.newHashMap();
if (CollectionUtils.isNotEmpty(gpsBsDataList)) {
gpsBsDataMap = gpsBsDataList.stream().collect(Collectors.toMap(GpsBsData::getSn, Function.identity(), (o, n) -> n));
}
return gpsBsDataMap;
}
/**
* 根据设备号获取定位信息
*
* @param snList 设备号集合
* @return
*/
public List<GpsBsData> getLastGpsBsListBySns(List<String> snList) {
List<Device> deviceList = deviceMapper.selectBySns(snList);
//注意这里过滤了设备类型为空的数据,如果设备不在线,要检查设备类型数据是否同步或设置
Map<String, Integer> snsMap = deviceList.stream().filter(m -> m.getDeviceType() != null).collect(Collectors.toMap(Device::getSn, Device::getDeviceType, (o, n) -> n));
R<List<GpsBsData>> listR = gpsBsFeignService.getLastGpsBsBySns(snsMap);
List<GpsBsData> gpsBsDataList = listR.getDataList(new TypeToken<List<GpsBsData>>() {
}.getType());
return gpsBsDataList;
}
/**
* 根据设备号和激活时间获取激活定位点经纬度数据
*
* @return
*/
public List<GpsBsData> getFirstGpsBsBatch(List<String> snList) {
List<GpsBsFirstBatchRequest> gpsBsFirstBatchRequestList = Lists.newArrayList();
List<VehicleDevice> vehicleDeviceList = vehicleDeviceMapper.selectBindingDevices(snList);
vehicleDeviceList.stream().filter(vehicleDevice -> vehicleDevice.getCreatedDate() != null).forEach(vehicleDevice -> {
GpsBsFirstBatchRequest gpsBsFirstBatchRequest = new GpsBsFirstBatchRequest();
gpsBsFirstBatchRequest.setSn(vehicleDevice.getSn());
gpsBsFirstBatchRequest.setActiveDate(DateUtil.formatDateTime(vehicleDevice.getCreatedDate()));
gpsBsFirstBatchRequest.setDeviceTypeRelationEnum(DeviceTypeRelationEnum.GPS);
gpsBsFirstBatchRequestList.add(gpsBsFirstBatchRequest);
});
R<List<GpsBsData>> firstGpsBsBatchR = gpsBsFeignService.getFirstGpsBsBatch(gpsBsFirstBatchRequestList);
List<GpsBsData> firstGpsBsDataList = firstGpsBsBatchR.getDataList(new TypeToken<List<GpsBsData>>() {
}.getType());
return firstGpsBsDataList;
}
/**
* 将定位集合list 转换成map
*
* @param snList 设备集合
* @return
*/
public Map<String, GpsBsData> getLastGpsBsBatchBySns(List<String> snList) {
R<List<GpsBsData>> lastGpsBsBatch = gpsBsFeignService.getLastGpsBsBatch(snList);
List<GpsBsData> gpsBsDataList = lastGpsBsBatch.getDataList(new TypeToken<List<GpsBsData>>() {
}.getType());
Map<String, GpsBsData> gpsBsDataMap = Maps.newHashMap();
if (CollectionUtils.isNotEmpty(gpsBsDataList)) {
gpsBsDataMap = gpsBsDataList.stream().collect(Collectors.toMap(GpsBsData::getSn, Function.identity(), (o, n) -> n));
}
return gpsBsDataMap;
}
/**
* 将定位集合list 转换成map
*
* @param snList 设备集合
* @return
*/
public Map<String, GpsBsData> getLastGpsBsSimpleBatchBySns(List<String> snList) {
R<List<GpsBsData>> lastGpsBsBatch = gpsBsFeignService.getLastGpsBsSimpleBatch(snList);
List<GpsBsData> gpsBsDataList = lastGpsBsBatch.getDataList(new TypeToken<List<GpsBsData>>() {
}.getType());
Map<String, GpsBsData> gpsBsDataMap = Maps.newHashMap();
if (CollectionUtils.isNotEmpty(gpsBsDataList)) {
gpsBsDataMap = gpsBsDataList.stream().collect(Collectors.toMap(GpsBsData::getSn, Function.identity(), (o, n) -> n));
}
return gpsBsDataMap;
}
}