From 21eb47b061d16056f37eee47928c7fe629b63061 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期日, 12 十一月 2023 20:18:15 +0800
Subject: [PATCH] 实体修改用户密码功能,实现密码MD5加密功能,及其他代码完善
---
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java | 77 ++
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java | 1479 +++++++++++++++++++++++++++++++++++++++++++
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaUser.java | 1
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaUserMapper.java | 8
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtilUnsigned.java | 345 ++++++++++
pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java | 21
pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserMapper.xml | 12
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/MD5.java | 30
pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java | 18
pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/Constant.java | 45 +
10 files changed, 2,028 insertions(+), 8 deletions(-)
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java
new file mode 100644
index 0000000..7b06e4d
--- /dev/null
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtil.java
@@ -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;
+ }
+
+ /**
+ * 瀛楄妭鍙朾it
+ * @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;
+ }
+
+ /**
+ * 瀛楄妭鍙朾it
+ * @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;
+ }
+
+
+ /**
+ * 涓�涓瓧鑺傝浆姝f暣鏁�
+ *
+ * @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浣峛yte鏁扮粍
+ * @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浣峛yte鏁扮粍锛屽瓧鑺傞『搴忔槸鍊掔殑
+ * @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绫诲瀷杞崲鎴恇yte鏁扮粍
+ * @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绫诲瀷杞崲鎴恇yte鏁扮粍锛屽瓧鑺傞『搴忔槸鍊掔殑
+ * @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绫诲瀷杞崲鎴恇yte鏁扮粍
+ * @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绫诲瀷杞崲鎴恇yte鏁扮粍锛屽瓧鑺傞『搴忔槸鍊掔殑
+ * @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'};
+ /**
+ * 灏哹yte[]杞崲涓�16杩涘埗瀛楃涓�
+ *
+ * @param bytes 寰呰浆鎹yte[]
+ * @return 杞崲鍚庣殑瀛楃涓�
+ */
+ public static String bytesToHex(byte[] bytes) {
+ //涓�涓猙yte涓�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;
+ }
+
+ /**
+ * 澶х妯″紡銆婃暟鎹綆浣嶅湪鏁扮粍楂樺瓧鑺傘��
+ * 闀挎暣褰㈣浆鎴怋CD缂栫爜
+ * @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;
+ }
+
+ /**
+ * 灏忕妯″紡銆婃暟鎹綆浣嶅湪鏁扮粍浣庡瓧鑺傘��
+ * 闀挎暣褰㈣浆鎴怋CD缂栫爜锛屽瓧鑺傞『搴忔槸鍊掔殑
+ * @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锛岄『搴忔槸姝g殑
+ * @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] );
+ }
+ }
+
+
+
+ /**
+ * 澶х妯″紡銆婃暟鎹綆浣嶅湪鏁扮粍楂樺瓧鑺傘��
+ * 瑙g爜BCD锛岄『搴忔槸姝g殑
+ * @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("瑙g爜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("瑙g爜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);
+ }
+
+}
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtilUnsigned.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtilUnsigned.java
new file mode 100644
index 0000000..8635450
--- /dev/null
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/ByteUtilUnsigned.java
@@ -0,0 +1,345 @@
+package com.dy.common.util;
+
+@SuppressWarnings("unuseed")
+public class ByteUtilUnsigned {
+ /**
+ * 澶х妯″紡銆婃暟鎹綆浣嶅湪鏁扮粍楂樺瓧鑺傘��
+ * 鏃犵鍙穒nt绫诲瀷杞崲鎴�4浣峛yte鏁扮粍
+ * java娌℃湁鏃犵鍙锋暣鍨嬫暟鎹紝鍙湁鏈夌鍙锋暣鏁帮紝鍙栧�艰寖鍥存槸-2147483648~2147483647
+ * C鏈夋棤绗﹀彿鏁村瀷鏁版嵁锛屽彇鍊艰寖鍥存槸0鍒�4294967295锛屽凡缁忚秴鍑轰簡java鐨勬湁绗﹀彿鏁存暟涓婇檺锛屾墍浠ュ彧鑳界敤java鐨刲ong鍨嬭〃绀烘棤绗﹀彿鏁存暟
+ * @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鏃舵暟缁勮秺鐣�");
+ }
+ }
+
+
+ /**
+ * 灏忕妯″紡銆婃暟鎹綆浣嶅湪鏁扮粍浣庡瓧鑺傘��
+ * 涓庢柟娉昳nt2Bytes绠楁硶涓�鏍凤紝鍙槸鎶婇『搴忓弽杩囨潵
+ * @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鏃舵暟缁勮秺鐣�");
+ }
+ }
+
+ /**
+ * 灏忕妯″紡銆婃暟鎹綆浣嶅湪鏁扮粍浣庡瓧鑺傘��
+ * 涓庢柟娉昩ytes2Int绠楁硶涓�鏍凤紝鍙槸鎶婇『搴忓弽杩囨潵
+ * @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鏃舵暟缁勮秺鐣�");
+ }
+ }
+ /**
+ * 澶х妯″紡銆婃暟鎹綆浣嶅湪鏁扮粍楂樺瓧鑺傘��
+ * 鏃犵鍙穝hort绫诲瀷杞崲鎴�2浣峛yte鏁扮粍
+ * java娌℃湁鏃犵鍙风煭鏁村瀷鏁版嵁锛屽彧鏈夋湁绗﹀彿鐭暣鏁帮紝鍙栧�艰寖鍥存槸-32768~32767
+ * 鑻ユā鎷熸棤绗﹀彿鐭暣鍨嬫暟鎹紝鍙栧�艰寖鍥存槸0鍒�65535 锛屽凡缁忚秴鍑轰簡java鐨勬湁绗﹀彿鏁存暟涓婇檺锛屾墍浠ュ彧鑳界敤java鐨処nt鍨嬭〃绀烘棤绗﹀彿鏁存暟
+ * @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鏃舵暟缁勮秺鐣�");
+ }
+ }
+ /**
+ * 灏忕妯″紡銆婃暟鎹綆浣嶅湪鏁扮粍浣庡瓧鑺傘��
+ * 涓庢柟娉晄hort2Bytes绠楁硶涓�鏍凤紝鍙槸鎶婇『搴忓弽杩囨潵
+ * @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鏃舵暟缁勮秺鐣�");
+ }
+ }
+
+ /**
+ * 灏忕妯″紡銆婃暟鎹綆浣嶅湪鏁扮粍浣庡瓧鑺傘��
+ * 涓庢柟娉昩ytes2Short绠楁硶涓�鏍凤紝鍙槸鎶婇『搴忓弽杩囨潵
+ * @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 ;
+ }
+ }
+ /**
+ * 鏃犵鍙穝hort绫诲瀷杞崲鎴�1浣峛yte
+ * java娌℃湁鏃犵鍙风煭鏁村瀷鏁版嵁锛屽彧鏈夋湁绗﹀彿鐭暣鏁帮紝鍙栧�艰寖鍥存槸-128~127
+ * 鑻ユā鎷熸棤绗﹀彿鐭暣鍨嬫暟鎹紝鍙栧�艰寖鍥存槸0鍒�255 锛屽凡缁忚秴鍑轰簡java鐨勬湁绗﹀彿鏁存暟涓婇檺锛屾墍浠ュ彧鑳界敤java鐨剆hort鍨嬭〃绀烘棤绗﹀彿鏁存暟
+ * @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);
+ }
+ */
+}
diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/MD5.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/MD5.java
new file mode 100644
index 0000000..96b6ba2
--- /dev/null
+++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/MD5.java
@@ -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));
+ }
+ */
+}
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaUserMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaUserMapper.java
index 48f6d23..a3b347a 100644
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoBa/BaUserMapper.java
+++ b/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
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaUser.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaUser.java
index e192923..fa40e54 100644
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoBa/BaUser.java
+++ b/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;
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/Constant.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/Constant.java
new file mode 100644
index 0000000..c523017
--- /dev/null
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/util/Constant.java
@@ -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 ;
+ }
+
+}
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserMapper.xml
index efab302..6ed6777 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/BaUserMapper.xml
+++ b/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}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java
index e38a597..9368a24 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserCtrl.java
+++ b/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)){
+ /*
+ 濡傛灉鍓嶇杩涜浜哹ase64鍔犲瘑
+ 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 ;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
+ po.orgTag = null ;//璁剧疆涓簄ull锛屼笉鍋氭洿鏂�
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 = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝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("鏂板瘑鐮佷笉鑳戒负绌�") ;
+ }
+ /*
+ 濡傛灉鍓嶇杩涜浜哹ase64鍔犲瘑
+ 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("鏃у瘑鐮佷笉姝g‘锛岃姹傚け璐�") ;
+ }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 鏄惁鎴愬姛
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java
index 5a9b75e..d03c8ae 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-base/src/main/java/com/dy/pipIrrBase/user/UserSv.java
+++ b/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){
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
index 6ca0341..bc7b78e 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
+++ b/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)){
+ /*
+ 濡傛灉鍓嶇杩涜浜哹ase64鍔犲瘑
+ 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)){
+ /*
+ 濡傛灉鍓嶇杩涜浜哹ase64鍔犲瘑
+ 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);
--
Gitblit v1.8.0