puzhibing
2 小时以前 4ad32c37e3317fb6cb7cbfb034b53d3220c27db4
ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/server/ExgMsgService.java
@@ -1,6 +1,7 @@
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;
@@ -12,6 +13,7 @@
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;
@@ -19,6 +21,7 @@
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Iterator;
import java.util.List;
/**
 * @author zhibing.pu
@@ -52,7 +55,7 @@
   
   public void up_exg_msg(ChannelHandlerContext ctx, OuterPacket out) {
      if (!redisTemplate.hasKey("login:" + out.getGnsscenterId())) {
         log.error("链路还未登录校验,拒绝连接");
         log.error("链路还未登录校验,拒绝连接:{}", out.getGnsscenterId());
         ctx.close();
         return;
      }
@@ -174,7 +177,7 @@
      downExgMsgReportDriverInfo.setDataType(DataType.DOWN_EXG_MSG_REPORT_DRIVER_INFO.getCode());
      downExgMsgReportDriverInfo.setDataLength(0);
      byte[] body = downExgMsgReportDriverInfo.encode();
      OuterPacket out = new OuterPacket(DataType.DOWN_EXG_MSG.getCode(), body);
      OuterPacket out = new OuterPacket(DataType.DOWN_EXG_MSG.getCode(), inferiorPlatformId, body);
      //获取从链路通道
      Channel channel = ChannelMap.getClientChannel(inferiorPlatformId);
      if (null != channel && channel.isActive()) {
@@ -194,6 +197,15 @@
      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());
      }
   }
   
   
@@ -216,7 +228,7 @@
    */
   public void down_exg_msg_take_ewaybill_req(int inferiorPlatformId, String vehicleNo, int VehicleColor) {
      if (!redisTemplate.hasKey("login:" + inferiorPlatformId)) {
         log.error("链路还未登录校验,拒绝连接");
         log.error("链路还未登录校验,拒绝连接:{}", inferiorPlatformId);
         return;
      }
      DOWNExgMsgTakeEwaybillReq downExgMsgTakeEwaybillReq = new DOWNExgMsgTakeEwaybillReq();
@@ -226,7 +238,7 @@
      downExgMsgTakeEwaybillReq.setDataLength(0);
      
      byte[] body = downExgMsgTakeEwaybillReq.encode();
      OuterPacket out = new OuterPacket(DataType.DOWN_EXG_MSG.getCode(), body);
      OuterPacket out = new OuterPacket(DataType.DOWN_EXG_MSG.getCode(), inferiorPlatformId, body);
      //获取从链路通道
      Channel channel = ChannelMap.getClientChannel(inferiorPlatformId);
      if (null != channel && channel.isActive()) {
@@ -248,6 +260,19 @@
      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);
      }
   }
   
   
@@ -283,4 +308,29 @@
      }
   }
   
   /**
    * 补报车辆静态信息
    */
   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));
      }
   }
}