|
@@ -51,8 +51,8 @@ public class BeidouLocationServiceImpl extends ServiceImpl<BeidouLocationMapper,
|
|
|
@Autowired
|
|
|
protected IShipStatusService shipStatusService;
|
|
|
|
|
|
- private Map<String,String> locationMaps= new HashMap<>();
|
|
|
- private Vector<BeidouLocationEntity> locationEntities= new Vector<>();
|
|
|
+ private Map<String,String> locationMap= new HashMap<>();
|
|
|
+ private Map<String,BeidouLocationEntity> entityMap= new HashMap<>();
|
|
|
|
|
|
@Autowired
|
|
|
private SimpleFeatureType sftLocation;
|
|
@@ -75,12 +75,15 @@ public class BeidouLocationServiceImpl extends ServiceImpl<BeidouLocationMapper,
|
|
|
BeidouLocationEntity locationEntity = JSONObject.parseObject(msg.toString(), BeidouLocationEntity.class);
|
|
|
String location = StrUtil.format("POINT ({} {})", locationEntity.getLongitude(),locationEntity.getLatitude());
|
|
|
locationEntity.setLocation(location);
|
|
|
-// BigDecimal longitudeDecimal = new BigDecimal(locationEntity.getLongitude());
|
|
|
-// locationEntity.setLongitude(LatLngUtil.latLng2Dfm(longitudeDecimal.doubleValue()));
|
|
|
-// BigDecimal latitudeDecimal = new BigDecimal(locationEntity.getLatitude());
|
|
|
-// locationEntity.setLatitude(LatLngUtil.latLng2Dfm(latitudeDecimal.doubleValue()));
|
|
|
- locationEntities.add(locationEntity);
|
|
|
- shipStatusService.pushOnLineDeviceId(locationEntity.getDeviceId(),"true");
|
|
|
+ String locationTime = locationEntity.getLocationTime();
|
|
|
+ if (null == entityMap.get(locationEntity.getDeviceId())) {
|
|
|
+ shipStatusService.pushOnLineDeviceId(locationEntity.getDeviceId(),"true");
|
|
|
+ entityMap.put(locationEntity.getDeviceId(),locationEntity);
|
|
|
+ }else if (StringUtils.hasText(locationTime)&& !locationTime.equals(entityMap.get(
|
|
|
+ locationEntity.getDeviceId()).getLocationTime())) {
|
|
|
+ shipStatusService.pushOnLineDeviceId(locationEntity.getDeviceId(),"true");
|
|
|
+ entityMap.put(locationEntity.getDeviceId(),locationEntity);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -91,9 +94,9 @@ public class BeidouLocationServiceImpl extends ServiceImpl<BeidouLocationMapper,
|
|
|
@Override
|
|
|
public void cacheBeidouToMySql() {
|
|
|
Date begin = new Date();
|
|
|
- if(locationEntities.size() > 0){
|
|
|
- List<BeidouLocationEntity> saveList = new ArrayList<>(locationEntities);
|
|
|
- locationEntities.clear();
|
|
|
+ if(entityMap.size() > 0){
|
|
|
+ List<BeidouLocationEntity> saveList = new ArrayList<>(entityMap.values());
|
|
|
+ entityMap.clear();
|
|
|
for(BeidouLocationEntity e : saveList){
|
|
|
if(!StringUtils.hasText(e.getShipName())){
|
|
|
QueryWrapper<BeidouShipArchives> wrapper = new QueryWrapper();
|
|
@@ -104,20 +107,17 @@ public class BeidouLocationServiceImpl extends ServiceImpl<BeidouLocationMapper,
|
|
|
}
|
|
|
}
|
|
|
String location = e.getLocation();
|
|
|
- if (StringUtils.hasText(location) && !location.equals(locationMaps.get(e.getDeviceId()))) {
|
|
|
-// if (StringUtils.hasText(location)) {
|
|
|
-// String longitude = location.substring(location.indexOf("(")+1,location.indexOf(" ",location.indexOf("(")));
|
|
|
-// String latitude = location.substring(location.indexOf(" ",location.indexOf("("))+1,location.indexOf(")"));
|
|
|
+ if (StringUtils.hasText(location) && !location.equals(locationMap.get(e.getDeviceId()))) {
|
|
|
List<ContainsDTO> result = warningAreaMapper.containsPoint(e.getLongitude(),e.getLatitude());
|
|
|
if(result.size()>0){
|
|
|
shipStatusService.pushinportDeviceId(e.getDeviceId(), WarningCodeConstants.INPORT_WARNING);
|
|
|
}else{
|
|
|
shipStatusService.pushinportDeviceId(e.getDeviceId(),WarningCodeConstants.OUTPROT_WARNING);
|
|
|
}
|
|
|
- locationMaps.put(e.getDeviceId(),e.getLocation());
|
|
|
+ locationMap.put(e.getDeviceId(),location);
|
|
|
}
|
|
|
}
|
|
|
- saveBatch(saveList);
|
|
|
+ baseMapper.insertLocationList(saveList);
|
|
|
log.info("位置数据写入数据库完成!耗时 {} 毫秒, 合计保存 {} 条记录", (new Date()).getTime() - begin.getTime(), saveList.size());
|
|
|
}
|
|
|
}
|