AsyncTasks.java
3.52 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
package cn.com.glsx.stdinterface.modules.multithread;
import cn.com.glsx.devicemonitor.api.dto.response.GpsBsData;
import cn.com.glsx.devicemonitor.api.dto.response.GpsLocation;
import cn.com.glsx.stdinterface.common.constants.Constants;
import cn.com.glsx.stdinterface.modules.entity.VehicleDevice;
import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper;
import cn.com.glsx.stdinterface.modules.remote.RemoteGpsBsService;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
@Slf4j
@Service
public class AsyncTasks {
/**
* 异步填充设备激活经纬度和激活地址信息
*
* @param snList
* @param countDownLatch
* @param remoteGpsBsService
*/
@Async
public void saveActiveInfo(List<String> snList, CountDownLatch countDownLatch, RemoteGpsBsService remoteGpsBsService, VehicleDeviceMapper vehicleDeviceMapper) {
if (CollectionUtils.isEmpty(snList)) {
log.info("countDownLatch查询数据为空关闭资源");
countDownLatch.countDown();
return;
}
try {
List<GpsBsData> lastGpsBsList = remoteGpsBsService.getLastGpsBsListBySns(snList);
if (CollectionUtil.isEmpty(lastGpsBsList)) {
log.info("lastGpsBsList is null");
return;
}
lastGpsBsList.forEach(gpsBsData -> {
VehicleDevice vehicleDevice = vehicleDeviceMapper.selectBindingDeviceBySn(gpsBsData.getSn());
GpsLocation gpsLocation = gpsBsData.getGpsLocation();
// 默认保存GPS定位数据 没有GPS定位数据 保存BS定位数据
if (Objects.nonNull(gpsLocation)) {
vehicleDevice.setActiveLocationDate(DateUtil.parseDateTime(gpsLocation.getDateTime()));
vehicleDevice.setActiveLocationType(Constants.LocationType.GPS);
vehicleDevice.setActiveLocationLng(gpsLocation.getLng());
vehicleDevice.setActiveLocationLat(gpsLocation.getLat());
vehicleDevice.setActiveLocationAddress(gpsLocation.getAddress());
} else {
GpsLocation bsLocation = gpsBsData.getBsLocation();
if (Objects.nonNull(bsLocation)) {
vehicleDevice.setActiveLocationDate(DateUtil.parseDateTime(bsLocation.getDateTime()));
vehicleDevice.setActiveLocationType(Constants.LocationType.BS);
vehicleDevice.setActiveLocationLng(bsLocation.getLng());
vehicleDevice.setActiveLocationLat(bsLocation.getLat());
vehicleDevice.setActiveLocationAddress(bsLocation.getAddress());
}
}
// 保存激活信息
log.info("active device info:" + JSONUtil.toJsonStr(vehicleDevice));
vehicleDeviceMapper.updateByPrimaryKeySelective(vehicleDevice);
});
} catch (Exception e) {
log.info("saveActiveInfo异常信息===" + e.getMessage());
} finally {
countDownLatch.countDown();
log.info(Thread.currentThread().getName() + "countDownLatch关闭资源");
}
}
}