From 1c549ae7af5f8d7bdeecb4ad38ab181af4831821 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期四, 29 二月 2024 18:07:41 +0800
Subject: [PATCH] 添加齐河项目的卡结构

---
 app/src/main/java/com/dayu/recharge/card/UserCard.java |  474 ++++++++++++++++++++++++++++-------------------------------
 1 files changed, 225 insertions(+), 249 deletions(-)

diff --git a/app/src/main/java/com/dayu/recharge/card/UserCard.java b/app/src/main/java/com/dayu/recharge/card/UserCard.java
index df69beb..90cb38a 100644
--- a/app/src/main/java/com/dayu/recharge/card/UserCard.java
+++ b/app/src/main/java/com/dayu/recharge/card/UserCard.java
@@ -4,36 +4,222 @@
 import com.dayu.recharge.tools.HexUtil;
 import com.dayu.recharge.utils.MornyUtil;
 import com.dayu.recharge.utils.MyCommon;
+import com.tencent.bugly.crashreport.CrashReport;
 
 import java.io.Serializable;
 import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
 
 /**
  * Copyright (C), 2023,
  * Author: zuo
  * Date: 2023-11-07 9:37
- * Description: 鐢ㄦ埛鍗$粨鏋�
+ * Description: 榻愭渤椤圭洰鐢ㄦ埛鍗$粨鏋�
  */
 public class UserCard implements Serializable {
     public String cardType = MyCommon.USER_CARD_TYPE_1;//鍐欏崱鏍囧織 A1鍒峰崱寮�娉靛墠 A8鍒峰崱寮�娉靛悗  A2鍙犲姞鍏呭��
 
-    public int rechargeTimes;//鍏呭�兼鏁�
+    public short arerNumber;//鍖哄煙鍙�(搴曚綅鍦ㄥ墠楂樹綅鍦ㄥ悗)
 
-    public short swipeNumber;//鍒峰崱娆℃暟 涓�鑸笉鐢ㄧ簿缁嗙鎺ф墠鐢�
+    public short deviceNumberl;//璁惧缂栧彿(搴曚綅鍦ㄥ墠楂樹綅鍦ㄥ悗)
+    public byte rechargeTimes;//鍏呭�兼鏁�
 
-    public float electricityPrice;//鐢甸噺鍗曚环 绠$悊鍏冨彲浠ヤ慨鏀�
+    public int totalWater;//鐢ㄦ埛鎬荤敤姘撮噺  搴曚綅鍦ㄥ墠锛岄珮浣嶅湪鍚�2浣嶅皬鏁扮偣  鍚袱涓皬鏁扮偣鐨勬暣鏁�
 
-    public String state = "00";//鍗$姸鎬� 杩斿啓鏌ヨ鍏呭�兼椂鍗$姸鎬佷綅
+    public int totalElectric;//鎬荤敤鐢甸噺浣� 搴曚綅鍦ㄥ墠锛岄珮浣嶅湪鍚�  1浣嶅皬鏁扮偣  鍚�1浣嶅皬鏁扮偣鐨勬暣鏁�
 
-    public int balance;//浣欓(鍗曚綅涓哄垎)
+    public int balance;//鍓╀綑閲戦 搴曚綅鍦ㄥ墠  2浣嶅皬鏁扮偣锛屽崟浣嶅厓
 
-    public String addressCode;//琛屾斂鍖哄煙
+    public int surplusWater;//鍓╀綑姘撮噺 搴曚綅鍦ㄥ墠  2浣嶅皬鏁扮偣銆�鍗曚綅绔嬫柟绫�
 
-    public Calendar rechargeDate;//璐按鏃堕棿
+    public Calendar rechargeDate;// 璐按鏃堕棿 BCD
 
-    public String initPeasantCode;//鐢ㄦ埛娉ㄥ唽缂栧彿
 
+    /**
+     * 閫氳繃byte杞琤ean
+     *
+     * @param data
+     */
+    public static UserCard getBean(List<byte[]> data) {
+        try {
+            UserCard userCard = new UserCard();
+            //绗�0鍧楄В鏋�
+            byte[] zero = data.get(0);
+
+            userCard.cardType = HexUtil.byteToHex(zero[0]);
+
+            byte[] arerNumberByte = new byte[2];
+            System.arraycopy(zero, 1, arerNumberByte, 0, arerNumberByte.length);
+            userCard.arerNumber = (short) HexUtil.get16to10LowHigh(HexUtil.bytesToHex(arerNumberByte));
+
+            byte[] deviceNumberlByte = new byte[2];
+            System.arraycopy(zero, 3, deviceNumberlByte, 0, deviceNumberlByte.length);
+            userCard.deviceNumberl = (short) HexUtil.get16to10LowHigh(HexUtil.bytesToHex(deviceNumberlByte));
+
+            userCard.rechargeTimes = HexUtil.hexToByte(HexUtil.byteToHex(zero[5]));
+
+            byte[] totalWaterByte = new byte[4];
+            System.arraycopy(zero, 3, totalWaterByte, 0, totalWaterByte.length);
+            userCard.totalWater = HexUtil.get16to10LowHigh(HexUtil.bytesToHex(totalWaterByte));
+
+            byte[] totalElectricByte = new byte[4];
+            System.arraycopy(zero, 3, totalElectricByte, 0, totalElectricByte.length);
+            userCard.totalElectric = HexUtil.get16to10LowHigh(HexUtil.bytesToHex(totalElectricByte));
+
+            //绗�1鍧楄В鏋�
+            byte[] one = data.get(1);
+
+            byte[] balanceByte = new byte[4];
+            System.arraycopy(one, 0, balanceByte, 0, balanceByte.length);
+            userCard.balance = HexUtil.get16to10LowHigh(HexUtil.bytesToHex(balanceByte));
+
+            byte[] surplusWaterByte = new byte[4];
+            System.arraycopy(one, 4, surplusWaterByte, 0, surplusWaterByte.length);
+            userCard.surplusWater = HexUtil.get16to10LowHigh(HexUtil.bytesToHex(surplusWaterByte));
+
+            byte[] rechargeDateByte = new byte[3];
+            System.arraycopy(one, 12, rechargeDateByte, 0, rechargeDateByte.length);
+
+            int year = HexUtil.getBcdToInt(one[12]);
+            int month = HexUtil.getBcdToInt(one[13]);
+            int day = HexUtil.getBcdToInt(one[14]);
+
+            Calendar calendar = Calendar.getInstance();
+            calendar.set(2000 + year, month, day, 0, 0, 0);
+            userCard.rechargeDate = calendar;
+
+            return userCard;
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+
+    }
+
+
+    /**
+     * 鐢ㄦ埛鍗�0鍧�
+     */
+    public class Zero extends BaseCard {
+        public byte[] toByte() {
+            try {
+                byte[] data = new byte[16];
+                data[0] = HexUtil.hexToByte(cardType);
+                byte[] arerNumberBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(arerNumber));
+                if (arerNumberBytes != null) {
+                    System.arraycopy(arerNumberBytes, 0, data, 1, arerNumberBytes.length);
+                }
+                byte[] deviceNumberlBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(deviceNumberl));
+                if (deviceNumberlBytes != null) {
+                    System.arraycopy(deviceNumberlBytes, 0, data, 3, deviceNumberlBytes.length);
+                }
+                byte rechargeTimesByte = HexUtil.hexToByte(HexUtil.get10to16(rechargeTimes));
+                data[5] = rechargeTimesByte;
+                byte[] totalWaterBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(totalWater));
+                if (totalWaterBytes != null) {
+                    System.arraycopy(totalWaterBytes, 0, data, 6, totalWaterBytes.length);
+                }
+                byte[] totalElectricBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(totalElectric));
+                if (totalElectricBytes != null) {
+                    System.arraycopy(totalElectricBytes, 0, data, 10, totalElectricBytes.length);
+                }
+                data[15] = getByteSum(data);
+                return data;
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
+            return null;
+        }
+
+    }
+
+    /**
+     * 鐢ㄦ埛鍗�1鍧�
+     */
+    public class One extends BaseCard {
+
+        public byte[] toBytes() {
+            byte[] data = new byte[16];
+
+
+            try {
+                byte[] balanceBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(balance));
+                if (balanceBytes != null) {
+                    System.arraycopy(balanceBytes, 0, data, 0, balanceBytes.length);
+                }
+
+                byte[] surplusWaterBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(surplusWater));
+                if (surplusWaterBytes != null) {
+                    System.arraycopy(surplusWaterBytes, 0, data, 0, surplusWaterBytes.length);
+                }
+
+
+                if (rechargeDate != null) {
+                    // 鑾峰彇骞淬�佹湀銆佹棩銆佹椂銆佸垎銆佺
+                    int year = (rechargeDate.get(Calendar.YEAR)) % 1000;
+                    int month = rechargeDate.get(Calendar.MONTH) + 1; // 鏈堜唤浠�0寮�濮嬶紝鎵�浠ラ渶瑕佸姞1
+                    int day = rechargeDate.get(Calendar.DAY_OF_MONTH);
+                    byte bcdYear = (byte) ((year / 10) << 4 | ((year % 10) / 100));
+                    byte bcdMonth = (byte) ((month / 10) << 4 | (month % 10));
+                    byte bcdDay = (byte) ((day / 10) << 4 | (day % 10));
+                    data[12] = bcdYear;
+                    data[13] = bcdMonth;
+                    data[14] = bcdDay;
+                }
+
+                data[15] = getByteSum(data);
+            } catch (Exception e) {
+                e.printStackTrace();
+                CrashReport.postCatchedException(e);
+            }
+            return data;
+        }
+
+
+    }
+
+    /**
+     * 鐢ㄦ埛鍗�2鍧�
+     */
+    public class Two extends BaseCard {
+        public byte[] toBytes() {
+            byte[] data = new byte[16];
+
+            try {
+                byte[] balanceBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(balance));
+                if (balanceBytes != null) {
+                    System.arraycopy(balanceBytes, 0, data, 0, balanceBytes.length);
+                }
+
+                byte[] surplusWaterBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(surplusWater));
+                if (surplusWaterBytes != null) {
+                    System.arraycopy(surplusWaterBytes, 0, data, 0, surplusWaterBytes.length);
+                }
+
+                if (rechargeDate != null) {
+                    // 鑾峰彇骞淬�佹湀銆佹棩銆佹椂銆佸垎銆佺
+                    int year = (rechargeDate.get(Calendar.YEAR)) % 1000;
+                    int month = rechargeDate.get(Calendar.MONTH) + 1; // 鏈堜唤浠�0寮�濮嬶紝鎵�浠ラ渶瑕佸姞1
+                    int day = rechargeDate.get(Calendar.DAY_OF_MONTH);
+                    byte bcdYear = (byte) ((year / 10) << 4 | ((year % 10) / 100));
+                    byte bcdMonth = (byte) ((month / 10) << 4 | (month % 10));
+                    byte bcdDay = (byte) ((day / 10) << 4 | (day % 10));
+                    data[12] = bcdYear;
+                    data[13] = bcdMonth;
+                    data[14] = bcdDay;
+                }
+
+                data[15] = getByteSum(data);
+            } catch (Exception e) {
+                e.printStackTrace();
+                CrashReport.postCatchedException(e);
+            }
+            return data;
+        }
+    }
 
     public byte[] getZeroBytes() {
         Zero zero = new Zero();
@@ -50,215 +236,6 @@
         return zero.toBytes();
     }
 
-    /**
-     * 閫氳繃byte杞琤ean
-     *
-     * @param data
-     */
-    public static UserCard getBean(List<byte[]> data) {
-        try {
-            UserCard userCard = new UserCard();
-            if (data != null) {
-                byte[] zero = data.get(0);
-                byte[] one = data.get(1);
-                byte[] two = data.get(2);
-                userCard.cardType = HexUtil.byteToHex(zero[0]);
-                userCard.rechargeTimes = HexUtil.get16to10(HexUtil.byteToHex(zero[1]));
-                byte[] swipeNumberBytes = new byte[2];
-                swipeNumberBytes[0] = zero[2];
-                swipeNumberBytes[1] = zero[3];
-                String swipeNumberHex = HexUtil.bytesToHex(swipeNumberBytes);
-                userCard.swipeNumber = (short) HexUtil.get16to10(swipeNumberHex);
-                byte[] electricityPriceBytes = new byte[4];
-                for (int i = 0; i < 4; i++) {
-                    electricityPriceBytes[i] = zero[i + 4];
-                }
-                userCard.electricityPrice = HexUtil.hexToFloat(HexUtil.bytesToHex(electricityPriceBytes));
-                userCard.state = BcdUtil.bcdToStr(zero[8]);
-                byte[] balanceBytes = new byte[4];
-                for (int i = 0; i < 4; i++) {
-                    balanceBytes[i] = zero[i + 9];
-                }
-                userCard.balance = HexUtil.get16to10LowHigh(HexUtil.bytesToHex(balanceBytes));
-
-                byte[] addressCodeBytes = new byte[6];
-                addressCodeBytes[0] = zero[13];
-                addressCodeBytes[1] = zero[14];
-                addressCodeBytes[2] = two[11];
-                addressCodeBytes[3] = two[12];
-                addressCodeBytes[4] = two[13];
-                addressCodeBytes[5] = two[14];
-                userCard.addressCode = BcdUtil.bcdToStr(addressCodeBytes);
-
-                int year = 0;
-                int month = 0;
-                int day = 0;
-                int hour = 0;
-                int minute = 0;
-                int second = 0;
-                for (int i = 0; i < 6; i++) {
-                    byte byteData = one[i + 4];
-                    switch (i) {
-                        case 0:
-                            year = getBcdToInt(byteData);
-                            break;
-                        case 1:
-                            month = getBcdToInt(byteData);
-                            break;
-                        case 2:
-                            day = getBcdToInt(byteData);
-                            break;
-                        case 3:
-                            hour = getBcdToInt(byteData);
-                            break;
-                        case 4:
-                            minute = getBcdToInt(byteData);
-                            break;
-                        case 5:
-                            second = getBcdToInt(byteData);
-                            break;
-                    }
-                }
-                Calendar calendar = Calendar.getInstance();
-                calendar.set(2000 + year, month, day, hour, minute, second);
-                byte[] initPeasantCodeBytes = new byte[16];
-                initPeasantCodeBytes[0] = one[10];
-                initPeasantCodeBytes[1] = one[11];
-                initPeasantCodeBytes[2] = one[12];
-                initPeasantCodeBytes[3] = one[13];
-                initPeasantCodeBytes[4] = one[14];
-                initPeasantCodeBytes[5] = two[0];
-                initPeasantCodeBytes[6] = two[1];
-                initPeasantCodeBytes[7] = two[2];
-                initPeasantCodeBytes[8] = two[3];
-                initPeasantCodeBytes[9] = two[4];
-                initPeasantCodeBytes[10] = two[5];
-                initPeasantCodeBytes[11] = two[6];
-                initPeasantCodeBytes[12] = two[7];
-                initPeasantCodeBytes[13] = two[8];
-                initPeasantCodeBytes[14] = two[9];
-                initPeasantCodeBytes[15] = two[10];
-                userCard.initPeasantCode = HexUtil.bytesToHex(initPeasantCodeBytes);
-                return userCard;
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
-        return null;
-    }
-
-
-    private static int getBcdToInt(byte data) {
-        return ((data & 0xF0) >> 4) * 10 + ((data & 0x0F));
-    }
-
-
-    /**
-     * 鐢ㄦ埛鍗�0鍧�
-     */
-    public class Zero extends BaseCard {
-        public byte[] toByte() {
-            byte[] data = new byte[16];
-            data[0] = HexUtil.hexToByte(cardType);
-            try {
-                data[1] = HexUtil.hexToByte(HexUtil.get10to16(rechargeTimes));
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-            byte[] swipeNumbers = HexUtil.hexToByteArray(HexUtil.get10to16(swipeNumber));
-            for (int i = 0; i < swipeNumbers.length; i++) {
-                data[i + 2] = swipeNumbers[i];
-            }
-            byte[] electricityPrices = HexUtil.hexToByteArray(HexUtil.folatToHexString(electricityPrice));
-            for (int i = 0; i < electricityPrices.length; i++) {
-                data[i + 4] = electricityPrices[i];
-            }
-            try {
-                data[8] = BcdUtil.strToBcd(state)[0];
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-            byte[] balances = HexUtil.hexToByteArray(HexUtil.get10to16LowHigh(balance, 8));
-            for (int i = 0; i < balances.length; i++) {
-                data[i + 9] = balances[i];
-            }
-            byte[] addresscodes = BcdUtil.strToBcd(addressCode);
-            data[13] = addresscodes[0];
-            data[14] = addresscodes[1];
-            data[15] = getByteSum(data);
-            return data;
-        }
-
-    }
-
-    /**
-     * 鐢ㄦ埛鍗�1鍧�
-     */
-    public class One extends BaseCard {
-
-        public byte[] toBytes() {
-            byte[] data = new byte[16];
-            byte[] balances = HexUtil.hexToByteArray(HexUtil.get10to16LowHigh(balance, 8));
-            for (int i = 0; i < balances.length; i++) {
-                data[i] = balances[i];
-            }
-            if (rechargeDate != null) {
-                // 鑾峰彇骞淬�佹湀銆佹棩銆佹椂銆佸垎銆佺
-
-//                bcdBytes[0] = (byte) ((year / 1000) << 4) | (byte) (year % 1000 / 100); // 骞翠唤鐨勫崄浣嶅拰涓綅锛堥珮瀛楄妭锛�
-//                bcdBytes[1] = (byte) ((year / 10 % 10) << 4) | (byte) (year % 10); // 骞翠唤鐨勫崄浣嶅拰涓綅锛堜綆瀛楄妭锛�
-                int year = (rechargeDate.get(Calendar.YEAR)) % 1000;
-                int month = rechargeDate.get(Calendar.MONTH) + 1; // 鏈堜唤浠�0寮�濮嬶紝鎵�浠ラ渶瑕佸姞1
-                int day = rechargeDate.get(Calendar.DAY_OF_MONTH);
-                int hour = rechargeDate.get(Calendar.HOUR_OF_DAY);
-                int minute = rechargeDate.get(Calendar.MINUTE);
-                int second = rechargeDate.get(Calendar.SECOND);
-
-                byte bcdYear = (byte) ((year / 10) << 4 | ((year % 10) / 100));
-                byte bcdMonth = (byte) ((month / 10) << 4 | (month % 10));
-                byte bcdDay = (byte) ((day / 10) << 4 | (day % 10));
-                byte bcdHour = (byte) ((hour / 10) << 4 | (hour % 10));
-                byte bcdMinute = (byte) ((minute / 10) << 4 | (minute % 10));
-                byte bcdSecond = (byte) ((second / 10) << 4 | (second % 10));
-                data[4] = bcdYear;
-                data[5] = bcdMonth;
-                data[6] = bcdDay;
-                data[7] = bcdHour;
-                data[8] = bcdMinute;
-                data[9] = bcdSecond;
-            }
-            byte[] initPeasantCodes = HexUtil.hexToByteArray(initPeasantCode);
-            for (int i = 0; i < 5; i++) {
-                data[i + 10] = initPeasantCodes[i];
-            }
-            data[15] = getByteSum(data);
-            return data;
-        }
-
-
-    }
-
-    /**
-     * 鐢ㄦ埛鍗�2鍧�
-     */
-    public class Two extends BaseCard {
-        public byte[] toBytes() {
-            byte[] data = new byte[16];
-            byte[] initPeasantCodes = HexUtil.hexToByteArray(initPeasantCode);
-            for (int i = 5; i < 16; i++) {
-                data[i - 5] = initPeasantCodes[i];
-            }
-            byte[] addresscodes = BcdUtil.strToBcd(addressCode);
-            data[11] = addresscodes[2];
-            data[12] = addresscodes[3];
-            data[13] = addresscodes[4];
-            data[14] = addresscodes[5];
-            data[15] = getByteSum(data);
-            return data;
-        }
-    }
-
 
     public String getCardType() {
         return cardType;
@@ -268,37 +245,44 @@
         this.cardType = cardType;
     }
 
-    public int getRechargeTimes() {
+    public short getArerNumber() {
+        return arerNumber;
+    }
+
+    public void setArerNumber(short arerNumber) {
+        this.arerNumber = arerNumber;
+    }
+
+    public short getDeviceNumberl() {
+        return deviceNumberl;
+    }
+
+    public void setDeviceNumberl(short deviceNumberl) {
+        this.deviceNumberl = deviceNumberl;
+    }
+
+    public byte getRechargeTimes() {
         return rechargeTimes;
     }
 
-    public void setRechargeTimes(int rechargeTimes) {
+    public void setRechargeTimes(byte rechargeTimes) {
         this.rechargeTimes = rechargeTimes;
     }
 
-
-    public short getSwipeNumber() {
-        return swipeNumber;
+    public int getTotalWater() {
+        return totalWater;
     }
 
-    public void setSwipeNumber(short swipeNumber) {
-        this.swipeNumber = swipeNumber;
+    public void setTotalWater(int totalWater) {
+        this.totalWater = totalWater;
     }
 
-    public float getElectricityPrice() {
-        return electricityPrice;
+    public int getTotalElectric() {
+        return totalElectric;
     }
 
-    public void setElectricityPrice(float electricityPrice) {
-        this.electricityPrice = electricityPrice;
-    }
-
-    public String getState() {
-        return state;
-    }
-
-    public void setState(String state) {
-        this.state = state;
+    public void setTotalElectric(int totalElectric) {
+        this.totalElectric = totalElectric;
     }
 
     public int getBalance() {
@@ -309,12 +293,12 @@
         this.balance = balance;
     }
 
-    public String getAddressCode() {
-        return addressCode;
+    public int getSurplusWater() {
+        return surplusWater;
     }
 
-    public void setAddressCode(String addressCode) {
-        this.addressCode = addressCode;
+    public void setSurplusWater(int surplusWater) {
+        this.surplusWater = surplusWater;
     }
 
     public Calendar getRechargeDate() {
@@ -323,14 +307,6 @@
 
     public void setRechargeDate(Calendar rechargeDate) {
         this.rechargeDate = rechargeDate;
-    }
-
-    public String getInitPeasantCode() {
-        return initPeasantCode;
-    }
-
-    public void setInitPeasantCode(String initPeasantCode) {
-        this.initPeasantCode = initPeasantCode;
     }
 
 

--
Gitblit v1.8.0