feat(utils): 添加数组工具类和国际化支持

- 添加ByteArray.toHexString和String.toHexByteArray扩展函数
- 实现多种数组类型的copyTo和copyFrom扩展方法
- 在AutoConfiguration中集成I18N国际化功能
- 添加AutoService注解及处理器用于自动服务注册
- 新增BadGatewayException HTTP状态异常类
- 更新启动横幅格式并添加国际化文本支持
This commit is contained in:
2026-02-08 03:17:14 +08:00
parent a5a532bc82
commit 450b4e1a93
93 changed files with 4271 additions and 1292 deletions
@@ -16,38 +16,47 @@
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile MysqlUUIDv1.kt
* LastUpdate 2026-01-08 08:22:14
* LastUpdate 2026-02-06 14:52:40
* UpdateUser MingLiPro
*/
@file:JvmName("MysqlUUIDConvertor")
package com.mingliqiye.utils.uuid
import com.mingliqiye.utils.array.copyTo
/**
* 将标准UUID字节数组转换为MySQL存储格式的字节数组
* MySQL中UUID的存储格式与标准UUID的字节顺序不同,需要重新排列字节顺序
*
* @param uuid 标准UUID格式的字节数组(16字节)
* @return 转换后的MySQL存储格式字节数组(16字节)
* @since 4.6.2
*/
fun uuidToMysql(uuid: ByteArray): ByteArray {
val reuuid = ByteArray(16)
reuuid[4] = uuid[0]
reuuid[5] = uuid[1]
reuuid[6] = uuid[2]
reuuid[7] = uuid[3]
reuuid[2] = uuid[4]
reuuid[3] = uuid[5]
reuuid[0] = uuid[6]
reuuid[1] = uuid[7]
System.arraycopy(uuid, 8, reuuid, 8, 8)
return reuuid
return ByteArray(16).also {
// 按照MySQL UUID存储格式重新排列字节:前4字节、中间2字节、后2字节、最后8字节
uuid.copyTo(it, 0, 4, 4)
.copyTo(it, 4, 2, 2)
.copyTo(it, 6, 0, 2)
.copyTo(it, 8, 8, 8)
}
}
/**
* 将MySQL存储格式的UUID字节数组转换回标准UUID格式
* MySQL中UUID的存储格式与标准UUID的字节顺序不同,需要恢复原始字节顺序
*
* @param uuid MySQL存储格式的字节数组(16字节)
* @return 转换后的标准UUID格式字节数组(16字节)
* @since 4.6.2
*/
fun mysqlToUuid(uuid: ByteArray): ByteArray {
val reuuid = ByteArray(16)
reuuid[6] = uuid[0]
reuuid[7] = uuid[1]
reuuid[4] = uuid[2]
reuuid[5] = uuid[3]
reuuid[0] = uuid[4]
reuuid[1] = uuid[5]
reuuid[2] = uuid[6]
reuuid[3] = uuid[7]
System.arraycopy(uuid, 8, reuuid, 8, 8)
return reuuid
return ByteArray(16).also {
// 按照标准UUID格式恢复字节顺序:第6-7字节、第4-5字节、第0-3字节、第8-15字节
uuid.copyTo(it, 0, 6, 2)
.copyTo(it, 2, 4, 2)
.copyTo(it, 4, 0, 4)
.copyTo(it, 8, 8, 8)
}
}
@@ -16,13 +16,14 @@
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile UUID.kt
* LastUpdate 2026-02-05 11:20:59
* LastUpdate 2026-02-06 14:33:24
* UpdateUser MingLiPro
*/
package com.mingliqiye.utils.uuid
import com.mingliqiye.utils.base.*
import com.mingliqiye.utils.io.IO.println
import com.mingliqiye.utils.random.randomByte
import com.mingliqiye.utils.random.secureRandom
import com.mingliqiye.utils.system.macAddressBytes
@@ -570,8 +571,11 @@ class UUID : Serializable {
* @return 如果相等则返回 true,否则返回 false
*/
override fun equals(other: Any?): Boolean {
if (this === other) return true
return when (other) {
is UUID -> {
this.println()
other.println()
this.data.contentEquals(other.data)
}
@@ -16,15 +16,41 @@
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile UUIDFormatType.kt
* LastUpdate 2026-02-04 21:54:04
* LastUpdate 2026-02-06 14:53:47
* UpdateUser MingLiPro
*/
package com.mingliqiye.utils.uuid
/**
* UUID格式类型枚举
* 定义了四种不同的UUID格式化选项,包括大小写和是否包含空格的组合
*
* @property isUpper 是否使用大写字母
* @property isnotSpace 是否不包含空格(true表示无空格,false表示有空格)
*/
enum class UUIDFormatType(val isUpper: Boolean, val isnotSpace: Boolean) {
/**
* 大写带分隔符
* 使用大写字母并保留空格分隔符
*/
UPPER_SPACE(true, false),
/**
* 小写带分隔符
* 使用小写字母并保留空格分隔符
*/
NO_UPPER_SPACE(false, false),
/**
* 小写无分隔符
* 使用小写字母且不包含空格分隔符
*/
NO_UPPER_NO_SPACE(false, true),
/**
* 大写无分隔符
* 使用大写字母且不包含空格分隔符
*/
UPPER_NO_SPACE(true, true),
}
@@ -1,31 +0,0 @@
/*
* Copyright 2026 mingliqiye
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile UUIDJsonFormat.kt
* LastUpdate 2026-02-04 22:14:47
* UpdateUser MingLiPro
*/
package com.mingliqiye.utils.uuid
import com.mingliqiye.utils.base.BaseType
@Target(AnnotationTarget.FIELD)
annotation class UUIDJsonFormat(
val value: UUIDFormatType = UUIDFormatType.NO_UPPER_SPACE,
val base: BaseType = BaseType.BASE16
)