diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteRealTimeService.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteRealTimeService.java new file mode 100644 index 0000000..13cf4b6 --- /dev/null +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteRealTimeService.java @@ -0,0 +1,19 @@ +package com.couplet.remote; + +import com.couplet.common.core.constant.ServiceNameConstants; +import com.couplet.common.core.domain.Result; +import com.couplet.common.domain.CoupletTroubleCode; +import com.couplet.remote.factory.RemoteRealTimeFallbackFactory; +import com.couplet.remote.factory.RemoteTroubleFallbackFactory; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +@FeignClient(contextId = "remoteRealTimeService" , + value = ServiceNameConstants.BUSINESS_SERVICE, + fallbackFactory = RemoteRealTimeFallbackFactory.class +) +public interface RemoteRealTimeService { + + +} diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java index 1b03483..ec9a53a 100644 --- a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/RemoteVehicleService.java @@ -63,13 +63,6 @@ public interface RemoteVehicleService { */ @PostMapping("/vehicleAndLogo/queryByLogoIds/{vehicleId}") public Result> queryByLogoIds(@PathVariable("vehicleId") Long vehicleId); - /** - * 根据车辆id查询绑定的标识 - * @param - * @return - */ -// @PostMapping("/vehicleAndLogo/queryByLogoIds/{vehicleId}") -// public Result> queryByLogoIds(@PathVariable("vehicleId") Long vehicleId); @PostMapping("/list") public Result list(@RequestBody VehicleListParams listParams); diff --git a/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteRealTimeFallbackFactory.java b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteRealTimeFallbackFactory.java new file mode 100644 index 0000000..16075fa --- /dev/null +++ b/couplet-common/couplet-common-business/src/main/java/com/couplet/remote/factory/RemoteRealTimeFallbackFactory.java @@ -0,0 +1,21 @@ +package com.couplet.remote.factory; + +import com.couplet.common.core.domain.Result; +import com.couplet.common.domain.CoupletTroubleCode; +import com.couplet.remote.RemoteRealTimeService; +import org.springframework.cloud.openfeign.FallbackFactory; +import org.springframework.stereotype.Component; + +/** + * @Author: LiJiaYao + * @Date: 2024/4/8 + * @Description: + */ +@Component +public class RemoteRealTimeFallbackFactory implements FallbackFactory { + + @Override + public RemoteRealTimeService create(Throwable cause) { + return null; + } +} diff --git a/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/contents/AnalyzeEventContents.java b/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/contents/AnalyzeEventContents.java index cd18fcf..b457d29 100644 --- a/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/contents/AnalyzeEventContents.java +++ b/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/contents/AnalyzeEventContents.java @@ -1,5 +1,6 @@ package com.couplet.analyze.common.contents; +import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; /** @@ -8,8 +9,7 @@ import org.springframework.stereotype.Component; * @Description: 事件内容 */ -@Component -public class AnalyzeEventContents { +public interface AnalyzeEventContents { /** * 故障 diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/mapper/IncidentMapper.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/mapper/IncidentMapper.java index 3f44416..aeb2c81 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/mapper/IncidentMapper.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/mapper/IncidentMapper.java @@ -2,6 +2,9 @@ package com.couplet.analyze.msg.mapper; import com.couplet.analyze.msg.domain.CoupletMsgData; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; /** * @Author: LiJiaYao @@ -20,6 +23,6 @@ public interface IncidentMapper { * 查询是否存在该vin */ // CoupletMsgData queryByIncident(RealTimeDataRequest realTimeDataRequest); - CoupletMsgData queryByIncident(String vin); + CoupletMsgData queryByIncident(@Param("vin") String vin, @Param("createTime") Date createTime); } 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 da4c02d..2559a2c 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 @@ -35,12 +35,8 @@ public class ModelsKafkaMessage { private static final String TOPIC_NAME = "online"; private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092"; - @Autowired - private AnalyzeEventContents analyzeEventContents; @Autowired private AnalyzeEventCache analyzeEventCache; -// @Autowired -// private RabbitTemplate rabbitTemplate; /** * 消费者配置 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 7ff9a1b..d625f8e 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 @@ -7,11 +7,14 @@ 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; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; +import java.util.Date; + /** * @Author: LiJiaYao * @Date: 2024/4/2 @@ -29,6 +32,8 @@ public class RealTimeDataServiceImpl implements IncidentService { @Autowired private RedisService redisService; + @Autowired + private RemoteRealTimeService remoteRealTimeService; /** * 实时数据事件 @@ -41,11 +46,15 @@ public class RealTimeDataServiceImpl implements IncidentService { log.info("实时数据事件开始....."); RealTimeDataRequest cacheObject = redisService.getCacheObject("vin:" + coupletMsgData.getVin()); - if (StringUtils.isArray(cacheObject)){ - log.info("[{}]有缓存数据,值为:[{}]", coupletMsgData.getVin(), cacheObject); - + + if (RealTimeJudge.addRealTime(cacheObject)) { + log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject); + CoupletMsgData query = incidentMapper.queryByIncident(coupletMsgData.getVin(), new Date()); + redisService.setCacheObject("vin:" + cacheObject.getVin(), query); + } else { + log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据不一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject); } - if (RealTimeJudge.isJudge(coupletMsgData.getVin())){ + if (RealTimeJudge.isJudge(coupletMsgData.getVin())) { log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin()); } log.info("[{}]开始传输实时数据", coupletMsgData.getVin()); @@ -56,6 +65,7 @@ public class RealTimeDataServiceImpl implements IncidentService { /** * 实时数据事件 + * * @return */ @Override diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/mapper/incident/SysIncidentMapper.xml b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/mapper/incident/SysIncidentMapper.xml index e53a115..29ccb3e 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/mapper/incident/SysIncidentMapper.xml +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/mapper/incident/SysIncidentMapper.xml @@ -72,7 +72,7 @@