package com.ruoyi.dataInterchange.model; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; import lombok.Data; import java.io.UnsupportedEncodingException; import java.time.LocalDateTime; import java.time.ZoneOffset; /** * 报警督办请求 * * @author zhibing.pu * @Date 2025/3/3 15:14 */ @Data public class DOWNWarnMsgUrgeTodoReq { /** * 车牌号 */ private String vehicleNo; /** * 车牌颜色 */ private int vehicleColor; /** * 子业务类型标识 */ private int dataType; /** * 后续数据长度 */ private int dataLength; /** * 报警信息来源 * 0x01: 车载终端 * 0x02: 企业监控平台 * 0x03: 政府监管平台 * 0x09: 其他 */ private int warnSrc; /** * 报警类型 */ private int warnType; /** * 报警时间 */ private long warnTime; /** * 报警督办ID */ private int supervisionId; /** * 督办截止时间 */ private long supervisionEndTime; /** * 督办级别 * 0x00: 紧急 * 0x01: 一般 */ private int supervisionLevel; /** * 督办人 */ private String supervisor; /** * 督办联系电话 */ private String supervisorTel; /** * 督办联系电子邮件 */ private String supervisorEmail; public DOWNWarnMsgUrgeTodoReq build(UPWarnMsgAdptInfo upWarnMsgAdptInfo) { this.vehicleNo = upWarnMsgAdptInfo.getVehicleNo(); this.vehicleColor = upWarnMsgAdptInfo.getVehicleColor(); this.warnSrc = upWarnMsgAdptInfo.getWarnSrc(); this.warnType = upWarnMsgAdptInfo.getWarnType(); this.warnTime = upWarnMsgAdptInfo.getWarnTime(); this.supervisionId = Integer.valueOf(upWarnMsgAdptInfo.getInfoId()); this.supervisionEndTime = LocalDateTime.now().plusDays(7).toEpochSecond(ZoneOffset.UTC); this.supervisionLevel = 0x01; this.supervisor = "谢茜"; this.supervisorTel = "18808258011"; this.supervisorEmail = "1360001080@qq.com"; return this; } /** * 编码报文 */ public byte[] encode() { ByteBuf byteBuf = Unpooled.buffer(120); byte[] bytes1 = new byte[0]; try { bytes1 = this.getVehicleNo().getBytes("GBK"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } for (int i = 0; i < 21; i++) { if (i < bytes1.length) { byteBuf.writeByte(bytes1[i]); } else { byteBuf.writeByte(0x00); } } byteBuf.writeByte(this.getVehicleColor()); byteBuf.writeShort(this.getDataType()); byteBuf.writeInt(this.getDataLength()); byteBuf.writeByte(this.getWarnSrc()); byteBuf.writeShort(this.getWarnType()); byteBuf.writeLong(this.getWarnTime()); byteBuf.writeInt(this.getSupervisionId()); byteBuf.writeLong(this.getSupervisionEndTime()); byteBuf.writeByte(this.getSupervisionLevel()); byte[] bytes2 = new byte[0]; try { bytes2 = this.getSupervisor().getBytes("GBK"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } for (int i = 0; i < 16; i++) { if (i < bytes2.length) { byteBuf.writeByte(bytes2[i]); } else { byteBuf.writeByte(0x00); } } byte[] bytes3 = new byte[0]; try { bytes3 = this.getSupervisorTel().getBytes("GBK"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } for (int i = 0; i < 20; i++) { if (i < bytes3.length) { byteBuf.writeByte(bytes3[i]); } else { byteBuf.writeByte(0x00); } } byte[] bytes4 = new byte[0]; try { bytes4 = this.getSupervisorEmail().getBytes("GBK"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } for (int i = 0; i < 32; i++) { if (i < bytes4.length) { byteBuf.writeByte(bytes4[i]); } else { byteBuf.writeByte(0x00); } } byte[] bytes = ByteBufUtil.getBytes(byteBuf); byteBuf.release(); return bytes; } }