From d0a0e8e242e293ad35dfbee1217f1103302818cd Mon Sep 17 00:00:00 2001
From: zuojincheng <lf_zuo@163.com>
Date: 星期四, 03 四月 2025 10:22:48 +0800
Subject: [PATCH] refactor(generallibrary):重构卡片和用户搜索功能
---
henanlibrary/src/main/java/com/dayu/henanlibrary/card/DomainCard.java | 63 +++++++------------------------
1 files changed, 14 insertions(+), 49 deletions(-)
diff --git a/henanlibrary/src/main/java/com/dayu/henanlibrary/card/DomainCard.java b/henanlibrary/src/main/java/com/dayu/henanlibrary/card/DomainCard.java
index 977ad1b..ec248e1 100644
--- a/henanlibrary/src/main/java/com/dayu/henanlibrary/card/DomainCard.java
+++ b/henanlibrary/src/main/java/com/dayu/henanlibrary/card/DomainCard.java
@@ -168,17 +168,17 @@
/**
* 鐢ㄦ埛鍗�0鍧�
*/
- public class Zero extends BaseCard {
+ public class Zero extends HNBaseCard {
public byte[] toByte() {
byte[] data = new byte[16];
data[0] = HexUtil.hexToByte(cardType);
+ domainLength = domainName.length();
// 鍩熷悕鍗℃柊涔1鍚庢湁01==0锛岄箍閭戞病鏈�01==1
if (type == 0) {
if (domainNumber != null) {
byte[] domainNumbers = BcdUtil.strToBcd(domainNumber);
data[1] = domainNumbers[0];
}
- domainLength = domainName.length();
data[2] = HexUtil.hexToByte(HexUtil.get10to16(domainLength));
String portStr = String.valueOf(port);
int lenght = portStr.length();
@@ -187,11 +187,7 @@
}
String ascii = IDN.toASCII(domainName + "," + portStr + "#");
asciiByte = ascii.getBytes();
- if (asciiByte.length < 12) {
- System.arraycopy(asciiByte, 0, data, 3, asciiByte.length);
- } else {
- System.arraycopy(asciiByte, 0, data, 3, 12);
- }
+ System.arraycopy(asciiByte, 0, data, 3, Math.min(asciiByte.length, 12));
} else {
data[1] = HexUtil.hexToByte(HexUtil.get10to16(domainLength));
String portStr = String.valueOf(port);
@@ -201,13 +197,7 @@
}
String ascii = IDN.toASCII(domainName + "," + portStr + "#");
asciiByte = ascii.getBytes();
- if (asciiByte.length < 13) {
- System.arraycopy(asciiByte, 0, data, 1, asciiByte.length);
- } else {
- System.arraycopy(asciiByte, 0, data, 1, 13);
- }
-
-
+ System.arraycopy(asciiByte, 0, data, 2, Math.min(asciiByte.length, 13));
}
@@ -220,26 +210,14 @@
/**
* 鐢ㄦ埛鍗�1鍧�
*/
- public class One extends BaseCard {
+ public class One extends HNBaseCard {
public byte[] toBytes() {
byte[] data = new byte[16];
- if (type==0){
- if (asciiByte.length > 12) {
- if (asciiByte.length - 12 < 15) {
- System.arraycopy(asciiByte, 12, data, 0, asciiByte.length - 12);
- } else {
- System.arraycopy(asciiByte, 12, data, 0, 15);
- }
- }
- }else {
- if (asciiByte.length > 13) {
- if (asciiByte.length - 13 < 15) {
- System.arraycopy(asciiByte, 13, data, 0, asciiByte.length - 12);
- } else {
- System.arraycopy(asciiByte, 13, data, 0, 15);
- }
- }
+ int offset = (type == 0) ? 12 : 13;
+
+ if (asciiByte.length > offset) {
+ System.arraycopy(asciiByte, offset, data, 0, Math.min(asciiByte.length - offset, 15));
}
data[15] = getByteSum(data);
@@ -252,27 +230,14 @@
/**
* 鐢ㄦ埛鍗�2鍧�
*/
- public class Two extends BaseCard {
+ public class Two extends HNBaseCard {
public byte[] toBytes() {
byte[] data = new byte[16];
- if (type==0){
- if (asciiByte.length > (12 + 15)) {
- if (asciiByte.length - (12 + 15) < 15) {
- System.arraycopy(asciiByte, 12 + 15, data, 0, asciiByte.length - (12 + 15));
- } else {
- System.arraycopy(asciiByte, 12 + 15, data, 0, 15);
- }
- }
- }else {
- if (asciiByte.length > (13 + 15)) {
- if (asciiByte.length - (13 + 15) < 15) {
- System.arraycopy(asciiByte, 13 + 15, data, 0, asciiByte.length - (12 + 15));
- } else {
- System.arraycopy(asciiByte, 13 + 15, data, 0, 15);
- }
- }
+ int offset = (type == 0) ? 27 : 28; // 12 + 15 and 13 + 15
+ if (asciiByte.length > offset) {
+ int lengthToCopy = Math.min(asciiByte.length - offset, 15);
+ System.arraycopy(asciiByte, offset, data, 0, lengthToCopy);
}
-
data[15] = getByteSum(data);
return data;
}
--
Gitblit v1.8.0