Sfoglia il codice sorgente

修复manage模块部分bug。

zhuoning 3 anni fa
parent
commit
d96c887afe
31 ha cambiato i file con 2994 aggiunte e 67 eliminazioni
  1. 9 0
      huimv-eartag2-platform/huimv-eartag2-common/pom.xml
  2. 13 0
      huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/dao/entity/EartagDeviceEartagCountEntity.java
  3. 935 0
      huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/utils/BytesUtil.java
  4. 16 2
      huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/utils/MathUtil.java
  5. 0 1
      huimv-eartag2-platform/huimv-eartag2-eartag/src/main/java/com/huimv/eartag2/eartag/listener/EartagListener.java
  6. 2 0
      huimv-eartag2-platform/huimv-eartag2-eartag/src/main/java/com/huimv/eartag2/eartag/service/ICacheService.java
  7. 6 0
      huimv-eartag2-platform/huimv-eartag2-eartag/src/main/java/com/huimv/eartag2/eartag/service/impl/CacheServiceImpl.java
  8. 104 6
      huimv-eartag2-platform/huimv-eartag2-eartag/src/main/java/com/huimv/eartag2/eartag/service/impl/EartagServiceImpl.java
  9. 3 6
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/server/EartagServerHandler2.java
  10. 25 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/controller/DeviceController.java
  11. 1 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/controller/DeviceRegisterController.java
  12. 1 1
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/controller/EartagController.java
  13. 3 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/IDeviceService.java
  14. 2 2
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/IEartagService.java
  15. 132 45
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/impl/DeviceServiceImpl.java
  16. 20 4
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/impl/EartagServiceImpl.java
  17. 66 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/FileCopy.java
  18. 184 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Hex.java
  19. 59 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/HexDump.java
  20. 51 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/HexDump2.java
  21. 29 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/HexTest.java
  22. 161 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/HexUtils.java
  23. 85 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Test004.java
  24. 120 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Test005.java
  25. 203 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Test006.java
  26. 261 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Test7.java
  27. 261 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Test72.java
  28. 99 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Test9.java
  29. 112 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Test92.java
  30. 24 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/test8.java
  31. 7 0
      huimv-eartag2-platform/pom.xml

+ 9 - 0
huimv-eartag2-platform/huimv-eartag2-common/pom.xml

@@ -14,6 +14,15 @@
     <version>0.0.1-SNAPSHOT</version>
     <packaging>jar</packaging>
 
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.7</version>
+        </dependency>
+
+    </dependencies>
+
     <!-- 后加 -->
     <build>
         <resources>

+ 13 - 0
huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/dao/entity/EartagDeviceEartagCountEntity.java

@@ -3,6 +3,7 @@ package com.huimv.eartag2.common.dao.entity;
 import javax.persistence.*;
 import java.io.Serializable;
 import java.sql.Date;
+import java.sql.Timestamp;
 
 @Entity
 @Table(name = "eartag_device_eartag_count")
@@ -30,6 +31,9 @@ public class EartagDeviceEartagCountEntity implements Serializable {
     @Column(name = "farm_id")
     private String farmId;
 
+    @Column(name = "update_time")
+    private Timestamp updateTime;
+
     public void setId(Integer id) {
         this.id = id;
     }
@@ -78,6 +82,14 @@ public class EartagDeviceEartagCountEntity implements Serializable {
         return farmId;
     }
 
+    public void setUpdateTime(Timestamp updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    public Timestamp getUpdateTime() {
+        return updateTime;
+    }
+
     @Override
     public String toString() {
         return "EartagDeviceEartagCountEntity{" +
@@ -87,6 +99,7 @@ public class EartagDeviceEartagCountEntity implements Serializable {
                 "total=" + total + '\'' +
                 "createDate=" + createDate + '\'' +
                 "farmId=" + farmId + '\'' +
+                "updateTime=" + updateTime + '\'' +
                 '}';
     }
 }

+ 935 - 0
huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/utils/BytesUtil.java

@@ -0,0 +1,935 @@
+package com.huimv.eartag2.common.utils;
+
+
+import java.nio.charset.Charset;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class BytesUtil {
+    public static final String GBK = "GBK";
+    public static final String UTF8 = "utf-8";
+    public static final char[] ascii = "0123456789ABCDEF".toCharArray();
+    private static char[] HEX_VOCABLE = {'0', '1', '2', '3', '4', '5', '6', '7',
+            '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+
+    /**
+     * 将short整型数值转换为字节数组
+     *
+     * @param data
+     * @return
+     */
+    public static byte[] getBytes(short data) {
+        byte[] bytes = new byte[2];
+        bytes[0] = (byte) ((data & 0xff00) >> 8);
+        bytes[1] = (byte) (data & 0xff);
+        return bytes;
+    }
+
+    /**
+     * 将字符转换为字节数组
+     *
+     * @param data
+     * @return
+     */
+    public static byte[] getBytes(char data) {
+        byte[] bytes = new byte[2];
+        bytes[0] = (byte) (data >> 8);
+        bytes[1] = (byte) (data);
+        return bytes;
+    }
+
+    /**
+     * 将布尔值转换为字节数组
+     *
+     * @param data
+     * @return
+     */
+    public static byte[] getBytes(boolean data) {
+        byte[] bytes = new byte[1];
+        bytes[0] = (byte) (data ? 1 : 0);
+        return bytes;
+    }
+
+    /**
+     * 将整型数值转换为字节数组
+     *
+     * @param data
+     * @return
+     */
+    public static byte[] getBytes(int data) {
+        byte[] bytes = new byte[4];
+        bytes[0] = (byte) ((data & 0xff000000) >> 24);
+        bytes[1] = (byte) ((data & 0xff0000) >> 16);
+        bytes[2] = (byte) ((data & 0xff00) >> 8);
+        bytes[3] = (byte) (data & 0xff);
+        return bytes;
+    }
+
+    /**
+     * 将long整型数值转换为字节数组
+     *
+     * @param data
+     * @return
+     */
+    public static byte[] getBytes(long data) {
+        byte[] bytes = new byte[8];
+        bytes[0] = (byte) ((data >> 56) & 0xff);
+        bytes[1] = (byte) ((data >> 48) & 0xff);
+        bytes[2] = (byte) ((data >> 40) & 0xff);
+        bytes[3] = (byte) ((data >> 32) & 0xff);
+        bytes[4] = (byte) ((data >> 24) & 0xff);
+        bytes[5] = (byte) ((data >> 16) & 0xff);
+        bytes[6] = (byte) ((data >> 8) & 0xff);
+        bytes[7] = (byte) (data & 0xff);
+        return bytes;
+    }
+
+    /**
+     * 将float型数值转换为字节数组
+     *
+     * @param data
+     * @return
+     */
+    public static byte[] getBytes(float data) {
+        int intBits = Float.floatToIntBits(data);
+        return getBytes(intBits);
+    }
+
+    /**
+     * 将double型数值转换为字节数组
+     *
+     * @param data
+     * @return
+     */
+    public static byte[] getBytes(double data) {
+        long intBits = Double.doubleToLongBits(data);
+        return getBytes(intBits);
+    }
+
+    /**
+     * 将字符串按照charsetName编码格式的字节数组
+     *
+     * @param data
+     *            字符串
+     * @param charsetName
+     *            编码格式
+     * @return
+     */
+    public static byte[] getBytes(String data, String charsetName) {
+        Charset charset = Charset.forName(charsetName);
+        return data.getBytes(charset);
+    }
+
+    /**
+     * 将字符串按照GBK编码格式的字节数组
+     *
+     * @param data
+     * @return
+     */
+    public static byte[] getBytes(String data) {
+        return getBytes(data, GBK);
+    }
+
+    /**
+     * 将字节数组第0字节转换为布尔值
+     *
+     * @param bytes
+     * @return
+     */
+    public static boolean getBoolean(byte[] bytes) {
+        return bytes[0] == 1;
+    }
+
+    /**
+     * 将字节数组的第index字节转换为布尔值
+     *
+     * @param bytes
+     * @param index
+     * @return
+     */
+    public static boolean getBoolean(byte[] bytes, int index) {
+        return bytes[index] == 1;
+    }
+
+    /**
+     * 将字节数组前2字节转换为short整型数值
+     *
+     * @param bytes
+     * @return
+     */
+    public static short getShort(byte[] bytes) {
+        return (short) ((0xff00 & (bytes[0] << 8)) | (0xff & bytes[1]));
+    }
+
+    /**
+     * 将字节数组从startIndex开始的2个字节转换为short整型数值
+     *
+     * @param bytes
+     * @param startIndex
+     * @return
+     */
+    public static short getShort(byte[] bytes, int startIndex) {
+        return (short) ((0xff00 & (bytes[startIndex] << 8))
+                | (0xff & bytes[startIndex + 1]));
+    }
+
+    /**
+     * 将字节数组前2字节转换为字符
+     *
+     * @param bytes
+     * @return
+     */
+    public static char getChar(byte[] bytes) {
+        return (char) ((0xff00 & (bytes[0] << 8)) | (0xff & bytes[1]));
+    }
+
+    /**
+     * 将字节数组从startIndex开始的2个字节转换为字符
+     *
+     * @param bytes
+     * @param startIndex
+     * @return
+     */
+    public static char getChar(byte[] bytes, int startIndex) {
+        return (char) ((0xff00 & (bytes[startIndex] << 8))
+                | (0xff & bytes[startIndex + 1]));
+    }
+
+    /**
+     * 将字节数组前4字节转换为整型数值
+     *
+     * @param bytes
+     * @return
+     */
+    public static int getInt(byte[] bytes) {
+        return (0xff000000 & (bytes[0] << 24) | (0xff0000 & (bytes[1] << 16))
+                | (0xff00 & (bytes[2] << 8)) | (0xff & bytes[3]));
+    }
+
+    /**
+     * 将字节数组从startIndex开始的4个字节转换为整型数值
+     *
+     * @param bytes
+     * @param startIndex
+     * @return
+     */
+    public static int getInt(byte[] bytes, int startIndex) {
+        return (0xff000000 & (bytes[startIndex] << 24)
+                | (0xff0000 & (bytes[startIndex + 1] << 16))
+                | (0xff00 & (bytes[startIndex + 2] << 8))
+                | (0xff & bytes[startIndex + 3]));
+    }
+
+    /**
+     * 将字节数组前8字节转换为long整型数值
+     *
+     * @param bytes
+     * @return
+     */
+    public static long getLong(byte[] bytes) {
+        return (0xff00000000000000L & ((long) bytes[0] << 56)
+                | (0xff000000000000L & ((long) bytes[1] << 48))
+                | (0xff0000000000L & ((long) bytes[2] << 40))
+                | (0xff00000000L & ((long) bytes[3] << 32))
+                | (0xff000000L & ((long) bytes[4] << 24))
+                | (0xff0000L & ((long) bytes[5] << 16))
+                | (0xff00L & ((long) bytes[6] << 8))
+                | (0xffL & (long) bytes[7]));
+    }
+
+    /**
+     * 将字节数组从startIndex开始的8个字节转换为long整型数值
+     *
+     * @param bytes
+     * @param startIndex
+     * @return
+     */
+    public static long getLong(byte[] bytes, int startIndex) {
+        return (0xff00000000000000L & ((long) bytes[startIndex] << 56)
+                | (0xff000000000000L & ((long) bytes[startIndex + 1] << 48))
+                | (0xff0000000000L & ((long) bytes[startIndex + 2] << 40))
+                | (0xff00000000L & ((long) bytes[startIndex + 3] << 32))
+                | (0xff000000L & ((long) bytes[startIndex + 4] << 24))
+                | (0xff0000L & ((long) bytes[startIndex + 5] << 16))
+                | (0xff00L & ((long) bytes[startIndex + 6] << 8))
+                | (0xffL & (long) bytes[startIndex + 7]));
+    }
+
+    /**
+     * 将字节数组前4字节转换为float型数值
+     *
+     * @param bytes
+     * @return
+     */
+    public static float getFloat(byte[] bytes) {
+        return Float.intBitsToFloat(getInt(bytes));
+    }
+
+    /**
+     * 将字节数组从startIndex开始的4个字节转换为float型数值
+     *
+     * @param bytes
+     * @param startIndex
+     * @return
+     */
+    public static float getFloat(byte[] bytes, int startIndex) {
+        byte[] result = new byte[4];
+        System.arraycopy(bytes, startIndex, result, 0, 4);
+        return Float.intBitsToFloat(getInt(result));
+    }
+
+    /**
+     * 将字节数组前8字节转换为double型数值
+     *
+     * @param bytes
+     * @return
+     */
+    public static double getDouble(byte[] bytes) {
+        long l = getLong(bytes);
+        return Double.longBitsToDouble(l);
+    }
+
+    /**
+     * 将字节数组从startIndex开始的8个字节转换为double型数值
+     *
+     * @param bytes
+     * @param startIndex
+     * @return
+     */
+    public static double getDouble(byte[] bytes, int startIndex) {
+        byte[] result = new byte[8];
+        System.arraycopy(bytes, startIndex, result, 0, 8);
+        long l = getLong(result);
+        return Double.longBitsToDouble(l);
+    }
+
+    /**
+     * 将charsetName编码格式的字节数组转换为字符串
+     *
+     * @param bytes
+     * @param charsetName
+     * @return
+     */
+    public static String getString(byte[] bytes, String charsetName) {
+        return new String(bytes, Charset.forName(charsetName));
+    }
+
+    /**
+     * 将GBK编码格式的字节数组转换为字符串
+     *
+     * @param bytes
+     * @return
+     */
+    public static String getString(byte[] bytes) {
+        return getString(bytes, GBK);
+    }
+
+    /**
+     * 将16进制字符串转换为字节数组
+     *
+     * @param
+     * @return
+     */
+    // @Deprecated
+    // public static byte[] hexStringToBytes(String hex) {
+    // if (hex == null || "".equals(hex)) {
+    // return null;
+    // }
+    // int len = hex.length() / 2;
+    // byte[] result = new byte[len];
+    // char[] chArr = hex.toCharArray();
+    // for (int i = 0; i < len; i++) {
+    // int pos = i * 2;
+    // result[i] = (byte) (toByte(chArr[pos]) << 4 | toByte(chArr[pos + 1]));
+    // }
+    // return result;
+    // }
+
+    public static byte[] hexStringToBytes(String hexString) {
+        if (hexString == null || hexString.equals("")) {
+            return null;
+        }
+        // toUpperCase将字符串中的所有字符转换为大写
+        hexString = hexString.toUpperCase();
+        int length = hexString.length() / 2;
+        // toCharArray将此字符串转换为一个新的字符数组。
+        char[] hexChars = hexString.toCharArray();
+        byte[] d = new byte[length];
+        for (int i = 0; i < length; i++) {
+            int pos = i * 2;
+            d[i] = (byte) (charToByte(hexChars[pos]) << 4
+                    | charToByte(hexChars[pos + 1]));
+        }
+        return d;
+    }
+
+    // charToByte返回在指定字符的第一个发生的字符串中的索引,即返回匹配字符
+    private static byte charToByte(char c) {
+        return (byte) "0123456789ABCDEF".indexOf(c);
+    }
+    /**
+     * 将16进制字符串转换为字节数组
+     *
+     * @param hex
+     * @return
+     */
+    public static byte[] hexToBytes(String hex) {
+        if (hex.length() % 2 != 0)
+            throw new IllegalArgumentException(
+                    "input string should be any multiple of 2!");
+        hex.toUpperCase();
+
+        byte[] byteBuffer = new byte[hex.length() / 2];
+
+        byte padding = 0x00;
+        boolean paddingTurning = false;
+        for (int i = 0; i < hex.length(); i++) {
+            if (paddingTurning) {
+                char c = hex.charAt(i);
+                int index = indexOf(hex, c);
+                padding = (byte) ((padding << 4) | index);
+                byteBuffer[i / 2] = padding;
+                padding = 0x00;
+                paddingTurning = false;
+            } else {
+                char c = hex.charAt(i);
+                int index = indexOf(hex, c);
+                padding = (byte) (padding | index);
+                paddingTurning = true;
+            }
+
+        }
+        return byteBuffer;
+    }
+
+    private static int indexOf(String input, char c) {
+        int index = ArrayUtils.indexOf(HEX_VOCABLE, c);
+
+        if (index < 0) {
+            throw new IllegalArgumentException("err input:" + input);
+        }
+        return index;
+
+    }
+
+    /**
+     * 将BCD编码的字节数组转换为字符串
+     *
+     * @param bcds
+     * @return
+     */
+    public static String bcdToString(byte[] bcds) {
+        if (bcds == null || bcds.length == 0) {
+            return null;
+        }
+        byte[] temp = new byte[2 * bcds.length];
+        for (int i = 0; i < bcds.length; i++) {
+            temp[i * 2] = (byte) ((bcds[i] >> 4) & 0x0f);
+            temp[i * 2 + 1] = (byte) (bcds[i] & 0x0f);
+        }
+        StringBuffer res = new StringBuffer();
+        for (int i = 0; i < temp.length; i++) {
+            res.append(ascii[temp[i]]);
+        }
+        return res.toString();
+    }
+
+    /**
+     * 字节转整形
+     *
+     * @param value
+     * @return
+     */
+    public static int bcdToInt(byte value) {
+        return ((value >> 4) * 10) + (value & 0x0F);
+    }
+
+    /**
+     * 字节数组转16进制字符串
+     *
+     * @param bs
+     * @return
+     */
+    public static String bytesToHex(byte[] bs) {
+        StringBuilder sb = new StringBuilder();
+        for (byte b : bs) {
+            int high = (b >> 4) & 0x0f;
+            int low = b & 0x0f;
+            sb.append(HEX_VOCABLE[high]);
+            sb.append(HEX_VOCABLE[low]);
+        }
+        return sb.toString();
+    }
+
+    /**
+     * 字节数组取前len个字节转16进制字符串
+     *
+     * @param bs
+     * @param len
+     * @return
+     */
+    public static String bytesToHex(byte[] bs, int len) {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < len; i++) {
+            byte b = bs[i];
+            int high = (b >> 4) & 0x0f;
+            int low = b & 0x0f;
+            sb.append(HEX_VOCABLE[high]);
+            sb.append(HEX_VOCABLE[low]);
+        }
+        return sb.toString();
+    }
+    /**
+     * 字节数组偏移offset长度之后的取len个字节转16进制字符串
+     *
+     * @param bs
+     * @param offset
+     * @param len
+     * @return
+     */
+    public static String bytesToHex(byte[] bs, int offset, int len) {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < len; i++) {
+            byte b = bs[offset + i];
+            int high = (b >> 4) & 0x0f;
+            int low = b & 0x0f;
+            sb.append(HEX_VOCABLE[high]);
+            sb.append(HEX_VOCABLE[low]);
+        }
+        return sb.toString();
+    }
+    /**
+     * 字节数组转16进制字符串
+     *
+     * @param
+     * @return
+     */
+    public static String byteToHex(byte b) {
+        StringBuilder sb = new StringBuilder();
+        int high = (b >> 4) & 0x0f;
+        int low = b & 0x0f;
+        sb.append(HEX_VOCABLE[high]);
+        sb.append(HEX_VOCABLE[low]);
+        return sb.toString();
+    }
+    /**
+     * 将字节数组取反
+     *
+     * @param src
+     * @return
+     */
+    public static String negate(byte[] src) {
+        if (src == null || src.length == 0) {
+            return null;
+        }
+        byte[] temp = new byte[2 * src.length];
+        for (int i = 0; i < src.length; i++) {
+            byte tmp = (byte) (0xFF ^ src[i]);
+            temp[i * 2] = (byte) ((tmp >> 4) & 0x0f);
+            temp[i * 2 + 1] = (byte) (tmp & 0x0f);
+        }
+        StringBuffer res = new StringBuffer();
+        for (int i = 0; i < temp.length; i++) {
+            res.append(ascii[temp[i]]);
+        }
+        return res.toString();
+    }
+
+    /**
+     * 比较字节数组是否相同
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static boolean compareBytes(byte[] a, byte[] b) {
+        if (a == null || a.length == 0 || b == null || b.length == 0
+                || a.length != b.length) {
+            return false;
+        }
+        if (a.length == b.length) {
+            for (int i = 0; i < a.length; i++) {
+                if (a[i] != b[i]) {
+                    return false;
+                }
+            }
+        } else {
+            return false;
+        }
+        return true;
+    }
+    /**
+     * 只比对指定长度byte
+     *
+     * @param a
+     * @param b
+     * @param len
+     * @return
+     */
+    public static boolean compareBytes(byte[] a, byte[] b, int len) {
+        if (a == null || a.length == 0 || b == null || b.length == 0
+                || a.length < len || b.length < len) {
+            return false;
+        }
+        for (int i = 0; i < len; i++) {
+            if (a[i] != b[i]) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * 将字节数组转换为二进制字符串
+     *
+     * @param items
+     * @return
+     */
+    public static String bytesToBinaryString(byte[] items) {
+        if (items == null || items.length == 0) {
+            return null;
+        }
+        StringBuffer buf = new StringBuffer();
+        for (byte item : items) {
+            buf.append(byteToBinaryString(item));
+        }
+        return buf.toString();
+    }
+
+    /**
+     * 将字节转换为二进制字符串
+     *
+     * @param
+     * @return
+     */
+    public static String byteToBinaryString(byte item) {
+        byte a = item;
+        StringBuffer buf = new StringBuffer();
+        for (int i = 0; i < 8; i++) {
+            buf.insert(0, a % 2);
+            a = (byte) (a >> 1);
+        }
+        return buf.toString();
+    }
+
+    /**
+     * 对数组a,b进行异或运算
+     *
+     * @param a
+     * @param b
+     * @return
+     */
+    public static byte[] xor(byte[] a, byte[] b) {
+        if (a == null || a.length == 0 || b == null || b.length == 0
+                || a.length != b.length) {
+            return null;
+        }
+        byte[] result = new byte[a.length];
+        for (int i = 0; i < a.length; i++) {
+            result[i] = (byte) (a[i] ^ b[i]);
+        }
+        return result;
+    }
+
+    /**
+     * 对数组a,b进行异或运算 运算长度len
+     *
+     * @param a
+     * @param b
+     * @param len
+     * @return
+     */
+    public static byte[] xor(byte[] a, byte[] b, int len) {
+        if (a == null || a.length == 0 || b == null || b.length == 0) {
+            return null;
+        }
+        if (a.length < len || b.length < len) {
+            return null;
+        }
+        byte[] result = new byte[len];
+        for (int i = 0; i < len; i++) {
+            result[i] = (byte) (a[i] ^ b[i]);
+        }
+        return result;
+    }
+    /**
+     * 将short整型数值转换为字节数组
+     *
+     * @param num
+     * @return
+     */
+    public static byte[] shortToBytes(int num) {
+        byte[] temp = new byte[2];
+        for (int i = 0; i < 2; i++) {
+            temp[i] = (byte) ((num >>> (8 - i * 8)) & 0xFF);
+        }
+        return temp;
+    }
+
+    /**
+     * 将字节数组转为整型
+     *
+     * @param
+     * @return
+     */
+    public static int bytesToShort(byte[] arr) {
+        int mask = 0xFF;
+        int temp = 0;
+        int result = 0;
+        for (int i = 0; i < 2; i++) {
+            result <<= 8;
+            temp = arr[i] & mask;
+            result |= temp;
+        }
+        return result;
+    }
+
+    /**
+     * 将整型数值转换为指定长度的字节数组
+     *
+     * @param num
+     * @return
+     */
+    public static byte[] intToBytes(int num) {
+        byte[] temp = new byte[4];
+        for (int i = 0; i < 4; i++) {
+            temp[i] = (byte) ((num >>> (24 - i * 8)) & 0xFF);
+        }
+        return temp;
+    }
+
+    /**
+     * 将整型数值转换为指定长度的字节数组
+     *
+     * @param src
+     * @param len
+     * @return
+     */
+    public static byte[] intToBytes(int src, int len) {
+        if (len < 1 || len > 4) {
+            return null;
+        }
+        byte[] temp = new byte[len];
+        for (int i = 0; i < len; i++) {
+            temp[len - 1 - i] = (byte) ((src >>> (8 * i)) & 0xFF);
+        }
+        return temp;
+    }
+
+    /**
+     * 将字节数组转换为整型数值
+     *
+     * @param arr
+     * @return
+     */
+    public static int bytesToInt(byte[] arr) {
+        int mask = 0xFF;
+        int temp = 0;
+        int result = 0;
+        for (int i = 0; i < 4; i++) {
+            result <<= 8;
+            temp = arr[i] & mask;
+            result |= temp;
+        }
+        return result;
+    }
+
+    /**
+     * 将long整型数值转换为字节数组
+     *
+     * @param num
+     * @return
+     */
+    public static byte[] longToBytes(long num) {
+        byte[] temp = new byte[8];
+        for (int i = 0; i < 8; i++) {
+            temp[i] = (byte) ((num >>> (56 - i * 8)) & 0xFF);
+        }
+        return temp;
+    }
+
+    /**
+     * 将字节数组转换为long整型数值
+     *
+     * @param arr
+     * @return
+     */
+    public static long bytesToLong(byte[] arr) {
+        int mask = 0xFF;
+        int temp = 0;
+        long result = 0;
+        int len = Math.min(8, arr.length);
+        for (int i = 0; i < len; i++) {
+            result <<= 8;
+            temp = arr[i] & mask;
+            result |= temp;
+        }
+        return result;
+    }
+
+    /**
+     * 将16进制字符转换为字节
+     *
+     * @param c
+     * @return
+     */
+    public static byte toByte(char c) {
+        byte b = (byte) "0123456789ABCDEF".indexOf(c);
+        return b;
+    }
+
+    /**
+     * 功能描述:把两个字节的字节数组转化为整型数据,高位补零,例如:<br/>
+     * 有字节数组byte[] data = new byte[]{1,2};转换后int数据的字节分布如下:<br/>
+     * 00000000 00000000 00000001 00000010,函数返回258
+     *
+     * @param lenData
+     *            需要进行转换的字节数组
+     * @return 字节数组所表示整型值的大小
+     */
+    public static int bytesToIntWhereByteLengthEquals2(byte lenData[]) {
+        if (lenData.length != 2) {
+            return -1;
+        }
+        byte fill[] = new byte[]{0, 0};
+        byte real[] = new byte[4];
+        System.arraycopy(fill, 0, real, 0, 2);
+        System.arraycopy(lenData, 0, real, 2, 2);
+        int len = byteToInt(real);
+        return len;
+
+    }
+
+    /**
+     * 功能描述:将byte数组转化为int类型的数据
+     *
+     * @param byteVal
+     *            需要转化的字节数组
+     * @return 字节数组所表示的整型数据
+     */
+    public static int byteToInt(byte[] byteVal) {
+        int result = 0;
+        for (int i = 0; i < byteVal.length; i++) {
+            int tmpVal = (byteVal[i] << (8 * (3 - i)));
+            switch (i) {
+                case 0 :
+                    tmpVal = tmpVal & 0xFF000000;
+                    break;
+                case 1 :
+                    tmpVal = tmpVal & 0x00FF0000;
+                    break;
+                case 2 :
+                    tmpVal = tmpVal & 0x0000FF00;
+                    break;
+                case 3 :
+                    tmpVal = tmpVal & 0x000000FF;
+                    break;
+            }
+
+            result = result | tmpVal;
+        }
+        return result;
+    }
+    public static byte CheckXORSum(byte[] bData) {
+        byte sum = 0x00;
+        for (int i = 0; i < bData.length; i++) {
+            sum ^= bData[i];
+        }
+        return sum;
+    }
+    /**
+     * 从offset开始 将后续长度为len的byte字节转为int
+     *
+     * @param data
+     * @param offset
+     * @param len
+     * @return
+     */
+    public static int bytesToInt(byte[] data, int offset, int len) {
+        int mask = 0xFF;
+        int temp = 0;
+        int result = 0;
+        len = Math.min(len, 4);
+        for (int i = 0; i < len; i++) {
+            result <<= 8;
+            temp = data[offset + i] & mask;
+            result |= temp;
+        }
+        return result;
+    }
+
+    /**
+     * byte字节数组中的字符串的长度
+     *
+     * @param data
+     * @return
+     */
+    public static int getBytesStringLen(byte[] data) {
+        int count = 0;
+        for (byte b : data) {
+            if (b == 0x00) {
+                break;
+            }
+            count++;
+        }
+        return count;
+    }
+
+    /**
+     * 校验和
+     *
+     * @param msg
+     *            需要计算校验和的byte数组
+     * @param length
+     *            校验和位数
+     * @return 计算出的校验和数组
+     */
+    public static byte[] SumCheck(byte[] msg, int length) {
+        long mSum = 0;
+        byte[] mByte = new byte[length];
+
+        /** 逐Byte添加位数和 */
+        for (byte byteMsg : msg) {
+            long mNum = ((long) byteMsg >= 0)
+                    ? (long) byteMsg
+                    : ((long) byteMsg + 256);
+            mSum += mNum;
+        } /** end of for (byte byteMsg : msg) */
+
+        /** 位数和转化为Byte数组 */
+        for (int liv_Count = 0; liv_Count < length; liv_Count++) {
+            mByte[length - liv_Count
+                    - 1] = (byte) (mSum >> (liv_Count * 8) & 0xff);
+        } /** end of for (int liv_Count = 0; liv_Count < length; liv_Count++) */
+
+        return mByte;
+    }
+
+    /**
+     * 字节数据转十进制字符(补码-无符号)
+     *
+     * @param data
+     * @return
+     */
+    public static String getByteToStr(byte[] data) {
+        StringBuffer str = new StringBuffer();
+        for (int i = 0; i < data.length; i++) {
+            if (data[i] < 0) {
+                int tem = data[i] + 256;
+                str.append(tem + " ");
+            } else {
+                str.append(data[i] + " ");
+            }
+        }
+        return str.toString();
+    }
+
+}

+ 16 - 2
huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/utils/MathUtil.java

@@ -24,12 +24,26 @@ public class MathUtil {
     public static double E = -0.0000000204758173596178;
 
     public static BigDecimal formatScale(String val1,String val2,Integer scale){
-        BigDecimal deviceRateBd= new BigDecimal(val1).divide(new BigDecimal(val2),2,BigDecimal.ROUND_HALF_UP);
+        if(scale == null){
+            scale = 2;
+        }
+        BigDecimal deviceRateBd= new BigDecimal(val1).divide(new BigDecimal(val2),scale,BigDecimal.ROUND_HALF_UP);
         return deviceRateBd;
     }
 
     public static BigDecimal countEnvtemp(String val1,Integer scale){
-        BigDecimal deviceRateBd= new BigDecimal(val1).divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP);
+        if(scale == null){
+            scale = 2;
+        }
+        BigDecimal deviceRateBd= new BigDecimal(val1).divide(new BigDecimal(100),scale,BigDecimal.ROUND_HALF_UP);
+        return deviceRateBd;
+    }
+
+    public static BigDecimal countRate(String val1,Integer scale){
+        if(scale == null){
+            scale = 2;
+        }
+        BigDecimal deviceRateBd= new BigDecimal(val1).divide(new BigDecimal(100),scale,BigDecimal.ROUND_HALF_UP);
         return deviceRateBd;
     }
 

+ 0 - 1
huimv-eartag2-platform/huimv-eartag2-eartag/src/main/java/com/huimv/eartag2/eartag/listener/EartagListener.java

@@ -65,7 +65,6 @@ public class EartagListener {
         //测试代码(属于测试耳标才能进行测试)
         if(checkTestRange(earmark)){
             if(type.trim().equalsIgnoreCase("eartag")){
-                System.out.println("askText>>"+askText);
                 //{处理耳标数据}
                 eartagService.handleEartag(dataJo);
             }

+ 2 - 0
huimv-eartag2-platform/huimv-eartag2-eartag/src/main/java/com/huimv/eartag2/eartag/service/ICacheService.java

@@ -57,6 +57,8 @@ public interface ICacheService {
 
     void putEartagTotal(Integer total, String farmId);
 
+    Object getHashProperty(String hashKey, String fieldName);
+
     //从缓存读取在线耳标数量
     Integer getEartagOnlineTotalFromCache(String farmId, String todayDateText);
 

+ 6 - 0
huimv-eartag2-platform/huimv-eartag2-eartag/src/main/java/com/huimv/eartag2/eartag/service/impl/CacheServiceImpl.java

@@ -370,6 +370,12 @@ public class CacheServiceImpl implements ICacheService {
         redisTemplate.opsForValue().set(valueKey,total);
     }
 
+    @Override
+    public Object getHashProperty(String hashKey, String fieldName) {
+        Object obj = redisTemplate.opsForHash().get(hashKey, fieldName);
+        return obj;
+    }
+
     /**
      * @Method      : getEartagOnlineTotalFromCache
      * @Description : 返回集合缓存的数量;

+ 104 - 6
huimv-eartag2-platform/huimv-eartag2-eartag/src/main/java/com/huimv/eartag2/eartag/service/impl/EartagServiceImpl.java

@@ -3,6 +3,7 @@ package com.huimv.eartag2.eartag.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.huimv.eartag2.common.dao.entity.*;
 import com.huimv.eartag2.common.dao.repo.*;
+import com.huimv.eartag2.common.utils.BizConst;
 import com.huimv.eartag2.common.utils.DateUtil;
 import com.huimv.eartag2.eartag.service.ICacheService;
 import com.huimv.eartag2.eartag.service.IDeviceService;
@@ -52,6 +53,8 @@ public class EartagServiceImpl implements IEartagService {
     private EartagDeviceEartagCountRepo deviceEartagCountRepo;
     @Autowired
     private EartagDeviceRegisterRepo deviceRegisterRepo;
+    @Autowired
+    private EartagDeviceOnlineRepo eartagDeviceOnlineRepo;
 
     @Override
     public void handleEartag(JSONObject dataJo) throws ParseException {
@@ -77,11 +80,14 @@ public class EartagServiceImpl implements IEartagService {
             //{更新耳标注册信息}
             updateEartagRegister(earmark, deviceCode, nowTimestamp, todayDate, farmId);
 
-            //{更新耳标在线信息}
+            //{更新设备在线统计}
+            updateDeviceOnline(earmark, deviceCode, todayDateText,nowTimestamp, todayDate, dataJo,farmId);
+
+            //{更新耳标在线统计}
             updateEartagOnline(earmark, deviceCode, todayDateText, todayDate, nowTimestamp, dataJo, farmId);
 
-            //{更新耳标设备在线统计}
-            updateEartagDeviceOnlineCount(earmark, deviceCode, todayDateText, todayDate, farmId);
+            //{更新耳标设备在线关联统计}
+            updateEartagDeviceOnlineCount(earmark, deviceCode, todayDateText, todayDate,nowTimestamp, farmId);
 
             //判断该设备编号是否存在牧场缓存在线集合当中;
             if (!cacheService.isExistEartagOnlineSet(farmId, earmark, todayDateText)) {
@@ -96,6 +102,96 @@ public class EartagServiceImpl implements IEartagService {
     }
 
     /**
+     * @Method      : updateDeviceOnline
+     * @Description : 更新设备在线统计
+     * @Params      : [earmark, deviceCode, nowTimestamp, todayDate, farmId]
+     * @Return      : void
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2022/3/29       
+     * @Time        : 9:13
+     */
+    private void updateDeviceOnline(String earmark, String deviceCode, String todayDateText, Timestamp nowTimestamp, java.sql.Date todayDate, JSONObject dataJo, String farmId) {
+        // 查询在线统计;
+        // 不存在,则新建设备在线统计
+        //存在,则直接更新耳标数量;
+        String hashKey = BizConst.DEVICE_REGISTER_PREFIX+deviceCode;
+        //计算设备别名
+        String alias = (String)cacheService.getHashProperty(hashKey,"deviceAlias");
+        String earTemp1 =  dataJo.getString("earTemp1");
+        String envTemp1 = dataJo.getString("envTemp1");
+
+        //读取在线日期
+        EartagDeviceOnlineEntity eartagDeviceOnlineEntity = eartagDeviceOnlineRepo.getDeviceOnline(deviceCode, todayDateText);
+        if (eartagDeviceOnlineEntity == null) {
+            Integer heartbeatTotal = 0;
+            Integer envtempTotal = 0;
+            Timestamp heartbeatFirstTime = null;
+            Timestamp heartbeatLastTime = null;
+            Timestamp envtempFirstTime = null;
+            Timestamp envtempLastTime = null;
+            Timestamp firstTime = nowTimestamp;
+            Timestamp lastTime = nowTimestamp;
+            Timestamp eartagFirstTime = nowTimestamp;
+            Timestamp eartagLastTime = nowTimestamp;
+            Integer eartagTotal = 1;
+            //{新建设备在线统计并创建缓存}
+            newDeviceOnline(deviceCode,alias,heartbeatTotal,envtempTotal,eartagTotal,todayDate,farmId,heartbeatFirstTime,heartbeatLastTime,envtempFirstTime,envtempLastTime,firstTime,lastTime,eartagFirstTime,eartagLastTime,earTemp1,envTemp1);
+        }else{
+
+            eartagDeviceOnlineEntity.setAlias(alias);
+            int eartagTotal = eartagDeviceOnlineEntity.getEartagTotal();
+            eartagDeviceOnlineEntity.setEartagTotal(++eartagTotal);
+            eartagDeviceOnlineEntity.setEartagFirstTime(nowTimestamp);
+            eartagDeviceOnlineEntity.setEartagLastTime(nowTimestamp);
+            eartagDeviceOnlineEntity.setLastEartag(earTemp1);
+            eartagDeviceOnlineEntity.setLastEnvtemp(envTemp1);
+            if(eartagDeviceOnlineEntity.getFirstTime() == null){
+                eartagDeviceOnlineEntity.setFirstTime(nowTimestamp);
+            }
+            eartagDeviceOnlineEntity.setLastTime(nowTimestamp);
+            eartagDeviceOnlineRepo.saveAndFlush(eartagDeviceOnlineEntity);
+            //更新设备在线缓存数据
+            cacheService.putDeviceInOnline(deviceCode,eartagDeviceOnlineEntity);
+        }
+
+    }
+    
+    /**
+     * @Method      : newDeviceOnline
+     * @Description : 新建设备在线
+     * @Params      : [deviceCode, alias, heartbeatTotal, envtempTotal, eartagTotal, todayDate, farmId, heartbeatFirstTime, heartbeatLastTime, envtempFirstTime, envtempLastTime, firstTime, lastTime, eartagFirstTime, eartagLastTime]
+     * @Return      : void
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2022/3/29       
+     * @Time        : 9:44
+     */
+    private void newDeviceOnline(String deviceCode, String alias, Integer heartbeatTotal, Integer envtempTotal, Integer eartagTotal, java.sql.Date todayDate, String farmId, Timestamp heartbeatFirstTime, Timestamp heartbeatLastTime, Timestamp envtempFirstTime, Timestamp envtempLastTime, Timestamp firstTime, Timestamp lastTime, Timestamp eartagFirstTime, Timestamp eartagLastTime, String earTemp1, String envTemp1) {
+        EartagDeviceOnlineEntity newEartagDeviceOnlineEntity = new EartagDeviceOnlineEntity();
+        newEartagDeviceOnlineEntity.setDeviceCode(deviceCode);
+        newEartagDeviceOnlineEntity.setAlias(alias);
+        newEartagDeviceOnlineEntity.setHeartbeatTotal(heartbeatTotal);;
+        newEartagDeviceOnlineEntity.setEnvtempTotal(envtempTotal);
+        newEartagDeviceOnlineEntity.setEartagTotal(eartagTotal);
+        newEartagDeviceOnlineEntity.setFirstTime(firstTime);
+        newEartagDeviceOnlineEntity.setLastTime(lastTime);
+        newEartagDeviceOnlineEntity.setLastEnvtemp(envTemp1);
+        newEartagDeviceOnlineEntity.setLastEartag(earTemp1);
+        newEartagDeviceOnlineEntity.setAddDate(todayDate);
+        newEartagDeviceOnlineEntity.setFarmId(farmId);
+        newEartagDeviceOnlineEntity.setHeartbeatFirstTime(heartbeatFirstTime);
+        newEartagDeviceOnlineEntity.setHeartbeatLastTime(heartbeatLastTime);
+        newEartagDeviceOnlineEntity.setEnvtempFirstTime(envtempFirstTime);
+        newEartagDeviceOnlineEntity.setEnvtempLastTime(envtempLastTime);
+        newEartagDeviceOnlineEntity.setEartagFirstTime(eartagFirstTime);
+        newEartagDeviceOnlineEntity.setEartagLastTime(eartagLastTime);
+        eartagDeviceOnlineRepo.saveAndFlush(newEartagDeviceOnlineEntity);
+        //将新建的设备在线数据更新到设备在线缓存
+        cacheService.putDeviceInOnline(deviceCode,newEartagDeviceOnlineEntity);
+    }
+
+    /**
      * @Method      : updateDeviceRegister
      * @Description : 更新设备注册状态信息
      * @Params      : [deviceCode, nowTimestamp, todayDate, farmId]
@@ -119,7 +215,7 @@ public class EartagServiceImpl implements IEartagService {
     }
 
     //更新耳标设备在线次数
-    private void updateEartagDeviceOnlineCount(String earmark, String deviceCode, String todayDateText, java.sql.Date todayDate, String farmId) {
+    private void updateEartagDeviceOnlineCount(String earmark, String deviceCode, String todayDateText, java.sql.Date todayDate, Timestamp nowTimestamp, String farmId) {
         //从缓存读取耳标关联数据
 //        Map timesMap = cacheService.getEartagDeviceOnlineCountEntries(earmark,deviceCode,todayDateText);
 //        System.out.println("###################### timesMap>>"+timesMap);
@@ -133,13 +229,14 @@ public class EartagServiceImpl implements IEartagService {
         if(deviceEartagCountEntityList.size()==0){
             Integer count = 1;
             //{新建耳标设备关联统计}
-            newEartagDeviceCount(earmark,deviceCode,count,todayDateText,todayDate,farmId);
+            newEartagDeviceCount(earmark,deviceCode,count,todayDateText,todayDate,nowTimestamp,farmId);
         }else{
             //更新次数
             EartagDeviceEartagCountEntity deviceEartagCountEntity = deviceEartagCountEntityList.get(0);
             int total = deviceEartagCountEntity.getTotal();
             ++total;
             deviceEartagCountEntity.setTotal(total);
+            deviceEartagCountEntity.setUpdateTime(nowTimestamp);
             deviceEartagCountRepo.saveAndFlush(deviceEartagCountEntity);
             //缓存里计数+1
             cacheService.countEartagDeviceOnlineTimes(earmark,deviceCode,total,deviceEartagCountEntity);
@@ -147,13 +244,14 @@ public class EartagServiceImpl implements IEartagService {
     }
 
     //新建耳标设备关联统计记录
-    private void newEartagDeviceCount(String earmark, String deviceCode, Integer count, String todayDateText, java.sql.Date todayDate, String farmId) {
+    private void newEartagDeviceCount(String earmark, String deviceCode, Integer count, String todayDateText, java.sql.Date todayDate, Timestamp nowTimestamp, String farmId) {
         EartagDeviceEartagCountEntity newDeviceEartagCountEntity = new EartagDeviceEartagCountEntity();
         newDeviceEartagCountEntity.setDeviceCode(deviceCode);
         newDeviceEartagCountEntity.setEarmark(earmark);
         newDeviceEartagCountEntity.setTotal(count);
         newDeviceEartagCountEntity.setCreateDate(todayDate);
         newDeviceEartagCountEntity.setFarmId(farmId);
+        newDeviceEartagCountEntity.setUpdateTime(nowTimestamp);
         deviceEartagCountRepo.saveAndFlush(newDeviceEartagCountEntity);
         //将数据保存到缓存中
         cacheService.putEartagDeviceOnlineCount(earmark,deviceCode,todayDateText,newDeviceEartagCountEntity);

+ 3 - 6
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/server/EartagServerHandler2.java

@@ -76,7 +76,6 @@ public class EartagServerHandler2 extends ChannelInboundHandlerAdapter {
 //            System.out.println("输入完成.");
             // 处理客户端消息
             handleClientMessage(askTextSb.toString(),ctx);
-//            handleClientMessage2(askTextSb.toString(),ctx);
             //清空重置;
             askTextSb.delete(0,askTextSb.length());
             num = 0;
@@ -84,13 +83,11 @@ public class EartagServerHandler2 extends ChannelInboundHandlerAdapter {
         }
     }
 
-    private void handleClientMessage2(String text, ChannelHandlerContext ctx) {
-        System.out.println("text >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+text);
-    }
-
     @Override
     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
-        cause.printStackTrace();
+        System.out.println("cause.getMessage()>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+cause.getMessage());
+        System.out.println(cause.toString());
+//        cause.printStackTrace();
         ctx.close();
     }
 

+ 25 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/controller/DeviceController.java

@@ -292,6 +292,31 @@ public class DeviceController {
     }
 
     /**
+     * @Method      : listDeviceEartagOnlineStatusByDeviceCodeAndDate
+     * @Description : 查询和设备相关的所有耳标状态
+     * @Params      : [deviceCode, earmark, addDate]
+     * @Return      : com.huimv.eartag2.common.utils.Result
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2022/3/29       
+     * @Time        : 10:55
+     */
+    @RequestMapping(value = "/listDeviceEartagOnlineStatusByDeviceCodeAndDate",method = RequestMethod.GET)
+    public Result listDeviceEartagOnlineStatusByDeviceCodeAndDate(@RequestParam(value = "deviceCode",required = true) String deviceCode,
+                                                                 @RequestParam(value = "earmark",required = false) String earmark,
+                                                                 @RequestParam(value = "addDate",required = false) String addDate) throws ParseException {
+        log.info("<listDeviceEartagOnlineStatusByDeviceCodeAndDate>输入参数 deviceCode>>"+deviceCode);
+        log.info("<listDeviceEartagOnlineStatusByDeviceCodeAndDate>输入参数 earmark>>"+earmark);
+        log.info("<listDeviceEartagOnlineStatusByDeviceCodeAndDate>输入参数 addDate>>"+addDate);
+        //
+        if(addDate == null || addDate.trim().length() == 0){
+            addDate  =  new DateUtil().getTodayDateText();
+        }
+        //查询设备关联的在线耳标统计
+        return deviceService.listDeviceEartagOnlineStatusByDeviceCodeAndDate(deviceCode,earmark,addDate);
+    }
+
+    /**
      * @Method      : listDeviceEnvtempByDeviceCode
      * @Description : 显示设备温度流水
      * @Params      : [deviceCode]

+ 1 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/controller/DeviceRegisterController.java

@@ -56,6 +56,7 @@ public class DeviceRegisterController {
         return deviceRegisterService.addDevice(chipId,deviceCode,deviceStatus,activeStatus,deviceAlias,location,remark,farmId);
     }
 
+
     @PostMapping("/addDevice1")
     public Result addDevice1(@RequestBody JSONObject json){
         System.out.println("## json>>"+json);

+ 1 - 1
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/controller/EartagController.java

@@ -36,7 +36,7 @@ public class EartagController {
      * @Time        : 18:39
      */
     @RequestMapping(value = "/getEartagRegisterByEarmark",method = RequestMethod.GET)
-    public Result getEartagRegisterByEarmark(@RequestParam(value = "earmark",required = true) String earmark){
+    public Result getEartagRegisterByEarmark(@RequestParam(value = "earmark",required = true) String earmark) throws ParseException {
         log.info("<getEartagRegisterByEarmark> 输入参数earmark>>"+earmark);
         //
         return eartagService.getEartagRegisterByEarmark(earmark);

+ 3 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/IDeviceService.java

@@ -57,4 +57,7 @@ public interface IDeviceService {
 
     //计算总状态信息
     void countFarmAllStatus(JSONObject deviceRegisterJo) throws ParseException;
+
+    //
+    Result listDeviceEartagOnlineStatusByDeviceCodeAndDate(String deviceCode, String earmark, String addDate);
 }

+ 2 - 2
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/IEartagService.java

@@ -6,7 +6,7 @@ import java.text.ParseException;
 
 public interface IEartagService {
     //
-    Result getEartagRegisterByEarmark(String earmark);
+    Result getEartagRegisterByEarmark(String earmark) throws ParseException;
 
     //根据耳标号读取今天所有流水
     Result listEartagFlowByEarmarkAndToday(String earmark) throws ParseException;
@@ -26,7 +26,7 @@ public interface IEartagService {
     Result listEartagFlowByDeviceCodeAndEarmarkAndTodayInPager(String earmark, String deviceCode, String createDate, Integer pageNo, Integer pageSize) throws ParseException;
 
     //带分页查询耳标流水
-    Result listEartagFlowByDeviceCodeAndEarmarkAndDateInPager(String earmark, String deviceCode, String addDate, Integer pageNo, Integer pageSize);
+    Result listEartagFlowByDeviceCodeAndEarmarkAndDateInPager(String earmark, String deviceCode, String addDate, Integer pageNo, Integer pageSize) throws ParseException;
 
     //前N天的耳标在线状态
     Result listEartagOnlineAllStatus(String farmId, Integer days) throws ParseException;

+ 132 - 45
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/impl/DeviceServiceImpl.java

@@ -299,48 +299,57 @@ public class DeviceServiceImpl implements IDeviceService {
         DateUtil dateUtil = new DateUtil();
         //{}
         Page<EartagDeviceRegisterEntity> pageDeviceRegister = deviceRegisterRepo.findAll(sf, pageable);
-        JSONObject outDataJo = new JSONObject();
-        outDataJo.put("pageable", pageDeviceRegister.getPageable());
-        outDataJo.put("last", pageDeviceRegister.isLast());
-        outDataJo.put("totalElements", pageDeviceRegister.getTotalElements());
-        outDataJo.put("totalPages", pageDeviceRegister.getTotalPages());
-        outDataJo.put("number", pageDeviceRegister.getNumber());
-        outDataJo.put("size", pageDeviceRegister.getSize());
-        outDataJo.put("sort", pageDeviceRegister.getSort());
-        outDataJo.put("numberOfElements", pageDeviceRegister.getNumberOfElements());
-        outDataJo.put("first", pageDeviceRegister.isFirst());
-        outDataJo.put("empty", pageDeviceRegister.isEmpty());
-
-        List<EartagDeviceRegisterEntity> deviceRegisterEntityList = pageDeviceRegister.getContent();
-//        System.out.println("## deviceRegisterEntityList.size>>"+deviceRegisterEntityList.size());
-        JSONArray outJa = new JSONArray();
-        outDataJo.put("content", outJa);
-        for (EartagDeviceRegisterEntity deviceRegisterEntity : deviceRegisterEntityList) {
-            JSONObject outJo = new JSONObject();
-            outJa.add(outJo);
-            outJo.put("id", deviceRegisterEntity.getId());
-            outJo.put("deviceCode", deviceRegisterEntity.getDeviceCode());
-            outJo.put("countyCode", deviceRegisterEntity.getCountyCode());
-            outJo.put("countyName", deviceRegisterEntity.getCountyName());
-            outJo.put("farmId", deviceRegisterEntity.getFarmId());
-            outJo.put("farmName", deviceRegisterEntity.getFarmName());
-            outJo.put("typeF", deviceRegisterEntity.getTypeF());
-            outJo.put("stage", deviceRegisterEntity.getStage());
-            outJo.put("pigpenId", deviceRegisterEntity.getPigpenId());
-            outJo.put("unitId", deviceRegisterEntity.getUnitId());
-            outJo.put("registerTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getRegisterTime()));
-            outJo.put("lastTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getLastTime()));
-            outJo.put("activeStatus", deviceRegisterEntity.getActiveStatus());
-            outJo.put("activeTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getActiveTime()));
-            outJo.put("deviceStatus", deviceRegisterEntity.getDeviceStatus());
-            outJo.put("deviceAlias", deviceRegisterEntity.getDeviceAlias());
-            outJo.put("location", deviceRegisterEntity.getLocation());
-            outJo.put("remark", deviceRegisterEntity.getRemark());
-            outJo.put("createDate", deviceRegisterEntity.getCreateDate());
-            outJo.put("updateType", deviceRegisterEntity.getUpdateType());
+        //////////////////////////////////////////////////////////////////////////////////
+//        JSONObject outDataJo = new JSONObject();
+//        outDataJo.put("pageable", pageDeviceRegister.getPageable());
+//        outDataJo.put("last", pageDeviceRegister.isLast());
+//        outDataJo.put("totalElements", pageDeviceRegister.getTotalElements());
+//        outDataJo.put("totalPages", pageDeviceRegister.getTotalPages());
+//        outDataJo.put("number", pageDeviceRegister.getNumber());
+//        outDataJo.put("size", pageDeviceRegister.getSize());
+//        outDataJo.put("sort", pageDeviceRegister.getSort());
+//        outDataJo.put("numberOfElements", pageDeviceRegister.getNumberOfElements());
+//        outDataJo.put("first", pageDeviceRegister.isFirst());
+//        outDataJo.put("empty", pageDeviceRegister.isEmpty());
+//
+//        List<EartagDeviceRegisterEntity> deviceRegisterEntityList = pageDeviceRegister.getContent();
+////        System.out.println("## deviceRegisterEntityList.size>>"+deviceRegisterEntityList.size());
+//        JSONArray outJa = new JSONArray();
+//        outDataJo.put("content", outJa);
+//        for (EartagDeviceRegisterEntity deviceRegisterEntity : deviceRegisterEntityList) {
+//            JSONObject outJo = new JSONObject();
+//            outJa.add(outJo);
+//            outJo.put("id", deviceRegisterEntity.getId());
+//            outJo.put("deviceCode", deviceRegisterEntity.getDeviceCode());
+//            outJo.put("countyCode", deviceRegisterEntity.getCountyCode());
+//            outJo.put("countyName", deviceRegisterEntity.getCountyName());
+//            outJo.put("farmId", deviceRegisterEntity.getFarmId());
+//            outJo.put("farmName", deviceRegisterEntity.getFarmName());
+//            outJo.put("typeF", deviceRegisterEntity.getTypeF());
+//            outJo.put("stage", deviceRegisterEntity.getStage());
+//            outJo.put("pigpenId", deviceRegisterEntity.getPigpenId());
+//            outJo.put("unitId", deviceRegisterEntity.getUnitId());
+////            outJo.put("registerTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getRegisterTime()));
+////            outJo.put("lastTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getLastTime()));
+//            outJo.put("activeStatus", deviceRegisterEntity.getActiveStatus());
+////            outJo.put("activeTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getActiveTime()));
+//            outJo.put("deviceStatus", deviceRegisterEntity.getDeviceStatus());
+//            outJo.put("deviceAlias", deviceRegisterEntity.getDeviceAlias());
+//            outJo.put("location", deviceRegisterEntity.getLocation());
+//            outJo.put("remark", deviceRegisterEntity.getRemark());
+//            outJo.put("createDate", deviceRegisterEntity.getCreateDate());
+//            outJo.put("updateType", deviceRegisterEntity.getUpdateType());
+//        }
+        ///////////////////////////////////////////////////////////////////////
+        JSONObject pageJo = JSONObject.parseObject(JSONObject.toJSONString(pageDeviceRegister));
+        JSONArray contentJa = pageJo.getJSONArray("content");
+        for(int a=0;a<contentJa.size();a++){
+            JSONObject contentJo = contentJa.getJSONObject(a);
+            contentJo.put("registerTime",dateUtil.formatDatetimeText(contentJo.getDate("registerTime")));
+            contentJo.put("lastTime",dateUtil.formatDatetimeText(contentJo.getDate("lastTime")));
+            contentJo.put("activeTime",dateUtil.formatDatetimeText(contentJo.getDate("activeTime")));
         }
-        return new Result(ResultCode.SUCCESS, outDataJo);
-//        return new Result(ResultCode.SUCCESS, deviceRegisterRepo.findAll(sf, pageable));
+        return new Result(ResultCode.SUCCESS, pageJo);
     }
 
     @Override
@@ -436,6 +445,48 @@ public class DeviceServiceImpl implements IDeviceService {
     }
 
     @Override
+    public Result listDeviceEartagOnlineStatusByDeviceCodeAndDate(String deviceCode, String earmark, String addDate) {
+        //
+        Specification<EartagDeviceEartagCountEntity> sf = (Specification<EartagDeviceEartagCountEntity>) (root, criteriaQuery, criteriaBuilder) -> {
+            //
+            List<Predicate> predList = new ArrayList<>();
+            if (null != earmark && earmark.trim().length() > 0) {
+                predList.add(criteriaBuilder.equal(root.get("earmark").as(String.class), earmark));
+            }
+            //
+            if (null != deviceCode && deviceCode.trim().length() > 0) {
+                predList.add(criteriaBuilder.equal(root.get("deviceCode").as(String.class), deviceCode));
+            }
+            //
+            if (null != addDate && addDate.trim().length() > 0) {
+                try {
+                    predList.add(criteriaBuilder.equal(root.get("createDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(addDate))));
+                } catch (ParseException e) {
+                    e.printStackTrace();
+                }
+            }
+            Predicate[] pred = new Predicate[predList.size()];
+            Predicate and = criteriaBuilder.and(predList.toArray(pred));
+            criteriaQuery.where(and);
+            //
+            List<Order> orders = new ArrayList<>();
+            orders.add(criteriaBuilder.desc(root.get("total")));
+            return criteriaQuery.orderBy(orders).getRestriction();
+        };
+        List<EartagDeviceEartagCountEntity> deviceEartagCountEntityList = deviceEartagCountRepo.findAll(sf);
+        JSONArray dataJa = new JSONArray();
+        for(EartagDeviceEartagCountEntity deviceEartagCountEntity:deviceEartagCountEntityList){
+            JSONObject eartagJo = new JSONObject();
+            dataJa.add(eartagJo);
+            String earmark1 = deviceEartagCountEntity.getEarmark();
+//            eartagJo.put("earmark",earmark1.substring(9,earmark1.length()));
+            eartagJo.put("earmark",earmark1);
+            eartagJo.put("value",deviceEartagCountEntity.getTotal());
+        }
+        return new Result(ResultCode.SUCCESS, dataJa);
+    }
+
+    @Override
     public void remoteProcessFarmAllStatus(String farmId) throws ParseException {
         String todayDateText = new com.huimv.eartag2.common.utils.DateUtil().getTodayDateText();
         java.sql.Date todayDate = new java.sql.Date(new java.util.Date().getTime());
@@ -710,6 +761,7 @@ public class DeviceServiceImpl implements IDeviceService {
             JSONObject resultJo = (JSONObject) JSON.toJSON(deviceRegisterEntity);
             resultJo.put("activeTime", dateUtil.formatDatetimeText(resultJo.getDate("activeTime")));
             resultJo.put("registerTime", dateUtil.formatDatetimeText(resultJo.getDate("registerTime")));
+            resultJo.put("lastTime", dateUtil.formatDatetimeText(resultJo.getDate("lastTime")));
             return new Result(ResultCode.SUCCESS, resultJo);
         }
     }
@@ -769,6 +821,29 @@ public class DeviceServiceImpl implements IDeviceService {
             return new Result(ResultCode.SUCCESS, resultJa);
         }
     }
+    
+    /**
+     * @Method      : processReturnResult
+     * @Description : 处理返回结果
+     * @Params      : [resultJo]
+     * @Return      : void
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2022/3/30       
+     * @Time        : 18:31
+     */
+    public void processReturnResult(JSONObject resultJo) throws ParseException {
+        MathUtil mathUtil = new MathUtil();
+        DateUtil dateUtil = new DateUtil();
+        resultJo.put("deviceRate",mathUtil.countRate(resultJo.getFloat("deviceRate"),1)+"%");
+        resultJo.put("eartagRate",mathUtil.countRate(resultJo.getIntValue("eartagOnline"),resultJo.getIntValue("eartagTotal"),1)+"%");
+        resultJo.put("updateTime", dateUtil.formatDatetimeText(resultJo.getDate("updateTime")));
+        resultJo.put("deviceTotal",resultJo.getString("deviceTotal")+"个");
+        resultJo.put("deviceOnline",resultJo.getString("deviceOnline")+"个");
+        resultJo.put("deviceOffline",resultJo.getString("deviceOffline")+"个");
+        resultJo.put("eartagTotal",resultJo.getString("eartagTotal")+"枚");
+        resultJo.put("eartagOnline",resultJo.getString("eartagOnline")+"枚");
+    }
 
     @Override
     public Result getNowAllStatus(String farmId) throws ParseException {
@@ -782,10 +857,15 @@ public class DeviceServiceImpl implements IDeviceService {
 
         //{从总状态缓存钟读取缓存数据}
         DateUtil dateUtil = new DateUtil();
+        MathUtil mathUtil = new MathUtil();
         Map farmAllStatusMap = cacheService.getFarmAllStatusByFarmId(farmId);
         if (farmAllStatusMap.size() > 0) {
             log.info("返回缓存数据.");
-            return new Result(ResultCode.SUCCESS, JSON.toJSON(farmAllStatusMap));
+            JSONObject resultJo = (JSONObject) JSON.toJSON(farmAllStatusMap);
+            //{处理返回结果}
+            processReturnResult(resultJo);
+//            return new Result(ResultCode.SUCCESS, JSON.toJSON(farmAllStatusMap));
+            return new Result(ResultCode.SUCCESS, resultJo);
         } else {
             //#从数据库读取总状态表
             String todayDateText = dateUtil.getTodayDateText();
@@ -795,7 +875,11 @@ public class DeviceServiceImpl implements IDeviceService {
             if (farmAllStatusEntity != null) {
                 //#初始化总状态缓存
                 cacheService.putFarmAllStatusCache(farmId, farmAllStatusEntity);
-                return new Result(ResultCode.SUCCESS, JSON.toJSON(farmAllStatusEntity));
+                JSONObject resultJo = (JSONObject) JSON.toJSON(farmAllStatusEntity);
+                //{处理返回结果}
+                processReturnResult(resultJo);
+//                return new Result(ResultCode.SUCCESS, JSON.toJSON(farmAllStatusEntity));
+                return new Result(ResultCode.SUCCESS, resultJo);
             } else {
                 //*构建总状态数据 */
                 int deviceTotal = getDeviceCancelTotalFromDeviceRegister(farmId);
@@ -820,8 +904,11 @@ public class DeviceServiceImpl implements IDeviceService {
                 farmAllStatusRepo.saveAndFlush(newFarmAllStatusEntity);
                 //*初始化总状态缓存*/
                 cacheService.putFarmAllStatusCache(farmId, newFarmAllStatusEntity);
-//                JSON.parseObject(JSON.toJSON(newFarmAllStatusEntity));
-                return new Result(ResultCode.SUCCESS, JSON.toJSON(newFarmAllStatusEntity));
+//                return new Result(ResultCode.SUCCESS, JSON.toJSON(newFarmAllStatusEntity));
+                JSONObject resultJo = (JSONObject) JSON.toJSON(newFarmAllStatusEntity);
+                //{处理返回结果}
+                processReturnResult(resultJo);
+                return new Result(ResultCode.SUCCESS, resultJo);
             }
         }
 

+ 20 - 4
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/impl/EartagServiceImpl.java

@@ -21,6 +21,7 @@ import java.sql.Date;
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @Project : huimv.shiwan
@@ -649,7 +650,7 @@ public class EartagServiceImpl implements IEartagService {
      * @Time : 22:14
      */
     @Override
-    public Result listEartagFlowByDeviceCodeAndEarmarkAndDateInPager(String earmark, String deviceCode, String addDate, Integer pageNo, Integer pageSize) {
+    public Result listEartagFlowByDeviceCodeAndEarmarkAndDateInPager(String earmark, String deviceCode, String addDate, Integer pageNo, Integer pageSize) throws ParseException {
         //
         Specification<EartagDataEntity> sf = (Specification<EartagDataEntity>) (root, criteriaQuery, criteriaBuilder) -> {
             //
@@ -679,7 +680,15 @@ public class EartagServiceImpl implements IEartagService {
             return criteriaQuery.orderBy(orders).getRestriction();
         };
         Pageable pageable = PageRequest.of(pageNo - 1, pageSize);
-        return new Result(ResultCode.SUCCESS, eartagDataRepo.findAll(sf, pageable));
+        Page<EartagDataEntity> pageEnvEntity = eartagDataRepo.findAll(sf, pageable);
+        DateUtil dateUtil = new DateUtil();
+        JSONObject pageJo = JSONObject.parseObject(JSONObject.toJSONString(pageEnvEntity));
+        JSONArray contentJa = pageJo.getJSONArray("content");
+        for(int a=0;a<contentJa.size();a++){
+            JSONObject contentJo = contentJa.getJSONObject(a);
+            contentJo.put("addTime",dateUtil.formatDatetimeText(contentJo.getDate("addTime")));
+        }
+        return new Result(ResultCode.SUCCESS, pageJo);
     }
 
     /**
@@ -783,11 +792,18 @@ public class EartagServiceImpl implements IEartagService {
      * @Time : 18:41
      */
     @Override
-    public Result getEartagRegisterByEarmark(String earmark) {
+    public Result getEartagRegisterByEarmark(String earmark) throws ParseException {
+        DateUtil dateUtil = new DateUtil();
         //
         EartagEartagRegisterEntity eartagRegisterEntity = eartagRegisterRepo.getEartagByEarmark(earmark);
         if (eartagRegisterEntity != null) {
-            return new Result(ResultCode.SUCCESS, JSON.toJSON(eartagRegisterEntity));
+            Map map = JSON.parseObject(JSONObject.toJSONString(eartagRegisterEntity), Map.class);
+//            map.put("lastTime",dateUtil.formatDatetimeText(new Date(dateUtil.parseDateTime(map.get("lastTime").toString()).getTime())));
+            map.put("firstTime",dateUtil.formatLongToDate(Long.parseLong(map.get("firstTime").toString())));
+            map.put("lastTime",dateUtil.formatLongToDate(Long.parseLong(map.get("lastTime").toString())));
+            map.put("activeTime",dateUtil.formatLongToDate(Long.parseLong(map.get("activeTime").toString())));
+            map.put("registerTime",dateUtil.formatLongToDate(Long.parseLong(map.get("registerTime").toString())));
+            return new Result(ResultCode.SUCCESS, map);
         } else {
             return new Result(BizConst.CODE_EARTAG_REGISTER_NO_EXIST, BizConst.MSG_EARTAG_REGISTER_NO_EXIST, false);
         }

+ 66 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/FileCopy.java

@@ -0,0 +1,66 @@
+package com.huimv.eartag2.manage.utils;
+
+import java.io.*;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class FileCopy {
+
+    // 二进制写入方法 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+        public static void main(String[] args) {
+            FileInputStream fis = null;
+            FileOutputStream fos = null;
+            DataInputStream dis = null;
+            DataOutputStream dos = null;
+            String file = "D:\\1\\16k.pcm";
+            String file2 = "D:\\1\\16k2.pcm";
+
+            try {
+                //创建输入流
+                fis = new FileInputStream(file);
+                dis = new DataInputStream(fis);
+
+                //创建输出流
+                fos = new FileOutputStream(file2);
+                dos = new DataOutputStream(fos);
+
+                //循环读取录入
+                int temp;
+                int sum=0;
+                while((temp = dis.read())!=-1){
+                    dos.write(temp);
+                    ++sum;
+                }
+                System.out.println("sum>>"+sum);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            finally{
+                try {
+                    if (fis!=null) {
+                        fis.close();
+                    }
+                    if (fos!=null) {
+                        fos.close();
+                    }
+                    if (dis!=null) {
+                        dis.close();
+                    }
+                    if (dos!=null) {
+                        dos.close();
+                    }
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+
+        }
+
+}

+ 184 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Hex.java

@@ -0,0 +1,184 @@
+package com.huimv.eartag2.manage.utils;
+
+/**
+ * reference apache commons <a
+ * href="http://commons.apache.org/codec/">http://commons.apache.org/codec/</a>
+ *
+ * byte占用8位,十六进制字符占用4位。所以可以把一个byte转换成两个相应的十六进制字符,即把byte的高4位和低4位 * 分别转换成相应的十六进制字符H和L,并组合起来。相反的转换也是同理。
+ *
+ */
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class Hex {
+
+    /**
+     * 用于建立十六进制字符的输出
+     */
+    private static final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+            'a', 'b', 'c', 'd', 'e', 'f' };
+
+    /**
+     * 用于建立十六进制字符的输出
+     */
+    private static final char[] DIGITS_UPPER = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+            'A', 'B', 'C', 'D', 'E', 'F' };
+
+    /**
+     * 将字节数组转换为十六进制字符数组。
+     *
+     * 因为使用两个字符表示一个字节,所以返回的char[]长度将是参数byte[]长度的两倍。
+     *
+     * @param data
+     *            用于转换为十六进制字符的byte[]
+     * @return 包含十六进制字符的char[]
+     */
+    public static char[] encodeHex(final byte[] data) {
+        return encodeHex(data, true);
+    }
+
+    /**
+     * 将字节数组转换为十六进制字符数组。
+     *
+     * 因为使用两个字符表示一个字节,所以返回的char[]长度将是参数byte[]长度的两倍。
+     *
+     * @param data
+     *            用于转换为十六进制字符的byte[]
+     * @param toLowerCase
+     *            <code>true</code> 传换成小写格式 , <code>false</code> 传换成大写格式
+     * @return 包含十六进制字符的char[]
+     */
+    public static char[] encodeHex(final byte[] data, final boolean toLowerCase) {
+        return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
+    }
+
+    /**
+     * 将字节数组转换为十六进制字符数组。
+     *
+     * 因为使用两个字符表示一个字节,所以返回的char[]长度将是参数byte[]长度的两倍。
+     *
+     * @param data
+     *            用于转换为十六进制字符的byte[]
+     * @param toDigits
+     *            用于控制输出的字母表
+     * @return 包含十六进制字符的char[]
+     */
+    protected static char[] encodeHex(final byte[] data, final char[] toDigits) {
+        int l = data.length;
+        char[] out = new char[l << 1];
+        // two characters form the hex value.
+        for (int i = 0, j = 0; i < l; i++) {
+            out[j++] = toDigits[(0xF0 & data[i]) >>> 4];
+            out[j++] = toDigits[0x0F & data[i]];
+        }
+        return out;
+    }
+
+    /**
+     * 将字节数组转换为十六进制字符串。
+     *
+     * 因为使用两个字符表示一个字节,所以返回的的字符串长度将是参数byte[]长度的两倍。
+     *
+     * @param data
+     *            用于转换为十六进制字符的byte[]
+     * @return 十六进制字符串
+     */
+    public static String encodeHexStr(final byte[] data) {
+        return encodeHexStr(data, true);
+    }
+
+    /**
+     * 将字节数组转换为十六进制字符串。
+     *
+     * 因为使用两个字符表示一个字节,所以返回的的字符串长度将是参数byte[]长度的两倍。
+     *
+     * @param data
+     *            用于转换为十六进制字符的byte[]
+     * @param toLowerCase
+     *            <code>true</code> 传换成小写格式 , <code>false</code> 传换成大写格式
+     * @return 十六进制字符串
+     */
+    public static String encodeHexStr(byte[] data, boolean toLowerCase) {
+        return encodeHexStr(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER);
+    }
+
+    /**
+     * 将字节数组转换为十六进制字符串。
+     *
+     * 因为使用两个字符表示一个字节,所以返回的的字符串长度将是参数byte[]长度的两倍。
+     *
+     * @param data
+     *            用于转换为十六进制字符的byte[]
+     * @param toDigits
+     *            用于控制输出的字母表
+     * @return 十六进制字符串
+     */
+    protected static String encodeHexStr(byte[] data, char[] toDigits) {
+        return new String(encodeHex(data, toDigits));
+    }
+
+    /**
+     * 将十六进制字符数组转换为字节数组
+     *
+     * @param data
+     *            十六进制char[]
+     * @return byte[]
+     * @throws RuntimeException
+     *             如果源十六进制字符数组的长度是奇数,将抛出运行时异常
+     */
+    public static byte[] decodeHex(char[] data) {
+        int len = data.length;
+
+        if ((len & 0x01) != 0) {
+            throw new RuntimeException("Odd number of characters.");
+        }
+
+        // 一个byte对应两个十六进制字符,则将byte[]大小设置为char[]大小的一半
+        byte[] out = new byte[len >> 1];
+
+        // two characters form the hex value.
+        for (int i = 0, j = 0; j < len; i++) {
+            int f = toDigit(data[j], j) << 4;
+            j++;
+            f = f | toDigit(data[j], j);
+            j++;
+            out[i] = (byte) (f & 0xFF);
+        }
+
+        return out;
+    }
+
+    /**
+     * 将十六进制字符转换成一个整数。
+     *
+     * @param ch
+     *            要转换成整数的字符
+     * @param index
+     *            字符在字符数组中的位置
+     * @return 一个整数
+     * @throws RuntimeException
+     *             当ch不是一个合法的十六进制字符时,抛出该异常
+     */
+    protected static int toDigit(final char ch, final int index) {
+        final int digit = Character.digit(ch, 16);
+        if (digit == -1) {
+            throw new RuntimeException("Illegal hexadecimal character " + ch + " at index " + index);
+        }
+        return digit;
+    }
+
+    public static void main(String[] args) {
+        String srcStr = "HelloWorld!";
+        String encodeStr = encodeHexStr(srcStr.getBytes(), false);
+        String decodeStr = new String(decodeHex(encodeStr.toCharArray()));
+        System.out.println("源字符串:" + srcStr);
+        System.out.println("字符串编码为十六进制:" + encodeStr);
+        System.out.println("十六进制解码为字符串:" + decodeStr);
+    }
+}

+ 59 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/HexDump.java

@@ -0,0 +1,59 @@
+package com.huimv.eartag2.manage.utils;
+
+import java.io.DataInputStream;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class HexDump {
+    public static void main(String[] args) {
+        try {
+            String file = "D:\\1\\16k.pcm";
+//            String file = "D:\\1\\16k_003.pcm";
+//            InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\0testData\\Data_21"));
+//            InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\1\\16k.pcm"));
+            DataInputStream  isr = new DataInputStream(new FileInputStream(file));
+
+            //每行显示16个数据
+            int bytesPerLine = 16;
+
+            int byteCount = 0;
+            int data;
+            System.out.println("开始>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+            int a=0;
+
+            //逐行读
+            while ((data = isr.read()) != -1) {
+//                System.out.print(">>"+data+"",data & 0xFF);
+//                System.out.printf("%02X", data & 0xFF);
+//                if (byteCount == 0) {
+//                    System.out.println(); //换行
+//                }
+//                else if (byteCount % bytesPerLine == 0){
+//                    System.out.printf("\n", byteCount); //换行
+//                }
+//                else {
+//                    System.out.print(" "); //空格
+//                }
+                //以两位十六进制形式打印显示
+                System.out.printf("%02X", data & 0xFF);
+//                System.out.println();
+//                byteCount += 1;
+                ++a;
+            }
+            System.out.println();
+            System.out.println("a="+a);
+
+        } catch (Exception e) {
+            System.out.println("Exception: " + e);
+        }
+    }
+
+}

+ 51 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/HexDump2.java

@@ -0,0 +1,51 @@
+package com.huimv.eartag2.manage.utils;
+
+import java.io.DataInputStream;
+import java.io.FileInputStream;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class HexDump2 {
+    public static void main(String[] args) {
+        try {
+//            String file = "D:\\1\\16k.pcm";
+            String file = "D:\\1\\16k_003.pcm";
+//            InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\0testData\\Data_21"));
+//            InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\1\\16k.pcm"));
+            DataInputStream  isr = new DataInputStream(new FileInputStream(file));
+
+            //每行显示16个数据
+            int bytesPerLine = 16;
+
+            int byteCount = 0;
+            int data;
+            System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+            while ((data = isr.read()) != -1) {
+//                System.out.print(">>"+data+"",data & 0xFF);
+//                System.out.printf("%02X", data & 0xFF);
+//                if (byteCount == 0) {
+//                    System.out.println(); //换行
+//                }
+//                else if (byteCount % bytesPerLine == 0){
+//                    System.out.printf("\n", byteCount); //换行
+//                }
+//                else {
+//                    System.out.print(" "); //空格
+//                }
+                //以两位十六进制形式打印显示
+                System.out.printf("%02X", data & 0xFF);
+//                byteCount += 1;
+            }
+            System.out.println();
+        } catch (Exception e) {
+            System.out.println("Exception: " + e);
+        }
+    }
+
+}

+ 29 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/HexTest.java

@@ -0,0 +1,29 @@
+package com.huimv.eartag2.manage.utils;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class HexTest {
+    public static void main(String[] args){
+        System.out.println("123");
+
+//        test_1();
+
+        test_2();
+    }
+
+    private static void test_2() {
+        String th = Integer.toHexString(1194684);    // 10进制转16进制
+        System.out.println("th>>"+th);
+    }
+
+    private static void test_1() {
+        String text = "46 ff 46 ff 68 ff 65 ff 5c ff 60 ff 30 ff 15 ff";
+
+    }
+}

+ 161 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/HexUtils.java

@@ -0,0 +1,161 @@
+package com.huimv.eartag2.manage.utils;
+
+import java.io.ByteArrayOutputStream;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class HexUtils {
+    /**
+     * 16进制数字字符集
+     */
+    private static String hexString="0123456789ABCDEF";
+
+    /**
+     * 转化字符串为十六进制编码
+     */
+    public static String toHexString(String s){
+        String str="";
+        for (int i=0;i<s.length();i++){
+            int ch = (int)s.charAt(i);
+            String s4 = Integer.toHexString(ch);
+            str = str + s4;
+        }
+        return str;
+    }
+
+    /**
+     * 转化十六进制编码为字符串
+     */
+    public static String toStringHex(String s){
+        byte[] baKeyword = new byte[s.length()/2];
+        for(int i = 0; i < baKeyword.length; i++){
+            try{
+                baKeyword[i] = (byte)(0xff & Integer.parseInt(s.substring(i*2, i*2+2),16));
+            }catch(Exception e){
+                e.printStackTrace();
+            }
+        }
+
+        try{
+            s = new String(baKeyword, "utf-8");//UTF-16le:Not
+        }catch (Exception e1){
+            e1.printStackTrace();
+        }
+        return s;
+    }
+
+    /**
+     * 将字符串编码成16进制数字,适用于所有字符(包括中文)
+     */
+    public static String encode(String str){
+        //根据默认编码获取字节数组
+        byte[] bytes=str.getBytes();
+        StringBuilder sb=new StringBuilder(bytes.length*2);
+        //将字节数组中每个字节拆解成2位16进制整数
+        for(int i=0;i<bytes.length;i++){
+            sb.append(hexString.charAt((bytes[i]&0xf0)>>4));
+            sb.append(hexString.charAt((bytes[i]&0x0f)>>0));
+        }
+        return sb.toString();
+    }
+    /**
+     * 将16进制数字解码成字符串,适用于所有字符(包括中文)
+     */
+    public static String decode(String bytes)
+    {
+        ByteArrayOutputStream baos=new ByteArrayOutputStream(bytes.length()/2);
+        //将每2位16进制整数组装成一个字节
+        for(int i=0;i<bytes.length();i+=2)
+            baos.write((hexString.indexOf(bytes.charAt(i))<<4 |hexString.indexOf(bytes.charAt(i+1))));
+        return new String(baos.toByteArray());
+    }
+
+    /**
+     * 将字符串转换成16进制编码字符串
+     *<p>Title: ToHexString</p>
+     *<p>Description: </p>
+     *@param str
+     *@return
+     */
+    public static String ToHexString(String str) {
+        String str1 = "";
+        try {
+            byte[] b = str.getBytes("gbk");
+            int i = 0;
+            int max = b.length;
+            for (; i < max; i++) {
+                str1 = str1 + Integer.toHexString(b[i] & 0xFF);
+            }
+        } catch (UnsupportedEncodingException e) {
+            System.out.println("异常信息ToHexString" + e.getMessage());
+        }
+        return str1;
+    }
+    /**
+     * 16进制编码字符串转字节数组
+     *<p>Title: toByteArray</p>
+     *<p>Description: </p>
+     *@param hexString
+     *@return
+     */
+    public static byte[] toByteArray(String hexString) {
+        hexString = hexString.toLowerCase();
+        final byte[] byteArray = new byte[hexString.length() / 2];
+        int k = 0;
+        for (int i = 0; i < byteArray.length; i++) {// 因为是16进制,最多只会占用4位,转换成字节需要两个16进制的字符,高位在先
+            byte high = (byte) (Character.digit(hexString.charAt(k), 16) & 0xff);
+            byte low = (byte) (Character.digit(hexString.charAt(k + 1), 16) & 0xff);
+            byteArray[i] = (byte) (high << 4 | low);
+            k += 2;
+        }
+        return byteArray;
+    }
+    /**
+     * 字节数组转16进制编码字符串
+     *<p>Title: toHexString</p>
+     *<p>Description: </p>
+     *@param byteArray
+     *@return
+     */
+    public static String toHexString(byte[] byteArray) {
+        String str = null;
+        if (byteArray != null && byteArray.length > 0) {
+            StringBuffer stringBuffer = new StringBuffer(byteArray.length);
+            for (byte byteChar : byteArray) {
+                stringBuffer.append(String.format("%02X", byteChar));
+            }
+            str = stringBuffer.toString();
+        }
+        return str;
+    }
+
+    /**
+     * 字节数组转字符串
+     *<p>Title: ByteArrayDecode</p>
+     *<p>Description: </p>
+     *@param bytes
+     *@return
+     */
+    public static String ByteArray2String(byte[] bytes) {
+        String hexStr = toHexString(bytes);
+        return decode(hexStr);
+    }
+
+    public static void main(String[] args) {
+        String str = "你好asbc121f,smf,m,ewflwf健康的";
+        String sljzstr = encode(str);
+        System.out.println("字符串转16进制数字____"+sljzstr);
+        System.out.println("16进制数字转成字符串____"+decode(sljzstr));
+        System.out.println("字节数组转字符串:"+ByteArray2String(str.getBytes()));
+        int a = 1<<4|2;
+        System.out.println("a="+a);
+    }
+
+}

+ 85 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Test004.java

@@ -0,0 +1,85 @@
+package com.huimv.eartag2.manage.utils;
+
+import java.io.*;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class Test004 {
+
+    // 二进制写入方法 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+
+        public static void main(String[] args) {
+            FileInputStream fis = null;
+            FileOutputStream fos = null;
+            DataInputStream dis = null;
+            DataOutputStream dos = null;
+            String file = "D:\\1\\16k.pcm";
+            String file2 = "D:\\1\\16k2a.pcm";
+            Test7 test7 = new Test7();
+
+            try {
+                //创建输入流(从文件输入)
+                fis = new FileInputStream(file);
+                dis = new DataInputStream(fis);
+
+                //创建输出流(写入文件)
+                fos = new FileOutputStream(file2);
+                dos = new DataOutputStream(fos);
+                //循环读取录入
+                int temp;
+                int sum=0;
+                while((temp = dis.read())!=-1){
+//                    System.out.printf("%02X", temp & 0xFF);
+//                    System.out.println();
+//                    dos.write(temp);
+                    sum+=1;
+                    System.out.println("循环次数="+sum);
+                    String text = test7.convert2Hex2(temp);
+                    System.out.println("temp="+temp+",转换后="+text);
+                    Integer data2 = test7.hexToDec2(text);
+                    System.out.println("text="+text+",再转回="+data2);
+                    
+                    dos.write(data2);
+
+//                    if(sum == 5){
+//                        break;
+//                    }
+                }
+                System.out.println();
+                System.out.println("sum>>"+sum);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            finally{
+                try {
+                    if (fis!=null) {
+                        fis.close();
+                    }
+                    if (fos!=null) {
+                        fos.close();
+                    }
+                    if (dis!=null) {
+                        dis.close();
+                    }
+                    if (dos!=null) {
+                        dos.close();
+                    }
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+
+        }
+
+}

+ 120 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Test005.java

@@ -0,0 +1,120 @@
+package com.huimv.eartag2.manage.utils;
+
+import java.io.*;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class Test005 {
+
+    //    String file = "D:\\1\\16k.pcm";
+    String file = "D:\\1\\16k_003.pcm";
+
+    public static void main(String[] args) {
+        Test005 test = new Test005();
+
+        String hexStr= "46";
+        String[] hexAllArray = hexStr.split(" ");
+//        for(int a=0;a<hexAllArray.length;a++){
+//            String text = hexAllArray[a];
+//            //
+//            test.write(text);
+//        }
+//        String[] hexArray = text.split(" ");
+//        for(int a=0;a<hexAllArray.length;a++){
+//            writePcm(hexAllArray[a]);
+//        }
+
+        test.testWrite(hexToByte(hexStr));
+
+
+        //测试写入
+//        test.testWrite();
+
+        //测试读出
+//        test.testRead();
+    }
+
+    private void write(String text) {
+        String[] hexArray = text.split(" ");
+        for(int a=0;a<hexArray.length;a++){
+            writePcm(hexArray[a]);
+        }
+    }
+
+    private void writePcm(String hexStr) {
+        testWrite(hexToByte(hexStr));
+    }
+
+    private void testRead() {
+        //读取data.bin文件中的数据
+        try {
+            DataInputStream is = new DataInputStream(
+                    new BufferedInputStream(new FileInputStream(
+                            file)));
+            byte[] c = new byte[2];
+            is.read(c);
+            is.close();
+//            log.info(":{}",c);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void testWrite(byte[] bytes) {
+        //将字节数组写入data.bin文件
+        byte[] b = {1, 2};
+        try {
+            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+            DataOutputStream os = new DataOutputStream(
+                    new BufferedOutputStream(new FileOutputStream(
+                            file)));
+//            log.info(":{}",b);
+//            System.out.println(":{}",b);
+//            os.write(b);
+            os.write(bytes);
+            os.flush();
+            os.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * hex转byte数组
+     * @param hex
+     * @return
+     */
+    public static byte[] hexToByte(String hex){
+        int m = 0, n = 0;
+        int byteLen = hex.length() / 2; // 每两个字符描述一个字节
+        byte[] ret = new byte[byteLen];
+        for (int i = 0; i < byteLen; i++) {
+            m = i * 2 + 1;
+            n = m + 1;
+            int intVal = Integer.decode("0x" + hex.substring(i * 2, m) + hex.substring(m, n));
+            ret[i] = Byte.valueOf((byte)intVal);
+        }
+        return ret;
+    }
+
+    /**
+     * byte数组转hex
+     * @param bytes
+     * @return
+     */
+    public static String byteToHex(byte[] bytes){
+        String strHex = "";
+        StringBuilder sb = new StringBuilder("");
+        for (int n = 0; n < bytes.length; n++) {
+            strHex = Integer.toHexString(bytes[n] & 0xFF);
+            sb.append((strHex.length() == 1) ? "0" + strHex : strHex); // 每个字节由两个字符表示,位数不够,高位补0
+        }
+        return sb.toString().trim();
+    }
+}

+ 203 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Test006.java

@@ -0,0 +1,203 @@
+package com.huimv.eartag2.manage.utils;
+
+import java.io.*;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class Test006 {
+    String file = "D:\\1\\16k_007.pcm";
+
+    //
+    public static void main(String[] args) throws FileNotFoundException {
+        Test006 test = new Test006();
+
+        //将16进制字符串转成二进制字节,再转成16进制字符串
+//        test.testConvert();
+
+        //执行写入流
+        test.testWrite_1();
+    }
+
+    //将16进制字符转成字节,写入到文件中
+    private void testWrite_1() throws FileNotFoundException {
+        String hexStr = "B2FFE8FF0200FAFF";
+//        String hexStr = "B2";
+        System.out.println("写入内容="+hexStr);
+        byte[] bytes = hexStrToBytes(hexStr);
+
+        //test1
+//        writeFile1(bytes);
+
+        //test2
+//        writeFile2(bytes);
+
+        //test3
+        writeFile3(bytes);
+
+        readFile(file);
+
+        System.out.println("写入完成.");
+    }
+
+    //读取文件
+    private void readFile(String file) {
+        System.out.println("开始读取内容");
+        int data;
+        int a = 0;
+        try {
+            DataInputStream isr = new DataInputStream(new FileInputStream(file));
+            //逐行读
+            while ((data = isr.read()) != -1) {
+                System.out.printf("%02X", data & 0xFF);
+                ++a;
+            }
+        } catch (Exception e) {
+            System.out.println("Exception: " + e);
+        }finally {
+            System.out.println();
+            System.out.println("a="+a);
+        }
+    }
+
+    //
+    private void writeFile3(byte[] bytes) throws FileNotFoundException {
+//        String file = "D:\\1\\16k_006.pcm";
+        DataOutputStream dos = null;
+        FileOutputStream fos = null;
+        try {
+            //创建输出流(写入文件)
+            fos = new FileOutputStream(file);
+            dos = new DataOutputStream(fos);
+            dos.write(bytes);
+        } catch (Exception e) {
+//            Log.error("write Exception:",e);
+            e.printStackTrace();
+        } finally {
+            try {
+                fos.close();
+            } catch (IOException e) {
+//                Log.error("fos.close() Exception:", e);
+                System.out.println("" + e.getMessage());
+            }
+        }
+    }
+
+    //
+    private void writeFile2(byte[] bytes) {
+        String file = "D:\\1\\16k_005.bin";
+        FileOutputStream fos = null;
+        try {
+            fos = new FileOutputStream(file);
+            fos.write(bytes);
+        } catch (Exception e) {
+//            Log.error("write Exception:",e);
+            e.printStackTrace();
+        } finally {
+            try {
+                fos.close();
+            } catch (IOException e) {
+//                Log.error("fos.close() Exception:", e);
+                System.out.println("" + e.getMessage());
+            }
+        }
+    }
+
+    //将二进制字节写入文件
+    private void writeFile1(byte[] bytes) {
+        //将字节数组写入data.bin文件
+//        byte[] b = {1, 2};
+        try {
+//            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+            DataOutputStream os = new DataOutputStream(
+                    new BufferedOutputStream(new FileOutputStream(
+                            file)));
+//            log.info(":{}",b);
+//            os.write(b);
+            os.write(bytes);
+            os.flush();
+            os.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            System.out.println("完成写入.");
+        }
+    }
+
+    //转换
+    private void testConvert() {
+        String hexStr = "B2";
+        byte[] bytes = hexStrToBytes(hexStr);
+        String text = bytesToHexStr(bytes, true);
+        System.out.println("text>>" + text);
+    }
+
+    /**
+     * byte数组转成字符串
+     *
+     * @param bytes     数组
+     * @param isCaptial 使用大写还是小写表示
+     * @return 转换后的字符串
+     */
+    public String bytesToHexStr(byte[] bytes, boolean isCaptial) {
+        if (null == bytes || bytes.length <= 0) {
+            return null;
+        }
+        StringBuilder s = new StringBuilder();
+        for (int i = 0; i < bytes.length; i++) {
+            if (isCaptial) {
+                //02表示使用2位16进制字符表示当前的byte数据,X或者x表示16进制字符串
+                s.append(String.format("%02X", bytes[i]));
+            } else {
+                s.append(String.format("%02x", bytes[i]));
+            }
+        }
+        return s.toString();
+    }
+
+    /*
+     * @Method      : hexStrToBytes
+     * @Description : 将16进制字符串转成byte数组
+     * @Params      : [hex]
+     * @Return      : byte[]
+     *
+     * @Author      : ZhuoNing
+     * @Date        : 2022/3/30
+     * @Time        : 9:10
+     */
+    public static byte[] hexStrToBytes(String hex) {
+        if (null == hex || hex.equals("")) {
+            return null;
+        }
+        int strLength = hex.length();//获取16进制字符串长度
+        int length = strLength / 2; //获取字节长度
+        char[] hexChars;//用来存放字符串转换成的字符数组
+        if (length * 2 < strLength) { // strLength is odd, add '0'
+            length += 1;
+            hexChars = ("0" + hex).toCharArray();
+        } else {
+            hexChars = hex.toCharArray();
+        }
+        byte[] bytes = new byte[length];//用来存放最终组成的数组
+        for (int i = 0; i < length; i++) {
+            int pos = i * 2;
+            //组成1字节的数据。因为是需要两个字符组成一个字节的数据,这就需要第一个字符向左移4位。
+            bytes[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
+        }
+        return bytes;
+    }
+
+    public static byte charToByte(char c) {
+        byte result = (byte) "0123456789abcdef".indexOf(c);
+        if (result == -1) {
+            return (byte) "0123456789ABCDEF".indexOf(c);
+        } else {
+            return result;
+        }
+    }
+}

+ 261 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Test7.java

@@ -0,0 +1,261 @@
+package com.huimv.eartag2.manage.utils;
+
+import java.io.*;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class Test7 {
+    //
+    public static void main(String[] args) throws FileNotFoundException {
+        Test7 test = new Test7();
+//        test.readFile();
+
+//        test.outFile();
+        test.writePcm();
+    }
+
+    private void writePcm() {
+        FileOutputStream fos = null;
+        DataOutputStream dos = null;
+        Test7 test7 = new Test7();
+
+        /* 读取数据 */
+        try {
+            //创建输出流(写入文件)
+            fos = new FileOutputStream("D:/1/16ka3.pcm");
+            dos = new DataOutputStream(fos);
+
+            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("D:/1/test7.txt")),
+                    "UTF-8"));
+            String lineTxt = null;
+            int sum = 0;
+            while ((lineTxt = br.readLine()) != null) {
+                sum+=1;
+                Integer data = test7.hexToDec2(lineTxt);
+                System.out.println("lineTxt="+lineTxt+" ,data="+data);
+                dos.write(data);
+//                if(sum>=5){
+//                    break;
+//                }
+            }
+            br.close();
+            System.out.println("次数="+sum);
+
+        } catch (Exception e) {
+            System.err.println("read errors :" + e);
+        } finally{
+            try {
+                if (fos!=null) {
+                    fos.close();
+                }
+                if (dos!=null) {
+                    dos.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    private void readFile() {
+        int a = 0;
+        int sum = 0;
+        try {
+            String file = "D:\\1\\16k.pcm";
+//            String file = "D:\\1\\16k_003.pcm";
+//            InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\0testData\\Data_21"));
+//            InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\1\\16k.pcm"));
+            DataInputStream isr = new DataInputStream(new FileInputStream(file));
+
+            //每行显示16个数据
+            int bytesPerLine = 16;
+
+            int byteCount = 0;
+            int data;
+            System.out.println("开始>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+
+
+            //逐行读
+            while ((data = isr.read()) != -1) {
+                System.out.println("循环读取次数=" + ++a);
+//                System.out.print(">>"+data+"",data & 0xFF);
+//                System.out.printf("%02X", data & 0xFF);
+//                if (byteCount == 0) {
+//                    System.out.println(); //换行
+//                }
+//                else if (byteCount % bytesPerLine == 0){
+//                    System.out.printf("\n", byteCount); //换行
+//                }
+//                else {
+//                    System.out.print(" "); //空格
+//                }
+                //以两位十六进制形式打印显示
+//                System.out.printf("%02X", data & 0xFF);
+                System.out.println("data=" + data);
+//                System.out.println("转换1=" + convert2Hex1(data));
+                String text = convert2Hex2(data);
+                System.out.println("转换2=" + text);
+
+                //写入txt文件当中
+                outTxt2(text);
+
+                Integer data2 = hexToDec2(text);
+                System.out.println("再转回=" + data2);
+//                System.out.println();
+//                sum+=data;
+//                String text = bytesToHexStr(data,true);
+//                System.out.println("text="+text);
+//                System.out.println();
+//                byteCount += 1;
+
+//                if (a >= 5) {
+//                    break;
+//                }
+                System.out.println();
+            }
+            System.out.println();
+//            System.out.println("a="+a);
+//            System.out.println("sum="+sum);
+
+        } catch (Exception e) {
+            System.out.println("Exception: " + e);
+        } finally {
+//            System.out.println();
+            System.out.println("a=" + a);
+            System.out.println();
+        }
+    }
+
+    //输出文件
+    public void outTxt(String text){
+        /* 输出数据 */
+        try {
+            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("D:/1/test7.txt")),
+                    "UTF-8"));
+                bw.write(text);
+                bw.newLine();
+            bw.close();
+        } catch (Exception e) {
+            System.err.println("write errors :" + e);
+        }
+    }
+
+    //追加方式写入
+    public void outTxt2(String conent) {
+        BufferedWriter out = null;
+        try {
+            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:/1/test7.txt", true)));
+            out.write(conent + "\r\n");
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                out.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    //
+    public String convert2Hex1(Integer i) {
+        String text = Integer.toHexString(i);
+//        System.out.println(i + " 系统方法:" + text);
+        return text;
+    }
+
+    public int hexToDec2(String hex){
+//        int dec = Integer.parseInt(hex,16);
+        int dec = Integer.valueOf(hex,16).shortValue();
+        return dec;
+    }
+
+    //将16进制转为10进制
+    public int hexToDec(String hex){
+        int dec = 0;
+        //十六进制开头是0x
+        int upper = hex.length()-3;
+        for(int i =2;i<hex.length();i++){
+            if(hex.charAt(i)=='A'){
+                dec += 10*Math.pow(16,upper);
+            }
+            else if(hex.charAt(i)=='B'){
+                dec += 11*Math.pow(16,upper);
+            }
+            else if(hex.charAt(i)=='C'){
+                dec += 12*Math.pow(16,upper);
+            }
+            else if(hex.charAt(i)=='D'){
+                dec += 13*Math.pow(16,upper);
+            }
+            else if(hex.charAt(i)=='E'){
+                dec += 14*Math.pow(16,upper);
+            }
+            else if(hex.charAt(i)=='F'){
+                dec += 15*Math.pow(16,upper);
+            }
+            else{
+                int b = (int)hex.charAt(i);
+                int n = b -(int)'0';
+                dec += n*Math.pow(16,upper);
+            }
+            upper--;
+        }
+        return dec;
+    }
+
+
+    /**
+     * 将一个整形化为十六进制,并以字符串的形式返回
+     */
+//    private final static String[] hexArray = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
+    private final static String[] hexArray = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"};
+
+    //
+    public String convert2Hex2(Integer n) {
+        if (n < 0) {
+            n = n + 256;
+        }
+        int d1 = n / 16;
+        int d2 = n % 16;
+        String text = hexArray[d1] + hexArray[d2];
+        return text;
+    }
+
+    public String bytesToHexStr(byte[] bytes, boolean isCaptial) {
+        if (null == bytes || bytes.length <= 0) {
+            return null;
+        }
+        StringBuilder s = new StringBuilder();
+        for (int i = 0; i < bytes.length; i++) {
+            if (isCaptial) {
+                //02表示使用2位16进制字符表示当前的byte数据,X或者x表示16进制字符串
+                s.append(String.format("%02X", bytes[i]));
+            } else {
+                s.append(String.format("%02x", bytes[i]));
+            }
+        }
+        return s.toString();
+    }
+
+    private void outFile() {
+        /* 输出数据 */
+        try {
+            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("D:/1/out1.txt")),
+                    "UTF-8"));
+            bw.write("B2");
+            bw.newLine();
+            bw.close();
+        } catch (Exception e) {
+            System.err.println("write errors :" + e);
+        } finally {
+            System.out.println("输出完成.");
+        }
+    }
+}

+ 261 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Test72.java

@@ -0,0 +1,261 @@
+package com.huimv.eartag2.manage.utils;
+
+import java.io.*;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class Test72 {
+    //
+    public static void main(String[] args) throws FileNotFoundException {
+        Test72 test = new Test72();
+//        test.readFile();
+
+//        test.outFile();
+        test.writePcm();
+    }
+
+    private void writePcm() {
+        FileOutputStream fos = null;
+        DataOutputStream dos = null;
+        Test72 test7 = new Test72();
+
+        /* 读取数据 */
+        try {
+            //创建输出流(写入文件)
+            fos = new FileOutputStream("D:/1/16ka3.pcm");
+            dos = new DataOutputStream(fos);
+
+            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("D:/1/test7.txt")),
+                    "UTF-8"));
+            String lineTxt = null;
+            int sum = 0;
+            while ((lineTxt = br.readLine()) != null) {
+                sum+=1;
+                Integer data = test7.hexToDec2(lineTxt);
+                System.out.println("lineTxt="+lineTxt+" ,data="+data);
+                dos.write(data);
+//                if(sum>=5){
+//                    break;
+//                }
+            }
+            br.close();
+            System.out.println("次数="+sum);
+
+        } catch (Exception e) {
+            System.err.println("read errors :" + e);
+        } finally{
+            try {
+                if (fos!=null) {
+                    fos.close();
+                }
+                if (dos!=null) {
+                    dos.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    private void readFile() {
+        int a = 0;
+        int sum = 0;
+        try {
+            String file = "D:\\1\\16k.pcm";
+//            String file = "D:\\1\\16k_003.pcm";
+//            InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\0testData\\Data_21"));
+//            InputStreamReader isr = new InputStreamReader(new FileInputStream("D:\\1\\16k.pcm"));
+            DataInputStream isr = new DataInputStream(new FileInputStream(file));
+
+            //每行显示16个数据
+            int bytesPerLine = 16;
+
+            int byteCount = 0;
+            int data;
+            System.out.println("开始>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+
+
+            //逐行读
+            while ((data = isr.read()) != -1) {
+                System.out.println("循环读取次数=" + ++a);
+//                System.out.print(">>"+data+"",data & 0xFF);
+//                System.out.printf("%02X", data & 0xFF);
+//                if (byteCount == 0) {
+//                    System.out.println(); //换行
+//                }
+//                else if (byteCount % bytesPerLine == 0){
+//                    System.out.printf("\n", byteCount); //换行
+//                }
+//                else {
+//                    System.out.print(" "); //空格
+//                }
+                //以两位十六进制形式打印显示
+//                System.out.printf("%02X", data & 0xFF);
+                System.out.println("data=" + data);
+//                System.out.println("转换1=" + convert2Hex1(data));
+                String text = convert2Hex2(data);
+                System.out.println("转换2=" + text);
+
+                //写入txt文件当中
+                outTxt2(text);
+
+                Integer data2 = hexToDec2(text);
+                System.out.println("再转回=" + data2);
+//                System.out.println();
+//                sum+=data;
+//                String text = bytesToHexStr(data,true);
+//                System.out.println("text="+text);
+//                System.out.println();
+//                byteCount += 1;
+
+//                if (a >= 5) {
+//                    break;
+//                }
+                System.out.println();
+            }
+            System.out.println();
+//            System.out.println("a="+a);
+//            System.out.println("sum="+sum);
+
+        } catch (Exception e) {
+            System.out.println("Exception: " + e);
+        } finally {
+//            System.out.println();
+            System.out.println("a=" + a);
+            System.out.println();
+        }
+    }
+
+    //输出文件
+    public void outTxt(String text){
+        /* 输出数据 */
+        try {
+            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("D:/1/test7.txt")),
+                    "UTF-8"));
+                bw.write(text);
+                bw.newLine();
+            bw.close();
+        } catch (Exception e) {
+            System.err.println("write errors :" + e);
+        }
+    }
+
+    //追加方式写入
+    public void outTxt2(String conent) {
+        BufferedWriter out = null;
+        try {
+            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:/1/test7.txt", true)));
+            out.write(conent + "\r\n");
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                out.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    //
+    public String convert2Hex1(Integer i) {
+        String text = Integer.toHexString(i);
+//        System.out.println(i + " 系统方法:" + text);
+        return text;
+    }
+
+    public int hexToDec2(String hex){
+//        int dec = Integer.parseInt(hex,16);
+        int dec = Integer.valueOf(hex,16).shortValue();
+        return dec;
+    }
+
+    //将16进制转为10进制
+    public int hexToDec(String hex){
+        int dec = 0;
+        //十六进制开头是0x
+        int upper = hex.length()-3;
+        for(int i =2;i<hex.length();i++){
+            if(hex.charAt(i)=='A'){
+                dec += 10*Math.pow(16,upper);
+            }
+            else if(hex.charAt(i)=='B'){
+                dec += 11*Math.pow(16,upper);
+            }
+            else if(hex.charAt(i)=='C'){
+                dec += 12*Math.pow(16,upper);
+            }
+            else if(hex.charAt(i)=='D'){
+                dec += 13*Math.pow(16,upper);
+            }
+            else if(hex.charAt(i)=='E'){
+                dec += 14*Math.pow(16,upper);
+            }
+            else if(hex.charAt(i)=='F'){
+                dec += 15*Math.pow(16,upper);
+            }
+            else{
+                int b = (int)hex.charAt(i);
+                int n = b -(int)'0';
+                dec += n*Math.pow(16,upper);
+            }
+            upper--;
+        }
+        return dec;
+    }
+
+
+    /**
+     * 将一个整形化为十六进制,并以字符串的形式返回
+     */
+//    private final static String[] hexArray = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
+    private final static String[] hexArray = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"};
+
+    //
+    public String convert2Hex2(Integer n) {
+        if (n < 0) {
+            n = n + 256;
+        }
+        int d1 = n / 16;
+        int d2 = n % 16;
+        String text = hexArray[d1] + hexArray[d2];
+        return text;
+    }
+
+    public String bytesToHexStr(byte[] bytes, boolean isCaptial) {
+        if (null == bytes || bytes.length <= 0) {
+            return null;
+        }
+        StringBuilder s = new StringBuilder();
+        for (int i = 0; i < bytes.length; i++) {
+            if (isCaptial) {
+                //02表示使用2位16进制字符表示当前的byte数据,X或者x表示16进制字符串
+                s.append(String.format("%02X", bytes[i]));
+            } else {
+                s.append(String.format("%02x", bytes[i]));
+            }
+        }
+        return s.toString();
+    }
+
+    private void outFile() {
+        /* 输出数据 */
+        try {
+            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("D:/1/out1.txt")),
+                    "UTF-8"));
+            bw.write("B2");
+            bw.newLine();
+            bw.close();
+        } catch (Exception e) {
+            System.err.println("write errors :" + e);
+        } finally {
+            System.out.println("输出完成.");
+        }
+    }
+}

+ 99 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Test9.java

@@ -0,0 +1,99 @@
+package com.huimv.eartag2.manage.utils;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class Test9 {
+    //
+    String srcFile = "D:/1/100.txt";
+    String dstFile = "D:/1/100a.pcm";
+
+    public static void main(String[] args) {
+        Test9 test = new Test9();
+
+        //读取文件内容
+        List txtList = test.readTxt();
+
+        //生存pcm文件
+        test.writePcm(txtList);
+    }
+
+    //生存pcm文件
+    private void writePcm(List txtList) {
+        FileOutputStream fos = null;
+        DataOutputStream dos = null;
+//        Test7 test7 = new Test7();
+        try {
+        //创建输出流(写入文件)
+            fos = new FileOutputStream(dstFile);
+            dos = new DataOutputStream(fos);
+            for(int a=0;a<txtList.size();a++){
+                String lineTxt = (String) txtList.get(a);
+//                Integer data = test7.hexToDec2(lineTxt);
+                Integer data = hexToDec2(lineTxt);
+                dos.write(data);
+            }
+            if (fos!=null) {
+                fos.close();
+            }
+            if (dos!=null) {
+                dos.close();
+            }
+        } catch (Exception e) {
+            System.err.println("read errors :" + e);
+        } finally{
+            System.out.println("写入完成,生成目标文件位于"+dstFile);
+        }
+    }
+
+    public int hexToDec2(String hex){
+//        int dec = Integer.parseInt(hex,16);
+        int dec = Integer.valueOf(hex,16).shortValue();
+        return dec;
+    }
+
+    //读取文件内容
+    private List readTxt() {
+
+        ArrayList list = new ArrayList();
+
+        /* 读取数据 */
+        try {
+            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(srcFile)),
+                    "UTF-8"));
+            String lineTxt = null;
+            StringBuilder sb = new StringBuilder();
+            while ((lineTxt = br.readLine()) != null) {
+                System.out.println("lineTxt="+lineTxt);
+                sb.append(lineTxt);
+            }
+            br.close();
+            String rawText = sb.toString();
+            String[] rawArray = rawText.split(";");
+
+            for(int a=0;a<rawArray.length;a++){
+                String text = rawArray[a];
+//                System.out.println((a+1)+",text="+text.trim());
+                String[] textArray = text.split(" ");
+                for(int b=0;b<textArray.length;b++){
+//                    System.out.println("textArray[b]="+textArray[b].toUpperCase());
+                    list.add(textArray[b].toUpperCase());
+                }
+            }
+        } catch (Exception e) {
+            System.err.println("read errors :" + e);
+        } finally{
+            System.out.println("读取完成,读取源文件位于"+srcFile);
+            return list;
+        }
+    }
+}

+ 112 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/Test92.java

@@ -0,0 +1,112 @@
+package com.huimv.eartag2.manage.utils;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class Test92 {
+    public static void main(String[] args) {
+//        test9
+        Test92 test = new Test92();
+
+        //读取文件内容
+        List txtList = test.readTxt();
+        System.out.println("txtList.size="+txtList.size());
+
+        //生存pcm文件
+        test.writePcm(txtList);
+    }
+
+    //生存pcm文件
+    private void writePcm(List txtList) {
+        FileOutputStream fos = null;
+        DataOutputStream dos = null;
+        Test7 test7 = new Test7();
+
+        try {
+        //创建输出流(写入文件)
+            fos = new FileOutputStream("D:/1/test0009b.pcm");
+            dos = new DataOutputStream(fos);
+            for(int a=0;a<txtList.size();a++){
+                String lineTxt = (String) txtList.get(a);
+//                System.out.println("lineTxt="+lineTxt);
+                Integer data = test7.hexToDec2(lineTxt);
+                System.out.println("lineTxt="+lineTxt+" ,data="+data);
+                dos.write(data);
+            }
+            if (fos!=null) {
+                fos.close();
+            }
+            if (dos!=null) {
+                dos.close();
+            }
+        } catch (Exception e) {
+            System.err.println("read errors :" + e);
+        } finally{
+
+        }
+    }
+
+    //读取文件内容
+    private List readTxt() {
+
+        ArrayList list = new ArrayList();
+
+        /* 读取数据 */
+        try {
+            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("D:/1/test0009.txt")),
+                    "UTF-8"));
+            String lineTxt = null;
+            StringBuilder sb = new StringBuilder();
+            int sum = 0;
+            while ((lineTxt = br.readLine()) != null) {
+                sum+=1;
+                System.out.println("lineTxt="+lineTxt);
+                sb.append(lineTxt);
+//                Integer data = test7.hexToDec2(lineTxt);
+//                System.out.println("lineTxt="+lineTxt+" ,data="+data);
+//                dos.write(data);
+//                if(sum>=5){
+//                    break;
+//                }
+            }
+            br.close();
+            System.out.println("次数="+sum);
+            System.out.println(">>"+sb.toString());
+            String rawText = sb.toString();
+            String[] rawArray = rawText.split(";");
+            System.out.println("rawArray.length="+rawArray.length);
+
+            int x1 =0;
+            for(int a=0;a<rawArray.length;a++){
+//                System.out.println(rawArray[a]);
+                String text = rawArray[a];
+                String[] textArray = text.split(" ");
+                for(int b=0;b<textArray.length;b++){
+//                    System.out.println(""+textArray[b].toUpperCase());
+//                    sb2.append(textArray[b].toUpperCase());
+                    list.add(textArray[b].toUpperCase());
+                    x1++;
+                }
+            }
+//            System.out.println("x1="+x1);
+////            System.out.println("sb2.length="+sb2.length());
+            System.out.println("list.size="+list.size());
+//            for(int a=0;a<list.size();a++){
+//                System.out.println(""+list.get(a));
+//            }
+        } catch (Exception e) {
+            System.err.println("read errors :" + e);
+        } finally{
+            return list;
+        }
+    }
+}

+ 24 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/test8.java

@@ -0,0 +1,24 @@
+package com.huimv.eartag2.manage.utils;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class test8 {
+    public static void main(String[] args) {
+        String str = "000AB";
+        System.out.println("str="+str);
+        Integer in = Integer.valueOf(str,16);
+        System.out.println("in="+in);
+        String st = Integer.toHexString(in).toUpperCase();
+        System.out.println("st="+st);
+        st = String.format("%5s",st);
+        System.out.println("st="+st);
+        st= st.replaceAll(" ","0");
+        System.out.println("st="+st);
+    }
+}

+ 7 - 0
huimv-eartag2-platform/pom.xml

@@ -98,6 +98,13 @@
             <version>1.16.18</version>
             <scope>provided</scope>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.7</version>
+        </dependency>
+
     </dependencies>