| | |
| | | package com.dayu.qiheonlinelibrary.card; |
| | | |
| | | import com.dayu.baselibrary.bean.BaseUserCardCard; |
| | | import com.dayu.baselibrary.tools.BcdUtil; |
| | | import com.dayu.baselibrary.tools.HexUtil; |
| | | |
| | | import com.dayu.qiheonlinelibrary.utils.CardCommon; |
| | | import com.tencent.bugly.crashreport.CrashReport; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Arrays; |
| | | import java.util.Calendar; |
| | | import java.util.List; |
| | | |
| | |
| | | * 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 int arerNumber;//区域号(底位在前高位在后) |
| | |
| | | |
| | | public Float electricPrice;//电单价,保留三位小数 |
| | | |
| | | /** |
| | | * 写卡完成后校验是否写卡成功 |
| | | * |
| | | * @param data |
| | | * @return |
| | | */ |
| | | public boolean equlsUserCard(List<byte[]> data) { |
| | | // 参数验证 |
| | | if (data == null || data.size() < 3) { |
| | | return false; |
| | | } |
| | | // 定义要比较的字节数组 |
| | | byte[][] expectedBytes = {getZeroBytes(), getOneBytes(), getTwoBytes()}; |
| | | // 逐个比较字节数组 |
| | | for (int i = 0; i < 3; i++) { |
| | | if (!Arrays.equals(data.get(i), expectedBytes[i])) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 返回完整的用户编号 |
| | | * |
| | | * @return |
| | | */ |
| | | public String getMyUserCode() { |
| | | return userCode + String.format("%04d", userCodeNumber); |
| | | // return ""; |
| | | } |
| | | |
| | | /** |
| | | * 通过byte转bean |
| | | * |
| | | * @param data |
| | | */ |
| | | public static UserCard getBean(List<byte[]> data) { |
| | | @Override |
| | | public UserCard getBean(List<byte[]> data) { |
| | | try { |
| | | UserCard userCard = new UserCard(); |
| | | //第0块解析 |
| | |
| | | |
| | | byte[] arerNumberByte = new byte[4]; |
| | | System.arraycopy(zero, 1, arerNumberByte, 0, arerNumberByte.length); |
| | | userCard.arerNumber = HexUtil.get16To10LowHightByBytes(arerNumberByte); |
| | | userCard.arerNumber = HexUtil.get16To10LowHightByBytes(arerNumberByte); |
| | | byte[] userCodeByte = new byte[6]; |
| | | System.arraycopy(zero, 5, userCodeByte, 0, userCodeByte.length); |
| | | userCard.userCode= BcdUtil.bcdToStr(userCodeByte); |
| | | userCard.userCode = BcdUtil.bcdToStr(userCodeByte); |
| | | byte[] userCodeNumber = new byte[2]; |
| | | System.arraycopy(zero, 10, userCodeNumber, 0, userCodeNumber.length); |
| | | userCard.userCodeNumber=HexUtil.get16To10LowHightByBytes(userCodeNumber); |
| | | System.arraycopy(zero, 11, userCodeNumber, 0, userCodeNumber.length); |
| | | userCard.userCodeNumber = HexUtil.get16To10LowHightByBytes(userCodeNumber); |
| | | byte[] cardWriteState = new byte[1]; |
| | | System.arraycopy(zero, 13, cardWriteState, 0, cardWriteState.length); |
| | | userCard.cardWriteState=HexUtil.get16To10LowHightByBytes(cardWriteState); |
| | | userCard.cardWriteState = HexUtil.get16To10LowHightByBytes(cardWriteState); |
| | | byte[] cardState = new byte[1]; |
| | | System.arraycopy(zero, 14, cardState, 0, cardState.length); |
| | | userCard.cardState=HexUtil.get16To10LowHightByBytes(cardState); |
| | | userCard.cardState = HexUtil.get16To10LowHightByBytes(cardState); |
| | | //第1块解析 |
| | | byte[] one = data.get(1); |
| | | byte[] balanceByte = new byte[4]; |
| | | System.arraycopy(one, 0, balanceByte, 0, balanceByte.length); |
| | | userCard.balance =HexUtil.get16To10LowHightByBytes(balanceByte); |
| | | userCard.balance = HexUtil.get16To10LowHightByBytes(balanceByte); |
| | | |
| | | byte[] surplusWaterByte = new byte[4]; |
| | | System.arraycopy(one, 4, surplusWaterByte, 0, surplusWaterByte.length); |
| | |
| | | byte[] cardStateDatas = HexUtil.hexToByteArray(HexUtil.get10To16LowHigh(cardState)); |
| | | System.arraycopy(cardStateDatas, 0, cardStateBytes, 0, cardStateDatas.length); |
| | | if (cardStateBytes != null) { |
| | | System.arraycopy(cardStateBytes, 0, data, 13, cardStateBytes.length); |
| | | System.arraycopy(cardStateBytes, 0, data, 14, cardStateBytes.length); |
| | | } |
| | | |
| | | |
| | |
| | | public void setElectricPrice(Float electricPrice) { |
| | | this.electricPrice = electricPrice; |
| | | } |
| | | |
| | | |
| | | } |