DeviceActiveService.java
3.41 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
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.admin.common.enums.TypeConverseEunm;
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 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 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;
/**
* 查询设备激活列表
*
* @param deviceActiveSearch 查询实体
* @return
*/
public List<DeviceActiveExprot> findDeviceActiveList(DeviceActiveSearch deviceActiveSearch) {
List<DeviceActiveExprot> deviceActiveList = vehicleMapper.getBaseDeviceActiveListWithAuth(deviceActiveSearch);
getDeviceActiveData(deviceActiveList);
return deviceActiveList;
}
/**
* 导出设备激活列表
*
* @param deviceActiveSearch 导出实体
* @return
*/
public List<DeviceActiveExprot> exportDeviceActiveList(DeviceActiveSearch deviceActiveSearch) {
List<DeviceActiveExprot> deviceActiveList = vehicleMapper.getBaseDeviceActiveListWithAuth(deviceActiveSearch);
getDeviceActiveData(deviceActiveList);
// 数字类型转换为字符串类型
deviceActiveList.forEach(deviceActiveExprot -> {
deviceActiveExprot.setDeviceTypeStr(TypeConverseEunm.DeviceTypeEnum.getStrByDeviceType(deviceActiveExprot.getDeviceType()));
deviceActiveExprot.setSourceStr(TypeConverseEunm.SourceEnum.getStrBySourceType(deviceActiveExprot.getSource()));
deviceActiveExprot.setSourceStr(TypeConverseEunm.OnLineEnum.getStrByonLineType(deviceActiveExprot.getIsOnLine()));
});
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###");
}
}