generated from mingliqiye/lib-tem
refactor: 重构项目并添加新功能
All checks were successful
Gitea Actions Build / Build (push) Successful in 51s
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:
parent
34dccd1895
commit
2819f5de5d
6
.gitattributes
vendored
6
.gitattributes
vendored
@ -1,5 +1 @@
|
||||
* text eol=lf
|
||||
*.bat text eol=crlf
|
||||
*.jar binary
|
||||
*.class binary
|
||||
*.png binary
|
||||
* text=auto eol=lf
|
||||
|
10
.gitignore
vendored
10
.gitignore
vendored
@ -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
BIN
.idea/icon.png
generated
Binary file not shown.
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
@ -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 {
|
||||
|
@ -1,4 +1,4 @@
|
||||
JDKVERSIONS=1.8
|
||||
GROUPSID=com.mingliqiye.utils
|
||||
ARTIFACTID=mingli-utils
|
||||
VERSIONS=1.0.7
|
||||
VERSIONS=1.1.3
|
||||
|
@ -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"
|
||||
|
@ -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 {
|
||||
|
||||
|
33
src/com/mingliqiye/utils/bytes/ByteUtil.java
Normal file
33
src/com/mingliqiye/utils/bytes/ByteUtil.java
Normal 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());
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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 实例,并支持与 Date、LocalDateTime 等类型的互转。
|
||||
*
|
||||
* @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());
|
||||
}
|
||||
}
|
||||
|
@ -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];
|
||||
|
@ -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。
|
||||
|
@ -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 类型之间的转换
|
||||
|
Loading…
x
Reference in New Issue
Block a user