From bc8558576f187b716b0dd505931a684d5768bf8f Mon Sep 17 00:00:00 2001 From: lijiayao <13831655+xiao-yao-charge-forward@user.noreply.gitee.com> Date: Tue, 9 Apr 2024 17:07:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/request/RealTimeDataRequest.java | 3 +- .../common/redis/service/RedisService.java | 74 ++++++++----------- .../analyze/msg/model/ModelsKafkaMessage.java | 2 +- .../impl/ElectronicFenceServiceImpl.java | 4 + .../service/impl/RealTimeDataServiceImpl.java | 23 ++---- .../impl/realTimeData/RealTimeJudge.java | 2 +- .../impl/VehicleDetectionServiceImpl.java | 19 +++-- .../src/main/resources/bootstrap.yml | 2 - .../couplet/mq/controller/MqController.java | 2 +- .../src/main/resources/bootstrap.yml | 2 - 10 files changed, 54 insertions(+), 79 deletions(-) diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/request/RealTimeDataRequest.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/request/RealTimeDataRequest.java index 1dc7bb4..35926ee 100644 --- a/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/request/RealTimeDataRequest.java +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/common/domain/request/RealTimeDataRequest.java @@ -6,6 +6,7 @@ import lombok.NoArgsConstructor; import lombok.ToString; import java.io.Serializable; +import java.util.List; /** * @author fufanrui @@ -20,7 +21,7 @@ import java.io.Serializable; public class RealTimeDataRequest implements Serializable { - private Long userId; + private List userId; private String vin; diff --git a/couplet-common/couplet-common-redis/src/main/java/com/couplet/common/redis/service/RedisService.java b/couplet-common/couplet-common-redis/src/main/java/com/couplet/common/redis/service/RedisService.java index 39204c6..3b6e681 100644 --- a/couplet-common/couplet-common-redis/src/main/java/com/couplet/common/redis/service/RedisService.java +++ b/couplet-common/couplet-common-redis/src/main/java/com/couplet/common/redis/service/RedisService.java @@ -23,14 +23,13 @@ public class RedisService { public RedisTemplate redisTemplate; - // ... 其他已有方法 ... /** * 向指定集合中添加值,如果值不存在则添加并返回true,否则返回false。 * * @param setKey 集合键名 - * @param value 要添加的值 + * @param value 要添加的值 * @return true表示值已成功添加(之前不存在),false表示值已存在 */ public boolean addToSetIfNotExists(String setKey, String value) { @@ -44,7 +43,7 @@ public class RedisService { * @param key 缓存的键值 * @param value 缓存的值 */ - public void setCacheObject (final String key, final T value) { + public void setCacheObject(final String key, final T value) { redisTemplate.opsForValue().set(key, value); } @@ -56,7 +55,7 @@ public class RedisService { * @param timeout 时间 * @param timeUnit 时间颗粒度 */ - public void setCacheObject (final String key, final T value, final Long timeout, final TimeUnit timeUnit) { + public void setCacheObject(final String key, final T value, final Long timeout, final TimeUnit timeUnit) { redisTemplate.opsForValue().set(key, value, timeout, timeUnit); } @@ -65,10 +64,9 @@ 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); } @@ -78,10 +76,9 @@ 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); } @@ -89,10 +86,9 @@ public class RedisService { * 获取有效时间 * * @param key Redis键 - * * @return 有效时间 */ - public long getExpire (final String key) { + public long getExpire(final String key) { return redisTemplate.getExpire(key); } @@ -100,10 +96,9 @@ public class RedisService { * 判断 key是否存在 * * @param key 键 - * * @return true 存在 false不存在 */ - public Boolean hasKey (String key) { + public Boolean hasKey(String key) { return redisTemplate.hasKey(key); } @@ -111,10 +106,9 @@ public class RedisService { * 获得缓存的基本对象。 * * @param key 缓存键值 - * * @return 缓存键值对应的数据 */ - public T getCacheObject (final String key) { + public T getCacheObject(final String key) { ValueOperations operation = redisTemplate.opsForValue(); return operation.get(key); } @@ -124,7 +118,7 @@ public class RedisService { * * @param key */ - public boolean deleteObject (final String key) { + public boolean deleteObject(final String key) { return redisTemplate.delete(key); } @@ -132,10 +126,9 @@ public class RedisService { * 删除集合对象 * * @param collection 多个对象 - * * @return */ - public boolean deleteObject (final Collection collection) { + public boolean deleteObject(final Collection collection) { return redisTemplate.delete(collection) > 0; } @@ -144,10 +137,9 @@ public class RedisService { * * @param key 缓存的键值 * @param dataList 待缓存的List数据 - * * @return 缓存的对象 */ - public long setCacheList (final String key, final List dataList) { + public long setCacheList(final String key, final List dataList) { Long count = redisTemplate.opsForList().rightPushAll(key, dataList); return count == null ? 0 : count; } @@ -156,10 +148,9 @@ public class RedisService { * 获得缓存的list对象 * * @param key 缓存的键值 - * * @return 缓存键值对应的数据 */ - public List getCacheList (final String key) { + public List getCacheList(final String key) { return redisTemplate.opsForList().range(key, 0, -1); } @@ -168,10 +159,9 @@ public class RedisService { * * @param key 缓存键值 * @param dataSet 缓存的数据 - * * @return 缓存数据的对象 */ - public BoundSetOperations setCacheSet (final String key, final Set dataSet) { + public BoundSetOperations setCacheSet(final String key, final Set dataSet) { BoundSetOperations setOperation = redisTemplate.boundSetOps(key); Iterator it = dataSet.iterator(); while (it.hasNext()) { @@ -179,25 +169,25 @@ public class RedisService { } return setOperation; } + /** * 缓存Set * - * @param key 缓存键值 + * @param key 缓存键值 * @param setValue 缓存的数据 - * * @return 缓存数据的对象 */ - public BoundSetOperations setCacheSet (final String key, final T setValue) { + public BoundSetOperations setCacheSet(final String key, final T setValue) { BoundSetOperations setOperation = redisTemplate.boundSetOps(key); setOperation.add(setValue); return setOperation; } + /** * 缓存Set * - * @param key 缓存键值 + * @param key 缓存键值 * @param setValue 缓存的数据 - * * @return 缓存数据的对象 */ public void deleteSet(String key, String setValue) { @@ -205,26 +195,25 @@ public class RedisService { BoundSetOperations setOperations = redisTemplate.boundSetOps(key); setOperations.remove(setValue); } + /** * 获得缓存的set * * @param key - * * @return */ - public Set getCacheSet (final String key) { + public Set getCacheSet(final String key) { return redisTemplate.opsForSet().members(key); } - /** * 缓存Map * * @param key * @param dataMap */ - public void setCacheMap (final String key, final Map dataMap) { + public void setCacheMap(final String key, final Map dataMap) { if (dataMap != null) { redisTemplate.opsForHash().putAll(key, dataMap); } @@ -234,10 +223,9 @@ public class RedisService { * 获得缓存的Map * * @param key - * * @return */ - public Map getCacheMap (final String key) { + public Map getCacheMap(final String key) { return redisTemplate.opsForHash().entries(key); } @@ -248,7 +236,7 @@ public class RedisService { * @param hKey Hash键 * @param value 值 */ - public void setCacheMapValue (final String key, final String hKey, final T value) { + public void setCacheMapValue(final String key, final String hKey, final T value) { redisTemplate.opsForHash().put(key, hKey, value); } @@ -257,10 +245,9 @@ public class RedisService { * * @param key Redis键 * @param hKey Hash键 - * * @return Hash中的对象 */ - public T getCacheMapValue (final String key, final String hKey) { + public T getCacheMapValue(final String key, final String hKey) { HashOperations opsForHash = redisTemplate.opsForHash(); return opsForHash.get(key, hKey); } @@ -270,10 +257,9 @@ public class RedisService { * * @param key Redis键 * @param hKeys Hash键集合 - * * @return Hash对象集合 */ - public List getMultiCacheMapValue (final String key, final Collection hKeys) { + public List getMultiCacheMapValue(final String key, final Collection hKeys) { return redisTemplate.opsForHash().multiGet(key, hKeys); } @@ -282,10 +268,9 @@ 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; } @@ -293,20 +278,19 @@ public class RedisService { * 获得缓存的基本对象列表 * * @param pattern 字符串前缀 - * * @return 对象列表 */ - public Collection keys (final String pattern) { + public Collection keys(final String pattern) { return redisTemplate.keys(pattern); } public void setVinAndUserId(RealTimeDataRequest realTimeDataRequest) { String key = "vin:" + realTimeDataRequest.getVin(); - redisTemplate.opsForSet().add(key,realTimeDataRequest); + redisTemplate.opsForSet().add(key, realTimeDataRequest); } public void stopViewingData(String vin) { - String key = "vin:"+vin; + String key = "vin:" + vin; redisTemplate.delete(key); } diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/model/ModelsKafkaMessage.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/model/ModelsKafkaMessage.java index 4098a01..b080d28 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/model/ModelsKafkaMessage.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/model/ModelsKafkaMessage.java @@ -38,7 +38,7 @@ import static java.lang.Thread.sleep; @Component @Slf4j public class ModelsKafkaMessage { - private static final String TOPIC_NAME = "xy"; + private static final String TOPIC_NAME = "topic_lyh"; private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092"; diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/ElectronicFenceServiceImpl.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/ElectronicFenceServiceImpl.java index fe7e15b..f06e875 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/ElectronicFenceServiceImpl.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/ElectronicFenceServiceImpl.java @@ -5,6 +5,7 @@ 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; @@ -48,6 +49,9 @@ public class ElectronicFenceServiceImpl implements IncidentService { log.info("电子围栏事件redis存在......."); for (Fence fence : cacheSet) { String fenceLongitudeLatitude = fence.getFenceLongitudeLatitude(); + if (!StringUtils.isEmpty(fenceLongitudeLatitude)){ + log.info("电子围栏没有数据鸭..."); + } /** * 先通过;后切割 */ diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/RealTimeDataServiceImpl.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/RealTimeDataServiceImpl.java index 550917e..c689963 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/RealTimeDataServiceImpl.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/RealTimeDataServiceImpl.java @@ -43,29 +43,16 @@ public class RealTimeDataServiceImpl implements IncidentService { @Override public void incident(CoupletMsgData coupletMsgData) { log.info("实时数据事件开始....."); - Set>> cacheSet = redisService.getCacheSet("vin:" + coupletMsgData.getVin()); -// //判断是否有缓存数据 -// if (redisService.hasKey("vin:query:" + coupletMsgData.getVin())){ -// redisService.deleteObject("vin:query:" + coupletMsgData.getVin()); -// } -// if (RealTimeJudge.isJudge(coupletMsgData.getVin())) { - if (StringUtils.isArray(cacheObject)){ - if (coupletMsgData.getVin().equals(cacheObject.getVin())){ -// log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin()); - //判断数据是否一致, -// if (RealTimeJudge.addRealTime(cacheObject)) { - log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject); + + 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); -// } else { -// log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据不一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject); -// } } - } - log.info("实时数据事件结束....."); - } /** diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/realTimeData/RealTimeJudge.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/realTimeData/RealTimeJudge.java index af9dba3..d7d35e0 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/realTimeData/RealTimeJudge.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/realTimeData/RealTimeJudge.java @@ -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; } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleDetectionServiceImpl.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleDetectionServiceImpl.java index c7ec950..b3686cf 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleDetectionServiceImpl.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleDetectionServiceImpl.java @@ -22,10 +22,7 @@ import org.springframework.stereotype.Service; import springfox.documentation.spring.web.json.Json; import java.lang.reflect.Array; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.concurrent.TimeUnit; /** @@ -63,13 +60,19 @@ public class VehicleDetectionServiceImpl implements VehicleDetectionService{ @Override public void monitorinData(String vin) { + //创建对象 RealTimeDataRequest realTimeDataRequest = new RealTimeDataRequest(); + //获取用户id Long userId = SecurityUtils.getUserId(); + //设置车辆vin realTimeDataRequest.setVin(vin); - realTimeDataRequest.setUserId(userId); -// analyzeEventCache.queryEvent("查询实时数据"+vin,realTimeDataRequest); -// redisService.expire("查询实时数据"+vin,4,TimeUnit.MINUTES); - redisService.setVinAndUserId(realTimeDataRequest); + //创建hashSet集合 + HashSet objects = new HashSet<>(); + //添加车辆id + objects.add(userId); + //把对象放入hashSet集合中 + //存储的对象是:key:业务+vin value: hashSet集合类型的对象 + redisService.setCacheSet("实时轨迹vin:"+ vin,objects); } @Override diff --git a/couplet-modules/couplet-business/src/main/resources/bootstrap.yml b/couplet-modules/couplet-business/src/main/resources/bootstrap.yml index ff5fb2c..d900876 100644 --- a/couplet-modules/couplet-business/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-business/src/main/resources/bootstrap.yml @@ -16,11 +16,9 @@ spring: discovery: # 服务注册地址 server-addr: 121.89.211.230:8848 - namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4 config: # 配置中心地址 server-addr: 121.89.211.230:8848 - namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4 # 配置文件格式 file-extension: yml # 共享配置 diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java index f1921d2..3ffbce2 100644 --- a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java +++ b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/MqController.java @@ -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()); diff --git a/couplet-modules/couplet-system/src/main/resources/bootstrap.yml b/couplet-modules/couplet-system/src/main/resources/bootstrap.yml index 859221a..d9315bd 100644 --- a/couplet-modules/couplet-system/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-system/src/main/resources/bootstrap.yml @@ -15,11 +15,9 @@ spring: discovery: # 服务注册地址 server-addr: 121.89.211.230:8848 - namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4 config: # 配置中心地址 server-addr: 121.89.211.230:8848 - namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4 # 配置文件格式 file-extension: yml # 共享配置