DeviceActiveService.java
5.28 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
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.admin.common.enums.TypeConverseEnum;
import cn.com.glsx.admin.modules.mapper.VehicleMapper;
import cn.com.glsx.admin.modules.model.export.DeviceActiveExprot;
import cn.com.glsx.admin.modules.model.param.DeviceActiveSearch;
import cn.com.glsx.admin.modules.multithread.AsyncTasks;
import cn.com.glsx.admin.modules.multithread.ListSplitIterator;
import cn.com.glsx.admin.modules.remote.RemoteGpsBsService;
import cn.com.glsx.admin.modules.remote.RemoteUserApiService;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;
import org.springframework.util.StringUtils;
import java.util.List;
import java.util.concurrent.CountDownLatch;
/**
* 设备激活 service
*
* @author yll
*/
@Slf4j
@Service
public class DeviceActiveService {
@Autowired
private RemoteGpsBsService remoteGpsBsService;
@Autowired
private VehicleMapper vehicleMapper;
@Autowired
private AsyncTasks asyncTasks;
@Autowired
private RemoteUserApiService remoteUserApiService;
@Autowired
private OrganizationApiService organizationApiService;
/**
* 查询设备激活列表
*
* @param search 查询实体
* @return
*/
public List<DeviceActiveExprot> findDeviceActiveList(DeviceActiveSearch search) {
if (search.getOrgId() != null) {
search.setCheckedOrgIds(Lists.newArrayList(search.getOrgId()));
remoteUserApiService.setCheckedOrgUsers(search);
}
List<DeviceActiveExprot> deviceActiveList = vehicleMapper.getBaseDeviceActiveListWithAuth(search);
// 填充组织层级
organizationApiService.drawAllLevel(deviceActiveList);
// 数字类型转换为字符串类型
deviceActiveList.forEach(deviceActiveExprot -> {
deviceActiveExprot.setDeviceTypeStr(TypeConverseEnum.DeviceTypeEnum.getStrByDeviceType(deviceActiveExprot.getDeviceType()));
deviceActiveExprot.setSourceStr(TypeConverseEnum.SourceEnum.getStrBySourceType(deviceActiveExprot.getSource()));
deviceActiveExprot.setIsOnLineStr(TypeConverseEnum.OnLineEnum.getStrByonLineType(deviceActiveExprot.getIsOnLine()));
if (!StringUtils.isEmpty(deviceActiveExprot.getLng()) && !StringUtils.isEmpty(deviceActiveExprot.getLat())) {
deviceActiveExprot.setLngAndLat(deviceActiveExprot.getLng() + "," + deviceActiveExprot.getLat());
}
deviceActiveExprot.setShopName(deviceActiveExprot.getBelongLevels());
});
getDeviceActiveData(deviceActiveList);
return deviceActiveList;
}
/**
* 导出设备激活列表
*
* @param search 导出实体
* @return
*/
public List<DeviceActiveExprot> exportDeviceActiveList(DeviceActiveSearch search) {
if (search.getOrgId() != null) {
search.setCheckedOrgIds(Lists.newArrayList(search.getOrgId()));
remoteUserApiService.setCheckedOrgUsers(search);
}
List<DeviceActiveExprot> deviceActiveList = vehicleMapper.getBaseDeviceActiveListWithAuth(search);
// 填充组织层级
organizationApiService.drawAllLevel(deviceActiveList);
// 数字类型转换为字符串类型
deviceActiveList.forEach(deviceActiveExprot -> {
deviceActiveExprot.setDeviceTypeStr(TypeConverseEnum.DeviceTypeEnum.getStrByDeviceType(deviceActiveExprot.getDeviceType()));
deviceActiveExprot.setSourceStr(TypeConverseEnum.SourceEnum.getStrBySourceType(deviceActiveExprot.getSource()));
deviceActiveExprot.setIsOnLineStr(TypeConverseEnum.OnLineEnum.getStrByonLineType(deviceActiveExprot.getIsOnLine()));
if (!StringUtils.isEmpty(deviceActiveExprot.getLng()) && !StringUtils.isEmpty(deviceActiveExprot.getLat())) {
deviceActiveExprot.setLngAndLat(deviceActiveExprot.getLng() + "," + deviceActiveExprot.getLat());
}
deviceActiveExprot.setShopName(deviceActiveExprot.getBelongLevels());
});
return deviceActiveList;
}
/**
* 多线程查询设备总里程和总行驶次数
*
* @param dataList 数据集合大小
*/
public void getDeviceActiveData(List<DeviceActiveExprot> dataList) {
log.info("###get device active data start###");
if (CollectionUtils.isEmpty(dataList)) {
return;
}
StopWatch sw = new StopWatch();
sw.start("getDeviceActiveData");
ListSplitIterator<DeviceActiveExprot> listSplitIterator = new ListSplitIterator<>(dataList, 500);
CountDownLatch countDownLatch = new CountDownLatch(listSplitIterator.size());
while (listSplitIterator.hasNext()) {
List<DeviceActiveExprot> deviceActiveList = listSplitIterator.next();
asyncTasks.getDeviceActiveData(deviceActiveList, countDownLatch, remoteGpsBsService);
}
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
sw.stop();
log.info("###get device active data end" + sw.getLastTaskTimeMillis() + "ms###");
}
}