| | |
| | | package com.ruoyi.dataInterchange.server; |
| | | |
| | | import com.ruoyi.common.core.utils.bean.BeanUtils; |
| | | import com.ruoyi.dataInterchange.dao.UPExgMsgRegisterDao; |
| | | import com.ruoyi.dataInterchange.model.BaseMsg; |
| | | import com.ruoyi.dataInterchange.model.UPBaseMsgVehicleAddedAck; |
| | | import com.ruoyi.dataInterchange.model.UPExgMsgRegister; |
| | | import com.ruoyi.dataInterchange.model.enu.DataType; |
| | | import com.ruoyi.dataInterchange.util.jtt809.common.Jtt809Util; |
| | | import com.ruoyi.dataInterchange.util.jtt809.packet.common.OuterPacket; |
| | | import io.netty.buffer.ByteBuf; |
| | | import io.netty.buffer.Unpooled; |
| | | import io.netty.channel.ChannelHandlerContext; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneOffset; |
| | | |
| | | /** |
| | | * @author zhibing.pu |
| | |
| | | @Resource |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | @Resource |
| | | private UPExgMsgRegisterDao upExgMsgRegisterDao; |
| | | |
| | | |
| | | public void up_base_msg(ChannelHandlerContext ctx, OuterPacket out) { |
| | | if (!redisTemplate.hasKey("login:" + out.getGnsscenterId())) { |
| | |
| | | ctx.close(); |
| | | return; |
| | | } |
| | | DataType dataType = DataType.getDataType(out.getId()); |
| | | BaseMsg baseMsg = getBaseMsg(out); |
| | | DataType dataType = DataType.getDataType(baseMsg.getDataType()); |
| | | switch (dataType) { |
| | | case UP_BASE_MSG_VEHICLE_ADDED_ACK: |
| | | log.info("补报车辆静态信息应答消息({}):{}", DataType.UP_BASE_MSG_VEHICLE_ADDED_ACK.getCode(), out); |
| | | up_base_msg_vehicle_added_ack(ctx, out.getGnsscenterId(), baseMsg); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 解析子业务数据 |
| | | * |
| | | * @param out |
| | | * @return |
| | | */ |
| | | public BaseMsg getBaseMsg(OuterPacket out) { |
| | | byte[] body = out.getBody(); |
| | | ByteBuf byteBuf = Unpooled.wrappedBuffer(body); |
| | | //车牌号 |
| | | String vehicleNo = Jtt809Util.readGBKString(byteBuf, 21); |
| | | //车牌颜色 |
| | | byte vehicleColor = byteBuf.readByte(); |
| | | //子业务类型标识 |
| | | int dataType = byteBuf.readUnsignedShort(); |
| | | //后续数据长度 |
| | | int dataLength = byteBuf.readInt(); |
| | | //子业务数据包 |
| | | byte[] data = new byte[byteBuf.readableBytes()]; |
| | | byteBuf.readBytes(data); |
| | | BaseMsg baseMsg = new BaseMsg(); |
| | | baseMsg.setVehicleNo(vehicleNo); |
| | | baseMsg.setVehicleColor(vehicleColor); |
| | | baseMsg.setDataType(dataType); |
| | | baseMsg.setDataLength(dataLength); |
| | | baseMsg.setData(data); |
| | | return baseMsg; |
| | | } |
| | | |
| | | |
| | | public void up_base_msg_vehicle_added_ack(ChannelHandlerContext ctx, int inferiorPlatformId, BaseMsg baseMsg){ |
| | | UPBaseMsgVehicleAddedAck upBaseMsgVehicleAddedAck = new UPBaseMsgVehicleAddedAck().decode(baseMsg); |
| | | UPExgMsgRegister upExgMsgRegister = new UPExgMsgRegister(); |
| | | BeanUtils.copyProperties(upBaseMsgVehicleAddedAck, upExgMsgRegister); |
| | | upExgMsgRegister.setInferiorPlatformId(inferiorPlatformId); |
| | | upExgMsgRegister.setCreateTime(LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))); |
| | | UPExgMsgRegister register = upExgMsgRegisterDao.findByVehicleNo(upExgMsgRegister.getVehicleNo()); |
| | | if (null == register) { |
| | | upExgMsgRegisterDao.save(upExgMsgRegister); |
| | | } |
| | | } |
| | | } |