Y_ANXI 2 yıl önce
ebeveyn
işleme
b2b329bb10
25 değiştirilmiş dosya ile 954 ekleme ve 92 silme
  1. 19 6
      pom.xml
  2. 34 0
      src/main/java/com/yunfei/adapter/accept/JSSFFunction.java
  3. 37 0
      src/main/java/com/yunfei/adapter/accept/JqFunction.java
  4. 13 7
      src/main/java/com/yunfei/adapter/accept/MqttSubscriber.java
  5. 1 0
      src/main/java/com/yunfei/adapter/accept/NhhFunction.java
  6. 1 1
      src/main/java/com/yunfei/adapter/accept/UniagroFunction.java
  7. 25 0
      src/main/java/com/yunfei/adapter/accept/cache/Entity.java
  8. 1 1
      src/main/java/com/yunfei/adapter/http/uniagro/UniagroHttp.java
  9. 46 13
      src/main/java/com/yunfei/adapter/http/uniagro/runner/ScheduledTasks.java
  10. 8 0
      src/main/java/com/yunfei/adapter/tcp/DefPacket.java
  11. 37 0
      src/main/java/com/yunfei/adapter/tcp/TcpFactory.java
  12. 65 0
      src/main/java/com/yunfei/adapter/tcp/TcpGroup.java
  13. 43 35
      src/main/java/com/yunfei/adapter/tcp/TcpHandle.java
  14. 10 1
      src/main/java/com/yunfei/adapter/tcp/TcpListener.java
  15. 28 28
      src/main/java/com/yunfei/adapter/tcp/TioConfig.java
  16. 48 0
      src/main/java/com/yunfei/adapter/tcp/nhh/NhhJpHandle.java
  17. 140 0
      src/main/java/com/yunfei/adapter/tcp/qj/JqSdSjHandle.java
  18. 23 0
      src/main/java/com/yunfei/adapter/tcpclient/JSSF.java
  19. 46 0
      src/main/java/com/yunfei/adapter/tcpclient/JSSFClientFactory.java
  20. 131 0
      src/main/java/com/yunfei/adapter/tcpclient/JSSFClientHandle.java
  21. 60 0
      src/main/java/com/yunfei/adapter/tcpclient/JSSFClientListener.java
  22. 75 0
      src/main/java/com/yunfei/adapter/tcpclient/JSSFScanner.java
  23. 26 0
      src/main/java/com/yunfei/adapter/util/AsciiJsonUtils.java
  24. 19 0
      src/main/java/com/yunfei/adapter/util/StaticMethodGetBean.java
  25. 18 0
      src/main/java/com/yunfei/adapter/util/TioUtil.java

+ 19 - 6
pom.xml

@@ -8,10 +8,13 @@
     <name>adapter</name>
     <description>adapter</description>
     <properties>
-        <java.version>17</java.version>
+        <java.version>1.8</java.version>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
-        <spring-boot.version>3.0.2</spring-boot.version>
+        <spring-boot.version>2.7.5</spring-boot.version>
     </properties>
     <dependencies>
         <dependency>
@@ -29,8 +32,18 @@
             <artifactId>tio-core</artifactId>
             <version>3.5.0.v20190822-RELEASE</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.pdfbox</groupId>
+            <artifactId>pdfbox</artifactId>
+            <version>2.0.27</version>
+        </dependency>
 
         <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+            <version>5.1.0</version>
+        </dependency>
+        <dependency>
             <groupId>cn.hutool</groupId>
             <artifactId>hutool-all</artifactId>
             <version>5.8.16</version>
@@ -47,7 +60,7 @@
         <dependency>
             <groupId>com.alibaba</groupId>
             <artifactId>fastjson</artifactId>
-            <version>1.2.80</version>
+            <version>2.0.19</version>
         </dependency>
         <dependency>
             <groupId>org.aspectj</groupId>
@@ -78,8 +91,8 @@
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>3.8.1</version>
                 <configuration>
-                    <source>17</source>
-                    <target>17</target>
+                    <source>8</source>
+                    <target>8</target>
                     <encoding>UTF-8</encoding>
                     <compilerArgs>
                         <arg>-parameters</arg>
@@ -92,7 +105,7 @@
                 <version>${spring-boot.version}</version>
                 <configuration>
                     <mainClass>com.yunfei.adapter.AdapterApplication</mainClass>
-                    <skip>true</skip>
+<!--                    <skip>true</skip>-->
                 </configuration>
                 <executions>
                     <execution>

+ 34 - 0
src/main/java/com/yunfei/adapter/accept/JSSFFunction.java

@@ -0,0 +1,34 @@
+package com.yunfei.adapter.accept;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.yunfei.adapter.tcp.DefPacket;
+import com.yunfei.adapter.tcpclient.JSSFClientFactory;
+import org.springframework.stereotype.Component;
+import org.tio.core.Tio;
+
+import java.nio.charset.StandardCharsets;
+
+@Function(name = "JSSF")
+@Component
+public class JSSFFunction {
+
+
+    @Function
+    public void loadInteractiveValue(String str) {
+        JSONObject jsonObject = JSON.parseObject(str);
+        JSONObject params = new JSONObject();
+        params.put("MsgType", "HardwareInteract");
+        params.put("UserID", jsonObject.getIntValue("deviceId"));
+        params.put("Function", "SendInteractiveElementValue");
+        params.put("ProjectID", "1");
+        JSONArray inputs = jsonObject.getJSONArray("inputs");
+        for (int i = 0; i < inputs.size(); i++) {
+            params.put(inputs.getJSONObject(i).getString("name"), inputs.getJSONObject(i).getInteger("value"));
+        }
+        DefPacket packet = new DefPacket();
+        packet.setBody(JSON.toJSONString(params).getBytes(StandardCharsets.UTF_8));
+        Tio.sendToUser(JSSFClientFactory.map.get(jsonObject.getString("deviceId")), jsonObject.getString("deviceId"), packet);
+    }
+}

+ 37 - 0
src/main/java/com/yunfei/adapter/accept/JqFunction.java

@@ -0,0 +1,37 @@
+package com.yunfei.adapter.accept;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.yunfei.adapter.tcp.DefPacket;
+import com.yunfei.adapter.tcp.TcpFactory;
+import org.springframework.stereotype.Component;
+import org.tio.core.Tio;
+
+import javax.annotation.Resource;
+import java.nio.charset.StandardCharsets;
+
+@Component
+@Function(name = "JQ")
+public class JqFunction {
+    @Resource
+    private TcpFactory tcpFactory;
+
+    @Function
+    public void cmd(String message) {
+        JSONObject obj = JSON.parseObject(message);
+        String deviceId = obj.getString("deviceId");
+        JSONArray inputs = obj.getJSONArray("inputs");
+        obj = new JSONObject();
+        for (int i = 0; i < inputs.size(); i++) {
+            obj.put(inputs.getJSONObject(i).getString("name"), inputs.getJSONObject(i).getIntValue("value"));
+        }
+        obj.put("frame", "cmd");
+        DefPacket packet = new DefPacket();
+        byte[] bytes = JSON.toJSONString(obj).getBytes(StandardCharsets.US_ASCII);
+        packet.setBody(bytes);
+        System.out.println(new String(bytes, StandardCharsets.US_ASCII));
+        Tio.sendToUser(tcpFactory.getTioConfig("JQ"), deviceId, packet);
+    }
+
+}

+ 13 - 7
src/main/java/com/yunfei/adapter/accept/MqttSubscriber.java

@@ -4,12 +4,12 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.yunfei.adapter.http.uniagro.UniagroHttp;
-import jakarta.annotation.PostConstruct;
-import jakarta.annotation.Resource;
 import org.eclipse.paho.client.mqttv3.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
 import java.lang.reflect.Method;
 import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
@@ -24,19 +24,24 @@ public class MqttSubscriber implements MqttCallback {
     @Resource
     private FuncHandleBeanInit beanInit;
     private HashMap<String, String> map = new HashMap<>();
-    private String[] topic = {
-            "/JP/A1030119BCE5EC92/adapter/write",
-            "/PY/9100/adapter/write"
-    };
+
 
     @PostConstruct
     public void init() throws MqttException {
+         String[] topic = {
+                "/JP/A1030119BCE5EC92/adapter/write",
+                "/PY/9100/adapter/write",
+                "/JQSDSJ/20837/adapter/write",
+                 "/JSSF/81/adapter/write"
+        };
         mqttClient.setCallback(this);
         mqttClient.connect();
         mqttClient.subscribe(topic);
         map.put("ZZ", "uniagro");
         map.put("PY", "uniagro");
         map.put("JP", "NHH");
+        map.put("JQSDSJ", "JQ");
+        map.put("JSSF", "JSSF");
     }
 
     @Override
@@ -51,6 +56,7 @@ public class MqttSubscriber implements MqttCallback {
             String deviceId = split[2];
             String product = split[1];
             JSONObject obj = JSON.parseObject(new String(mqttMessage.getPayload(), StandardCharsets.UTF_8));
+            obj.put("deviceId", deviceId);
             if (!obj.containsKey("functionId")) {
                 return;
             }
@@ -58,7 +64,7 @@ public class MqttSubscriber implements MqttCallback {
                 Object bean = beanInit.getBean(map.get(product));
                 Method[] declaredMethods = bean.getClass().getDeclaredMethods();
                 for (Method declaredMethod : declaredMethods) {
-                    if(declaredMethod.getName().equals(obj.get("functionId"))){
+                    if (declaredMethod.getName().equals(obj.get("functionId"))) {
                         declaredMethod.setAccessible(true);
                         declaredMethod.invoke(bean, new String(mqttMessage.getPayload(), StandardCharsets.UTF_8));
                     }

+ 1 - 0
src/main/java/com/yunfei/adapter/accept/NhhFunction.java

@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
 import java.util.HashMap;
 
 public class NhhFunction {
+
     public void NHHJp(JSONObject obj) {
         if (!obj.containsKey("inputs")) {
             return;

+ 1 - 1
src/main/java/com/yunfei/adapter/accept/UniagroFunction.java

@@ -4,9 +4,9 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.yunfei.adapter.http.uniagro.UniagroHttp;
-import jakarta.annotation.Resource;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.Resource;
 import java.util.HashMap;
 
 @Component

+ 25 - 0
src/main/java/com/yunfei/adapter/accept/cache/Entity.java

@@ -0,0 +1,25 @@
+package com.yunfei.adapter.accept.cache;
+
+import java.util.Date;
+
+public class Entity {
+    private Date reportTime;
+
+    private String data;
+
+    public Date getReportTime() {
+        return reportTime;
+    }
+
+    public void setReportTime(Date reportTime) {
+        this.reportTime = reportTime;
+    }
+
+    public String getData() {
+        return data;
+    }
+
+    public void setData(String data) {
+        this.data = data;
+    }
+}

+ 1 - 1
src/main/java/com/yunfei/adapter/http/uniagro/UniagroHttp.java

@@ -3,9 +3,9 @@ package com.yunfei.adapter.http.uniagro;
 import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import jakarta.annotation.Resource;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.Resource;
 import java.util.HashMap;
 import java.util.Objects;
 

+ 46 - 13
src/main/java/com/yunfei/adapter/http/uniagro/runner/ScheduledTasks.java

@@ -5,13 +5,14 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.yunfei.adapter.forword.MqttPublisher;
 import com.yunfei.adapter.http.uniagro.UniagroHttp;
-import jakarta.annotation.Resource;
 import org.eclipse.paho.client.mqttv3.MqttException;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
-import java.io.IOException;
+import javax.annotation.Resource;
 import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 
 @Component
@@ -22,20 +23,43 @@ public class ScheduledTasks {
     private MqttPublisher mqttPublisher;
     static List<Pair<String, String>> deviceIds = new ArrayList<>();
 
+    HashMap<String, String> map = new HashMap<>();
+
     static {
         deviceIds.add(new Pair<>("9001", "ZZ"));
         deviceIds.add(new Pair<>("9100", "PY"));
     }
 
+    int i = 0;
+
     @Scheduled(fixedRate = 20000)
     public void performTask() {
+        i++;
         for (Pair<String, String> device : deviceIds) {
-            String msg = uniagroHttp.readReport(device.getKey());
+            String msg = null;
             try {
-                mqttPublisher.publish("/" + device.getValue() + "/" + device.getKey() + "/properties/report", this.decode(msg));
-            } catch (MqttException e) {
-                throw new RuntimeException(e);
+                msg = uniagroHttp.readReport(device.getKey());
+            } catch (Exception e) {
+                e.printStackTrace();
+            } finally {
+                try {
+                    if (msg != null) {
+                        String decode = this.decode(msg);
+                        if (decode == null) {
+                            return;
+                        }
+                        mqttPublisher.publish("/" + device.getValue() + "/" + device.getKey() + "/properties/report", decode);
+                        map.put(device.getKey(), decode);
+                    } else {
+                        if (map.get(device.getKey()) != null) {
+                            mqttPublisher.publish("/" + device.getValue() + "/" + device.getKey() + "/properties/report", map.get(device.getKey()));
+                        }
+                    }
+                } catch (MqttException e) {
+                    e.printStackTrace();
+                }
             }
+
         }
     }
 
@@ -44,11 +68,11 @@ public class ScheduledTasks {
         JSONObject obj = JSON.parseObject(msg);
         if (obj.containsKey("data")) {
             JSONObject data = obj.getJSONObject("data");
-            if(data.containsKey("angle")){
-                this.putInputs(result,data.getJSONObject("angle"));
+            if (data.containsKey("angle")) {
+                this.putInputs(result, data.getJSONObject("angle"));
             }
 
-            if(data.containsKey("connected")){
+            if (data.containsKey("connected")) {
                 result.put("connected", data.get("connected"));
             }
         }
@@ -59,17 +83,26 @@ public class ScheduledTasks {
         if (obj.containsKey("deviceType")) {
             result.put("deviceType", obj.get("deviceType"));
         }
+        if (!obj.containsKey("data")) {
+            return null;
+        }
         if (obj.getJSONObject("data").containsKey("detail")) {
-            this.putInputs(result,obj.getJSONObject("data").getJSONObject("detail"));
+            this.putInputs(result, obj.getJSONObject("data").getJSONObject("detail"));
         }
         JSONObject property = new JSONObject();
-        property.put("properties",result);
+        property.put("properties", result);
+        property.put("reportTime", new Date());
         return property.toJSONString();
     }
 
-    public void putInputs(JSONObject result,JSONObject data){
+    public void putInputs(JSONObject result, JSONObject data) {
         for (String key : data.keySet()) {
-            result.put(key, data.get(key));
+            Object integer = data.get(key);
+            if (integer == null) {
+                result.put(key, 0);
+            } else {
+                result.put(key, integer);
+            }
         }
     }
 }

+ 8 - 0
src/main/java/com/yunfei/adapter/tcp/DefPacket.java

@@ -6,10 +6,18 @@ public class DefPacket extends Packet {
     private static final long serialVersionUID = -172060606924066412L;
     public static final String CHARSET = "utf-8";
     private byte[] body;
+    private int len;
     public static final String heartbeat = "hello";
 
     public static final String response = "AA01000100BB00CC";
 
+    public int getLen() {
+        return len;
+    }
+
+    public void setLen(int len) {
+        this.len = len;
+    }
 
     public byte[] getBody() {
         return body;

+ 37 - 0
src/main/java/com/yunfei/adapter/tcp/TcpFactory.java

@@ -0,0 +1,37 @@
+package com.yunfei.adapter.tcp;
+
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.stereotype.Component;
+import org.tio.server.ServerTioConfig;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+@Component
+public class TcpFactory implements ApplicationRunner {
+    Map<String, TcpGroup> map = new HashMap<String, TcpGroup>() {{
+        put("NHH", new TcpGroup("0.0.0.0", 6790, "NHH")); //农哈哈
+        put("JQ", new TcpGroup("0.0.0.0", 8082, "JQ")); //佳琪
+    }};
+
+    public ServerTioConfig getTioConfig(String name) {
+        TcpGroup tcpGroup = this.map.get(name);
+        return tcpGroup.getServerTioConfig();
+    }
+
+
+
+    @Override
+    public void run(ApplicationArguments args) throws Exception {
+        map.forEach((x, y) -> {
+            try {
+                y.getTioServer().start(y.getIp(), y.getPort());
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        });
+    }
+
+}

+ 65 - 0
src/main/java/com/yunfei/adapter/tcp/TcpGroup.java

@@ -0,0 +1,65 @@
+package com.yunfei.adapter.tcp;
+
+import org.tio.server.ServerTioConfig;
+import org.tio.server.TioServer;
+
+public class TcpGroup {
+
+    private String ip;
+
+    private Integer port;
+
+    private String name;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    private ServerTioConfig serverTioConfig;
+
+    private TioServer tioServer;
+
+    public TcpGroup(String ip, Integer port, String name) {
+        this.port = port;
+        this.ip = ip;
+        this.name = name;
+        this.serverTioConfig = new ServerTioConfig(new TcpHandle(name), new TcpListener(name));
+        this.tioServer = new TioServer(serverTioConfig);
+    }
+
+    public String getIp() {
+        return ip;
+    }
+
+    public void setIp(String ip) {
+        this.ip = ip;
+    }
+
+    public Integer getPort() {
+        return port;
+    }
+
+    public void setPort(Integer port) {
+        this.port = port;
+    }
+
+    public ServerTioConfig getServerTioConfig() {
+        return serverTioConfig;
+    }
+
+    public void setServerTioConfig(ServerTioConfig serverTioConfig) {
+        this.serverTioConfig = serverTioConfig;
+    }
+
+    public TioServer getTioServer() {
+        return tioServer;
+    }
+
+    public void setTioServer(TioServer tioServer) {
+        this.tioServer = tioServer;
+    }
+}

+ 43 - 35
src/main/java/com/yunfei/adapter/tcp/TcpHandle.java

@@ -1,10 +1,7 @@
 package com.yunfei.adapter.tcp;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.yunfei.adapter.forword.MqttPublisher;
-import jakarta.annotation.Resource;
-import org.springframework.stereotype.Component;
+import com.yunfei.adapter.tcp.nhh.NhhJpHandle;
+import com.yunfei.adapter.tcp.qj.JqSdSjHandle;
 import org.tio.core.ChannelContext;
 import org.tio.core.TioConfig;
 import org.tio.core.exception.AioDecodeException;
@@ -12,48 +9,59 @@ import org.tio.core.intf.Packet;
 import org.tio.server.intf.ServerAioHandler;
 
 import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
 
-@Component
 public class TcpHandle implements ServerAioHandler {
-    @Resource
-    private MqttPublisher mqttPublisher;
+    private String name;
+
+    public String getName() {
+        return name;
+    }
+
+    public TcpHandle(String name) {
+        this.name = name;
+    }
 
     @Override
     public Packet decode(ByteBuffer byteBuffer, int i, int i1, int i2, ChannelContext channelContext) throws AioDecodeException {
-        byte[] array = new byte[byteBuffer.remaining()];
-        byteBuffer.get(array);
-        DefPacket defPackage = new DefPacket();
-        defPackage.setBody(array);
-        return defPackage;
+        switch (this.getName()) {
+            case "NHH":
+                return NhhJpHandle.nhhJpDecode(byteBuffer, i, i1, i2, channelContext);
+            case "JQ":
+                return JqSdSjHandle.JqSDSJDecode(byteBuffer, i, i1, i2, channelContext);
+            default:
+                throw new AioDecodeException("请求失败");
+        }
     }
 
     @Override
     public ByteBuffer encode(Packet packet, TioConfig tioConfig, ChannelContext channelContext) {
-        return null;
+        DefPacket defaultPackage = (DefPacket) packet;
+        byte[] body = defaultPackage.getBody();
+        System.err.println("本次发送" + new String(body, StandardCharsets.US_ASCII));
+        ByteBuffer buffer = ByteBuffer.allocate(body.length);
+        buffer.put(body);
+        return buffer;
     }
 
     @Override
-    public void handler(Packet packet, ChannelContext channelContext) throws Exception {
-        DefPacket defPackage = (DefPacket) packet;
-        byte[] body = defPackage.getBody();
-        String msg = new String(body);
-        String[] split = msg.split(",");
-        mqttPublisher.publish("/NHH/" + split[1] + "/property/report", this.NHH(split));
-    }
+    public void handler(Packet packet, ChannelContext channelContext) {
+        try {
+            switch (this.getName()) {
+                case "NHH":
+                    NhhJpHandle.nhhJpHandle(packet, channelContext);
+                    break;
+                case "JQ":
+                    JqSdSjHandle.JqSDSJHandle(packet, channelContext);
+                    break;
+                default:
+                    throw new AioDecodeException("请求失败");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
 
-    private String NHH(String[] split){
-        //20230221-11:30:30,A1030119BCE5EC92,250,249,46,1,2600,0,0,0
-        JSONObject obj = new JSONObject();
-        obj.put("time",split[0]); //数据时间:20230221-11:30:30
-        obj.put("sn",split[1]); //设备编号:A1030119BCE5EC92
-        obj.put("sleep",split[2]);//设定速度:250  单位:分米/时
-        obj.put("runtime",split[3]); //管道水压:46   单位:MPa/100
-        obj.put("water_pressure",split[4]); //运行状态:1	   说明:0、停止,1、运行
-        obj.put("run",split[5]); //运行状态:1	   说明:0、停止,1、运行
-        obj.put("flow_count",split[6]); // 实时流量:2600 单位:升/时
-        obj.put("last",split[7]); // 末层状态:0    说明:0、非末层,1、末层
-        obj.put("run_surplus",split[8]); //近机倒计时:0  单位:分
-        obj.put("over",split[9]); // 完工停机状态: 说明:0、停止,1、运行
-        return obj.toJSONString();
     }
+
+
 }

+ 10 - 1
src/main/java/com/yunfei/adapter/tcp/TcpListener.java

@@ -5,8 +5,17 @@ import org.tio.core.ChannelContext;
 import org.tio.core.intf.Packet;
 import org.tio.server.intf.ServerAioListener;
 
-@Component
 public class TcpListener implements ServerAioListener {
+    private String name;
+
+    public String getName() {
+        return name;
+    }
+
+    public TcpListener(String name) {
+        this.name = name;
+    }
+
     @Override
     public void onAfterConnected(ChannelContext channelContext, boolean b, boolean b1) throws Exception {
 

+ 28 - 28
src/main/java/com/yunfei/adapter/tcp/TioConfig.java

@@ -1,28 +1,28 @@
-package com.yunfei.adapter.tcp;
-
-import jakarta.annotation.Resource;
-import org.springframework.context.annotation.Bean;
-import org.springframework.stereotype.Component;
-import org.tio.server.ServerTioConfig;
-import org.tio.server.TioServer;
-
-import java.io.IOException;
-
-@Component
-public class TioConfig {
-    @Resource
-    private TcpHandle tcpHandle;
-    @Resource
-    private TcpListener tcpListener;
-
-    @Bean
-    public TioServer create(){
-        TioServer tioServer = new TioServer(new ServerTioConfig(tcpHandle, tcpListener));
-        try {
-            tioServer.start("0.0.0.0",6789);
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-        return tioServer;
-    }
-}
+//package com.yunfei.adapter.tcp;
+//
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.stereotype.Component;
+//import org.tio.server.ServerTioConfig;
+//import org.tio.server.TioServer;
+//
+//import javax.annotation.Resource;
+//import java.io.IOException;
+//
+//@Component
+//public class TioConfig {
+//    @Resource
+//    private TcpHandle tcpHandle;
+//    @Resource
+//    private TcpListener tcpListener;
+//
+//    @Bean
+//    public TioServer create(){
+//        TioServer tioServer = new TioServer(new ServerTioConfig(tcpHandle, tcpListener));
+//        try {
+//            tioServer.start("0.0.0.0",6789);
+//        } catch (IOException e) {
+//            throw new RuntimeException(e);
+//        }
+//        return tioServer;
+//    }
+//}

+ 48 - 0
src/main/java/com/yunfei/adapter/tcp/nhh/NhhJpHandle.java

@@ -0,0 +1,48 @@
+package com.yunfei.adapter.tcp.nhh;
+
+import com.alibaba.fastjson.JSONObject;
+import com.yunfei.adapter.forword.MqttPublisher;
+import com.yunfei.adapter.tcp.DefPacket;
+import com.yunfei.adapter.util.StaticMethodGetBean;
+import org.eclipse.paho.client.mqttv3.MqttException;
+import org.tio.core.ChannelContext;
+import org.tio.core.intf.Packet;
+
+import java.nio.ByteBuffer;
+
+//农哈哈卷盘处理器
+public class NhhJpHandle {
+    public static void nhhJpHandle(Packet packet, ChannelContext channelContext) {
+        DefPacket defPackage = (DefPacket) packet;
+        byte[] body = defPackage.getBody();
+        String msg = new String(body);
+        String[] split = msg.split(",");
+        //20230221-11:30:30,A1030119BCE5EC92,250,249,46,1,2600,0,0,0,0
+        JSONObject obj = new JSONObject();
+        obj.put("time", split[0]); //数据时间:20230221-11:30:30
+        obj.put("sn", split[1]); //设备编号:A1030119BCE5EC92
+        obj.put("sleep", split[2]);//设定速度:250  单位:分米/时
+        obj.put("runtime", split[3]); //管道水压:46   单位:MPa/100
+        obj.put("water_pressure", split[4]); //运行状态:1	   说明:0、停止,1、运行
+        obj.put("run", split[5]); //运行状态:1	   说明:0、停止,1、运行
+        obj.put("flow_count", split[6]); // 实时流量:2600 单位:升/时
+        obj.put("last", split[7]); // 末层状态:0    说明:0、非末层,1、末层
+        obj.put("run_surplus", split[8]); //近机倒计时:0  单位:分
+        obj.put("over", split[9]); // 完工停机状态: 说明:0、停止,1、运行
+        obj.put("failure", split[10]); // 完工停机状态: 说明:0、停止,1、运行
+        try {
+            MqttPublisher bean = StaticMethodGetBean.getBean(MqttPublisher.class);
+            bean.publish("/NHH/" + split[1] + "/property/report", obj.toJSONString());
+        } catch (MqttException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static Packet nhhJpDecode(ByteBuffer byteBuffer, int i, int i1, int i2, ChannelContext channelContext) {
+        byte[] array = new byte[byteBuffer.remaining()];
+        byteBuffer.get(array);
+        DefPacket defPackage = new DefPacket();
+        defPackage.setBody(array);
+        return defPackage;
+    }
+}

+ 140 - 0
src/main/java/com/yunfei/adapter/tcp/qj/JqSdSjHandle.java

@@ -0,0 +1,140 @@
+package com.yunfei.adapter.tcp.qj;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.yunfei.adapter.forword.MqttPublisher;
+import com.yunfei.adapter.tcp.DefPacket;
+import com.yunfei.adapter.util.StaticMethodGetBean;
+import com.yunfei.adapter.util.TioUtil;
+import org.eclipse.paho.client.mqttv3.MqttException;
+import org.tio.core.ChannelContext;
+import org.tio.core.Tio;
+import org.tio.core.intf.Packet;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
+//嘉岐水电双记处理器
+public class JqSdSjHandle {
+
+    /**
+     * 嘉岐水电双记
+     *
+     * @param packet
+     * @param channelContext
+     */
+    public static void JqSDSJHandle(Packet packet, ChannelContext channelContext) throws MqttException {
+        MqttPublisher bean = StaticMethodGetBean.getBean(MqttPublisher.class);
+        DefPacket defPackage = (DefPacket) packet;
+        byte[] body = defPackage.getBody();
+        byte[] resultArray = Arrays.copyOfRange(body, 0, defPackage.getLen());
+        String str = new String(resultArray, StandardCharsets.US_ASCII);
+        System.err.println(str);
+        JSONObject jsonObject = JSON.parseObject(str);
+        if (!jsonObject.containsKey("frame")) {
+            if (jsonObject.containsKey("rssi")) {
+                JSONObject obj = new JSONObject();
+                obj.put("code", 3000);
+                TioUtil.send(channelContext, obj);
+                jsonObject.put("frame","heartbeat");
+            }
+            bean.publish("/JQSDSJ/" + channelContext.userid + "/property/report", paramsToInputs(jsonObject).toJSONString());
+            return;
+        }
+        String frame = jsonObject.getString("frame");
+        switch (frame) {
+            case "reg":
+                TioUtil.send(channelContext, register(jsonObject));
+                return;
+            case "login":
+                Tio.bindUser(channelContext, jsonObject.getString("reg_sn"));
+                TioUtil.send(channelContext, login(jsonObject.getString("reg_sn"), jsonObject.get("pak_sn")));
+                return;
+            case "device":
+                bean.publish("/JQSDSJ/" + channelContext.userid + "/property/report", paramsToInputs(jsonObject).toJSONString());
+                return;
+            case "ele_monitor":
+                JSONObject jsonObject1 = new JSONObject();
+                jsonObject1.put("code", 8000);
+                TioUtil.send(channelContext, jsonObject1);
+                bean.publish("/JQSDSJ/" + channelContext.userid + "/property/report", eleMonitorToInputs(jsonObject).toJSONString());
+                return;
+            case "user":
+                bean.publish("/JQSDSJ/" + channelContext.userid + "/property/report", userToInputs(jsonObject).toJSONString());
+            break;
+            default:
+                bean.publish("/JQSDSJ/" + channelContext.userid + "/property/report", paramsToInputs(jsonObject).toJSONString());
+        }
+    }
+
+    private static JSON userToInputs(JSONObject obj) {
+        JSONObject jsonObject = obj.getJSONObject("card");
+        obj.putAll(jsonObject);
+        return paramsToInputs(obj);
+    }
+
+    public static Packet JqSDSJDecode(ByteBuffer byteBuffer, int i, int i1, int i2, ChannelContext channelContext) {
+        byte[] array = new byte[byteBuffer.remaining()];
+        byteBuffer.get(array);
+        DefPacket defPackage = new DefPacket();
+        byte[] result = new byte[array.length];
+        int len = 0;
+        int end = -1;
+        for (int j = 0; j < array.length; j++) {
+            if (array[j] != 0x0A) {
+                len += 1;
+                result[j] = array[j];
+            } else {
+                end = array[j];
+                break;
+            }
+        }
+        if (end == -1) {
+            return null;
+        }
+        defPackage.setLen(len);
+        defPackage.setBody(result);
+        return defPackage;
+    }
+
+
+    public static JSONObject register(JSONObject jsonObject) {
+        JSONObject obj = new JSONObject();
+        obj.put("code", 1001);
+        obj.put("reg_sn", 11999);
+        return obj;
+    }
+
+    public static JSONObject login(String deviceNo, Object pakSn) {
+        JSONObject object = new JSONObject();
+        object.put("pak_sn", pakSn);
+        object.put("code", 2000);
+        object.put("token", deviceNo);
+        object.put("time_stamp", System.currentTimeMillis() / 1000);
+        return object;
+    }
+
+
+    public static JSONObject paramsToInputs(JSONObject obj) {
+        JSONObject property = new JSONObject();
+        JSONArray array = new JSONArray();
+        for (String s : obj.keySet()) {
+            JSONObject input = new JSONObject();
+            input.put("name", s);
+            input.put("value", obj.get(s));
+            array.add(input);
+        }
+        property.put("properties", array);
+        property.put("reportTime", System.currentTimeMillis());
+        return property;
+    }
+
+    public static JSONObject eleMonitorToInputs(JSONObject obj) {
+        JSONObject jsonObject = obj.getJSONObject("ele_meter");
+        obj.putAll(jsonObject);
+        return paramsToInputs(obj);
+    }
+
+}

+ 23 - 0
src/main/java/com/yunfei/adapter/tcpclient/JSSF.java

@@ -0,0 +1,23 @@
+package com.yunfei.adapter.tcpclient;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+@Getter
+@Setter
+public class JSSF {
+    private String userId;
+    private String password;
+    private List<Element> sfElement;
+
+    @Getter
+    @Setter
+    static
+    class Element{
+        private String InteractiveNumber;
+        private int intValue;
+        private boolean booleanValue;
+    }
+}

+ 46 - 0
src/main/java/com/yunfei/adapter/tcpclient/JSSFClientFactory.java

@@ -0,0 +1,46 @@
+package com.yunfei.adapter.tcpclient;
+
+
+import com.alibaba.fastjson.JSONObject;
+import com.yunfei.adapter.tcp.DefPacket;
+import com.yunfei.adapter.tcp.TcpGroup;
+import org.checkerframework.checker.units.qual.C;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.stereotype.Component;
+import org.tio.client.ClientChannelContext;
+import org.tio.client.ClientTioConfig;
+import org.tio.client.TioClient;
+import org.tio.core.Node;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+@Component
+public class JSSFClientFactory implements ApplicationRunner {
+    public static  Map<String, ClientTioConfig> map = new HashMap<String, ClientTioConfig>() {{
+        put("81", new ClientTioConfig(new JSSFClientHandle("81","139"), new JSSFClientListener("81","139"))); //农哈哈
+    }};
+
+
+    @Override
+    public void run(ApplicationArguments args) throws Exception {
+        map.forEach((x, y) -> {
+            TioClient tioClient = null;
+            try {
+                tioClient = new TioClient(y);
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+            ClientChannelContext connect = null;
+            try {
+                connect = tioClient.connect(new Node("47.92.48.140", 20001));
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        });
+
+    }
+}

+ 131 - 0
src/main/java/com/yunfei/adapter/tcpclient/JSSFClientHandle.java

@@ -0,0 +1,131 @@
+package com.yunfei.adapter.tcpclient;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.yunfei.adapter.tcp.DefPacket;
+import org.tio.client.intf.ClientAioHandler;
+import org.tio.core.ChannelContext;
+import org.tio.core.Tio;
+import org.tio.core.TioConfig;
+import org.tio.core.exception.AioDecodeException;
+import org.tio.core.intf.Packet;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+
+public class JSSFClientHandle implements ClientAioHandler {
+    private String userId;
+
+    private String pwd;
+
+    public JSSFClientHandle(String userId, String pwd) {
+        this.userId = userId;
+        this.pwd = pwd;
+    }
+
+    @Override
+    public Packet heartbeatPacket(ChannelContext channelContext) {
+        return null;
+    }
+
+    @Override
+    public Packet decode(ByteBuffer byteBuffer, int i, int i1, int i2, ChannelContext channelContext) throws AioDecodeException {
+        byte[] array = new byte[byteBuffer.remaining()];
+        String s = new String(array, StandardCharsets.UTF_8);
+        byteBuffer.get(array);
+        DefPacket defPackage = new DefPacket();
+        String message = new String(array, StandardCharsets.UTF_8);
+        defPackage.setBody(message.replace("/n/n", "").getBytes(StandardCharsets.UTF_8));
+        return defPackage;
+    }
+
+    @Override
+    public ByteBuffer encode(Packet packet, TioConfig tioConfig, ChannelContext channelContext) {
+        DefPacket defaultPackage = (DefPacket) packet;
+        byte[] body = defaultPackage.getBody();
+        String s = new String(body, StandardCharsets.UTF_8);
+        s += "\n\n";
+        body = s.getBytes(StandardCharsets.UTF_8);
+        ByteBuffer buffer = ByteBuffer.allocate(body.length);
+        buffer.put(body);
+        return buffer;
+    }
+
+    @Override
+    public void handler(Packet packet, ChannelContext channelContext) throws Exception {
+        DefPacket defPackage = (DefPacket) packet;
+        byte[] body = defPackage.getBody();
+        String s = new String(body, StandardCharsets.UTF_8);
+        JSONObject jsonObject = JSONObject.parseObject(s);
+        if (!jsonObject.containsKey("Function")) {
+            if (jsonObject.containsKey("MsgType")) {
+                if (jsonObject.getString("MsgType").equals("LogOn")) {
+                    getDevices(channelContext);
+                }
+            }
+            return;
+        }
+        switch (jsonObject.getString("Function")) {
+            case "LoadInteractiveAndElement":
+                this.loadInteractiveAndElement(jsonObject, channelContext);
+                return;
+            case "LoadInteractiveValue":
+                this.loadInteractiveValue(jsonObject, channelContext);
+                return;
+        }
+//        bean.publish("/JSSF/" + channelContext.userid + "/property/report", paramsToInputs(jsonObject).toJSONString());
+    }
+
+    private void loadInteractiveValue(JSONObject jsonObject, ChannelContext channelContext) {
+        JSSF jssf = JSSFScanner.currentDevice.get(channelContext.userid);
+        jssf.getSfElement().forEach(x -> {
+            if (x.getInteractiveNumber().equals(jsonObject.getString("InteractiveNumber"))) {
+                JSONObject jsonObject1 = jsonObject.getJSONObject("Values");
+                Set<String> keySet = jsonObject1.keySet();
+                for (String key : keySet) {
+                    if (jsonObject1.get(key) instanceof Boolean) {
+                        x.setBooleanValue(jsonObject1.getBooleanValue(key));
+                    } else if (jsonObject1.get(key) instanceof Integer) {
+                        x.setIntValue(jsonObject1.getIntValue(key));
+                    }
+                }
+            }
+        });
+    }
+
+    private void getDevices(ChannelContext channelContext) {
+        JSONObject obj = new JSONObject();
+        obj.put("MsgType", "APPProgram");
+        obj.put("UserID", channelContext.userid);
+        obj.put("ProjectID", 1);
+        obj.put("Function", "LoadInteractiveAndElement");
+        DefPacket defPacket = new DefPacket();
+        System.err.println(JSON.toJSONString(obj));
+        defPacket.setBody(JSON.toJSONString(obj).getBytes(StandardCharsets.UTF_8));
+        Tio.send(channelContext, defPacket);
+    }
+
+    public void loadInteractiveAndElement(JSONObject object, ChannelContext channelContext) {
+        JSONArray jsonArray = object.getJSONObject("DataTable").getJSONArray("Rows");
+        JSSF jssf = new JSSF();
+        jssf.setSfElement(new ArrayList<>());
+        jssf.setPassword(pwd);
+        jssf.setUserId(userId);
+        for (int i = 0; i < jsonArray.size(); i++) {
+            JSONArray jsonArray1 = jsonArray.getJSONObject(i).getJSONArray("Value");
+            if (jsonArray1.getString(5).equals("电磁阀")) {
+                if (jssf.getSfElement() == null || jssf.getSfElement().size() == 0) {
+                    jssf.setSfElement(new ArrayList<>());
+                }
+                JSSF.Element element = new JSSF.Element();
+                element.setInteractiveNumber(jsonArray1.getString(2));
+                element.setIntValue(0);
+                element.setBooleanValue(false);
+                jssf.getSfElement().add(element);
+            }
+        }
+        JSSFScanner.currentDevice.put(channelContext.userid, jssf);
+    }
+}

+ 60 - 0
src/main/java/com/yunfei/adapter/tcpclient/JSSFClientListener.java

@@ -0,0 +1,60 @@
+package com.yunfei.adapter.tcpclient;
+
+import com.alibaba.fastjson.JSONObject;
+import com.yunfei.adapter.tcp.DefPacket;
+import org.tio.client.intf.ClientAioListener;
+import org.tio.core.ChannelContext;
+import org.tio.core.Tio;
+import org.tio.core.intf.Packet;
+
+import java.nio.charset.StandardCharsets;
+
+public class JSSFClientListener implements ClientAioListener {
+
+    private String userId;
+    private String pwd;
+
+    public JSSFClientListener(String userId, String pwd) {
+        this.userId = userId;
+        this.pwd = pwd;
+    }
+
+    @Override
+    public void onAfterConnected(ChannelContext channelContext, boolean b, boolean b1) throws Exception {
+        JSONObject obj = new JSONObject();
+        obj.put("MsgType", "LogOn");
+        obj.put("ClientType", "APP");
+        obj.put("VersionNo", "2.3");
+        obj.put("UserName", userId);
+        obj.put("PassWord", pwd);
+        DefPacket defPacket = new DefPacket();
+        Tio.bindUser(channelContext, userId);
+        defPacket.setBody(obj.toJSONString().getBytes(StandardCharsets.UTF_8));
+        Tio.send(channelContext, defPacket);
+    }
+
+    @Override
+    public void onAfterDecoded(ChannelContext channelContext, Packet packet, int i) throws Exception {
+
+    }
+
+    @Override
+    public void onAfterReceivedBytes(ChannelContext channelContext, int i) throws Exception {
+
+    }
+
+    @Override
+    public void onAfterSent(ChannelContext channelContext, Packet packet, boolean b) throws Exception {
+
+    }
+
+    @Override
+    public void onAfterHandled(ChannelContext channelContext, Packet packet, long l) throws Exception {
+
+    }
+
+    @Override
+    public void onBeforeClose(ChannelContext channelContext, Throwable throwable, String s, boolean b) throws Exception {
+
+    }
+}

+ 75 - 0
src/main/java/com/yunfei/adapter/tcpclient/JSSFScanner.java

@@ -0,0 +1,75 @@
+package com.yunfei.adapter.tcpclient;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.yunfei.adapter.forword.MqttPublisher;
+import com.yunfei.adapter.tcp.DefPacket;
+import com.yunfei.adapter.tcp.qj.JqSdSjHandle;
+import org.eclipse.paho.client.mqttv3.MqttException;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+import org.tio.core.Tio;
+
+import javax.annotation.Resource;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+
+@Component
+public class JSSFScanner {
+    @Resource
+    private MqttPublisher mqttPublisher;
+
+    public static HashMap<String, JSSF> currentDevice = new LinkedHashMap<>();
+
+    @Scheduled(fixedRate = 50000)
+    public void jssfScanner() {
+        if (currentDevice.size() == 0) {
+            return;
+        }
+        Set<String> userIds = currentDevice.keySet();
+        for (String userId : userIds) {
+            JSSF jssf = currentDevice.get(userId);
+            if (jssf == null) continue;
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("MsgType", "HardwareInteract");
+            jsonObject.put("UserID", Integer.parseInt(jssf.getUserId()));
+            jsonObject.put("ProjectID", 1);
+            jsonObject.put("Function", "LoadInteractiveValue");
+            for (JSSF.Element ele : jssf.getSfElement()) {
+                jsonObject.put("InteractiveNumber", Integer.parseInt(ele.getInteractiveNumber()));
+                DefPacket packet = new DefPacket();
+                try {
+                    Thread.sleep(500);
+                } catch (InterruptedException e) {
+                    throw new RuntimeException(e);
+                }
+                packet.setBody(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8));
+                Tio.sendToUser(JSSFClientFactory.map.get(jssf.getUserId()), jssf.getUserId(), packet);
+            }
+        }
+    }
+
+
+    @Scheduled(fixedRate = 50000)
+    public void reportDeviceStatus() {
+        if (currentDevice.size() == 0) {
+            return;
+        }
+        Set<String> keyed = currentDevice.keySet();
+        for (String key : keyed) {
+            if (currentDevice.get(key) == null) continue;
+            JSSF jssfs = currentDevice.get(key);
+            JSONObject jsonObject = JqSdSjHandle.paramsToInputs(JSONObject.parseObject(JSON.toJSONString(jssfs)));
+            try {
+                mqttPublisher.publish("/JSSF/" + jssfs.getUserId() + "/property/report", jsonObject.toJSONString());
+                break;
+            } catch (MqttException e) {
+                throw new RuntimeException(e);
+            }
+
+        }
+    }
+
+
+}

+ 26 - 0
src/main/java/com/yunfei/adapter/util/AsciiJsonUtils.java

@@ -0,0 +1,26 @@
+package com.yunfei.adapter.util;
+
+import java.nio.charset.StandardCharsets;
+
+public class AsciiJsonUtils {
+
+    /**
+     * 将接收到的byte[]转换为字符串
+     *
+     * @param data 接收到的byte数组
+     * @return 转换后的字符串
+     */
+    public static String bytesToString(byte[] data) {
+        return new String(data, StandardCharsets.US_ASCII);
+    }
+
+    /**
+     * 将字符串转换为byte[]以发送给设备
+     *
+     * @param jsonStr 要发送的字符串
+     * @return 转换后的byte数组
+     */
+    public static byte[] stringToBytes(String jsonStr) {
+        return jsonStr.getBytes(StandardCharsets.US_ASCII);
+    }
+}

+ 19 - 0
src/main/java/com/yunfei/adapter/util/StaticMethodGetBean.java

@@ -0,0 +1,19 @@
+package com.yunfei.adapter.util;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+@Component
+public class StaticMethodGetBean<T> implements ApplicationContextAware {
+    private static ApplicationContext applicationContext;
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        StaticMethodGetBean.applicationContext = applicationContext;
+    }
+ 
+    public static <T> T  getBean(Class<T> clazz) {
+        return applicationContext != null?applicationContext.getBean(clazz):null;
+    }
+}

+ 18 - 0
src/main/java/com/yunfei/adapter/util/TioUtil.java

@@ -0,0 +1,18 @@
+package com.yunfei.adapter.util;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.yunfei.adapter.tcp.DefPacket;
+import org.tio.core.ChannelContext;
+import org.tio.core.Tio;
+
+import java.nio.charset.StandardCharsets;
+
+public class TioUtil {
+
+    public static boolean send(ChannelContext channelContext, JSONObject obj) {
+        DefPacket defPacket = new DefPacket();
+        defPacket.setBody(JSON.toJSONString(obj).getBytes(StandardCharsets.US_ASCII));
+        return Tio.send(channelContext, defPacket);
+    }
+}