Pu Zhibing
2025-07-18 fdfa8b3b237d8bba8964bda67364f54c08d79432
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/server/ExgMsgService.java
@@ -61,41 +61,41 @@
      }
      UPExgMsg exgMsg = getExgMsg(out);
      DataType dataType = DataType.getDataType(exgMsg.getDataType());
      log.info("主链路车辆动态信息交换子业务({}):{}", dataType.getCode(), out);
      log.debug("主链路车辆动态信息交换子业务({}):{}", dataType.getCode(), out);
      switch (dataType) {
         case UP_EXG_MSG_REGISTER:
            log.info("上传车辆注册信息({}):{}", DataType.UP_EXG_MSG_REGISTER.getCode(), out);
            log.debug("上传车辆注册信息({}):{}", DataType.UP_EXG_MSG_REGISTER.getCode(), out);
            up_exg_msg_register(ctx, out.getGnsscenterId(), exgMsg);
            break;
         case UP_EXG_MSG_REAL_LOCATION:
            log.info("上传车辆实时定位信息({}):{}", DataType.UP_EXG_MSG_REAL_LOCATION.getCode(), out);
            log.debug("上传车辆实时定位信息({}):{}", DataType.UP_EXG_MSG_REAL_LOCATION.getCode(), out);
            up_exg_msg_real_location(ctx, out.getGnsscenterId(), exgMsg);
            break;
         case UP_EXG_MSG_HISTORY_LOCATION:
            log.info("车辆定位信息自动补报请求({}):{}", DataType.UP_EXG_MSG_HISTORY_LOCATION.getCode(), out);
            log.debug("车辆定位信息自动补报请求({}):{}", DataType.UP_EXG_MSG_HISTORY_LOCATION.getCode(), out);
            up_exg_msg_history_location(ctx, out.getGnsscenterId(), exgMsg);
            break;
         case UP_EXG_MSG_RETURN_STARTUP_ACK:
            log.info("启动车辆定位信息交换应答({}):{}", DataType.UP_EXG_MSG_RETURN_STARTUP_ACK.getCode(), out);
            log.debug("启动车辆定位信息交换应答({}):{}", DataType.UP_EXG_MSG_RETURN_STARTUP_ACK.getCode(), out);
            break;
         case UP_EXG_MSG_RETURN_END_ACK:
            log.info("结束车辆定位信息交换应答({}):{}", DataType.UP_EXG_MSG_RETURN_END_ACK.getCode(), out);
            log.debug("结束车辆定位信息交换应答({}):{}", DataType.UP_EXG_MSG_RETURN_END_ACK.getCode(), out);
            break;
         case UP_EXG_MSG_APPLY_FOR_MONITOR_STARTUP:
            log.info("申请交换指定车辆定位信息请求({}):{}", DataType.UP_EXG_MSG_APPLY_FOR_MONITOR_STARTUP.getCode(), out);
            log.debug("申请交换指定车辆定位信息请求({}):{}", DataType.UP_EXG_MSG_APPLY_FOR_MONITOR_STARTUP.getCode(), out);
            break;
         case UP_EXG_MSG_APPLY_FOR_MONITOR_END:
            log.info("取消交换指定车辆定位信息请求({}):{}", DataType.UP_EXG_MSG_APPLY_FOR_MONITOR_END.getCode(), out);
            log.debug("取消交换指定车辆定位信息请求({}):{}", DataType.UP_EXG_MSG_APPLY_FOR_MONITOR_END.getCode(), out);
            break;
         case UP_EXG_MSG_APPLY_HISGNSSDATA_REQ:
            log.info("车辆定位信息补发请求({}):{}", DataType.UP_EXG_MSG_APPLY_HISGNSSDATA_REQ.getCode(), out);
            log.debug("车辆定位信息补发请求({}):{}", DataType.UP_EXG_MSG_APPLY_HISGNSSDATA_REQ.getCode(), out);
            break;
         case UP_EXG_MSG_REPORT_DRIVER_INFO_ACK:
            log.info("上报驾驶员身份信息应答({}):{}", DataType.UP_EXG_MSG_REPORT_DRIVER_INFO_ACK.getCode(), out);
            log.debug("上报驾驶员身份信息应答({}):{}", DataType.UP_EXG_MSG_REPORT_DRIVER_INFO_ACK.getCode(), out);
            up_exg_msg_report_driver_info_ack(ctx, out.getGnsscenterId(), exgMsg);
            break;
         case UP_EXG_MSG_TAKE_EWAYBILL_ACK:
            log.info("上报车辆电子运单应答消息({}):{}", DataType.UP_EXG_MSG_TAKE_EWAYBILL_ACK.getCode(), out);
            log.debug("上报车辆电子运单应答消息({}):{}", DataType.UP_EXG_MSG_TAKE_EWAYBILL_ACK.getCode(), out);
            up_exg_msg_take_ewaybill_ack(ctx, out.getGnsscenterId(), exgMsg);
            break;
         default:
@@ -144,11 +144,118 @@
      upExgMsgRegister.setInferiorPlatformId(inferiorPlatformId);
      upExgMsgRegister.setCreateTime(LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8)));
      UPExgMsgRegister register = upExgMsgRegisterDao.findByVehicleNo(upExgMsgRegister.getVehicleNo());
      log.info("上传车辆注册信息({}):{}", DataType.UP_EXG_MSG_REGISTER.getCode(), JSON.toJSON(upExgMsgRegister));
      if (null == register) {
         upExgMsgRegisterDao.save(upExgMsgRegister);
      }
   }
   
   /**
    * 上传车辆实时定位信息
    *
    * @param ctx
    */
   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().toEpochSecond(ZoneOffset.ofHours(8)));
      upExgMsgRealLocationDao.save(upExgMsgRealLocation);
      log.info("上传车辆实时定位信息({}):{}", DataType.UP_EXG_MSG_REAL_LOCATION.getCode(), JSON.toJSON(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());
      }
   }
   /**
    * 车辆定位信息自动补报请求
    *
    * @param ctx
    * @param inferiorPlatformId
    * @param exgMsg
    */
   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().toEpochSecond(ZoneOffset.ofHours(8)));
      upExgMsgHistoryLocationDao.save(upExgMsgHistoryLocation);
      log.info("车辆定位信息自动补报请求({}):{}", DataType.UP_EXG_MSG_HISTORY_LOCATION.getCode(), JSON.toJSONString(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);
      }
   }
   /**
    * 上报驾驶员身份识别信息应答
    *
    * @param ctx
    * @param inferiorPlatformId
    * @param exgMsg
    */
   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().toEpochSecond(ZoneOffset.ofHours(8)));
      upExgMsgReportDriverInfoAckDao.save(upExgMsgReportDriverInfoAck);
      log.info("上报驾驶员身份信息应答({}):{}", DataType.UP_EXG_MSG_REPORT_DRIVER_INFO_ACK.getCode(), JSON.toJSONString(upExgMsgReportDriverInfoAck));
   }
   /**
    * 上报车辆电子运单应答
    *
    * @param ctx
    * @param inferiorPlatformId
    * @param exgMsg
    */
   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().toEpochSecond(ZoneOffset.ofHours(8)));
      UPExgMsgTakeEwayBillAck byVehicleNo = upExgMsgTakeEwayBillAckDao.findByVehicleNo(upExgMsgTakeEwayBillAck.getVehicleNo());
      log.info("上报车辆电子运单应答消息({}):{}", DataType.UP_EXG_MSG_TAKE_EWAYBILL_ACK.getCode(), JSON.toJSONString(upExgMsgTakeEwayBillAck));
      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));
      }
   }
   
   /**
    * 定时获取司机基础信息
@@ -186,29 +293,6 @@
      }
   }
   
   /**
    * 上传车辆实时定位信息
    *
    * @param ctx
    */
   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().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());
      }
   }
   /**
    * 定时任务获取车辆运单信息
    */
@@ -219,7 +303,6 @@
         down_exg_msg_take_ewaybill_req(pojo.getInferiorPlatformId(), pojo.getVehicleNo(), pojo.getVehicleColor());
      }
   }
   
   /**
    * 上报车辆电子运单请求
@@ -244,92 +327,6 @@
      if (null != channel && channel.isActive()) {
         channel.writeAndFlush(out);
         log.info("上报车辆电子运单请求({}):{}", DataType.DOWN_EXG_MSG_TAKE_EWAYBILL_REQ.getCode(), JSON.toJSONString(downExgMsgTakeEwaybillReq));
      }
   }
   /**
    * 车辆定位信息自动补报请求
    *
    * @param ctx
    * @param inferiorPlatformId
    * @param exgMsg
    */
   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().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);
      }
   }
   /**
    * 上报驾驶员身份识别信息应答
    *
    * @param ctx
    * @param inferiorPlatformId
    * @param exgMsg
    */
   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().toEpochSecond(ZoneOffset.ofHours(8)));
      upExgMsgReportDriverInfoAckDao.save(upExgMsgReportDriverInfoAck);
   }
   /**
    * 上报车辆电子运单应答
    *
    * @param ctx
    * @param inferiorPlatformId
    * @param exgMsg
    */
   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().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));
      }
   }