DeviceLocationService.java
2.42 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
package cn.com.glsx.stdinterface.modules.service;
import cn.com.glsx.stdinterface.dto.DeviceLocationDto;
import cn.com.glsx.stdinterface.modules.mapper.DeviceLocationMapper;
import cn.com.glsx.stdinterface.modules.model.DeviceLocation;
import cn.com.glsx.stdinterface.modules.model.LocationCheckBO;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.Date;
import java.util.List;
/**
* 设备上点 serviceImpl
*
* @author yll
*/
@Slf4j
@Service
public class DeviceLocationService {
@Autowired
private DeviceLocationMapper deviceLocationMapper;
/**
* 插入或者更新设备上点数据
*
* @param deviceLocationDtoList
*/
public void saveOrUpdateDeviceLocationData(Collection<DeviceLocationDto> deviceLocationDtoList) {
deviceLocationDtoList.forEach(deviceLocationDto -> {
DeviceLocation locationBySn = deviceLocationMapper.getDeviceLocationBySn(deviceLocationDto.getSn());
if (ObjectUtil.isNull(locationBySn)) {
DeviceLocation deviceLocation = new DeviceLocation();
BeanUtils.copyProperties(deviceLocationDto, deviceLocation);
deviceLocation.setCreatedTime(new Date());
deviceLocationMapper.insertSelective(deviceLocation);
} else {
mergeData(locationBySn, deviceLocationDto);
deviceLocationMapper.updateByPrimaryKeySelective(locationBySn);
}
});
}
private void mergeData(DeviceLocation locationBySn, DeviceLocationDto deviceLocationDto) {
if (ObjectUtil.isNotEmpty(deviceLocationDto.getLastGpsTime())) {
locationBySn.setLastGpsTime(deviceLocationDto.getLastGpsTime());
}
if (ObjectUtil.isNotEmpty(deviceLocationDto.getLastBsTime())) {
locationBySn.setLastBsTime(deviceLocationDto.getLastBsTime());
}
locationBySn.setUpdatedTime(new Date());
}
/**
* 获取E盾中的所有设备号集合
*
* @return
*/
public List<String> getAllSnInNewEshield() {
return deviceLocationMapper.getAllSnInNewEshield();
}
/**
* 位置验证
*
* @param checkBO
*/
public void locationCheck(LocationCheckBO checkBO) {
}
}