feat(mybatisplus): 新增 FastBaseIService 并发布 mingli-utils 5.4.0
Gitea Actions Build / Build (push) Canceled after 0s
Gitea Actions Build / Build (push) Canceled after 0s
- 新增 FastBaseIService 服务层便捷基类,与 FastBaseMapper 对齐常用增删改查,移除旧的 BaseMapperQuery - Jackson 自动配置改用 Jackson2ObjectMapperBuilderCustomizer Bean 注册模块,避免直接依赖 ObjectMapper - SpringBeanUtils 新增 lazyBean 延迟获取 Bean 便捷函数 - SystemUtil 新增 lineSeparator 相关常量并整理链式调用格式 - FileUtils.writeLines(charset) 修复自递归问题 - build.gradle.kts 增加 mybatis-plus-spring 编译依赖
This commit is contained in:
+3
-2
@@ -13,10 +13,10 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ProjectName FastBaseMapper.kt
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils
|
* ModuleName mingli-utils
|
||||||
* CurrentFile build.gradle.kts
|
* CurrentFile build.gradle.kts
|
||||||
* LastUpdate 2026-10-26 23:22:18
|
* LastUpdate 2026-10-28 21:50:32
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -85,6 +85,7 @@ dependencies {
|
|||||||
compileOnly("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.8")
|
compileOnly("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.8")
|
||||||
compileOnly("com.baomidou:mybatis-plus-extension:3.5.15")
|
compileOnly("com.baomidou:mybatis-plus-extension:3.5.15")
|
||||||
compileOnly("com.baomidou:mybatis-plus-jsqlparser:3.5.15")
|
compileOnly("com.baomidou:mybatis-plus-jsqlparser:3.5.15")
|
||||||
|
compileOnly("com.baomidou:mybatis-plus-spring:3.5.9")
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
|
testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
|
||||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||||
testImplementation("com.mingliqiye.logger:logger-log4j2:1.0.9")
|
testImplementation("com.mingliqiye.logger:logger-log4j2:1.0.9")
|
||||||
|
|||||||
+3
-3
@@ -13,13 +13,13 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
# ProjectName FastBaseMapper.kt
|
# ProjectName mingli-utils
|
||||||
# ModuleName mingli-utils
|
# ModuleName mingli-utils
|
||||||
# CurrentFile gradle.properties
|
# CurrentFile gradle.properties
|
||||||
# LastUpdate 2026-10-27 10:34:17
|
# LastUpdate 2026-10-28 23:34:13
|
||||||
# UpdateUser MingLiPro
|
# UpdateUser MingLiPro
|
||||||
#
|
#
|
||||||
JDKVERSIONS=17
|
JDKVERSIONS=17
|
||||||
GROUPSID=com.mingliqiye.utils
|
GROUPSID=com.mingliqiye.utils
|
||||||
ARTIFACTID=mingli-utils
|
ARTIFACTID=mingli-utils
|
||||||
VERSIONS=5.3.7
|
VERSIONS=5.4.0
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile FileUtils.kt
|
* CurrentFile FileUtils.kt
|
||||||
* LastUpdate 2026-01-28 10:49:14
|
* LastUpdate 2026-10-28 22:40:34
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
@file:JvmName("FileUtils")
|
@file:JvmName("FileUtils")
|
||||||
@@ -627,7 +627,9 @@ fun File.writeLines(lines: List<String>) {
|
|||||||
*/
|
*/
|
||||||
fun File.writeLines(lines: List<String>, charset: Charset) {
|
fun File.writeLines(lines: List<String>, charset: Charset) {
|
||||||
this.parentFile?.mkdirs()
|
this.parentFile?.mkdirs()
|
||||||
this.writeLines(lines, charset)
|
for (line in lines) {
|
||||||
|
this.writeText(line + System.lineSeparator(), charset)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 复制文件
|
// 复制文件
|
||||||
|
|||||||
@@ -1,38 +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 FastBaseMapper.kt
|
|
||||||
* ModuleName mingli-utils.main
|
|
||||||
* CurrentFile BaseMapperQuery.kt
|
|
||||||
* LastUpdate 2026-10-26 23:22:18
|
|
||||||
* UpdateUser MingLiPro
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.mingliqiye.utils.mybatisplus
|
|
||||||
|
|
||||||
|
|
||||||
@Deprecated(
|
|
||||||
"rename to FastBaseMapper",
|
|
||||||
replaceWith = ReplaceWith(
|
|
||||||
expression = "FastBaseMapper",
|
|
||||||
imports = ["com.mingliqiye.utils.mybatisplus.FastBaseMapper"]
|
|
||||||
),
|
|
||||||
level = DeprecationLevel.WARNING
|
|
||||||
)
|
|
||||||
/**
|
|
||||||
* @since 4.6.1
|
|
||||||
* 已经重命名 [FastBaseMapper]
|
|
||||||
*/
|
|
||||||
typealias BaseMapperQuery<T> = FastBaseMapper<T>
|
|
||||||
@@ -0,0 +1,822 @@
|
|||||||
|
/*
|
||||||
|
* 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 FastBaseIService.kt
|
||||||
|
* LastUpdate 2026-10-28 23:26:17
|
||||||
|
* UpdateUser MingLiPro
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.mingliqiye.utils.mybatisplus
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.support.SFunction
|
||||||
|
import com.baomidou.mybatisplus.extension.kotlin.KtQueryChainWrapper
|
||||||
|
import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
|
||||||
|
import com.baomidou.mybatisplus.extension.kotlin.KtUpdateChainWrapper
|
||||||
|
import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseIService.Companion.ktQueryChainWrapper
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseIService.Companion.ktQueryWrapper
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseIService.Companion.ktUpdateChainWrapper
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseIService.Companion.ktUpdateWrapper
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.delete
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.deleteByColumn
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.exists
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.existsByColumn
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktQueryChain
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktQueryChainWrapper
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktQueryWrapper
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktUpdateChain
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktUpdateChainWrapper
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktUpdateWrapper
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.selectCount
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.selectList
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.selectListByColumn
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.selectListByColumns
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.selectMapByColumn
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.selectOne
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.selectOneByColumn
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.selectPage
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.update
|
||||||
|
import kotlin.reflect.KProperty1
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MyBatis-Plus[IService]的便捷基类,在服务层暴露与[FastBaseMapper]一致的常用查询、更新、删除方法
|
||||||
|
* 内部统一委托给[mapper]执行,避免重复书写包装器构建代码
|
||||||
|
* @param T 实体类型
|
||||||
|
* @param D 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
*/
|
||||||
|
open class FastBaseIService<T, D : FastBaseMapper<T>> : ServiceImpl<D, T>(), IService<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前服务绑定的基础映射器实例,等价于[com.baomidou.mybatisplus.extension.repository.CrudRepository.getBaseMapper]
|
||||||
|
* @return D 继承自[FastBaseMapper]的映射器实例
|
||||||
|
*/
|
||||||
|
val mapper: D
|
||||||
|
get() = getBaseMapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建[com.baomidou.mybatisplus.core.conditions.query.QueryWrapper]实例
|
||||||
|
* @return QueryWrapper<T> 查询包装器实例
|
||||||
|
*/
|
||||||
|
fun queryWrapper() = mapper.queryWrapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建[com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper]实例
|
||||||
|
* @return UpdateWrapper<T> 更新包装器实例
|
||||||
|
*/
|
||||||
|
fun updateWrapper() = mapper.updateWrapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建[com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper]实例
|
||||||
|
* @return LambdaQueryWrapper<T> Lambda查询包装器实例
|
||||||
|
*/
|
||||||
|
fun lambdaQueryWrapper() = mapper.lambdaQueryWrapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建[com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper]实例
|
||||||
|
* @return LambdaUpdateWrapper<T> Lambda更新包装器实例
|
||||||
|
*/
|
||||||
|
fun lambdaUpdateWrapper() = mapper.lambdaUpdateWrapper()
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [queryWrapper]的简写形式
|
||||||
|
* @return QueryWrapper<T> 查询包装器实例
|
||||||
|
*/
|
||||||
|
fun qw() = queryWrapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [updateWrapper]的简写形式
|
||||||
|
* @return UpdateWrapper<T> 更新包装器实例
|
||||||
|
*/
|
||||||
|
fun uw() = updateWrapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [lambdaQueryWrapper]的简写形式
|
||||||
|
* @return LambdaQueryWrapper<T> Lambda查询包装器实例
|
||||||
|
*/
|
||||||
|
fun lqw() = lambdaQueryWrapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [lambdaUpdateWrapper]的简写形式
|
||||||
|
* @return LambdaUpdateWrapper<T> Lambda更新包装器实例
|
||||||
|
*/
|
||||||
|
fun luw() = lambdaUpdateWrapper()
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按字符串列名等值条件查询记录列表
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun <R> selectListByColumn(
|
||||||
|
column: String,
|
||||||
|
value: R,
|
||||||
|
) = mapper.selectListByColumn(column, value, qw())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[com.baomidou.mybatisplus.core.conditions.query.QueryWrapper]上追加字符串列名等值条件并查询记录列表
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @param wrapper 承载查询条件的查询包装器
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun <R> selectListByColumn(
|
||||||
|
column: String,
|
||||||
|
value: R,
|
||||||
|
wrapper: QueryWrapper<T>,
|
||||||
|
) = mapper.selectListByColumn(column, value, wrapper)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按方法引用列等值条件查询记录列表
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun <R> selectListByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: R,
|
||||||
|
) = mapper.selectListByColumn(column, value, lqw())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper]上追加方法引用列等值条件并查询记录列表
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @param wrapper 承载查询条件的Lambda查询包装器
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun <R> selectListByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: R,
|
||||||
|
wrapper: LambdaQueryWrapper<T>,
|
||||||
|
) = mapper.selectListByColumn(column, value, wrapper)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按方法引用列IN条件查询记录列表,集合为空时直接返回空列表而不执行查询
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun <R> selectListByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
) = mapper.selectListByColumn(column, value, lqw())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[LambdaQueryWrapper]上追加方法引用列IN条件并查询记录列表,集合为空时直接返回空列表而不执行查询
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @param wrapper 承载查询条件的Lambda查询包装器
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun <R> selectListByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
wrapper: LambdaQueryWrapper<T> = lqw(),
|
||||||
|
) = mapper.selectListByColumn(column, value, wrapper)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按字符串列名IN条件查询记录列表,集合为空时直接返回空列表而不执行查询
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun <R> selectListByColumn(
|
||||||
|
column: String,
|
||||||
|
value: Collection<R>,
|
||||||
|
) = mapper.selectListByColumn(column, value, qw())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[QueryWrapper]上追加字符串列名IN条件并查询记录列表,集合为空时直接返回空列表而不执行查询
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @param wrapper 承载查询条件的查询包装器
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun <R> selectListByColumn(
|
||||||
|
column: String,
|
||||||
|
value: Collection<R>,
|
||||||
|
wrapper: QueryWrapper<T> = qw(),
|
||||||
|
) = mapper.selectListByColumn(column, value, wrapper)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按多个字符串列名等值条件查询记录列表,各列条件以AND连接
|
||||||
|
* @param columns 列名与列值构成的二元组,逐项执行等值匹配
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun selectListByColumns(
|
||||||
|
vararg columns: FastBaseMapper.StringAnyTuple2,
|
||||||
|
) = mapper.selectListByColumns(columns = columns)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按多个方法引用列等值条件查询记录列表,各列条件以AND连接
|
||||||
|
* @param columns 方法引用列与列值构成的二元组,逐项执行等值匹配
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun selectListByColumns(
|
||||||
|
vararg columns: FastBaseMapper.SFunctionAnyTuple2<T, *>,
|
||||||
|
) = mapper.selectListByColumns(lqw(), columns = columns)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[LambdaQueryWrapper]上追加多个方法引用列等值条件并查询记录列表,各列条件以AND连接
|
||||||
|
* @param wrapper 承载查询条件的Lambda查询包装器
|
||||||
|
* @param columns 方法引用列与列值构成的二元组,逐项执行等值匹配
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun selectListByColumns(
|
||||||
|
wrapper: LambdaQueryWrapper<T>,
|
||||||
|
vararg columns: FastBaseMapper.SFunctionAnyTuple2<T, *>,
|
||||||
|
) = mapper.selectListByColumns(wrapper = wrapper, columns = columns)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按字符串列名等值条件查询单条记录,结果数量不为1时返回null
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @return T? 唯一的查询结果,不存在或多于一条时返回null
|
||||||
|
*/
|
||||||
|
fun <R> selectOneByColumn(
|
||||||
|
column: String,
|
||||||
|
value: R,
|
||||||
|
) = mapper.selectOneByColumn(column, value, qw())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[QueryWrapper]上追加字符串列名等值条件并查询单条记录,结果数量不为1时返回null
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @param wrapper 承载查询条件的查询包装器
|
||||||
|
* @return T? 唯一的查询结果,不存在或多于一条时返回null
|
||||||
|
*/
|
||||||
|
fun <R> selectOneByColumn(
|
||||||
|
column: String,
|
||||||
|
value: R,
|
||||||
|
wrapper: QueryWrapper<T> = qw(),
|
||||||
|
) = mapper.selectOneByColumn(
|
||||||
|
column, value, wrapper
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按方法引用列等值条件查询单条记录,结果数量不为1时返回null
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @return T? 唯一的查询结果,不存在或多于一条时返回null
|
||||||
|
*/
|
||||||
|
fun <R> selectOneByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: R,
|
||||||
|
) = selectOneByColumn(
|
||||||
|
column, value, lqw()
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[LambdaQueryWrapper]上追加方法引用列等值条件并查询单条记录,结果数量不为1时返回null
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @param wrapper 承载查询条件的Lambda查询包装器
|
||||||
|
* @return T? 唯一的查询结果,不存在或多于一条时返回null
|
||||||
|
*/
|
||||||
|
fun <R> selectOneByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: R,
|
||||||
|
wrapper: LambdaQueryWrapper<T>,
|
||||||
|
) = mapper.selectOneByColumn(
|
||||||
|
column, value, wrapper
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按字符串列名等值条件判断记录是否存在
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @return Boolean 存在符合条件的记录返回true,否则返回false
|
||||||
|
*/
|
||||||
|
fun <R> existsByColumn(
|
||||||
|
column: String,
|
||||||
|
value: R,
|
||||||
|
) = mapper.existsByColumn(column, value, qw())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[QueryWrapper]上追加字符串列名等值条件并判断记录是否存在
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @param wrapper 承载查询条件的查询包装器
|
||||||
|
* @return Boolean 存在符合条件的记录返回true,否则返回false
|
||||||
|
*/
|
||||||
|
fun <R> existsByColumn(
|
||||||
|
column: String,
|
||||||
|
value: R,
|
||||||
|
wrapper: QueryWrapper<T> = qw(),
|
||||||
|
) = mapper.existsByColumn(
|
||||||
|
column, value, wrapper
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按方法引用列等值条件判断记录是否存在
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @return Boolean 存在符合条件的记录返回true,否则返回false
|
||||||
|
*/
|
||||||
|
fun <R> existsByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: R,
|
||||||
|
) = mapper.existsByColumn(column, value, lqw())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[LambdaQueryWrapper]上追加方法引用列等值条件并判断记录是否存在
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @param wrapper 承载查询条件的Lambda查询包装器
|
||||||
|
* @return Boolean 存在符合条件的记录返回true,否则返回false
|
||||||
|
*/
|
||||||
|
fun <R> existsByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: R,
|
||||||
|
wrapper: LambdaQueryWrapper<T> = lqw(),
|
||||||
|
) = mapper.existsByColumn(
|
||||||
|
column, value, wrapper
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按方法引用列IN条件查询记录并构建有序映射,集合为空时直接返回空映射而不执行查询
|
||||||
|
* 返回的[LinkedHashMap]保持入参集合的迭代顺序,缺失的键对应的值为null
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @return LinkedHashMap<R, T?> 以列值为键、实体为值的有序映射
|
||||||
|
*/
|
||||||
|
fun <R> selectMapByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
) = mapper.selectMapByColumn(column, value, lqw())
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[LambdaQueryWrapper]上按方法引用列IN条件查询记录并构建有序映射,集合为空时直接返回空映射而不执行查询
|
||||||
|
* 返回的[LinkedHashMap]保持入参集合的迭代顺序,缺失的键对应的值为null
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @param wrapper 承载查询条件的Lambda查询包装器
|
||||||
|
* @return LinkedHashMap<R, T?> 以列值为键、实体为值的有序映射
|
||||||
|
*/
|
||||||
|
fun <R> selectMapByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
wrapper: LambdaQueryWrapper<T> = lqw(),
|
||||||
|
) = mapper.selectMapByColumn(column, value, wrapper)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按字符串列名IN条件删除记录,集合为空时直接返回0而不执行删除
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @return Int 被删除的行数
|
||||||
|
*/
|
||||||
|
fun <R> deleteByColumn(
|
||||||
|
column: String,
|
||||||
|
value: Collection<R>,
|
||||||
|
) = mapper.deleteByColumn(column, value, qw())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[QueryWrapper]上按字符串列名IN条件删除记录,集合为空时直接返回0而不执行删除
|
||||||
|
* 注意:MyBatis-Plus对空集合的IN条件会整体跳过,若不拦截将导致全表删除
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @param wrapper 承载查询条件的查询包装器
|
||||||
|
* @return Int 被删除的行数
|
||||||
|
*/
|
||||||
|
fun <R> deleteByColumn(
|
||||||
|
column: String,
|
||||||
|
value: Collection<R>,
|
||||||
|
wrapper: QueryWrapper<T> = qw(),
|
||||||
|
) = mapper.deleteByColumn(column, value, wrapper)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按方法引用列IN条件删除记录,集合为空时直接返回0而不执行删除
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @return Int 被删除的行数
|
||||||
|
*/
|
||||||
|
fun <R> deleteByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
) = mapper.deleteByColumn(column, value, lqw())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[LambdaQueryWrapper]上按方法引用列IN条件删除记录,集合为空时直接返回0而不执行删除
|
||||||
|
* 注意:MyBatis-Plus对空集合的IN条件会整体跳过,若不拦截将导致全表删除
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @param wrapper 承载查询条件的Lambda查询包装器
|
||||||
|
* @return Int 被删除的行数
|
||||||
|
*/
|
||||||
|
fun <R> deleteByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
wrapper: LambdaQueryWrapper<T>,
|
||||||
|
) = mapper.deleteByColumn(column, value, wrapper)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为[FastBaseIService]绑定的实体类型创建[com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper]实例
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @return KtQueryWrapper<T> Kotlin查询包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.ktQueryWrapper(): KtQueryWrapper<T> =
|
||||||
|
KtQueryWrapper(T::class.java)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为[FastBaseIService]绑定的实体类型创建[com.baomidou.mybatisplus.extension.kotlin.KtQueryChainWrapper]实例
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @return KtQueryChainWrapper<T> Kotlin查询链式包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.ktQueryChainWrapper(): KtQueryChainWrapper<T> =
|
||||||
|
KtQueryChainWrapper(T::class.java)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为[FastBaseIService]绑定的实体类型创建[com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper]实例
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @return KtUpdateWrapper<T> Kotlin更新包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.ktUpdateWrapper(): KtUpdateWrapper<T> =
|
||||||
|
KtUpdateWrapper(T::class.java)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为[FastBaseIService]绑定的实体类型创建[com.baomidou.mybatisplus.extension.kotlin.KtUpdateChainWrapper]实例
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @return KtUpdateChainWrapper<T> Kotlin更新链式包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.ktUpdateChainWrapper(): KtUpdateChainWrapper<T> =
|
||||||
|
KtUpdateChainWrapper(T::class.java)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建绑定当前映射器的[KtQueryChainWrapper]实例
|
||||||
|
* 与[ktQueryChainWrapper]不同,该链式包装器持有映射器引用,可直接调用`list`/`one`/`page`等方法执行查询
|
||||||
|
* @param T 实体类型,必须继承自Any
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @return KtQueryChainWrapper<T> 可执行的Kotlin查询链式包装器实例
|
||||||
|
*/
|
||||||
|
fun <T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.ktQueryChain(): KtQueryChainWrapper<T> =
|
||||||
|
this.mapper.ktQueryChain()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建绑定当前映射器的[KtUpdateChainWrapper]实例
|
||||||
|
* 与[ktUpdateChainWrapper]不同,该链式包装器持有映射器引用,可直接调用`update`/`remove`等方法执行操作
|
||||||
|
* @param T 实体类型,必须继承自Any
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @return KtUpdateChainWrapper<T> 可执行的Kotlin更新链式包装器实例
|
||||||
|
*/
|
||||||
|
fun <T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.ktUpdateChain(): KtUpdateChainWrapper<T> =
|
||||||
|
this.mapper.ktUpdateChain()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [ktQueryWrapper]的简写形式
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @return KtQueryWrapper<T> Kotlin查询包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.kqw(): KtQueryWrapper<T> =
|
||||||
|
this.mapper.ktQueryWrapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [ktUpdateWrapper]的简写形式
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @return KtUpdateWrapper<T> Kotlin更新包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.kuw(): KtUpdateWrapper<T> =
|
||||||
|
this.mapper.ktUpdateWrapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [ktQueryChainWrapper]的简写形式
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @return KtQueryChainWrapper<T> Kotlin查询链式包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.kqcw(): KtQueryChainWrapper<T> =
|
||||||
|
this.mapper.ktQueryChainWrapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [ktUpdateChainWrapper]的简写形式
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @return KtUpdateChainWrapper<T> Kotlin更新链式包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.kucw(): KtUpdateChainWrapper<T> =
|
||||||
|
this.mapper.ktUpdateChainWrapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[KtUpdateWrapper]并执行更新
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param funs 更新包装器构建函数,返回构建完成的更新包装器
|
||||||
|
* @return Int 受影响的行数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.update(funs: (wrapper: KtUpdateWrapper<T>) -> KtUpdateWrapper<T>) =
|
||||||
|
mapper.update(funs)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[KtUpdateWrapper]并携带实体执行更新
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param entity 承载待更新字段值的实体对象
|
||||||
|
* @param funs 更新包装器构建函数,返回构建完成的更新包装器
|
||||||
|
* @return Int 受影响的行数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.update(
|
||||||
|
entity: T,
|
||||||
|
funs: (wrapper: KtUpdateWrapper<T>) -> KtUpdateWrapper<T>,
|
||||||
|
) = mapper.update(entity, funs)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[KtQueryWrapper]并执行查询
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param funs 查询包装器构建函数,返回构建完成的查询包装器
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.selectList(funs: (wrapper: KtQueryWrapper<T>) -> KtQueryWrapper<T>) =
|
||||||
|
mapper.selectList(funs)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[KtQueryWrapper]并执行分页查询
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param page 分页参数对象
|
||||||
|
* @param funs 查询包装器构建函数,返回构建完成的查询包装器
|
||||||
|
* @return Page<T> 分页查询结果
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.selectPage(
|
||||||
|
page: Page<T>,
|
||||||
|
funs: (wrapper: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
) = mapper.selectPage(page, funs)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过页码与每页大小直接执行分页查询
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param current 当前页码,从1开始
|
||||||
|
* @param size 每页记录数
|
||||||
|
* @param funs 查询包装器构建函数,返回构建完成的查询包装器
|
||||||
|
* @return Page<T> 分页查询结果
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.selectPage(
|
||||||
|
current: Long,
|
||||||
|
size: Long,
|
||||||
|
funs: (wrapper: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
) = mapper.selectPage(
|
||||||
|
current, size, funs
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[KtQueryWrapper]并查询单条记录
|
||||||
|
* 结果数量不为1时返回null,不抛出异常
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param funs 查询包装器构建函数,返回构建完成的查询包装器
|
||||||
|
* @return T? 唯一的查询结果,不存在或多于一条时返回null
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.selectOne(funs: (wrapper: KtQueryWrapper<T>) -> KtQueryWrapper<T>) =
|
||||||
|
mapper.selectOne(funs)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[KtQueryWrapper]并统计记录数
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param funs 查询包装器构建函数,返回构建完成的查询包装器
|
||||||
|
* @return Long 符合条件的记录总数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.selectCount(funs: (wrapper: KtQueryWrapper<T>) -> KtQueryWrapper<T>) =
|
||||||
|
mapper.selectCount(funs)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[KtQueryWrapper]并判断记录是否存在
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param funs 查询包装器构建函数,返回构建完成的查询包装器
|
||||||
|
* @return Boolean 存在符合条件的记录返回true,否则返回false
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.exists(funs: (wrapper: KtQueryWrapper<T>) -> KtQueryWrapper<T>) =
|
||||||
|
mapper.exists(funs)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[KtQueryWrapper]并执行删除
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param funs 查询包装器构建函数,返回构建完成的查询包装器
|
||||||
|
* @return Int 被删除的行数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.delete(funs: (wrapper: KtQueryWrapper<T>) -> KtQueryWrapper<T>) =
|
||||||
|
mapper.delete(
|
||||||
|
funs
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单列等值条件查询记录列表
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @param R 列值类型
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param column 实体列属性引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在等值条件之前应用
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>, R> FastBaseIService<T, MP>.selectListByColumn(
|
||||||
|
column: KProperty1<T, R>,
|
||||||
|
value: R,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
) = mapper.selectListByColumn(
|
||||||
|
column, value, funs
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单列IN条件查询记录列表,集合为空时直接返回空列表而不执行查询
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @param R 列值类型
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param column 实体列属性引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在IN条件之前应用
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>, R> FastBaseIService<T, MP>.selectListByColumn(
|
||||||
|
column: KProperty1<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
) = mapper.selectListByColumn(
|
||||||
|
column, value, funs
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按多列等值条件查询记录列表
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param columns 列属性引用与列值的键值对,逐项执行等值匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在各列等值条件之前应用
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>> FastBaseIService<T, MP>.selectListByColumns(
|
||||||
|
vararg columns: Pair<KProperty1<T, *>, Any?>,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
) = mapper.selectListByColumns(columns = columns, funs)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单列等值条件查询单条记录,结果数量不为1时返回null
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @param R 列值类型
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param column 实体列属性引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在等值条件之前应用
|
||||||
|
* @return T? 唯一的查询结果,不存在或多于一条时返回null
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>, R> FastBaseIService<T, MP>.selectOneByColumn(
|
||||||
|
column: KProperty1<T, R>,
|
||||||
|
value: R,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
) = mapper.selectOneByColumn(
|
||||||
|
column, value, funs
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单列等值条件判断记录是否存在
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @param R 列值类型
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param column 实体列属性引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在等值条件之前应用
|
||||||
|
* @return Boolean 存在符合条件的记录返回true,否则返回false
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>, R> FastBaseIService<T, MP>.existsByColumn(
|
||||||
|
column: KProperty1<T, R>,
|
||||||
|
value: R,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
) = mapper.existsByColumn(
|
||||||
|
column, value, funs
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单列IN条件查询记录并构建有序映射,集合为空时直接返回空映射而不执行查询
|
||||||
|
* 返回的[LinkedHashMap]保持入参集合的迭代顺序,缺失的键对应的值为null
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @param R 列值类型
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param column 实体列属性引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在IN条件之前应用
|
||||||
|
* @return LinkedHashMap<R, T?> 以列值为键、实体为值的有序映射
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>, R> FastBaseIService<T, MP>.selectMapByColumn(
|
||||||
|
column: KProperty1<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
) = mapper.selectMapByColumn(
|
||||||
|
column, value, funs
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单列等值条件删除记录
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @param R 列值类型
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param column 实体列属性引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在等值条件之前应用
|
||||||
|
* @return Int 被删除的行数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>, R> FastBaseIService<T, MP>.deleteByColumn(
|
||||||
|
column: KProperty1<T, R>,
|
||||||
|
value: R,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
) = mapper.deleteByColumn(column, value, funs)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单列IN条件删除记录,集合为空时直接返回0而不执行删除
|
||||||
|
* 注意:MyBatis-Plus对空集合的IN条件会整体跳过,若不拦截将导致全表删除
|
||||||
|
* @param T 实体类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param MP 基础映射器类型,必须继承自[FastBaseMapper]<T>
|
||||||
|
* @param R 列值类型
|
||||||
|
* @receiver FastBaseIService<T, MP> 快速服务实例
|
||||||
|
* @param column 实体列属性引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在IN条件之前应用
|
||||||
|
* @return Int 被删除的行数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, MP : FastBaseMapper<T>, R> FastBaseIService<T, MP>.deleteByColumn(
|
||||||
|
column: KProperty1<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
) = mapper.deleteByColumn(column, value, funs)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,10 +13,10 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ProjectName FastBaseMapper.kt
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile FastBaseMapper.kt
|
* CurrentFile FastBaseMapper.kt
|
||||||
* LastUpdate 2026-10-27 10:23:10
|
* LastUpdate 2026-10-28 22:23:47
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -37,6 +37,7 @@ import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktQueryChainWra
|
|||||||
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktQueryWrapper
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktQueryWrapper
|
||||||
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktUpdateChainWrapper
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktUpdateChainWrapper
|
||||||
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktUpdateWrapper
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktUpdateWrapper
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.selectListByColumns
|
||||||
import com.mingliqiye.utils.tuple.Tuple
|
import com.mingliqiye.utils.tuple.Tuple
|
||||||
import kotlin.reflect.KProperty1
|
import kotlin.reflect.KProperty1
|
||||||
|
|
||||||
@@ -786,8 +787,8 @@ interface FastBaseMapper<T> : BaseMapper<T> {
|
|||||||
*/
|
*/
|
||||||
inline fun <reified T : Any, R> FastBaseMapper<T>.existsByColumn(
|
inline fun <reified T : Any, R> FastBaseMapper<T>.existsByColumn(
|
||||||
column: KProperty1<T, R>,
|
column: KProperty1<T, R>,
|
||||||
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
|
||||||
value: R,
|
value: R,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
): Boolean = exists { wrapper: KtQueryWrapper<T> ->
|
): Boolean = exists { wrapper: KtQueryWrapper<T> ->
|
||||||
funs(wrapper).eq(column, value)
|
funs(wrapper).eq(column, value)
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-8
@@ -13,23 +13,24 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ProjectName FastBaseMapper.kt
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile JacksonJsonAutoConfiguration.kt
|
* CurrentFile JacksonJsonAutoConfiguration.kt
|
||||||
* LastUpdate 2026-10-26 23:22:18
|
* LastUpdate 2026-10-28 23:30:03
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.mingliqiye.utils.springboot.autoconfigure
|
package com.mingliqiye.utils.springboot.autoconfigure
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
|
||||||
import com.mingliqiye.utils.json.converters.DateTimeJsonConverter
|
import com.mingliqiye.utils.json.converters.DateTimeJsonConverter
|
||||||
import com.mingliqiye.utils.json.converters.UUIDJsonConverter
|
import com.mingliqiye.utils.json.converters.UUIDJsonConverter
|
||||||
import com.mingliqiye.utils.json.converters.base.getJacksonModule
|
import com.mingliqiye.utils.json.converters.base.getJacksonModule
|
||||||
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer
|
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Jackson 2 的序列化模块自动配置(过渡兼容)。
|
* Jackson 2 的序列化模块自动配置(过渡兼容)。
|
||||||
@@ -60,16 +61,32 @@ import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilde
|
|||||||
*/
|
*/
|
||||||
@ConditionalOnClass(name = ["com.fasterxml.jackson.databind.ObjectMapper", "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration"])
|
@ConditionalOnClass(name = ["com.fasterxml.jackson.databind.ObjectMapper", "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration"])
|
||||||
@AutoConfigureAfter(name = ["org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration"])
|
@AutoConfigureAfter(name = ["org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration"])
|
||||||
open class JacksonJsonAutoConfiguration(objectMapper: ObjectMapper) {
|
open class JacksonJsonAutoConfiguration {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val log = MingLiLoggerFactory.getLogger<JacksonJsonAutoConfiguration>()
|
private val log = MingLiLoggerFactory.getLogger<JacksonJsonAutoConfiguration>()
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
@Bean("DateTimeJsonConverterJackson2ObjectMapperBuilderCustomizer")
|
||||||
objectMapper.registerModule(DateTimeJsonConverter.getJsonConverter().getJacksonModule())
|
@ConditionalOnMissingBean(name = ["DateTimeJsonConverterJackson2ObjectMapperBuilderCustomizer"])
|
||||||
objectMapper.registerModule(UUIDJsonConverter.getJsonConverter().getJacksonModule())
|
fun getDateTimeJsonConverterJackson2ObjectMapperBuilderCustomizer() = Jackson2ObjectMapperBuilderCustomizer {
|
||||||
log.info("MingliUtils JacksonModule UUID,DateTime Serializers created")
|
log.info(
|
||||||
|
"MingliUtils Jackson2 DateTime Serializers created"
|
||||||
|
)
|
||||||
|
it.modulesToInstall { modules ->
|
||||||
|
modules.add(DateTimeJsonConverter.getJsonConverter().getJacksonModule())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean("UUIDJsonConverterJackson2ObjectMapperBuilderCustomizer")
|
||||||
|
@ConditionalOnMissingBean(name = ["UUIDJsonConverterJackson2ObjectMapperBuilderCustomizer"])
|
||||||
|
fun getUUIDJsonConverterJackson2ObjectMapperBuilderCustomizer() = Jackson2ObjectMapperBuilderCustomizer {
|
||||||
|
log.info(
|
||||||
|
"MingliUtils Jackson2 UUID Serializers created"
|
||||||
|
)
|
||||||
|
it.modulesToInstall { modules ->
|
||||||
|
modules.add(UUIDJsonConverter.getJsonConverter().getJacksonModule())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile SpringBeanUtils.kt
|
* CurrentFile SpringBeanUtils.kt
|
||||||
* LastUpdate 2026-10-02 16:18:14
|
* LastUpdate 2026-10-27 12:51:22
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -44,6 +44,12 @@ class SpringBeanUtils : ApplicationContextAware {
|
|||||||
|
|
||||||
private var applicationContextBase: ApplicationContext? = null
|
private var applicationContextBase: ApplicationContext? = null
|
||||||
|
|
||||||
|
inline fun <reified T : Any> lazyBean(): Lazy<T> = lazy(::getBean)
|
||||||
|
|
||||||
|
inline fun <reified T : Any> lazyBean(name: String): Lazy<T> = lazy {
|
||||||
|
getBean(name, T::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Throws(BeansException::class)
|
@Throws(BeansException::class)
|
||||||
inline fun <reified T : Any> getBean() = getBean(T::class.java)
|
inline fun <reified T : Any> getBean() = getBean(T::class.java)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile SystemUtil.kt
|
* CurrentFile SystemUtil.kt
|
||||||
* LastUpdate 2026-10-20 18:54:24
|
* LastUpdate 2026-10-28 22:43:54
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
@file:JvmName("SystemUtils")
|
@file:JvmName("SystemUtils")
|
||||||
@@ -30,8 +30,7 @@ import com.mingliqiye.utils.random.Random.nextBytes as randomByte
|
|||||||
private val UNIX_PREFIXES = arrayOf("Linux", "AIX", "SunOS", "Mac OS X", "FreeBSD")
|
private val UNIX_PREFIXES = arrayOf("Linux", "AIX", "SunOS", "Mac OS X", "FreeBSD")
|
||||||
private val HEX_UPPER: Array<String> = Array(256) { "%02X".format(it) }
|
private val HEX_UPPER: Array<String> = Array(256) { "%02X".format(it) }
|
||||||
|
|
||||||
private fun <T> Enumeration<T>?.toList(): List<T> =
|
private fun <T> Enumeration<T>?.toList(): List<T> = if (this == null) emptyList() else Collections.list(this)
|
||||||
if (this == null) emptyList() else Collections.list(this)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作系统名称属性,延迟初始化
|
* 操作系统名称属性,延迟初始化
|
||||||
@@ -85,8 +84,7 @@ val javaVersionAsInteger: Int by lazy {
|
|||||||
}
|
}
|
||||||
val normalized = if (version.startsWith("1.")) version.substring(2) else version
|
val normalized = if (version.startsWith("1.")) version.substring(2) else version
|
||||||
val major = normalized.substringBefore('.').substringBefore('-')
|
val major = normalized.substringBefore('.').substringBefore('-')
|
||||||
major.toIntOrNull()
|
major.toIntOrNull() ?: throw IllegalStateException("Invalid Java version format: $version")
|
||||||
?: throw IllegalStateException("Invalid Java version format: $version")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,12 +101,8 @@ val isJdk8Plus: Boolean by lazy {
|
|||||||
*/
|
*/
|
||||||
val localIps: Array<String> by lazy {
|
val localIps: Array<String> by lazy {
|
||||||
try {
|
try {
|
||||||
activeNetworkInterfaces()
|
activeNetworkInterfaces().flatMap { it.inetAddresses.toList() }.filterIsInstance<Inet4Address>()
|
||||||
.flatMap { it.inetAddresses.toList() }
|
.mapNotNull { it.hostAddress }.toList().toTypedArray()
|
||||||
.filterIsInstance<Inet4Address>()
|
|
||||||
.mapNotNull { it.hostAddress }
|
|
||||||
.toList()
|
|
||||||
.toTypedArray()
|
|
||||||
} catch (e: SocketException) {
|
} catch (e: SocketException) {
|
||||||
throw RuntimeException("Failed to get local IP addresses", e)
|
throw RuntimeException("Failed to get local IP addresses", e)
|
||||||
}
|
}
|
||||||
@@ -124,13 +118,8 @@ val localIpsByList: List<String> by lazy { localIps.toList() }
|
|||||||
*/
|
*/
|
||||||
val loopbackIps: Array<String> by lazy {
|
val loopbackIps: Array<String> by lazy {
|
||||||
try {
|
try {
|
||||||
NetworkInterface.getNetworkInterfaces().toList()
|
NetworkInterface.getNetworkInterfaces().toList().asSequence().filter { it.isLoopback && it.isUp }
|
||||||
.asSequence()
|
.flatMap { it.inetAddresses.toList().asSequence() }.mapNotNull { it.hostAddress }.toList().toTypedArray()
|
||||||
.filter { it.isLoopback && it.isUp }
|
|
||||||
.flatMap { it.inetAddresses.toList().asSequence() }
|
|
||||||
.mapNotNull { it.hostAddress }
|
|
||||||
.toList()
|
|
||||||
.toTypedArray()
|
|
||||||
} catch (_: SocketException) {
|
} catch (_: SocketException) {
|
||||||
arrayOf("127.0.0.1")
|
arrayOf("127.0.0.1")
|
||||||
}
|
}
|
||||||
@@ -160,20 +149,16 @@ val pidAsString: String by lazy {
|
|||||||
* 计算机名;获取失败返回 "unknown"
|
* 计算机名;获取失败返回 "unknown"
|
||||||
*/
|
*/
|
||||||
val computerName: String by lazy {
|
val computerName: String by lazy {
|
||||||
getEnvVar("COMPUTERNAME")
|
getEnvVar("COMPUTERNAME") ?: getEnvVar("HOSTNAME")
|
||||||
?: getEnvVar("HOSTNAME")
|
?: runCatching { InetAddress.getLocalHost().hostName }.getOrNull()?.takeIf { it.isNotBlank() } ?: "unknown"
|
||||||
?: runCatching { InetAddress.getLocalHost().hostName }.getOrNull()?.takeIf { it.isNotBlank() }
|
|
||||||
?: "unknown"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前用户名;获取失败返回 "unknown"
|
* 当前用户名;获取失败返回 "unknown"
|
||||||
*/
|
*/
|
||||||
val userName: String by lazy {
|
val userName: String by lazy {
|
||||||
getEnvVar("USERNAME")
|
getEnvVar("USERNAME") ?: getEnvVar("USER") ?: runCatching { System.getProperty("user.name") }.getOrNull()
|
||||||
?: getEnvVar("USER")
|
?.takeIf { it.isNotBlank() } ?: "unknown"
|
||||||
?: runCatching { System.getProperty("user.name") }.getOrNull()?.takeIf { it.isNotBlank() }
|
|
||||||
?: "unknown"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getEnvVar(name: String): String? = runCatching {
|
private fun getEnvVar(name: String): String? = runCatching {
|
||||||
@@ -187,8 +172,7 @@ private fun getEnvVar(name: String): String? = runCatching {
|
|||||||
*/
|
*/
|
||||||
val macAddressBytes: ByteArray by lazy {
|
val macAddressBytes: ByteArray by lazy {
|
||||||
val found = try {
|
val found = try {
|
||||||
activeNetworkInterfaces()
|
activeNetworkInterfaces().mapNotNull { runCatching { it.hardwareAddress }.getOrNull() }
|
||||||
.mapNotNull { runCatching { it.hardwareAddress }.getOrNull() }
|
|
||||||
.firstOrNull { it.isNotEmpty() }
|
.firstOrNull { it.isNotEmpty() }
|
||||||
} catch (_: SocketException) {
|
} catch (_: SocketException) {
|
||||||
null
|
null
|
||||||
@@ -215,14 +199,11 @@ val macAddressFormattedString: String by lazy {
|
|||||||
*/
|
*/
|
||||||
val allMacAddresses: Map<String, ByteArray> by lazy {
|
val allMacAddresses: Map<String, ByteArray> by lazy {
|
||||||
try {
|
try {
|
||||||
NetworkInterface.getNetworkInterfaces().toList()
|
NetworkInterface.getNetworkInterfaces().toList().asSequence().filter { !it.isLoopback && !it.isVirtual }
|
||||||
.asSequence()
|
|
||||||
.filter { !it.isLoopback && !it.isVirtual }
|
|
||||||
.mapNotNull { ni ->
|
.mapNotNull { ni ->
|
||||||
val mac = runCatching { ni.hardwareAddress }.getOrNull()
|
val mac = runCatching { ni.hardwareAddress }.getOrNull()
|
||||||
if (mac != null && mac.isNotEmpty()) ni.name to mac else null
|
if (mac != null && mac.isNotEmpty()) ni.name to mac else null
|
||||||
}
|
}.toMap()
|
||||||
.toMap()
|
|
||||||
} catch (_: SocketException) {
|
} catch (_: SocketException) {
|
||||||
emptyMap()
|
emptyMap()
|
||||||
}
|
}
|
||||||
@@ -243,15 +224,13 @@ val availableProcessors: Int by lazy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun activeNetworkInterfaces(): Sequence<NetworkInterface> =
|
private fun activeNetworkInterfaces(): Sequence<NetworkInterface> =
|
||||||
NetworkInterface.getNetworkInterfaces().toList().asSequence()
|
NetworkInterface.getNetworkInterfaces().toList().asSequence().filter { !it.isLoopback && !it.isVirtual && it.isUp }
|
||||||
.filter { !it.isLoopback && !it.isVirtual && it.isUp }
|
|
||||||
|
|
||||||
|
|
||||||
private val protocol: String by lazy {
|
private val protocol: String by lazy {
|
||||||
val target = ProtocolAnchor::class.java
|
val target = ProtocolAnchor::class.java
|
||||||
val resourceName = target.simpleName + ".class"
|
val resourceName = target.simpleName + ".class"
|
||||||
val resource: URL = target.getResource(resourceName)
|
val resource: URL = target.getResource(resourceName) ?: throw IllegalStateException(
|
||||||
?: throw IllegalStateException(
|
|
||||||
"Unable to locate resource '$resourceName' for class ${target.name}"
|
"Unable to locate resource '$resourceName' for class ${target.name}"
|
||||||
)
|
)
|
||||||
resource.protocol
|
resource.protocol
|
||||||
@@ -282,5 +261,13 @@ val isJswarMode: Boolean get() = protocol == "jswar"
|
|||||||
/** 是否不为 JSWAR 模式 */
|
/** 是否不为 JSWAR 模式 */
|
||||||
val isNotJswarMode: Boolean get() = protocol != "jswar"
|
val isNotJswarMode: Boolean get() = protocol != "jswar"
|
||||||
|
|
||||||
|
val lineSeparator
|
||||||
|
get() = System.lineSeparator()
|
||||||
|
|
||||||
|
const val lineSeparatorLF = "\n"
|
||||||
|
|
||||||
|
const val lineSeparatorCR = "\r"
|
||||||
|
|
||||||
|
const val lineSeparatorCRLF = lineSeparatorCR + lineSeparatorLF
|
||||||
|
|
||||||
private object ProtocolAnchor
|
private object ProtocolAnchor
|
||||||
|
|||||||
Reference in New Issue
Block a user