jiazx0107@163.com
2023-10-26 233c0e20548cadafb77efdcb3418f38c6658bbad
四川省网关接口相关7
已重命名1个文件
已修改19个文件
已添加9个文件
1246 ■■■■ 文件已修改
pom.xml 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/data/GatewayDeviceType.java 34 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/data/GatewayProtocol.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/data/PushProtocol.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/data/SyncProtocol.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/service/ApiTriggerService.java 57 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/utils/BytesUtil.java 404 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/utils/ContextUtil.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/api/utils/SpringUtil.java 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/GatewayRunner.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/GatewayUtils.java 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/api/DeviceReportService.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/api/GatewayRemoteManager.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/api/GatewaySyncWeightService.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/entity/GatewayDevice.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/ScConstant.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/data/WebSocketPacketHeader.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncWeightImpl1.java 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/websocket/WebSocketDeviceLed.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/websocket/WebSocketDeviceReport.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/view/GatewayConf.view.xml 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml 76 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/package-info.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/weightyh/MessageConsumer.java 114 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/weightyh/SessionListener.java 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/weightyh/YhScaleServerEngine.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -170,6 +170,14 @@
        <!-- </dependency> -->
        <!-- å¼•å…¥IO包 -->
        <dependency>
            <groupId>com.ld.base.io</groupId>
            <artifactId>base-io-netty</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
        <!-- mysql连接 -->
        <dependency>
            <groupId>mysql</groupId>
src/main/java/com/fzzy/api/data/GatewayDeviceProtocol.java
@@ -1,6 +1,11 @@
package com.fzzy.api.data;
import com.fzzy.api.entity.ApiTrigger;
import java.util.ArrayList;
import java.util.List;
/**
 * ç½‘关与设备直接的通讯协议
 */
@@ -12,12 +17,24 @@
    DEVICE_IDCARD_HTTP("DEVICE_IDCARD_HTTP", "身份证-HTTP协议"),
    DEVICE_LED_HTTP("DEVICE_LED_HTTP", "LED-HTTP协议"),
    DEVICE_LPR_SDK_HK("DEVICE_LPR_SDK_HK", "车牌识别-SDK海康"),
    DEVICE_TEST("DEVICE_TEST", "测试协议");
    DEVICE_TEST("DEVICE_TEST", "空协议");
    private String code;
    private String name;
    public static List<ApiTrigger> listTrigger() {
        List<ApiTrigger> list = new ArrayList<>();
        list.add(new ApiTrigger(GRAIN_FZZY_ZH_2023.getCode(), GRAIN_FZZY_ZH_2023.getName()));
        list.add(new ApiTrigger(DEVICE_WEIGHT_HTTP.getCode(), DEVICE_WEIGHT_HTTP.getName()));
        list.add(new ApiTrigger(DEVICE_WEIGHT_TCP_YH.getCode(), DEVICE_WEIGHT_TCP_YH.getName()));
        list.add(new ApiTrigger(DEVICE_IDCARD_HTTP.getCode(), DEVICE_IDCARD_HTTP.getName()));
        list.add(new ApiTrigger(DEVICE_LED_HTTP.getCode(), DEVICE_LED_HTTP.getName()));
        list.add(new ApiTrigger(DEVICE_LPR_SDK_HK.getCode(), DEVICE_LPR_SDK_HK.getName()));
        list.add(new ApiTrigger(DEVICE_TEST.getCode(), DEVICE_TEST.getName()));
        return list;
    }
    public String getCode() {
        return code;
src/main/java/com/fzzy/api/data/GatewayDeviceType.java
@@ -1,24 +1,44 @@
package com.fzzy.api.data;
import com.fzzy.api.entity.ApiTrigger;
import java.util.ArrayList;
import java.util.List;
/**
 * ç½‘关设备类型
 */
public enum GatewayDeviceType {
    GRAIN_FZZY_ZH_2023("GRAIN_FZZY_ZH_2023", "粮情-风正致远控制柜协议2023"),
    DEVICE_WEIGHT_HTTP("DEVICE_WEIGHT_HTTP", "地磅-HTTP协议"),
    DEVICE_WEIGHT_TCP_YH("DEVICE_WEIGHT_TCP_YH", "地磅-耀华TCP协议"),
    DEVICE_IDCARD_HTTP("DEVICE_IDCARD_HTTP", "身份证-HTTP协议"),
    DEVICE_LED_HTTP("DEVICE_LED_HTTP", "LED-HTTP协议"),
    DEVICE_LPR_SDK_HK("DEVICE_LPR_SDK_HK", "车牌识别-SDK海康"),
    DEVICE_TEST("DEVICE_TEST", "测试协议");
    TYPE_01("TYPE_01", "地磅"),
    TYPE_02("TYPE_02", "车牌识别"),
    TYPE_03("TYPE_03", "道闸"),
    TYPE_04("TYPE_04", "LED"),
    TYPE_05("TYPE_05", "扦样机"),
    TYPE_06("TYPE_06", "摄像头"),
    TYPE_07("TYPE_07", "粮情分机"),
    TYPE_99("TYPE_99", "独立IOT");
    private String code;
    private String name;
    public static List<ApiTrigger> listTrigger() {
        List<ApiTrigger> list = new ArrayList<>();
        list.add(new ApiTrigger(TYPE_01.getCode(), TYPE_01.getName()));
        list.add(new ApiTrigger(TYPE_02.getCode(), TYPE_02.getName()));
        list.add(new ApiTrigger(TYPE_03.getCode(), TYPE_03.getName()));
        list.add(new ApiTrigger(TYPE_04.getCode(), TYPE_04.getName()));
        list.add(new ApiTrigger(TYPE_05.getCode(), TYPE_05.getName()));
        list.add(new ApiTrigger(TYPE_06.getCode(), TYPE_06.getName()));
        list.add(new ApiTrigger(TYPE_07.getCode(), TYPE_07.getName()));
        list.add(new ApiTrigger(TYPE_99.getCode(), TYPE_99.getName()));
        return list;
    }
    public String getCode() {
        return code;
    }
src/main/java/com/fzzy/api/data/GatewayProtocol.java
@@ -1,6 +1,11 @@
package com.fzzy.api.data;
import com.fzzy.api.entity.ApiTrigger;
import java.util.ArrayList;
import java.util.List;
/**
 * ç³»ç»Ÿä¸Žç½‘关之间的通讯协议
 */
@@ -15,6 +20,15 @@
    private String code;
    private String name;
    public static List<ApiTrigger> listTrigger() {
        List<ApiTrigger> list = new ArrayList<>();
        list.add(new ApiTrigger(GATE_WEBSOCKET.getCode(), GATE_WEBSOCKET.getName()));
        list.add(new ApiTrigger(GATE_MQTT.getCode(), GATE_MQTT.getName()));
        list.add(new ApiTrigger(GATE_HTTP.getCode(), GATE_HTTP.getName()));
        list.add(new ApiTrigger(GATE_TEST.getCode(), GATE_TEST.getName()));
        return list;
    }
    public String getCode() {
        return code;
src/main/java/com/fzzy/api/data/PushProtocol.java
@@ -1,6 +1,11 @@
package com.fzzy.api.data;
import com.fzzy.api.entity.ApiTrigger;
import java.util.ArrayList;
import java.util.List;
/**
 * @Desc: ç³»ç»Ÿæ”¯æŒå·²ç»å®žçŽ°çš„åè®®
 * @author: andy.jia
@@ -26,6 +31,25 @@
    private String name;
    public static List<ApiTrigger> listTrigger() {
        List<ApiTrigger> list = new ArrayList<>();
        list.add(new ApiTrigger(GB_DEFAULT.getCode(), GB_DEFAULT.getName()));
        list.add(new ApiTrigger(GB_2022.getCode(), GB_2022.getName()));
        list.add(new ApiTrigger(SB_SH_2021.getCode(), SB_SH_2021.getName()));
        list.add(new ApiTrigger(SB_GD_2022.getCode(), SB_GD_2022.getName()));
        list.add(new ApiTrigger(SB_GD_2020.getCode(), SB_GD_2020.getName()));
        list.add(new ApiTrigger(SB_HN_2022.getCode(), SB_HN_2022.getName()));
        list.add(new ApiTrigger(SB_WHJL_2023.getCode(), SB_WHJL_2023.getName()));
        list.add(new ApiTrigger(HB_FZZY_JG_2022.getCode(), HB_FZZY_JG_2022.getName()));
        list.add(new ApiTrigger(SB_SHJdJW_2023.getCode(), SB_SHJdJW_2023.getName()));
        list.add(new ApiTrigger(SB_SH_2023.getCode(), SB_SH_2023.getName()));
        list.add(new ApiTrigger(GATEWAY_SC_2023.getCode(), GATEWAY_SC_2023.getName()));
        return list;
    }
    public String getCode() {
        return code;
    }
src/main/java/com/fzzy/api/data/SyncProtocol.java
@@ -1,6 +1,11 @@
package com.fzzy.api.data;
import com.fzzy.api.entity.ApiTrigger;
import java.util.ArrayList;
import java.util.List;
/**
 * @Desc: ç³»ç»Ÿæ”¯æŒçš„同步协议
 * @author: andy.jia
@@ -20,6 +25,19 @@
    private String name;
    public static List<ApiTrigger> listTrigger() {
        List<ApiTrigger> list = new ArrayList<>();
        list.add(new ApiTrigger(GB_DEFAULT.getCode(), GB_DEFAULT.getName()));
        list.add(new ApiTrigger(FZZY_V30_GB.getCode(), FZZY_V30_GB.getName()));
        list.add(new ApiTrigger(FZZY_V35_GB.getCode(), FZZY_V35_GB.getName()));
        list.add(new ApiTrigger(FZZY_V40_GB.getCode(), FZZY_V40_GB.getName()));
        list.add(new ApiTrigger(FZZY_V40_WHJL.getCode(), FZZY_V40_WHJL.getName()));
        list.add(new ApiTrigger(FZZY_V35_SHYZ.getCode(), FZZY_V35_SHYZ.getName()));
        return list;
    }
    public String getCode() {
        return code;
    }
src/main/java/com/fzzy/api/service/ApiTriggerService.java
@@ -4,10 +4,7 @@
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.Expose;
import com.fzzy.api.Constant;
import com.fzzy.api.data.GatewayDeviceProtocol;
import com.fzzy.api.data.GatewayProtocol;
import com.fzzy.api.data.PushProtocol;
import com.fzzy.api.data.SyncProtocol;
import com.fzzy.api.data.*;
import com.fzzy.api.entity.ApiTrigger;
import com.fzzy.api.utils.RedisConst;
import com.fzzy.api.utils.RedisUtil;
@@ -180,21 +177,7 @@
     */
    @DataProvider
    public List<ApiTrigger> triggerPushProtocol() {
        List<ApiTrigger> list = new ArrayList<>();
        list.add(new ApiTrigger(PushProtocol.GB_DEFAULT.getCode(), PushProtocol.GB_DEFAULT.getName()));
        list.add(new ApiTrigger(PushProtocol.GB_2022.getCode(), PushProtocol.GB_2022.getName()));
        list.add(new ApiTrigger(PushProtocol.SB_SH_2021.getCode(), PushProtocol.SB_SH_2021.getName()));
        list.add(new ApiTrigger(PushProtocol.SB_SC_2021.getCode(), PushProtocol.SB_SC_2021.getName()));
        list.add(new ApiTrigger(PushProtocol.SB_GD_2022.getCode(), PushProtocol.SB_GD_2022.getName()));
        list.add(new ApiTrigger(PushProtocol.SB_GD_2020.getCode(), PushProtocol.SB_GD_2020.getName()));
        list.add(new ApiTrigger(PushProtocol.SB_HN_2022.getCode(), PushProtocol.SB_HN_2022.getName()));
        list.add(new ApiTrigger(PushProtocol.SB_WHJL_2023.getCode(), PushProtocol.SB_WHJL_2023.getName()));
        list.add(new ApiTrigger(PushProtocol.HB_FZZY_JG_2022.getCode(), PushProtocol.HB_FZZY_JG_2022.getName()));
        list.add(new ApiTrigger(PushProtocol.SB_SHJdJW_2023.getCode(), PushProtocol.SB_SHJdJW_2023.getName()));
        list.add(new ApiTrigger(PushProtocol.SB_SH_2023.getCode(), PushProtocol.SB_SH_2023.getName()));
        list.add(new ApiTrigger(PushProtocol.GATEWAY_SC_2023.getCode(), PushProtocol.GATEWAY_SC_2023.getName()));
        return list;
        return PushProtocol.listTrigger();
    }
    /**
@@ -205,14 +188,7 @@
     */
    @DataProvider
    public List<ApiTrigger> triggerSyncProtocol() {
        List<ApiTrigger> list = new ArrayList<>();
        list.add(new ApiTrigger(SyncProtocol.GB_DEFAULT.getCode(), SyncProtocol.GB_DEFAULT.getName()));
        list.add(new ApiTrigger(SyncProtocol.FZZY_V30_GB.getCode(), SyncProtocol.FZZY_V30_GB.getName()));
        list.add(new ApiTrigger(SyncProtocol.FZZY_V35_GB.getCode(), SyncProtocol.FZZY_V35_GB.getName()));
        list.add(new ApiTrigger(SyncProtocol.FZZY_V40_GB.getCode(), SyncProtocol.FZZY_V40_GB.getName()));
        list.add(new ApiTrigger(SyncProtocol.FZZY_V40_WHJL.getCode(), SyncProtocol.FZZY_V40_WHJL.getName()));
        list.add(new ApiTrigger(SyncProtocol.FZZY_V35_SHYZ.getCode(), SyncProtocol.FZZY_V35_SHYZ.getName()));
        return list;
        return SyncProtocol.listTrigger();
    }
    /**
@@ -223,12 +199,7 @@
     */
    @DataProvider
    public List<ApiTrigger> triggerGatewayProtocol() {
        List<ApiTrigger> list = new ArrayList<>();
        list.add(new ApiTrigger(GatewayProtocol.GATE_HTTP.getCode(), GatewayProtocol.GATE_HTTP.getName()));
        list.add(new ApiTrigger(GatewayProtocol.GATE_MQTT.getCode(), GatewayProtocol.GATE_MQTT.getName()));
        list.add(new ApiTrigger(GatewayProtocol.GATE_WEBSOCKET.getCode(), GatewayProtocol.GATE_WEBSOCKET.getName()));
        list.add(new ApiTrigger(GatewayProtocol.GATE_TEST.getName(), GatewayProtocol.GATE_TEST.getName()));
        return list;
        return GatewayProtocol.listTrigger();
    }
    /**
@@ -239,16 +210,18 @@
     */
    @DataProvider
    public List<ApiTrigger> triggerGatewayDeviceProtocol() {
        List<ApiTrigger> list = new ArrayList<>();
        list.add(new ApiTrigger(GatewayDeviceProtocol.GRAIN_FZZY_ZH_2023.getCode(), GatewayDeviceProtocol.GRAIN_FZZY_ZH_2023.getName()));
        return GatewayDeviceProtocol.listTrigger();
    }
        list.add(new ApiTrigger(GatewayDeviceProtocol.DEVICE_WEIGHT_HTTP.getCode(), GatewayDeviceProtocol.DEVICE_WEIGHT_HTTP.getName()));
        list.add(new ApiTrigger(GatewayDeviceProtocol.DEVICE_IDCARD_HTTP.getCode(), GatewayDeviceProtocol.DEVICE_IDCARD_HTTP.getName()));
        list.add(new ApiTrigger(GatewayDeviceProtocol.DEVICE_LED_HTTP.getCode(), GatewayDeviceProtocol.DEVICE_LED_HTTP.getName()));
        list.add(new ApiTrigger(GatewayDeviceProtocol.DEVICE_LPR_HTTP.getCode(), GatewayDeviceProtocol.DEVICE_LPR_HTTP.getName()));
        list.add(new ApiTrigger(GatewayDeviceProtocol.DEVICE_TEST.getCode(), GatewayDeviceProtocol.DEVICE_TEST.getName()));
        return list;
    /**
     * ${dorado.getDataProvider("apiTriggerService#triggerGatewayDeviceType").getResult()}
     * ç³»ç»Ÿä¸Žç½‘关直接的通讯协议
     *
     * @return
     */
    @DataProvider
    public List<ApiTrigger> triggerGatewayDeviceType() {
        return GatewayDeviceType.listTrigger();
    }
src/main/java/com/fzzy/api/utils/BytesUtil.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,404 @@
package com.fzzy.api.utils;
import java.math.BigInteger;
public class BytesUtil {
    /**
     * bytes输出十进制
     *
     * @param bytes
     * @return
     */
    public static Integer bytesToInt(byte[] bytes) {
        String str = "";
        int i = 0;
        boolean flag = true && bytes.length > 0;
        while (flag) {
            Byte b = bytes[i];
            i++;
            Integer bi = Byte.toUnsignedInt(b);
            str += toHexString(bi);
            if (i >= bytes.length || str.endsWith("EEEE"))
                flag = false;
        }
        return Integer.parseInt(str, 16);
    }
    /**
     * bytes输出十六进制字符串
     *
     * @param bytes
     * @return
     */
    public static String bytesToString(byte[] bytes) {
        String str = "";
        int i = 0;
        boolean flag = true && bytes.length > 0;
        while (flag) {
            Byte b = bytes[i];
            i++;
            Integer bi = Byte.toUnsignedInt(b);
            str += toHexString(bi);
            if (i >= bytes.length)
                flag = false;
        }
        return str;
    }
    /**
     * åå…­è¿›åˆ¶è½¬å­—节
     *
     * @param hex
     * @return
     */
    public static byte hexToByte(Integer hex) {
        return hex.byteValue();
    }
    /**
     * short转2字节 å·²è°ƒæ•´é«˜ä½Žä½
     *
     * @param number
     * @return
     */
    public static byte[] shortToByte(short number) {
        int temp = number;
        byte[] b = new byte[2];
        for (int i = 0; i < b.length; i++) {
            b[i] = new Integer(temp & 0xff).byteValue();// å°†æœ€ä½Žä½ä¿å­˜åœ¨æœ€ä½Žä½
            temp = temp >> 8; // å‘右移8位
        }
        return b;
    }
    /**
     * äºŒè¿›åˆ¶å­ä¸²è½¬16进制子串
     *
     * @param bin
     * @return
     */
    public static String binToHex(String bin) {
        String hexStr = "";
        int size = bin.length() / 8;
        for (int i = 0; i < size; i++) {
            String value = bin.substring(i * 8, (i + 1) * 8);
            int temp = Integer.parseInt(value, 2);
            String tempHex = Integer.toHexString(temp);
            hexStr += tempHex;
        }
        return hexStr;
    }
    /**
     * äºŒè¿›åˆ¶è½¬16进制,不足2位补位
     *
     * @param bin
     * @return
     */
    public static String bin2Hex(String bin) {
        String hexStr = "";
        int size = bin.length() / 8;
        for (int i = 0; i < size; i++) {
            String value = bin.substring(i * 8, (i + 1) * 8);
            int temp = Integer.parseInt(value, 2);
            String tempHex = Integer.toHexString(temp);
            if (tempHex.length() < 2) {
                tempHex = "0" + tempHex;
            }
            hexStr += tempHex;
        }
        return hexStr;
    }
    /**
     * è½¬ä¸ºåå…­è¿›åˆ¶ä¸²ï¼Œä¸è¶³2位补0
     *
     * @param value
     * @return
     */
    public static String toHexString(int value) {
        String tempHex = Integer.toHexString(value);
        if (tempHex.length() < 2) {
            tempHex = "0" + tempHex;
        }
        return tempHex.toUpperCase();
    }
    public static String getTargetId(String value, boolean isTwo) {
        String tempHex = Integer.toHexString(Integer.valueOf(value));
        if (tempHex.length() < 2) {
            tempHex = "0" + tempHex;
        }
        if (isTwo) {
            if (tempHex.length() < 4) {
                tempHex = "0" + tempHex;
            }
            if (tempHex.length() < 4) {
                tempHex = "0" + tempHex;
            }
        }
        return tempHex.toUpperCase();
    }
    /**
     * æ ¹æ®æ•°å€¼èŽ·å–åˆ°é•¿åº¦ä¸º2字节的16进制字符
     *
     * @param value
     * @return
     */
    public static String getHex2LenStr(int value) {
        String tempHex = Integer.toHexString(value);
        if (tempHex.length() < 2) {
            tempHex = "0" + tempHex;
        }
        if (tempHex.length() < 4) {
            tempHex = "0" + tempHex;
        }
        if (tempHex.length() < 4) {
            tempHex = "0" + tempHex;
        }
        return tempHex.toUpperCase();
    }
    public static String getOrderId(int value) {
        return getHex2LenStr(value);
    }
    /**
     * å°†value转为same个相同满8位的二进制字串
     *
     * @param value
     * @param same
     * @return
     */
    public static String toBinary8StringSame(int value, int same) {
        String tempBinStr = toBinary8String(value);
        String rsBinStr = "";
        for (int i = 0; i < same; i++) {
            rsBinStr += tempBinStr;
        }
        return rsBinStr;
    }
    /**
     * ä¸è¶³width个字节宽度时,前面补0至width*8
     *
     * @param value
     * @param width
     * @return
     */
    public static String toBinary8String(int value, int width) {
        String tempBinStr = toBinary8String(value);
        int size = tempBinStr.length();
        for (int i = 0; i < width; i++) {
            int temp = (i + 1) * 8;
            if (temp > size) {
                tempBinStr = "00000000" + tempBinStr;
                size = tempBinStr.length();
            }
        }
        return tempBinStr;
    }
    /**
     * è¡¥è¶³8位
     *
     * @param value
     * @return
     */
    public static String toBinary8String(int value) {
        String temp = Integer.toBinaryString(value);
        if (value == 0) {
            temp = "00000000";
        }
        int length = temp.length();
        while (length < 8) {
            temp = "0" + temp;
            length = temp.length();
        }
        return temp;
    }
    public static String toEmptyBinaryWidthString(int width) {
        String str = "";
        for (int i = 0; i < width; i++) {
            str += "00000000";
        }
        return str;
    }
    public static byte[] emptyBytes(int bytes) {
        byte[] bys = new byte[bytes];
        for (int i = 0; i < bytes; i++) {
            bys[i] = emptyByte();
        }
        return bys;
    }
    public static byte emptyByte() {
        Integer b0 = 0x00;
        return b0.byteValue();
    }
    public static byte binToBytes(String bin) {
        return Integer.valueOf(bin, 2).byteValue();
    }
    public static byte[] binaryStrToBytes(String binStr) {
        int size = binStr.length() / 8;
        byte[] bs = new byte[size];
        for (int i = 0; i < size; i++) {
            String temp = binStr.substring(i * 8, (i + 1) * 8);
            bs[i] = Integer.valueOf(temp, 2).byteValue();
        }
        return bs;
    }
    /**
     * åå…­è¿›åˆ¶ä¸²è½¬å­—节数组
     *
     * @param hexStr
     * @return
     */
    public static byte[] hexStrToBytes(String hexStr) {
        int size = hexStr.length() / 2;
        byte[] bytes = new byte[size];
        for (int i = 0; i < size; i++) {
            String tmp = hexStr.substring(i * 2, (i + 1) * 2);
            Integer tmpHex = Integer.parseInt(tmp, 16);
            bytes[i] = tmpHex.byteValue();
        }
        return bytes;
    }
    /**
     * ä¸¤å­—节高低位装换
     *
     * @param b
     * @return
     */
    public static byte[] hexHeightLow(byte[] b) {
        byte[] b2 = new byte[2];
        // è½¬æ¢é«˜ä½Žä½
        b2[0] = b[1];
        b2[1] = b[0];
        return b2;
    }
    /**
     * 16进制转换为10进制
     *
     * @param strHex
     * @return
     */
    public static int hexToInt(String strHex) {
        short s = (short) (Integer.valueOf(strHex, 16) & 0xffff);
        return s;
    }
    /**
     * 16进制转换为10进制
     *
     * @param strHex
     * @return
     */
    public static int hexToBigInt(String strHex) {
        BigInteger bigint = new BigInteger(strHex, 16);
        return bigint.intValue();
    }
    /**
     * int转16进制字符串 2位 00 00
     *
     * @param num
     * @return
     */
    public static String intToHexStr(int num) {
        // éœ€è¦ä½¿ç”¨2字节表示b
        return String.format("%04x", num).toUpperCase();
    }
    // è®¡ç®—16进制对应的数值
    public static int GetHex(char ch) throws Exception {
        if (ch >= '0' && ch <= '9')
            return (int) (ch - '0');
        if (ch >= 'a' && ch <= 'f')
            return (int) (ch - 'a' + 10);
        if (ch >= 'A' && ch <= 'F')
            return (int) (ch - 'A' + 10);
        throw new Exception("error param");
    }
    // è®¡ç®—幂
    public static int GetPower(int nValue, int nCount) throws Exception {
        if (nCount < 0)
            throw new Exception("nCount can't small than 1!");
        if (nCount == 0)
            return 1;
        int nSum = 1;
        for (int i = 0; i < nCount; ++i) {
            nSum = nSum * nValue;
        }
        return nSum;
    }
    public static void main(String[] args) {
        double d1 = hexToBigInt("000906EB")/100.0;
        double d2 = hexToBigInt("0004F6E6")/100.0;
        System.out.println(d1);
        System.out.println(d2);
        System.out.println(d1 + d2);
    }
    /**
     * 16进制字符串 é«˜ä½Žæ¢ä½
     *
     * @param info
     * @return
     */
    public static String tran_LH(String info) {
        return info.substring(2) + info.substring(0, 2);
    }
    /**
     * 16进制字符串 é«˜ä½Žæ¢ä½ 8个字符
     *
     * @param info
     * @return
     */
    public static String tran_LH8(String info) {
        return tran_LH(info.substring(4)) + tran_LH(info.substring(0, 4));
    }
    /**
     * å°† 4字节的16进制字符串,转换为32位带符号的十进制浮点型
     *
     * 42c60000 -> 99.00
     *
     * @param str
     *            4字节 16进制字符
     * @return
     */
    public static float hexToFloat(String str) {
        return Float.intBitsToFloat(new BigInteger(str, 16).intValue());
    }
    /**
     * å°†å¸¦ç¬¦å·çš„32位浮点数装换为16进制
     *
     * 99.00 -> 42c60000
     *
     *
     * @param value
     * @return
     */
    public static String folatToHexString(Float value) {
        return Integer.toHexString(Float.floatToIntBits(value));
    }
}
src/main/java/com/fzzy/api/utils/ContextUtil.java
@@ -136,4 +136,15 @@
            return null;
        }
    }
    /**
     * ç”ŸæˆTCP连接的KEY
     *
     * @param ip
     * @param port
     * @return
     */
    public static String getServerKey(String ip, Integer port) {
        return ip + ":" + port;
    }
}
src/main/java/com/fzzy/api/utils/SpringUtil.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,58 @@
package com.fzzy.api.utils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class SpringUtil implements ApplicationContextAware {
    private static ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if (SpringUtil.applicationContext == null) {
            SpringUtil.applicationContext = applicationContext;
        }
    }
    /**
     * èŽ·å–applicationContext
     * @return
     */
    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }
    /**
     * é€šè¿‡name获取 Bean.
     * @param name
     * @return
     */
    public static Object getBean(String name) {
        return getApplicationContext().getBean(name);
    }
    /**
     * é€šè¿‡class获取Bean.
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> T getBean(Class<T> clazz) {
        return getApplicationContext().getBean(clazz);
    }
    /**
     * é€šè¿‡name,以及Clazz返回指定的Bean
     * @param name
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> T getBean(String name, Class<T> clazz) {
        return getApplicationContext().getBean(name, clazz);
    }
}
src/main/java/com/fzzy/gateway/GatewayRunner.java
@@ -27,7 +27,6 @@
        //四川网关接口,启动默认获取鉴权信息,长期有效
        apiInitService.init();
    }
}
src/main/java/com/fzzy/gateway/GatewayUtils.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,66 @@
package com.fzzy.gateway;
import com.fzzy.gateway.entity.GatewayDevice;
import java.util.HashMap;
import java.util.Map;
/**
 * å¸¸é‡
 */
public class GatewayUtils {
    /**
     * è®¾å¤‡åœ¨çº¿æ ‡è®°ï¼Œé’ˆå¯¹WEBSocket请求,控制设备是否在线,key = deviceId,Value=Y/N
     */
    public static Map<String, String> contextOnlineMap = new HashMap<>();
    /**
     * è®¾å¤‡ç¼“å­˜
     */
    public static Map<String, GatewayDevice> cacheMapDeviceId = new HashMap<>();
    /**
     * è®¾å¤‡ç¼“å­˜
     */
    public static Map<String, GatewayDevice> cacheMapDeviceSn = new HashMap<>();
    public static void add2Cache(GatewayDevice device) {
        cacheMapDeviceId.put(device.getDeviceId(), device);
        cacheMapDeviceSn.put(device.getDeviceSn(), device);
    }
    public static GatewayDevice getCacheByDeviceId(String deviceId) {
        return cacheMapDeviceId.get(deviceId);
    }
    public static GatewayDevice getCacheByDeviceSn(String deviceSn) {
        return cacheMapDeviceSn.get(deviceSn);
    }
    public static void removeCache(GatewayDevice data) {
        cacheMapDeviceId.remove(data.getDeviceId());
        cacheMapDeviceSn.remove(data.getDeviceSn());
    }
    public static void updateOnline(String deviceId) {
        contextOnlineMap.put(deviceId, "Y");
    }
    public static void updateOffOnline(String deviceId) {
        contextOnlineMap.put(deviceId, "N");
    }
    public static boolean isOnline(String deviceId) {
        String value = contextOnlineMap.get(deviceId);
        if (null == value || "N".equals(value)) return false;
        return true;
    }
}
src/main/java/com/fzzy/gateway/api/DeviceReportService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,24 @@
package com.fzzy.gateway.api;
import com.fzzy.gateway.entity.GatewayDevice;
public interface DeviceReportService {
    /**
     * åè®®å®šä¹‰
     *
     * @return
     */
    String getProvinceProtocol();
    /**
     * é€šè¿‡è®¾å¤‡åºåˆ—号返回结果信息
     *
     * @param weigh
     * @param device è®¾å¤‡åºåˆ—号
     */
    String report2GatewayBySn(double weigh, GatewayDevice device);
}
src/main/java/com/fzzy/gateway/api/GatewayRemoteManager.java
@@ -17,6 +17,8 @@
    public static Map<String, GatewayRemoteService> remoteMap = new HashMap<>();
    public static Map<String, DeviceReportService> reportMap = new HashMap<>();
    public static Map<String, GatewaySyncGranService> syncGrain = new HashMap<>();
    public static Map<String, GatewaySyncIdCardService> syncIdCard = new HashMap<>();
@@ -58,6 +60,11 @@
        Map<String, GatewaySyncWeightService> serviceMap6 = applicationContext.getBeansOfType(GatewaySyncWeightService.class);
        for (String key : serviceMap6.keySet()) {
            syncWeight.put(serviceMap6.get(key).getWeightProtocol(), serviceMap6.get(key));
        }
        Map<String, DeviceReportService> serviceMap7 = applicationContext.getBeansOfType(DeviceReportService.class);
        for (String key : serviceMap7.keySet()) {
            reportMap.put(serviceMap7.get(key).getProvinceProtocol(), serviceMap7.get(key));
        }
    }
@@ -123,4 +130,14 @@
        return syncWeight.get(protocol);
    }
    /**
     * æ ¹æ®å®žçŽ°åè®®èŽ·å–å½“å‰å®žçŽ°æ–¹æ³•
     *
     * @param protocol
     * @return
     */
    public DeviceReportService getDeviceReportService(String protocol) {
        return reportMap.get(protocol);
    }
}
src/main/java/com/fzzy/gateway/api/GatewaySyncWeightService.java
@@ -22,5 +22,4 @@
     * @return
     */
    public WeightInfo syncWeightInfo(SyncReqData reqData);
}
src/main/java/com/fzzy/gateway/entity/GatewayDevice.java
@@ -1,9 +1,11 @@
package com.fzzy.gateway.entity;
import com.bstek.dorado.annotation.PropertyDef;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;
/**
@@ -27,7 +29,7 @@
    @PropertyDef(label = "设备序列号")
    private String deviceSn;
    @Column(name = "DEVICE_ID_", length = 100)
    @Column(name = "DEVICE_ID_", length = 50)
    @PropertyDef(label = "设备ID")
    private String deviceId;
@@ -55,6 +57,14 @@
    @PropertyDef(label = "通讯端口")
    private Integer port;
    
    @PropertyDef(label = "设备用户名")
    @Column(name = "username", length = 50)
    private String userName;
    @PropertyDef(label = "设备密码")
    @Column(name = "password", length = 50)
    private String password;
    @Column(name = "RTSP_", length = 100)
    @PropertyDef(label = "视频RTSP", description = "用于局域网内抓拍配置")
    private String rtsp;
@@ -67,6 +77,10 @@
    @Column(name = "PUSH_PROTOCOL_", length = 20)
    private String pushProtocol;
    @PropertyDef(label = "省平台协议")
    @Column(name = "PROVINCE_PROTOCOL_", length = 20)
    private String provinceProtocol;
    @PropertyDef(label = "同步协议")
    @Column(name = "SYNC_PROTOCOL_", length = 20)
    private String syncProtocol;
src/main/java/com/fzzy/gateway/hx2023/ScConstant.java
@@ -1,8 +1,5 @@
package com.fzzy.gateway.hx2023;
import java.util.HashMap;
import java.util.Map;
/**
 * å¸¸é‡
 */
@@ -10,26 +7,6 @@
    public static String API_URL_AUTH = "${auth}/authorize/login";
    /**
     * è®¾å¤‡åœ¨çº¿æ ‡è®°ï¼Œé’ˆå¯¹WEBSocket请求,控制设备是否在线,key = deviceId,Value=Y/N
     */
    public static Map<String, String> contextOnlineMap = new HashMap<>();
    public static void updateOnline(String deviceId) {
        contextOnlineMap.put(deviceId, "Y");
    }
    public static void updateOffOnline(String deviceId) {
        contextOnlineMap.put(deviceId, "N");
    }
    public static boolean isOnline(String deviceId) {
        String value = contextOnlineMap.get(deviceId);
        if (null == value || "N".equals(value)) return false;
        return true;
    }
}
src/main/java/com/fzzy/gateway/hx2023/data/WebSocketPacketHeader.java
@@ -8,13 +8,11 @@
    private String productId;
    private String keepOnlineTimeoutSeconds;
    private int keepOnlineTimeoutSeconds = 600 ;
    private String keepOnline;
    private boolean keepOnline = true;
    private String deviceName;
    private String orgId;
}
src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,56 @@
package com.fzzy.gateway.hx2023.service;
import com.fzzy.api.data.GatewayProtocol;
import com.fzzy.api.data.PushProtocol;
import com.fzzy.gateway.api.DeviceReportService;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.hx2023.data.WebSocketPacket;
import com.fzzy.gateway.hx2023.data.WebSocketPacketHeader;
import com.fzzy.gateway.hx2023.websocket.WebSocketDeviceReport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Slf4j
@Component
public class DeviceReportServiceImpl implements DeviceReportService {
    @Resource
    private WebSocketDeviceReport webSocketDeviceReport;
    @Override
    public String getProvinceProtocol() {
        return PushProtocol.GATEWAY_SC_2023.getCode();
    }
    @Override
    public String report2GatewayBySn(double weigh, GatewayDevice device) {
        if (null == device) {
            log.error("-----------没有获取到设备配置信息-----");
            return "ERROR:没有获取到设备配置信息";
        }
        //使用WEBSOCKET返回
        if (GatewayProtocol.GATE_WEBSOCKET.equals(device.getPushProtocol())) {
            WebSocketPacket packet = new WebSocketPacket();
            WebSocketPacketHeader header = new WebSocketPacketHeader();
            header.setDeviceName(device.getDeviceName());
            packet.setHeaders(header);
            packet.setMessageType("");
            packet.setDeviceId(device.getDeviceId());
            packet.setProperties(null);
            packet.setTimestamp(System.currentTimeMillis());
            webSocketDeviceReport.sendByPacket(packet);
        }
        return null;
    }
}
src/main/java/com/fzzy/gateway/hx2023/service/HxGatewaySyncWeightImpl1.java
@@ -1,14 +1,18 @@
package com.fzzy.gateway.hx2023.service;
import com.fzzy.api.data.GatewayDeviceProtocol;
import com.fzzy.gateway.api.GatewaySyncLprService;
import com.fzzy.api.data.GatewayProtocol;
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.gateway.api.GatewaySyncWeightService;
import com.fzzy.gateway.hx2023.data.LprData;
import com.fzzy.gateway.hx2023.data.SyncReqData;
import com.fzzy.gateway.hx2023.data.WeightInfo;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.hx2023.data.*;
import com.fzzy.gateway.hx2023.websocket.WebSocketDeviceReport;
import com.fzzy.gateway.service.GatewayDeviceService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
 * ç½‘关与设备之间的通讯
@@ -19,6 +23,12 @@
public class HxGatewaySyncWeightImpl1 implements GatewaySyncWeightService {
    @Resource
    private GatewayDeviceService deviceService;
    @Resource
    private WebSocketDeviceReport webSocketDeviceReport;
    @Override
    public String getWeightProtocol() {
        return GatewayDeviceProtocol.DEVICE_WEIGHT_TCP_YH.getCode();
@@ -27,6 +37,7 @@
    @Override
    public WeightInfo syncWeightInfo(SyncReqData reqData) {
        //doNothing
        return null;
    }
src/main/java/com/fzzy/gateway/hx2023/websocket/WebSocketDeviceLed.java
@@ -1,7 +1,7 @@
package com.fzzy.gateway.hx2023.websocket;
import com.alibaba.fastjson.JSONObject;
import com.fzzy.gateway.hx2023.ScConstant;
import com.fzzy.gateway.GatewayUtils;
import com.fzzy.gateway.hx2023.data.WebSocketPacket;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
@@ -42,7 +42,7 @@
        sessionPool.put(key, session);
        sessionIds.put(session.getId(), key);
        ScConstant.updateOnline(deviceId);
        GatewayUtils.updateOnline(deviceId);
        log.info("new webSocket,clientId={}", key);
    }
@@ -57,7 +57,7 @@
        String deviceId = key.substring(0, key.indexOf("-"));
        ScConstant.updateOffOnline(deviceId);
        GatewayUtils.updateOffOnline(deviceId);
        log.info("WebSocket连接关闭={}", key);
@@ -84,7 +84,7 @@
        String deviceId = key.substring(0, key.indexOf("-"));
        ScConstant.updateOffOnline(deviceId);
        GatewayUtils.updateOffOnline(deviceId);
        sessionPool.remove(key);
        sessionIds.remove(session.getId());
src/main/java/com/fzzy/gateway/hx2023/websocket/WebSocketDeviceReport.java
ÎļþÃû´Ó src/main/java/com/fzzy/gateway/hx2023/websocket/WebSocketDevice.java ÐÞ¸Ä
@@ -1,6 +1,7 @@
package com.fzzy.gateway.hx2023.websocket;
import com.alibaba.fastjson.JSONObject;
import com.fzzy.gateway.GatewayUtils;
import com.fzzy.gateway.hx2023.ScConstant;
import com.fzzy.gateway.hx2023.data.WebSocketPacket;
import lombok.extern.slf4j.Slf4j;
@@ -19,7 +20,7 @@
@Slf4j
@Component
@ServerEndpoint(value = "/device/{productId}/{deviceId}/message/property/report")
public class WebSocketDevice {
public class WebSocketDeviceReport {
    private static Map<String, Session> sessionPool = new ConcurrentHashMap<>();
    private static Map<String, String> sessionIds = new ConcurrentHashMap<>();
@@ -42,7 +43,7 @@
        sessionPool.put(key, session);
        sessionIds.put(session.getId(), key);
        ScConstant.updateOnline(deviceId);
        GatewayUtils.updateOnline(deviceId);
        log.info("new webSocket,clientId={}", key);
    }
@@ -52,9 +53,9 @@
        String key = sessionIds.get(session.getId());
        String deviceId = key.substring(0, key.indexOf("-"));
        String deviceId = key.substring(key.indexOf("-"));
        ScConstant.updateOffOnline(deviceId);
        GatewayUtils.updateOffOnline(deviceId);
        sessionPool.remove(key);
        sessionIds.remove(session.getId());
@@ -81,9 +82,9 @@
        String key = sessionIds.get(session.getId());
        String deviceId = key.substring(0, key.indexOf("-"));
        String deviceId = key.substring(key.indexOf("-"));
        ScConstant.updateOffOnline(deviceId);
        GatewayUtils.updateOffOnline(deviceId);
        sessionPool.remove(key);
        sessionIds.remove(session.getId());
@@ -96,17 +97,24 @@
     *
     * @param packet
     */
    public static void sendByPacket(WebSocketPacket packet) {
    public void sendByPacket(WebSocketPacket packet) {
        if (StringUtils.isEmpty(packet.getDeviceId())) {
            log.error("WebSocket信息推送失败,设备编码为空。");
            return;
        }
        String tag = packet.getDeviceId();
        // éåŽ†æŽ¨é€
        Session session;
        String productId;
        for (String key : sessionPool.keySet()) {
            productId = key.substring(0, key.indexOf("-"));
            packet.getHeaders().setProductId(productId);
            if (key.indexOf(tag) != -1) {
                session = sessionPool.get(key);
                session.getAsyncRemote().sendText(
src/main/java/com/fzzy/gateway/service/GatewayDeviceService.java
@@ -6,22 +6,22 @@
import com.fzzy.api.utils.ContextUtil;
import com.fzzy.api.utils.RedisConst;
import com.fzzy.api.utils.RedisUtil;
import com.fzzy.gateway.GatewayUtils;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.service.repository.GatewayDeviceRep;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
public class GatewayDeviceService {
    @Resource
    private GatewayDeviceRep gatewayDeviceRep;
    @Resource
    private RedisUtil redisUtil;
    /**
     * gatewayDeviceService#listAll
@@ -30,10 +30,7 @@
     */
    @DataProvider
    public List<GatewayDevice> listAll() {
        List<GatewayDevice> list = gatewayDeviceRep.findAll();
        return list;
        return gatewayDeviceRep.findAll();
    }
    /**
@@ -48,6 +45,15 @@
        if (null == data.getId()) {
            data.setId(ContextUtil.getUUID());
        }
        if (null == data.getDeviceSn()) {
            if (null != entity.getIp()) {
                data.setDeviceSn(entity.getIp());
            } else {
                data.setDeviceSn(data.getDeviceId());
            }
        }
        gatewayDeviceRep.save(data);
@@ -66,6 +72,8 @@
        BeanUtils.copyProperties(data, data2);
        gatewayDeviceRep.delete(data2);
        GatewayUtils.removeCache(data2);
        flushCache();
        return null;
    }
@@ -78,23 +86,8 @@
    public void flushCache() {
        List<GatewayDevice> list = listAll();
        if (null == list || list.isEmpty()) return;
        String key;
        for (GatewayDevice device : list) {
            key = RedisConst.buildKey(RedisConst.KYE_GATE_DEVICE, device.getDeviceId());
            redisUtil.set(key, device);
            GatewayUtils.add2Cache(device);
        }
    }
    /**
     * ç¼“存获取设备信息
     *
     * @param deviceId
     * @return
     */
    public GatewayDevice getCacheDevice(String deviceId) {
        String key = RedisConst.buildKey(RedisConst.KYE_GATE_DEVICE, deviceId);
        return (GatewayDevice) redisUtil.get(key);
    }
}
src/main/java/com/fzzy/gateway/view/GatewayConf.view.xml
@@ -16,31 +16,39 @@
        <Property name="required">true</Property>
      </PropertyDef>
      <PropertyDef name="appId">
        <Property/>
        <Property></Property>
        <Property name="label">appId</Property>
      </PropertyDef>
      <PropertyDef name="gatewayId">
        <Property/>
        <Property></Property>
        <Property name="label">网关ID</Property>
      </PropertyDef>
      <PropertyDef name="gatewayIp">
      <PropertyDef name="gatewayUsername">
        <Property/>
        <Property name="label">网关用户名</Property>
      </PropertyDef>
      <PropertyDef name="gatewayPassword">
        <Property/>
        <Property name="label">网关密码</Property>
      </PropertyDef>
      <PropertyDef name="gatewayIp">
        <Property></Property>
        <Property name="label">网关IP</Property>
      </PropertyDef>
      <PropertyDef name="gatewayMac">
        <Property/>
        <Property></Property>
        <Property name="label">网关Mac</Property>
      </PropertyDef>
      <PropertyDef name="gatewayCPU">
        <Property/>
        <Property></Property>
        <Property name="label">网关CPU</Property>
      </PropertyDef>
      <PropertyDef name="gatewayMem">
        <Property/>
        <Property></Property>
        <Property name="label">网关内存</Property>
      </PropertyDef>
      <PropertyDef name="gatewayHardDisk">
        <Property/>
        <Property></Property>
        <Property name="label">网关硬盘</Property>
      </PropertyDef>
      <PropertyDef name="userName">
@@ -216,6 +224,17 @@
              <Editor/>
            </AutoFormElement>
            <AutoFormElement>
              <Property name="name">gatewayUsername</Property>
              <Property name="property">gatewayUsername</Property>
              <Editor/>
            </AutoFormElement>
            <AutoFormElement>
              <Property name="name">gatewayPassword</Property>
              <Property name="property">gatewayPassword</Property>
              <Property name="editorType">PasswordEditor</Property>
              <Editor/>
            </AutoFormElement>
            <AutoFormElement>
              <Property name="name">gatewayIp</Property>
              <Property name="property">gatewayIp</Property>
              <Editor/>
src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml
@@ -22,14 +22,15 @@
      <PropertyDef name="type">
        <Property></Property>
        <Property name="label">设备类型</Property>
        <Property name="mapping">
          <Property name="keyProperty">code</Property>
          <Property name="valueProperty">name</Property>
          <Property name="mapValues">${dorado.getDataProvider(&quot;apiTriggerService#triggerGatewayDeviceType&quot;).getResult()}</Property>
        </Property>
      </PropertyDef>
      <PropertyDef name="depotId">
        <Property></Property>
        <Property name="label">所属仓库</Property>
      </PropertyDef>
      <PropertyDef name="depotName">
        <Property></Property>
        <Property name="label">所属仓库</Property>
        <Property name="label">所属仓库编码</Property>
      </PropertyDef>
      <PropertyDef name="ip">
        <Property></Property>
@@ -43,6 +44,16 @@
        <Property></Property>
        <Property name="label">视频RTSP</Property>
      </PropertyDef>
      <PropertyDef name="provinceProtocol">
        <Property/>
        <Property name="label">省平台协议</Property>
        <Property name="mapping">
          <Property name="mapValues">${dorado.getDataProvider(&quot;apiTriggerService#triggerPushProtocol&quot;).getResult()}</Property>
          <Property name="keyProperty">code</Property>
          <Property name="valueProperty">name</Property>
        </Property>
        <Property name="required">true</Property>
      </PropertyDef>
      <PropertyDef name="pushProtocol">
        <Property></Property>
        <Property name="label">系统网关通讯协议</Property>
@@ -55,7 +66,7 @@
      </PropertyDef>
      <PropertyDef name="syncProtocol">
        <Property></Property>
        <Property name="label">网关与设备通讯协议</Property>
        <Property name="label">网关设备通讯协议</Property>
        <Property name="mapping">
          <Property name="keyProperty">code</Property>
          <Property name="valueProperty">name</Property>
@@ -76,8 +87,24 @@
        <Property name="label">HTTP地址</Property>
      </PropertyDef>
      <PropertyDef name="deviceSn">
        <Property/>
        <Property></Property>
        <Property name="label">设备序列号</Property>
      </PropertyDef>
      <PropertyDef name="serPort">
        <Property name="dataType">int</Property>
        <Property name="label">TCP服务端口</Property>
      </PropertyDef>
      <PropertyDef name="userName">
        <Property/>
        <Property name="label">设备用户名</Property>
      </PropertyDef>
      <PropertyDef name="password">
        <Property/>
        <Property name="label">设备密码</Property>
      </PropertyDef>
      <PropertyDef name="depotName">
        <Property/>
        <Property name="label">所属仓库</Property>
      </PropertyDef>
    </DataType>
  </Model>
@@ -150,9 +177,6 @@
      <DataColumn name="type">
        <Property name="property">type</Property>
      </DataColumn>
      <DataColumn name="depotName">
        <Property name="property">depotName</Property>
      </DataColumn>
      <DataColumn name="syncProtocol">
        <Property name="property">syncProtocol</Property>
      </DataColumn>
@@ -192,13 +216,18 @@
          <AutoForm>
            <Property name="dataSet">dsMain</Property>
            <Property name="cols">*,*,*</Property>
            <Property name="labelWidth">100</Property>
            <Property name="labelWidth">125</Property>
            <Property name="labelAlign">right</Property>
            <Property name="labelSeparator">:</Property>
            <Property name="labelPosition">left</Property>
            <AutoFormElement>
            <AutoFormElement layoutConstraint="colSpan:2">
              <Property name="name">deviceId</Property>
              <Property name="property">deviceId</Property>
              <Editor/>
            </AutoFormElement>
            <AutoFormElement>
              <Property name="name">deviceSn</Property>
              <Property name="property">deviceSn</Property>
              <Editor/>
            </AutoFormElement>
            <AutoFormElement>
@@ -209,6 +238,11 @@
            <AutoFormElement>
              <Property name="name">type</Property>
              <Property name="property">type</Property>
              <Editor/>
            </AutoFormElement>
            <AutoFormElement>
              <Property name="name">orgId</Property>
              <Property name="property">orgId</Property>
              <Editor/>
            </AutoFormElement>
            <AutoFormElement>
@@ -227,18 +261,32 @@
              <Editor/>
            </AutoFormElement>
            <AutoFormElement>
              <Property name="name">userName</Property>
              <Property name="property">userName</Property>
              <Editor/>
            </AutoFormElement>
            <AutoFormElement>
              <Property name="name">password</Property>
              <Property name="property">password</Property>
              <Editor/>
            </AutoFormElement>
            <Control/>
            <AutoFormElement>
              <Property name="name">pushProtocol</Property>
              <Property name="property">pushProtocol</Property>
              <Property name="labelWidth">150</Property>
              <Editor/>
            </AutoFormElement>
            <AutoFormElement>
              <Property name="name">syncProtocol</Property>
              <Property name="property">syncProtocol</Property>
              <Property name="labelWidth">150</Property>
              <Editor/>
            </AutoFormElement>
            <AutoFormElement>
              <Property name="name">orgId</Property>
              <Property name="property">orgId</Property>
              <Property name="name">serPort</Property>
              <Property name="property">serPort</Property>
              <Property name="labelWidth">150</Property>
              <Editor/>
            </AutoFormElement>
            <AutoFormElement layoutConstraint="colSpan:2">
src/main/java/com/fzzy/protocol/package-info.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,4 @@
/**
 * ç³»ç»Ÿç›¸å…³åè®®
 */
package com.fzzy.protocol;
src/main/java/com/fzzy/protocol/weightyh/MessageConsumer.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,114 @@
package com.fzzy.protocol.weightyh;
import com.fzzy.api.utils.BytesUtil;
import com.fzzy.api.utils.SpringUtil;
import com.fzzy.gateway.GatewayUtils;
import com.fzzy.gateway.api.DeviceReportService;
import com.fzzy.gateway.api.GatewayRemoteManager;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.hx2023.service.HxGatewaySyncWeightImpl1;
import com.ld.io.api.IoMsgConsumer;
import com.ld.io.api.IoSession;
import lombok.extern.slf4j.Slf4j;
/**
 * åœ°ç£…信息推送
 *
 * @author: andy.jia
 * @description:
 * @version:
 * @data:2020å¹´3月19日
 */
@Slf4j
public class MessageConsumer implements IoMsgConsumer {
    private long timeTag = 0;
    private GatewayRemoteManager reportService;
    @Override
    public void consume(IoSession session, byte[] bytes) {
        analysisInfo(session.getAddress(), session.getPort(), bytes);
    }
    /**
     * 02 2B 30 30 31 31 38 30 30 31 33 03 02开始 03 ç»“束
     */
    public void analysisInfo(String ip, Integer port, byte[] bytes) {
        String strMsg = BytesUtil.bytesToString(bytes);
        //log.debug("开始解析地磅返回信息=" + strMsg);
        if (strMsg.length() < 22) {
            return;
        }
        // æ¯é—´éš”2.5执行一次
        if (System.currentTimeMillis() - timeTag <= 2500) {
            return;
        }
        timeTag = System.currentTimeMillis();
        String temp = strMsg.substring(2, 4);
        String symbol = HexASCIIToConvert(temp);
        temp = strMsg.substring(4, 16);
        String w = HexASCIIToConvert(temp);
        temp = strMsg.substring(16, 18);
        int d = getProduct(Integer.parseInt(HexASCIIToConvert(temp)));
        //最终重量结果
        double weigh = Double.valueOf(w) / d;
        log.debug("----------地磅称重数值解析------{}", weigh);
        //当前地磅协议不支持传递SN,使用局域网IP作为SN
        String sn = ip;
        //根据信息获取设备
        GatewayDevice device = GatewayUtils.getCacheByDeviceSn(sn);
        if (null == device) {
            log.error("----------没有获取到设备信息--------{}", sn);
            return;
        }
        //直接调用实现类,更多实现类单独调用
        if (null == reportService) {
            reportService = SpringUtil.getBean(GatewayRemoteManager.class);
        }
        reportService.getDeviceReportService(device.getProvinceProtocol()).report2GatewayBySn(weigh, device);
    }
    /**
     * æ ¹æ®å°æ•°ç‚¹ä½æ•°è®¡ç®—原数字需要除以多少
     *
     * @param i
     */
    private int getProduct(int i) {
        if (i == 0)
            return 1;
        int num = 1;
        for (int a = 0; a < i; a++) {
            num = num * 10;
        }
        return num;
    }
    private String HexASCIIToConvert(String value) {
        // String value = "30 30 31 31 38 30 30";
        StringBuffer sbu = new StringBuffer();
        char t = 0;
        int size = value.length() / 2;
        for (int i = 0; i < size; i++) {
            String tmp = value.substring(i * 2, (i + 1) * 2);
            t = (char) Integer.parseInt(""
                    + BytesUtil.bytesToInt(BytesUtil.hexStrToBytes(tmp)));
            sbu.append(t);
        }
        return sbu.toString();
    }
}
src/main/java/com/fzzy/protocol/weightyh/SessionListener.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,31 @@
package com.fzzy.protocol.weightyh;
import com.fzzy.api.utils.ContextUtil;
import com.ld.io.api.IoSession;
import com.ld.io.api.IoSessionListener;
import lombok.extern.slf4j.Slf4j;
/**
 * @author: andy.jia
 * @description:
 * @version:
 */
@Slf4j
public class SessionListener implements IoSessionListener {
    public static final String BEAN_ID = "yh.sessionListener";
    @Override
    public void onCreate(IoSession session) {
        // æ·»åŠ è‡ªå®šä¹‰ä¸šåŠ¡ID
        session.setBusinessKey(ContextUtil.getServerKey(session.getAddress(), session.getPort()));
        log.info("地磅成功连接,IP={},port={}", session.getAddress(), session.getPort());
    }
    @Override
    public void onDestroy(IoSession session) {
        log.info("地磅断开连接,IP={},port={}", session.getAddress(), session.getPort());
    }
}
src/main/java/com/fzzy/protocol/weightyh/YhScaleServerEngine.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,43 @@
package com.fzzy.protocol.weightyh;
import com.fzzy.api.utils.BytesUtil;
import com.ld.io.api.IoServerOption;
import com.ld.io.netty.NettyServer;
import lombok.extern.slf4j.Slf4j;
/**
 * åœ°ç£…服务启动
 *
 * @author: andy.jia
 * @description:
 * @version:
 */
@Slf4j
public class YhScaleServerEngine {
    public static final int port = 19090;
    public static NettyServer ioServer = null;
    // é…ç½®æ¶ˆæ¯æŽ¥æ”¶ç±»
    private static MessageConsumer messageConsume = new MessageConsumer();
    // ç›‘听会话的创建与销毁
    private static SessionListener ioSessionListener = new SessionListener();
    public static void start() throws InterruptedException {
        // é…ç½®Server的配置
        IoServerOption ioServerOption = new IoServerOption(port);
        // æ‹†åŒ…器配置
        //ioServerOption.setSplitDecoderType(SplitByteDecoderType.DELIMITER_SYMBOL);
        ioServerOption.setDelimiter(BytesUtil.hexStrToBytes("03"));
        ioServer = new NettyServer(ioServerOption, messageConsume, ioSessionListener);
        ioServer.startup();
        log.info("* ========================");
        log.info("* ");
        log.info("* åœ°ç£…-耀华品牌服务启动,端口号={}", YhScaleServerEngine.port);
        log.info("* ");
        log.info("* ========================");
    }
}