|
@@ -1,13 +1,31 @@
|
|
package cn.com.taiji.track.service.impl;
|
|
package cn.com.taiji.track.service.impl;
|
|
|
|
|
|
|
|
+import cn.com.taiji.track.dto.BeidouShipLocationDTO;
|
|
|
|
+import cn.com.taiji.track.dto.IGeomesaTrackDTO;
|
|
import cn.com.taiji.track.entity.BeidouLocationEntity;
|
|
import cn.com.taiji.track.entity.BeidouLocationEntity;
|
|
import cn.com.taiji.track.mapper.BeidouLocationMapper;
|
|
import cn.com.taiji.track.mapper.BeidouLocationMapper;
|
|
import cn.com.taiji.track.service.IBeidouLocationService;
|
|
import cn.com.taiji.track.service.IBeidouLocationService;
|
|
|
|
+import cn.com.taiji.track.service.IShipStatusService;
|
|
import cn.com.taiji.track.utils.LatLngUtil;
|
|
import cn.com.taiji.track.utils.LatLngUtil;
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
|
|
|
+import org.geotools.data.FeatureReader;
|
|
|
|
+import org.geotools.data.FeatureWriter;
|
|
|
|
+import org.geotools.data.Query;
|
|
|
|
+import org.geotools.data.Transaction;
|
|
|
|
+import org.geotools.factory.CommonFactoryFinder;
|
|
|
|
+import org.geotools.feature.simple.SimpleFeatureBuilder;
|
|
|
|
+import org.geotools.filter.identity.FeatureIdImpl;
|
|
|
|
+import org.geotools.util.factory.Hints;
|
|
|
|
+import org.locationtech.geomesa.redis.data.RedisDataStore;
|
|
|
|
+import org.opengis.feature.simple.SimpleFeature;
|
|
|
|
+import org.opengis.feature.simple.SimpleFeatureType;
|
|
|
|
+import org.opengis.filter.Filter;
|
|
|
|
+import org.opengis.filter.FilterFactory2;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
@@ -21,8 +39,18 @@ import java.util.*;
|
|
@Service
|
|
@Service
|
|
@Slf4j
|
|
@Slf4j
|
|
public class BeidouLocationServiceImpl extends ServiceImpl<BeidouLocationMapper, BeidouLocationEntity> implements IBeidouLocationService {
|
|
public class BeidouLocationServiceImpl extends ServiceImpl<BeidouLocationMapper, BeidouLocationEntity> implements IBeidouLocationService {
|
|
|
|
+ @Autowired
|
|
|
|
+ protected IShipStatusService shipStatusService;
|
|
|
|
+
|
|
|
|
+ private Map<String,BeidouShipLocationDTO> locationMaps= new HashMap<>();
|
|
private Vector<BeidouLocationEntity> locationEntities= new Vector<>();
|
|
private Vector<BeidouLocationEntity> locationEntities= new Vector<>();
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private SimpleFeatureType sftLocation;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisDataStore redisDataStore;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IGeomesaTrackDTO geomesaLocationDTO;
|
|
@Override
|
|
@Override
|
|
public void beidouDynamicShipToCache(List<ConsumerRecord<?, ?>> records){
|
|
public void beidouDynamicShipToCache(List<ConsumerRecord<?, ?>> records){
|
|
try {
|
|
try {
|
|
@@ -31,12 +59,14 @@ public class BeidouLocationServiceImpl extends ServiceImpl<BeidouLocationMapper,
|
|
if (message.isPresent()) {
|
|
if (message.isPresent()) {
|
|
Object msg = message.get();
|
|
Object msg = message.get();
|
|
BeidouLocationEntity locationEntity = JSONObject.parseObject(msg.toString(), BeidouLocationEntity.class);
|
|
BeidouLocationEntity locationEntity = JSONObject.parseObject(msg.toString(), BeidouLocationEntity.class);
|
|
- locationEntity.setLocation(String.format("POINT(%s %s)",locationEntity.getLongitude(),locationEntity.getLatitude()));
|
|
|
|
|
|
+ String location = StrUtil.format("POINT ({} {})", locationEntity.getLongitude(),locationEntity.getLatitude());
|
|
|
|
+ locationEntity.setLocation(location);
|
|
BigDecimal longitudeDecimal = new BigDecimal(locationEntity.getLongitude());
|
|
BigDecimal longitudeDecimal = new BigDecimal(locationEntity.getLongitude());
|
|
locationEntity.setLongitude(LatLngUtil.latLng2Dfm(longitudeDecimal.doubleValue()));
|
|
locationEntity.setLongitude(LatLngUtil.latLng2Dfm(longitudeDecimal.doubleValue()));
|
|
BigDecimal latitudeDecimal = new BigDecimal(locationEntity.getLatitude());
|
|
BigDecimal latitudeDecimal = new BigDecimal(locationEntity.getLatitude());
|
|
locationEntity.setLatitude(LatLngUtil.latLng2Dfm(latitudeDecimal.doubleValue()));
|
|
locationEntity.setLatitude(LatLngUtil.latLng2Dfm(latitudeDecimal.doubleValue()));
|
|
locationEntities.add(locationEntity);
|
|
locationEntities.add(locationEntity);
|
|
|
|
+ shipStatusService.pushOnLineDeviceId(locationEntity.getDeviceId());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -56,7 +86,67 @@ public class BeidouLocationServiceImpl extends ServiceImpl<BeidouLocationMapper,
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void queryLocationToRedis() {
|
|
|
|
-
|
|
|
|
|
|
+ public void listLocationToCache() {
|
|
|
|
+ List<BeidouShipLocationDTO> results = baseMapper.listLocation();
|
|
|
|
+ if (results.size() > 0) {
|
|
|
|
+ FeatureReader<SimpleFeatureType, SimpleFeature> reader = null;
|
|
|
|
+ FeatureWriter<SimpleFeatureType, SimpleFeature> writer = null;
|
|
|
|
+ try {
|
|
|
|
+ writer = redisDataStore.getFeatureWriterAppend(sftLocation.getTypeName(), Transaction.AUTO_COMMIT);
|
|
|
|
+ SimpleFeatureBuilder builder = new SimpleFeatureBuilder(sftLocation);
|
|
|
|
+ for (IGeomesaTrackDTO dto : results) {
|
|
|
|
+ dto.setKafkaConsumerGroup(geomesaLocationDTO.getKafkaConsumerGroup());
|
|
|
|
+ dto.setExpirySeconds(geomesaLocationDTO.getExpirySeconds());
|
|
|
|
+ if (!dto.checkPoint()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ String fid = dto.getFid();
|
|
|
|
+ boolean append = true;
|
|
|
|
+ FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2();
|
|
|
|
+ Filter filter = null;
|
|
|
|
+ if (null != fid && !"".equals(fid)) {
|
|
|
|
+ filter = filterFactory.id(filterFactory.featureId(fid));
|
|
|
|
+ } else {
|
|
|
|
+ String id = UUID.randomUUID().toString();
|
|
|
|
+ filter = filterFactory.id(filterFactory.featureId(id));
|
|
|
|
+ }
|
|
|
|
+ Query query = new Query(dto.getTypeName(), filter);
|
|
|
|
+ reader = redisDataStore.getFeatureReader(query, Transaction.AUTO_COMMIT);
|
|
|
|
+ if (reader.hasNext()) {
|
|
|
|
+ append = false;
|
|
|
|
+ String[] propList = dto.getPropList();
|
|
|
|
+ Object[] valueList = dto.getValueList();
|
|
|
|
+ redisDataStore.getFeatureSource(dto.getTypeName()).modifyFeatures(propList, valueList, filter);
|
|
|
|
+ }
|
|
|
|
+ reader.close();
|
|
|
|
+ reader = null;
|
|
|
|
+ if (append) {
|
|
|
|
+ SimpleFeature toWrite = writer.next();
|
|
|
|
+ builder.reset();
|
|
|
|
+ SimpleFeature feature = dto.toSimpleFeature(builder, fid);
|
|
|
|
+ toWrite.setAttributes(feature.getAttributes());
|
|
|
|
+ toWrite.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);
|
|
|
|
+ ((FeatureIdImpl) toWrite.getIdentifier()).setID(feature.getID());
|
|
|
|
+ toWrite.getUserData().putAll(feature.getUserData());
|
|
|
|
+ writer.write();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("=======插入geomesa发生异常============");
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ try {
|
|
|
|
+ if (null != writer) {
|
|
|
|
+ writer.close();
|
|
|
|
+ }
|
|
|
|
+ if (null != reader) {
|
|
|
|
+ reader.close();
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("=======close操作发生异常============");
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|