From feb7add1979c830e0d940286242a7c489f2f8f96 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期五, 27 九月 2024 09:23:34 +0800
Subject: [PATCH] 优化NFC模块架构,将一些方法抽调到父类中。

---
 qihealonelibrary/src/main/java/com/dayu/qihealonelibrary/card/UserCard.java |  100 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 61 insertions(+), 39 deletions(-)

diff --git a/qihealonelibrary/src/main/java/com/dayu/qihealonelibrary/card/UserCard.java b/qihealonelibrary/src/main/java/com/dayu/qihealonelibrary/card/UserCard.java
index d9bee63..b814a8c 100644
--- a/qihealonelibrary/src/main/java/com/dayu/qihealonelibrary/card/UserCard.java
+++ b/qihealonelibrary/src/main/java/com/dayu/qihealonelibrary/card/UserCard.java
@@ -1,5 +1,6 @@
 package com.dayu.qihealonelibrary.card;
 
+import com.dayu.baselibrary.bean.BaseUserCardCard;
 import com.dayu.baselibrary.tools.HexUtil;
 import com.dayu.qihealonelibrary.utils.CardCommon;
 import com.tencent.bugly.crashreport.CrashReport;
@@ -14,21 +15,21 @@
  * Date: 2023-11-07 9:37
  * Description: 榻愭渤椤圭洰鐢ㄦ埛鍗$粨鏋�
  */
-public class UserCard implements Serializable {
+public class UserCard extends BaseUserCardCard implements Serializable {
     public String cardType = CardCommon.USER_CARD_TYPE_1;//鍐欏崱鏍囧織 A1鍒峰崱寮�娉靛墠 A8鍒峰崱寮�娉靛悗  A2鍙犲姞鍏呭��
 
-    public short arerNumber;//鍖哄煙鍙�(搴曚綅鍦ㄥ墠楂樹綅鍦ㄥ悗)
+    public int arerNumber;//鍖哄煙鍙�(搴曚綅鍦ㄥ墠楂樹綅鍦ㄥ悗)
 
-    public short deviceNumberl;//璁惧缂栧彿(搴曚綅鍦ㄥ墠楂樹綅鍦ㄥ悗)
-    public byte rechargeTimes;//鍏呭�兼鏁�
+    public int deviceNumberl;//璁惧缂栧彿(搴曚綅鍦ㄥ墠楂樹綅鍦ㄥ悗)
+    public short rechargeTimes;//鍏呭�兼鏁�
 
     public int totalWater;//鐢ㄦ埛鎬荤敤姘撮噺  搴曚綅鍦ㄥ墠锛岄珮浣嶅湪鍚�2浣嶅皬鏁扮偣  鍚袱涓皬鏁扮偣鐨勬暣鏁�
 
     public int totalElectric;//鎬荤敤鐢甸噺浣� 搴曚綅鍦ㄥ墠锛岄珮浣嶅湪鍚�  1浣嶅皬鏁扮偣  鍚�1浣嶅皬鏁扮偣鐨勬暣鏁�
 
-    public int balance;//鍓╀綑閲戦 搴曚綅鍦ㄥ墠  2浣嶅皬鏁扮偣锛屽崟浣嶅厓
+    public int balance;//鍓╀綑閲戦 搴曚綅鍦ㄥ墠  2浣嶅皬鏁扮偣锛屽崟浣嶅垎
 
-    public int surplusWater;//鍓╀綑姘撮噺 搴曚綅鍦ㄥ墠  2浣嶅皬鏁扮偣銆�鍗曚綅绔嬫柟绫�
+    public int surplusWater;//鍓╀綑姘撮噺 搴曚綅鍦ㄥ墠  2浣嶅皬鏁扮偣銆�鍗曚綅绔嬫柟绫� (璺熶环鏍间竴鏍峰厛涔樹互100)
 
     public Calendar rechargeDate;// 璐按鏃堕棿 BCD
 
@@ -38,7 +39,8 @@
      *
      * @param data
      */
-    public static UserCard getBean(List<byte[]> data) {
+    @Override
+    public  UserCard getBean(List<byte[]> data) {
         try {
             UserCard userCard = new UserCard();
             //绗�0鍧楄В鏋�
@@ -48,32 +50,31 @@
 
             byte[] arerNumberByte = new byte[2];
             System.arraycopy(zero, 1, arerNumberByte, 0, arerNumberByte.length);
-            userCard.arerNumber = (short) HexUtil.get16to10LowHigh(HexUtil.bytesToHex(arerNumberByte));
+            userCard.arerNumber =  HexUtil.get16To10LowHightByBytes(arerNumberByte);
 
             byte[] deviceNumberlByte = new byte[2];
             System.arraycopy(zero, 3, deviceNumberlByte, 0, deviceNumberlByte.length);
-            userCard.deviceNumberl = (short) HexUtil.get16to10LowHigh(HexUtil.bytesToHex(deviceNumberlByte));
+            userCard.deviceNumberl =  HexUtil.get16To10LowHightByBytes(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));
+            System.arraycopy(zero, 6, totalWaterByte, 0, totalWaterByte.length);
+            userCard.totalWater = HexUtil.get16To10LowHightByBytes(totalWaterByte);
 
             byte[] totalElectricByte = new byte[4];
-            System.arraycopy(zero, 3, totalElectricByte, 0, totalElectricByte.length);
-            userCard.totalElectric = HexUtil.get16to10LowHigh(HexUtil.bytesToHex(totalElectricByte));
+            System.arraycopy(zero, 10, totalElectricByte, 0, totalElectricByte.length);
+            userCard.totalElectric = HexUtil.get16To10LowHightByBytes(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));
+            userCard.balance =HexUtil.get16To10LowHightByBytes(balanceByte);
 
             byte[] surplusWaterByte = new byte[4];
             System.arraycopy(one, 4, surplusWaterByte, 0, surplusWaterByte.length);
-            userCard.surplusWater = HexUtil.get16to10LowHigh(HexUtil.bytesToHex(surplusWaterByte));
+            userCard.surplusWater = HexUtil.get16To10LowHightByBytes(surplusWaterByte);
 
             byte[] rechargeDateByte = new byte[3];
             System.arraycopy(one, 12, rechargeDateByte, 0, rechargeDateByte.length);
@@ -104,21 +105,35 @@
             try {
                 byte[] data = new byte[16];
                 data[0] = HexUtil.hexToByte(cardType);
-                byte[] arerNumberBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(arerNumber));
+                //鍖哄煙鍙�
+                byte[] arerNumberBytes = new byte[2];
+                byte[] arerNumberDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(arerNumber));
+                System.arraycopy(arerNumberDatas, 0, arerNumberBytes, 0, arerNumberDatas.length);
                 if (arerNumberBytes != null) {
                     System.arraycopy(arerNumberBytes, 0, data, 1, arerNumberBytes.length);
                 }
-                byte[] deviceNumberlBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(deviceNumberl));
+                //璁惧缂栧彿
+                byte[] deviceNumberlBytes = new byte[2];
+                byte[] deviceNumberlDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(deviceNumberl));
+                System.arraycopy(deviceNumberlDatas, 0, deviceNumberlBytes, 0, deviceNumberlDatas.length);
                 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));
+
+                //鐢ㄦ埛鎬荤敤姘撮噺
+                byte[] totalWaterBytes = new byte[4];
+                byte[] totalWaterDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(totalWater));
+                System.arraycopy(totalWaterDatas, 0, totalWaterBytes, 0, totalWaterDatas.length);
                 if (totalWaterBytes != null) {
                     System.arraycopy(totalWaterBytes, 0, data, 6, totalWaterBytes.length);
                 }
-                byte[] totalElectricBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(totalElectric));
+                //鎬荤敤鐢甸噺浣�
+                byte[] totalElectricBytes = new byte[4];
+                byte[] totalElectricDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(totalElectric));
+                System.arraycopy(totalElectricDatas, 0, totalElectricBytes, 0, totalElectricDatas.length);
                 if (totalElectricBytes != null) {
                     System.arraycopy(totalElectricBytes, 0, data, 10, totalElectricBytes.length);
                 }
@@ -143,25 +158,28 @@
 
 
             try {
-                byte[] balanceBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(balance));
+                byte[] balanceBytes = new byte[4];
+                byte[] balanceDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(balance));
+                System.arraycopy(balanceDatas, 0, balanceBytes, 0, balanceDatas.length);
                 if (balanceBytes != null) {
                     System.arraycopy(balanceBytes, 0, data, 0, balanceBytes.length);
                 }
 
-                byte[] surplusWaterBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(surplusWater));
+                byte[] surplusWaterBytes = new byte[4];
+                byte[] surplusWaterDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(surplusWater));
+                System.arraycopy(surplusWaterDatas, 0, surplusWaterBytes, 0, surplusWaterDatas.length);
                 if (surplusWaterBytes != null) {
-                    System.arraycopy(surplusWaterBytes, 0, data, 0, surplusWaterBytes.length);
+                    System.arraycopy(surplusWaterBytes, 0, data, 4, 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));
+                    byte bcdYear = HexUtil.getIntToBCD(year)[0];
+                    byte bcdMonth = HexUtil.getIntToBCD(month)[0];
+                    byte bcdDay = HexUtil.getIntToBCD(day)[0];
                     data[12] = bcdYear;
                     data[13] = bcdMonth;
                     data[14] = bcdDay;
@@ -186,14 +204,18 @@
             byte[] data = new byte[16];
 
             try {
-                byte[] balanceBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(balance));
+                byte[] balanceBytes = new byte[4];
+                byte[] balanceDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(balance));
+                System.arraycopy(balanceDatas, 0, balanceBytes, 0, balanceDatas.length);
                 if (balanceBytes != null) {
                     System.arraycopy(balanceBytes, 0, data, 0, balanceBytes.length);
                 }
 
-                byte[] surplusWaterBytes = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(surplusWater));
+                byte[] surplusWaterBytes = new byte[4];
+                byte[] surplusWaterDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(surplusWater));
+                System.arraycopy(surplusWaterDatas, 0, surplusWaterBytes, 0, surplusWaterDatas.length);
                 if (surplusWaterBytes != null) {
-                    System.arraycopy(surplusWaterBytes, 0, data, 0, surplusWaterBytes.length);
+                    System.arraycopy(surplusWaterBytes, 0, data, 4, surplusWaterBytes.length);
                 }
 
                 if (rechargeDate != null) {
@@ -201,9 +223,9 @@
                     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));
+                    byte bcdYear = HexUtil.getIntToBCD(year)[0];
+                    byte bcdMonth = HexUtil.getIntToBCD(month)[0];
+                    byte bcdDay = HexUtil.getIntToBCD(day)[0];
                     data[12] = bcdYear;
                     data[13] = bcdMonth;
                     data[14] = bcdDay;
@@ -242,27 +264,27 @@
         this.cardType = cardType;
     }
 
-    public short getArerNumber() {
+    public int getArerNumber() {
         return arerNumber;
     }
 
-    public void setArerNumber(short arerNumber) {
+    public void setArerNumber(int arerNumber) {
         this.arerNumber = arerNumber;
     }
 
-    public short getDeviceNumberl() {
+    public int getDeviceNumberl() {
         return deviceNumberl;
     }
 
-    public void setDeviceNumberl(short deviceNumberl) {
+    public void setDeviceNumberl(int deviceNumberl) {
         this.deviceNumberl = deviceNumberl;
     }
 
-    public byte getRechargeTimes() {
+    public short getRechargeTimes() {
         return rechargeTimes;
     }
 
-    public void setRechargeTimes(byte rechargeTimes) {
+    public void setRechargeTimes(short rechargeTimes) {
         this.rechargeTimes = rechargeTimes;
     }
 

--
Gitblit v1.8.0