From be2e99af0c95d3e5d4f539312d1160b237ec5ec2 Mon Sep 17 00:00:00 2001 From: liuyunhu <3286117488@qq.com> Date: Mon, 8 Apr 2024 14:44:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E7=AE=A1=E7=90=86=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=20=20=E5=8A=A0=E6=B3=A8=E9=87=8A=20=20=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E6=94=B9=EF=BC=8C=E8=A7=A6=E5=8F=91=E5=88=B7=E6=96=B0?= =?UTF-8?q?=E7=BC=93=E5=AD=98=20=E5=A2=9E=E5=8A=A0=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../analyze/msg/model/ModelsKafkaMessage.java | 1 + .../service/impl/VehicleServiceImpl.java | 58 ++++++++++++++----- .../src/main/resources/bootstrap.yml | 18 +++--- 3 files changed, 54 insertions(+), 23 deletions(-) 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 1c2c085..79d7dc1 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 @@ -1,5 +1,6 @@ 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; import com.couplet.common.core.exception.vehicle.VehicleException; diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleServiceImpl.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleServiceImpl.java index 6443e4b..6c22945 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleServiceImpl.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleServiceImpl.java @@ -22,9 +22,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.HashSet; import java.util.List; +import java.util.concurrent.TimeUnit; /** * @ProjectName: five-groups-couplet @@ -140,6 +142,7 @@ public class VehicleServiceImpl extends ServiceImpl impl * @Return: java.lang.String **/ @Override + @Transactional(rollbackFor = Exception.class) public String editById(VehicleEditParams editParams) { String result = ""; @@ -200,6 +203,7 @@ public class VehicleServiceImpl extends ServiceImpl impl * @Return: java.lang.String **/ @Override + @Transactional(rollbackFor = Exception.class) public String insert(VehicleInsertParams insertParams) { String result = ""; @@ -303,7 +307,13 @@ public class VehicleServiceImpl extends ServiceImpl impl } - //通过vin修改车辆上下线的状态 + /* + * @Author: LiuYunHu + * @Date: 2024/4/8 14:11 + * @Description: 通过vin修改车辆上下线的状态 + * @Param: [vin, status] + * @Return: java.lang.Integer + **/ @Override public Integer onOrOutLineByVIN(String vin, int status) { @@ -315,6 +325,13 @@ public class VehicleServiceImpl extends ServiceImpl impl return vehicleMapper.addVehicle(userId, vehicleIds); } + /* + * @Author: LiuYunHu + * @Date: 2024/4/8 14:11 + * @Description: 通过vin查询车辆,因为是plus,所以是List + * @Param: [vin] + * @Return: java.util.List + **/ @Override public List findByVIN(String vin) { @@ -330,19 +347,19 @@ public class VehicleServiceImpl extends ServiceImpl impl } -// @Scheduled(cron = "0/1 * * * * *") -// public void aa() { -// System.out.println("********************************************************"); -// } - - //判断车辆是否下线 + /* + * @Author: LiuYunHu + * @Date: 2024/4/8 14:12 + * @Description: 定时执行,查询缓存中下线的车辆,修改其状态 + * @Param: [] + * @Return: void + **/ @Scheduled(cron = "0/1 * * * * *") public void downLine() { log.info("定时器启动"); //先查询车辆列表 List list = this.list(new VehicleListParams(null, null, null, null)); - list.forEach(vehicle -> { try { //只针对已经上线的车辆 @@ -372,30 +389,43 @@ public class VehicleServiceImpl extends ServiceImpl impl } /* - * 车辆绑定标识的缓存 - * */ + * @Author: LiuYunHu + * @Date: 2024/4/8 14:14 + * @Description: 刷新缓存中 的数据 车辆绑定标识的缓存 + * @Param: [] + * @Return: void + **/ @Scheduled(cron = "0/3 * * * * *") public void reCache() { -//先获取所有车辆的信息 + //刷新缓存执行开始 + + //先获取所有车辆的信息 List list = list(new VehicleListParams()); - //通过车辆的id获取对应的标识 list.forEach(vehicle -> { + //通过车辆的id获取对应的标识集合 List bindLogoById = getBindLogoById(vehicle.getVehicleId()); + //遍历标识集合 bindLogoById.forEach(logoId -> { - //存标识id + + //存标识id 的set HashSet logos = new HashSet<>(); logos.add(logoId); + //存入redis redis.setCacheSet("车辆vin和标识:" + vehicle.getVin(), logos); + redis.expire("车辆vin和标识:" + vehicle.getVin(), 2, TimeUnit.MINUTES); - //存围栏id + //通过标识id获取标识绑定的电子围栏集合 List fences = fenAndLogoService.findFencesByLogoId(logoId); + //遍历电子围栏集合 fences.forEach(fence -> { HashSet fanceSet = new HashSet<>(); fanceSet.add(fence); + //存入redis redis.setCacheSet("车辆vin和电子围栏:" + vehicle.getVin(), fanceSet); + redis.expire("车辆vin和电子围栏:" + vehicle.getVin(), 2, TimeUnit.MINUTES); }); }); }); diff --git a/couplet-modules/couplet-modules-mq/src/main/resources/bootstrap.yml b/couplet-modules/couplet-modules-mq/src/main/resources/bootstrap.yml index 7c61da2..cccb96b 100644 --- a/couplet-modules/couplet-modules-mq/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-modules-mq/src/main/resources/bootstrap.yml @@ -35,15 +35,15 @@ logging: com.couplet.system.mapper: DEBUG # 订阅端配置 -mqtt: - server: - broker: tcp://8.130.181.16:1883 -# broker: tcp://115.159.47.13:1883 - username: - password: - clientid: mqttx - qos: 0 - topic: test +#mqtt: +# server: +# broker: tcp://8.130.181.16:1883 +## broker: tcp://115.159.47.13:1883 +# username: +# password: +# clientid: mqttx +# qos: 0 +# topic: test # RabbitMQ配置 mq: