liurunyu
2023-11-12 21eb47b061d16056f37eee47928c7fe629b63061
实体修改用户密码功能,实现密码MD5加密功能,及其他代码完善
4个文件已添加
6个文件已修改
2036 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java 1479 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtilUnsigned.java 345 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/MD5.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaUserMapper.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaUser.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/Constant.java 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserMapper.xml 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java
New file
@@ -0,0 +1,1479 @@
package com.dy.common.util;
import java.util.Locale;
public class ByteUtil {
    /**
     * 将字节数组合并到字节数组上
     * @param bGroup1 被合并数组
     * @param bGroup2 合并数组
     * @return 合并后数组
     */
    public static byte[] bytesMerge(byte[] bGroup1, byte[] bGroup2){
        if(bGroup1 == null && bGroup2 == null){
            return null ;
        }else if(bGroup1 == null && bGroup2 != null){
            return bGroup2 ;
        }else if(bGroup1 != null && bGroup2 == null){
            return bGroup1 ;
        }else{
            //dest != null && append != null
            byte[] bs = new byte[bGroup1.length + bGroup2.length] ;
            System.arraycopy(bGroup1, 0, bs, 0, bGroup1.length) ;
            System.arraycopy(bGroup2, 0, bs, bGroup1.length, bGroup2.length) ;
            return bs ;
        }
    }
    /**
     * 判断所有字节是否为0xFF
     * @param bs
     * @param index
     * @param len
     * @return
     * @throws Exception
     */
    public static boolean bytesIsAll0xFF(byte[] bs, int index, int len)throws Exception {
        int count = 0 ;
        for(int i = index; i < index + len; i++){
            if(bs[i] == (byte)0xFF){
                count++ ;
            }
        }
        return count==len?true:false ;
    }
    /**
     * 二进制转十进制数
     * @param str
     * @return
     * @throws Exception
     */
    public static int binary2Int(String str) throws Exception {
        int cnt=0;
        int sum=0;
        str=new StringBuilder(str).reverse().toString();//反转字符串
        for(int i=0;i<str.length();i++){
            cnt++;
            if (str.charAt(i)=='1'){
                int mul=1;
                for (int j=1;j<cnt;j++){
                    mul*=2;
                }
                sum+=mul;
            }
            else continue;
        }
        return sum;
    }
    /**
     * 字节转存二进制
     *
     * @param b byte
     * @throws Exception
     * @return String
     */
    public static String byte2Binary(byte b) throws Exception {
        int n = (b + 256) % 256 + 256;
        try {
            return Integer.toBinaryString(n).substring(1);
        } catch (Exception e) {
            throw new Exception("字节转换成二进制的字符串出错!", null);
        }
    }
    /**
     * 字节转存8位二进制
     *
     * @param b
     *            byte
     * @throws Exception
     * @return String
     */
    public static String byte2bit8Binary(byte b) throws Exception {
        String s = byte2Binary(b);
        int len = s.length();
        for (int i = 0; i < 8 - len; i++) {
            s = "0" + s;
        }
        return s;
    }
    /**
     * 字节取bit
     * @param b
     * @param index
     * @throws Exception
     * @return String
     */
    public static byte[] getBit(byte b) throws Exception {
        byte[] bs = new byte[8] ;
        bs[0] = (byte)(b & 1) ;
        bs[1] = (byte)((b & 2) >> 1) ;
        bs[2] = (byte)((b & 4) >> 2) ;
        bs[3] = (byte)((b & 8) >> 3) ;
        bs[4] = (byte)((b & 16) >> 4) ;
        bs[5] = (byte)((b & 32) >> 5) ;
        bs[6] = (byte)((b & 64) >> 6) ;
        bs[7] = (byte)((b & 128) >> 7) ;
        return bs;
    }
    /**
     * 字节取bit
     * @param b
     * @param index
     * @throws Exception
     * @return String
     */
    public static byte getBit(byte b, byte index) throws Exception {
        if(index == 0){
            return (byte)(b & 1) ;
        }else if(index == 1){
            return (byte)((b & 2) >> 1) ;
        }else if(index == 2){
            return (byte)((b & 4) >> 2) ;
        }else if(index == 3){
            return (byte)((b & 8) >> 3) ;
        }else if(index == 4){
            return (byte)((b & 16) >> 4) ;
        }else if(index == 5){
            return (byte)((b & 32) >> 5) ;
        }else if(index == 6){
            return (byte)((b & 64) >> 6) ;
        }else if(index == 7){
            return (byte)((b & 128) >> 7) ;
        }
        return 0;
    }
    /**
     * 一个字节转正整数
     *
     * @param b
     *            byte
     * @throws Exception
     * @return String
     */
    public static Short byte2PlusInt(byte b) throws Exception {
        short v = b ;
        if(v < 0){
            v = (short)(255 + v + 1) ;
        }
        return v ;
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * double转换byte
     * @param bs byte[]
     * @param value double double类型的参数
     * @param from int
     */
    public static void double2Bytes_BE(byte[] bs, double value, int from)throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 8);
        if (b) {
            Long l = Double.doubleToLongBits(value);
            long2Bytes_BE(bs, l, from);
        } else {
            throw new Exception("double2Bytes时数组越界");
        }
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * double转换byte,字节顺序是倒的
     * @param bs byte[]
     * @param value double double类型的参数
     * @param from int
     */
    public static void double2Bytes_LE(byte[] bs, double value, int from)throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 8);
        if (b) {
            Long l = Double.doubleToLongBits(value);
            long2Bytes_LE(bs, l, from);
        } else {
            throw new Exception("double2Bytes时数组越界");
        }
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * byte转换double
     * @param bs byte[]
     * @param from int
     */
    public static double bytes2Double_BE(byte[] bs, int from) throws Exception {
        long l = bytes2Long_BE(bs, from);
        return Double.longBitsToDouble(l);
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * byte转换double,字节顺序是倒的
     * @param bs byte[]
     * @param from int
     */
    public static double bytes2Double_LE(byte[] bs, int from) throws Exception {
        long l = bytes2Long_LE(bs, from);
        return Double.longBitsToDouble(l);
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * float转换byte
     * @value bs byte[]
     * @value value float float类型的参数
     * @value from int
     */
    public static void float2Bytes_BE(byte[] bs, float value, int from)
            throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 4);
        if (b) {
            Integer it = Float.floatToIntBits(value);
            int2Bytes_BE(bs, it, from);
        } else {
            throw new Exception("float2Bytes时数组越界");
        }
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * float转换byte,字节顺序是倒的
     * @value bs byte[]
     * @value value float float类型的参数
     * @value from int
     */
    public static void float2Bytes_LE(byte[] bs, float value, int from) throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 4);
        if (b) {
            Integer it = Float.floatToIntBits(value);
            int2Bytes_LE(bs, it, from);
        } else {
            throw new Exception("float2Bytes时数组越界");
        }
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * byte转换float
     * @value bs byte[]
     * @value from int
     */
    public static float bytes2Float_BE(byte[] bs, int from) throws Exception {
        int i = bytes2Int_BE(bs, from);
        return Float.intBitsToFloat(i);
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * byte转换float,字节顺序是倒的
     * @value bs byte[]
     * @value from int
     */
    public static float bytes2Float_LE(byte[] bs, int from) throws Exception {
        int i = bytes2Int_LE(bs, from);
        return Float.intBitsToFloat(i);
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 转换long型为byte数组
     * @value bs byte[]
     * @value value long
     * @value from int
     */
    public static void long2Bytes_BE(byte[] bs, long value, int from)throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 8);
        if (b) {
            for (int i = 7; i >= 0; i--) {
                bs[from + i] = Long.valueOf(value & 0xff).byteValue();// 将最低位保存在最低位
                value = value >> 8; // 向右移8位
                if(value == 0){
                    break ;
                }
            }
        } else {
            throw new Exception("long2Bytes时数组越界");
        }
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 转换long型为byte数组
     * @value bs byte[]
     * @value value long
     * @value from int
     */
    public static void long2Bytes_LE(byte[] bs, long value, int from)throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 8);
        if (b) {
            for (int i = 0; i < 8; i++) {
                bs[from + i] = Long.valueOf(value & 0xff).byteValue();
                value = value >> 8;
            if(value == 0){
                break ;
            }
            }
        } else {
            throw new Exception("long2Bytes时数组越界");
        }
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 8位字节数组转换为长整型
     * @param bs byte[]
     * @return
     */
    public static long bytes2Long_BE(byte[] bs) {
        int len = bs.length ;
        if (len > 0) {
            long l = 0;
            long[] ls = new long[len] ;
            for(int i = 0 ; i < len; i++){
                ls[i] = bs[i] ;
            }
            for(int i = len-1 ; i >= 0; i--){
                ls[(len - 1) - i] <<= 8 * i ;
            }
            for(int i = 0 ; i < len; i++){
                l = l | ls[i] ;
            }
            return l;
        }
        return 0L ;
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 8位字节数组转换为长整型
     * @param bs byte[]
     * @param from int
     * @return
     */
    public static long bytes2Long_BE(byte[] bs, int from) throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 8);
        if (b) {
            long s = 0;
            long s0 = bs[from + 0] ;// 最低位
            long s1 = bs[from + 1] ;
            long s2 = bs[from + 2] ;
            long s3 = bs[from + 3] ;
            long s4 = bs[from + 4] ;
            long s5 = bs[from + 5] ;
            long s6 = bs[from + 6] ;
            long s7 = bs[from + 7] ;
            // s7不变
            s6 <<= 8;
            s5 <<= 16;
            s4 <<= 24;
            s3 <<= 8 * 4;
            s2 <<= 8 * 5;
            s1 <<= 8 * 6;
            s0 <<= 8 * 7;
            s = s0 | s1 | s2 | s3 | s4 | s5 | s6 | s7;
            return s;
        } else {
            throw new Exception("byte2Long时数组越界");
        }
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 8位字节数组转换为长整型
     * @param bs byte[]
     * @param from int
     * @param end int
     * @return
     */
    public static long bytes2Long_BE(byte[] bs, int from, int end) throws Exception {
        boolean b = isOutOfArrLength(bs.length, end);
        if (b) {
            short len = (short)(end - from + 1) ;
            long[] ls = new long[len] ;
            for(short i = 0 ; i < len; i++){
                ls[i] = bs[from + i] ;
            }
            for(short i = (short)(len-1) ; i >= 0; i--){
                ls[i] <<= 8 * (len - (i + 1)) ;
            }
            long s = 0;
            for(short i = 0 ; i < len; i++){
                s = s | ls[i] ;
            }
            return s;
        } else {
            throw new Exception("byte2Long时数组越界");
        }
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 8位字节数组转换为长整型
     * @param bs byte[]
     * @return
     */
    public static long bytes2Long_LE(byte[] bs) {
        int len = bs.length ;
        if (len > 0) {
            long l = 0;
            long[] ls = new long[len] ;
            for(int i = 0 ; i < len; i++){
                ls[i] = bs[i] ;
            }
            for(int i = 0 ; i < len; i++){
                ls[(len - 1) - i] <<= 8 * i ;
            }
            for(int i = 0 ; i < len; i++){
                l = l | ls[i] ;
            }
            return l;
        }
        return 0L ;
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 8位字节数组转换为长整型
     * @param bs byte[]
     * @param from int
     * @return
     */
    public static long bytes2Long_LE(byte[] bs, int from) throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 8);
        if (b) {
            long s = 0;
            long s0 = bs[from + 0] ;// 最低位
            long s1 = bs[from + 1] ;
            long s2 = bs[from + 2] ;
            long s3 = bs[from + 3] ;
            long s4 = bs[from + 4] ;
            long s5 = bs[from + 5] ;
            long s6 = bs[from + 6] ;
            long s7 = bs[from + 7] ;
            // s0不变
            s1 <<= 8;
            s2 <<= 16;
            s3 <<= 24;
            s4 <<= 8 * 4;
            s5 <<= 8 * 5;
            s6 <<= 8 * 6;
            s7 <<= 8 * 7;
            s = s0 | s1 | s2 | s3 | s4 | s5 | s6 | s7;
            return s;
        } else {
            throw new Exception("byte2Long时数组越界");
        }
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 8位字节数组转换为长整型
     * @param bs byte[]
     * @param from int
     * @param end int
     * @return
     */
    public static long bytes2Long_LE(byte[] bs, int from, int end) throws Exception {
        boolean b = isOutOfArrLength(bs.length, end);
        if (b) {
            short len = (short)(end - from + 1) ;
            long[] ls = new long[len] ;
            for(short i = 0 ; i < len; i++){
                ls[i] = bs[from + i] ;
            }
            for(short i = 0 ; i < len; i++){
                ls[i] <<= 8 * i ;
            }
            long s = 0;
            for(short i = 0 ; i < len; i++){
                s = s | ls[i] ;
            }
            return s;
        } else {
            throw new Exception("byte2Long时数组越界");
        }
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * int类型转换成4位byte数组
     * @value bs byte[]
     * @value value int int类型的参数
     * @value from int
     */
    public static void int2Bytes_BE(byte[] bs, int value, int from)throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 4);
        if (b) {
            for (int i = 3; i >= 0; i--) {
                bs[from + i] = Integer.valueOf(value & 0xff).byteValue();// 将最低位保存在高字节
                value = value >> 8; // 向右移8位
                if(value == 0){
                    break ;
                }
            }
        } else {
            throw new Exception("int2Bytes时数组越界");
        }
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * int类型转换成4位byte数组,字节顺序是倒的
     * @value bs byte[]
     * @value value int int类型的参数
     * @value from int
     */
    public static void int2Bytes_LE(byte[] bs, int value, int from)throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 4);
        if (b) {
            for (int i = 0; i < 4; i++) {
                bs[from + i] = Integer.valueOf(value & 0xff).byteValue();// 将最低位保存在低字节
                value = value >> 8; // 向右移8位
            if(value == 0){
                break ;
            }
            }
        } else {
            throw new Exception("int2Bytes时数组越界");
        }
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 4位字节数组转换为整型
     * @param b
     * @return
     */
    public static int bytes2Int_BE(byte[] bs, int from) throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 4);
        if (b) {
            int s = 0;
            int s0 = bs[from + 0] ;// 最低位
            int s1 = bs[from + 1] ;
            int s2 = bs[from + 2] ;
            int s3 = bs[from + 3] ;
            // s3不变
            s2 <<= 8;
            s1 <<= 16;
            s0 <<= 24;
            s = s0 | s1 | s2 | s3;
            return s;
        } else {
            throw new Exception("byte2Int时数组越界");
        }
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 4位字节数组转换为整型,字节顺序是倒的
     * @param b
     * @return
     */
    public static int bytes2Int_LE(byte[] bs, int from) throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 4);
        if (b) {
            int s = 0;
            int s0 = bs[from + 0] ;// 最低位
            int s1 = bs[from + 1] ;
            int s2 = bs[from + 2] ;
            int s3 = bs[from + 3] ;
            // s0不变
            s1 <<= 8;
            s2 <<= 16;
            s3 <<= 24;
            s = s0 | s1 | s2 | s3;
            return s;
        } else {
            throw new Exception("byte2Int时数组越界");
        }
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * short类型转换成byte数组
     * @value bs byte[]
     * @value value short
     * @value from int
     */
    public static void short2Bytes_BE(byte[] bs, short value, int from)throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 2);
        if (b) {
            for (int i = 1; i >= 0 ; i--) {
                bs[from + i] = Integer.valueOf(value & 0xff).byteValue();// 将低位保存在高字节
                value = (short) (value >> 8); // 向右移8位
            }
        } else {
            throw new Exception("short2Bytes时数组越界");
        }
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * short类型转换成byte数组,字节顺序是倒的
     * @value bs byte[]
     * @value value short
     * @value from int
     */
    public static void short2Bytes_LE(byte[] bs, short value, int from)throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 2);
        if (b) {
            for (int i = 0; i < 2; i++) {
                bs[from + i] = Integer.valueOf(value & 0xff).byteValue();// 将最低位保存在低字节
                value = (short) (value >> 8); // 向右移8位
            }
        } else {
            throw new Exception("short2Bytes时数组越界");
        }
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * short类型转换成byte数组
     * @value value short
     * @value from int
     */
    public static byte[] short2Bytes_BE(short value)throws Exception {
        byte[] bs = new byte[2] ;
        for (int i = 1; i >= 0 ; i--) {
            bs[i] = (byte)(value & 0xff) ;// 将低位保存在高字节
            value = (short) (value >> 8); // 向右移8位
        }
        return bs ;
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * short类型转换成byte数组,字节顺序是倒的
     * @value value short
     * @value from int
     */
    public static byte[] short2Bytes_LE(short value)throws Exception {
        byte[] bs = new byte[2] ;
        for (int i = 0; i < 2; i++) {
            bs[i] = (byte)(value & 0xff) ;// 将最低位保存在低字节
            value = (short) (value >> 8); // 向右移8位
        }
        return bs ;
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 2位字节数组转换为短整型
     * @param b
     * @return
     */
    public static short bytes2Short_BE(byte[] bs, int from) throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 2);
        if (b) {
            int s = 0;
            int s0 = bs[from + 0] ;
            int s1 = bs[from + 1] ;
            // s1不变
            s0 <<= 8;
            s = s0 | s1;
            return (short) s;
        } else {
            throw new Exception("byte2Short时数组越界");
        }
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 2位字节数组转换为短整型,字节顺序是倒的
     * @param b
     * @return
     */
    public static short bytes2Short_LE(byte[] bs, int from) throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 2);
        if (b) {
            int s = 0;
            int s0 = bs[from + 0] ;
            int s1 = bs[from + 1] ;
            // s0不变
            s1 <<= 8;
            s = s0 | s1;
            return (short) s;
        } else {
            throw new Exception("byte2Short时数组越界");
        }
    }
    /**
     * 字符到一字节转换
     *
     * @value bs byte[]
     * @value ch char char类型的参数
     * @value index int
     * @return
     */
    public static void char2Bytes(byte[] bs, char ch, int index)throws Exception {
        boolean b = isOutOfArrLength(bs.length, index);
        if (b) {
            bs[index] = (byte) ch;
        } else {
            throw new Exception("char2Bytes时数组越界");
        }
    }
    /**
     * 一字节转换为字符
     *
     * @param b
     * @value index int
     * @return
     */
    public static char bytes2Char(byte[] bs, int index) throws Exception {
        boolean b = isOutOfArrLength(bs.length, index);
        if (b) {
            return (char) bs[index];
        } else {
            throw new Exception("byte2Char时数组越界");
        }
    }
    /**
     * 字符串型数字转成byte
     *
     * @param s
     * @return
     * @throws Exception
     */
    public static byte string2byte(String s) throws Exception {
        int n = 0;
        try {
            n = Integer.parseInt(s);
        } catch (Exception e) {
            throw new Exception("字符串型数字字节时出错,不是合法数字:" + s, null);
        }
        return (byte) n;
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 字符串转换成byte数组
     * @value bs byte[]
     * @value str String
     * @value from int
     * @return
     * @throws java.io.UnsupportedEncodingException
     */
    public static int string2Bytes_BE(byte[] bs, String str, int from, int end)throws Exception {
        byte[] bb = str.getBytes();
        boolean b = isOutOfArrLength(bs.length, (from -1 + bb.length));
        if (b) {
            if(end - from + 1 < bb.length){
                throw new Exception("string2Bytes时,字符串转成的字节数组超过的协议定义的长度 ");
            }else{
                for (int i = 0; i < bb.length; i++) {
                    bs[from + i] = bb[i];
                }
            }
        } else {
            throw new Exception("string2Bytes时数组越界");
        }
        return bb.length ;
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 字符串转换成byte数组
     * @value bs byte[]
     * @value str String
     * @value from int
     * @return
     * @throws java.io.UnsupportedEncodingException
     */
    public static int string2Bytes_LE(byte[] bs, String str, int from, int end)throws Exception {
        byte[] bb = str.getBytes();
        boolean b = isOutOfArrLength(bs.length, (from -1 + bb.length));
        if (b) {
            if(end - from + 1 < bb.length){
                throw new Exception("string2Bytes时,字符串转成的字节数组超过的协议定义的长度 ");
            }else{
                for (int i = bb.length - 1; i >= 0; i--) {
                    bs[from + i] = bb[i];
                }
            }
        } else {
            throw new Exception("string2Bytes时数组越界");
        }
        return bb.length ;
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 字符串转换成byte数组
     * @value bs byte[]
     * @value str String
     * @value from int
     * @return
     * @throws java.io.UnsupportedEncodingException
     */
    public static int string2Bytes_BE(byte[] bs, String str, int from)throws Exception {
        byte[] bb = str.getBytes();
        boolean b = isOutOfArrLength(bs.length, (from -1 + bb.length));
        if (b) {
            for (int i = 0; i < bb.length; i++) {
                bs[from + i] = bb[i];
            }
        } else {
            throw new Exception("string2Bytes时数组越界");
        }
        return bb.length ;
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 字符串转换成byte数组
     * @value bs byte[]
     * @value str String
     * @value from int
     * @return
     * @throws java.io.UnsupportedEncodingException
     */
    public static int string2Bytes_LE(byte[] bs, String str, int from)throws Exception {
        byte[] bb = str.getBytes();
        boolean b = isOutOfArrLength(bs.length, (from -1 + bb.length));
        if (b) {
            for (int i = bb.length-1; i >= 0; i--) {
                bs[from + i] = bb[i];
            }
        } else {
            throw new Exception("string2Bytes时数组越界");
        }
        return bb.length ;
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * byte数组转换成字符串
     * @value bs byte[]
     * @value str String
     * @value from int
     * @throws java.io.UnsupportedEncodingException
     */
    public static String bytes2String_BE(byte[] bs, int from, int end)throws Exception {
        byte[] bb = new byte[end - from + 1];
        int count = 0 ;
        for (int i = from; i <= end; i++) {
            bb[count++] = bs[i];
        }
        return new String(bb);
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * byte数组转换成字符串
     * @value bs byte[]
     * @value str String
     * @value from int
     * @throws java.io.UnsupportedEncodingException
     */
    public static String bytes2String_LE(byte[] bs, int from, int end)throws Exception {
        byte[] bb = new byte[end - from + 1];
        int count = 0 ;
        for (int i = end; i >= from; i--) {
            bb[count++] = bs[i];
        }
        return new String(bb);
    }
    /**
     * 判断数组下标是否越界
     *
     * @value bsLength 数组总长度
     * @value toSite 数组偏移量
     * @return
     */
    private static boolean isOutOfArrLength(int bsLength, int toSite) {
        if (bsLength > toSite) {
            return true;
        } else {
            return false;
        }
    }
    /**
     * 字节数组转换成十六进制的字符串
     *
     * @param b byte[]
     * @param hasBlank 16进制是否用空格分隔
     * @return String
     */
    public static String bytes2Hex(byte[] src, boolean hasBlank){
        StringBuilder stringBuilder = new StringBuilder("");
        if (src == null || src.length <= 0) {
            return null;
        }
        for (int i = 0; i < src.length; i++) {
            int v = src[i] & 0xFF;
            String str = Integer.toHexString(v);
            if (str.length() < 2) {
                str = "0" + str;
            }
            if (hasBlank) {
                if (i == 0) {
                    stringBuilder.append(str);
                } else {
                    stringBuilder.append(" " + str);
                }
            } else {
                stringBuilder.append(str);
            }
        }
        return stringBuilder.toString().toUpperCase(Locale.US);
    }
    /**
     * 字节数组转换成十六进制的字符串
     *
     * @param b byte[]
     * @param hasBlank 16进制是否用空格分隔
     * @param from
     * @param len
     * @return String
     */
    public static String bytes2Hex(byte[] src, boolean hasBlank, int from, int len){
        if (src == null || src.length <= 0 || src.length < from + len) {
            return null;
        }
        byte[] bb = new byte[len];
        for (int i = 0 ; i < len; i++) {
            bb[i] = src[from + i];
        }
        return bytes2Hex(bb, hasBlank) ;
    }
    /**
     * 十六进制转字节数组
     * @param hexString the hex string
     * @return byte[]
     */
    public static byte[] hex2Bytes(String hex) {
        if (hex == null || hex.equals("")) {
            return null;
        }
        hex = hex.toUpperCase(Locale.ENGLISH);
        int length = hex.length() / 2;
        char[] hexChars = hex.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;
    }
    /**
     * 十六进制转字节数组
     * @param hexString the hex string
     * @return byte[]
     */
    public static int hex2Bytes(String hex, byte[] bs, int fromIndex) {
        if (hex == null || hex.equals("")) {
            return fromIndex;
        }
        hex = hex.toUpperCase(Locale.ENGLISH);
        int length = hex.length() / 2;
        char[] hexChars = hex.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]));
        }
        for(int i = 0 ; i < d.length; i++){
            bs[fromIndex++] = d[i] ;
        }
        return fromIndex ;
    }
    private static final char[] HEX_CHAR = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
    /**
     * 将byte[]转换为16进制字符串
     *
     * @param bytes 待转换byte[]
     * @return 转换后的字符串
     */
    public static String bytesToHex(byte[] bytes) {
        //一个byte为8位,可用两个十六进制位标识
        char[] buf = new char[bytes.length * 2];
        int a = 0;
        int index = 0;
        for (byte b : bytes) { // 使用除与取余进行转换
            if (b < 0) {
                a = 256 + b;
            } else {
                a = b;
            }
            buf[index++] = HEX_CHAR[a / 16];
            buf[index++] = HEX_CHAR[a % 16];
        }
        return new String(buf);
    }
    /**
     * 将16进制字符串转换为byte[]
     *
     * @param str 待转换字符串
     * @return 转换后的byte[]
     */
    public static byte[] hexToBytes(String str) {
        if (str == null || "".equals(str.trim())) {
            return new byte[0];
        }
        byte[] bytes = new byte[str.length() / 2];
        for (int i = 0; i < str.length() / 2; i++) {
            String subStr = str.substring(i * 2, i * 2 + 2);
            bytes[i] = (byte) Integer.parseInt(subStr, 16);
        }
        return bytes;
    }
    /**
     * Convert char to byte
     * @param c char
     * @return byte
     */
    private static byte charToByte(char c) {
        return (byte) "0123456789ABCDEF".indexOf(c);
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 整形转成BCD编码
     * @param l
     * @return
     */
    public static byte[] int2BCD_BE(int i)throws Exception {
        String str = "" + i;
        byte[] b = null;
        if (str.length() % 2 == 0) {
            b = new byte[str.length() / 2];
        } else {
            b = new byte[(str.length() / 2) + 1];
        }
        encodeBCD_BE(str, b, 0, b.length);
        return b;
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 整形转成BCD编码,字节顺序是倒的
     * @param l
     * @return
     */
    public static byte[] int2BCD_LE(int i)throws Exception {
        String str = "" + i;
        byte[] b = null;
        if (str.length() % 2 == 0) {
            b = new byte[str.length() / 2];
        } else {
            b = new byte[(str.length() / 2) + 1];
        }
        encodeBCD_LE(str, b, 0, b.length);
        return b;
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 长整形转成BCD编码
     * @param l
     * @return
     */
    public static byte[] long2BCD_BE(long l)throws Exception {
        String str = "" + l;
        byte[] b = null;
        if (str.length() % 2 == 0) {
            b = new byte[str.length() / 2];
        } else {
            b = new byte[(str.length() / 2) + 1];
        }
        encodeBCD_BE(str, b, 0, b.length);
        return b;
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 长整形转成BCD编码,字节顺序是倒的
     * @param l
     * @return
     */
    public static byte[] long2BCD_LE(long l) throws Exception {
        String str = "" + l;
        byte[] b = null;
        if (str.length() % 2 == 0) {
            b = new byte[str.length() / 2];
        } else {
            b = new byte[(str.length() / 2) + 1];
        }
        encodeBCD_LE(str, b, 0, b.length);
        return b;
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 字符串型数字转成BCD编码
     * @param s
     * @return
     * @throws Exception
     */
    public static byte[] string2BCD_BE(String s) throws Exception {
        byte[] b = null;
        if (s.length() % 2 == 0) {
            b = new byte[s.length() / 2];
        } else {
            b = new byte[(s.length() / 2) + 1];
        }
        encodeBCD_BE(s, b, 0, b.length);
        return b ;
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 字符串转换成byte数组
     * @value bs byte[]
     * @value str String
     * @value fromIndex int
     * @return
     * @throws java.io.Exception
     */
    public static int string2BCD_BE(byte[] bs, String str, int fromIndex)throws Exception {
        byte[] bb = string2BCD_BE(str);
        boolean b = isOutOfArrLength(bs.length, (fromIndex -1 + bb.length));
        if (b) {
            for (int i = 0; i < bb.length; i++) {
                bs[fromIndex + i] = bb[i];
            }
        } else {
            throw new Exception("string2BCD时数组越界");
        }
        return bb.length ;
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 字符串型数字转成BCD编码,字节顺序是倒的
     * @param s
     * @return
     * @throws Exception
     */
    public static byte[] string2BCD_LE(String s) throws Exception {
        byte[] b = null;
        if (s.length() % 2 == 0) {
            b = new byte[s.length() / 2];
        } else {
            b = new byte[(s.length() / 2) + 1];
        }
        encodeBCD_LE(s, b, 0, b.length);
        return b;
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 字符串转换成byte数组
     * @value bs byte[]
     * @value str String
     * @value fromIndex int
     * @return
     * @throws java.io.Exception
     */
    public static int string2BCD_LE(byte[] bs, String str, int fromIndex)throws Exception {
        byte[] bb = string2BCD_LE(str);
        boolean b = isOutOfArrLength(bs.length, (fromIndex -1 + bb.length));
        if (b) {
            for (int i = bb.length-1; i >= 0 ; i--) {
                bs[fromIndex + i] = bb[i];
            }
        } else {
            throw new Exception("string2BCD时数组越界");
        }
        return bb.length ;
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * BCD编码转成整型
     * @param b
     * @param startIndex
     * @param endIndex
     * @return
     * @throws Exception
     */
    public static int BCD2Int_BE(byte b) throws Exception {
        String str = "";
        str = decodeBCD_BE(new byte[] { b }, 0, 1);
        int n = Integer.parseInt(str);
        return n;
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * BCD编码转成整型,字节顺序是倒的
     * @param b
     * @param startIndex
     * @param endIndex
     * @return
     * @throws Exception
     */
    public static int BCD2Int_LE(byte b) throws Exception {
        String str = "";
        str = decodeBCD_LE(new byte[] { b }, 0, 1);
        int n = Integer.parseInt(str);
        return n;
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * BCD编码转成整型
     * @param b
     * @param startIndex
     * @param endIndex
     * @return
     * @throws Exception
     */
    public static int BCD2Int_BE(byte[] b, int startIndex, int endIndex)throws Exception {
        String str = "";
        str = decodeBCD_BE(b, startIndex, endIndex - startIndex + 1);
        int n = Integer.parseInt(str);
        return n;
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * BCD编码转成整型,字节顺序是倒的
     * @param b
     * @param startIndex
     * @param endIndex
     * @return
     * @throws Exception
     */
    public static int BCD2Int_LE(byte[] b, int startIndex, int endIndex)throws Exception {
        String str = "";
        str = decodeBCD_LE(b, startIndex, endIndex - startIndex + 1);
        int n = Integer.parseInt(str);
        return n;
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * BCD编码转成字符串型
     * @param b
     * @param startIndex
     * @param endIndex
     * @return
     * @throws Exception
     */
    public static long BCD2Long_BE(byte[] b, int startIndex, int endIndex)throws Exception {
        String str = "";
        str = decodeBCD_BE(b, startIndex, endIndex - startIndex + 1);
        long n = Long.parseLong(str);
        return n;
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * BCD编码转成字符串型,字节顺序是倒的
     * @param b
     * @param startIndex
     * @param endIndex
     * @return
     * @throws Exception
     */
    public static long BCD2Long_LE(byte[] b, int startIndex, int endIndex)throws Exception {
        String str = "";
        str = decodeBCD_LE(b, startIndex, endIndex - startIndex + 1);
        long n = Long.parseLong(str);
        return n;
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * BCD编码转成字符串型
     * @param b
     * @param startIndex
     * @param endIndex
     * @return
     * @throws Exception
     */
    public static String BCD2String_BE(byte[] b, int startIndex, int endIndex) throws Exception {
        return decodeBCD_BE(b, startIndex, endIndex - startIndex + 1);
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * BCD编码转成字符串型,字节顺序是倒的
     * @param b
     * @param startIndex
     * @param endIndex
     * @return
     * @throws Exception
     */
    public static String BCD2String_LE(byte[] b, int startIndex, int endIndex) throws Exception {
        return decodeBCD_LE(b, startIndex, endIndex - startIndex + 1);
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 编码BCD,例如1387编码成  13  87,顺序是正的
     * @param value
     * @param dest
     * @param startIndex
     * @param length
     */
    private static void encodeBCD_BE(String value, byte[] dest, int startIndex, int length)throws Exception {
        if (value == null || !value.matches("\\d*")) {
            throw new Exception("数字转成BCD编码时出错,不是合法数字:" + value, null);
        }
        int[] tmpInts = new int[2 * length];
        int index = value.length() - 1;
        for (int i = tmpInts.length - 1; i >= 0 && index >= 0; i--, index--) {
            tmpInts[i] = value.charAt(index) - '0';
        }
        for (int i = startIndex, j = 0; i < startIndex + length; i++, j++) {
            dest[i] = (byte) (tmpInts[2 * j] * 16 + tmpInts[2 * j + 1]);
        }
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 编码BCD,例如1387编码成  87  13,顺序是倒的
     * @param value
     * @param dest
     * @param startIndex
     * @param length
     */
    private static void encodeBCD_LE(String value, byte[] dest, int startIndex, int length)throws Exception {
        if (value == null || !value.matches("\\d*")) {
            throw new Exception("数字转成BCD编码时出错,不是合法数字:" + value, null);
        }
        int[] tmpInts = new int[2 * length];
        int index = value.length() - 1;
        for (int i = 0; i <= tmpInts.length - 1 && index >= 0; i++, index--) {
            tmpInts[i] = value.charAt(index) - '0';
        }
        for (int i = startIndex, j = 0; i < startIndex + length; i++, j++) {
            dest[i] = (byte) (tmpInts[2 * j + 1] * 16 + tmpInts[2 * j] );
        }
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 解码BCD,顺序是正的
     * @param src
     * @param startIndex
     * @param length
     * @return
     */
    private static String decodeBCD_BE(byte[] src, int startIndex, int length)throws Exception {
        StringBuilder sb = new StringBuilder();
        for (int i = startIndex; i < startIndex + length ; i++) {
            int value = (src[i] + 256) % 256;
            sb.append((char) (value / 16 + '0')).append((char) (value % 16 + '0'));
            value++;
        }
        String result = sb.toString();
        if (!result.matches("\\d*")) {
            throw new Exception("解码BCD,但数据(" + result + "[startIndex=" + startIndex + ",length=" + length + "])非BCD码!");
        }
        return result;
    }
    /**
     * 小端模式《数据低位在数组低字节》
      * 编码BCD,顺序是倒的
     * @param src
     * @param startIndex
     * @param length
     * @return
     */
    private static String decodeBCD_LE(byte[] src, int startIndex, int length)throws Exception {
        StringBuilder sb = new StringBuilder();
        for (int i = (startIndex + length - 1); i >= startIndex; i--) {
            int value = (src[i] + 256) % 256;
            sb.append((char) (value / 16 + '0')).append((char) (value % 16 + '0'));
        }
        String result = sb.toString();
        if (!result.matches("\\d*")) {
            throw new Exception("解码BCD,但数据(" + result + "[startIndex=" + startIndex + ",length=" + length + "])非BCD码!");
        }
        return result;
    }
//    public static void main(String[] args) throws Exception {
//        // 帧头 + 帧长度 + 终端ID + 功能码 + 数据
//        int len = 2 + 4 + 4 + 2 + (4 + 4);
//
//        byte[] b = new byte[len];
//        ByteUtil.int2Bytes(b, 1234567890, 0);
//        int v1 = ByteUtil.bytes2Int(b, 0);
//        System.out.println(v1);
//
//        b = new byte[len];
//        ByteUtil.short2Bytes(b, (short) -1234, 0);
//        short v2 = ByteUtil.bytes2Short(b, 0);
//        System.out.println(v2);
//
//        b = new byte[len];
//        ByteUtil.long2Bytes(b, 4638387438405602509L, 0);
//        long v3 = ByteUtil.bytes2Long(b, 0);
//        System.out.println(v3);
//
//        b = new byte[len];
//        ByteUtil.float2Bytes(b, (float) -123456.45, 0);
//        float v4 = ByteUtil.bytes2Float(b, 0);
//        System.out.println(v4);
//
//        b = new byte[len];
//        ByteUtil.double2Bytes(b, -256.1234567890123D, 0);
//        double v5 = ByteUtil.bytes2Double(b, 0);
//        System.out.println(v5);
//
//    }
    public static void main(String[] args) throws Exception {
        byte[] bs = new byte[]{0x38, 0x36, 0x39, 0x31} ;
        String s = bytes2String_BE(bs, 0, 3) ;
        System.out.println(s);
        byte[] bss = new byte[]{(byte)0x8F} ;
        int v = bss[0] ;
        System.out.println(v);
        if(v < 0){
            v = 255 + v + 1 ;
        }
        System.out.println(v);
    }
}
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtilUnsigned.java
New file
@@ -0,0 +1,345 @@
package com.dy.common.util;
@SuppressWarnings("unuseed")
public class ByteUtilUnsigned {
    /**
     * 大端模式《数据低位在数组高字节》
     * 无符号int类型转换成4位byte数组
     * java没有无符号整型数据,只有有符号整数,取值范围是-2147483648~2147483647
     * C有无符号整型数据,取值范围是0到4294967295,已经超出了java的有符号整数上限,所以只能用java的long型表示无符号整数
     * @value bs byte[]
     * @value value int int类型的参数
     * @value from int
     * @throws Exception 异常
     */
    public static void int2Bytes_BE(byte[] bs, long value, int from)throws Exception {
        int len = 4 ;
        Long maxIntUnsigned = Long.valueOf(Integer.MAX_VALUE * 2 + 1) ;
        Long minIntUnsigned = Long.valueOf(Integer.MIN_VALUE * 2) ;
        if(value < minIntUnsigned || value > maxIntUnsigned ){
            throw new Exception("数据" + value + "超出了无符号Int型的取值范围(" + minIntUnsigned + "~" + maxIntUnsigned + ")") ;
        }
        int temp ;
        if(value > Integer.MAX_VALUE){
            temp = (Long.valueOf(value - (Integer.MAX_VALUE * 2 + 1) - 1)).intValue() ;
        }else{
            temp = Long.valueOf(value).intValue() ;
        }
        boolean b = isOutOfArrLength(bs.length, (from - 1) + len);
        if (!b) {
            for (int i = (len - 1); i >= 0; i--) {
                bs[from + i] = Integer.valueOf(temp & 0xff).byteValue();//将最低位保存在高字节
                temp = temp >> 8; // 向右移8位
            }
        } else {
            throw new Exception("int2Bytes时数组越界");
        }
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 与方法int2Bytes算法一样,只是把顺序反过来
     * @value bs byte[]
     * @value value int int类型的参数
     * @value from int
     */
    public static void int2Bytes_LE(byte[] bs, long value, int from)throws Exception {
        int len = 4 ;
        Long maxIntUnsigned = Long.valueOf(Integer.MAX_VALUE) * 2 + 1;
        Long minIntUnsigned = Long.valueOf(Integer.MIN_VALUE) * 2 ;
        if(value < minIntUnsigned || value > maxIntUnsigned ){
            throw new Exception("数据" + value + "超出了无符号Int型的取值范围(" + minIntUnsigned + "~" + maxIntUnsigned + ")") ;
        }
        int temp ;
        if(value > Integer.MAX_VALUE){
            temp = (Long.valueOf(value - (Integer.MAX_VALUE * 2 + 1) - 1)).intValue() ;
        }else{
            temp = Long.valueOf(value).intValue() ;
        }
        boolean b = isOutOfArrLength(bs.length, (from - 1) + len);
        if (!b) {
            for (int i = 0; i > len ; i++) {
                bs[from + i] = Integer.valueOf(temp & 0xff).byteValue();// 将最低位保存在低字节
                temp = temp >> 8; // 向右移8位
            }
        } else {
            throw new Exception("int2Bytes时数组越界");
        }
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 4位字节数组转换为整型
     * @param bs 字节数组
     * @param from 起始位置
     * @return 结果
     */
    public static long bytes2Int_BE(byte[] bs, int from) throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 4);
        if (!b) {
            long s = 0;
            long s0 = bs[from + 0] & 0xFF ;// 数据的最高位在低字节
            long s1 = bs[from + 1] & 0xFF ;
            long s2 = bs[from + 2] & 0xFF ;
            long s3 = bs[from + 3] & 0xFF ;
            // 最低位S3不变
            s0 <<= 24;
            s1 <<= 16;
            s2 <<= 8;
            s = s0 | s1 | s2 | s3;
            if(s < 0){
                //s = Integer.MAX_VALUE -s ;
                s = Integer.MAX_VALUE * 2 + 1 + s + 1 ;
            }
            return s;
        } else {
            throw new Exception("byte2Int时数组越界");
        }
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 与方法bytes2Int算法一样,只是把顺序反过来
     * @param bs 字节数组
     * @param from 字节数组起始位置
     * @return
     */
    public static long bytes2Int_LE(byte[] bs, int from) throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 4);
        if (!b) {
            long s = 0;
            long s0 = bs[from + 0] & 0xFF ;// 数据的最低位在低字节
            long s1 = bs[from + 1] & 0xFF ;
            long s2 = bs[from + 2] & 0xFF ;
            long s3 = bs[from + 3] & 0xFF ;
            // S0不变
            s1 <<= 8;
            s2 <<= 16;
            s3 <<= 24;
            s = s0 | s1 | s2 | s3;
            if(s < 0){
                //s = Integer.MAX_VALUE -s ;
                s = Integer.MAX_VALUE * 2 + 1 + s + 1 ;
            }
            return s;
        } else {
            throw new Exception("byte2Int时数组越界");
        }
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 无符号short类型转换成2位byte数组
     * java没有无符号短整型数据,只有有符号短整数,取值范围是-32768~32767
     * 若模拟无符号短整型数据,取值范围是0到65535 ,已经超出了java的有符号整数上限,所以只能用java的Int型表示无符号整数
     * @value bs byte[]
     * @value value int int类型的参数
     * @value from int
     */
    public static void short2Bytes_BE(byte[] bs, int value, int from)throws Exception {
        int maxShortUnsigned = Integer.valueOf(Short.MAX_VALUE) * 2 + 1;
        int minShortUnsigned = Integer.valueOf(Short.MIN_VALUE) * 2 ;
        if(value < minShortUnsigned || value > maxShortUnsigned ){
            throw new Exception("数据" + value + "超出了无符号short型的取值范围(" + minShortUnsigned + "~" + maxShortUnsigned + ")") ;
        }
        short temp = 0 ;
        if(value > Short.MAX_VALUE){
            temp = (Integer.valueOf(value - (Short.MAX_VALUE * 2 + 1) - 1)).shortValue() ;//(Integer.valueOf(Short.MAX_VALUE - value)).shortValue() ;
        }else{
            temp = Integer.valueOf(value).shortValue() ;
        }
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 2);
        if (!b) {
            for (int i = 1; i >= 0; i--) {
                bs[from + i] = Integer.valueOf(temp & 0xff).byteValue();//将最低位保存在高字节
                temp = (short)(temp >> 8); // 向右移8位
            }
        } else {
            throw new Exception("short2Bytes时数组越界");
        }
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 与方法short2Bytes算法一样,只是把顺序反过来
     * @value bs byte[]
     * @value value int int类型的参数
     * @value from int
     */
    public static void short2Bytes_LE(byte[] bs, int value, int from)throws Exception {
        int len = 2 ;
        int maxShortUnsigned = Integer.valueOf(Short.MAX_VALUE) * 2 + 1;
        int minShortUnsigned = Integer.valueOf(Short.MIN_VALUE) * 2 ;
        if(value < minShortUnsigned || value > maxShortUnsigned ){
            throw new Exception("数据" + value + "超出了无符号short型的取值范围(" + minShortUnsigned + "~" + maxShortUnsigned + ")") ;
        }
        short temp = 0 ;
        if(value > Short.MAX_VALUE){
            temp = (Integer.valueOf(value - (Short.MAX_VALUE * 2 + 1) - 1)).shortValue() ;//(Integer.valueOf(Short.MAX_VALUE - value)).shortValue() ;
        }else{
            temp = Integer.valueOf(value).shortValue() ;
        }
        boolean b = isOutOfArrLength(bs.length, (from - 1) + len);
        if (!b) {
            for (int i = 0; i < len; i++) {
                bs[from + i] = Integer.valueOf(temp & 0xff).byteValue();//将数据低位保存在数据低字节
                temp = (short)(temp >> 8); // 向右移8位
            }
        } else {
            throw new Exception("short2Bytes时数组越界");
        }
    }
    /**
     * 大端模式《数据低位在数组高字节》
     * 2位字节数组转换为短整型
     * @param bs 字节数组
     * @param from 字节数组起始位置
     * @return 结果
     */
    public static int bytes2Short_BE(byte[] bs, int from) throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 2);
        if (!b) {
            int s = 0;
            int s0 = Integer.valueOf(bs[from + 0] & 0xff).shortValue();// 最低位
            int s1 = Integer.valueOf(bs[from + 1] & 0xff).shortValue();
            // 最低位S1不变
            s0 <<= 8;
            s = s0 | s1 ;
            if(s < 0){
                s = (Short.MAX_VALUE * 2 + 1) + s + 1;
            }
            return s;
        } else {
            throw new Exception("bytes2Short时数组越界");
        }
    }
    /**
     * 小端模式《数据低位在数组低字节》
     * 与方法bytes2Short算法一样,只是把顺序反过来
     * @param bs 字节数组
     * @param from 字节数组起始位置
     * @return 结果
     */
    public static int bytes2Short_LE(byte[] bs, int from) throws Exception {
        boolean b = isOutOfArrLength(bs.length, (from - 1) + 2);
        if (!b) {
            int s = 0;
            int s0 = Integer.valueOf(bs[from + 0] & 0xff).shortValue();// 小下标字节转数据低位
            int s1 = Integer.valueOf(bs[from + 1] & 0xff).shortValue();// 大下标字节转数据高位
            // 最低位S0不变
            s1 <<= 8;
            s = s1 | s0 ;
            if(s < 0){
                s = (Short.MAX_VALUE * 2 + 1) + s + 1;
            }
            return s;
        } else {
            throw new Exception("bytes2Short时数组越界");
        }
    }
    /**
     * 1位字节数组转换为短整型
     * @param bs 字节数组
     * @param index 字节数组起始位置
     * @return 结果
     */
    public static short byte2Byte(byte[] bs, int index) throws Exception {
        if (bs.length - 1 < index) {
            throw new Exception("byte2Short(byte[] bs, int index)时数组越界");
        } else {
            byte bv = (byte)(bs[index] & 0xff) ;
            short s = 0 ;
            if(bv < 0){
                s = (short)(Byte.MAX_VALUE * 2 + 1 + bv + 1) ;
            }else{
                s = bv ;
            }
            return s ;
        }
    }
    /**
     * 无符号short类型转换成1位byte
     * java没有无符号短整型数据,只有有符号短整数,取值范围是-128~127
     * 若模拟无符号短整型数据,取值范围是0到255 ,已经超出了java的有符号整数上限,所以只能用java的short型表示无符号整数
     * @value bs byte[] 字节数组
     * @value value short short类型的参数
     * @value index 起始位置
     */
    public static void byte2Byte(byte[] bs, short value, int index)throws Exception {
        int maxShortUnsigned = Integer.valueOf(Byte.MAX_VALUE) * 2 + 1;
        int minShortUnsigned = Integer.valueOf(Byte.MIN_VALUE) * 2 ;
        if(value < minShortUnsigned || value > maxShortUnsigned ){
            throw new Exception("数据" + value + "超出了无符号byte型的取值范围(" + minShortUnsigned + "~" + maxShortUnsigned + ")") ;
        }
        if (bs.length - 1 < index) {
            throw new Exception("byte2Byte(byte[] bs, short value, int index)时数组越界");
        } else {
            bs[index] = Integer.valueOf(value & 0xff).byteValue() ;
        }
    }
    /**
     * 判断所有字节是否为0xFF
     * @param bs  字节数组
     * @param index 起始位置
     * @param len 长度
     * @return 结果
     * @throws Exception
     */
    public static boolean bytesIsAll0xFF(byte[] bs, int index, int len)throws Exception {
        int count = 0 ;
        for(int i = index; i < index + len; i++){
            if(bs[i] == (byte)0xFF){
                count++ ;
            }
        }
        return count==len?true:false ;
    }
    /**
     * 判断数组下标是否越界
     *
     * @value bsLength 数组总长度
     * @value toSite 数组偏移量
     * @return 结果
     */
    private static boolean isOutOfArrLength(int bsLength, int toSite) {
        if (bsLength > toSite) {
            return false;
        } else {
            return true;
        }
    }
    /*
    public static void main(String[] args) throws Exception{
//        int d = 123456;
//        byte[] bs = new byte[4] ;
//        int2Bytes_BE(bs, d, 0) ;
//        System.out.println(ByteUtil.bytes2Hex(bs, false));
//        long dd = bytes2Int_BE(bs, 0) ;
//        System.out.println(dd);
//
//        byte[] bb = new byte[1] ;
//        bb[0] = (byte)255 ;
//        short s = byte2Byte(bb, 0);
//        System.out.println(s);
        byte[] bs = new byte[]{(byte)0x00, (byte)0x00, (byte)0x3A, (byte)0x88} ;
        //byte[] bs = new byte[]{(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff} ;
        boolean flag = ByteUtilUnsigned.bytesIsAll0xFF(bs, 0, 4) ;
        System.out.println(flag);
        Long s = ByteUtilUnsigned.bytes2Int_BE(bs, 0);
        System.out.println(s);
    }
    */
}
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/MD5.java
New file
@@ -0,0 +1,30 @@
package com.dy.common.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5 {
    /**
     * MD5加密
     * @param str 待加密字符串
     * @return 16进制加密字符串
     * @throws Exception 异常
     */
    public static String encrypt(String str) throws Exception{
        MessageDigest md5 = MessageDigest.getInstance("MD5") ;
        byte[] digest = md5.digest(str.getBytes("utf-8")) ;
        return ByteUtil.bytes2Hex(digest, false) ;
    }
    /*
    public static void main(String[] args) throws Exception{
        String str = "123456" ;
        System.out.println(encrypt(str));
        str = "admin!@#,;." ;
        System.out.println(encrypt(str));
        str = "admin!@#,;.admin!@#,;.admin!@#,;." ;
        System.out.println(encrypt(str));
        str = "1" ;
        System.out.println(encrypt(str));
    }
    */
}
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaUserMapper.java
@@ -65,6 +65,14 @@
    int updateByPrimaryKey(BaUser record);
    /**
     * update record
     * @param id 实体ID
     * @param password 新密码
     * @return update count
     */
    int changePassword(@Param("id") Long id, @Param("password") String password) ;
    /**
     * delete by primary key
     * @param id primaryKey
     * @return deleteCount
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaUser.java
@@ -36,6 +36,7 @@
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "用户实体")
public class BaUser implements BaseEntity {
    public static final long serialVersionUID = 202310100926001L;
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/Constant.java
New file
@@ -0,0 +1,45 @@
package com.dy.pipIrrGlobal.util;
import java.util.ArrayList;
import java.util.List;
public class Constant {
    /**
     * 是与否
     */
    public static final Integer yes = 1 ;
    public static final Integer no = 0 ;
    public static final String YES = "1" ;
    public static final String NO = "0" ;
    public static List<String[]> yesNo(){
        List<String[]> list = new ArrayList<>() ;
        list.add(new String[]{YES , "是"}) ;
        list.add(new String[]{NO , "否"}) ;
        return list ;
    }
    public static String getYesNo(Integer flag){
        if(flag != null){
            if(flag.intValue() == yes.intValue()){
                return "是" ;
            }else
            if(flag.intValue() == no.intValue()){
                return "否" ;
            }
        }
        return null ;
    }
    public static String getYesNo(String flag){
        if(flag != null){
            if(flag.equals(YES)){
                return "是" ;
            }else
            if(flag.equals(NO)){
                return "否" ;
            }
        }
        return null ;
    }
}
pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserMapper.xml
@@ -44,7 +44,7 @@
    </sql>
    <sql id="part_Column_List">
        id, name, phone, orgTag, disabled
        id, name, phone, disabled
    </sql>
    <sql id="Login_Column_List">
@@ -61,7 +61,7 @@
    <select id="selectTotal" parameterType="java.util.Map" resultType="java.lang.Long">
        select
        count(*)
        from ba_user where supperAdmin!=1 and disabled!=1 and deleted!=1
        from ba_user where supperAdmin!=1 and deleted!=1
        <trim prefix="and" suffixOverrides="and">
            <if test="name != null">
                name like concat('%', #{name}, '%') and
@@ -74,7 +74,7 @@
    <select id="selectSome" parameterType="java.util.Map" resultMap="someResultMap">
        select
        <include refid="part_Column_List" />
        from ba_user where supperAdmin!=1 and disabled!=1 and deleted!=1
        from ba_user where supperAdmin!=1 and deleted!=1
        <trim prefix="and" suffixOverrides="and">
            <if test="name != null">
                name like concat('%', #{name}, '%') and
@@ -188,6 +188,12 @@
        deleted = #{deleted,jdbcType=TINYINT}
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="changePassword" >
        update ba_user
        set password = #{password,jdbcType=VARCHAR}
        where id = #{id,jdbcType=BIGINT}
    </update>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from ba_user
        where id = #{id,jdbcType=BIGINT}
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java
@@ -1,11 +1,16 @@
package com.dy.pipIrrBase.user;
import com.dy.common.aop.SsoAop;
import com.dy.common.multiDataSource.DataSourceContext;
import com.dy.common.mybatis.envm.Deleted;
import com.dy.common.mybatis.envm.Disabled;
import com.dy.common.util.MD5;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.common.webUtil.ResultCodeMsg;
import com.dy.pipIrrGlobal.pojoBa.BaUser;
import com.mysql.cj.util.StringUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
@@ -107,6 +112,16 @@
        po.id = null ;
        int count;
        try {
            po.disabled = Disabled.NO ;//默认不禁用
            po.deleted = Deleted.NO ;//默认不删除
            po.orgTag = DataSourceContext.get() ;//机构标签
            if(!StringUtils.isNullOrEmpty(po.password)){
                /*
                如果前端进行了base64加密
                po.password = new String(Base64.getDecoder().decode(po.password)) ;
                */
                po.password = MD5.encrypt(po.password) ;//进行加密码
            }
            count = this.sv.save(po);
        } catch (Exception e) {
            log.error("保存用户异常", e);
@@ -144,6 +159,8 @@
        }
        int count;
        try {
            po.deleted = null ;//设置为null,不做更新
            po.orgTag = null ;//设置为null,不做更新
            count = this.sv.update(po);
        } catch (Exception e) {
            log.error("保存用户异常", e);
@@ -158,6 +175,66 @@
    /**
     * 修改密码
     * @param id 用户ID
     * @return 是否成功
     */
    @Operation(summary = "修改密码", description = "提交用户ID、旧密码、新密码,进行改密码")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "操作结果:true:成功,false:失败(BaseResponse.content)",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = Boolean.class))}
            )
    })
    @GetMapping(path = "changePassword", consumes = MediaType.TEXT_PLAIN_VALUE)
    @SsoAop("-1")//@SsoAop(power = "-1")
    public BaseResponse<Boolean> changePassword(@Parameter(description = "实体id", required = true) Long id,
                                                @Parameter(description = "旧密码", required = true) String oldPassword,
                                                @Parameter(description = "新密码", required = true) String newPassword) throws Exception{
        if(id == null){
            return BaseResponseUtils.buildFail("id不能为空") ;
        }
        if(StringUtils.isNullOrEmpty(oldPassword)){
            return BaseResponseUtils.buildFail("旧密码不能为空") ;
        }
        if(StringUtils.isNullOrEmpty(newPassword)){
            return BaseResponseUtils.buildFail("新密码不能为空") ;
        }
        /*
        如果前端进行了base64加密
        oldPassword = new String(Base64.getDecoder().decode(oldPassword)) ;
        newPassword = new String(Base64.getDecoder().decode(newPassword)) ;
        */
        oldPassword = MD5.encrypt(oldPassword) ;//进行加密码
        newPassword = MD5.encrypt(newPassword) ;//进行加密码
        int count ;
        try {
            BaUser po = this.sv.selectById(id);
            if(Objects.isNull(po)){
                return BaseResponseUtils.buildFail("未得到用户,请求失败") ;
            }else{
                if(!po.password.equalsIgnoreCase(oldPassword)){
                    return BaseResponseUtils.buildFail("旧密码不正确,请求失败") ;
                }else{
                    count = this.sv.changePassword(id, newPassword) ;
                }
            }
        } catch (Exception e) {
            log.error("保存用户异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
        if(count <= 0){
            return BaseResponseUtils.buildFail("数据库存储失败") ;
        }else{
            return BaseResponseUtils.buildSuccess(true) ;
        }
    }
    /**
     * 删除用户
     * @param id 用户ID
     * @return 是否成功
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java
@@ -3,7 +3,6 @@
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.daoBa.BaUserMapper;
import com.dy.pipIrrGlobal.pojoBa.BaDistrict;
import com.dy.pipIrrGlobal.pojoBa.BaUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -17,7 +16,6 @@
@Slf4j
@Service
//public class UserSv extends MPJBaseServiceImpl<BaUserMapper, BaUser> {
public class UserSv {
    private BaUserMapper dao;
@@ -58,7 +56,7 @@
    /**
     * 保存实体
     * @param po 实体
     * @return 数量
     * @return 影响记录数量
     */
    @Transactional
    public int save(BaUser po){
@@ -68,7 +66,7 @@
    /**
     * 保存修改实体
     * @param po 实体
     * @return 数量
     * @return 影响记录数量
     */
    @Transactional
    public int update(BaUser po){
@@ -76,9 +74,19 @@
    }
    /**
     * 修改密码
     * @param id 用户ID
     * @param password 新密码
     * @return 影响记录数量
     */
    public int changePassword(Long id, String password){
        return this.dao.changePassword(id, password) ;
    }
    /**
     * 保存修改实体
     * @param id 实体ID
     * @return 数量
     * @return 影响记录数量
     */
    @Transactional
    public int delete(Long id){
pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
@@ -2,10 +2,12 @@
import com.dy.common.aop.SsoVo;
import com.dy.common.multiDataSource.DataSourceContext;
import com.dy.common.util.MD5;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.ResultCodeMsg;
import com.dy.pipIrrGlobal.pojoBa.BaUser;
import com.mysql.cj.util.StringUtils;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -80,12 +82,24 @@
        if(bindingResult != null && bindingResult.hasErrors()){
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        if(vo.orgTag == null || vo.orgTag.trim().length() == 0){
            return BaseResponseUtils.buildFail("未选择组织单位");
        }
        //把组织单位标签作为数据源名称
        DataSourceContext.set(vo.orgTag);
        String uuid ;
        BaUser userPo ;
        try {
            //Boolean flag = cacheManager.getCacheNames().isEmpty() ;
            uuid = UUID.randomUUID().toString();
            if(!StringUtils.isNullOrEmpty(vo.password)){
                /*
                如果前端进行了base64加密
                po.password = new String(Base64.getDecoder().decode(po.password)) ;
                */
                vo.password = MD5.encrypt(vo.password) ;
            }
            userPo = this.sv.loginWithMapperXml(uuid, vo.phone, vo.password);
        } catch (Exception e) {
            log.error("用户登录异常", e);
@@ -131,6 +145,13 @@
        try {
            //Boolean flag = cacheManager.getCacheNames().isEmpty() ;
            uuid = UUID.randomUUID().toString();
            if(!StringUtils.isNullOrEmpty(vo.password)){
                /*
                如果前端进行了base64加密
                po.password = new String(Base64.getDecoder().decode(po.password)) ;
                */
                vo.password = MD5.encrypt(vo.password) ;
            }
            userPo = this.sv.loginWithMapperXml(uuid, vo.phone, vo.password);
        } catch (Exception e) {
            log.error("用户登录异常", e);