From 4806b676dbbab4675e5ee43b4018f2cd9d43797f Mon Sep 17 00:00:00 2001 From: ‘liusuyi’ <1951119284@qq.com> Date: 星期一, 23 十月 2023 17:15:09 +0800 Subject: [PATCH] 1. 将sdk动态链接库dll集成到项目内,提升部署便捷性; 2. 增加设备断线重连回调方法,打印相关日志; 3. 删除多余依赖,减小jar包体积; 4. 处理SDK日志打印; --- ard-work/src/main/java/com/ruoyi/device/dhsdk/lib/Utils.java | 420 ++++++++++++++++++++++++++++++------------------------------ 1 files changed, 210 insertions(+), 210 deletions(-) diff --git a/ard-work/src/main/java/com/ruoyi/device/dhsdk/lib/Utils.java b/ard-work/src/main/java/com/ruoyi/device/dhsdk/lib/Utils.java index b51d0c6..5b3bd0c 100644 --- a/ard-work/src/main/java/com/ruoyi/device/dhsdk/lib/Utils.java +++ b/ard-work/src/main/java/com/ruoyi/device/dhsdk/lib/Utils.java @@ -1,210 +1,210 @@ -package com.ruoyi.device.dhsdk.lib; - -import com.sun.jna.IntegerType; -import com.sun.jna.Native; -import com.sun.jna.Platform; -import com.sun.jna.Structure; - -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.List; - -public class Utils { - public Utils() { - - } - - /** - * 鑾峰彇绯荤粺瀵瑰簲鐨勭紪鐮� - * - */ - public static String getPlatformEncode() { - String encode = ""; - String osPrefix = getOsPrefix(); - if (osPrefix.toLowerCase().startsWith("win32")) { - encode = "GBK"; - } else if (osPrefix.toLowerCase().startsWith("linux")) { - encode = "UTF-8"; - }else if(osPrefix.toLowerCase().startsWith("mac")){ - encode="UTF-8"; - } - if(encode.isEmpty()){ - encode="UTF-8"; - } - return encode; - } - - // 鑾峰彇鎿嶄綔骞冲彴淇℃伅 - public static String getOsPrefix() { - String arch = System.getProperty("os.arch").toLowerCase(); - final String name = System.getProperty("os.name"); - String osPrefix; - switch (Platform.getOSType()) { - case Platform.WINDOWS: { - if ("i386".equals(arch)) - arch = "x86"; - osPrefix = "win32-" + arch; - } - break; - case Platform.LINUX: { - if ("x86".equals(arch)) { - arch = "i386"; - } else if ("x86_64".equals(arch)) { - arch = "amd64"; - } - osPrefix = "linux-" + arch; - } - break; - case Platform.MAC: { - //mac绯荤粺鐨刼s.arch閮芥槸ppc(鑰佺増鏈殑mac鏄痯owerpc锛屽凡缁忓熀鏈笉鐢�)鐪嬩笉鍑虹郴缁熶綅鏁帮紝浣跨敤涓嬮潰鐨勫弬鏁拌〃绀� - arch = System.getProperty("sun.arch.data.model"); - osPrefix = "mac-" + arch; - } - break; - default: { - osPrefix = name.toLowerCase(); - if ("x86".equals(arch)) { - arch = "i386"; - } - if ("x86_64".equals(arch)) { - arch = "amd64"; - } - int space = osPrefix.indexOf(" "); - if (space != -1) { - osPrefix = osPrefix.substring(0, space); - } - osPrefix += "-" + arch; - } - break; - - } - - return osPrefix; - } - - public static String getOsName() { - String osName = ""; - String osPrefix = getOsPrefix(); - if (osPrefix.toLowerCase().startsWith("win32-x86") - || osPrefix.toLowerCase().startsWith("win32-amd64")) { - osName = "win"; - } else if (osPrefix.toLowerCase().startsWith("linux-i386") - || osPrefix.toLowerCase().startsWith("linux-amd64")) { - osName = "linux"; - } else if (osPrefix.toLowerCase().startsWith("mac-64") - || osPrefix.toLowerCase().startsWith("mac-32")) { - osName = "mac"; - } - - return osName; - } - - // 鑾峰彇鍔犺浇搴� - public static String getLoadLibrary(String library) { - if (isChecking()) { - return null; - } - - String loadLibrary = ""; - String osPrefix = getOsPrefix(); - if (osPrefix.toLowerCase().startsWith("win32-x86")) { - loadLibrary = "./libs/win32/"; - } else if (osPrefix.toLowerCase().startsWith("win32-amd64")) { - loadLibrary = "./libs/win64/"; - } else if (osPrefix.toLowerCase().startsWith("linux-i386")) { - loadLibrary = ""; - } else if (osPrefix.toLowerCase().startsWith("linux-amd64")) { - loadLibrary = ""; - } else if (osPrefix.toLowerCase().startsWith("mac-64")) { - loadLibrary = ""; - } -// else if(osPrefix.toLowerCase().startsWith("mac-32")) { -// loadLibrary = ""; -// } 32浣峬ac鐗堟湰鍩烘湰娌′汉鐢ㄤ簡锛屾殏鏃朵笉鐢� - - System.out.printf("鍔犺浇搴揫%s]\n", loadLibrary + library); - return loadLibrary + library; - } - - private static boolean checking = false; - - public static void setChecking() { - checking = true; - } - - public static void clearChecking() { - checking = false; - } - - public static boolean isChecking() { - return checking; - } - - public static class LLong extends IntegerType { - private static final long serialVersionUID = 1L; - - /** - * Size of a native long, in bytes. - */ - public static int size; - - static { - size = Native.LONG_SIZE; - if (Utils.getOsPrefix().toLowerCase().equals("linux-amd64") - || Utils.getOsPrefix().toLowerCase().equals("win32-amd64") - || Utils.getOsPrefix().toLowerCase().equals("mac-64")) { - size = 8; - } else if (Utils.getOsPrefix().toLowerCase().equals("linux-i386") - || Utils.getOsPrefix().toLowerCase().equals("win32-x86")) { - size = 4; - } - } - - /** - * Create a zero-valued LLong. - */ - public LLong() { - this(0); - } - - /** - * Create a LLong with the given value. - */ - public LLong(long value) { - super(size, value); - } - } - - public static class SdkStructure extends Structure { - @Override - protected List<String> getFieldOrder() { - List<String> fieldOrderList = new ArrayList<String>(); - for (Class<?> cls = getClass(); - !cls.equals(NetSDKLib.SdkStructure.class); - cls = cls.getSuperclass()) { - Field[] fields = cls.getDeclaredFields(); - int modifiers; - for (Field field : fields) { - modifiers = field.getModifiers(); - if (Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) { - continue; - } - fieldOrderList.add(field.getName()); - } - } - // System.out.println(fieldOrderList); - - return fieldOrderList; - } - } - - // 鑾峰彇褰撳墠鏃堕棿 - public static String getDate() { - SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - return simpleDate.format(new java.util.Date()) - .replace(" ", "_").replace(":", "-"); - } - -} +package com.ruoyi.device.dhsdk.lib; + +import com.sun.jna.IntegerType; +import com.sun.jna.Native; +import com.sun.jna.Platform; +import com.sun.jna.Structure; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +public class Utils { + public Utils() { + + } + + /** + * 鑾峰彇绯荤粺瀵瑰簲鐨勭紪鐮� + * + */ + public static String getPlatformEncode() { + String encode = ""; + String osPrefix = getOsPrefix(); + if (osPrefix.toLowerCase().startsWith("win32")) { + encode = "GBK"; + } else if (osPrefix.toLowerCase().startsWith("linux")) { + encode = "UTF-8"; + }else if(osPrefix.toLowerCase().startsWith("mac")){ + encode="UTF-8"; + } + if(encode.isEmpty()){ + encode="UTF-8"; + } + return encode; + } + + // 鑾峰彇鎿嶄綔骞冲彴淇℃伅 + public static String getOsPrefix() { + String arch = System.getProperty("os.arch").toLowerCase(); + final String name = System.getProperty("os.name"); + String osPrefix; + switch (Platform.getOSType()) { + case Platform.WINDOWS: { + if ("i386".equals(arch)) + arch = "x86"; + osPrefix = "win32-" + arch; + } + break; + case Platform.LINUX: { + if ("x86".equals(arch)) { + arch = "i386"; + } else if ("x86_64".equals(arch)) { + arch = "amd64"; + } + osPrefix = "linux-" + arch; + } + break; + case Platform.MAC: { + //mac绯荤粺鐨刼s.arch閮芥槸ppc(鑰佺増鏈殑mac鏄痯owerpc锛屽凡缁忓熀鏈笉鐢�)鐪嬩笉鍑虹郴缁熶綅鏁帮紝浣跨敤涓嬮潰鐨勫弬鏁拌〃绀� + arch = System.getProperty("sun.arch.data.model"); + osPrefix = "mac-" + arch; + } + break; + default: { + osPrefix = name.toLowerCase(); + if ("x86".equals(arch)) { + arch = "i386"; + } + if ("x86_64".equals(arch)) { + arch = "amd64"; + } + int space = osPrefix.indexOf(" "); + if (space != -1) { + osPrefix = osPrefix.substring(0, space); + } + osPrefix += "-" + arch; + } + break; + + } + + return osPrefix; + } + + public static String getOsName() { + String osName = ""; + String osPrefix = getOsPrefix(); + if (osPrefix.toLowerCase().startsWith("win32-x86") + || osPrefix.toLowerCase().startsWith("win32-amd64")) { + osName = "win"; + } else if (osPrefix.toLowerCase().startsWith("linux-i386") + || osPrefix.toLowerCase().startsWith("linux-amd64")) { + osName = "linux"; + } else if (osPrefix.toLowerCase().startsWith("mac-64") + || osPrefix.toLowerCase().startsWith("mac-32")) { + osName = "mac"; + } + + return osName; + } + + // 鑾峰彇鍔犺浇搴� + public static String getLoadLibrary(String library) { + if (isChecking()) { + return null; + } + + String loadLibrary = ""; + String osPrefix = getOsPrefix(); + if (osPrefix.toLowerCase().startsWith("win32-x86")) { + loadLibrary = "./lib/win32/"; + } else if (osPrefix.toLowerCase().startsWith("win32-amd64")) { + loadLibrary = "./lib/win64/"; + } else if (osPrefix.toLowerCase().startsWith("linux-i386")) { + loadLibrary = ""; + } else if (osPrefix.toLowerCase().startsWith("linux-amd64")) { + loadLibrary = ""; + } else if (osPrefix.toLowerCase().startsWith("mac-64")) { + loadLibrary = ""; + } +// else if(osPrefix.toLowerCase().startsWith("mac-32")) { +// loadLibrary = ""; +// } 32浣峬ac鐗堟湰鍩烘湰娌′汉鐢ㄤ簡锛屾殏鏃朵笉鐢� + + System.out.printf("鍔犺浇搴揫%s]\n", loadLibrary + library); + return loadLibrary + library; + } + + private static boolean checking = false; + + public static void setChecking() { + checking = true; + } + + public static void clearChecking() { + checking = false; + } + + public static boolean isChecking() { + return checking; + } + + public static class LLong extends IntegerType { + private static final long serialVersionUID = 1L; + + /** + * Size of a native long, in bytes. + */ + public static int size; + + static { + size = Native.LONG_SIZE; + if (Utils.getOsPrefix().toLowerCase().equals("linux-amd64") + || Utils.getOsPrefix().toLowerCase().equals("win32-amd64") + || Utils.getOsPrefix().toLowerCase().equals("mac-64")) { + size = 8; + } else if (Utils.getOsPrefix().toLowerCase().equals("linux-i386") + || Utils.getOsPrefix().toLowerCase().equals("win32-x86")) { + size = 4; + } + } + + /** + * Create a zero-valued LLong. + */ + public LLong() { + this(0); + } + + /** + * Create a LLong with the given value. + */ + public LLong(long value) { + super(size, value); + } + } + + public static class SdkStructure extends Structure { + @Override + protected List<String> getFieldOrder() { + List<String> fieldOrderList = new ArrayList<String>(); + for (Class<?> cls = getClass(); + !cls.equals(NetSDKLib.SdkStructure.class); + cls = cls.getSuperclass()) { + Field[] fields = cls.getDeclaredFields(); + int modifiers; + for (Field field : fields) { + modifiers = field.getModifiers(); + if (Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) { + continue; + } + fieldOrderList.add(field.getName()); + } + } + // System.out.println(fieldOrderList); + + return fieldOrderList; + } + } + + // 鑾峰彇褰撳墠鏃堕棿 + public static String getDate() { + SimpleDateFormat simpleDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return simpleDate.format(new java.util.Date()) + .replace(" ", "_").replace(":", "-"); + } + +} -- Gitblit v1.9.3