From a836f03a5d1fbfa81e147d09ffdfa87ba3975c13 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期二, 18 三月 2025 16:45:02 +0800
Subject: [PATCH] 1

---
 server/web/src/main/java/com/doumee/jtt808/web/endpoint/JT808Endpoint.java |  239 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 239 insertions(+), 0 deletions(-)

diff --git a/server/web/src/main/java/com/doumee/jtt808/web/endpoint/JT808Endpoint.java b/server/web/src/main/java/com/doumee/jtt808/web/endpoint/JT808Endpoint.java
new file mode 100644
index 0000000..c565b42
--- /dev/null
+++ b/server/web/src/main/java/com/doumee/jtt808/web/endpoint/JT808Endpoint.java
@@ -0,0 +1,239 @@
+package com.doumee.jtt808.web.endpoint;
+
+import com.alibaba.fastjson.JSONObject;
+import com.doumee.core.utils.DateUtil;
+import com.doumee.dao.business.model.Bikes;
+import com.doumee.jtt808.web.service.Jtt808Service;
+import com.doumee.service.business.BikesService;
+import io.github.yezhihao.netmc.core.annotation.Async;
+import io.github.yezhihao.netmc.core.annotation.AsyncBatch;
+import io.github.yezhihao.netmc.core.annotation.Endpoint;
+import io.github.yezhihao.netmc.core.annotation.Mapping;
+import io.github.yezhihao.netmc.session.Session;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.yzh.protocol.basics.JTMessage;
+import org.yzh.protocol.commons.JT808;
+import org.yzh.protocol.commons.transform.AttributeKey;
+import org.yzh.protocol.commons.transform.attribute.Battery;
+import org.yzh.protocol.t808.*;
+import com.doumee.jtt808.web.model.entity.DeviceDO;
+import com.doumee.jtt808.web.model.enums.SessionKey;
+import com.doumee.jtt808.web.service.FileService;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.Date;
+import java.util.List;
+
+import static org.yzh.protocol.commons.JT808.*;
+
+@Endpoint
+@Component
+public class JT808Endpoint {
+
+    @Autowired
+    private Jtt808Service jtt808Service;
+
+    private static final Logger log = LoggerFactory.getLogger(JT808Endpoint.class);
+
+    @Autowired
+    private FileService fileService;
+
+    @Mapping(types = 缁堢閫氱敤搴旂瓟, desc = "缁堢閫氱敤搴旂瓟")
+    public Object T0001(T0001 message, Session session) {
+        session.response(message);
+        return null;
+    }
+
+    @Mapping(types = 缁堢蹇冭烦, desc = "缁堢蹇冭烦")
+    public void T0002(JTMessage message, Session session) {
+        log.info("缁堢蹇冭烦========={}", JSONObject.toJSONString(message));
+    }
+
+    @Mapping(types = 缁堢娉ㄩ攢, desc = "缁堢娉ㄩ攢")
+    public void T0003(JTMessage message, Session session) {
+        session.invalidate();
+    }
+
+    @Mapping(types = 鏌ヨ鏈嶅姟鍣ㄦ椂闂�, desc = "鏌ヨ鏈嶅姟鍣ㄦ椂闂�")
+    public T8004 T0004(JTMessage message, Session session) {
+        T8004 result = new T8004(LocalDateTime.now(ZoneOffset.UTC));
+        return result;
+    }
+
+    @Mapping(types = 缁堢琛ヤ紶鍒嗗寘璇锋眰, desc = "缁堢琛ヤ紶鍒嗗寘璇锋眰")
+    public void T8003(T8003 message, Session session) {
+    }
+    @Mapping(types = 缁堢鏍℃椂璇锋眰涓婅, desc = "缁堢鏍℃椂璇锋眰涓婅")
+    public void T0F01(JTMessage message, Session session) {
+    }
+
+    @Mapping(types = 缁堢娉ㄥ唽, desc = "缁堢娉ㄥ唽")
+    public T8100 T0100(T0100 message, Session session) {
+        session.register(message);
+        DeviceDO device = new DeviceDO();
+        device.setProtocolVersion(message.getProtocolVersion());
+        device.setMobileNo(message.getClientId());
+        device.setDeviceId(message.getDeviceId());
+        device.setPlateNo(message.getPlateNo());
+        session.setAttribute(SessionKey.Device, device);
+        T8100 result = new T8100();
+        result.setResponseSerialNo(message.getSerialNo());
+        result.setToken(message.getDeviceId() + "," + message.getPlateNo());
+        result.setResultCode(T8100.Success);
+        return result;
+    }
+
+    @Mapping(types = 缁堢閴存潈, desc = "缁堢閴存潈")
+    public T0001 T0102(T0102 message, Session session) {
+        session.register(message);
+        DeviceDO device = new DeviceDO();
+        String[] token = message.getToken().split(",");
+        device.setProtocolVersion(message.getProtocolVersion());
+        device.setMobileNo(message.getClientId());
+        device.setDeviceId(token[0]);
+        if (token.length > 1)
+            device.setPlateNo(token[1]);
+        session.setAttribute(SessionKey.Device, device);
+
+        T0001 result = new T0001();
+        result.setResponseSerialNo(message.getSerialNo());
+        result.setResponseMessageId(message.getMessageId());
+        result.setResultCode(T0001.Success);
+        return result;
+    }
+
+    @Mapping(types = 鏌ヨ缁堢鍙傛暟搴旂瓟, desc = "鏌ヨ缁堢鍙傛暟搴旂瓟")
+    public void T0104(T0104 message, Session session) {
+        session.response(message);
+    }
+
+    @Mapping(types = 鏌ヨ缁堢灞炴�у簲绛�, desc = "鏌ヨ缁堢灞炴�у簲绛�")
+    public void T0107(T0107 message, Session session) {
+        log.info("鏌ヨ缁堢灞炴�у簲绛�========={}", JSONObject.toJSONString(message));
+        session.response(message);
+    }
+
+    @Mapping(types = 缁堢鍗囩骇缁撴灉閫氱煡, desc = "缁堢鍗囩骇缁撴灉閫氱煡")
+    public void T0108(T0108 message, Session session) {
+    }
+
+    /**
+     * 寮傛鎵归噺澶勭悊
+     * poolSize锛氬弬鑰冩暟鎹簱CPU鏍稿績鏁伴噺
+     * maxElements锛氭渶澶х疮绉�4000鏉¤褰曞鐞嗕竴娆�
+     * maxWait锛氭渶澶х瓑寰呮椂闂�1绉�
+     */
+    @AsyncBatch(poolSize = 2, maxElements = 4000, maxWait = 1000)
+    @Mapping(types = 浣嶇疆淇℃伅姹囨姤, desc = "浣嶇疆淇℃伅姹囨姤")
+    public void T0200(List<T0200> list) throws Exception {
+        jtt808Service.updateBikesInfo(list);
+        System.out.println(JSONObject.toJSONString(list)
+      );
+    }
+
+    @Mapping(types = 瀹氫綅鏁版嵁鎵归噺涓婁紶, desc = "瀹氫綅鏁版嵁鎵归噺涓婁紶")
+    public void T0704(T0704 message) {
+    }
+    public static String bcd2String(byte[] bytes) {
+        StringBuilder temp = new StringBuilder(bytes.length * 2);
+        for (int i = 0; i < bytes.length; i++) {
+            // 楂樺洓浣�
+            temp.append((bytes[i] & 0xf0) >>> 4);
+            // 浣庡洓浣�
+            temp.append(bytes[i] & 0x0f);
+        }
+        return temp.toString().substring(0, 1).equalsIgnoreCase("0") ? temp.toString().substring(1) : temp.toString();
+    }
+
+    @Mapping(types = {浣嶇疆淇℃伅鏌ヨ搴旂瓟, 杞﹁締鎺у埗搴旂瓟}, desc = "浣嶇疆淇℃伅鏌ヨ搴旂瓟/杞﹁締鎺у埗搴旂瓟")
+    public void T0201_0500(T0201_0500 message, Session session) {
+        session.response(message);
+    }
+
+    @Mapping(types = 浜嬩欢鎶ュ憡, desc = "浜嬩欢鎶ュ憡")
+    public void T0301(T0301 message, Session session) {
+    }
+
+    @Mapping(types = 鎻愰棶搴旂瓟, desc = "鎻愰棶搴旂瓟")
+    public void T0302(T0302 message, Session session) {
+    }
+
+    @Mapping(types = 淇℃伅鐐规挱_鍙栨秷, desc = "淇℃伅鐐规挱/鍙栨秷")
+    public void T0303(T0303 message, Session session) {
+    }
+
+    @Mapping(types = 鏌ヨ鍖哄煙鎴栫嚎璺暟鎹簲绛�, desc = "鏌ヨ鍖哄煙鎴栫嚎璺暟鎹簲绛�")
+    public void T0608(T0608 message, Session session) {
+        session.response(message);
+    }
+
+    @Mapping(types = 琛岄┒璁板綍鏁版嵁涓婁紶, desc = "琛岄┒璁板綍浠暟鎹笂浼�")
+    public void T0700(T0700 message, Session session) {
+        session.response(message);
+    }
+
+    @Mapping(types = 鐢靛瓙杩愬崟涓婃姤, desc = "鐢靛瓙杩愬崟涓婃姤")
+    public void T0701(JTMessage message, Session session) {
+    }
+
+    @Mapping(types = 椹鹃┒鍛樿韩浠戒俊鎭噰闆嗕笂鎶�, desc = "椹鹃┒鍛樿韩浠戒俊鎭噰闆嗕笂鎶�")
+    public void T0702(T0702 message, Session session) {
+        session.response(message);
+    }
+
+    @Mapping(types = CAN鎬荤嚎鏁版嵁涓婁紶, desc = "CAN鎬荤嚎鏁版嵁涓婁紶")
+    public void T0705(T0705 message, Session session) {
+    }
+
+    @Mapping(types = 澶氬獟浣撲簨浠朵俊鎭笂浼�, desc = "澶氬獟浣撲簨浠朵俊鎭笂浼�")
+    public void T0800(T0800 message, Session session) {
+    }
+
+    @Async
+    @Mapping(types = 澶氬獟浣撴暟鎹笂浼�, desc = "澶氬獟浣撴暟鎹笂浼�")
+    public JTMessage T0801(T0801 message, Session session) {
+        if (message.getPacket() == null) {
+            T0001 result = new T0001();
+            result.copyBy(message);
+            result.setMessageId(JT808.骞冲彴閫氱敤搴旂瓟);
+            result.setSerialNo(session.nextSerialNo());
+
+            result.setResponseSerialNo(message.getSerialNo());
+            result.setResponseMessageId(message.getMessageId());
+            result.setResultCode(T0001.Success);
+            return result;
+        }
+        fileService.saveMediaFile(message);
+        T8800 result = new T8800();
+        result.setMediaId(message.getId());
+        return result;
+    }
+
+    @Mapping(types = 瀛樺偍澶氬獟浣撴暟鎹绱㈠簲绛�, desc = "瀛樺偍澶氬獟浣撴暟鎹绱㈠簲绛�")
+    public void T0802(T0802 message, Session session) {
+        session.response(message);
+    }
+
+    @Mapping(types = 鎽勫儚澶寸珛鍗虫媿鎽勫懡浠ゅ簲绛�, desc = "鎽勫儚澶寸珛鍗虫媿鎽勫懡浠ゅ簲绛�")
+    public void T0805(T0805 message, Session session) {
+        session.response(message);
+    }
+
+    @Mapping(types = 鏁版嵁涓婅閫忎紶, desc = "鏁版嵁涓婅閫忎紶")
+    public void T0900(T0900 message, Session session) {
+    }
+
+    @Mapping(types = 鏁版嵁鍘嬬缉涓婃姤, desc = "鏁版嵁鍘嬬缉涓婃姤")
+    public void T0901(T0901 message, Session session) {
+    }
+
+    @Mapping(types = 缁堢RSA鍏挜, desc = "缁堢RSA鍏挜")
+    public void T0A00(T0A00_8A00 message, Session session) {
+        session.response(message);
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3