From 4ad32c37e3317fb6cb7cbfb034b53d3220c27db4 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期五, 30 五月 2025 17:59:16 +0800 Subject: [PATCH] 优化报警 --- ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/server/ExgMsgService.java | 129 ++++++++++++++++++++++++++++++++++--------- 1 files changed, 102 insertions(+), 27 deletions(-) diff --git a/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/server/ExgMsgService.java b/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/server/ExgMsgService.java index a70a715..ea9ab1d 100644 --- a/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/server/ExgMsgService.java +++ b/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/server/ExgMsgService.java @@ -1,23 +1,27 @@ package com.ruoyi.dataInterchange.server; import com.alibaba.fastjson.JSON; +import com.ruoyi.dataInterchange.api.vo.GnssDataVo; import com.ruoyi.dataInterchange.dao.*; import com.ruoyi.dataInterchange.model.*; import com.ruoyi.dataInterchange.model.enu.DataType; import com.ruoyi.dataInterchange.netty.client.ChannelMap; import com.ruoyi.dataInterchange.util.jtt809.common.Jtt809Util; import com.ruoyi.dataInterchange.util.jtt809.packet.common.OuterPacket; -import com.ruoyi.dataInterchange.wapper.UPConnect; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.Iterator; +import java.util.List; /** * @author zhibing.pu @@ -45,10 +49,19 @@ @Resource private UPExgMsgTakeEwayBillAckDao upExgMsgTakeEwayBillAckDao; + @Resource + private RedisTemplate redisTemplate; + public void up_exg_msg(ChannelHandlerContext ctx, OuterPacket out) { + if (!redisTemplate.hasKey("login:" + out.getGnsscenterId())) { + log.error("链路还未登录校验,拒绝连接:{}", out.getGnsscenterId()); + ctx.close(); + return; + } UPExgMsg exgMsg = getExgMsg(out); DataType dataType = DataType.getDataType(exgMsg.getDataType()); + log.info("主链路车辆动态信息交换子业务({}):{}", dataType.getCode(), out); switch (dataType) { case UP_EXG_MSG_REGISTER: log.info("上传车辆注册信息({}):{}", DataType.UP_EXG_MSG_REGISTER.getCode(), out); @@ -129,34 +142,47 @@ public void up_exg_msg_register(ChannelHandlerContext ctx, int inferiorPlatformId, UPExgMsg exgMsg) { UPExgMsgRegister upExgMsgRegister = new UPExgMsgRegister().decode(exgMsg); upExgMsgRegister.setInferiorPlatformId(inferiorPlatformId); - upExgMsgRegister.setCreateTime(LocalDateTime.now()); - upExgMsgRegisterDao.save(upExgMsgRegister); - //上报驾驶员身份识别信息请求 - down_exg_msg_report_driver_info(ctx, inferiorPlatformId, upExgMsgRegister.getVehicleNo(), upExgMsgRegister.getVehicleColor()); + upExgMsgRegister.setCreateTime(LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))); + UPExgMsgRegister register = upExgMsgRegisterDao.findByVehicleNo(upExgMsgRegister.getVehicleNo()); + if (null == register) { + upExgMsgRegisterDao.save(upExgMsgRegister); + } + } + + + /** + * 定时获取司机基础信息 + */ + public void taskReportDriverInfo() { + Iterator<UPExgMsgRegister> iterator = upExgMsgRegisterDao.findAll().iterator(); + while (iterator.hasNext()) { + UPExgMsgRegister register = iterator.next(); + + //上报驾驶员身份识别信息请求 + UPExgMsgReportDriverInfoAck byVehicleNo = upExgMsgReportDriverInfoAckDao.findByVehicleNo(register.getVehicleNo()); + if (null == byVehicleNo) { + down_exg_msg_report_driver_info(register.getInferiorPlatformId(), register.getVehicleNo(), register.getVehicleColor()); + } + } + } /** * 上报驾驶员身份识别信息请求 - * - * @param ctx */ - public void down_exg_msg_report_driver_info(ChannelHandlerContext ctx, int inferiorPlatformId, String vehicleNo, int VehicleColor) { + public void down_exg_msg_report_driver_info(int inferiorPlatformId, String vehicleNo, int VehicleColor) { DOWNExgMsgReportDriverInfo downExgMsgReportDriverInfo = new DOWNExgMsgReportDriverInfo(); downExgMsgReportDriverInfo.setVehicleNo(vehicleNo); downExgMsgReportDriverInfo.setVehicleColor(VehicleColor); downExgMsgReportDriverInfo.setDataType(DataType.DOWN_EXG_MSG_REPORT_DRIVER_INFO.getCode()); downExgMsgReportDriverInfo.setDataLength(0); - log.info("上报驾驶员身份识别信息请求({}):{}", DataType.DOWN_EXG_MSG_REPORT_DRIVER_INFO.getCode(), JSON.toJSONString(downExgMsgReportDriverInfo)); byte[] body = downExgMsgReportDriverInfo.encode(); - OuterPacket out = new OuterPacket(DataType.DOWN_EXG_MSG_REPORT_DRIVER_INFO.getCode(), body); + OuterPacket out = new OuterPacket(DataType.DOWN_EXG_MSG.getCode(), inferiorPlatformId, body); //获取从链路通道 Channel channel = ChannelMap.getClientChannel(inferiorPlatformId); if (null != channel && channel.isActive()) { channel.writeAndFlush(out); - channel.flush(); - } else { - ctx.writeAndFlush(out); - ctx.flush(); + log.info("上报驾驶员身份识别信息请求({}):{}", DataType.DOWN_EXG_MSG_REPORT_DRIVER_INFO.getCode(), JSON.toJSONString(downExgMsgReportDriverInfo)); } } @@ -169,8 +195,17 @@ public void up_exg_msg_real_location(ChannelHandlerContext ctx, int inferiorPlatformId, UPExgMsg exgMsg) { UPExgMsgRealLocation upExgMsgRealLocation = new UPExgMsgRealLocation().decode(exgMsg); upExgMsgRealLocation.setInferiorPlatformId(inferiorPlatformId); - upExgMsgRealLocation.setCreateTime(LocalDateTime.now()); + upExgMsgRealLocation.setCreateTime(LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))); upExgMsgRealLocationDao.save(upExgMsgRealLocation); + //修改车辆实时定位 + GnssDataVo vo = new GnssDataVo(); + BeanUtils.copyProperties(upExgMsgRealLocation.getGnssData(), vo); + redisTemplate.opsForValue().set("location:" + upExgMsgRealLocation.getVehicleNo(), vo); + //查询车辆信息,没有则主动发起请求 + UPExgMsgRegister msgRegister = upExgMsgRegisterDao.findByVehicleNo(upExgMsgRealLocation.getVehicleNo()); + if (null == msgRegister) { + down_base_msg_vehicle_added(inferiorPlatformId, upExgMsgRealLocation.getVehicleNo(), upExgMsgRealLocation.getVehicleColor()); + } } @@ -192,24 +227,23 @@ * @param inferiorPlatformId */ public void down_exg_msg_take_ewaybill_req(int inferiorPlatformId, String vehicleNo, int VehicleColor) { + if (!redisTemplate.hasKey("login:" + inferiorPlatformId)) { + log.error("链路还未登录校验,拒绝连接:{}", inferiorPlatformId); + return; + } DOWNExgMsgTakeEwaybillReq downExgMsgTakeEwaybillReq = new DOWNExgMsgTakeEwaybillReq(); downExgMsgTakeEwaybillReq.setVehicleNo(vehicleNo); downExgMsgTakeEwaybillReq.setVehicleColor(VehicleColor); - downExgMsgTakeEwaybillReq.setDataType(DataType.DOWN_EXG_MSG_REPORT_DRIVER_INFO.getCode()); + downExgMsgTakeEwaybillReq.setDataType(DataType.DOWN_EXG_MSG_TAKE_EWAYBILL_REQ.getCode()); downExgMsgTakeEwaybillReq.setDataLength(0); - log.info("上报车辆电子运单请求({}):{}", DataType.DOWN_EXG_MSG_TAKE_EWAYBILL_REQ.getCode(), JSON.toJSONString(downExgMsgTakeEwaybillReq)); byte[] body = downExgMsgTakeEwaybillReq.encode(); - OuterPacket out = new OuterPacket(DataType.DOWN_EXG_MSG_TAKE_EWAYBILL_REQ.getCode(), body); + OuterPacket out = new OuterPacket(DataType.DOWN_EXG_MSG.getCode(), inferiorPlatformId, body); //获取从链路通道 Channel channel = ChannelMap.getClientChannel(inferiorPlatformId); if (null != channel && channel.isActive()) { channel.writeAndFlush(out); - channel.flush(); - } else { - //重新连接从链路 - UPConnect ipAndPort = ChannelMap.getIpAndPort(inferiorPlatformId); - connectReqService.downConnect(inferiorPlatformId, ipAndPort.getDownLinkIp(), ipAndPort.getDownLinkPort(), ipAndPort.getVerifyCode()); + log.info("上报车辆电子运单请求({}):{}", DataType.DOWN_EXG_MSG_TAKE_EWAYBILL_REQ.getCode(), JSON.toJSONString(downExgMsgTakeEwaybillReq)); } } @@ -224,8 +258,21 @@ public void up_exg_msg_history_location(ChannelHandlerContext ctx, int inferiorPlatformId, UPExgMsg exgMsg) { UPExgMsgHistoryLocation upExgMsgHistoryLocation = new UPExgMsgHistoryLocation().decode(exgMsg); upExgMsgHistoryLocation.setInferiorPlatformId(inferiorPlatformId); - upExgMsgHistoryLocation.setCreateTime(LocalDateTime.now()); + upExgMsgHistoryLocation.setCreateTime(LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))); upExgMsgHistoryLocationDao.save(upExgMsgHistoryLocation); + + //将数据存储实时定位数据表中 + List<GnssData> gnssData = upExgMsgHistoryLocation.getGnssData(); + for (GnssData gnssDatum : gnssData) { + UPExgMsgRealLocation upExgMsgRealLocation = new UPExgMsgRealLocation(); + upExgMsgRealLocation.setVehicleNo(upExgMsgHistoryLocation.getVehicleNo()); + upExgMsgRealLocation.setVehicleColor(upExgMsgHistoryLocation.getVehicleColor()); + upExgMsgRealLocation.setInferiorPlatformId(inferiorPlatformId); + upExgMsgRealLocation.setDataType(DataType.UP_EXG_MSG_REAL_LOCATION.getCode()); + upExgMsgRealLocation.setGnssData(gnssDatum); + upExgMsgRealLocation.setCreateTime(LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))); + upExgMsgRealLocationDao.save(upExgMsgRealLocation); + } } @@ -239,7 +286,7 @@ public void up_exg_msg_report_driver_info_ack(ChannelHandlerContext ctx, int inferiorPlatformId, UPExgMsg exgMsg) { UPExgMsgReportDriverInfoAck upExgMsgReportDriverInfoAck = new UPExgMsgReportDriverInfoAck().decode(exgMsg); upExgMsgReportDriverInfoAck.setInferiorPlatformId(inferiorPlatformId); - upExgMsgReportDriverInfoAck.setCreateTime(LocalDateTime.now()); + upExgMsgReportDriverInfoAck.setCreateTime(LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))); upExgMsgReportDriverInfoAckDao.save(upExgMsgReportDriverInfoAck); } @@ -254,8 +301,36 @@ public void up_exg_msg_take_ewaybill_ack(ChannelHandlerContext ctx, int inferiorPlatformId, UPExgMsg exgMsg) { UPExgMsgTakeEwayBillAck upExgMsgTakeEwayBillAck = new UPExgMsgTakeEwayBillAck().decode(exgMsg); upExgMsgTakeEwayBillAck.setInferiorPlatformId(inferiorPlatformId); - upExgMsgTakeEwayBillAck.setCreateTime(LocalDateTime.now()); - upExgMsgTakeEwayBillAckDao.save(upExgMsgTakeEwayBillAck); + upExgMsgTakeEwayBillAck.setCreateTime(LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))); + UPExgMsgTakeEwayBillAck byVehicleNo = upExgMsgTakeEwayBillAckDao.findByVehicleNo(upExgMsgTakeEwayBillAck.getVehicleNo()); + if (null == byVehicleNo) { + upExgMsgTakeEwayBillAckDao.save(upExgMsgTakeEwayBillAck); + } + } + + + /** + * 补报车辆静态信息 + */ + public void down_base_msg_vehicle_added(int inferiorPlatformId, String vehicleNo, int VehicleColor) { + if (!redisTemplate.hasKey("login:" + inferiorPlatformId)) { + log.error("链路还未登录校验,拒绝连接:{}", inferiorPlatformId); + return; + } + DOWNBaseMsgVehicleAdded downBaseMsgVehicleAdded = new DOWNBaseMsgVehicleAdded(); + downBaseMsgVehicleAdded.setVehicleNo(vehicleNo); + downBaseMsgVehicleAdded.setVehicleColor(VehicleColor); + downBaseMsgVehicleAdded.setDataType(DataType.DOWN_BASE_MSG_VEHICLE_ADDED.getCode()); + downBaseMsgVehicleAdded.setDataLength(0); + + byte[] body = downBaseMsgVehicleAdded.encode(); + OuterPacket out = new OuterPacket(DataType.DOWN_BASE_MSG.getCode(), inferiorPlatformId, body); + //获取从链路通道 + Channel channel = ChannelMap.getClientChannel(inferiorPlatformId); + if (null != channel && channel.isActive()) { + channel.writeAndFlush(out); + log.info("补报车辆静态信息请求({}):{}", DataType.DOWN_BASE_MSG_VEHICLE_ADDED.getCode(), JSON.toJSONString(downBaseMsgVehicleAdded)); + } } } -- Gitblit v1.7.1