refactor: 重构项目并添加新功能
All checks were successful
Gitea Actions Build / Build (push) Successful in 51s

- 更新 .gitattributes 和 .gitignore 文件
-重构 AesUtils 类,优化代码结构
- 新增 ByteUtil工具类,用于处理字节数组
- 更新 DateTime 类,增加新方法并改进现有方法- 更新 Gradle 配置和版本号
- 优化 Lists工具类,增加空值安全的 toArray 方法
- 重构 MysqlUUIDv1 类,改进 UUID 转换逻辑
- 更新 UUID 类和 UUIDBinaryTypeHandler 类
- 移除 package.json 中的 pnpm 配置
This commit is contained in:
Armamem0t 2025-08-20 11:06:05 +08:00
parent 34dccd1895
commit 2819f5de5d
Signed by: minglipro
GPG Key ID: 5F355A77B22AA93B
13 changed files with 132 additions and 43 deletions

6
.gitattributes vendored
View File

@ -1,5 +1 @@
* text eol=lf
*.bat text eol=crlf
*.jar binary
*.class binary
*.png binary
* text=auto eol=lf

10
.gitignore vendored
View File

@ -5,10 +5,8 @@ build/
!**/src/test/**/build/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
.idea
!.idea/icon.png
*.iws
*.iml
*.ipr
@ -16,8 +14,6 @@ out/
!**/src/main/**/out/
!**/src/test/**/out/
!.idea/icon.png
### Eclipse ###
.apt_generated
.classpath
@ -47,5 +43,5 @@ bin/
log
.idea
node_modules
pnpm-lock.yaml
*lock*

BIN
.idea/icon.png generated

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 KiB

After

Width:  |  Height:  |  Size: 98 KiB

View File

@ -66,8 +66,8 @@ repositories {
publishing {
repositories {
maven {
name = "localMaven"
url = uri("D:/git/maven-repository-raw")
name = "MavenRepositoryRaw"
url = uri("C:/data/git/maven-repository-raw")
}
}
publications {

View File

@ -1,4 +1,4 @@
JDKVERSIONS=1.8
GROUPSID=com.mingliqiye.utils
ARTIFACTID=mingli-utils
VERSIONS=1.0.7
VERSIONS=1.1.3

View File

@ -6,7 +6,6 @@
"buildw": "gradlew build-jar",
"format": "prettier --write \"**/*.{js,ts,jsx,tsx,cjs,cts,mjs,mts,vue,astro,json,java}\""
},
"packageManager": "pnpm@10.4.1",
"devDependencies": {
"prettier-plugin-java": "^2.7.1",
"prettier": "^3.6.2"

View File

@ -1,14 +1,13 @@
package com.mingliqiye.utils.aes;
import com.mingliqiye.utils.base64.Base64Utils;
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class AesUtils {

View File

@ -0,0 +1,33 @@
package com.mingliqiye.utils.bytes;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author MingLiPro
*
* 字节数组处理工具类
*/
public class ByteUtil {
/**
* 将字节数组转换为十六进制字符串列表
* <p>
* 每个字节都会被转换为两位的十六进制字符串表示形式
* 例如: 字节值为10的字节会被转换为"0a"值为255的字节会被转换为"ff"
*
* @param bytes 输入的字节数组
* @return 包含每个字节对应十六进制字符串的列表
*/
public static List<String> getByteArrayString(byte[] bytes) {
List<Byte> byteList = new ArrayList<>(bytes.length);
for (byte aByte : bytes) {
byteList.add(aByte);
}
return byteList
.stream()
.map(a -> String.format("%02x", a & 0xFF))
.collect(Collectors.toList());
}
}

View File

@ -2,6 +2,7 @@ package com.mingliqiye.utils.collection;
import java.util.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Lists工具类提供了一系列创建List实现的便捷方法
@ -245,4 +246,16 @@ public class Lists {
}
return newList.toArray(new String[0]);
}
@Nullable
public static <T> T[] toArray(List<T> ts) {
if (ts == null) {
return null;
}
T[] items = (T[]) new Object[ts.size()];
ForEach.forEach(ts, (t, i) -> {
items[i] = t;
});
return items;
}
}

View File

@ -4,18 +4,27 @@ import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import lombok.Getter;
import lombok.Setter;
import lombok.var;
import org.jetbrains.annotations.NotNull;
/**
* 时间工具类用于处理日期时间的转换格式化等操作
* 提供了多种静态方法来创建 DateTime 实例并支持与 DateLocalDateTime 等类型的互转
*
* @author MingLiPro
* @see java.time
* @see LocalDateTime
* @see ChronoUnit
* @see Date
* @see DateTimeFormatter
* @see ZoneId
* @see Instant
*/
public final class DateTime {
@Getter
@ -73,6 +82,16 @@ public final class DateTime {
);
}
/**
* 根据 LocalDateTime 创建 DateTime 实例
*
* @param localDateTime LocalDateTime 对象
* @return 返回对应的 DateTime 实例
*/
public static DateTime of(LocalDateTime localDateTime) {
return new DateTime(localDateTime);
}
/**
* 解析时间字符串并生成 DateTime 实例
*
@ -307,11 +326,12 @@ public final class DateTime {
* @return 返回修改后的 DateTime 实例
*/
public DateTime add(DateTimeOffset dateTimeOffset) {
this.localDateTime = this.localDateTime.plus(
dateTimeOffset.getOffset(),
dateTimeOffset.getOffsetType()
return new DateTime(
this.localDateTime.plus(
dateTimeOffset.getOffset(),
dateTimeOffset.getOffsetType()
)
);
return this;
}
/**
@ -321,11 +341,12 @@ public final class DateTime {
* @return 返回修改后的 DateTime 实例
*/
public DateTime sub(DateTimeOffset dateTimeOffset) {
this.localDateTime = this.localDateTime.plus(
-dateTimeOffset.getOffset(),
dateTimeOffset.getOffsetType()
return new DateTime(
this.localDateTime.plus(
-dateTimeOffset.getOffset(),
dateTimeOffset.getOffsetType()
)
);
return this;
}
/**
@ -407,7 +428,41 @@ public final class DateTime {
return false;
}
/**
* 将当前 DateTime 转换为 Instant 对象
*
* @return 返回 Instant 对象
*/
@NotNull
public Instant toInstant() {
return localDateTime.atZone(zoneId).toInstant();
}
/**
* 判断当前时间是否在指定时间之后
*
* @param dateTime 指定时间
* @return 如果当前时间在指定时间之后则返回 true否则返回 false
*/
public boolean isAfter(DateTime dateTime) {
if (dateTime == null) {
return false;
}
return toInstant().isAfter(dateTime.toInstant());
}
/**
* 判断当前时间是否在指定时间之前
*
* @param dateTime 指定时间
* @return 如果当前时间在指定时间之前则返回 true否则返回 false
*/
public boolean isBefore(DateTime dateTime) {
if (dateTime == null) {
return false;
}
return toInstant().isBefore(dateTime.toInstant());
}
}

View File

@ -11,12 +11,12 @@ import lombok.var;
public class MysqlUUIDv1 {
/**
* MySQL格式的UUID转换为标准UUID格式
* 标准UUID格式转换为MySQL格式的UUID
*
* @param uuid MySQL格式的UUID字节数组长度必须为16字节
* @return 标准UUID格式的字节数组长度为16字节
* @param uuid 标准UUID格式的字节数组长度必须为16字节
* @return MySQL格式的UUID字节数组长度为16字节
*/
public static byte[] mysqlToUuid(byte[] uuid) {
public static byte[] uuidToMysql(byte[] uuid) {
var reuuid = new byte[16];
// 转换时间戳低位部分
reuuid[4] = uuid[0];
@ -38,12 +38,12 @@ public class MysqlUUIDv1 {
}
/**
* 标准UUID格式转换为MySQL格式的UUID
* MySQL格式的UUID转换为标准UUID格式
*
* @param uuid 标准UUID格式的字节数组长度必须为16字节
* @return MySQL格式的UUID字节数组长度为16字节
* @param uuid MySQL格式的UUID字节数组长度必须为16字节
* @return 标准UUID格式的字节数组长度为16字节
*/
public static byte[] uuidToMysql(byte[] uuid) {
public static byte[] mysqlToUuid(byte[] uuid) {
var reuuid = new byte[16];
// 转换时间戳高位部分
reuuid[6] = uuid[0];

View File

@ -4,13 +4,12 @@ import com.github.f4b6a3.uuid.UuidCreator;
import com.mingliqiye.utils.string.StringUtil;
import com.mingliqiye.utils.time.DateTime;
import com.mingliqiye.utils.time.DateTimeOffset;
import lombok.Data;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.time.temporal.ChronoUnit;
import java.util.Locale;
import java.util.Objects;
import lombok.Data;
/**
* UUID 工具类用于生成解析和操作 UUID

View File

@ -1,15 +1,14 @@
package com.mingliqiye.utils.uuid.typehandlers;
import com.mingliqiye.utils.uuid.UUID;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
/**
* UUIDBinaryTypeHandler 类用于处理 UUID 类型与数据库 BINARY 类型之间的转换