Compare commits
No commits in common. "server_five" and "server_five_liuyunhu" have entirely different histories.
server_fiv
...
server_fiv
|
@ -6,7 +6,6 @@ import lombok.NoArgsConstructor;
|
|||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fufanrui
|
||||
|
@ -21,7 +20,7 @@ import java.util.List;
|
|||
public class RealTimeDataRequest implements Serializable {
|
||||
|
||||
|
||||
private List<Long> userId;
|
||||
private Long userId;
|
||||
|
||||
private String vin;
|
||||
|
||||
|
|
|
@ -23,13 +23,14 @@ public class RedisService {
|
|||
public RedisTemplate redisTemplate;
|
||||
|
||||
|
||||
|
||||
// ... 其他已有方法 ...
|
||||
|
||||
/**
|
||||
* 向指定集合中添加值,如果值不存在则添加并返回true,否则返回false。
|
||||
*
|
||||
* @param setKey 集合键名
|
||||
* @param value 要添加的值
|
||||
* @param value 要添加的值
|
||||
* @return true表示值已成功添加(之前不存在),false表示值已存在
|
||||
*/
|
||||
public boolean addToSetIfNotExists(String setKey, String value) {
|
||||
|
@ -43,7 +44,7 @@ public class RedisService {
|
|||
* @param key 缓存的键值
|
||||
* @param value 缓存的值
|
||||
*/
|
||||
public <T> void setCacheObject(final String key, final T value) {
|
||||
public <T> void setCacheObject (final String key, final T value) {
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
}
|
||||
|
||||
|
@ -55,7 +56,7 @@ public class RedisService {
|
|||
* @param timeout 时间
|
||||
* @param timeUnit 时间颗粒度
|
||||
*/
|
||||
public <T> void setCacheObject(final String key, final T value, final Long timeout, final TimeUnit timeUnit) {
|
||||
public <T> void setCacheObject (final String key, final T value, final Long timeout, final TimeUnit timeUnit) {
|
||||
redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
|
||||
}
|
||||
|
||||
|
@ -64,9 +65,10 @@ public class RedisService {
|
|||
*
|
||||
* @param key Redis键
|
||||
* @param timeout 超时时间
|
||||
*
|
||||
* @return true=设置成功;false=设置失败
|
||||
*/
|
||||
public boolean expire(final String key, final long timeout) {
|
||||
public boolean expire (final String key, final long timeout) {
|
||||
return expire(key, timeout, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
@ -76,9 +78,10 @@ public class RedisService {
|
|||
* @param key Redis键
|
||||
* @param timeout 超时时间
|
||||
* @param unit 时间单位
|
||||
*
|
||||
* @return true=设置成功;false=设置失败
|
||||
*/
|
||||
public boolean expire(final String key, final long timeout, final TimeUnit unit) {
|
||||
public boolean expire (final String key, final long timeout, final TimeUnit unit) {
|
||||
return redisTemplate.expire(key, timeout, unit);
|
||||
}
|
||||
|
||||
|
@ -86,9 +89,10 @@ public class RedisService {
|
|||
* 获取有效时间
|
||||
*
|
||||
* @param key Redis键
|
||||
*
|
||||
* @return 有效时间
|
||||
*/
|
||||
public long getExpire(final String key) {
|
||||
public long getExpire (final String key) {
|
||||
return redisTemplate.getExpire(key);
|
||||
}
|
||||
|
||||
|
@ -96,9 +100,10 @@ public class RedisService {
|
|||
* 判断 key是否存在
|
||||
*
|
||||
* @param key 键
|
||||
*
|
||||
* @return true 存在 false不存在
|
||||
*/
|
||||
public Boolean hasKey(String key) {
|
||||
public Boolean hasKey (String key) {
|
||||
return redisTemplate.hasKey(key);
|
||||
}
|
||||
|
||||
|
@ -106,9 +111,10 @@ public class RedisService {
|
|||
* 获得缓存的基本对象。
|
||||
*
|
||||
* @param key 缓存键值
|
||||
*
|
||||
* @return 缓存键值对应的数据
|
||||
*/
|
||||
public <T> T getCacheObject(final String key) {
|
||||
public <T> T getCacheObject (final String key) {
|
||||
ValueOperations<String, T> operation = redisTemplate.opsForValue();
|
||||
return operation.get(key);
|
||||
}
|
||||
|
@ -118,7 +124,7 @@ public class RedisService {
|
|||
*
|
||||
* @param key
|
||||
*/
|
||||
public boolean deleteObject(final String key) {
|
||||
public boolean deleteObject (final String key) {
|
||||
return redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
|
@ -126,9 +132,10 @@ public class RedisService {
|
|||
* 删除集合对象
|
||||
*
|
||||
* @param collection 多个对象
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean deleteObject(final Collection collection) {
|
||||
public boolean deleteObject (final Collection collection) {
|
||||
return redisTemplate.delete(collection) > 0;
|
||||
}
|
||||
|
||||
|
@ -137,9 +144,10 @@ public class RedisService {
|
|||
*
|
||||
* @param key 缓存的键值
|
||||
* @param dataList 待缓存的List数据
|
||||
*
|
||||
* @return 缓存的对象
|
||||
*/
|
||||
public <T> long setCacheList(final String key, final List<T> dataList) {
|
||||
public <T> long setCacheList (final String key, final List<T> dataList) {
|
||||
Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
|
||||
return count == null ? 0 : count;
|
||||
}
|
||||
|
@ -148,9 +156,10 @@ public class RedisService {
|
|||
* 获得缓存的list对象
|
||||
*
|
||||
* @param key 缓存的键值
|
||||
*
|
||||
* @return 缓存键值对应的数据
|
||||
*/
|
||||
public <T> List<T> getCacheList(final String key) {
|
||||
public <T> List<T> getCacheList (final String key) {
|
||||
return redisTemplate.opsForList().range(key, 0, -1);
|
||||
}
|
||||
|
||||
|
@ -159,9 +168,10 @@ public class RedisService {
|
|||
*
|
||||
* @param key 缓存键值
|
||||
* @param dataSet 缓存的数据
|
||||
*
|
||||
* @return 缓存数据的对象
|
||||
*/
|
||||
public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet) {
|
||||
public <T> BoundSetOperations<String, T> setCacheSet (final String key, final Set<T> dataSet) {
|
||||
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
|
||||
Iterator<T> it = dataSet.iterator();
|
||||
while (it.hasNext()) {
|
||||
|
@ -169,25 +179,25 @@ public class RedisService {
|
|||
}
|
||||
return setOperation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存Set
|
||||
*
|
||||
* @param key 缓存键值
|
||||
* @param key 缓存键值
|
||||
* @param setValue 缓存的数据
|
||||
*
|
||||
* @return 缓存数据的对象
|
||||
*/
|
||||
public <T> BoundSetOperations<String, T> setCacheSet(final String key, final T setValue) {
|
||||
public <T> BoundSetOperations<String, T> setCacheSet (final String key, final T setValue) {
|
||||
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
|
||||
setOperation.add(setValue);
|
||||
return setOperation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存Set
|
||||
*
|
||||
* @param key 缓存键值
|
||||
* @param key 缓存键值
|
||||
* @param setValue 缓存的数据
|
||||
*
|
||||
* @return 缓存数据的对象
|
||||
*/
|
||||
public <T> void deleteSet(String key, String setValue) {
|
||||
|
@ -195,25 +205,26 @@ public class RedisService {
|
|||
BoundSetOperations setOperations = redisTemplate.boundSetOps(key);
|
||||
setOperations.remove(setValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得缓存的set
|
||||
*
|
||||
* @param key
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public <T> Set<T> getCacheSet(final String key) {
|
||||
public <T> Set<T> getCacheSet (final String key) {
|
||||
return redisTemplate.opsForSet().members(key);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 缓存Map
|
||||
*
|
||||
* @param key
|
||||
* @param dataMap
|
||||
*/
|
||||
public <T> void setCacheMap(final String key, final Map<String, T> dataMap) {
|
||||
public <T> void setCacheMap (final String key, final Map<String, T> dataMap) {
|
||||
if (dataMap != null) {
|
||||
redisTemplate.opsForHash().putAll(key, dataMap);
|
||||
}
|
||||
|
@ -223,9 +234,10 @@ public class RedisService {
|
|||
* 获得缓存的Map
|
||||
*
|
||||
* @param key
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public <T> Map<String, T> getCacheMap(final String key) {
|
||||
public <T> Map<String, T> getCacheMap (final String key) {
|
||||
return redisTemplate.opsForHash().entries(key);
|
||||
}
|
||||
|
||||
|
@ -236,7 +248,7 @@ public class RedisService {
|
|||
* @param hKey Hash键
|
||||
* @param value 值
|
||||
*/
|
||||
public <T> void setCacheMapValue(final String key, final String hKey, final T value) {
|
||||
public <T> void setCacheMapValue (final String key, final String hKey, final T value) {
|
||||
redisTemplate.opsForHash().put(key, hKey, value);
|
||||
}
|
||||
|
||||
|
@ -245,9 +257,10 @@ public class RedisService {
|
|||
*
|
||||
* @param key Redis键
|
||||
* @param hKey Hash键
|
||||
*
|
||||
* @return Hash中的对象
|
||||
*/
|
||||
public <T> T getCacheMapValue(final String key, final String hKey) {
|
||||
public <T> T getCacheMapValue (final String key, final String hKey) {
|
||||
HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
|
||||
return opsForHash.get(key, hKey);
|
||||
}
|
||||
|
@ -257,9 +270,10 @@ public class RedisService {
|
|||
*
|
||||
* @param key Redis键
|
||||
* @param hKeys Hash键集合
|
||||
*
|
||||
* @return Hash对象集合
|
||||
*/
|
||||
public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys) {
|
||||
public <T> List<T> getMultiCacheMapValue (final String key, final Collection<Object> hKeys) {
|
||||
return redisTemplate.opsForHash().multiGet(key, hKeys);
|
||||
}
|
||||
|
||||
|
@ -268,9 +282,10 @@ public class RedisService {
|
|||
*
|
||||
* @param key Redis键
|
||||
* @param hKey Hash键
|
||||
*
|
||||
* @return 是否成功
|
||||
*/
|
||||
public boolean deleteCacheMapValue(final String key, final String hKey) {
|
||||
public boolean deleteCacheMapValue (final String key, final String hKey) {
|
||||
return redisTemplate.opsForHash().delete(key, hKey) > 0;
|
||||
}
|
||||
|
||||
|
@ -278,19 +293,20 @@ public class RedisService {
|
|||
* 获得缓存的基本对象列表
|
||||
*
|
||||
* @param pattern 字符串前缀
|
||||
*
|
||||
* @return 对象列表
|
||||
*/
|
||||
public Collection<String> keys(final String pattern) {
|
||||
public Collection<String> keys (final String pattern) {
|
||||
return redisTemplate.keys(pattern);
|
||||
}
|
||||
|
||||
public void setVinAndUserId(RealTimeDataRequest realTimeDataRequest) {
|
||||
String key = "vin:" + realTimeDataRequest.getVin();
|
||||
redisTemplate.opsForSet().add(key, realTimeDataRequest);
|
||||
String key = "vin:"+realTimeDataRequest.getVin();
|
||||
redisTemplate.opsForValue().set(key, realTimeDataRequest);
|
||||
}
|
||||
|
||||
public void stopViewingData(String vin) {
|
||||
String key = "vin:" + vin;
|
||||
String key = "vin:"+vin;
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.couplet.analyze.msg;
|
||||
|
||||
import com.couplet.analyze.msg.model.ModelsKafkaMessage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
@ -20,8 +18,5 @@ public class CoupletMsgApplication {
|
|||
public static void main(String[] args) {
|
||||
SpringApplication.run(CoupletMsgApplication.class);
|
||||
System.out.println("解析系统启动成功");
|
||||
new ModelsKafkaMessage().initKafkaConsumer();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.couplet.analyze.msg.model;
|
||||
|
||||
|
||||
import com.couplet.analyze.common.event.AnalyzeEventCache;
|
||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||
import com.couplet.analyze.msg.service.IncidentService;
|
||||
|
@ -11,7 +10,6 @@ import org.apache.kafka.clients.consumer.ConsumerConfig;
|
|||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
@ -38,7 +36,7 @@ import static java.lang.Thread.sleep;
|
|||
@Component
|
||||
@Slf4j
|
||||
public class ModelsKafkaMessage {
|
||||
private static final String TOPIC_NAME = "topic_lyh";
|
||||
private static final String TOPIC_NAME = "lyh";
|
||||
private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092";
|
||||
|
||||
|
||||
|
@ -52,16 +50,13 @@ public class ModelsKafkaMessage {
|
|||
private AnalyzeEventCache analyzeEventCache;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//kafka消费者初始化
|
||||
@PostConstruct
|
||||
public void initKafkaConsumer() {
|
||||
Properties props = new Properties();
|
||||
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
|
||||
// props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-consumer-group");
|
||||
props.put(ConsumerConfig.GROUP_ID_CONFIG, "group");
|
||||
props.put(ConsumerConfig.GROUP_ID_CONFIG, "lll");
|
||||
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
|
||||
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
|
||||
|
||||
|
@ -91,7 +86,7 @@ public class ModelsKafkaMessage {
|
|||
while (true) {
|
||||
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
|
||||
records.forEach(record -> {
|
||||
log.info("接收到的数据:" + record.value());
|
||||
System.out.println("接收到的数据:" + record.value());
|
||||
String str = hexToString(record.value());
|
||||
List<CoupletMsgData> coupletMsgDataList = sendMsg(str);
|
||||
for (CoupletMsgData msgData : coupletMsgDataList) {
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.couplet.analyze.common.contents.AnalyzeEventContents;
|
|||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||
import com.couplet.analyze.msg.service.IncidentService;
|
||||
import com.couplet.common.core.text.Convert;
|
||||
import com.couplet.common.core.utils.StringUtils;
|
||||
import com.couplet.common.domain.Fence;
|
||||
import com.couplet.common.domain.request.FenceAndLogeRequest;
|
||||
import com.couplet.common.redis.service.RedisService;
|
||||
|
@ -47,32 +46,34 @@ public class ElectronicFenceServiceImpl implements IncidentService {
|
|||
if (redisService.hasKey(fenceKey)) {
|
||||
Set<Fence> cacheSet = redisService.getCacheSet(fenceKey);
|
||||
log.info("电子围栏事件redis存在.......");
|
||||
// jingdu;
|
||||
// longitude;
|
||||
// weidu;
|
||||
// latitude;
|
||||
for (Fence fence : cacheSet) {
|
||||
String fenceLongitudeLatitude = fence.getFenceLongitudeLatitude();
|
||||
if (StringUtils.isEmpty(fenceLongitudeLatitude)){
|
||||
/**
|
||||
* 先通过;后切割
|
||||
*/
|
||||
String[] split = fenceLongitudeLatitude.split(";");
|
||||
for (String s : split) {
|
||||
String[] strings = s.split(",");
|
||||
if (strings.length == 2) {
|
||||
// 经度
|
||||
Double trim = Double.valueOf(strings[0].trim());
|
||||
// 纬度
|
||||
Double trim1 = Double.valueOf(strings[1].trim());
|
||||
boolean a = trim <= Double.valueOf(coupletMsgData.getLongitude());
|
||||
boolean b = trim1 <= Double.valueOf(coupletMsgData.getLatitude());
|
||||
if (a && b) {
|
||||
log.info("电子围栏报警啦!!!!您的车驶出范围啦!!!");
|
||||
} else {
|
||||
log.info("电子围栏报警啦!!!!正常啦!!!");
|
||||
}
|
||||
log.info("经度是:" + trim);
|
||||
log.info("纬度是:" + trim1);
|
||||
/**
|
||||
* 先通过;后切割
|
||||
*/
|
||||
String[] split = fenceLongitudeLatitude.split(";");
|
||||
for (String s : split) {
|
||||
String[] strings = s.split(",");
|
||||
if (strings.length == 2) {
|
||||
// 经度
|
||||
Double trim = Double.valueOf(strings[0].trim());
|
||||
// 纬度
|
||||
Double trim1 = Double.valueOf(strings[1].trim());
|
||||
boolean a = trim <= Double.valueOf(coupletMsgData.getLongitude());
|
||||
boolean b = trim1 <= Double.valueOf(coupletMsgData.getLatitude());
|
||||
if (a && b) {
|
||||
log.info("电子围栏报警啦!!!!您的车驶出范围啦!!!");
|
||||
} else {
|
||||
throw new RuntimeException("电子围栏经纬度格式错误" + strings);
|
||||
log.info("电子围栏报警啦!!!!正常啦!!!");
|
||||
}
|
||||
log.info("经度是:" + trim);
|
||||
log.info("纬度是:" + trim1);
|
||||
} else {
|
||||
throw new RuntimeException("电子围栏经纬度格式错误" + strings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.couplet.analyze.msg.domain.CoupletMsgData;
|
|||
import com.couplet.analyze.msg.mapper.IncidentMapper;
|
||||
import com.couplet.analyze.msg.service.IncidentService;
|
||||
import com.couplet.analyze.msg.service.impl.realTimeData.RealTimeJudge;
|
||||
import com.couplet.common.core.utils.StringUtils;
|
||||
import com.couplet.common.domain.request.RealTimeDataRequest;
|
||||
import com.couplet.common.redis.service.RedisService;
|
||||
import com.couplet.remote.RemoteRealTimeService;
|
||||
|
@ -13,8 +12,6 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
|
@ -26,6 +23,12 @@ import java.util.concurrent.TimeUnit;
|
|||
@Log4j2
|
||||
public class RealTimeDataServiceImpl implements IncidentService {
|
||||
|
||||
/**
|
||||
* 查询传入的数据是否存在
|
||||
*/
|
||||
@Autowired
|
||||
private IncidentMapper incidentMapper;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
@ -37,16 +40,28 @@ public class RealTimeDataServiceImpl implements IncidentService {
|
|||
@Override
|
||||
public void incident(CoupletMsgData coupletMsgData) {
|
||||
log.info("实时数据事件开始.....");
|
||||
|
||||
if (redisService.hasKey("实时轨迹vin:"+ coupletMsgData.getVin())){
|
||||
boolean a= ("实时轨迹vin:" + coupletMsgData.getVin()).equals("实时轨迹vin:"+ coupletMsgData.getVin());
|
||||
if (a){
|
||||
log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据一致,开始传输实时数据", coupletMsgData.getVin(), coupletMsgData);
|
||||
redisService.setCacheSet("vin:query:" + coupletMsgData.getVin(), coupletMsgData);
|
||||
redisService.expire("vin:"+coupletMsgData.getVin(),10, TimeUnit.MINUTES);
|
||||
}
|
||||
RealTimeDataRequest cacheObject = redisService.getCacheObject("vin:" + coupletMsgData.getVin());
|
||||
// //判断是否有缓存数据
|
||||
// if (redisService.hasKey("vin:query:" + coupletMsgData.getVin())){
|
||||
// redisService.deleteObject("vin:query:" + coupletMsgData.getVin());
|
||||
// }
|
||||
// if (RealTimeJudge.isJudge(coupletMsgData.getVin())) {
|
||||
if (coupletMsgData.getVin().equals(cacheObject.getVin())){
|
||||
// log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin());
|
||||
//判断数据是否一致,
|
||||
// if (RealTimeJudge.addRealTime(cacheObject)) {
|
||||
log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject);
|
||||
redisService.setCacheSet("vin:query:" + coupletMsgData.getVin(), coupletMsgData);
|
||||
redisService.expire("vin:"+coupletMsgData.getVin(),10, TimeUnit.MINUTES);
|
||||
// } else {
|
||||
// log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据不一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject);
|
||||
// }
|
||||
}
|
||||
|
||||
log.info("[{}]开始传输实时数据", coupletMsgData.getVin());
|
||||
|
||||
log.info("实时数据事件结束.....");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,7 +37,7 @@ public class RealTimeJudge {
|
|||
userIds = new HashSet<>();
|
||||
setMap.put(realTimeDataRequest.getVin(),userIds);
|
||||
}
|
||||
// userIds.add(realTimeDataRequest.getUserId());
|
||||
userIds.add(realTimeDataRequest.getUserId());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,12 +44,12 @@ public class FenceServiceImpl extends ServiceImpl<FenceMapper, Fence> implements
|
|||
*/
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 远程调用队列服务
|
||||
*/
|
||||
// @Autowired
|
||||
// private RemoteFenceService remoteFenceService;
|
||||
|
||||
@Override
|
||||
public List<Fence> pageQuery(FenceConfig fenceConfig) {
|
||||
List<Fence> list = fenceMapper.pageQuery(fenceConfig);
|
||||
|
@ -70,26 +70,36 @@ public class FenceServiceImpl extends ServiceImpl<FenceMapper, Fence> implements
|
|||
// remoteFenceService.fenceQueue(fenceUpdateRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fenceInsert(FenceRequest fenceRequest) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务实现:添加围栏
|
||||
*
|
||||
* @param
|
||||
* @param request
|
||||
* @param fenceRequest
|
||||
*/
|
||||
@Override
|
||||
public void fenceInsert(FenceRequest fenceRequest) {
|
||||
String username = SecurityUtils.getUsername();
|
||||
fenceRequest.setCrateName(username);
|
||||
fenceRequest.setMaintainerName(username);
|
||||
//先添加围栏
|
||||
fenceMapper.insertFence(fenceRequest);
|
||||
|
||||
fenAndLogoService.addBach(fenceRequest.getFenceId(), fenceRequest.getLogoIds());
|
||||
/**
|
||||
* 电子围栏发送改变
|
||||
*/
|
||||
redisTemplate.opsForValue().set("fenceInsert", JSON.toJSONString(fenceRequest), 10, TimeUnit.MINUTES);
|
||||
}
|
||||
// @Override
|
||||
// public void fenceInsert(HttpServletRequest request, FenceRequest fenceRequest) {
|
||||
// String username = SecurityUtils.getUsername();
|
||||
// fenceRequest.setCrateName(username);
|
||||
// //先添加围栏
|
||||
// fenceMapper.insertFence(fenceRequest);
|
||||
// String[] logoIds = fenceRequest.getLogoIds();
|
||||
// String[] parts = new String[0];
|
||||
// for (String logoId : logoIds) {
|
||||
// //把前台传入的字符串分割成数组
|
||||
// parts = logoId.split(",");
|
||||
// //再添加围栏和标识中间表
|
||||
// fenAndLogoService.addBach(fenceRequest.getFenceId(), parts);
|
||||
// }
|
||||
// /**
|
||||
// * 电子围栏发送改变
|
||||
// */
|
||||
// redisTemplate.opsForValue().set("fenceInsert", JSON.toJSONString(fenceRequest), 10, TimeUnit.MINUTES);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void removeByFenceId(Long fenceId) {
|
||||
|
|
|
@ -21,8 +21,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
import springfox.documentation.spring.web.json.Json;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
|
@ -53,26 +53,21 @@ public class VehicleDetectionServiceImpl implements VehicleDetectionService{
|
|||
public List<CoupletMsgData> monitorinDataList(String vin) {
|
||||
String key = "vin:query:" + vin;
|
||||
log.info("key为:"+key);
|
||||
Set<CoupletMsgData> cacheSet = redisService.getCacheSet(key);
|
||||
ArrayList<CoupletMsgData> coupletMsgData = new ArrayList<>(cacheSet);
|
||||
return coupletMsgData;
|
||||
CoupletMsgData coupletMsgData = redisService.getCacheObject(key);
|
||||
ArrayList<CoupletMsgData> coupletMsgDataArrayList = new ArrayList<>();
|
||||
coupletMsgDataArrayList.add(coupletMsgData);
|
||||
return coupletMsgDataArrayList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void monitorinData(String vin) {
|
||||
//创建对象
|
||||
RealTimeDataRequest realTimeDataRequest = new RealTimeDataRequest();
|
||||
//获取用户id
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
//设置车辆vin
|
||||
realTimeDataRequest.setVin(vin);
|
||||
//创建hashSet集合
|
||||
HashSet<Long> objects = new HashSet<>();
|
||||
//添加车辆id
|
||||
objects.add(userId);
|
||||
//把对象放入hashSet集合中
|
||||
//存储的对象是:key:业务+vin value: hashSet集合类型的对象
|
||||
redisService.setCacheSet("实时轨迹vin:"+ vin,objects);
|
||||
realTimeDataRequest.setUserId(userId);
|
||||
// analyzeEventCache.queryEvent("查询实时数据"+vin,realTimeDataRequest);
|
||||
// redisService.expire("查询实时数据"+vin,4,TimeUnit.MINUTES);
|
||||
redisService.setVinAndUserId(realTimeDataRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -57,10 +57,11 @@
|
|||
</sql>
|
||||
<insert id="insertFence" parameterType="com.couplet.common.domain.request.FenceRequest" keyProperty="fenceId"
|
||||
useGeneratedKeys="true">
|
||||
INSERT INTO `couplet-cloud`.`couplet_fence_info`
|
||||
(`fence_name`,`fence_longitude_latitude`, `fence_description`, `is_delete`, `fence_state`, `create_time`,
|
||||
`update_time`, `create_name`, `maintainer_name`, `alarm_status`, `fence_condition`)
|
||||
VALUES (#{fenceName}, NULL, #{fenceDescription} , 0, 0, now(), NULL, #{crateName}, #{maintainerName}, 0, 1)
|
||||
INSERT INTO `couplet-cloud`.`couplet_fence_info`
|
||||
(`fence_name`, `fence_longitude_latitude`, `fence_description`, `is_delete`, `fence_state`, `create_time`,
|
||||
`update_time`, `create_name`, `maintainer_name`, `alarm_status`,`fence_condition`)
|
||||
VALUES
|
||||
(#{fenceName}, null, #{fenceDescription}, 0, 0, now(), null, null, #{maintainerName}, 0 ,0)
|
||||
|
||||
|
||||
</insert>
|
||||
|
|
|
@ -74,7 +74,7 @@ public class MqController {
|
|||
RealTimeDataRequest realTimeDataRequest = new RealTimeDataRequest();
|
||||
realTimeDataRequest.setVin(vin);
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
|
||||
realTimeDataRequest.setUserId(userId);
|
||||
rabbitTemplate.convertAndSend(RabbitMQConfig.VinExchangeName, RabbitMQConfig.VinRoutingKey, realTimeDataRequest,
|
||||
message -> {
|
||||
message.getMessageProperties().setMessageId(IdUtils.randomUUID());
|
||||
|
|
|
@ -76,7 +76,7 @@ public class MqttMonitor {
|
|||
|
||||
|
||||
//Kafka生产者配置
|
||||
private static final String TOPIC_NAME = "topic_lhy";
|
||||
private static final String TOPIC_NAME = "lyh";
|
||||
private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092";
|
||||
|
||||
//线程池,用于异步处理消息到来时的业务逻辑
|
||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: 172469
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: 172469
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
@ -36,7 +38,7 @@ mqtt:
|
|||
# broker: mqtt://115.159.47.13:1883
|
||||
username:
|
||||
password:
|
||||
clientId: aaaaaad
|
||||
clientId: liuyunhu
|
||||
qos: 0
|
||||
topic: xiaoYao
|
||||
topic: liuyunhu
|
||||
|
||||
|
|
Loading…
Reference in New Issue