From d41f7088e7854d061e037ae35dc94a1d6345d2ab Mon Sep 17 00:00:00 2001 From: zhangshengli <18103773227@163.com> Date: Tue, 29 Oct 2024 18:02:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/hive/bee/entity/BeeHive.java | 1 + src/main/java/com/hive/bee/entity/BeeHiveLog.java | 2 ++ src/main/java/com/hive/bee/vo/BeeHiveVo.java | 3 +++ .../hive/communication/netty/server/EchoServer.java | 4 ++-- .../server/dataprocessing/HandlerDateProcessing.java | 8 +++++++- .../netty/server/handler/EchoServerHandler.java | 11 +++++++---- src/main/java/com/hive/util/DateConvetUtil.java | 1 + 7 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/hive/bee/entity/BeeHive.java b/src/main/java/com/hive/bee/entity/BeeHive.java index 3824f8e..501044f 100644 --- a/src/main/java/com/hive/bee/entity/BeeHive.java +++ b/src/main/java/com/hive/bee/entity/BeeHive.java @@ -97,5 +97,6 @@ public class BeeHive implements Serializable { /** * 数据上传时间原始数据 */ + @TableField(exist = false) private String dateUploadTimeHex; } \ No newline at end of file diff --git a/src/main/java/com/hive/bee/entity/BeeHiveLog.java b/src/main/java/com/hive/bee/entity/BeeHiveLog.java index 7fd6b02..57364ea 100644 --- a/src/main/java/com/hive/bee/entity/BeeHiveLog.java +++ b/src/main/java/com/hive/bee/entity/BeeHiveLog.java @@ -67,4 +67,6 @@ public class BeeHiveLog implements Serializable { * 数据上传时间 */ private LocalDateTime dateUploadTime; + @TableField(exist = false) + private String dateUploadTimeHex; } \ No newline at end of file diff --git a/src/main/java/com/hive/bee/vo/BeeHiveVo.java b/src/main/java/com/hive/bee/vo/BeeHiveVo.java index 067dc14..9fcba2f 100644 --- a/src/main/java/com/hive/bee/vo/BeeHiveVo.java +++ b/src/main/java/com/hive/bee/vo/BeeHiveVo.java @@ -1,6 +1,7 @@ package com.hive.bee.vo; import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; @@ -85,5 +86,7 @@ public class BeeHiveVo implements Serializable { * 数据上传时间 */ private LocalDateTime dateUploadTime; + @TableField(exist = false) + private String dateUploadTimeHex; } \ No newline at end of file diff --git a/src/main/java/com/hive/communication/netty/server/EchoServer.java b/src/main/java/com/hive/communication/netty/server/EchoServer.java index 0ab712a..a7e69ff 100644 --- a/src/main/java/com/hive/communication/netty/server/EchoServer.java +++ b/src/main/java/com/hive/communication/netty/server/EchoServer.java @@ -55,8 +55,8 @@ public class EchoServer { System.out.println("报告完毕"); ch.pipeline().addLast(new StringEncoder(Charset.forName("UTF-8"))); - String startDelimiterStr = "99"; - String endDelimiterStr = "0A"; + String startDelimiterStr = "55"; + String endDelimiterStr = "aa"; ByteBuf startDelimiter = Unpooled.copiedBuffer(startDelimiterStr, Charset.forName("UTF-8")); ByteBuf endDelimiter = Unpooled.copiedBuffer(endDelimiterStr, Charset.forName("UTF-8")); // ch.pipeline().addLast(new DelimiterBasedFrameDecoder(startDelimiter, endDelimiter)); diff --git a/src/main/java/com/hive/communication/netty/server/dataprocessing/HandlerDateProcessing.java b/src/main/java/com/hive/communication/netty/server/dataprocessing/HandlerDateProcessing.java index deb7615..5dfc254 100644 --- a/src/main/java/com/hive/communication/netty/server/dataprocessing/HandlerDateProcessing.java +++ b/src/main/java/com/hive/communication/netty/server/dataprocessing/HandlerDateProcessing.java @@ -1,6 +1,8 @@ package com.hive.communication.netty.server.dataprocessing; import cn.hutool.core.util.HexUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.hive.bee.entity.BeeHive; @@ -88,10 +90,14 @@ public class HandlerDateProcessing { public BeeHive dataAnalysis(String data) { BeeHiveAdd beeHiveAdd = SpringUtil.getBean(BeeHiveAdd.class); BeeHive beeHive = new BeeHive(); - if (data.length() != 61) { + System.out.println(data.length()); + String substring = data.substring(0, 6); + String sub = StrUtil.sub(data, -6,data.length()); + if (ObjectUtil.notEqual(substring,"558511")||ObjectUtil.notEqual(sub,"aa")) { return beeHive; } for (int i = 0; i < 7; i++) { + Integer startIndex = 0; Integer endIndex = 0; switch (i) { diff --git a/src/main/java/com/hive/communication/netty/server/handler/EchoServerHandler.java b/src/main/java/com/hive/communication/netty/server/handler/EchoServerHandler.java index 5ec3f2d..af6d896 100644 --- a/src/main/java/com/hive/communication/netty/server/handler/EchoServerHandler.java +++ b/src/main/java/com/hive/communication/netty/server/handler/EchoServerHandler.java @@ -1,6 +1,7 @@ package com.hive.communication.netty.server.handler; +import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.hive.bee.entity.BeeHive; import com.hive.communication.netty.server.dataprocessing.HandlerDateProcessing; @@ -17,6 +18,7 @@ import java.io.UnsupportedEncodingException; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.time.LocalDateTime; +import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.concurrent.*; @@ -54,13 +56,14 @@ public class EchoServerHandler extends ChannelInboundHandlerAdapter { stringBuilder.append(start); stringBuilder.append("8561"); stringBuilder.append(beeHive.getDateUploadTimeHex()); - stringBuilder.append("0b01"); + stringBuilder.append("0801"); // String paddedString = String.format("%4s", code).replace(' ', '0'); //获取十分钟后的时间秒数, // 转换为16进制 - String hexSeconds = Long.toHexString(getCurrentSeconds()).toUpperCase(); - stringBuilder.append(hexSeconds); - stringBuilder.append("0000ff000000"); +// String hexSeconds = Long.toHexString(getCurrentSeconds()).toUpperCase(); + String upperCase = Long.toHexString(DateUtil.offsetHour(new Date(), -8).toInstant().getEpochSecond()).toUpperCase(); + stringBuilder.append(upperCase); + stringBuilder.append("0000ff"); byte[] dataSum = hexStringToByteArray(stringBuilder.toString()); // 计算校验码1 diff --git a/src/main/java/com/hive/util/DateConvetUtil.java b/src/main/java/com/hive/util/DateConvetUtil.java index fa3b5cb..524b64f 100644 --- a/src/main/java/com/hive/util/DateConvetUtil.java +++ b/src/main/java/com/hive/util/DateConvetUtil.java @@ -55,4 +55,5 @@ public class DateConvetUtil { return newSeconds; } + }