From 01c11cea018f4d73cc9c56882762c169c84395a0 Mon Sep 17 00:00:00 2001 From: liuyunhu <3286117488@qq.com> Date: Mon, 8 Apr 2024 10:02:52 +0800 Subject: [PATCH 1/9] =?UTF-8?q?4.8=E5=A2=9E=E5=8A=A0set=E7=BC=93=E5=AD=98?= =?UTF-8?q?=20=20=E8=BD=A6=E8=BE=86vin=20=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/VehicleServiceImpl.java | 52 +++++++++++-------- 1 file changed, 30 insertions(+), 22 deletions(-) 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 5dd54a5..36295a3 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,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import java.util.HashSet; import java.util.List; /** @@ -119,6 +120,9 @@ public class VehicleServiceImpl extends ServiceImpl impl Result.error(result); } + //刷新set缓存 + reCache(); + result = "删除成功!"; return result; @@ -175,16 +179,8 @@ public class VehicleServiceImpl extends ServiceImpl impl vehicleAndLogoService.vehicleBindLogo(editParams.getVehicleId(), editParams.getLogoIds()); -// //mq -// List logoList = getBindLogoById(editParams.getVehicleId()); -// if (0 != logoList.size()) { -// String ids = ""; -// for (Long l : logoList) { -// ids = "," + l; -// } -// ids = ids.substring(1); -// remoteFenceService.vehicleQueue(editParams.getVehicleId() + "-" + ids); -// } + //刷新set缓存 + reCache(); result = "编辑成功!"; @@ -254,16 +250,9 @@ public class VehicleServiceImpl extends ServiceImpl impl //执行添加电子围栏 int i = vehicleAndLogoService.vehicleBindLogo(vehicle.getVehicleId(), insertParams.getLogoIds()); -// -// List logoList = getBindLogoById(vehicle.getVehicleId()); -// if (0 != logoList.size()) { -// String ids = ""; -// for (Long l : logoList) { -// ids = "," + l; -// } -// ids = ids.substring(1); -// remoteFenceService.vehicleQueue(vehicle.getVehicleId() + "-" + ids); -// } + + //刷新set缓存 + reCache(); result = "新增成功!"; @@ -337,7 +326,6 @@ public class VehicleServiceImpl extends ServiceImpl impl } - @Scheduled(cron = "0/1 * * * * *") public void aa() { System.out.println("********************************************************"); @@ -362,7 +350,7 @@ public class VehicleServiceImpl extends ServiceImpl impl //执行修改下线状态的方法 // Integer i = this.onOrOutLineByVIN(vehicle.getVin() + "," + 0); - Integer i = this.onOrOutLineByVIN(vehicle.getVin() , 0); + Integer i = this.onOrOutLineByVIN(vehicle.getVin(), 0); if (0 == i) { log.error("下线状态修改失败"); @@ -379,4 +367,24 @@ public class VehicleServiceImpl extends ServiceImpl impl } + /* + * 车辆绑定标识的缓存 + * */ +// @Scheduled(cron = "0/1 * * * * *") + public void reCache() { +//先获取所有车辆的信息 + List list = list(new VehicleListParams()); + + //通过车辆的id获取对应的标识 + list.forEach(vehicle -> { + List bindLogoById = getBindLogoById(vehicle.getVehicleId()); + + bindLogoById.forEach(logoId -> { + HashSet longs = new HashSet<>(); + longs.add(logoId); + redis.setCacheSet("车辆vin和标识:" + vehicle.getVin(), longs); + }); + }); + } + } From e91a4cb6d4e7d1367c8f23abe211f002d3fc3380 Mon Sep 17 00:00:00 2001 From: liuyunhu <3286117488@qq.com> Date: Mon, 8 Apr 2024 13:21:23 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=20=20=E5=A2=9E=E5=88=A0=E6=94=B9=EF=BC=8C?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=88=B7=E6=96=B0=E7=BC=93=E5=AD=98=EF=BC=9A?= =?UTF-8?q?set=E5=AD=98=E8=BD=A6=E8=BE=86=E5=92=8C=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E7=94=B5=E5=AD=90=E5=9B=B4=E6=A0=8F=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- couplet-auth/src/main/resources/bootstrap.yml | 2 + .../src/main/resources/bootstrap.yml | 2 + .../src/main/resources/bootstrap.yml | 4 +- .../server/mapper/FenAndLogoMapper.java | 2 + .../server/service/FenAndLogoService.java | 5 +++ .../service/impl/FenAndLogoServiceImpl.java | 10 +++++ .../server/service/impl/FenceServiceImpl.java | 8 ++-- .../service/impl/VehicleServiceImpl.java | 39 ++++++++++++------- .../src/main/resources/bootstrap.yml | 2 + .../mapper/business/FenAndLogoMapper.xml | 28 ++++++++----- .../src/main/resources/bootstrap.yml | 2 + .../src/main/resources/bootstrap.yml | 2 + .../src/main/resources/bootstrap.yml | 2 + .../src/main/resources/bootstrap.yml | 2 + .../couplet-modules-onLine/pom.xml | 16 +++----- .../com/couplet/online/utils/MqttMonitor.java | 9 ++--- .../src/main/resources/bootstrap.yml | 10 ++--- .../src/main/resources/bootstrap.yml | 2 + .../src/main/resources/bootstrap.yml | 2 + 19 files changed, 100 insertions(+), 49 deletions(-) diff --git a/couplet-auth/src/main/resources/bootstrap.yml b/couplet-auth/src/main/resources/bootstrap.yml index 427f682..68c3c25 100644 --- a/couplet-auth/src/main/resources/bootstrap.yml +++ b/couplet-auth/src/main/resources/bootstrap.yml @@ -17,9 +17,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 # 共享配置 diff --git a/couplet-gateway/src/main/resources/bootstrap.yml b/couplet-gateway/src/main/resources/bootstrap.yml index 091e68a..6dc39fe 100644 --- a/couplet-gateway/src/main/resources/bootstrap.yml +++ b/couplet-gateway/src/main/resources/bootstrap.yml @@ -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 # 共享配置 diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/bootstrap.yml b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/bootstrap.yml index 83462d9..183987e 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/bootstrap.yml @@ -15,16 +15,16 @@ spring: discovery: # 服务注册地址 server-addr: 121.89.211.230:8848 - namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 + namespace: 172469 config: # 配置中心地址 server-addr: 121.89.211.230:8848 + namespace: 172469 # 配置文件格式 file-extension: yml # 共享配置 shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} - namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 main: allow-bean-definition-overriding: true rabbitmq: diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/FenAndLogoMapper.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/FenAndLogoMapper.java index 219f2d5..2864f4c 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/FenAndLogoMapper.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/FenAndLogoMapper.java @@ -28,4 +28,6 @@ public interface FenAndLogoMapper extends BaseMapper { * @param aLong */ List queryByFenceAndLogoIds(FenceAndLogeRequest aLong); + + List findFencesByLogoId(@Param("logoId") Long logoId); } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/FenAndLogoService.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/FenAndLogoService.java index 5fa9e42..a144785 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/FenAndLogoService.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/FenAndLogoService.java @@ -28,4 +28,9 @@ public interface FenAndLogoService extends IService { */ List queryByFenceAndLogoIds(FenceAndLogeRequest request); + /* + * 通过标识id查询围栏id + * */ + List findFencesByLogoId(Long logoId); + } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/FenAndLogoServiceImpl.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/FenAndLogoServiceImpl.java index 0fba2fe..364e1f3 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/FenAndLogoServiceImpl.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/FenAndLogoServiceImpl.java @@ -47,4 +47,14 @@ public class FenAndLogoServiceImpl extends ServiceImpl return fenAndLogoMapper.queryByFenceAndLogoIds(request); } + + /* + * 通过标识id查询围栏信息 + * */ + @Override + public List findFencesByLogoId(Long logoId) { + + + return fenAndLogoMapper.findFencesByLogoId(logoId); + } } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/FenceServiceImpl.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/FenceServiceImpl.java index 52bf7a8..d2b8f08 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/FenceServiceImpl.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/FenceServiceImpl.java @@ -11,7 +11,7 @@ import com.couplet.common.domain.request.FenceRequest; import com.couplet.common.domain.request.FenceUpdateRequest; import com.couplet.common.redis.service.RedisService; import com.couplet.common.security.utils.SecurityUtils; -import com.couplet.mq.remote.RemoteFenceService; +//import com.couplet.mq.remote.RemoteFenceService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; @@ -47,8 +47,8 @@ public class FenceServiceImpl extends ServiceImpl implements /** * 远程调用队列服务 */ - @Autowired - private RemoteFenceService remoteFenceService; +// @Autowired +// private RemoteFenceService remoteFenceService; @Override public List pageQuery(FenceConfig fenceConfig) { @@ -67,7 +67,7 @@ public class FenceServiceImpl extends ServiceImpl implements */ redisTemplate.opsForValue().set("changeFenceStatus", JSON.toJSONString(fenceUpdateRequest), 10, TimeUnit.MINUTES); - remoteFenceService.fenceQueue(fenceUpdateRequest); +// remoteFenceService.fenceQueue(fenceUpdateRequest); } @Override 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 ef570f2..6443e4b 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 @@ -4,14 +4,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.couplet.business.server.mapper.VehicleMapper; +import com.couplet.business.server.service.FenAndLogoService; import com.couplet.business.server.service.VehicleAndLogoService; import com.couplet.business.server.service.VehicleService; import com.couplet.business.server.service.VehicleTypeService; import com.couplet.common.core.domain.Result; import com.couplet.common.core.utils.StringUtils; import com.couplet.common.core.utils.uuid.UUID; +import com.couplet.common.domain.Fence; import com.couplet.common.domain.Vehicle; -import com.couplet.common.domain.VehicleMiddle; import com.couplet.common.domain.VehicleType; import com.couplet.common.domain.request.VehicleEditParams; import com.couplet.common.domain.request.VehicleInsertParams; @@ -53,6 +54,9 @@ public class VehicleServiceImpl extends ServiceImpl impl @Autowired private VehicleAndLogoService vehicleAndLogoService; + @Autowired + private FenAndLogoService fenAndLogoService; + /* * @Author: LiuYunHu * @Date: 2024/3/26 22:11 @@ -293,7 +297,6 @@ public class VehicleServiceImpl extends ServiceImpl impl } - @Override public List vehicleAll() { return vehicleMapper.vehicleAll(); @@ -309,7 +312,7 @@ public class VehicleServiceImpl extends ServiceImpl impl @Override public Integer addVehicle(Long userId, List vehicleIds) { - return vehicleMapper.addVehicle(userId,vehicleIds); + return vehicleMapper.addVehicle(userId, vehicleIds); } @Override @@ -327,10 +330,10 @@ public class VehicleServiceImpl extends ServiceImpl impl } - @Scheduled(cron = "0/1 * * * * *") - public void aa() { - System.out.println("********************************************************"); - } +// @Scheduled(cron = "0/1 * * * * *") +// public void aa() { +// System.out.println("********************************************************"); +// } //判断车辆是否下线 @Scheduled(cron = "0/1 * * * * *") @@ -343,10 +346,10 @@ public class VehicleServiceImpl extends ServiceImpl impl list.forEach(vehicle -> { try { //只针对已经上线的车辆 - if (redis.hasKey(vehicle.getVin())) { + if (redis.hasKey("已上线的车辆vin:" + vehicle.getVin())) { //如果vin的缓存 时间还剩一秒,则判断为已经下线 - if (redis.getExpire(vehicle.getVin()) <= 3) { + if (redis.getExpire("已上线的车辆vin:" + vehicle.getVin()) <= 3) { log.info(vehicle.getVin() + "的车辆已经下线"); //执行修改下线状态的方法 @@ -371,7 +374,7 @@ public class VehicleServiceImpl extends ServiceImpl impl /* * 车辆绑定标识的缓存 * */ -// @Scheduled(cron = "0/1 * * * * *") + @Scheduled(cron = "0/3 * * * * *") public void reCache() { //先获取所有车辆的信息 List list = list(new VehicleListParams()); @@ -381,9 +384,19 @@ public class VehicleServiceImpl extends ServiceImpl impl List bindLogoById = getBindLogoById(vehicle.getVehicleId()); bindLogoById.forEach(logoId -> { - HashSet longs = new HashSet<>(); - longs.add(logoId); - redis.setCacheSet("车辆vin和标识:" + vehicle.getVin(), longs); + //存标识id + HashSet logos = new HashSet<>(); + logos.add(logoId); + redis.setCacheSet("车辆vin和标识:" + vehicle.getVin(), logos); + + + //存围栏id + List fences = fenAndLogoService.findFencesByLogoId(logoId); + fences.forEach(fence -> { + HashSet fanceSet = new HashSet<>(); + fanceSet.add(fence); + redis.setCacheSet("车辆vin和电子围栏:" + vehicle.getVin(), fanceSet); + }); }); }); } diff --git a/couplet-modules/couplet-business/src/main/resources/bootstrap.yml b/couplet-modules/couplet-business/src/main/resources/bootstrap.yml index d900876..b88e464 100644 --- a/couplet-modules/couplet-business/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-business/src/main/resources/bootstrap.yml @@ -16,9 +16,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 # 共享配置 diff --git a/couplet-modules/couplet-business/src/main/resources/mapper/business/FenAndLogoMapper.xml b/couplet-modules/couplet-business/src/main/resources/mapper/business/FenAndLogoMapper.xml index 536b2ab..5953d01 100644 --- a/couplet-modules/couplet-business/src/main/resources/mapper/business/FenAndLogoMapper.xml +++ b/couplet-modules/couplet-business/src/main/resources/mapper/business/FenAndLogoMapper.xml @@ -10,15 +10,15 @@ - - - - - + + + + + - + @@ -36,11 +36,19 @@ fence_longitude_latitude, logo_name FROM couplet_fences_and_logo a - INNER JOIN couplet_fence_info f on a.fences_id=f.fence_id - INNER JOIN couplet_logo_info l on l.logo_id=a.logo_id - left JOIN couplet_vehicle_and_logo c on l.logo_id=c.logo_id - WHERE l.logo_id=#{logoIds} and c.vehicle_id=#{id} + INNER JOIN couplet_fence_info f on a.fences_id = f.fence_id + INNER JOIN couplet_logo_info l on l.logo_id = a.logo_id + left JOIN couplet_vehicle_and_logo c on l.logo_id = c.logo_id + WHERE l.logo_id = #{logoIds} + and c.vehicle_id = #{id} + + diff --git a/couplet-modules/couplet-file/src/main/resources/bootstrap.yml b/couplet-modules/couplet-file/src/main/resources/bootstrap.yml index fa968e9..b0d1d24 100644 --- a/couplet-modules/couplet-file/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-file/src/main/resources/bootstrap.yml @@ -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 # 共享配置 diff --git a/couplet-modules/couplet-gen/src/main/resources/bootstrap.yml b/couplet-modules/couplet-gen/src/main/resources/bootstrap.yml index e3d77cd..d2113ff 100644 --- a/couplet-modules/couplet-gen/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-gen/src/main/resources/bootstrap.yml @@ -17,9 +17,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 # 共享配置 diff --git a/couplet-modules/couplet-job/src/main/resources/bootstrap.yml b/couplet-modules/couplet-job/src/main/resources/bootstrap.yml index bb1f871..41d1fef 100644 --- a/couplet-modules/couplet-job/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-job/src/main/resources/bootstrap.yml @@ -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 # 共享配置 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 00ac887..7c61da2 100644 --- a/couplet-modules/couplet-modules-mq/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-modules-mq/src/main/resources/bootstrap.yml @@ -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 # 共享配置 diff --git a/couplet-modules/couplet-modules-onLine/pom.xml b/couplet-modules/couplet-modules-onLine/pom.xml index 44947a4..85f4737 100644 --- a/couplet-modules/couplet-modules-onLine/pom.xml +++ b/couplet-modules/couplet-modules-onLine/pom.xml @@ -11,11 +11,11 @@ couplet-modules-online - - - - - + + + + + couplet-modules-online车辆上线的模块 @@ -91,7 +91,7 @@ 1.2.5 - + com.couplet couplet-common-business @@ -99,10 +99,6 @@ - - - - org.apache.kafka kafka-clients diff --git a/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/utils/MqttMonitor.java b/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/utils/MqttMonitor.java index cd954e7..6f4bfc9 100644 --- a/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/utils/MqttMonitor.java +++ b/couplet-modules/couplet-modules-onLine/src/main/java/com/couplet/online/utils/MqttMonitor.java @@ -11,7 +11,6 @@ import org.eclipse.paho.client.mqttv3.*; import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @@ -184,7 +183,7 @@ public class MqttMonitor { //调取接口,通过vin查询车辆 List vehicles = remoteVehicleService.findByVIN(start17).getData(); - System.out.println("**************" + vehicles); +// System.out.println("**************" + vehicles); //如果不存在这个车 @@ -198,7 +197,7 @@ public class MqttMonitor { log.info("远程调用查询到的车辆数据:" + vehicle); //上线车辆存入redis 6秒 用于判断车辆是否下线,还要写定时器,定时查询 - redis.setCacheObject(start17, start17, 6L, TimeUnit.SECONDS); + redis.setCacheObject("已上线的车辆vin:"+start17, start17, 6L, TimeUnit.SECONDS); log.info("vin码为" + start17 + "的车辆属于本系统,允许上线!"); @@ -207,7 +206,7 @@ public class MqttMonitor { Integer i = remoteVehicleService.onOrOutLineByVIN(start17 + "," + 1); //上线成功 if (0 != i) { - log.info("上线成功!"); +// log.info("上线成功!"); try { produceMessage(message); } catch (Exception e) { @@ -239,7 +238,7 @@ public class MqttMonitor { //发送消息 kafkaProducer.send(new ProducerRecord<>(TOPIC_NAME, message)); - System.out.println("发送消息:" + message); +// System.out.println("发送消息:" + message); } catch (Exception e) { log.error("消息发送失败:" + e.getMessage()); diff --git a/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml b/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml index 16394e6..2d20009 100644 --- a/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml @@ -15,16 +15,16 @@ spring: discovery: # 服务注册地址 server-addr: 121.89.211.230:8848 - namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 + namespace: 172469 config: # 配置中心地址 server-addr: 121.89.211.230:8848 + namespace: 172469 # 配置文件格式 file-extension: yml # 共享配置 shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} - namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 main: allow-bean-definition-overriding: true logging: @@ -35,10 +35,10 @@ logging: mqtt: server: broker: tcp://115.159.47.13:1883 -# broker: mqtt://115.159.47.13:1883 + # broker: mqtt://115.159.47.13:1883 username: password: - clientId: fluxMq + clientId: liuyunhu qos: 0 - topic: test + topic: liuyunhu diff --git a/couplet-modules/couplet-system/src/main/resources/bootstrap.yml b/couplet-modules/couplet-system/src/main/resources/bootstrap.yml index d9315bd..91453d0 100644 --- a/couplet-modules/couplet-system/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-system/src/main/resources/bootstrap.yml @@ -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 # 共享配置 diff --git a/couplet-visual/couplet-monitor/src/main/resources/bootstrap.yml b/couplet-visual/couplet-monitor/src/main/resources/bootstrap.yml index d1064dc..d219500 100644 --- a/couplet-visual/couplet-monitor/src/main/resources/bootstrap.yml +++ b/couplet-visual/couplet-monitor/src/main/resources/bootstrap.yml @@ -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 # 共享配置 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 3/9] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=20=20=E5=8A=A0=E6=B3=A8=E9=87=8A=20=20?= =?UTF-8?q?=E5=A2=9E=E5=88=A0=E6=94=B9=EF=BC=8C=E8=A7=A6=E5=8F=91=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E7=BC=93=E5=AD=98=20=E5=A2=9E=E5=8A=A0=E7=BC=93?= =?UTF-8?q?=E5=AD=98=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: From 05b2baf32e9d2feda0fc8a9e68d991ae443608bb Mon Sep 17 00:00:00 2001 From: lijiayao <13831655+xiao-yao-charge-forward@user.noreply.gitee.com> Date: Mon, 8 Apr 2024 19:50:45 +0800 Subject: [PATCH 4/9] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/contents/AnalyzeEventContents.java | 1 - .../common/event/AnalyzeEventCache.java | 8 + .../analyze/msg/consumer/CodeConsumer.java | 404 +++++++++--------- .../analyze/msg/mapper/IncidentMapper.java | 4 +- .../analyze/msg/model/ModelsKafkaMessage.java | 5 +- .../impl/ElectronicFenceServiceImpl.java | 42 +- .../service/impl/RealTimeDataServiceImpl.java | 29 +- .../service/impl/StoredEventServiceImpl.java | 2 +- .../mapper/incident/SysIncidentMapper.xml | 6 +- couplet-modules/couplet-business/pom.xml | 4 + .../impl/VehicleDetectionServiceImpl.java | 12 +- .../impl/VehicleManageServiceImpl.java | 2 +- .../src/main/resources/bootstrap.yml | 2 - .../src/main/resources/bootstrap.yml | 2 - 14 files changed, 264 insertions(+), 259 deletions(-) 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 b457d29..7e76640 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 @@ -8,7 +8,6 @@ import org.springframework.stereotype.Component; * @Date: 2024/4/7 * @Description: 事件内容 */ - public interface AnalyzeEventContents { /** diff --git a/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/event/AnalyzeEventCache.java b/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/event/AnalyzeEventCache.java index 1602a67..b5dba7e 100644 --- a/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/event/AnalyzeEventCache.java +++ b/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/event/AnalyzeEventCache.java @@ -1,5 +1,6 @@ package com.couplet.analyze.common.event; +import com.couplet.common.domain.request.RealTimeDataRequest; import com.couplet.common.redis.service.RedisService; import org.springframework.beans.factory.annotation.Autowired; @@ -38,6 +39,12 @@ public class AnalyzeEventCache { public void removeEvent(String vin,String eventName){ redisService.deleteSet(encode(vin), eventName); } + /** + * 查询事件 + */ + public void queryEvent(String vin, final RealTimeDataRequest eventName){ + redisService.setCacheObject(encode(vin), eventName); + } /** * 获取事件集合 * @@ -47,4 +54,5 @@ public class AnalyzeEventCache { return redisService.getCacheSet(encode(vin)); } + } diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/CodeConsumer.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/CodeConsumer.java index 9dc7660..139fa31 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/CodeConsumer.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/consumer/CodeConsumer.java @@ -1,203 +1,203 @@ -package com.couplet.analyze.msg.consumer; - -import com.alibaba.fastjson.JSONObject; -import com.couplet.analyze.msg.domain.CoupletMsgData; -import com.couplet.analyze.msg.utils.MsgUtils; -import com.couplet.common.domain.CoupletTroubleCode; -import com.couplet.common.redis.service.RedisService; -import com.couplet.remote.RemoteTroubleService; -import com.rabbitmq.client.Channel; -import lombok.extern.slf4j.Slf4j; -import org.springframework.amqp.rabbit.annotation.Queue; -import org.springframework.amqp.rabbit.annotation.RabbitListener; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.amqp.core.Message; -import org.springframework.stereotype.Component; - -import java.util.Date; -import java.util.concurrent.CompletableFuture; - -/** - * @author DongXiaoDong - * @version 1.0 - * @date 2024/4/6 15:37 - * @description - */ -@Component -@Slf4j -public class CodeConsumer { +//package com.couplet.analyze.msg.consumer; +// +//import com.alibaba.fastjson.JSONObject; +//import com.couplet.analyze.msg.domain.CoupletMsgData; +//import com.couplet.analyze.msg.utils.MsgUtils; +//import com.couplet.common.domain.CoupletTroubleCode; +//import com.couplet.common.redis.service.RedisService; +//import com.couplet.remote.RemoteTroubleService; +//import com.rabbitmq.client.Channel; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.amqp.rabbit.annotation.Queue; +//import org.springframework.amqp.rabbit.annotation.RabbitListener; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.data.redis.core.RedisTemplate; +//import org.springframework.amqp.core.Message; +//import org.springframework.stereotype.Component; +// +//import java.util.Date; +//import java.util.concurrent.CompletableFuture; +// +///** +// * @author DongXiaoDong +// * @version 1.0 +// * @date 2024/4/6 15:37 +// * @description +// */ +//@Component +//@Slf4j +//public class CodeConsumer { +//// @Autowired +//// private RedisTemplate redisTemplate; +// // @Autowired -// private RedisTemplate redisTemplate; - - @Autowired - private RedisService redisService; - @Autowired - private RemoteTroubleService remoteTroubleService; - - @RabbitListener(queuesToDeclare = {@Queue("couplet-code-queue")}) - public void sendLogQueueConsumer(Message message, CoupletMsgData msgData, Channel channel) { - log.info("日志队列:{},接收到的消息:{},开始消费...","couplet-code-queue", JSONObject.toJSONString(msgData)); - long start = System.currentTimeMillis(); - - String messageId = message.getMessageProperties().getMessageId(); - - try { - boolean addToSetIfNotExists = redisService.addToSetIfNotExists("couplet-code-queue", messageId); - if (addToSetIfNotExists) { - //异步保存记录 - CompletableFuture.runAsync(() -> { - CoupletTroubleCode troubleCode = new CoupletTroubleCode(); - troubleCode.setTroubleStartTime(new Date()); - troubleCode.setTroubleVin(msgData.getVin()); - // 随机生成故障码 - String faultCode = MsgUtils.generateGTA(); - troubleCode.setTroubleCode(faultCode); - - switch (msgData.getVehicleStatus()) { - case 0: - troubleCode.setTroublePosition("190"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getChargingStatus()) { - case 0: - troubleCode.setTroublePosition("191"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getOperatingStatus()) { - case 0: - troubleCode.setTroublePosition("192"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getSocStatus()) { - case 0: - troubleCode.setTroublePosition("193"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getChargingEnergyStorageStatus()) { - case 0: - troubleCode.setTroublePosition("194"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getDriveMotorStatus()) { - case 0: - troubleCode.setTroublePosition("195"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getPositionStatus()) { - case 0: - troubleCode.setTroublePosition("196"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getEasStatus()) { - case 0: - troubleCode.setTroublePosition("197"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getPtcStatus()) { - case 0: - troubleCode.setTroublePosition("198"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getEpsStatus()) { - case 0: - troubleCode.setTroublePosition("199"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getAbsStatus()) { - case 0: - troubleCode.setTroublePosition("200"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getMcuStatus()) { - case 0: - troubleCode.setTroublePosition("201"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getHeatingStatus()) { - case 0: - troubleCode.setTroublePosition("202"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getBatteryStatus()) { - case 0: - troubleCode.setTroublePosition("203"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getBatteryInsulationStatus()) { - case 0: - troubleCode.setTroublePosition("204"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getDcdcStatus()) { - case 0: - troubleCode.setTroublePosition("205"); - troubleCode.setProcessingState(0); - break; - default: - switch (msgData.getChgStatus()) { - case 0: - troubleCode.setTroublePosition("206"); - troubleCode.setProcessingState(0); - break; - default: - // do nothing - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - break; - } - remoteTroubleService.newFaultData(troubleCode); - }); - } - long end = System.currentTimeMillis(); - log.info("日志队列:{},接收到的消息:{},消费完成,耗时:{}毫秒","couplet-code-queue", JSONObject.toJSONString(msgData), (end-start)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } -} +// private RedisService redisService; +// @Autowired +// private RemoteTroubleService remoteTroubleService; +// +// @RabbitListener(queuesToDeclare = {@Queue("couplet-code-queue")}) +// public void sendLogQueueConsumer(Message message, CoupletMsgData msgData, Channel channel) { +// log.info("日志队列:{},接收到的消息:{},开始消费...","couplet-code-queue", JSONObject.toJSONString(msgData)); +// long start = System.currentTimeMillis(); +// +// String messageId = message.getMessageProperties().getMessageId(); +// +// try { +// boolean addToSetIfNotExists = redisService.addToSetIfNotExists("couplet-code-queue", messageId); +// if (addToSetIfNotExists) { +// //异步保存记录 +// CompletableFuture.runAsync(() -> { +// CoupletTroubleCode troubleCode = new CoupletTroubleCode(); +// troubleCode.setTroubleStartTime(new Date()); +// troubleCode.setTroubleVin(msgData.getVin()); +// // 随机生成故障码 +// String faultCode = MsgUtils.generateGTA(); +// troubleCode.setTroubleCode(faultCode); +// +// switch (msgData.getVehicleStatus()) { +// case 0: +// troubleCode.setTroublePosition("190"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getChargingStatus()) { +// case 0: +// troubleCode.setTroublePosition("191"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getOperatingStatus()) { +// case 0: +// troubleCode.setTroublePosition("192"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getSocStatus()) { +// case 0: +// troubleCode.setTroublePosition("193"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getChargingEnergyStorageStatus()) { +// case 0: +// troubleCode.setTroublePosition("194"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getDriveMotorStatus()) { +// case 0: +// troubleCode.setTroublePosition("195"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getPositionStatus()) { +// case 0: +// troubleCode.setTroublePosition("196"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getEasStatus()) { +// case 0: +// troubleCode.setTroublePosition("197"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getPtcStatus()) { +// case 0: +// troubleCode.setTroublePosition("198"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getEpsStatus()) { +// case 0: +// troubleCode.setTroublePosition("199"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getAbsStatus()) { +// case 0: +// troubleCode.setTroublePosition("200"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getMcuStatus()) { +// case 0: +// troubleCode.setTroublePosition("201"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getHeatingStatus()) { +// case 0: +// troubleCode.setTroublePosition("202"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getBatteryStatus()) { +// case 0: +// troubleCode.setTroublePosition("203"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getBatteryInsulationStatus()) { +// case 0: +// troubleCode.setTroublePosition("204"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getDcdcStatus()) { +// case 0: +// troubleCode.setTroublePosition("205"); +// troubleCode.setProcessingState(0); +// break; +// default: +// switch (msgData.getChgStatus()) { +// case 0: +// troubleCode.setTroublePosition("206"); +// troubleCode.setProcessingState(0); +// break; +// default: +// // do nothing +// break; +// } +// break; +// } +// break; +// } +// break; +// } +// break; +// } +// break; +// } +// break; +// } +// break; +// } +// break; +// } +// break; +// } +// break; +// } +// break; +// } +// break; +// } +// break; +// } +// break; +// } +// break; +// } +// break; +// } +// remoteTroubleService.newFaultData(troubleCode); +// }); +// } +// long end = System.currentTimeMillis(); +// log.info("日志队列:{},接收到的消息:{},消费完成,耗时:{}毫秒","couplet-code-queue", JSONObject.toJSONString(msgData), (end-start)); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// } +//} 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 aeb2c81..b786542 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 @@ -4,8 +4,6 @@ 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 * @Date: 2024/4/2 @@ -23,6 +21,6 @@ public interface IncidentMapper { * 查询是否存在该vin */ // CoupletMsgData queryByIncident(RealTimeDataRequest realTimeDataRequest); - CoupletMsgData queryByIncident(@Param("vin") String vin, @Param("createTime") Date createTime); + CoupletMsgData queryByIncident(String vin); } 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..d47c633 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,7 @@ package com.couplet.analyze.msg.model; +import com.couplet.analyze.common.contents.AnalyzeEventContents; +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; @@ -36,7 +38,6 @@ public class ModelsKafkaMessage { @Autowired private AnalyzeEventCache analyzeEventCache; - /** * 消费者配置 * @@ -52,9 +53,7 @@ public class ModelsKafkaMessage { //创建消费者 KafkaConsumer consumer = new KafkaConsumer<>(props); - try { - //订阅主题 consumer.subscribe(Collections.singletonList(TOPIC_NAME)); //持续消费消息 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 28036b3..63a232c 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 @@ -13,14 +13,16 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * @Author: LiJiaYao * @Date: 2024/4/2 * @Description: 电子围栏事件服务实现类 */ -@Service("electronic-fence") +@Service("electronic_fence") @Log4j2 public class ElectronicFenceServiceImpl implements IncidentService { @@ -39,56 +41,44 @@ public class ElectronicFenceServiceImpl implements IncidentService { log.info("电子围栏事件开始......."); - String fenceKey="fence"; - -// redisService.getCacheSet() - ArrayList fences = new ArrayList<>(); + String fenceKey = "车辆vin和电子围栏:" + coupletMsgData.getVin(); if (redisService.hasKey(fenceKey)) { + Set cacheSet = redisService.getCacheSet(fenceKey); log.info("电子围栏事件redis存在......."); -// redisService.getCacheObject(); -// for (String s : fence) { -// Fence parseObject = JSON.parseObject(s, Fence.class); -// fences.add(parseObject); -// } // jingdu; // longitude; // weidu; // latitude; - for (Fence data : fences) { - - String fenceLongitudeLatitude = data.getFenceLongitudeLatitude(); + for (Fence fence : cacheSet) { + String fenceLongitudeLatitude = fence.getFenceLongitudeLatitude(); /** - * 先通过;号切割 + * 先通过;后切割 */ String[] split = fenceLongitudeLatitude.split(";"); for (String s : split) { - String[] strings = s.split(","); - if (strings.length == 2){ + 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 a = trim <= Double.valueOf(coupletMsgData.getLongitude()); boolean b = trim1 <= Double.valueOf(coupletMsgData.getLatitude()); - if (a && b){ + if (a && b) { log.info("电子围栏报警啦!!!!您的车驶出范围啦!!!"); - }else { + } else { log.info("电子围栏报警啦!!!!正常啦!!!"); } - log.info("经度是:"+trim); - log.info("纬度是:"+trim1); - }else { - throw new RuntimeException("电子围栏经纬度格式错误"+strings); + log.info("经度是:" + trim); + log.info("纬度是:" + trim1); + } else { + throw new RuntimeException("电子围栏经纬度格式错误" + strings); } } } -// log.info("更改的电子围栏内容是:"+fence); log.info("电子围栏事件结束......."); } - 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 d625f8e..daf4aec 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 @@ -4,23 +4,21 @@ 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; 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; +import java.util.concurrent.TimeUnit; /** * @Author: LiJiaYao * @Date: 2024/4/2 * @Description: 实时数据事件 */ -@Service("real-time-data") +@Service("real_time_data") @Log4j2 public class RealTimeDataServiceImpl implements IncidentService { @@ -32,8 +30,6 @@ public class RealTimeDataServiceImpl implements IncidentService { @Autowired private RedisService redisService; - @Autowired - private RemoteRealTimeService remoteRealTimeService; /** * 实时数据事件 @@ -46,17 +42,20 @@ public class RealTimeDataServiceImpl implements IncidentService { log.info("实时数据事件开始....."); RealTimeDataRequest cacheObject = redisService.getCacheObject("vin:" + coupletMsgData.getVin()); - - 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()); + //判断数据是否一致, + if (RealTimeJudge.addRealTime(cacheObject)) { + log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject); + CoupletMsgData query = incidentMapper.queryByIncident(coupletMsgData.getVin()); + redisService.setCacheObject("vin:query:" + cacheObject.getVin(), query); + redisService.expire("vin:"+cacheObject.getVin(),10, TimeUnit.MINUTES); + } else { + log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据不一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject); + } } + log.info("[{}]开始传输实时数据", coupletMsgData.getVin()); log.info("实时数据事件结束....."); diff --git a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/StoredEventServiceImpl.java b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/StoredEventServiceImpl.java index ef6517f..f7504b8 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/StoredEventServiceImpl.java +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/service/impl/StoredEventServiceImpl.java @@ -12,7 +12,7 @@ import org.springframework.stereotype.Service; * @Date: 2024/4/2 * @Description: 事件存储服务 */ -@Service("stored-event") +@Service("stored_event") @Log4j2 public class StoredEventServiceImpl implements IncidentService { @Autowired 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 29ccb3e..f3f2af9 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,11 @@ diff --git a/couplet-modules/couplet-business/pom.xml b/couplet-modules/couplet-business/pom.xml index a5aea00..25956ae 100644 --- a/couplet-modules/couplet-business/pom.xml +++ b/couplet-modules/couplet-business/pom.xml @@ -101,6 +101,10 @@ com.couplet couplet-modules-mq + + com.couplet + couplet-common-event + 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 08020a3..06f1bb6 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 @@ -1,6 +1,8 @@ package com.couplet.business.server.service.impl; +import afu.org.checkerframework.checker.units.qual.A; import com.alibaba.fastjson.JSON; +import com.couplet.analyze.common.event.AnalyzeEventCache; import com.couplet.business.server.mapper.VehicleDetectionMapper; import com.couplet.business.server.service.VehicleDetectionService; import com.couplet.business.server.service.VehicleManageService; @@ -17,6 +19,7 @@ import org.springframework.stereotype.Service; import springfox.documentation.spring.web.json.Json; import java.util.List; +import java.util.concurrent.TimeUnit; /** * @author fufanrui @@ -31,10 +34,14 @@ public class VehicleDetectionServiceImpl implements VehicleDetectionService{ private VehicleDetectionMapper vehicleDetectionMapper; @Autowired private RedisService redisService; + @Autowired + private AnalyzeEventCache analyzeEventCache; @Override public List detectionList() { - return vehicleDetectionMapper.detectionList(); + List vehicles = vehicleDetectionMapper.detectionList(); + + return vehicles; } @Override @@ -43,8 +50,9 @@ public class VehicleDetectionServiceImpl implements VehicleDetectionService{ Long userId = SecurityUtils.getUserId(); realTimeDataRequest.setVin(vin); realTimeDataRequest.setUserId(userId); +// analyzeEventCache.queryEvent("查询实时数据"+vin,realTimeDataRequest); +// redisService.expire("查询实时数据"+vin,4,TimeUnit.MINUTES); redisService.setVinAndUserId(realTimeDataRequest); - } @Override diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleManageServiceImpl.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleManageServiceImpl.java index fa3c412..dc12028 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleManageServiceImpl.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/VehicleManageServiceImpl.java @@ -54,7 +54,7 @@ public class VehicleManageServiceImpl implements VehicleManageService { /* * @param middle: - * @return Result + * @return Result * @author 付凡芮 * @description 添加车辆 * @date diff --git a/couplet-modules/couplet-business/src/main/resources/bootstrap.yml b/couplet-modules/couplet-business/src/main/resources/bootstrap.yml index 6c75304..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: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 config: # 配置中心地址 server-addr: 121.89.211.230:8848 - namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 # 配置文件格式 file-extension: yml # 共享配置 diff --git a/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml b/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml index 16394e6..d5c530c 100644 --- a/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-modules-onLine/src/main/resources/bootstrap.yml @@ -15,7 +15,6 @@ spring: discovery: # 服务注册地址 server-addr: 121.89.211.230:8848 - namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 config: # 配置中心地址 server-addr: 121.89.211.230:8848 @@ -24,7 +23,6 @@ spring: # 共享配置 shared-configs: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} - namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 main: allow-bean-definition-overriding: true logging: From 9327ecae1f354fe685cdf7676702c593243f365d Mon Sep 17 00:00:00 2001 From: liuyunhu <3286117488@qq.com> Date: Mon, 8 Apr 2024 19:51:32 +0800 Subject: [PATCH 5/9] huhuhu --- .../common/event/AnalyzeEventCache.java | 2 + couplet-modules/couplet-business/pom.xml | 5 ++ .../service/impl/VehicleServiceImpl.java | 34 ++++++++++- .../com/couplet/mq/controller/KafkaTest.java | 60 +++++++++---------- 4 files changed, 70 insertions(+), 31 deletions(-) diff --git a/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/event/AnalyzeEventCache.java b/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/event/AnalyzeEventCache.java index 1602a67..6fd55bf 100644 --- a/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/event/AnalyzeEventCache.java +++ b/couplet-common/couplet-common-event/src/main/java/com/couplet/analyze/common/event/AnalyzeEventCache.java @@ -2,6 +2,7 @@ package com.couplet.analyze.common.event; import com.couplet.common.redis.service.RedisService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import java.util.Set; @@ -11,6 +12,7 @@ import java.util.Set; * @Description: */ +@Component public class AnalyzeEventCache { @Autowired diff --git a/couplet-modules/couplet-business/pom.xml b/couplet-modules/couplet-business/pom.xml index a5aea00..09492af 100644 --- a/couplet-modules/couplet-business/pom.xml +++ b/couplet-modules/couplet-business/pom.xml @@ -87,6 +87,11 @@ spring-boot-starter-amqp + + com.couplet + couplet-common-event + + org.springframework.boot 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 6c22945..e0bfe47 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 @@ -3,6 +3,8 @@ package com.couplet.business.server.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.couplet.analyze.common.contents.AnalyzeEventContents; +import com.couplet.analyze.common.event.AnalyzeEventCache; import com.couplet.business.server.mapper.VehicleMapper; import com.couplet.business.server.service.FenAndLogoService; import com.couplet.business.server.service.VehicleAndLogoService; @@ -24,6 +26,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.annotation.PostConstruct; import java.util.HashSet; import java.util.List; import java.util.concurrent.TimeUnit; @@ -59,6 +62,9 @@ public class VehicleServiceImpl extends ServiceImpl impl @Autowired private FenAndLogoService fenAndLogoService; + @Autowired + private AnalyzeEventCache eventCache; + /* * @Author: LiuYunHu * @Date: 2024/3/26 22:11 @@ -254,6 +260,7 @@ public class VehicleServiceImpl extends ServiceImpl impl Result.error(result); } + //获取新增的车辆id值 //执行添加电子围栏 int i = vehicleAndLogoService.vehicleBindLogo(vehicle.getVehicleId(), insertParams.getLogoIds()); @@ -262,6 +269,9 @@ public class VehicleServiceImpl extends ServiceImpl impl //刷新set缓存 reCache(); + //加入事件缓存 + reEvent(); + result = "新增成功!"; @@ -395,7 +405,10 @@ public class VehicleServiceImpl extends ServiceImpl impl * @Param: [] * @Return: void **/ - @Scheduled(cron = "0/3 * * * * *") +// @Scheduled(cron = "0/3 * * * * *") + + //初始化 + @PostConstruct public void reCache() { //刷新缓存执行开始 @@ -431,4 +444,23 @@ public class VehicleServiceImpl extends ServiceImpl impl }); } + + /* + * @Author: LiuYunHu + * @Date: 2024/4/8 19:39 + * @Description: 初始化 车辆事件 默认车辆有所有事件 + * @Param: [] + * @Return: void + **/ + @PostConstruct + public void reEvent() { + List list = list(new VehicleListParams()); + + list.forEach(vehicle -> { + eventCache.addEvent(vehicle.getVin(), AnalyzeEventContents.STORED_EVENT); + eventCache.addEvent(vehicle.getVin(), AnalyzeEventContents.BREAKDOWN); + eventCache.addEvent(vehicle.getVin(), AnalyzeEventContents.ELECTRONIC_FENCE); + eventCache.addEvent(vehicle.getVin(), AnalyzeEventContents.REAL_TIME_DATA); + }); + } } diff --git a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/KafkaTest.java b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/KafkaTest.java index d078386..a0f255a 100644 --- a/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/KafkaTest.java +++ b/couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/KafkaTest.java @@ -27,10 +27,10 @@ public class KafkaTest { public static void main(String[] args) { //生产者示例 -// produceMessage(); + produceMessage(); //消费者示例 -// consumerMessages(); + consumerMessages(); } @@ -61,33 +61,33 @@ public class KafkaTest { } //消费者 -// private static void consumerMessages() { -// Properties props = new Properties(); -// props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS); -// props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-consumer-group"); -// 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"); -// -// //创建消费者 -// KafkaConsumer consumer = new KafkaConsumer<>(props); -// -// try { -// -// //订阅主题 -// consumer.subscribe(Collections.singletonList(TOPIC_NAME)); -// -// //持续消费消息 -// while (true) { -// ConsumerRecords records = consumer.poll(Duration.ofMillis(100)); -// records.forEach(record -> { -// System.out.println("消费者接受到的消息值:" + record.value()); -// }); -// } -// } catch (Exception e) { -// e.printStackTrace(); -// } finally { -// consumer.close(); -// } -// } + private static void consumerMessages() { + Properties props = new Properties(); + props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS); + props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-consumer-group"); + 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"); + + //创建消费者 + KafkaConsumer consumer = new KafkaConsumer<>(props); + + try { + + //订阅主题 + consumer.subscribe(Collections.singletonList(TOPIC_NAME)); + + //持续消费消息 + while (true) { + ConsumerRecords records = consumer.poll(Duration.ofMillis(100)); + records.forEach(record -> { + System.out.println("消费者接受到的消息值:" + record.value()); + }); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + consumer.close(); + } + } } From c4f1beed8bf8e6bef820a8bbc5993f69095895cd Mon Sep 17 00:00:00 2001 From: dongxiaodong <13970843+dxdwork@user.noreply.gitee.com> Date: Mon, 8 Apr 2024 20:07:06 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../couplet/analyze/msg/model/ModelsKafkaMessage.java | 1 + .../src/main/resources/bootstrap.yml | 2 ++ .../server/controller/SysTroubleController.java | 9 +++++++++ .../business/server/mapper/SysTroubleMapper.java | 2 ++ .../business/server/service/SysTroubleService.java | 2 ++ .../server/service/impl/SysTroubleServiceImpl.java | 10 ++++++++++ .../resources/mapper/business/SysTroubleMapper.xml | 3 +++ .../couplet-file/src/main/resources/bootstrap.yml | 2 ++ .../couplet-gen/src/main/resources/bootstrap.yml | 2 ++ .../couplet-job/src/main/resources/bootstrap.yml | 2 ++ .../src/main/resources/bootstrap.yml | 2 ++ .../src/main/resources/bootstrap.yml | 4 ++-- .../couplet-system/src/main/resources/bootstrap.yml | 2 ++ .../couplet-monitor/src/main/resources/bootstrap.yml | 2 ++ 14 files changed, 43 insertions(+), 2 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-analyze/couplet-analyze-msg/src/main/resources/bootstrap.yml b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/bootstrap.yml index bed4d26..1c4ab93 100644 --- a/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/bootstrap.yml +++ b/couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/bootstrap.yml @@ -15,9 +15,11 @@ spring: discovery: # 服务注册地址 server-addr: 121.89.211.230:8848 + namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 config: # 配置中心地址 server-addr: 121.89.211.230:8848 + namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15 # 配置文件格式 file-extension: yml # 共享配置 diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/SysTroubleController.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/SysTroubleController.java index b9f733b..8f79174 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/SysTroubleController.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/controller/SysTroubleController.java @@ -93,4 +93,13 @@ public class SysTroubleController extends BaseController { troubleService.newFaultData(code); return success(); } + + /** + * 查询故障的状态并处理 + */ + @PostMapping("/getUpdState") + public Result getUpdState(@RequestBody CoupletTroubleCode code) { + int updateState = troubleService.updateState(code); + return Result.success(updateState); + } } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/SysTroubleMapper.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/SysTroubleMapper.java index bf95533..760a95a 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/SysTroubleMapper.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/mapper/SysTroubleMapper.java @@ -29,4 +29,6 @@ public interface SysTroubleMapper extends BaseMapper { void newFaultData(CoupletTroubleCode code); void cleanTroubleCode(); + + int updateState(CoupletTroubleCode code); } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/SysTroubleService.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/SysTroubleService.java index cb9b551..ca8ba18 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/SysTroubleService.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/SysTroubleService.java @@ -26,4 +26,6 @@ public interface SysTroubleService extends IService { void newFaultData(CoupletTroubleCode code); void cleanTroubleCode(); + + int updateState(CoupletTroubleCode code); } diff --git a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/SysTroubleServiceImpl.java b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/SysTroubleServiceImpl.java index 56797cc..511ff60 100644 --- a/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/SysTroubleServiceImpl.java +++ b/couplet-modules/couplet-business/src/main/java/com/couplet/business/server/service/impl/SysTroubleServiceImpl.java @@ -58,4 +58,14 @@ public class SysTroubleServiceImpl extends ServiceImpl truncate table couplet_trouble_code + + update couplet_trouble_code set processing_state = 1 where thourble_id = #{troubleId} +