Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eaf7ee7a31 | ||
|
|
38ad9884d0 | ||
|
|
0e5ce5597b | ||
|
|
85fd391849 | ||
|
|
390afa5462
|
+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 mingli-utils
|
* ProjectName FastBaseMapper.kt
|
||||||
* ModuleName mingli-utils
|
* ModuleName mingli-utils
|
||||||
* CurrentFile build.gradle.kts
|
* CurrentFile build.gradle.kts
|
||||||
* LastUpdate 2026-10-11 16:44:37
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -84,6 +84,7 @@ dependencies {
|
|||||||
compileOnly("net.java.dev.jna:jna:5.17.0")
|
compileOnly("net.java.dev.jna:jna:5.17.0")
|
||||||
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")
|
||||||
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 mingli-utils
|
# ProjectName FastBaseMapper.kt
|
||||||
# ModuleName mingli-utils
|
# ModuleName mingli-utils
|
||||||
# CurrentFile gradle.properties
|
# CurrentFile gradle.properties
|
||||||
# LastUpdate 2026-10-12 13:57:03
|
# LastUpdate 2026-10-26 23:22:18
|
||||||
# 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.2
|
VERSIONS=5.3.6
|
||||||
|
|||||||
@@ -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 mingli-utils
|
* ProjectName FastBaseMapper.kt
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile SuperStream.java
|
* CurrentFile SuperStream.java
|
||||||
* LastUpdate 2026-10-11 17:23:57
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile BadGatewayException.kt
|
* CurrentFile BadGatewayException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:07:34
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Bad Gateway"
|
* @param message 异常信息,默认为 "Bad Gateway"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class BadGatewayException(
|
class BadGatewayException @JvmOverloads constructor(
|
||||||
override val message: String? = "Bad Gateway",
|
override val message: String? = "Bad Gateway",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(502, message, cause)
|
) : HttpStatusException(502, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile BadRequestException.kt
|
* CurrentFile BadRequestException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Bad Request"
|
* @param message 异常信息,默认为 "Bad Request"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class BadRequestException(
|
class BadRequestException @JvmOverloads constructor(
|
||||||
override val message: String? = "Bad Request",
|
override val message: String? = "Bad Request",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(400, message, cause)
|
) : HttpStatusException(400, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile ConflictException.kt
|
* CurrentFile ConflictException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Conflict"
|
* @param message 异常信息,默认为 "Conflict"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class ConflictException(
|
class ConflictException @JvmOverloads constructor(
|
||||||
override val message: String? = "Conflict",
|
override val message: String? = "Conflict",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(409, message, cause)
|
) : HttpStatusException(409, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile ForbiddenException.kt
|
* CurrentFile ForbiddenException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Forbidden"
|
* @param message 异常信息,默认为 "Forbidden"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class ForbiddenException(
|
class ForbiddenException @JvmOverloads constructor(
|
||||||
override val message: String? = "Forbidden",
|
override val message: String? = "Forbidden",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(403, message, cause)
|
) : HttpStatusException(403, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile FoundException.kt
|
* CurrentFile FoundException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Found"
|
* @param message 异常信息,默认为 "Found"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class FoundException(
|
class FoundException @JvmOverloads constructor(
|
||||||
override val message: String? = "Found",
|
override val message: String? = "Found",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(302, message, cause)
|
) : HttpStatusException(302, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile GatewayTimeoutException.kt
|
* CurrentFile GatewayTimeoutException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:48
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Gateway Timeout"
|
* @param message 异常信息,默认为 "Gateway Timeout"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class GatewayTimeoutException(
|
class GatewayTimeoutException @JvmOverloads constructor(
|
||||||
override val message: String? = "Gateway Timeout",
|
override val message: String? = "Gateway Timeout",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(504, message, cause)
|
) : HttpStatusException(504, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile GoneException.kt
|
* CurrentFile GoneException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:48
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Gone"
|
* @param message 异常信息,默认为 "Gone"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class GoneException(
|
class GoneException @JvmOverloads constructor(
|
||||||
override val message: String? = "Gone",
|
override val message: String? = "Gone",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(410, message, cause)
|
) : HttpStatusException(410, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile HttpVersionNotSupportedException.kt
|
* CurrentFile HttpVersionNotSupportedException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:48
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "HTTP Version Not Supported"
|
* @param message 异常信息,默认为 "HTTP Version Not Supported"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class HttpVersionNotSupportedException(
|
class HttpVersionNotSupportedException @JvmOverloads constructor(
|
||||||
override val message: String? = "HTTP Version Not Supported",
|
override val message: String? = "HTTP Version Not Supported",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(505, message, cause)
|
) : HttpStatusException(505, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile InternalServerErrorException.kt
|
* CurrentFile InternalServerErrorException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Internal Server Error"
|
* @param message 异常信息,默认为 "Internal Server Error"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class InternalServerErrorException(
|
class InternalServerErrorException @JvmOverloads constructor(
|
||||||
override val message: String? = "Internal Server Error",
|
override val message: String? = "Internal Server Error",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(500, message, cause)
|
) : HttpStatusException(500, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile LengthRequiredException.kt
|
* CurrentFile LengthRequiredException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:48
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Length Required"
|
* @param message 异常信息,默认为 "Length Required"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class LengthRequiredException(
|
class LengthRequiredException @JvmOverloads constructor(
|
||||||
override val message: String? = "Length Required",
|
override val message: String? = "Length Required",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(411, message, cause)
|
) : HttpStatusException(411, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile MethodNotAllowedException.kt
|
* CurrentFile MethodNotAllowedException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:48
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Method Not Allowed"
|
* @param message 异常信息,默认为 "Method Not Allowed"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class MethodNotAllowedException(
|
class MethodNotAllowedException @JvmOverloads constructor(
|
||||||
override val message: String? = "Method Not Allowed",
|
override val message: String? = "Method Not Allowed",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(405, message, cause)
|
) : HttpStatusException(405, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile MovedPermanentlyException.kt
|
* CurrentFile MovedPermanentlyException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:48
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Moved Permanently"
|
* @param message 异常信息,默认为 "Moved Permanently"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class MovedPermanentlyException(
|
class MovedPermanentlyException @JvmOverloads constructor(
|
||||||
override val message: String? = "Moved Permanently",
|
override val message: String? = "Moved Permanently",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(301, message, cause)
|
) : HttpStatusException(301, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile MultipleChoicesException.kt
|
* CurrentFile MultipleChoicesException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:48
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Multiple Choices"
|
* @param message 异常信息,默认为 "Multiple Choices"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class MultipleChoicesException(
|
class MultipleChoicesException @JvmOverloads constructor(
|
||||||
override val message: String? = "Multiple Choices",
|
override val message: String? = "Multiple Choices",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(300, message, cause)
|
) : HttpStatusException(300, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile NotAcceptableException.kt
|
* CurrentFile NotAcceptableException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Not Acceptable"
|
* @param message 异常信息,默认为 "Not Acceptable"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class NotAcceptableException(
|
class NotAcceptableException @JvmOverloads constructor(
|
||||||
override val message: String? = "Not Acceptable",
|
override val message: String? = "Not Acceptable",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(406, message, cause)
|
) : HttpStatusException(406, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile NotFoundException.kt
|
* CurrentFile NotFoundException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Not Found"
|
* @param message 异常信息,默认为 "Not Found"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class NotFoundException(
|
class NotFoundException @JvmOverloads constructor(
|
||||||
override val message: String? = "Not Found",
|
override val message: String? = "Not Found",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(404, message, cause)
|
) : HttpStatusException(404, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile NotImplementedException.kt
|
* CurrentFile NotImplementedException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Not Implemented"
|
* @param message 异常信息,默认为 "Not Implemented"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class NotImplementedException(
|
class NotImplementedException @JvmOverloads constructor(
|
||||||
override val message: String? = "Not Implemented",
|
override val message: String? = "Not Implemented",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(501, message, cause)
|
) : HttpStatusException(501, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile NotModifiedException.kt
|
* CurrentFile NotModifiedException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:48
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Not Modified"
|
* @param message 异常信息,默认为 "Not Modified"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class NotModifiedException(
|
class NotModifiedException @JvmOverloads constructor(
|
||||||
override val message: String? = "Not Modified",
|
override val message: String? = "Not Modified",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(304, message, cause)
|
) : HttpStatusException(304, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile PaymentRequiredException.kt
|
* CurrentFile PaymentRequiredException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Payment Required"
|
* @param message 异常信息,默认为 "Payment Required"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class PaymentRequiredException(
|
class PaymentRequiredException @JvmOverloads constructor(
|
||||||
override val message: String? = "Payment Required",
|
override val message: String? = "Payment Required",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(402, message, cause)
|
) : HttpStatusException(402, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile PreconditionFailedException.kt
|
* CurrentFile PreconditionFailedException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Precondition Failed"
|
* @param message 异常信息,默认为 "Precondition Failed"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class PreconditionFailedException(
|
class PreconditionFailedException @JvmOverloads constructor(
|
||||||
override val message: String? = "Precondition Failed",
|
override val message: String? = "Precondition Failed",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(412, message, cause)
|
) : HttpStatusException(412, message, cause)
|
||||||
|
|||||||
+2
-2
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile ProxyAuthenticationRequiredException.kt
|
* CurrentFile ProxyAuthenticationRequiredException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Proxy Authentication Required"
|
* @param message 异常信息,默认为 "Proxy Authentication Required"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class ProxyAuthenticationRequiredException(
|
class ProxyAuthenticationRequiredException @JvmOverloads constructor(
|
||||||
override val message: String? = "Proxy Authentication Required",
|
override val message: String? = "Proxy Authentication Required",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(407, message, cause)
|
) : HttpStatusException(407, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile RequestEntityTooLargeException.kt
|
* CurrentFile RequestEntityTooLargeException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Request Entity Too Large"
|
* @param message 异常信息,默认为 "Request Entity Too Large"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class RequestEntityTooLargeException(
|
class RequestEntityTooLargeException @JvmOverloads constructor(
|
||||||
override val message: String? = "Request Entity Too Large",
|
override val message: String? = "Request Entity Too Large",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(413, message, cause)
|
) : HttpStatusException(413, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile RequestTimeoutException.kt
|
* CurrentFile RequestTimeoutException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Request Timeout"
|
* @param message 异常信息,默认为 "Request Timeout"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class RequestTimeoutException(
|
class RequestTimeoutException @JvmOverloads constructor(
|
||||||
override val message: String? = "Request Timeout",
|
override val message: String? = "Request Timeout",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(408, message, cause)
|
) : HttpStatusException(408, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile RequestUriTooLargeException.kt
|
* CurrentFile RequestUriTooLargeException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Request URI Too Large"
|
* @param message 异常信息,默认为 "Request URI Too Large"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class RequestUriTooLargeException(
|
class RequestUriTooLargeException @JvmOverloads constructor(
|
||||||
override val message: String? = "Request URI Too Large",
|
override val message: String? = "Request URI Too Large",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(414, message, cause)
|
) : HttpStatusException(414, message, cause)
|
||||||
|
|||||||
+2
-2
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile RequestedRangeNotSatisfiableException.kt
|
* CurrentFile RequestedRangeNotSatisfiableException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Requested Range Not Satisfiable"
|
* @param message 异常信息,默认为 "Requested Range Not Satisfiable"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class RequestedRangeNotSatisfiableException(
|
class RequestedRangeNotSatisfiableException @JvmOverloads constructor(
|
||||||
override val message: String? = "Requested Range Not Satisfiable",
|
override val message: String? = "Requested Range Not Satisfiable",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(416, message, cause)
|
) : HttpStatusException(416, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile SeeOtherException.kt
|
* CurrentFile SeeOtherException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "See Other"
|
* @param message 异常信息,默认为 "See Other"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class SeeOtherException(
|
class SeeOtherException @JvmOverloads constructor(
|
||||||
override val message: String? = "See Other",
|
override val message: String? = "See Other",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(303, message, cause)
|
) : HttpStatusException(303, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile ServiceUnavailableException.kt
|
* CurrentFile ServiceUnavailableException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Service Unavailable"
|
* @param message 异常信息,默认为 "Service Unavailable"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class ServiceUnavailableException(
|
class ServiceUnavailableException @JvmOverloads constructor(
|
||||||
override val message: String? = "Service Unavailable",
|
override val message: String? = "Service Unavailable",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(503, message, cause)
|
) : HttpStatusException(503, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile TemporaryRedirectException.kt
|
* CurrentFile TemporaryRedirectException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Temporary Redirect"
|
* @param message 异常信息,默认为 "Temporary Redirect"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class TemporaryRedirectException(
|
class TemporaryRedirectException @JvmOverloads constructor(
|
||||||
override val message: String? = "Temporary Redirect",
|
override val message: String? = "Temporary Redirect",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(307, message, cause)
|
) : HttpStatusException(307, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile UnauthorizedException.kt
|
* CurrentFile UnauthorizedException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Unauthorized"
|
* @param message 异常信息,默认为 "Unauthorized"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class UnauthorizedException(
|
class UnauthorizedException @JvmOverloads constructor(
|
||||||
override val message: String? = "Unauthorized",
|
override val message: String? = "Unauthorized",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(401, message, cause)
|
) : HttpStatusException(401, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile UnsupportedMediaTypeException.kt
|
* CurrentFile UnsupportedMediaTypeException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:19
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Unsupported Media Type"
|
* @param message 异常信息,默认为 "Unsupported Media Type"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class UnsupportedMediaTypeException(
|
class UnsupportedMediaTypeException @JvmOverloads constructor(
|
||||||
override val message: String? = "Unsupported Media Type",
|
override val message: String? = "Unsupported Media Type",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(415, message, cause)
|
) : HttpStatusException(415, message, cause)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile UseProxyException.kt
|
* CurrentFile UseProxyException.kt
|
||||||
* LastUpdate 2026-02-05 14:55:04
|
* LastUpdate 2026-10-22 22:09:48
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ package com.mingliqiye.utils.exception
|
|||||||
* @param message 异常信息,默认为 "Use Proxy"
|
* @param message 异常信息,默认为 "Use Proxy"
|
||||||
* @param cause 异常原因,默认为 null
|
* @param cause 异常原因,默认为 null
|
||||||
*/
|
*/
|
||||||
class UseProxyException(
|
class UseProxyException @JvmOverloads constructor(
|
||||||
override val message: String? = "Use Proxy",
|
override val message: String? = "Use Proxy",
|
||||||
override val cause: Throwable? = null,
|
override val cause: Throwable? = null,
|
||||||
) : HttpStatusException(305, message, cause)
|
) : HttpStatusException(305, message, cause)
|
||||||
|
|||||||
@@ -16,13 +16,13 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile Pipeline.kt
|
* CurrentFile Pipeline.kt
|
||||||
* LastUpdate 2026-02-24 09:10:26
|
* LastUpdate 2026-10-20 20:59:13
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.mingliqiye.utils.functions
|
package com.mingliqiye.utils.functions
|
||||||
|
|
||||||
import com.mingliqiye.utils.require.Require
|
import com.mingliqiye.utils.require.requireTrue
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,9 +159,9 @@ class Pipeline<T>(private val value: T) {
|
|||||||
* @return 当前Pipeline实例
|
* @return 当前Pipeline实例
|
||||||
*/
|
*/
|
||||||
fun require(
|
fun require(
|
||||||
any: Any, message: String, exception: Class<out Exception> = IllegalArgumentException::class.java
|
any: Any, message: String, exception: Class<out Exception> = IllegalArgumentException::class.java,
|
||||||
): Pipeline<T> {
|
): Pipeline<T> {
|
||||||
Require.require(any == value, message, exception)
|
requireTrue(any == value, exception, message)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,9 +173,9 @@ class Pipeline<T>(private val value: T) {
|
|||||||
* @return 当前Pipeline实例
|
* @return 当前Pipeline实例
|
||||||
*/
|
*/
|
||||||
fun require(
|
fun require(
|
||||||
any: Any, message: String
|
any: Any, message: String,
|
||||||
): Pipeline<T> {
|
): Pipeline<T> {
|
||||||
Require.require(any == value, message)
|
requireTrue(any == value, message)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,9 +189,9 @@ class Pipeline<T>(private val value: T) {
|
|||||||
fun require(
|
fun require(
|
||||||
must: P1RFunction<T, Boolean>,
|
must: P1RFunction<T, Boolean>,
|
||||||
message: String,
|
message: String,
|
||||||
exception: Class<out Throwable> = IllegalArgumentException::class.java
|
exception: Class<out Throwable> = IllegalArgumentException::class.java,
|
||||||
): Pipeline<T> {
|
): Pipeline<T> {
|
||||||
Require.require(must.call(value), message, exception)
|
requireTrue(must.call(value), exception, message)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,9 +205,9 @@ class Pipeline<T>(private val value: T) {
|
|||||||
fun require(
|
fun require(
|
||||||
any: Any,
|
any: Any,
|
||||||
message: String,
|
message: String,
|
||||||
exception: KClass<out Throwable> = IllegalArgumentException::class
|
exception: KClass<out Throwable> = IllegalArgumentException::class,
|
||||||
): Pipeline<T> {
|
): Pipeline<T> {
|
||||||
Require.require(any == value, message, exception)
|
requireTrue(any == value, exception.java, message)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,11 +219,11 @@ class Pipeline<T>(private val value: T) {
|
|||||||
* @return 当前Pipeline实例
|
* @return 当前Pipeline实例
|
||||||
*/
|
*/
|
||||||
fun require(
|
fun require(
|
||||||
must: P1RFunction<T, Boolean>,
|
must: (T) -> Boolean,
|
||||||
message: String,
|
message: String,
|
||||||
exception: KClass<out Throwable> = IllegalArgumentException::class
|
exception: KClass<out Throwable> = IllegalArgumentException::class,
|
||||||
): Pipeline<T> {
|
): Pipeline<T> {
|
||||||
Require.require(must.call(value), message, exception)
|
requireTrue(must(value), exception.java, message)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,9 +234,9 @@ class Pipeline<T>(private val value: T) {
|
|||||||
* @return 当前Pipeline实例
|
* @return 当前Pipeline实例
|
||||||
*/
|
*/
|
||||||
fun require(
|
fun require(
|
||||||
must: P1RFunction<T, Boolean>, message: String
|
must: P1RFunction<T, Boolean>, message: String,
|
||||||
): Pipeline<T> {
|
): Pipeline<T> {
|
||||||
Require.require(must.call(value), message, IllegalArgumentException::class.java)
|
requireTrue(must.call(value), message)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +259,7 @@ class Pipeline<T>(private val value: T) {
|
|||||||
*/
|
*/
|
||||||
fun require(
|
fun require(
|
||||||
predicate: P1RFunction<T, Boolean>,
|
predicate: P1RFunction<T, Boolean>,
|
||||||
lazyMessage: P1RFunction<T, Any> = P1RFunction { "Requirement failed" }
|
lazyMessage: P1RFunction<T, Any> = P1RFunction { "Requirement failed" },
|
||||||
): Pipeline<T> {
|
): Pipeline<T> {
|
||||||
if (!predicate.call(value)) {
|
if (!predicate.call(value)) {
|
||||||
throw IllegalArgumentException(lazyMessage.call(value).toString())
|
throw IllegalArgumentException(lazyMessage.call(value).toString())
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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 BaseResponse.kt
|
||||||
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
|
* UpdateUser MingLiPro
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.mingliqiye.utils.http
|
||||||
|
|
||||||
|
open class BaseResponse<T>(
|
||||||
|
open val time: String,
|
||||||
|
open var message: String,
|
||||||
|
open var data: T,
|
||||||
|
open var statusCode: Int,
|
||||||
|
|
||||||
|
) {
|
||||||
|
/**
|
||||||
|
* 返回响应对象的字符串表示
|
||||||
|
*
|
||||||
|
* 重写toString方法以提供更有意义的对象表示,便于日志记录和调试。
|
||||||
|
* 显示时间、消息、数据类型和值以及状态码。
|
||||||
|
*
|
||||||
|
* @return 格式化的字符串表示
|
||||||
|
*/
|
||||||
|
override fun toString(): String =
|
||||||
|
"${javaClass.simpleName}(time=${time}, message=${message}, data=${data}, statusCode=${statusCode})"
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* 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 PageData.kt
|
||||||
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
|
* UpdateUser MingLiPro
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.mingliqiye.utils.http
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页数据类
|
||||||
|
*/
|
||||||
|
data class PageData<T>(
|
||||||
|
/**
|
||||||
|
* 当前页的数据列表
|
||||||
|
*/
|
||||||
|
val records: Collection<T> = emptyList(),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总条数(总记录数)
|
||||||
|
*/
|
||||||
|
val totalCount: Long = 0,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总页数
|
||||||
|
*/
|
||||||
|
val totalPages: Long = 0,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每页大小
|
||||||
|
*/
|
||||||
|
val pageSize: Long = 0,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前页码(从 1 开始)
|
||||||
|
*/
|
||||||
|
val pageIndex: Long = 0,
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
fun <T> of(page: Page<T>): PageData<T> = PageData(
|
||||||
|
records = page.records,
|
||||||
|
totalCount = page.total,
|
||||||
|
totalPages = page.pages,
|
||||||
|
pageSize = page.size,
|
||||||
|
pageIndex = page.current,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
/*
|
||||||
|
* 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 PagedResponse.kt
|
||||||
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
|
* UpdateUser MingLiPro
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.mingliqiye.utils.http
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
|
||||||
|
import com.mingliqiye.utils.time.DateTime
|
||||||
|
|
||||||
|
data class PagedResponse<T>(
|
||||||
|
override val time: String, // 响应时间,一旦创建不可修改
|
||||||
|
override var message: String, // 响应消息,可通过setter修改
|
||||||
|
override var data: PageData<T>, // 响应数据,可通过setter修改
|
||||||
|
override var statusCode: Int, // HTTP状态码,可通过setter修改
|
||||||
|
) : BaseResponse<PageData<T>>(
|
||||||
|
time,
|
||||||
|
message,
|
||||||
|
data,
|
||||||
|
statusCode
|
||||||
|
) {
|
||||||
|
companion object {
|
||||||
|
/**
|
||||||
|
* 创建一个默认的成功响应对象
|
||||||
|
* 使用默认消息"操作成功",无数据,状态码200
|
||||||
|
*
|
||||||
|
* @return Response<Nothing> 默认的成功响应对象
|
||||||
|
*/
|
||||||
|
fun ok() = ok("操作成功")
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个默认的错误响应对象
|
||||||
|
* 使用默认消息"服务器错误",无数据,状态码500
|
||||||
|
*
|
||||||
|
* @return Response<Nothing> 默认的成功响应对象
|
||||||
|
*/
|
||||||
|
fun error() = error("服务器错误")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个成功的响应对象(仅包含消息)
|
||||||
|
*
|
||||||
|
* @param message 响应消息
|
||||||
|
* @return Response<Any> 成功的响应对象,数据为null
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun ok(message: String) = PagedResponse(
|
||||||
|
time = DateTime.now().format(), message = message, data = PageData<Nothing>(), statusCode = 200
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个错误的响应对象
|
||||||
|
*
|
||||||
|
* @param message 错误消息,默认为"服务器错误"
|
||||||
|
* @param statusCode HTTP状态码,默认为500
|
||||||
|
* @return Response<Any> 错误的响应对象
|
||||||
|
*/
|
||||||
|
fun error(message: String = "服务器错误", statusCode: Int = 500) = ok(message).withStatusCode(statusCode)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个成功的响应对象(仅包含数据)
|
||||||
|
* 使用默认消息"操作成功"
|
||||||
|
*
|
||||||
|
* @param T 响应数据的类型
|
||||||
|
* @param data 响应数据
|
||||||
|
* @return Response<T> 成功的响应对象,包含数据
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun <T> okData(data: PageData<T>) = PagedResponse(
|
||||||
|
time = DateTime.now().format(), message = "操作成功", data = data, statusCode = 200
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从mybatisplus的page构建
|
||||||
|
*/
|
||||||
|
@JvmOverloads
|
||||||
|
fun <T> okPgae(
|
||||||
|
page: Page<T>,
|
||||||
|
time: String = DateTime.now().format(),
|
||||||
|
message: String = "操作成功",
|
||||||
|
statusCode: Int = 200,
|
||||||
|
): PagedResponse<T> {
|
||||||
|
|
||||||
|
return PagedResponse(
|
||||||
|
time = time, message = message, data = PageData.of(page), statusCode = statusCode
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个成功的响应对象(包含数据和消息)
|
||||||
|
*
|
||||||
|
* @param T 响应数据的类型
|
||||||
|
* @param data 响应数据
|
||||||
|
* @param message 响应消息
|
||||||
|
* @return Response<T> 成功的响应对象,包含数据和消息
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun <T> okData(data: PageData<T>, message: String) = PagedResponse(
|
||||||
|
time = DateTime.now().format(), message = message, data = data, statusCode = 200
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个指定状态码的响应对象(仅包含状态码)
|
||||||
|
* 使用默认消息"操作成功",无数据
|
||||||
|
*
|
||||||
|
* @param statusCode HTTP状态码
|
||||||
|
* @return Response<Any> 指定状态码的响应对象
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun code(statusCode: Int) = PagedResponse(
|
||||||
|
time = DateTime.now().format(), message = "操作成功", data = PageData<Nothing>(), statusCode = statusCode
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个指定状态码的响应对象(包含状态码和消息)
|
||||||
|
* 无数据
|
||||||
|
*
|
||||||
|
* @param statusCode HTTP状态码
|
||||||
|
* @param message 响应消息
|
||||||
|
* @return Response<Any> 指定状态码和消息的响应对象
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun code(statusCode: Int, message: String) = PagedResponse(
|
||||||
|
time = DateTime.now().format(), message = message, data = PageData<Nothing>(), statusCode = statusCode
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认构造函数,创建一个默认的成功响应对象
|
||||||
|
* 使用当前时间、默认消息"操作成功"、状态码200、无数据
|
||||||
|
*/
|
||||||
|
constructor() : this(
|
||||||
|
time = DateTime.now().format(), message = "操作成功", statusCode = 200, data = PageData()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置响应数据
|
||||||
|
*
|
||||||
|
* 该方法允许修改响应数据,并返回当前对象以支持链式调用。
|
||||||
|
*
|
||||||
|
* @param data 新的响应数据
|
||||||
|
* @return Response<T> 当前响应对象(支持链式调用)
|
||||||
|
*/
|
||||||
|
fun setData(data: PageData<T>): PagedResponse<T> {
|
||||||
|
this.data = data
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个新的Response对象,使用指定的时间
|
||||||
|
*
|
||||||
|
* 该方法用于创建具有新时间的响应对象,遵循不可变对象的设计模式。
|
||||||
|
* 如果时间相同,则返回原对象避免不必要的对象创建。
|
||||||
|
*
|
||||||
|
* @param time 新的响应时间
|
||||||
|
* @return Response<T> 新的响应对象(如果时间相同则返回原对象)
|
||||||
|
*/
|
||||||
|
fun withTime(time: String): PagedResponse<T> =
|
||||||
|
if (this.time == time) this else PagedResponse(time, message, data, statusCode)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个新的Response对象,使用指定的数据
|
||||||
|
*
|
||||||
|
* 该方法允许改变响应数据的类型,创建一个新的响应对象。
|
||||||
|
* 适用于需要在保持其他字段不变的情况下更新数据类型的场景。
|
||||||
|
*
|
||||||
|
* @param D 新的数据类型
|
||||||
|
* @param data 新的响应数据
|
||||||
|
* @return Response<D> 新的响应对象,数据类型为D
|
||||||
|
*/
|
||||||
|
fun <D> withData(data: PageData<D>): PagedResponse<D> =
|
||||||
|
PagedResponse(this.time, this.message, data, this.statusCode)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个新的Response对象,使用指定的消息
|
||||||
|
*
|
||||||
|
* 该方法用于创建具有新消息的响应对象,遵循不可变对象的设计模式。
|
||||||
|
* 如果消息相同,则返回原对象避免不必要的对象创建。
|
||||||
|
*
|
||||||
|
* @param message 新的响应消息
|
||||||
|
* @return Response<T> 新的响应对象(如果消息相同则返回原对象)
|
||||||
|
*/
|
||||||
|
fun withMessage(message: String): PagedResponse<T> =
|
||||||
|
if (this.message == message) this else PagedResponse(time, message, data, statusCode)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建一个新的Response对象,使用指定的状态码
|
||||||
|
*
|
||||||
|
* 该方法用于创建具有新状态码的响应对象,遵循不可变对象的设计模式。
|
||||||
|
* 如果状态码相同,则返回原对象避免不必要的对象创建。
|
||||||
|
*
|
||||||
|
* @param statusCode 新的状态码
|
||||||
|
* @return Response<T> 新的响应对象(如果状态码相同则返回原对象)
|
||||||
|
*/
|
||||||
|
fun withStatusCode(statusCode: Int): PagedResponse<T> =
|
||||||
|
if (this.statusCode == statusCode) this else PagedResponse(time, message, data, statusCode)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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 mingli-utils
|
* ProjectName FastBaseMapper.kt
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile Response.kt
|
* CurrentFile Response.kt
|
||||||
* LastUpdate 2026-03-14 08:01:32
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -38,10 +38,15 @@ import com.mingliqiye.utils.time.DateTime
|
|||||||
* @property statusCode HTTP状态码
|
* @property statusCode HTTP状态码
|
||||||
*/
|
*/
|
||||||
data class Response<T>(
|
data class Response<T>(
|
||||||
private val time: String, // 响应时间,一旦创建不可修改
|
override val time: String, // 响应时间,一旦创建不可修改
|
||||||
private var message: String, // 响应消息,可通过setter修改
|
override var message: String, // 响应消息,可通过setter修改
|
||||||
private var data: T?, // 响应数据,可通过setter修改
|
override var data: T?, // 响应数据,可通过setter修改
|
||||||
private var statusCode: Int, // HTTP状态码,可通过setter修改
|
override var statusCode: Int, // HTTP状态码,可通过setter修改
|
||||||
|
) : BaseResponse<T?>(
|
||||||
|
time,
|
||||||
|
message,
|
||||||
|
data,
|
||||||
|
statusCode,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -70,10 +75,7 @@ data class Response<T>(
|
|||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun ok(message: String) = Response(
|
fun ok(message: String) = Response(
|
||||||
time = DateTime.now().format(),
|
time = DateTime.now().format(), message = message, data = null, statusCode = 200
|
||||||
message = message,
|
|
||||||
data = null,
|
|
||||||
statusCode = 200
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,10 +97,7 @@ data class Response<T>(
|
|||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun <T> okData(data: T) = Response(
|
fun <T> okData(data: T) = Response(
|
||||||
time = DateTime.now().format(),
|
time = DateTime.now().format(), message = "操作成功", data = data, statusCode = 200
|
||||||
message = "操作成功",
|
|
||||||
data = data,
|
|
||||||
statusCode = 200
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,10 +110,7 @@ data class Response<T>(
|
|||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun <T> okData(data: T, message: String) = Response(
|
fun <T> okData(data: T, message: String) = Response(
|
||||||
time = DateTime.now().format(),
|
time = DateTime.now().format(), message = message, data = data, statusCode = 200
|
||||||
message = message,
|
|
||||||
data = data,
|
|
||||||
statusCode = 200
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,10 +122,7 @@ data class Response<T>(
|
|||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun code(statusCode: Int) = Response(
|
fun code(statusCode: Int) = Response(
|
||||||
time = DateTime.now().format(),
|
time = DateTime.now().format(), message = "操作成功", data = null, statusCode = statusCode
|
||||||
message = "操作成功",
|
|
||||||
data = null,
|
|
||||||
statusCode = statusCode
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,10 +135,7 @@ data class Response<T>(
|
|||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun code(statusCode: Int, message: String) = Response(
|
fun code(statusCode: Int, message: String) = Response(
|
||||||
time = DateTime.now().format(),
|
time = DateTime.now().format(), message = message, data = null, statusCode = statusCode
|
||||||
message = message,
|
|
||||||
data = null,
|
|
||||||
statusCode = statusCode
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,75 +144,9 @@ data class Response<T>(
|
|||||||
* 使用当前时间、默认消息"操作成功"、状态码200、无数据
|
* 使用当前时间、默认消息"操作成功"、状态码200、无数据
|
||||||
*/
|
*/
|
||||||
constructor() : this(
|
constructor() : this(
|
||||||
time = DateTime.now().format(),
|
time = DateTime.now().format(), message = "操作成功", statusCode = 200, data = null
|
||||||
message = "操作成功",
|
|
||||||
statusCode = 200,
|
|
||||||
data = null
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取格式化后的时间字符串。
|
|
||||||
*
|
|
||||||
* @return 格式化后的时间字符串
|
|
||||||
*/
|
|
||||||
fun getTime(): String = time
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取响应消息
|
|
||||||
*
|
|
||||||
* @return String 当前响应消息
|
|
||||||
*/
|
|
||||||
fun getMessage(): String = message
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置响应消息
|
|
||||||
*
|
|
||||||
* 该方法允许修改响应消息,并返回当前对象以支持链式调用。
|
|
||||||
*
|
|
||||||
* @param message 新的响应消息
|
|
||||||
* @return Response<T> 当前响应对象(支持链式调用)
|
|
||||||
*/
|
|
||||||
fun setMessage(message: String): Response<T> {
|
|
||||||
this.message = message
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取响应数据
|
|
||||||
*
|
|
||||||
* 返回的响应数据可能为null,调用前应进行空值检查。
|
|
||||||
*
|
|
||||||
* @return T? 响应数据,可能为空
|
|
||||||
*/
|
|
||||||
fun getData(): T? = data
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取非空数据对象
|
|
||||||
*
|
|
||||||
* 该方法强制解包data属性,如果data为null则会抛出NullPointerException异常。
|
|
||||||
* 适用于确定data不为null的场景,避免重复的空值检查。
|
|
||||||
*
|
|
||||||
* @return T 非空的数据对象
|
|
||||||
* @throws NullPointerException 当data属性为null时抛出此异常
|
|
||||||
*/
|
|
||||||
@Throws(NullPointerException::class)
|
|
||||||
fun notNullData(): T {
|
|
||||||
return data ?: throw NullPointerException("at Response.notNullData() because data is null")
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置响应数据
|
|
||||||
*
|
|
||||||
* 该方法允许修改响应数据,并返回当前对象以支持链式调用。
|
|
||||||
*
|
|
||||||
* @param data 新的响应数据
|
|
||||||
* @return Response<T> 当前响应对象(支持链式调用)
|
|
||||||
*/
|
|
||||||
fun setData(data: T): Response<T> {
|
|
||||||
this.data = data
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个新的Response对象,使用指定的时间
|
* 创建一个新的Response对象,使用指定的时间
|
||||||
*
|
*
|
||||||
@@ -232,8 +156,7 @@ data class Response<T>(
|
|||||||
* @param time 新的响应时间
|
* @param time 新的响应时间
|
||||||
* @return Response<T> 新的响应对象(如果时间相同则返回原对象)
|
* @return Response<T> 新的响应对象(如果时间相同则返回原对象)
|
||||||
*/
|
*/
|
||||||
fun withTime(time: String): Response<T> =
|
fun withTime(time: String): Response<T> = if (this.time == time) this else Response(time, message, data, statusCode)
|
||||||
if (this.time == time) this else Response(time, message, data, statusCode)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个新的Response对象,使用指定的数据
|
* 创建一个新的Response对象,使用指定的数据
|
||||||
@@ -245,8 +168,7 @@ data class Response<T>(
|
|||||||
* @param data 新的响应数据
|
* @param data 新的响应数据
|
||||||
* @return Response<D> 新的响应对象,数据类型为D
|
* @return Response<D> 新的响应对象,数据类型为D
|
||||||
*/
|
*/
|
||||||
fun <D> withData(data: D): Response<D> =
|
fun <D> withData(data: D): Response<D> = Response(this.time, this.message, data, this.statusCode)
|
||||||
Response(this.time, this.message, data, this.statusCode)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个新的Response对象,使用指定的消息
|
* 创建一个新的Response对象,使用指定的消息
|
||||||
@@ -272,25 +194,6 @@ data class Response<T>(
|
|||||||
fun withStatusCode(statusCode: Int): Response<T> =
|
fun withStatusCode(statusCode: Int): Response<T> =
|
||||||
if (this.statusCode == statusCode) this else Response(time, message, data, statusCode)
|
if (this.statusCode == statusCode) this else Response(time, message, data, statusCode)
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取状态码
|
|
||||||
*
|
|
||||||
* @return Int 当前HTTP状态码
|
|
||||||
*/
|
|
||||||
fun getStatusCode(): Int = statusCode
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置状态码
|
|
||||||
*
|
|
||||||
* 该方法允许修改状态码,并返回当前对象以支持链式调用。
|
|
||||||
*
|
|
||||||
* @param statusCode 新的HTTP状态码
|
|
||||||
* @return Response<T> 当前响应对象(支持链式调用)
|
|
||||||
*/
|
|
||||||
fun setStatusCode(statusCode: Int): Response<T> {
|
|
||||||
this.statusCode = statusCode
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回响应对象的字符串表示
|
* 返回响应对象的字符串表示
|
||||||
@@ -301,5 +204,5 @@ data class Response<T>(
|
|||||||
* @return 格式化的字符串表示
|
* @return 格式化的字符串表示
|
||||||
*/
|
*/
|
||||||
override fun toString(): String =
|
override fun toString(): String =
|
||||||
"Response<${data?.javaClass?.simpleName ?: "Nothing"}>(time=${getTime()}, message=${getMessage()}, data=${getData()}, statusCode=${getStatusCode()})"
|
"Response<${data?.javaClass?.simpleName ?: "Nothing"}>(time=${time}, message=${message}, data=${data}, statusCode=${statusCode})"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,35 +16,45 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile OkHttpUtils.kt
|
* CurrentFile OkHttpUtils.kt
|
||||||
* LastUpdate 2026-02-27 22:16:15
|
* LastUpdate 2026-10-22 20:20:42
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
@file:JvmName("OkHttpUtils")
|
@file:JvmName("OkHttpUtils")
|
||||||
|
|
||||||
package com.mingliqiye.utils.http.okhttp
|
package com.mingliqiye.utils.http.okhttp
|
||||||
|
|
||||||
import com.mingliqiye.utils.http.MediaType
|
|
||||||
import com.mingliqiye.utils.http.okhttp
|
|
||||||
import com.mingliqiye.utils.json.api.JSONA
|
import com.mingliqiye.utils.json.api.JSONA
|
||||||
import com.mingliqiye.utils.json.api.JSONA.toJson
|
import com.mingliqiye.utils.json.api.base.JsonApi
|
||||||
|
import com.mingliqiye.utils.json.api.base.JsonApi.Companion.parse
|
||||||
|
import okhttp3.Call
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.RequestBody.Companion.toRequestBody
|
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
|
|
||||||
|
|
||||||
inline fun <reified T> Response.json() = body.use {
|
inline fun <reified T> Response.json(jsonApi: JsonApi? = null): T = body.use {
|
||||||
|
if (jsonApi != null) {
|
||||||
|
return jsonApi.parse<T>(it.bytes())
|
||||||
|
} else {
|
||||||
JSONA.parse<T>(it.bytes())
|
JSONA.parse<T>(it.bytes())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Response.text() = body.use {
|
fun Response.text() = body.use {
|
||||||
String(it.bytes())
|
String(it.bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun OkHttpClient.request() = Request.Builder()
|
|
||||||
fun Request.Builder.call(okHttpClient: OkHttpClient) = okHttpClient.newCall(this.build())
|
|
||||||
|
|
||||||
fun Request.Builder.postWithJson(data: Any): Request.Builder {
|
fun newRequest(calld: Request.Builder.() -> Unit): Request {
|
||||||
data.toJson().toRequestBody(MediaType.APPLICATION_JSON.okhttp())
|
val request = Request.Builder()
|
||||||
return this
|
calld(request)
|
||||||
|
return request.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun OkHttpClient.newCall(calld: Request.Builder.() -> Unit): Call {
|
||||||
|
return this.newCall(newRequest(calld))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun OkHttpClient.newExecute(calld: Request.Builder.() -> Unit): Response {
|
||||||
|
return this.newCall(newRequest(calld)).execute()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile SIO.kt
|
* CurrentFile SIO.kt
|
||||||
* LastUpdate 2026-06-21 10:40:58
|
* LastUpdate 2026-10-22 20:21:49
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -29,68 +29,6 @@ import org.slf4j.Logger
|
|||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
|
|
||||||
/**
|
|
||||||
* 已弃用的IO对象,所有方法都委托给SIO对象
|
|
||||||
* @deprecated 请使用SIO对象替代
|
|
||||||
*/
|
|
||||||
@Deprecated("This IO is deprecated. reName SIO", replaceWith = ReplaceWith("SIO"), level = DeprecationLevel.WARNING)
|
|
||||||
object IO {
|
|
||||||
/**
|
|
||||||
* 打印多个参数,使用空格分隔
|
|
||||||
* @param args 要打印的参数数组
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
|
||||||
fun print(vararg args: Any?) = SIO.print(*args)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印多个参数并换行,使用空格分隔
|
|
||||||
* @param args 要打印的参数数组
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
|
||||||
fun println(vararg args: Any?) = SIO.println(*args)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印多个参数并换行,指定分隔符
|
|
||||||
* @param sp 分隔符
|
|
||||||
* @param args 要打印的参数数组
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
|
||||||
fun printlnA(sp: String, vararg args: Any?) = SIO.printlnA(sp, *args)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印多个参数,指定分隔符
|
|
||||||
* @param sp 分隔符,默认为空字符串
|
|
||||||
* @param args 要打印的参数数组
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
|
||||||
fun printA(sp: String = "", vararg args: Any?) = SIO.printA(sp, *args)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 重定向 System.out 到 INFO 级别日志
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
|
||||||
fun redirectOutToInfo() = SIO.redirectOutToInfo()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 重定向 System.err 到 ERROR 级别
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
|
||||||
fun redirectErrToError() = SIO.redirectErrToError()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 完全重定向(包括第三方库的输出)
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
|
||||||
fun redirectAll() = SIO.redirectAll()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 恢复原始输出流
|
|
||||||
*/
|
|
||||||
@JvmStatic
|
|
||||||
fun restore() = SIO.restore()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IO工具类,提供打印功能和系统输出流重定向到日志的功能
|
* IO工具类,提供打印功能和系统输出流重定向到日志的功能
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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 mingli-utils
|
* ProjectName FastBaseMapper.kt
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile JsonConverterUtils.kt
|
* CurrentFile JsonConverterUtils.kt
|
||||||
* LastUpdate 2026-02-26 16:01:49
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
@file:JvmName("JsonConverterUtils")
|
@file:JvmName("JsonConverterUtils")
|
||||||
@@ -74,11 +74,11 @@ inline fun <reified T : BaseJsonConverter<*, *>> com.fasterxml.jackson.databind.
|
|||||||
* @return 配置了自定义序列化器和反序列化器的 SimpleModule 对象。
|
* @return 配置了自定义序列化器和反序列化器的 SimpleModule 对象。
|
||||||
*/
|
*/
|
||||||
fun <F, T> JsonConverter<F, T>.getJacksonModule(): com.fasterxml.jackson.databind.module.SimpleModule =
|
fun <F, T> JsonConverter<F, T>.getJacksonModule(): com.fasterxml.jackson.databind.module.SimpleModule =
|
||||||
com.fasterxml.jackson.databind.module.SimpleModule("${getFromClass().name}To${getToClass().name}")
|
com.fasterxml.jackson.databind.module.SimpleModule("(${getFromClass().name})-(${getToClass().name})")
|
||||||
.addSerializer(getFromClass(), JackJsonSerializer(null, this))
|
.addSerializer(getFromClass(), JackJsonSerializer(null, this))
|
||||||
.addDeserializer(getFromClass(), JackJsonDeserializer(null, this))
|
.addDeserializer(getFromClass(), JackJsonDeserializer(null, this))
|
||||||
|
|
||||||
fun <F, T> JsonConverter<F, T>.getJackson3Module(): tools.jackson.databind.module.SimpleModule =
|
fun <F, T> JsonConverter<F, T>.getJackson3Module(): tools.jackson.databind.module.SimpleModule =
|
||||||
tools.jackson.databind.module.SimpleModule("${getFromClass().name}To${getToClass().name}")
|
tools.jackson.databind.module.SimpleModule("(${getFromClass().name})-(${getToClass().name})")
|
||||||
.addSerializer(getFromClass(), JackJson3Serializer(null, this))
|
.addSerializer(getFromClass(), JackJson3Serializer(null, this))
|
||||||
.addDeserializer(getFromClass(), JackJson3Deserializer(null, this))
|
.addDeserializer(getFromClass(), JackJson3Deserializer(null, this))
|
||||||
|
|||||||
@@ -13,25 +13,15 @@
|
|||||||
* 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 mingli-utils
|
* ProjectName FastBaseMapper.kt
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile BaseMapperQuery.kt
|
* CurrentFile BaseMapperQuery.kt
|
||||||
* LastUpdate 2026-10-12 13:33:03
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.mingliqiye.utils.mybatisplus
|
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.conditions.update.LambdaUpdateWrapper
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
@Deprecated(
|
@Deprecated(
|
||||||
"rename to FastBaseMapper",
|
"rename to FastBaseMapper",
|
||||||
@@ -45,112 +35,4 @@ import com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper
|
|||||||
* @since 4.6.1
|
* @since 4.6.1
|
||||||
* 已经重命名 [FastBaseMapper]
|
* 已经重命名 [FastBaseMapper]
|
||||||
*/
|
*/
|
||||||
interface BaseMapperQuery<T> : FastBaseMapper<T>
|
typealias BaseMapperQuery<T> = FastBaseMapper<T>
|
||||||
|
|
||||||
/**
|
|
||||||
* 扩展[BaseMapper]接口,提供便捷的查询和更新包装器创建方法
|
|
||||||
* 包含普通包装器、`Lambda`包装器和`Kotlin`专用包装器的创建方法
|
|
||||||
*/
|
|
||||||
interface FastBaseMapper<T> : BaseMapper<T> {
|
|
||||||
/**
|
|
||||||
* 创建[QueryWrapper]实例
|
|
||||||
* @return QueryWrapper<T> 查询包装器实例
|
|
||||||
*/
|
|
||||||
fun queryWrapper() = QueryWrapper<T>()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建[UpdateWrapper]实例
|
|
||||||
* @return UpdateWrapper<T> 更新包装器实例
|
|
||||||
*/
|
|
||||||
fun updateWrapper() = UpdateWrapper<T>()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建[LambdaQueryWrapper]实例
|
|
||||||
* @return LambdaQueryWrapper<T> Lambda查询包装器实例
|
|
||||||
*/
|
|
||||||
fun lambdaQueryWrapper() = LambdaQueryWrapper<T>()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建[LambdaUpdateWrapper]实例
|
|
||||||
* @return LambdaUpdateWrapper<T> Lambda更新包装器实例
|
|
||||||
*/
|
|
||||||
fun lambdaUpdateWrapper() = LambdaUpdateWrapper<T>()
|
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 为[BaseMapper]创建[QueryWrapper]实例
|
|
||||||
* @param T 范型类型,通过reified获取实际类型
|
|
||||||
* @receiver BaseMapper<T> 基础映射器实例
|
|
||||||
* @return QueryWrapper<T> 查询包装器实例,使用T类作为参数
|
|
||||||
*/
|
|
||||||
inline fun <reified T> BaseMapper<T>.queryWrapper(): QueryWrapper<T> = QueryWrapper<T>(T::class.java)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 为[BaseMapper]创建[UpdateWrapper]实例
|
|
||||||
* @param T 范型类型,通过reified获取实际类型
|
|
||||||
* @receiver BaseMapper<T> 基础映射器实例
|
|
||||||
* @return UpdateWrapper<T> 更新包装器实例
|
|
||||||
*/
|
|
||||||
inline fun <reified T> BaseMapper<T>.updateWrapper(): UpdateWrapper<T> = UpdateWrapper<T>()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 为[BaseMapper]创建[LambdaQueryWrapper]实例
|
|
||||||
* @param T 范型类型,通过reified获取实际类型
|
|
||||||
* @receiver BaseMapper<T> 基础映射器实例
|
|
||||||
* @return LambdaQueryWrapper<T> Lambda查询包装器实例,使用T类作为参数
|
|
||||||
*/
|
|
||||||
inline fun <reified T> BaseMapper<T>.lambdaQueryWrapper(): LambdaQueryWrapper<T> =
|
|
||||||
LambdaQueryWrapper<T>(T::class.java)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 为[BaseMapper]创建[LambdaUpdateWrapper]实例
|
|
||||||
* @param T 范型类型,通过reified获取实际类型
|
|
||||||
* @receiver BaseMapper<T> 基础映射器实例
|
|
||||||
* @return LambdaUpdateWrapper<T> Lambda更新包装器实例,使用T类作为参数
|
|
||||||
*/
|
|
||||||
inline fun <reified T> BaseMapper<T>.lambdaUpdateWrapper(): LambdaUpdateWrapper<T> =
|
|
||||||
LambdaUpdateWrapper<T>(T::class.java)
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 为[BaseMapper]创建[KtQueryWrapper]实例
|
|
||||||
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
|
||||||
* @receiver BaseMapper<T> 基础映射器实例
|
|
||||||
* @return KtQueryWrapper<T> Kotlin查询包装器实例,使用T类作为参数
|
|
||||||
*/
|
|
||||||
inline fun <reified T : Any> BaseMapper<T>.ktQueryWrapper(): KtQueryWrapper<T> = KtQueryWrapper(T::class.java)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 为[BaseMapper]创建[KtQueryChainWrapper]实例
|
|
||||||
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
|
||||||
* @receiver BaseMapper<T> 基础映射器实例
|
|
||||||
* @return KtQueryChainWrapper<T> Kotlin查询链式包装器实例,使用T类作为参数
|
|
||||||
*/
|
|
||||||
inline fun <reified T : Any> BaseMapper<T>.ktQueryChainWrapper(): KtQueryChainWrapper<T> =
|
|
||||||
KtQueryChainWrapper(T::class.java)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 为[BaseMapper]创建[KtUpdateWrapper]实例
|
|
||||||
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
|
||||||
* @receiver BaseMapper<T> 基础映射器实例
|
|
||||||
* @return KtUpdateWrapper<T> Kotlin更新包装器实例,使用T类作为参数
|
|
||||||
*/
|
|
||||||
inline fun <reified T : Any> BaseMapper<T>.ktUpdateWrapper(): KtUpdateWrapper<T> =
|
|
||||||
KtUpdateWrapper(T::class.java)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 为[BaseMapper]创建[KtUpdateChainWrapper]实例
|
|
||||||
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
|
||||||
* @receiver BaseMapper<T> 基础映射器实例
|
|
||||||
* @return KtUpdateChainWrapper<T> Kotlin更新链式包装器实例,使用T类作为参数
|
|
||||||
*/
|
|
||||||
inline fun <reified T : Any> BaseMapper<T>.ktUpdateChainWrapper(): KtUpdateChainWrapper<T> =
|
|
||||||
KtUpdateChainWrapper(T::class.java)
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,866 @@
|
|||||||
|
/*
|
||||||
|
* 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 FastBaseMapper.kt
|
||||||
|
* LastUpdate 2026-10-27 10:23:10
|
||||||
|
* 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.conditions.update.LambdaUpdateWrapper
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper
|
||||||
|
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.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktQueryChainWrapper
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktQueryWrapper
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktUpdateChainWrapper
|
||||||
|
import com.mingliqiye.utils.mybatisplus.FastBaseMapper.Companion.ktUpdateWrapper
|
||||||
|
import com.mingliqiye.utils.tuple.Tuple
|
||||||
|
import kotlin.reflect.KProperty1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展[com.baomidou.mybatisplus.core.mapper.BaseMapper]接口,提供便捷的查询和更新包装器创建方法
|
||||||
|
* 包含普通包装器、`Lambda`包装器和`Kotlin`专用包装器的创建方法
|
||||||
|
*/
|
||||||
|
interface FastBaseMapper<T> : BaseMapper<T> {
|
||||||
|
/**
|
||||||
|
* 创建[com.baomidou.mybatisplus.core.conditions.query.QueryWrapper]实例
|
||||||
|
* @return QueryWrapper<T> 查询包装器实例
|
||||||
|
*/
|
||||||
|
fun queryWrapper() = QueryWrapper<T>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建[com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper]实例
|
||||||
|
* @return UpdateWrapper<T> 更新包装器实例
|
||||||
|
*/
|
||||||
|
fun updateWrapper() = UpdateWrapper<T>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建[com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper]实例
|
||||||
|
* @return LambdaQueryWrapper<T> Lambda查询包装器实例
|
||||||
|
*/
|
||||||
|
fun lambdaQueryWrapper() = LambdaQueryWrapper<T>()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建[com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper]实例
|
||||||
|
* @return LambdaUpdateWrapper<T> Lambda更新包装器实例
|
||||||
|
*/
|
||||||
|
fun lambdaUpdateWrapper() = LambdaUpdateWrapper<T>()
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [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,
|
||||||
|
): List<T> = selectListByColumn(column, value, qw())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[QueryWrapper]上追加字符串列名等值条件并查询记录列表
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @param wrapper 承载查询条件的查询包装器
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun <R> selectListByColumn(
|
||||||
|
column: String,
|
||||||
|
value: R,
|
||||||
|
wrapper: QueryWrapper<T>,
|
||||||
|
): List<T> = selectList(wrapper.eq(column, value))
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按方法引用列等值条件查询记录列表
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun <R> selectListByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: R,
|
||||||
|
): List<T> = selectListByColumn(column, value, lqw())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[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>,
|
||||||
|
): List<T> = selectList(wrapper.eq(column, value))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按方法引用列IN条件查询记录列表,集合为空时直接返回空列表而不执行查询
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun <R> selectListByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
): List<T> = 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(),
|
||||||
|
): List<T> {
|
||||||
|
if (value.isEmpty()) return emptyList()
|
||||||
|
return selectList(wrapper.`in`(column, value))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按字符串列名IN条件查询记录列表,集合为空时直接返回空列表而不执行查询
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun <R> selectListByColumn(
|
||||||
|
column: String,
|
||||||
|
value: Collection<R>,
|
||||||
|
): List<T> = 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(),
|
||||||
|
): List<T> {
|
||||||
|
if (value.isEmpty()) return emptyList()
|
||||||
|
return selectList(wrapper.`in`(column, value))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符串列名与列值构成的二元组,用于[selectListByColumns]的可变参数传参
|
||||||
|
* @property t1 列名(数据库字段名)
|
||||||
|
* @property t2 列值
|
||||||
|
*/
|
||||||
|
class StringAnyTuple2(
|
||||||
|
val t1: String,
|
||||||
|
val t2: Any,
|
||||||
|
) : Tuple(2) {
|
||||||
|
operator fun component1() = t1
|
||||||
|
operator fun component2() = t2
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 方法引用列与列值构成的二元组,用于[selectListByColumns]的可变参数传参
|
||||||
|
* @param T 实体类型
|
||||||
|
* @param D 列值类型
|
||||||
|
* @property t1 实体列的方法引用
|
||||||
|
* @property t2 列值
|
||||||
|
*/
|
||||||
|
class SFunctionAnyTuple2<T, D>(
|
||||||
|
val t1: SFunction<T, D>,
|
||||||
|
val t2: D,
|
||||||
|
) : Tuple(2) {
|
||||||
|
operator fun component1() = t1
|
||||||
|
operator fun component2() = t2
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按多个字符串列名等值条件查询记录列表,各列条件以AND连接
|
||||||
|
* @param columns 列名与列值构成的二元组,逐项执行等值匹配
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun selectListByColumns(
|
||||||
|
vararg columns: StringAnyTuple2,
|
||||||
|
): List<T> = selectList(qw().let { wrapper ->
|
||||||
|
columns.forEach { (column, value) ->
|
||||||
|
wrapper.eq(column, value)
|
||||||
|
}
|
||||||
|
wrapper
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按多个方法引用列等值条件查询记录列表,各列条件以AND连接
|
||||||
|
* @param columns 方法引用列与列值构成的二元组,逐项执行等值匹配
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun selectListByColumns(
|
||||||
|
vararg columns: SFunctionAnyTuple2<T, *>,
|
||||||
|
): List<T> = selectListByColumns(lqw(), *columns)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在给定[LambdaQueryWrapper]上追加多个方法引用列等值条件并查询记录列表,各列条件以AND连接
|
||||||
|
* @param wrapper 承载查询条件的Lambda查询包装器
|
||||||
|
* @param columns 方法引用列与列值构成的二元组,逐项执行等值匹配
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
fun selectListByColumns(
|
||||||
|
wrapper: LambdaQueryWrapper<T>,
|
||||||
|
vararg columns: SFunctionAnyTuple2<T, *>,
|
||||||
|
): List<T> = selectList(wrapper.let {
|
||||||
|
columns.forEach { (column, value) ->
|
||||||
|
it.eq(column, value)
|
||||||
|
}
|
||||||
|
it
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按字符串列名等值条件查询单条记录,结果数量不为1时返回null
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @return T? 唯一的查询结果,不存在或多于一条时返回null
|
||||||
|
*/
|
||||||
|
fun <R> selectOneByColumn(
|
||||||
|
column: String,
|
||||||
|
value: R,
|
||||||
|
): T? = 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(),
|
||||||
|
): T? = selectOne(
|
||||||
|
wrapper.eq(column, value),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按方法引用列等值条件查询单条记录,结果数量不为1时返回null
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @return T? 唯一的查询结果,不存在或多于一条时返回null
|
||||||
|
*/
|
||||||
|
fun <R> selectOneByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: R,
|
||||||
|
): T? = 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>,
|
||||||
|
): T? = selectOne(
|
||||||
|
wrapper.eq(column, value),
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按字符串列名等值条件判断记录是否存在
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @return Boolean 存在符合条件的记录返回true,否则返回false
|
||||||
|
*/
|
||||||
|
fun <R> existsByColumn(
|
||||||
|
column: String,
|
||||||
|
value: R,
|
||||||
|
): Boolean = 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(),
|
||||||
|
): Boolean = exists(
|
||||||
|
wrapper.eq(column, value),
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按方法引用列等值条件判断记录是否存在
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @return Boolean 存在符合条件的记录返回true,否则返回false
|
||||||
|
*/
|
||||||
|
fun <R> existsByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: R,
|
||||||
|
): Boolean = 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(),
|
||||||
|
): Boolean = exists(
|
||||||
|
wrapper.eq(column, value),
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按方法引用列IN条件查询记录并构建有序映射,集合为空时直接返回空映射而不执行查询
|
||||||
|
* 返回的[LinkedHashMap]保持入参集合的迭代顺序,缺失的键对应的值为null
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @return LinkedHashMap<R, T?> 以列值为键、实体为值的有序映射
|
||||||
|
*/
|
||||||
|
fun <R> selectMapByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
): LinkedHashMap<R, T?> {
|
||||||
|
return 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(),
|
||||||
|
): LinkedHashMap<R, T?> {
|
||||||
|
if (value.isEmpty()) return linkedMapOf()
|
||||||
|
|
||||||
|
val data = selectList(wrapper.`in`(column, value))
|
||||||
|
|
||||||
|
val mapdata: Map<R, T> = data.associateBy { column.apply(it) }
|
||||||
|
|
||||||
|
val map = LinkedHashMap<R, T?>(value.size)
|
||||||
|
value.forEach { key ->
|
||||||
|
map[key] = mapdata[key]
|
||||||
|
}
|
||||||
|
return map
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按字符串列名IN条件删除记录,集合为空时直接返回0而不执行删除
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 列名(数据库字段名)
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @return Int 被删除的行数
|
||||||
|
*/
|
||||||
|
fun <R> deleteByColumn(
|
||||||
|
column: String,
|
||||||
|
value: Collection<R>,
|
||||||
|
): Int {
|
||||||
|
return 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(),
|
||||||
|
): Int {
|
||||||
|
if (value.isEmpty()) return 0
|
||||||
|
return delete(
|
||||||
|
wrapper.`in`(
|
||||||
|
column, value
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按方法引用列IN条件删除记录,集合为空时直接返回0而不执行删除
|
||||||
|
* @param R 列值类型
|
||||||
|
* @param column 实体列的方法引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @return Int 被删除的行数
|
||||||
|
*/
|
||||||
|
fun <R> deleteByColumn(
|
||||||
|
column: SFunction<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
): Int {
|
||||||
|
return 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>,
|
||||||
|
): Int {
|
||||||
|
if (value.isEmpty()) return 0
|
||||||
|
return delete(
|
||||||
|
wrapper.`in`(
|
||||||
|
column, value
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为[BaseMapper]创建[com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper]实例
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver BaseMapper<T> 基础映射器实例
|
||||||
|
* @return KtQueryWrapper<T> Kotlin查询包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> BaseMapper<T>.ktQueryWrapper(): KtQueryWrapper<T> = KtQueryWrapper(T::class.java)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为[BaseMapper]创建[com.baomidou.mybatisplus.extension.kotlin.KtQueryChainWrapper]实例
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver BaseMapper<T> 基础映射器实例
|
||||||
|
* @return KtQueryChainWrapper<T> Kotlin查询链式包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> BaseMapper<T>.ktQueryChainWrapper(): KtQueryChainWrapper<T> =
|
||||||
|
KtQueryChainWrapper(T::class.java)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为[BaseMapper]创建[com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper]实例
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver BaseMapper<T> 基础映射器实例
|
||||||
|
* @return KtUpdateWrapper<T> Kotlin更新包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> BaseMapper<T>.ktUpdateWrapper(): KtUpdateWrapper<T> =
|
||||||
|
KtUpdateWrapper(T::class.java)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为[BaseMapper]创建[com.baomidou.mybatisplus.extension.kotlin.KtUpdateChainWrapper]实例
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver BaseMapper<T> 基础映射器实例
|
||||||
|
* @return KtUpdateChainWrapper<T> Kotlin更新链式包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> BaseMapper<T>.ktUpdateChainWrapper(): KtUpdateChainWrapper<T> =
|
||||||
|
KtUpdateChainWrapper(T::class.java)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建绑定当前映射器的[com.baomidou.mybatisplus.extension.kotlin.KtQueryChainWrapper]实例
|
||||||
|
* 与[ktQueryChainWrapper]不同,该链式包装器持有映射器引用,可直接调用`list`/`one`/`page`等方法执行查询
|
||||||
|
* @param T 范型类型,必须继承自Any
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @return KtQueryChainWrapper<T> 可执行的Kotlin查询链式包装器实例
|
||||||
|
*/
|
||||||
|
fun <T : Any> FastBaseMapper<T>.ktQueryChain(): KtQueryChainWrapper<T> =
|
||||||
|
KtQueryChainWrapper<T>(this as BaseMapper<T>)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建绑定当前映射器的[com.baomidou.mybatisplus.extension.kotlin.KtUpdateChainWrapper]实例
|
||||||
|
* 与[ktUpdateChainWrapper]不同,该链式包装器持有映射器引用,可直接调用`update`/`remove`等方法执行操作
|
||||||
|
* @param T 范型类型,必须继承自Any
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @return KtUpdateChainWrapper<T> 可执行的Kotlin更新链式包装器实例
|
||||||
|
*/
|
||||||
|
fun <T : Any> FastBaseMapper<T>.ktUpdateChain(): KtUpdateChainWrapper<T> =
|
||||||
|
KtUpdateChainWrapper<T>(this as BaseMapper<T>)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [ktQueryWrapper]的简写形式
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @return KtQueryWrapper<T> Kotlin查询包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> FastBaseMapper<T>.kqw(): KtQueryWrapper<T> = ktQueryWrapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [ktUpdateWrapper]的简写形式
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @return KtUpdateWrapper<T> Kotlin更新包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> FastBaseMapper<T>.kuw(): KtUpdateWrapper<T> = ktUpdateWrapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [ktQueryChainWrapper]的简写形式
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @return KtQueryChainWrapper<T> Kotlin查询链式包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> FastBaseMapper<T>.kqcw(): KtQueryChainWrapper<T> = ktQueryChainWrapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [ktUpdateChainWrapper]的简写形式
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @return KtUpdateChainWrapper<T> Kotlin更新链式包装器实例,使用T类作为参数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> FastBaseMapper<T>.kucw(): KtUpdateChainWrapper<T> = ktUpdateChainWrapper()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper]并执行更新
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param funs 更新包装器构建函数,返回构建完成的更新包装器
|
||||||
|
* @return Int 受影响的行数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> FastBaseMapper<T>.update(funs: (wrapper: KtUpdateWrapper<T>) -> KtUpdateWrapper<T>): Int =
|
||||||
|
this.update(funs(kuw()))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[com.baomidou.mybatisplus.extension.kotlin.KtUpdateWrapper]并携带实体执行更新
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param entity 承载待更新字段值的实体对象
|
||||||
|
* @param funs 更新包装器构建函数,返回构建完成的更新包装器
|
||||||
|
* @return Int 受影响的行数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> FastBaseMapper<T>.update(
|
||||||
|
entity: T,
|
||||||
|
funs: (wrapper: KtUpdateWrapper<T>) -> KtUpdateWrapper<T>,
|
||||||
|
): Int = this.update(entity, funs(kuw()))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper]并执行查询
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param funs 查询包装器构建函数,返回构建完成的查询包装器
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> FastBaseMapper<T>.selectList(funs: (wrapper: KtQueryWrapper<T>) -> KtQueryWrapper<T>): List<T> =
|
||||||
|
this.selectList(funs(kqw()))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper]并执行分页查询
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param page 分页参数对象
|
||||||
|
* @param funs 查询包装器构建函数,返回构建完成的查询包装器
|
||||||
|
* @return Page<T> 分页查询结果
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> FastBaseMapper<T>.selectPage(
|
||||||
|
page: Page<T>,
|
||||||
|
funs: (wrapper: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
): Page<T> = this.selectPage(page, funs(kqw()))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过页码与每页大小直接执行分页查询
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param current 当前页码,从1开始
|
||||||
|
* @param size 每页记录数
|
||||||
|
* @param funs 查询包装器构建函数,返回构建完成的查询包装器
|
||||||
|
* @return Page<T> 分页查询结果
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> FastBaseMapper<T>.selectPage(
|
||||||
|
current: Long,
|
||||||
|
size: Long,
|
||||||
|
funs: (wrapper: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
): Page<T> = this.selectPage(Page(current, size), funs(kqw()))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper]并查询单条记录
|
||||||
|
* 结果数量不为1时返回null,不抛出异常
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param funs 查询包装器构建函数,返回构建完成的查询包装器
|
||||||
|
* @return T? 唯一的查询结果,不存在或多于一条时返回null
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> FastBaseMapper<T>.selectOne(funs: (wrapper: KtQueryWrapper<T>) -> KtQueryWrapper<T>): T? =
|
||||||
|
this.selectList(funs).let {
|
||||||
|
if (it.size != 1) null
|
||||||
|
else it[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper]并统计记录数
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param funs 查询包装器构建函数,返回构建完成的查询包装器
|
||||||
|
* @return Long 符合条件的记录总数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> FastBaseMapper<T>.selectCount(funs: (wrapper: KtQueryWrapper<T>) -> KtQueryWrapper<T>): Long =
|
||||||
|
this.selectCount(funs(kqw()))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper]并判断记录是否存在
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param funs 查询包装器构建函数,返回构建完成的查询包装器
|
||||||
|
* @return Boolean 存在符合条件的记录返回true,否则返回false
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> FastBaseMapper<T>.exists(funs: (wrapper: KtQueryWrapper<T>) -> KtQueryWrapper<T>): Boolean =
|
||||||
|
this.exists(funs(kqw()))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过Lambda构建[com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper]并执行删除
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param funs 查询包装器构建函数,返回构建完成的查询包装器
|
||||||
|
* @return Int 被删除的行数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> FastBaseMapper<T>.delete(funs: (wrapper: KtQueryWrapper<T>) -> KtQueryWrapper<T>): Int =
|
||||||
|
this.delete(funs(kqw()))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单列等值条件查询记录列表
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param R 列值类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param column 实体列属性引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在等值条件之前应用
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, R> FastBaseMapper<T>.selectListByColumn(
|
||||||
|
column: KProperty1<T, R>,
|
||||||
|
value: R,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
): List<T> = selectList { wrapper: KtQueryWrapper<T> ->
|
||||||
|
funs(wrapper).eq(column, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单列IN条件查询记录列表,集合为空时直接返回空列表而不执行查询
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param R 列值类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param column 实体列属性引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在IN条件之前应用
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, R> FastBaseMapper<T>.selectListByColumn(
|
||||||
|
column: KProperty1<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
): List<T> {
|
||||||
|
if (value.isEmpty()) return emptyList()
|
||||||
|
return selectList { wrapper: KtQueryWrapper<T> ->
|
||||||
|
funs(wrapper).`in`(column, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按多列等值条件查询记录列表
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param columns 列属性引用与列值的键值对,逐项执行等值匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在各列等值条件之前应用
|
||||||
|
* @return List<T> 查询结果列表
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any> FastBaseMapper<T>.selectListByColumns(
|
||||||
|
vararg columns: Pair<KProperty1<T, *>, Any?>,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
): List<T> = selectList { wrapper: KtQueryWrapper<T> ->
|
||||||
|
val w = funs(wrapper)
|
||||||
|
columns.forEach { (column, value) -> w.eq(column, value) }
|
||||||
|
w
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单列等值条件查询单条记录,结果数量不为1时返回null
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param R 列值类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param column 实体列属性引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在等值条件之前应用
|
||||||
|
* @return T? 唯一的查询结果,不存在或多于一条时返回null
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, R> FastBaseMapper<T>.selectOneByColumn(
|
||||||
|
column: KProperty1<T, R>,
|
||||||
|
value: R,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
): T? = selectOne { wrapper: KtQueryWrapper<T> ->
|
||||||
|
funs(wrapper).eq(column, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单列等值条件判断记录是否存在
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param R 列值类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param column 实体列属性引用
|
||||||
|
* @param funs 附加查询包装器构建函数,在等值条件之前应用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @return Boolean 存在符合条件的记录返回true,否则返回false
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, R> FastBaseMapper<T>.existsByColumn(
|
||||||
|
column: KProperty1<T, R>,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
value: R,
|
||||||
|
): Boolean = exists { wrapper: KtQueryWrapper<T> ->
|
||||||
|
funs(wrapper).eq(column, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单列IN条件查询记录并构建有序映射,集合为空时直接返回空映射而不执行查询
|
||||||
|
* 返回的[LinkedHashMap]保持入参集合的迭代顺序,缺失的键对应的值为null
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param R 列值类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param column 实体列属性引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在IN条件之前应用
|
||||||
|
* @return LinkedHashMap<R, T?> 以列值为键、实体为值的有序映射
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, R> FastBaseMapper<T>.selectMapByColumn(
|
||||||
|
column: KProperty1<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
): LinkedHashMap<R, T?> {
|
||||||
|
if (value.isEmpty()) return linkedMapOf()
|
||||||
|
|
||||||
|
val data = selectList { wrapper: KtQueryWrapper<T> ->
|
||||||
|
funs(wrapper).`in`(column, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
val mapdata: Map<R, T> = data.associateBy { column(it) }
|
||||||
|
|
||||||
|
val map = LinkedHashMap<R, T?>(value.size)
|
||||||
|
value.forEach { key ->
|
||||||
|
map[key] = mapdata[key]
|
||||||
|
}
|
||||||
|
return map
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单列等值条件删除记录
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param R 列值类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param column 实体列属性引用
|
||||||
|
* @param value 列值,执行等值匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在等值条件之前应用
|
||||||
|
* @return Int 被删除的行数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, R> FastBaseMapper<T>.deleteByColumn(
|
||||||
|
column: KProperty1<T, R>,
|
||||||
|
value: R,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
): Int = delete { wrapper: KtQueryWrapper<T> ->
|
||||||
|
funs(wrapper).eq(column, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按单列IN条件删除记录,集合为空时直接返回0而不执行删除
|
||||||
|
* 注意:MyBatis-Plus对空集合的IN条件会整体跳过,若不拦截将导致全表删除
|
||||||
|
* @param T 范型类型,必须继承自Any,通过reified获取实际类型
|
||||||
|
* @param R 列值类型
|
||||||
|
* @receiver FastBaseMapper<T> 快速映射器实例
|
||||||
|
* @param column 实体列属性引用
|
||||||
|
* @param value 列值集合,执行IN匹配
|
||||||
|
* @param funs 附加查询包装器构建函数,在IN条件之前应用
|
||||||
|
* @return Int 被删除的行数
|
||||||
|
*/
|
||||||
|
inline fun <reified T : Any, R> FastBaseMapper<T>.deleteByColumn(
|
||||||
|
column: KProperty1<T, R>,
|
||||||
|
value: Collection<R>,
|
||||||
|
funs: (w: KtQueryWrapper<T>) -> KtQueryWrapper<T> = { it },
|
||||||
|
): Int {
|
||||||
|
if (value.isEmpty()) return 0
|
||||||
|
return delete { wrapper: KtQueryWrapper<T> ->
|
||||||
|
funs(wrapper).`in`(column, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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 BooleanUtils.kt
|
||||||
|
* LastUpdate 2026-10-22 19:57:04
|
||||||
|
* UpdateUser MingLiPro
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.mingliqiye.utils.objects
|
||||||
|
|
||||||
|
class BooleanIfFunction(private val boolean: Boolean) {
|
||||||
|
|
||||||
|
fun elses(function: () -> Unit): Boolean {
|
||||||
|
if (boolean) {
|
||||||
|
function()
|
||||||
|
}
|
||||||
|
return !boolean
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun Boolean.ifs(function: () -> Unit): BooleanIfFunction {
|
||||||
|
return if (this) {
|
||||||
|
function()
|
||||||
|
BooleanIfFunction(false)
|
||||||
|
} else BooleanIfFunction(true)
|
||||||
|
}
|
||||||
@@ -13,16 +13,15 @@
|
|||||||
* 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 mingli-utils
|
* ProjectName FastBaseMapper.kt
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile ObjectPool.kt
|
* CurrentFile ObjectPool.kt
|
||||||
* LastUpdate 2026-10-12 13:57:11
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.mingliqiye.utils.pool
|
package com.mingliqiye.utils.pool
|
||||||
|
|
||||||
import com.mingliqiye.utils.require.Require.require
|
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
import java.util.concurrent.locks.Condition
|
import java.util.concurrent.locks.Condition
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile RequireTrue.kt
|
* CurrentFile RequireTrue.kt
|
||||||
* LastUpdate 2026-10-20 20:05:24
|
* LastUpdate 2026-10-20 21:07:55
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -58,16 +58,17 @@ class Required<T : Throwable>(private val newException: (message: String) -> T)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun newRequired(): Required<IllegalArgumentException> {
|
|
||||||
return newRequired<IllegalArgumentException>()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T : Throwable> newRequired(clazz: Class<T>): Required<T> {
|
fun <T : Throwable> newRequired(clazz: Class<T>): Required<T> {
|
||||||
return Required {
|
return Required {
|
||||||
newException(clazz, it)
|
newException(clazz, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun newRequired(): Required<IllegalArgumentException> {
|
||||||
|
return newRequired<IllegalArgumentException>()
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmName("newRequiredInline")
|
||||||
inline fun <reified T : Throwable> newRequired(): Required<T> {
|
inline fun <reified T : Throwable> newRequired(): Required<T> {
|
||||||
return newRequired(T::class.java)
|
return newRequired(T::class.java)
|
||||||
}
|
}
|
||||||
@@ -84,6 +85,7 @@ fun <T : Throwable> newException(clazz: Class<T>, msg: String): T = try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalContracts::class)
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
@JvmName("requireTrueDef")
|
||||||
fun <T : Throwable> requireTrue(value: Boolean, clazz: Class<T>, lazyMessage: () -> String) {
|
fun <T : Throwable> requireTrue(value: Boolean, clazz: Class<T>, lazyMessage: () -> String) {
|
||||||
contract {
|
contract {
|
||||||
returns() implies value
|
returns() implies value
|
||||||
@@ -94,6 +96,7 @@ fun <T : Throwable> requireTrue(value: Boolean, clazz: Class<T>, lazyMessage: ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalContracts::class)
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
@JvmName("requireTrueInline")
|
||||||
inline fun <reified T : Throwable> requireTrue(value: Boolean, noinline lazyMessage: () -> String) {
|
inline fun <reified T : Throwable> requireTrue(value: Boolean, noinline lazyMessage: () -> String) {
|
||||||
contract {
|
contract {
|
||||||
returns() implies value
|
returns() implies value
|
||||||
@@ -102,6 +105,7 @@ inline fun <reified T : Throwable> requireTrue(value: Boolean, noinline lazyMess
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalContracts::class)
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
@JvmName("requireTrueOnBoolean")
|
||||||
fun <T : Throwable> Boolean.requireTrue(clazz: Class<T>, lazyMessage: () -> String) {
|
fun <T : Throwable> Boolean.requireTrue(clazz: Class<T>, lazyMessage: () -> String) {
|
||||||
contract {
|
contract {
|
||||||
returns() implies this@requireTrue
|
returns() implies this@requireTrue
|
||||||
@@ -110,6 +114,7 @@ fun <T : Throwable> Boolean.requireTrue(clazz: Class<T>, lazyMessage: () -> Stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalContracts::class)
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
@JvmName("requireTrueOnBoolean")
|
||||||
fun <T : Throwable> Boolean.requireTrue(clazz: Class<T>, message: String) {
|
fun <T : Throwable> Boolean.requireTrue(clazz: Class<T>, message: String) {
|
||||||
contract {
|
contract {
|
||||||
returns() implies this@requireTrue
|
returns() implies this@requireTrue
|
||||||
@@ -128,6 +133,7 @@ fun <T : Throwable> requireTrue(value: Boolean, clazz: Class<T>, message: String
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalContracts::class)
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
@JvmName("requireTrueInline")
|
||||||
inline fun <reified T : Throwable> requireTrue(value: Boolean, message: String) {
|
inline fun <reified T : Throwable> requireTrue(value: Boolean, message: String) {
|
||||||
contract {
|
contract {
|
||||||
returns() implies value
|
returns() implies value
|
||||||
@@ -137,6 +143,7 @@ inline fun <reified T : Throwable> requireTrue(value: Boolean, message: String)
|
|||||||
|
|
||||||
|
|
||||||
@OptIn(ExperimentalContracts::class)
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
@JvmName("requireTrueOnBoolean")
|
||||||
inline fun <reified T : Throwable> Boolean.requireTrue(noinline lazyMessage: () -> String) {
|
inline fun <reified T : Throwable> Boolean.requireTrue(noinline lazyMessage: () -> String) {
|
||||||
contract {
|
contract {
|
||||||
returns() implies this@requireTrue
|
returns() implies this@requireTrue
|
||||||
@@ -146,6 +153,7 @@ inline fun <reified T : Throwable> Boolean.requireTrue(noinline lazyMessage: ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalContracts::class)
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
@JvmName("requireTrueOnBoolean")
|
||||||
inline fun <reified T : Throwable> Boolean.requireTrue(message: String) {
|
inline fun <reified T : Throwable> Boolean.requireTrue(message: String) {
|
||||||
contract {
|
contract {
|
||||||
returns() implies this@requireTrue
|
returns() implies this@requireTrue
|
||||||
@@ -163,6 +171,7 @@ fun <T : Throwable> requireTrue(value: Boolean, clazz: Class<T>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalContracts::class)
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
@JvmName("requireTrueInline")
|
||||||
inline fun <reified T : Throwable> requireTrue(value: Boolean) {
|
inline fun <reified T : Throwable> requireTrue(value: Boolean) {
|
||||||
contract {
|
contract {
|
||||||
returns() implies value
|
returns() implies value
|
||||||
@@ -170,8 +179,33 @@ inline fun <reified T : Throwable> requireTrue(value: Boolean) {
|
|||||||
requireTrue(value, T::class.java) { DEFAULT_MESSAGE }
|
requireTrue(value, T::class.java) { DEFAULT_MESSAGE }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
fun requireTrue(value: Boolean) {
|
||||||
|
contract {
|
||||||
|
returns() implies value
|
||||||
|
}
|
||||||
|
requireTrue(value, IllegalArgumentException::class.java) { DEFAULT_MESSAGE }
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalContracts::class)
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
fun requireTrue(value: Boolean, message: String) {
|
||||||
|
contract {
|
||||||
|
returns() implies value
|
||||||
|
}
|
||||||
|
requireTrue(value, IllegalArgumentException::class.java) { message }
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
fun requireTrue(value: Boolean, lazyMessage: () -> String) {
|
||||||
|
contract {
|
||||||
|
returns() implies value
|
||||||
|
}
|
||||||
|
requireTrue(value, IllegalArgumentException::class.java, lazyMessage)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
@JvmName("requireTrueOnBoolean")
|
||||||
fun <T : Throwable> Boolean.requireTrue(clazz: Class<T>) {
|
fun <T : Throwable> Boolean.requireTrue(clazz: Class<T>) {
|
||||||
contract {
|
contract {
|
||||||
returns() implies this@requireTrue
|
returns() implies this@requireTrue
|
||||||
@@ -181,6 +215,7 @@ fun <T : Throwable> Boolean.requireTrue(clazz: Class<T>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalContracts::class)
|
@OptIn(ExperimentalContracts::class)
|
||||||
|
@JvmName("requireTrueOnBoolean")
|
||||||
inline fun <reified T : Throwable> Boolean.requireTrue() {
|
inline fun <reified T : Throwable> Boolean.requireTrue() {
|
||||||
contract {
|
contract {
|
||||||
returns() implies this@requireTrue
|
returns() implies this@requireTrue
|
||||||
|
|||||||
+29
-9
@@ -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 mingli-utils
|
* ProjectName FastBaseMapper.kt
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile Jackson3AutoConfiguration.kt
|
* CurrentFile Jackson3AutoConfiguration.kt
|
||||||
* LastUpdate 2026-10-02 16:11:12
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -38,15 +38,35 @@ open class Jackson3AutoConfiguration {
|
|||||||
|
|
||||||
private val logger = MingLiLoggerFactory.getLogger<Jackson3AutoConfiguration>()
|
private val logger = MingLiLoggerFactory.getLogger<Jackson3AutoConfiguration>()
|
||||||
|
|
||||||
@Bean
|
/**
|
||||||
@ConditionalOnMissingBean(JsonMapperBuilderCustomizer::class)
|
* 注册 UUID 的 Jackson 3 序列化/反序列化模块。
|
||||||
open fun myJsonMapperCustomizer(): JsonMapperBuilderCustomizer {
|
*
|
||||||
|
* 如需替换 UUID 处理逻辑,注册名为 [UUIDJsonConverterJsonMapperCustomizer]
|
||||||
|
* 的 [JsonMapperBuilderCustomizer] Bean 即可,本 Bean 将自动跳过。
|
||||||
|
*/
|
||||||
|
@Bean("UUIDJsonConverterJsonMapperCustomizer")
|
||||||
|
@ConditionalOnMissingBean(name = ["UUIDJsonConverterJsonMapperCustomizer"])
|
||||||
|
open fun getUUIDJsonConverterJsonMapperCustomizer(): JsonMapperBuilderCustomizer {
|
||||||
return JsonMapperBuilderCustomizer { builder ->
|
return JsonMapperBuilderCustomizer { builder ->
|
||||||
builder
|
builder.addModule(UUIDJsonConverter.getJsonConverter().getJackson3Module())
|
||||||
.addModule(UUIDJsonConverter.getJsonConverter().getJackson3Module())
|
|
||||||
.addModule(DateTimeJsonConverter.getJsonConverter().getJackson3Module())
|
|
||||||
}.also {
|
}.also {
|
||||||
logger.info("MingliUtils Jackson3 Serializers created")
|
logger.info("MingliUtils Jackson3 UUID Serializers created")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册日期时间的 Jackson 3 序列化/反序列化模块。
|
||||||
|
*
|
||||||
|
* 如需替换日期时间处理逻辑,注册名为 [DateTimeJsonConverterJsonMapperCustomizer]
|
||||||
|
* 的 [JsonMapperBuilderCustomizer] Bean 即可,本 Bean 将自动跳过。
|
||||||
|
*/
|
||||||
|
@Bean("DateTimeJsonConverterJsonMapperCustomizer")
|
||||||
|
@ConditionalOnMissingBean(name = ["DateTimeJsonConverterJsonMapperCustomizer"])
|
||||||
|
open fun getDateTimeJsonConverterJsonMapperCustomizer(): JsonMapperBuilderCustomizer {
|
||||||
|
return JsonMapperBuilderCustomizer { builder ->
|
||||||
|
builder.addModule(DateTimeJsonConverter.getJsonConverter().getJackson3Module())
|
||||||
|
}.also {
|
||||||
|
logger.info("MingliUtils Jackson3 DateTime Serializers created")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+53
-4
@@ -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 mingli-utils
|
* ProjectName FastBaseMapper.kt
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile Jackson3JsonApiAutoConfiguration.kt
|
* CurrentFile Jackson3JsonApiAutoConfiguration.kt
|
||||||
* LastUpdate 2026-10-02 16:11:02
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -33,17 +33,66 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
|||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
import tools.jackson.databind.json.JsonMapper
|
import tools.jackson.databind.json.JsonMapper
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基于 Jackson 3 的 [JsonApi] 自动配置。
|
||||||
|
*
|
||||||
|
* 在类路径存在 Jackson 3(`tools.jackson.databind.json.JsonMapper`)
|
||||||
|
* 及 Spring Boot 的 Jackson 自动配置时生效,将容器中的 [JsonMapper]
|
||||||
|
* 包装为 [Jackson3JsonApi] 并以 [JsonApi] 类型注册为 Bean,
|
||||||
|
* 同时尝试初始化全局单例 [JSONA]。
|
||||||
|
*
|
||||||
|
* ## 生效顺序
|
||||||
|
*
|
||||||
|
* 本类依赖 [Jackson3AutoConfiguration] 注册的 `JsonMapper` 构建定制器,
|
||||||
|
* 通过 `@AutoConfigureAfter` 保证在其之后处理,确保 `JsonMapper` 已按
|
||||||
|
* 自定义模块完成配置。
|
||||||
|
*
|
||||||
|
* ## 覆盖方式
|
||||||
|
*
|
||||||
|
* 若调用方需要自定义 [JsonApi] 实现,只需自行声明一个 [JsonApi] Bean,
|
||||||
|
* 本配置的 `@ConditionalOnMissingBean(JsonApi::class)` 将自动跳过创建。
|
||||||
|
*
|
||||||
|
* ## 全局单例
|
||||||
|
*
|
||||||
|
* [JSONA] 是进程级全局 JSON 访问入口。本配置在创建 Bean 后尝试读取
|
||||||
|
* [JSONA] 当前实例;若尚未设置(读取抛 [NullPointerException]),
|
||||||
|
* 则将本次创建的 [JsonApi] 设置为其全局实现。若调用方已在更早阶段
|
||||||
|
* 设置过 [JSONA],则保留既有实现,不覆盖。
|
||||||
|
*
|
||||||
|
* @see Jackson3AutoConfiguration
|
||||||
|
* @see Jackson3JsonApi
|
||||||
|
*/
|
||||||
@ConditionalOnClass(name = ["tools.jackson.databind.json.JsonMapper", "org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration"])
|
@ConditionalOnClass(name = ["tools.jackson.databind.json.JsonMapper", "org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration"])
|
||||||
@AutoConfigureAfter(name = ["com.mingliqiye.utils.springboot.autoconfigure.Jackson3AutoConfiguration"])
|
@AutoConfigureAfter(name = ["com.mingliqiye.utils.springboot.autoconfigure.Jackson3AutoConfiguration"])
|
||||||
open class Jackson3JsonApiAutoConfiguration {
|
open class Jackson3JsonApiAutoConfiguration {
|
||||||
private val logger = MingLiLoggerFactory.getLogger<Jackson3JsonApiAutoConfiguration>()
|
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val logger = MingLiLoggerFactory.getLogger<Jackson3JsonApiAutoConfiguration>()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建并注册默认的 [JsonApi] Bean。
|
||||||
|
*
|
||||||
|
* 使用容器中的 [JsonMapper] 构造 [Jackson3JsonApi]。读取器直接返回该 [JsonMapper];
|
||||||
|
* 写入器被设计为抛出 [JsonException],即本实现不允许通过 [JsonApi] 替换底层
|
||||||
|
* `JsonMapper`,底层实例由 Spring 容器统一管理。
|
||||||
|
*
|
||||||
|
* 创建完成后会尝试初始化全局 [JSONA]:
|
||||||
|
* - 若 [JSONA] 尚未设置,则设置为本实例;
|
||||||
|
* - 若已设置,则保留既有实现。
|
||||||
|
*
|
||||||
|
* 该 Bean 仅在容器中不存在其他 [JsonApi] 时创建。
|
||||||
|
*
|
||||||
|
* @param jsonMapper 容器中的 Jackson 3 映射器
|
||||||
|
* @return 基于 Jackson 3 的 JSON 访问门面
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(JsonApi::class)
|
@ConditionalOnMissingBean(JsonApi::class)
|
||||||
open fun jsonApi(jsonMapper: JsonMapper): JsonApi {
|
open fun jsonApi(jsonMapper: JsonMapper): JsonApi {
|
||||||
return Jackson3JsonApi(
|
return Jackson3JsonApi(
|
||||||
get = { jsonMapper },
|
get = { jsonMapper },
|
||||||
set = { throw JsonException("JSON API set method is not allowed.") }).also {
|
set = { throw JsonException("JSON API set method is not allowed.") })
|
||||||
|
.also {
|
||||||
logger.info("JsonApi Bean Auto Configuration Success")
|
logger.info("JsonApi Bean Auto Configuration Success")
|
||||||
try {
|
try {
|
||||||
JSONA.getJsonApi()
|
JSONA.getJsonApi()
|
||||||
|
|||||||
+9
-40
@@ -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 mingli-utils
|
* ProjectName FastBaseMapper.kt
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile JacksonAutoConfiguration.kt
|
* CurrentFile JacksonJsonApiAutoConfiguration.kt
|
||||||
* LastUpdate 2026-10-02 16:10:53
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -26,9 +26,6 @@ import com.fasterxml.jackson.databind.ObjectMapper
|
|||||||
import com.mingliqiye.utils.json.api.JSONA
|
import com.mingliqiye.utils.json.api.JSONA
|
||||||
import com.mingliqiye.utils.json.api.JacksonJsonApi
|
import com.mingliqiye.utils.json.api.JacksonJsonApi
|
||||||
import com.mingliqiye.utils.json.api.base.JsonApi
|
import com.mingliqiye.utils.json.api.base.JsonApi
|
||||||
import com.mingliqiye.utils.json.converters.DateTimeJsonConverter
|
|
||||||
import com.mingliqiye.utils.json.converters.UUIDJsonConverter
|
|
||||||
import com.mingliqiye.utils.json.converters.base.addJsonConverter
|
|
||||||
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
||||||
@@ -37,28 +34,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
|||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
import org.springframework.context.annotation.Primary
|
import org.springframework.context.annotation.Primary
|
||||||
|
|
||||||
/*
|
|
||||||
* 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 JacksonAutoConfiguration.kt
|
|
||||||
* LastUpdate 2026-02-05 10:39:54
|
|
||||||
* UpdateUser MingLiPro
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JacksonAutoConfiguration 是一个 Spring Boot 自动配置类,用于配置 Jackson 相关的序列化和反序列化功能。
|
* JacksonAutoConfiguration 是一个 Spring Boot 自动配置类,用于配置 Jackson 相关的序列化和反序列化功能。
|
||||||
* 该类在检测到 ObjectMapper 和 Spring Boot 的 JacksonAutoConfiguration 存在时自动生效,
|
* 该类在检测到 ObjectMapper 和 Spring Boot 的 JacksonAutoConfiguration 存在时自动生效,
|
||||||
@@ -67,21 +42,15 @@ import org.springframework.context.annotation.Primary
|
|||||||
* @param objectMapper 用于 JSON 序列化和反序列化的 ObjectMapper 实例。
|
* @param objectMapper 用于 JSON 序列化和反序列化的 ObjectMapper 实例。
|
||||||
*/
|
*/
|
||||||
@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 = ["com.mingliqiye.utils.springboot.autoconfigure.JacksonJsonAutoConfiguration"])
|
||||||
open class JacksonAutoConfiguration(objectMapper: ObjectMapper) {
|
open class JacksonJsonApiAutoConfiguration {
|
||||||
private val log: Logger = MingLiLoggerFactory.getLogger("MingliUtils-JacksonAutoConfiguration")
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 初始化块:在类实例化时执行。
|
companion object {
|
||||||
* 注册自定义的 UUID 和 DateTime JSON 转换器模块到 ObjectMapper 中。
|
private val log: Logger = MingLiLoggerFactory.getLogger("MingliUtils-JacksonAutoConfiguration")
|
||||||
*/
|
|
||||||
init {
|
|
||||||
objectMapper
|
|
||||||
.addJsonConverter<UUIDJsonConverter>()
|
|
||||||
.addJsonConverter<DateTimeJsonConverter>()
|
|
||||||
log.info("MingliUtils Jackson Serializers created")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 创建并返回一个 JsonApi Bean 实例。
|
* 创建并返回一个 JsonApi Bean 实例。
|
||||||
* 该方法会在没有其他 JsonApi Bean 存在时被调用,并将创建的 JacksonJsonApi 实例设置为全局默认的 JSON API。
|
* 该方法会在没有其他 JsonApi Bean 存在时被调用,并将创建的 JacksonJsonApi 实例设置为全局默认的 JSON API。
|
||||||
+75
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* 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 JacksonJsonAutoConfiguration.kt
|
||||||
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
|
* UpdateUser MingLiPro
|
||||||
|
*/
|
||||||
|
|
||||||
|
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.UUIDJsonConverter
|
||||||
|
import com.mingliqiye.utils.json.converters.base.getJacksonModule
|
||||||
|
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
||||||
|
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Jackson 2 的序列化模块自动配置(过渡兼容)。
|
||||||
|
*
|
||||||
|
* 在类路径存在 Jackson 2(`com.fasterxml.jackson.databind.ObjectMapper`)
|
||||||
|
* 及对应 Spring Boot 自动配置时生效,向容器注册用于追加 UUID / 日期时间
|
||||||
|
* 模块的 [Jackson2ObjectMapperBuilderCustomizer]。
|
||||||
|
*
|
||||||
|
* ## 定位说明
|
||||||
|
*
|
||||||
|
* Spring Boot 4 起默认 JSON 库为 Jackson 3,Jackson 2 的自动配置已被弃用,
|
||||||
|
* 仅用于迁移过渡,并计划在未来版本移除。本类只服务于仍在使用 Jackson 2 的场景,
|
||||||
|
* 新项目应优先使用 Jackson 3 的对应配置。
|
||||||
|
*
|
||||||
|
* ## 类名注意
|
||||||
|
*
|
||||||
|
* 条件与排序中引用的自动配置类名需与目标 Spring Boot 版本一致。
|
||||||
|
* Spring Boot 4 中 Jackson 2 的自动配置类位于 `spring-boot-jackson2` 模块
|
||||||
|
* (包路径形如 `org.springframework.boot.jackson2.autoconfigure.Jackson2AutoConfiguration`)。
|
||||||
|
* 若项目中引用的类名不存在,本配置会被整体跳过而不报错,需自行核对。
|
||||||
|
*
|
||||||
|
* ## Bean 命名
|
||||||
|
*
|
||||||
|
* 与 Jackson 3 配置中的定制器 Bean 名称刻意区分(后缀 `2`),
|
||||||
|
* 避免两套配置同时生效时发生名称冲突。
|
||||||
|
*
|
||||||
|
* @see Jackson2ObjectMapperBuilderCustomizer
|
||||||
|
*/
|
||||||
|
@ConditionalOnClass(name = ["com.fasterxml.jackson.databind.ObjectMapper", "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration"])
|
||||||
|
@AutoConfigureAfter(name = ["org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration"])
|
||||||
|
open class JacksonJsonAutoConfiguration(objectMapper: ObjectMapper) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val log = MingLiLoggerFactory.getLogger<JacksonJsonAutoConfiguration>()
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
objectMapper.registerModule(DateTimeJsonConverter.getJsonConverter().getJacksonModule())
|
||||||
|
objectMapper.registerModule(UUIDJsonConverter.getJsonConverter().getJacksonModule())
|
||||||
|
log.info("MingliUtils JacksonModule UUID,DateTime Serializers created")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+74
-25
@@ -13,18 +13,19 @@
|
|||||||
* 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 mingli-utils
|
* ProjectName FastBaseMapper.kt
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile Okhttp3AutoConfiguration.kt
|
* CurrentFile Okhttp3AutoConfiguration.kt
|
||||||
* LastUpdate 2026-10-02 16:10:15
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.mingliqiye.utils.springboot.autoconfigure
|
package com.mingliqiye.utils.springboot.autoconfigure
|
||||||
|
|
||||||
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
||||||
|
import com.mingliqiye.utils.springboot.autoconfigure.builder.OkhttpBuilder
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.beans.factory.ObjectProvider
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration
|
import org.springframework.boot.autoconfigure.AutoConfiguration
|
||||||
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.condition.ConditionalOnMissingBean
|
||||||
@@ -32,43 +33,91 @@ import org.springframework.context.annotation.Bean
|
|||||||
import org.springframework.context.event.ContextClosedEvent
|
import org.springframework.context.event.ContextClosedEvent
|
||||||
import org.springframework.context.event.EventListener
|
import org.springframework.context.event.EventListener
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OkHttp 3 的 Spring Boot 自动配置。
|
||||||
|
*
|
||||||
|
* 在类路径存在 `okhttp3.OkHttpClient` 时生效,向容器注册一个默认的
|
||||||
|
* [okhttp3.OkHttpClient] Bean。构建过程中会依次应用容器中所有
|
||||||
|
* [OkhttpBuilder] 定制器(按 `@Order` / [org.springframework.core.Ordered] 排序),
|
||||||
|
* 便于调用方追加拦截器、超时、代理、连接池等配置,而无需自行创建客户端。
|
||||||
|
*
|
||||||
|
* ## 覆盖方式
|
||||||
|
*
|
||||||
|
* 若调用方需要完全自定义客户端,只需自行声明一个 [okhttp3.OkHttpClient] Bean,
|
||||||
|
* 本配置的 `@ConditionalOnMissingBean` 将自动跳过创建,不会产生多余实例。
|
||||||
|
*
|
||||||
|
* 若只想在默认客户端上做增量调整,实现 [OkhttpBuilder] 并注册为 Bean 即可,
|
||||||
|
* 无需替换整个客户端。
|
||||||
|
*
|
||||||
|
* ## 生命周期
|
||||||
|
*
|
||||||
|
* 由本配置创建的客户端会在 Spring 上下文关闭时([ContextClosedEvent])
|
||||||
|
* 主动清理连接池并关闭分发器线程池,避免线程与连接泄漏。
|
||||||
|
* 调用方自行声明的客户端不会被本配置清理,其生命周期由调用方负责。
|
||||||
|
*
|
||||||
|
* @see OkhttpBuilder
|
||||||
|
*/
|
||||||
@AutoConfiguration
|
@AutoConfiguration
|
||||||
@ConditionalOnClass(name = ["okhttp3.OkHttpClient"])
|
@ConditionalOnClass(name = ["okhttp3.OkHttpClient"])
|
||||||
open class Okhttp3AutoConfiguration {
|
open class Okhttp3AutoConfiguration {
|
||||||
|
|
||||||
private var okHttpClient: okhttp3.OkHttpClient? = null
|
companion object {
|
||||||
|
|
||||||
val log: Logger = MingLiLoggerFactory.getLogger<Okhttp3AutoConfiguration>()
|
val log: Logger = MingLiLoggerFactory.getLogger<Okhttp3AutoConfiguration>()
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
open var userDefinedBuilder: okhttp3.OkHttpClient.Builder? = null
|
|
||||||
|
|
||||||
open fun initOkHttpClient() {
|
|
||||||
okHttpClient = if (userDefinedBuilder == null) {
|
|
||||||
okhttp3.OkHttpClient()
|
|
||||||
} else {
|
|
||||||
userDefinedBuilder!!.build()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 由本配置创建并注册的 [okhttp3.OkHttpClient] 实例,供上下文关闭时清理使用。
|
||||||
|
*
|
||||||
|
* 当调用方自行声明了 `OkHttpClient` Bean 时,本配置的 Bean 方法不会执行,
|
||||||
|
* 该字段保持 `null`,关闭时的清理逻辑也会相应跳过。
|
||||||
|
*/
|
||||||
|
var okhttp: okhttp3.OkHttpClient? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建默认的 [okhttp3.OkHttpClient] Bean。
|
||||||
|
*
|
||||||
|
* 依次应用容器中所有 [OkhttpBuilder] 定制器后构建客户端。没有任何定制器时
|
||||||
|
* 也能正常构建([ObjectProvider] 允许零个元素)。
|
||||||
|
*
|
||||||
|
* 该 Bean 仅在容器中不存在其他 `OkHttpClient` 时创建;若调用方已自行声明,
|
||||||
|
* 本方法不会被调用。
|
||||||
|
*
|
||||||
|
* @param builders 容器中的 OkHttp 构建定制器,按 `@Order` 排序后依次应用
|
||||||
|
* @return 构建完成的 OkHttp 客户端
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
open fun okHttpClient(): okhttp3.OkHttpClient {
|
open fun okHttpClient(builders: ObjectProvider<OkhttpBuilder>): okhttp3.OkHttpClient {
|
||||||
if (okHttpClient == null) {
|
var connt = 0
|
||||||
initOkHttpClient()
|
return okhttp3.OkHttpClient.Builder().let { builder ->
|
||||||
|
var b = builder
|
||||||
|
builders.orderedStream().forEach {
|
||||||
|
b = it.customize(b)
|
||||||
|
connt++
|
||||||
|
}
|
||||||
|
b.build()
|
||||||
|
}.also {
|
||||||
|
okhttp = it
|
||||||
|
log.info("load $connt OkhttpBuilder initialized OkHttpClient successfully")
|
||||||
}
|
}
|
||||||
log.info("OkHttpClient initialized (using ${if (userDefinedBuilder != null) "user-defined" else "default"} builder)")
|
|
||||||
return okHttpClient!!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在 Spring 上下文关闭时清理本配置创建的 OkHttp 客户端。
|
||||||
|
*
|
||||||
|
* 执行两步清理:
|
||||||
|
* 1. [okhttp3.ConnectionPool.evictAll] 立即关闭连接池中的空闲连接;
|
||||||
|
* 2. 关闭 [okhttp3.Dispatcher] 的线程池,中断未完成的任务。
|
||||||
|
*
|
||||||
|
* 仅当 [okhttp] 字段非空(即客户端由本配置创建)时执行;
|
||||||
|
* 调用方自行声明的客户端不会被清理。
|
||||||
|
*/
|
||||||
@EventListener(ContextClosedEvent::class)
|
@EventListener(ContextClosedEvent::class)
|
||||||
open fun handleContextClosed() {
|
open fun handleContextClosed() {
|
||||||
if (okHttpClient != null) {
|
okhttp?.let {
|
||||||
log.info("Context closed, cleaning up OkHttpClient...")
|
log.info("Context closed, cleaning up OkHttpClient...")
|
||||||
okHttpClient?.dispatcher?.executorService?.shutdown()
|
it.connectionPool.evictAll()
|
||||||
okHttpClient?.connectionPool?.evictAll()
|
it.dispatcher.executorService.shutdownNow()
|
||||||
okHttpClient?.dispatcher?.executorService?.shutdownNow()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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 OkhttpBuilder.kt
|
||||||
|
* LastUpdate 2026-10-26 23:22:18
|
||||||
|
* UpdateUser MingLiPro
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.mingliqiye.utils.springboot.autoconfigure.builder
|
||||||
|
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
fun interface OkhttpBuilder {
|
||||||
|
fun customize(builder: OkHttpClient.Builder): OkHttpClient.Builder
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
+4
-3
@@ -13,15 +13,16 @@
|
|||||||
# 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 mingli-utils
|
# ProjectName FastBaseMapper.kt
|
||||||
# ModuleName mingli-utils.main
|
# ModuleName mingli-utils.main
|
||||||
# CurrentFile org.springframework.boot.autoconfigure.AutoConfiguration.imports
|
# CurrentFile org.springframework.boot.autoconfigure.AutoConfiguration.imports
|
||||||
# LastUpdate 2026-02-27 17:39:55
|
# LastUpdate 2026-10-26 23:22:18
|
||||||
# UpdateUser MingLiPro
|
# UpdateUser MingLiPro
|
||||||
#
|
#
|
||||||
|
|
||||||
com.mingliqiye.utils.springboot.autoconfigure.AutoConfiguration
|
com.mingliqiye.utils.springboot.autoconfigure.AutoConfiguration
|
||||||
com.mingliqiye.utils.springboot.autoconfigure.JacksonAutoConfiguration
|
com.mingliqiye.utils.springboot.autoconfigure.JacksonJsonAutoConfiguration
|
||||||
|
com.mingliqiye.utils.springboot.autoconfigure.JacksonJsonApiAutoConfiguration
|
||||||
com.mingliqiye.utils.springboot.autoconfigure.Jackson3AutoConfiguration
|
com.mingliqiye.utils.springboot.autoconfigure.Jackson3AutoConfiguration
|
||||||
com.mingliqiye.utils.springboot.autoconfigure.Jackson3JsonApiAutoConfiguration
|
com.mingliqiye.utils.springboot.autoconfigure.Jackson3JsonApiAutoConfiguration
|
||||||
com.mingliqiye.utils.springboot.autoconfigure.Okhttp3AutoConfiguration
|
com.mingliqiye.utils.springboot.autoconfigure.Okhttp3AutoConfiguration
|
||||||
|
|||||||
Reference in New Issue
Block a user