mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
Compare commits
140 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1b72884fcb | ||
|
9463cb6437 | ||
|
7614007346 | ||
|
5c3cd62a5f | ||
|
a8b4f77753 | ||
|
0ffac304b9 | ||
|
399609c9fb | ||
|
28392edd61 | ||
|
8e8eb6afdd | ||
|
0356b4c201 | ||
|
6d847adce5 | ||
|
65e466c0e7 | ||
|
91e0528da5 | ||
|
a1c309949a | ||
|
683d640d81 | ||
|
7b03ca05d4 | ||
|
3bd8a78e6b | ||
|
c056475a12 | ||
|
cd82858357 | ||
|
20b21c6d9d | ||
|
cbedb2f58c | ||
|
0b9577e7c4 | ||
|
bb2c8115e0 | ||
|
6a314b1b70 | ||
|
d27318503e | ||
|
44e5a5e79d | ||
|
609234dd2e | ||
|
40b6eff2cc | ||
|
9eb7aac005 | ||
|
08d3b1cf9b | ||
|
b029065187 | ||
|
46a23bfb99 | ||
|
6327dcd15e | ||
|
c50da64608 | ||
|
e93b72bad7 | ||
|
93c81ab043 | ||
|
9f2a79693e | ||
|
5067324103 | ||
|
b3f56f9292 | ||
|
0b065266a1 | ||
|
7c8afeaa98 | ||
|
0353f972e7 | ||
|
4401ad8ca6 | ||
|
42a63cf4d1 | ||
|
9dd1cfbde7 | ||
|
9173f6e5c8 | ||
|
6abb21a5ee | ||
|
d7f7f19fac | ||
|
8ecc698723 | ||
|
6e1c7945c6 | ||
|
3db7995d34 | ||
|
34d920196f | ||
|
2c5b8678d6 | ||
|
5d16d68d4e | ||
|
0ed4bb2278 | ||
|
034c341f5c | ||
|
ce3548c7d2 | ||
|
eb3cecf626 | ||
|
5b61dfedd8 | ||
|
effdc96299 | ||
|
720934500f | ||
|
56ef6c57f7 | ||
|
4d38516ea2 | ||
|
30629ee12a | ||
|
117f465646 | ||
|
f2b3308d53 | ||
|
1f3a73056d | ||
|
14ea2c45b0 | ||
|
9e65e33301 | ||
|
b4ce33141d | ||
|
0a05f48032 | ||
|
15ec4b86b1 | ||
|
4c4fae44a1 | ||
|
7ee3f52d95 | ||
|
cc08e57540 | ||
|
e562c159d1 | ||
|
7abd8550a3 | ||
|
3c27dc921c | ||
|
484eb831dc | ||
|
bac3938b11 | ||
|
c2dfbf29b4 | ||
|
7e4b778f79 | ||
|
047faf4891 | ||
|
51f39d1129 | ||
|
951316e84f | ||
|
7e3ee68d73 | ||
|
6a5983aad4 | ||
|
8495c7c153 | ||
|
5fd49c83e7 | ||
|
5a7416345a | ||
|
6947d89697 | ||
|
5c587a3bfe | ||
|
27444dda74 | ||
|
52a0eb3cc9 | ||
|
543c987983 | ||
|
ec56620e4d | ||
|
81013e34b7 | ||
|
280e9901ed | ||
|
b6d04d5ea4 | ||
|
7e30322e2b | ||
|
bee3f83dea | ||
|
0519bd47ee | ||
|
31662a6e9e | ||
|
d604be19ac | ||
|
5269f3a535 | ||
|
ae6116ce95 | ||
|
646fefaada | ||
|
754cf726fd | ||
|
c898aa56c4 | ||
|
7a05056e6f | ||
|
8bc94f2038 | ||
|
fd0e559c3a | ||
|
fa95c33847 | ||
|
369ec8db05 | ||
|
01043008f9 | ||
|
9794aa3545 | ||
|
3558d94c68 | ||
|
9c683963cb | ||
|
108ed07bd6 | ||
|
ab92b9811f | ||
|
2ee52e39a6 | ||
|
5767ad4b1e | ||
|
33e35ee1fb | ||
|
19329cfb28 | ||
|
b252c474a1 | ||
|
1a82b74952 | ||
|
e3d5187c35 | ||
|
d291edf026 | ||
|
7e03776471 | ||
|
9f4a7a0ea0 | ||
|
cde5c86518 | ||
|
879cecaca9 | ||
|
ad878e454f | ||
|
bb2b322246 | ||
|
c32988d4b6 | ||
|
6fb8e958f5 | ||
|
5c76932fdc | ||
|
5582305376 | ||
|
1673cfe4c0 | ||
|
24b1d51155 |
@ -1,15 +0,0 @@
|
||||
### 当前使用版本(必填,否则不予处理)
|
||||
|
||||
|
||||
|
||||
### 该问题是如何引起的?(确定最新版也有问题再提!!!)
|
||||
|
||||
|
||||
|
||||
### 重现步骤(如果有就写完整)
|
||||
|
||||
|
||||
|
||||
### 报错信息
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
### 该Pull Request关联的Issue
|
||||
|
||||
|
||||
|
||||
### 修改描述
|
||||
|
||||
|
||||
|
||||
### 测试用例
|
||||
|
||||
|
||||
|
||||
### 修复效果的截屏
|
||||
|
||||
|
13
.github/dependabot.yml
vendored
Normal file
13
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "maven" # See documentation for possible values
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
ignore:
|
||||
- dependency-name: "com.baomidou:mybatis-plus*"
|
39
.github/workflows/depoly.yml
vendored
Normal file
39
.github/workflows/depoly.yml
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
name: Maven Package
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
|
||||
- name: Set up Apache Maven Central
|
||||
uses: actions/setup-java@v4
|
||||
with: # running setup-java again overwrites the settings.xml
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
server-id: maven # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
server-username: MAVEN_USERNAME # env variable for username in deploy
|
||||
server-password: MAVEN_CENTRAL_TOKEN # env variable for token in deploy
|
||||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
|
||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
|
||||
|
||||
- name: Publish to Apache Maven Central
|
||||
run: mvn com.github.yulichang:pom-maven-plugin:pom && mvn clean deploy
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
|
||||
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
31
.github/workflows/maven.yml
vendored
Normal file
31
.github/workflows/maven.yml
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
|
||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
|
||||
|
||||
# This workflow uses actions that are not certified by GitHub.
|
||||
# They are provided by a third-party and are governed by
|
||||
# separate terms of service, privacy policy, and support
|
||||
# documentation.
|
||||
|
||||
name: Java CI with Maven
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
39
.github/workflows/snapshot.yml
vendored
Normal file
39
.github/workflows/snapshot.yml
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
name: Maven Package
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- snapshot
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
|
||||
- name: Set up Apache Maven Central
|
||||
uses: actions/setup-java@v4
|
||||
with: # running setup-java again overwrites the settings.xml
|
||||
distribution: 'temurin'
|
||||
java-version: '17'
|
||||
server-id: maven # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
server-username: MAVEN_USERNAME # env variable for username in deploy
|
||||
server-password: MAVEN_CENTRAL_TOKEN # env variable for token in deploy
|
||||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
|
||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
|
||||
|
||||
- name: Publish to Apache Maven Central
|
||||
run: mvn com.github.yulichang:pom-maven-plugin:pom -Dprofile=snapshot && mvn clean deploy
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
|
||||
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
25
README-zh.md
25
README-zh.md
@ -10,7 +10,7 @@
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://central.sonatype.com/artifact/com.github.yulichang/mybatis-plus-join-boot-starter">
|
||||
<img alt="maven" src="https://img.shields.io/maven-central/v/com.github.yulichang/mybatis-plus-join-boot-starter.svg?style=flat-square">
|
||||
<img alt="Maven central" src="https://img.shields.io/maven-central/v/com.github.yulichang/mybatis-plus-join-boot-starter.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://www.apache.org/licenses/LICENSE-2.0">
|
||||
<img alt="code style" src="https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat-square">
|
||||
@ -30,7 +30,6 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
QQ群:680016987 或者
|
||||
<a href="https://gitee.com/best_handsome/mybatis-plus-join/issues/I65N2M" target="_blank">添加作者微信,备注MPJ,加入微信群</a>
|
||||
<br/>
|
||||
<img width="200px" height="200px" src="https://foruda.gitee.com/images/1714756135330585984/bcc86eb0_2020985.png" alt="添加作者微信,备注MPJ,加入微信群"/>
|
||||
@ -47,16 +46,16 @@ QQ群:680016987 或者
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.4</version>
|
||||
</dependency>
|
||||
```
|
||||
- Gradle
|
||||
```
|
||||
implementation 'com.github.yulichang:mybatis-plus-join-boot-starter:1.5.0'
|
||||
implementation 'com.github.yulichang:mybatis-plus-join-boot-starter:1.5.4'
|
||||
```
|
||||
或者clone代码到本地执行 mvn install, 再引入以上依赖
|
||||
或者clone代码到本地执行 `mvn install`, 再引入以上依赖
|
||||
<br>
|
||||
注意: MyBatis Plus版本需要3.3.0+
|
||||
注意: MyBatis Plus版本需要3.1.2+
|
||||
<br>
|
||||
|
||||
### 使用
|
||||
@ -111,14 +110,10 @@ WHERE (
|
||||
AND t.id > ?)
|
||||
```
|
||||
|
||||
MPJLambdaWrapper其他功能
|
||||
# <a href="https://mybatis-plus-join.github.io" target="_blank">完整使用文档 wiki</a>
|
||||
|
||||
* <a href="https://mybatis-plus-join.github.io/pages/core/lambda/select/selectCollection.html" target="_blank">
|
||||
一对一,一对多使用</a>
|
||||
* <a href="https://mybatis-plus-join.github.io/pages/core/lambda/select/selectFunc.html" target="_blank">简单的SQL函数使用</a>
|
||||
* <a href="https://mybatis-plus-join.github.io/pages/core/lambda/join/leftJoin.html" target="_blank">ON语句多条件支持</a>
|
||||
* <a href="https://mybatis-plus-join.github.io" target="_blank">其他全部功能请参考使用文档</a>
|
||||
|
||||
# <a href="https://mybatis-plus-join.github.io" target="_blank">使用文档 wiki</a>
|
||||
# 用爱发电
|
||||

|
||||
|
||||
<a href="https://mybatis-plus-join.github.io/pages/quickstart/support.html" target="_blank">
|
||||
<img alt="支持一下mybatis-plus-join" src="https://foruda.gitee.com/images/1717191488951888381/8463cfcd_2020985.png">
|
||||
</a>
|
||||
|
26
README.md
26
README.md
@ -10,7 +10,7 @@
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://central.sonatype.com/artifact/com.github.yulichang/mybatis-plus-join-boot-starter">
|
||||
<img alt="maven" src="https://img.shields.io/maven-central/v/com.github.yulichang/mybatis-plus-join-boot-starter.svg?style=flat-square">
|
||||
<img alt="Maven central" src="https://img.shields.io/maven-central/v/com.github.yulichang/mybatis-plus-join-boot-starter.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://www.apache.org/licenses/LICENSE-2.0">
|
||||
<img alt="code style" src="https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat-square">
|
||||
@ -30,7 +30,6 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
QQ群:680016987 或者
|
||||
<a href="https://gitee.com/best_handsome/mybatis-plus-join/issues/I65N2M" target="_blank">添加作者微信,备注MPJ,加入微信群</a>
|
||||
<br/>
|
||||
<img width="200px" height="200px" src="https://github.com/yulichang/mybatis-plus-join/assets/33247410/6a2aedfa-c67d-4691-9441-204f28b6c73d" alt="添加作者微信,备注MPJ,加入微信群"/>
|
||||
@ -47,16 +46,16 @@ QQ群:680016987 或者
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.5.4</version>
|
||||
</dependency>
|
||||
```
|
||||
- Gradle
|
||||
```
|
||||
implementation 'com.github.yulichang:mybatis-plus-join-boot-starter:1.5.0'
|
||||
implementation 'com.github.yulichang:mybatis-plus-join-boot-starter:1.5.4'
|
||||
```
|
||||
或者clone代码到本地执行 mvn install, 再引入以上依赖
|
||||
或者clone代码到本地执行 `mvn install`, 再引入以上依赖
|
||||
<br>
|
||||
注意: MyBatis Plus版本需要3.3.0+
|
||||
注意: MyBatis Plus版本需要3.1.2+
|
||||
<br>
|
||||
|
||||
### 使用
|
||||
@ -111,15 +110,8 @@ WHERE (
|
||||
AND t.id > ?)
|
||||
```
|
||||
|
||||
|
||||
MPJLambdaWrapper其他功能
|
||||
|
||||
* <a href="https://mybatis-plus-join.github.io/pages/core/lambda/select/selectCollection.html" target="_blank">
|
||||
一对一,一对多使用</a>
|
||||
* <a href="https://mybatis-plus-join.github.io/pages/core/lambda/select/selectFunc.html" target="_blank">简单的SQL函数使用</a>
|
||||
* <a href="https://mybatis-plus-join.github.io/pages/core/lambda/join/leftJoin.html" target="_blank">ON语句多条件支持</a>
|
||||
* <a href="https://mybatis-plus-join.github.io" target="_blank">其他全部功能请参考使用文档</a>
|
||||
|
||||
# <a href="https://mybatis-plus-join.github.io" target="_blank">使用文档 wiki</a>
|
||||
# <a href="https://mybatis-plus-join.github.io" target="_blank">完整使用文档 wiki</a>
|
||||
# 用爱发电
|
||||

|
||||
<a href="https://mybatis-plus-join.github.io/pages/quickstart/support.html" target="_blank">
|
||||
<img alt="支持一下mybatis-plus-join" src="https://mybatis-plus-join.github.io/support.png">
|
||||
</a>
|
||||
|
@ -2,7 +2,6 @@ package com.github.yulichang.adapter.jsqlparser.v46;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
||||
import net.sf.jsqlparser.schema.Column;
|
||||
import net.sf.jsqlparser.statement.Statement;
|
||||
@ -41,7 +40,7 @@ public class JSqlParserHelperV46 {
|
||||
} else {
|
||||
col = selectExpressionItem.getAlias().getName();
|
||||
}
|
||||
if (StringUtils.isNotBlank(col)) {
|
||||
if (isNotBlank(col)) {
|
||||
columConsumer.accept(col);
|
||||
}
|
||||
}
|
||||
@ -56,4 +55,9 @@ public class JSqlParserHelperV46 {
|
||||
throw new RuntimeException(throwable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean isNotBlank(String str) {
|
||||
return str != null && !str.trim().isEmpty();
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,13 @@
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-core</artifactId>
|
||||
<version>${mpj.mybatis.plus.version}</version>
|
||||
<version>${mybatis.plus.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-jsqlparser</artifactId>
|
||||
<version>${mybatis.plus.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -2,7 +2,6 @@ package com.github.yulichang.adapter.jsqlparser;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
||||
import net.sf.jsqlparser.schema.Column;
|
||||
import net.sf.jsqlparser.statement.Statement;
|
||||
@ -38,7 +37,7 @@ public class JSqlParserHelper {
|
||||
} else {
|
||||
col = item.getAlias().getName();
|
||||
}
|
||||
if (StringUtils.isNotBlank(col)) {
|
||||
if (isNotBlank(col)) {
|
||||
columConsumer.accept(col);
|
||||
}
|
||||
}
|
||||
@ -51,4 +50,8 @@ public class JSqlParserHelper {
|
||||
throw new RuntimeException(throwable);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isNotBlank(String str) {
|
||||
return str != null && !str.trim().isEmpty();
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,13 @@
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
<version>${mpj.mybatis.plus.version}</version>
|
||||
<version>${mybatis.plus.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-jsqlparser</artifactId>
|
||||
<version>${mybatis.plus.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -38,6 +38,10 @@ public interface IAdapter {
|
||||
return tableFieldInfo.isPrimitive();
|
||||
}
|
||||
|
||||
default boolean isWithUpdateFill(TableFieldInfo tableFieldInfo) {
|
||||
return tableFieldInfo.isWithUpdateFill();
|
||||
}
|
||||
|
||||
default String mpjMapping(TableFieldInfo tableFieldInfo) {
|
||||
return tableFieldInfo.getMapping();
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package com.github.yulichang.adapter.base.tookit;
|
||||
|
||||
public class CharSequenceUtils {
|
||||
|
||||
public static boolean isBlank(String str) {
|
||||
return str == null || str.trim().isEmpty();
|
||||
}
|
||||
|
||||
public static boolean isNotBlank(String str) {
|
||||
return !isBlank(str);
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
package com.github.yulichang.adapter.base.tookit;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||
|
||||
/**
|
||||
* 版本工具类
|
||||
*
|
||||
@ -8,8 +11,24 @@ package com.github.yulichang.adapter.base.tookit;
|
||||
*/
|
||||
public class VersionUtils {
|
||||
|
||||
public static String version = MybatisPlusVersion.getVersion();
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void setMybatisPlusVersion(String version) {
|
||||
VersionUtils.version = version;
|
||||
}
|
||||
|
||||
public static String getVersion() {
|
||||
if (version != null) {
|
||||
return version;
|
||||
} else {
|
||||
throw ExceptionUtils.mpe("mybatis-plus version is blank, " +
|
||||
"please add VersionUtils.setMybatisPlusVersion(?) code before running application");
|
||||
}
|
||||
}
|
||||
|
||||
public static int compare(String v1, String v2) {
|
||||
String[] v1s = v1.split("\\.");
|
||||
String[] v1s = v1.split("-")[0].split("\\.");
|
||||
String[] v2s = v2.split("\\.");
|
||||
|
||||
String[] vs = v1s.length > v2s.length ? v2s : v1s;
|
||||
|
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--suppress ALL -->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-adapter</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<artifactId>mybatis-plus-join-adapter-v312</artifactId>
|
||||
<version>${revision}</version>
|
||||
<name>mybatis-plus-join-adapter-v312</name>
|
||||
|
||||
<description>An enhanced toolkit of Mybatis-Plus to simplify development.</description>
|
||||
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache License, Version 2.0</name>
|
||||
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>mybatis-plus-join</id>
|
||||
<name>yulichang</name>
|
||||
<email>yu_lichang@qq.com</email>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/yulichang/mybatis-plus-join.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/yulichang/mybatis-plus-join.git</developerConnection>
|
||||
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
||||
</scm>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-adapter-base</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,98 @@
|
||||
package com.github.yulichang.adapter.v312;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.github.yulichang.adapter.base.IAdapter;
|
||||
import com.github.yulichang.adapter.base.metadata.OrderFieldInfo;
|
||||
import com.github.yulichang.adapter.base.tookit.CharSequenceUtils;
|
||||
import com.github.yulichang.adapter.jsqlparser.v46.JSqlParserHelperV46;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
import org.apache.ibatis.type.TypeHandlerRegistry;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author yulichang
|
||||
* @since 1.4.3
|
||||
*/
|
||||
public class Adapter312 implements IAdapter {
|
||||
|
||||
@Override
|
||||
public boolean mpjHasLogic(TableInfo tableInfo) {
|
||||
return tableInfo.isLogicDelete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mpjIsPrimitive(TableFieldInfo tableFieldInfo) {
|
||||
return tableFieldInfo.getPropertyType().isPrimitive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWithUpdateFill(TableFieldInfo tableFieldInfo) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mpjMapping(TableFieldInfo tableFieldInfo) {
|
||||
String el = tableFieldInfo.getEl();
|
||||
if (el != null && el.contains(StringPool.COMMA)) {
|
||||
return el.substring(el.indexOf(StringPool.COMMA) + 1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableFieldInfo mpjGetLogicField(TableInfo tableInfo) {
|
||||
return tableInfo.getFieldList().stream().filter(f -> Objects.nonNull(f.getLogicDeleteValue())
|
||||
|| Objects.nonNull(f.getLogicNotDeleteValue())).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mpjHasPK(TableInfo tableInfo) {
|
||||
return CharSequenceUtils.isNotBlank(tableInfo.getKeyProperty()) ||
|
||||
CharSequenceUtils.isNotBlank(tableInfo.getKeyColumn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Configuration mpjGetConfiguration(TableInfo tableInfo) {
|
||||
return tableInfo.getConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field mpjGetField(TableFieldInfo fieldInfo, Supplier<Field> supplier) {
|
||||
return supplier.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderFieldInfo> mpjGetOrderField(TableInfo tableInfo) {
|
||||
throw new UnsupportedOperationException("不支持排序");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parserColum(String alias, String from, String selectSql, Consumer<String> columConsumer) {
|
||||
JSqlParserHelperV46.parserColum(alias, from, selectSql, columConsumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeHandler<?> getTypeHandler(Configuration configuration, Class<?> propertyType, Class<? extends TypeHandler<?>> typeHandlerClass, Field field) {
|
||||
TypeHandlerRegistry registry = configuration.getTypeHandlerRegistry();
|
||||
TypeHandler<?> typeHandler = registry.getMappingTypeHandler(typeHandlerClass);
|
||||
if (typeHandler == null) {
|
||||
typeHandler = registry.getInstance(propertyType, typeHandlerClass);
|
||||
}
|
||||
return typeHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wrapperInnerPage(Interceptor interceptor, Predicate<Object> predicate, Function<Object, Object> function) {
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
package com.github.yulichang.adapter.v33x;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.adapter.base.IAdapter;
|
||||
import com.github.yulichang.adapter.base.metadata.OrderFieldInfo;
|
||||
import com.github.yulichang.adapter.base.tookit.CharSequenceUtils;
|
||||
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
||||
import com.github.yulichang.adapter.jsqlparser.v46.JSqlParserHelperV46;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
@ -28,7 +27,7 @@ import java.util.function.Supplier;
|
||||
*/
|
||||
public class Adapter33x implements IAdapter {
|
||||
|
||||
private static final boolean is330 = VersionUtils.compare(MybatisPlusVersion.getVersion(), "3.3.0") == 0;
|
||||
private static final boolean is330 = VersionUtils.compare(VersionUtils.getVersion(), "3.3.0") == 0;
|
||||
|
||||
@Override
|
||||
public boolean mpjHasLogic(TableInfo tableInfo) {
|
||||
@ -43,7 +42,7 @@ public class Adapter33x implements IAdapter {
|
||||
@Override
|
||||
public String mpjMapping(TableFieldInfo tableFieldInfo) {
|
||||
String el = tableFieldInfo.getEl();
|
||||
if (StringUtils.isNotBlank(el) && el.contains(StringPool.COMMA)) {
|
||||
if (el != null && el.contains(StringPool.COMMA)) {
|
||||
return el.substring(el.indexOf(StringPool.COMMA) + 1);
|
||||
}
|
||||
return null;
|
||||
@ -57,8 +56,8 @@ public class Adapter33x implements IAdapter {
|
||||
|
||||
@Override
|
||||
public boolean mpjHasPK(TableInfo tableInfo) {
|
||||
return StringUtils.isNotBlank(tableInfo.getKeyProperty()) ||
|
||||
StringUtils.isNotBlank(tableInfo.getKeyColumn());
|
||||
return CharSequenceUtils.isNotBlank(tableInfo.getKeyProperty()) ||
|
||||
CharSequenceUtils.isNotBlank(tableInfo.getKeyColumn());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,10 +1,8 @@
|
||||
package com.github.yulichang.adapter.v3431;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.adapter.base.IAdapter;
|
||||
import com.github.yulichang.adapter.base.metadata.OrderFieldInfo;
|
||||
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
||||
@ -29,13 +27,13 @@ import java.util.stream.Collectors;
|
||||
@AllArgsConstructor
|
||||
public class Adapter3431 implements IAdapter {
|
||||
|
||||
private static final boolean v = VersionUtils.compare(MybatisPlusVersion.getVersion(), "3.4.3") < 0;
|
||||
private static final boolean v = VersionUtils.compare(VersionUtils.getVersion(), "3.4.3") < 0;
|
||||
|
||||
@Override
|
||||
public String mpjMapping(TableFieldInfo tableFieldInfo) {
|
||||
if (v) {
|
||||
String el = tableFieldInfo.getEl();
|
||||
if (StringUtils.isNotBlank(el) && el.contains(StringPool.COMMA)) {
|
||||
if (el != null && el.contains(StringPool.COMMA)) {
|
||||
return el.substring(el.indexOf(StringPool.COMMA) + 1);
|
||||
}
|
||||
return null;
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
<modules>
|
||||
<module>mybatis-plus-join-adapter-base</module>
|
||||
<module>mybatis-plus-join-adapter-v312</module>
|
||||
<module>mybatis-plus-join-adapter-v33x</module>
|
||||
<module>mybatis-plus-join-adapter-v3431</module>
|
||||
<module>mybatis-plus-join-adapter-v352</module>
|
||||
|
@ -4,10 +4,13 @@ import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 动态表名注解
|
||||
* <p>
|
||||
* 1.5.2及以后无需添加此注解就可实现动态表名
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.4.4
|
||||
*/
|
||||
@Deprecated
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
|
@ -18,12 +18,17 @@ import java.lang.annotation.Target;
|
||||
* <li>加APT后缀并且大写 %SAPT</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* 支持Ognl语法字段说明<br/>
|
||||
* 支持Ognl语法,字段说明<br/>
|
||||
* Ognl上下文
|
||||
* <ul>
|
||||
* <li>className 类名</li>
|
||||
* <li>classPackage 包名</li>
|
||||
* <li>util 工具类 stringHelper {@link com.github.yulichang.apt.OgnlRoot.StringHelper}</li>
|
||||
* <li>
|
||||
* util 工具类 OgnlUtil {@link com.github.yulichang.processor.utils.OgnlUtil} ,
|
||||
* <a href="https://github.com/yulichang/mybatis-plus-join/tree/master/plugin/mybatis-plus-join-processor/src/main/java/com/github/yulichang/processor/utils/OgnlUtil.java">
|
||||
* github link
|
||||
* </a>
|
||||
* </li>
|
||||
* </ul>
|
||||
* 指定开头 Ognl# 这不是ognl语法,这是MPJ规定的 用于区分 ognl还是String.format
|
||||
* <p>
|
||||
|
@ -46,8 +46,8 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mpj.mybatis.plus.version}</version>
|
||||
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
|
||||
<version>${mybatis.plus.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.yulichang.autoconfigure;
|
||||
|
||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusLanguageDriverAutoConfiguration;
|
||||
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
||||
import com.github.yulichang.autoconfigure.conditional.JoinSqlInjectorCondition;
|
||||
import com.github.yulichang.autoconfigure.consumer.MybatisPlusJoinIfExistsConsumer;
|
||||
@ -54,7 +53,7 @@ import java.util.Optional;
|
||||
@ConditionalOnClass({SqlSessionFactory.class, SqlSessionFactoryBean.class})
|
||||
@ConditionalOnSingleCandidate(DataSource.class)
|
||||
@EnableConfigurationProperties(MybatisPlusJoinProperties.class)
|
||||
@AutoConfigureAfter({DataSourceAutoConfiguration.class, MybatisPlusLanguageDriverAutoConfiguration.class})
|
||||
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
|
||||
public class MybatisPlusJoinAutoConfiguration {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(MybatisPlusJoinAutoConfiguration.class);
|
||||
|
@ -39,6 +39,11 @@
|
||||
<artifactId>mybatis-plus-join-annotation</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-adapter-v312</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-adapter-v33x</artifactId>
|
||||
@ -59,10 +64,27 @@
|
||||
<artifactId>mybatis-plus-join-adapter-v355</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-wrapper-ext</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
<version>${mpj.mybatis.plus.version}</version>
|
||||
<version>${mybatis.plus.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-jsqlparser</artifactId>
|
||||
<version>${mybatis.plus.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-spring</artifactId>
|
||||
<version>${mybatis.plus.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -82,5 +104,19 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -1,16 +1,14 @@
|
||||
package com.github.yulichang.adapter;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||
import com.github.yulichang.adapter.base.IAdapter;
|
||||
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
||||
import com.github.yulichang.adapter.v312.Adapter312;
|
||||
import com.github.yulichang.adapter.v33x.Adapter33x;
|
||||
import com.github.yulichang.adapter.v3431.Adapter3431;
|
||||
import com.github.yulichang.adapter.v355.Adapter355;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author yulichang
|
||||
* @since 1.4.3
|
||||
@ -22,9 +20,7 @@ public class AdapterHelper {
|
||||
|
||||
|
||||
static {
|
||||
String lastAdapter = "3.5.7";
|
||||
String version = Optional.ofNullable(MybatisPlusVersion.getVersion()).orElse(lastAdapter);
|
||||
|
||||
String version = VersionUtils.getVersion();
|
||||
if (VersionUtils.compare(version, "3.5.6") >= 0) {
|
||||
adapter = new Adapter();
|
||||
} else if (VersionUtils.compare(version, "3.5.4") >= 0) {
|
||||
@ -33,8 +29,10 @@ public class AdapterHelper {
|
||||
adapter = new Adapter3431();
|
||||
} else if (VersionUtils.compare(version, "3.3.0") >= 0) {
|
||||
adapter = new Adapter33x();
|
||||
} else if (VersionUtils.compare(version, "3.1.2") >= 0) {
|
||||
adapter = new Adapter312();
|
||||
} else {
|
||||
throw ExceptionUtils.mpe("MPJ需要MP版本3.3.0+,当前MP版本%s", version);
|
||||
throw ExceptionUtils.mpe("MPJ需要MP版本3.1.2+,当前MP版本%s", version);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,137 @@
|
||||
package com.github.yulichang.base;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import com.github.yulichang.toolkit.Constant;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* join相关方法
|
||||
*
|
||||
* @author yulichang
|
||||
*/
|
||||
public interface JoinMapper<T> {
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,连表删除
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
int deleteJoin(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录
|
||||
*
|
||||
* @param entity 实体对象 (set 条件值,可以为 null)
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
int updateJoin(@Param(Constants.ENTITY) T entity, @Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录 (null字段也会更新 !!!)
|
||||
*
|
||||
* @param entity 实体对象 (set 条件值,可以为 null)
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
int updateJoinAndNull(@Param(Constants.ENTITY) T entity, @Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,查询总记录数
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
Long selectJoinCount(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回一条记录
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @return T
|
||||
*/
|
||||
default T selectJoinOne(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper) {
|
||||
return selectJoinOne(null, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连表查询返回一条记录
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
*/
|
||||
<DTO> DTO selectJoinOne(@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
default Map<String, Object> selectJoinMap(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper) {
|
||||
//noinspection unchecked
|
||||
return selectJoinOne(Map.class, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连表查询返回记录集合
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @return List<T>
|
||||
*/
|
||||
default List<T> selectJoinList(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper) {
|
||||
return selectJoinList(null, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连表查询返回记录集合
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
*/
|
||||
<DTO> List<DTO> selectJoinList(@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map集合
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
default List<Map<String, Object>> selectJoinMaps(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper) {
|
||||
//noinspection unchecked
|
||||
return (List<Map<String, Object>>) ((Object) selectJoinList(Map.class, wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 连表查询返回记录集合并分页
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
default <P extends IPage<T>> P selectJoinPage(P page, @Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper) {
|
||||
return selectJoinPage(page, null, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连表查询返回记录集合并分页
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
* @param <DTO> 分页返回对象
|
||||
*/
|
||||
<DTO, P extends IPage<DTO>> P selectJoinPage(P page,
|
||||
@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map集合并分页
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
default <P extends IPage<Map<String, Object>>> P selectJoinMapsPage(P page,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper) {
|
||||
//noinspection unchecked,rawtypes
|
||||
return (P) selectJoinPage((IPage) page, Map.class, wrapper);
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package com.github.yulichang.base;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public interface JoinService<T> {
|
||||
|
||||
BaseMapper<T> getBaseMapper();
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,连表删除
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
default boolean deleteJoin(MPJBaseJoin<T> wrapper) {
|
||||
return SqlHelper.retBool(((JoinMapper<T>) getBaseMapper()).deleteJoin(wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录
|
||||
*
|
||||
* @param entity 实体对象 (set 条件值,可以为 null)
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
default boolean updateJoin(T entity, MPJBaseJoin<T> wrapper) {
|
||||
return SqlHelper.retBool(((JoinMapper<T>) getBaseMapper()).updateJoin(entity, wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录 (null字段也会更新 !!!)
|
||||
*
|
||||
* @param entity 实体对象 (set 条件值,可以为 null)
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
default boolean updateJoinAndNull(T entity, MPJBaseJoin<T> wrapper) {
|
||||
return SqlHelper.retBool(((JoinMapper<T>) getBaseMapper()).updateJoinAndNull(entity, wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,查询总记录数
|
||||
*/
|
||||
default Long selectJoinCount(MPJBaseJoin<T> wrapper) {
|
||||
return ((JoinMapper<T>) getBaseMapper()).selectJoinCount(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回一条记录
|
||||
*/
|
||||
default <DTO> DTO selectJoinOne(Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((JoinMapper<T>) getBaseMapper()).selectJoinOne(clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回集合
|
||||
*/
|
||||
default <DTO> List<DTO> selectJoinList(Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((JoinMapper<T>) getBaseMapper()).selectJoinList(clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回集合并分页
|
||||
*/
|
||||
default <DTO, P extends IPage<DTO>> P selectJoinListPage(P page, Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((JoinMapper<T>) getBaseMapper()).selectJoinPage(page, clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map
|
||||
*/
|
||||
default Map<String, Object> selectJoinMap(MPJBaseJoin<T> wrapper) {
|
||||
return ((JoinMapper<T>) getBaseMapper()).selectJoinMap(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map集合
|
||||
*/
|
||||
default List<Map<String, Object>> selectJoinMaps(MPJBaseJoin<T> wrapper) {
|
||||
return ((JoinMapper<T>) getBaseMapper()).selectJoinMaps(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map集合并分页
|
||||
*/
|
||||
default <P extends IPage<Map<String, Object>>> P selectJoinMapsPage(P page, MPJBaseJoin<T> wrapper) {
|
||||
return ((JoinMapper<T>) getBaseMapper()).selectJoinMapsPage(page, wrapper);
|
||||
}
|
||||
}
|
@ -1,99 +1,11 @@
|
||||
package com.github.yulichang.base;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import com.github.yulichang.toolkit.Constant;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author yulichang
|
||||
* @see BaseMapper
|
||||
*/
|
||||
public interface MPJBaseMapper<T> extends BaseMapper<T> {
|
||||
public interface MPJBaseMapper<T> extends BaseMapper<T>, JoinMapper<T> {
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,连表删除
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
int deleteJoin(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录
|
||||
*
|
||||
* @param entity 实体对象 (set 条件值,可以为 null)
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
int updateJoin(@Param(Constants.ENTITY) T entity, @Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录 (null字段也会更新 !!!)
|
||||
*
|
||||
* @param entity 实体对象 (set 条件值,可以为 null)
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
int updateJoinAndNull(@Param(Constants.ENTITY) T entity, @Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,查询总记录数
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
Long selectJoinCount(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回一条记录
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
*/
|
||||
<DTO> DTO selectJoinOne(@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
Map<String, Object> selectJoinMap(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回记录集合
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
*/
|
||||
<DTO> List<DTO> selectJoinList(@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map集合
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
List<Map<String, Object>> selectJoinMaps(@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回记录集合并分页
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
* @param clazz resultType
|
||||
* @param <DTO> 分页返回对象
|
||||
*/
|
||||
<DTO, P extends IPage<DTO>> P selectJoinPage(P page,
|
||||
@Param(Constant.CLAZZ) Class<DTO> clazz,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
|
||||
/**
|
||||
* 连表查询返回Map集合并分页
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
<P extends IPage<Map<String, Object>>> P selectJoinMapsPage(P page,
|
||||
@Param(Constants.WRAPPER) MPJBaseJoin<T> wrapper);
|
||||
}
|
||||
|
@ -1,12 +1,6 @@
|
||||
package com.github.yulichang.base;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 基础service
|
||||
@ -15,84 +9,6 @@ import java.util.Map;
|
||||
* @author yulichang
|
||||
*/
|
||||
@SuppressWarnings({"unused"})
|
||||
public interface MPJBaseService<T> extends IService<T> {
|
||||
public interface MPJBaseService<T> extends IService<T>, JoinService<T> {
|
||||
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,连表删除
|
||||
*
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
default boolean deleteJoin(MPJBaseJoin<T> wrapper) {
|
||||
return SqlHelper.retBool(((MPJBaseMapper<T>) getBaseMapper()).deleteJoin(wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录
|
||||
*
|
||||
* @param entity 实体对象 (set 条件值,可以为 null)
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
default boolean updateJoin(T entity, MPJBaseJoin<T> wrapper) {
|
||||
return SqlHelper.retBool(((MPJBaseMapper<T>) getBaseMapper()).updateJoin(entity, wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 whereEntity 条件,更新记录 (null字段也会更新 !!!)
|
||||
*
|
||||
* @param entity 实体对象 (set 条件值,可以为 null)
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
default boolean updateJoinAndNull(T entity, MPJBaseJoin<T> wrapper) {
|
||||
return SqlHelper.retBool(((MPJBaseMapper<T>) getBaseMapper()).updateJoinAndNull(entity, wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,查询总记录数
|
||||
*/
|
||||
default Long selectJoinCount(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinCount(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回一条记录
|
||||
*/
|
||||
default <DTO> DTO selectJoinOne(Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinOne(clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回集合
|
||||
*/
|
||||
default <DTO> List<DTO> selectJoinList(Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinList(clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回集合并分页
|
||||
*/
|
||||
default <DTO, P extends IPage<DTO>> P selectJoinListPage(P page, Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinPage(page, clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map
|
||||
*/
|
||||
default Map<String, Object> selectJoinMap(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMap(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map集合
|
||||
*/
|
||||
default List<Map<String, Object>> selectJoinMaps(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMaps(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map集合并分页
|
||||
*/
|
||||
default <P extends IPage<Map<String, Object>>> P selectJoinMapsPage(P page, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMapsPage(page, wrapper);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.github.yulichang.config;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.github.yulichang.interceptor.MPJInterceptor;
|
||||
import com.github.yulichang.toolkit.InterceptorList;
|
||||
import com.github.yulichang.toolkit.MybatisJoinPlusVersion;
|
||||
import org.apache.ibatis.logging.Log;
|
||||
import org.apache.ibatis.logging.LogFactory;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
@ -30,7 +31,7 @@ public class MPJInterceptorConfig {
|
||||
System.out.println(" _ _ |_ _ _|_. ___ _ | _ . _ . _ \n" +
|
||||
"| | |\\/|_)(_| | |_\\ |_)||_|_\\ | (_) | | | \n" +
|
||||
" / | /\n" +
|
||||
" 1.5.0");
|
||||
" " + MybatisJoinPlusVersion.getVersion());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.github.yulichang.config.enums;
|
||||
|
||||
import com.github.yulichang.toolkit.MPJStringUtils;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import com.github.yulichang.wrapper.interfaces.MPredicate;
|
||||
|
||||
import java.io.Serializable;
|
||||
@ -21,11 +21,11 @@ public enum IfExistsEnum implements MPredicate<Object>, Serializable {
|
||||
/**
|
||||
* 非空字符串 例: "" -> false, " " -> true ...
|
||||
*/
|
||||
NOT_EMPTY(val -> NOT_NULL.and(v -> !(v instanceof CharSequence) || MPJStringUtils.isNotEmpty((CharSequence) v)).test(val)),
|
||||
NOT_EMPTY(val -> NOT_NULL.and(v -> !(v instanceof CharSequence) || StrUtils.isNotEmpty((CharSequence) v)).test(val)),
|
||||
/**
|
||||
* NOT_BLANK 非空白字符串 例: "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
|
||||
*/
|
||||
NOT_BLANK(val -> NOT_NULL.and(v -> !(v instanceof CharSequence) || MPJStringUtils.isNotBlank((CharSequence) v)).test(val));
|
||||
NOT_BLANK(val -> NOT_NULL.and(v -> !(v instanceof CharSequence) || StrUtils.isNotBlank((CharSequence) v)).test(val));
|
||||
|
||||
private final MPredicate<Object> predicate;
|
||||
|
||||
|
@ -6,18 +6,14 @@ import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.adapter.AdapterHelper;
|
||||
import com.github.yulichang.extension.apt.matedata.BaseColumn;
|
||||
import com.github.yulichang.extension.apt.matedata.Column;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
||||
import com.github.yulichang.extension.apt.interfaces.QueryJoin;
|
||||
import com.github.yulichang.toolkit.Constant;
|
||||
import com.github.yulichang.toolkit.LogicInfoUtils;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.TableMap;
|
||||
import com.github.yulichang.extension.apt.matedata.BaseColumn;
|
||||
import com.github.yulichang.extension.apt.matedata.Column;
|
||||
import com.github.yulichang.toolkit.*;
|
||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||
import com.github.yulichang.wrapper.interfaces.MFunction;
|
||||
import com.github.yulichang.wrapper.segments.PageInfo;
|
||||
@ -124,7 +120,7 @@ public abstract class AptAbstractWrapper<T, Children extends AptAbstractWrapper<
|
||||
* 构造方法
|
||||
*/
|
||||
protected AptAbstractWrapper(BaseColumn<T> baseColumn) {
|
||||
this.alias = StringUtils.isNotBlank(baseColumn.getAlias()) ? baseColumn.getAlias() : this.alias;
|
||||
this.alias = StrUtils.isNotBlank(baseColumn.getAlias()) ? baseColumn.getAlias() : this.alias;
|
||||
setEntityClass(baseColumn.getColumnClass());
|
||||
this.baseColumn = baseColumn;
|
||||
initNeed();
|
||||
@ -136,7 +132,7 @@ public abstract class AptAbstractWrapper<T, Children extends AptAbstractWrapper<
|
||||
* @param entity 主表实体类
|
||||
*/
|
||||
protected AptAbstractWrapper(BaseColumn<T> baseColumn, T entity) {
|
||||
this.alias = StringUtils.isNotBlank(baseColumn.getAlias()) ? baseColumn.getAlias() : this.alias;
|
||||
this.alias = StrUtils.isNotBlank(baseColumn.getAlias()) ? baseColumn.getAlias() : this.alias;
|
||||
setEntity(entity);
|
||||
this.baseColumn = baseColumn;
|
||||
initNeed();
|
||||
@ -310,10 +306,10 @@ public abstract class AptAbstractWrapper<T, Children extends AptAbstractWrapper<
|
||||
* 获取连表部分语句
|
||||
*/
|
||||
public String getFrom() {
|
||||
if (StringUtils.isBlank(from.getStringValue())) {
|
||||
if (StrUtils.isBlank(from.getStringValue())) {
|
||||
StringBuilder value = new StringBuilder();
|
||||
for (Children wrapper : onWrappers) {
|
||||
if (StringUtils.isBlank(wrapper.from.getStringValue())) {
|
||||
if (StrUtils.isBlank(wrapper.from.getStringValue())) {
|
||||
if (this.subLogicSql && this.logicDelType == LogicDelTypeEnum.ON) {
|
||||
TableInfo tableInfo = TableHelper.getAssert(wrapper.getJoinClass());
|
||||
if (AdapterHelper.getAdapter().mpjHasLogic(tableInfo)) {
|
||||
@ -371,7 +367,7 @@ public abstract class AptAbstractWrapper<T, Children extends AptAbstractWrapper<
|
||||
Children instance = instance(newIndex, keyWord, baseColumn.getColumnClass(), info.getTableName());
|
||||
instance.isMain = false;
|
||||
onWrappers.add(instance);
|
||||
if (StringUtils.isBlank(baseColumn.getAlias())) {
|
||||
if (StrUtils.isBlank(baseColumn.getAlias())) {
|
||||
aptIndex.put(baseColumn, subTableAlias + newIndex);
|
||||
instance.alias = subTableAlias;
|
||||
instance.hasAlias = false;
|
||||
@ -393,10 +389,10 @@ public abstract class AptAbstractWrapper<T, Children extends AptAbstractWrapper<
|
||||
* @param joinSql sql
|
||||
*/
|
||||
@Override
|
||||
public Children join(String keyWord, boolean condition, String joinSql) {
|
||||
public Children join(String keyWord, boolean condition, String joinSql, Object... objects) {
|
||||
if (condition) {
|
||||
Children wrapper = instanceEmpty();
|
||||
wrapper.from.setStringValue(joinSql);
|
||||
wrapper.from.setStringValue(formatSqlMaybeWithParam(joinSql, objects));
|
||||
wrapper.keyWord = keyWord;
|
||||
onWrappers.add(wrapper);
|
||||
}
|
||||
@ -410,7 +406,7 @@ public abstract class AptAbstractWrapper<T, Children extends AptAbstractWrapper<
|
||||
*/
|
||||
public boolean isUseAnnotationOrderBy() {
|
||||
final String _sqlSegment = this.getSqlSegment();
|
||||
if (StringUtils.isBlank(_sqlSegment)) {
|
||||
if (StrUtils.isBlank(_sqlSegment)) {
|
||||
return true;
|
||||
}
|
||||
final String _sqlSegmentToUpperCase = _sqlSegment.toUpperCase();
|
||||
|
@ -5,26 +5,25 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.extension.apt.matedata.BaseColumn;
|
||||
import com.github.yulichang.extension.apt.matedata.Column;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.extension.apt.interfaces.Query;
|
||||
import com.github.yulichang.extension.apt.interfaces.QueryLabel;
|
||||
import com.github.yulichang.extension.apt.matedata.BaseColumn;
|
||||
import com.github.yulichang.extension.apt.matedata.Column;
|
||||
import com.github.yulichang.extension.apt.toolkit.AptWrapperUtils;
|
||||
import com.github.yulichang.extension.apt.toolkit.AptWrappers;
|
||||
import com.github.yulichang.toolkit.Constant;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import com.github.yulichang.toolkit.TableMap;
|
||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.interfaces.Chain;
|
||||
import com.github.yulichang.wrapper.interfaces.MBiPredicate;
|
||||
import com.github.yulichang.wrapper.interfaces.MFunction;
|
||||
import com.github.yulichang.wrapper.interfaces.SelectWrapper;
|
||||
import com.github.yulichang.wrapper.resultmap.Label;
|
||||
import com.github.yulichang.wrapper.segments.Select;
|
||||
import com.github.yulichang.wrapper.segments.SelectApt;
|
||||
import com.github.yulichang.wrapper.segments.SelectCache;
|
||||
import com.github.yulichang.wrapper.segments.SelectSub;
|
||||
import com.github.yulichang.wrapper.segments.*;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
@ -192,10 +191,27 @@ public class AptQueryWrapper<T> extends AptAbstractWrapper<T, AptQueryWrapper<T>
|
||||
return selectAll(getBaseColumn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AptQueryWrapper<T> selectFunc(String sql, MFunction<AptConsumer> column, String alias) {
|
||||
AptConsumer apply = column.apply(new AptConsumer());
|
||||
String formatSql;
|
||||
if (ArrayUtils.isEmpty(apply.getValues())) {
|
||||
formatSql = sql;
|
||||
} else {
|
||||
formatSql = formatSqlMaybeWithParam(sql, apply.getValues());
|
||||
}
|
||||
getSelectColum().add(new SelectApt(apply.getColumns(), () -> formatSql, alias));
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
public <E, F> AptQueryWrapper<T> selectSub(BaseColumn<E> baseColumn, Consumer<AptQueryWrapper<E>> consumer, SFunction<F, ?> alias) {
|
||||
return selectSub(baseColumn, consumer, LambdaUtils.getName(alias));
|
||||
}
|
||||
|
||||
/**
|
||||
* 子查询
|
||||
*/
|
||||
public <E, F> AptQueryWrapper<T> selectSub(BaseColumn<E> baseColumn, Consumer<AptQueryWrapper<E>> consumer, SFunction<F, ?> alias) {
|
||||
public <E, F> AptQueryWrapper<T> selectSub(BaseColumn<E> baseColumn, Consumer<AptQueryWrapper<E>> consumer, String alias) {
|
||||
AptQueryWrapper<E> wrapper = new AptQueryWrapper<E>(null, baseColumn, SharedString.emptyString(),
|
||||
paramNameSeq, paramNameValuePairs, new MergeSegments(), new SharedString(this.paramAlias
|
||||
.getStringValue()), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||
@ -209,8 +225,7 @@ public class AptQueryWrapper<T> extends AptAbstractWrapper<T, AptQueryWrapper<T>
|
||||
wrapper.subTableAlias = ConfigProperties.subQueryAlias;
|
||||
consumer.accept(wrapper);
|
||||
addCustomWrapper(wrapper);
|
||||
String name = LambdaUtils.getName(alias);
|
||||
this.selectColumns.add(new SelectSub(() -> AptWrapperUtils.buildSubSqlByWrapper(baseColumn.getColumnClass(), wrapper, name), hasAlias, this.alias, name));
|
||||
this.selectColumns.add(new SelectSub(() -> AptWrapperUtils.buildSubSqlByWrapper(baseColumn.getColumnClass(), wrapper, alias), hasAlias, this.alias, alias));
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@ -277,7 +292,7 @@ public class AptQueryWrapper<T> extends AptAbstractWrapper<T, AptQueryWrapper<T>
|
||||
*/
|
||||
@Override
|
||||
public String getSqlSelect() {
|
||||
if (StringUtils.isBlank(sqlSelect.getStringValue()) && CollectionUtils.isNotEmpty(selectColumns)) {
|
||||
if (StrUtils.isBlank(sqlSelect.getStringValue()) && CollectionUtils.isNotEmpty(selectColumns)) {
|
||||
String s = selectColumns.stream().map(i -> {
|
||||
if (i.isStr()) {
|
||||
return i.getColumn();
|
||||
|
@ -12,13 +12,14 @@ import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.extension.apt.matedata.Column;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.extension.apt.interfaces.CompareIfExists;
|
||||
import com.github.yulichang.extension.apt.interfaces.Func;
|
||||
import com.github.yulichang.extension.apt.interfaces.OnCompare;
|
||||
import com.github.yulichang.extension.apt.matedata.Column;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
import com.github.yulichang.toolkit.MPJSqlInjectionUtils;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import com.github.yulichang.toolkit.Ref;
|
||||
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||
@ -32,6 +33,8 @@ import java.util.function.BiPredicate;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.baomidou.mybatisplus.core.enums.SqlKeyword.*;
|
||||
@ -170,7 +173,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
|
||||
/**
|
||||
* 设置 IfExists
|
||||
* .IfExists(val -> val != null && StringUtils.isNotBlank(val))
|
||||
* .IfExists(val -> val != null && StrUtils.isNotBlank(val))
|
||||
*
|
||||
* @param IfExists 判断
|
||||
* @return Children
|
||||
@ -280,18 +283,22 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
@Override
|
||||
public Children apply(boolean condition, String applySql, Object... values) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(APPLY,
|
||||
() -> formatSqlMaybeWithParam(applySql, null, values)));
|
||||
() -> formatSqlMaybeWithParam(applySql, values)));
|
||||
}
|
||||
|
||||
public Children applyFunc(String applySql, SFunction<AptConsumer, Column[]> consumerFunction, Object... values) {
|
||||
public Children applyFunc(String applySql, MFunction<AptConsumer> consumerFunction, Object... values) {
|
||||
return applyFunc(true, applySql, consumerFunction, values);
|
||||
}
|
||||
|
||||
public Children applyFunc(boolean condition, String applySql,
|
||||
SFunction<AptConsumer, Column[]> consumerFunction, Object... values) {
|
||||
MFunction<AptConsumer> consumerFunction, Object... values) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(APPLY,
|
||||
() -> formatSqlMaybeWithParam(String.format(applySql,
|
||||
Arrays.stream(consumerFunction.apply(AptConsumer.func)).map(this::columnToString).toArray()), null, values)));
|
||||
() -> {
|
||||
AptConsumer apply = consumerFunction.apply(new AptConsumer());
|
||||
return formatSqlMaybeWithParam(String.format(applySql,
|
||||
Arrays.stream(apply.getColumns()).map(this::columnToString).toArray()),
|
||||
ArrayUtils.isNotEmpty(values) ? values : apply.getValues());
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -328,7 +335,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
@Override
|
||||
public Children exists(boolean condition, String existsSql, Object... values) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(EXISTS,
|
||||
() -> String.format("(%s)", formatSqlMaybeWithParam(existsSql, null, values))));
|
||||
() -> String.format("(%s)", formatSqlMaybeWithParam(existsSql, values))));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -476,7 +483,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
@Override
|
||||
public Children having(boolean condition, String sqlHaving, Object... params) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(HAVING,
|
||||
() -> formatSqlMaybeWithParam(sqlHaving, null, params)));
|
||||
() -> formatSqlMaybeWithParam(sqlHaving, params)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -568,21 +575,27 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
* <p>
|
||||
* 支持 "{0}" 这种,或者 "sql {0} sql" 这种
|
||||
*
|
||||
* @param sqlStr 可能是sql片段
|
||||
* @param mapping 例如: "javaType=int,jdbcType=NUMERIC,typeHandler=xxx.xxx.MyTypeHandler" 这种
|
||||
* @param params 参数
|
||||
* @param sqlStr 可能是sql片段
|
||||
* @param params 参数
|
||||
* @return sql片段
|
||||
*/
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
protected final String formatSqlMaybeWithParam(String sqlStr, String mapping, Object... params) {
|
||||
if (StringUtils.isBlank(sqlStr)) {
|
||||
// todo 何时会这样?
|
||||
protected final String formatSqlMaybeWithParam(String sqlStr, Object... params) {
|
||||
if (StrUtils.isBlank(sqlStr)) {
|
||||
return null;
|
||||
}
|
||||
if (ArrayUtils.isNotEmpty(params)) {
|
||||
for (int i = 0; i < params.length; ++i) {
|
||||
final String target = Constants.LEFT_BRACE + i + Constants.RIGHT_BRACE;
|
||||
sqlStr = sqlStr.replace(target, formatParam(mapping, params[i]));
|
||||
String target = Constants.LEFT_BRACE + i + Constants.RIGHT_BRACE;
|
||||
if (sqlStr.contains(target)) {
|
||||
sqlStr = sqlStr.replace(target, formatParam(null, params[i]));
|
||||
} else {
|
||||
Matcher matcher = Pattern.compile("[{]" + i + ",[a-zA-Z0-9.,=]+}").matcher(sqlStr);
|
||||
if (!matcher.find()) {
|
||||
throw ExceptionUtils.mpe("Please check the syntax correctness! sql not contains: \"%s\"", target);
|
||||
}
|
||||
String group = matcher.group();
|
||||
sqlStr = sqlStr.replace(group, formatParam(group.substring(target.length(), group.length() - 1), params[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return sqlStr;
|
||||
@ -674,7 +687,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
|
||||
@Override
|
||||
public String getSqlComment() {
|
||||
if (StringUtils.isNotBlank(sqlComment.getStringValue())) {
|
||||
if (StrUtils.isNotBlank(sqlComment.getStringValue())) {
|
||||
return "/*" + StringEscape.escapeRawString(sqlComment.getStringValue()) + "*/";
|
||||
}
|
||||
return null;
|
||||
@ -682,7 +695,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
|
||||
@Override
|
||||
public String getSqlFirst() {
|
||||
if (StringUtils.isNotBlank(sqlFirst.getStringValue())) {
|
||||
if (StrUtils.isNotBlank(sqlFirst.getStringValue())) {
|
||||
return StringEscape.escapeRawString(sqlFirst.getStringValue());
|
||||
}
|
||||
return null;
|
||||
@ -859,7 +872,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
public <V> Children allEqStr(boolean condition, Map<String, V> params, boolean null2IsNull) {
|
||||
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||
params.forEach((k, v) -> {
|
||||
if (StringUtils.checkValNotNull(v)) {
|
||||
if (StrUtils.checkValNotNull(v)) {
|
||||
eq(k, v);
|
||||
} else {
|
||||
if (null2IsNull) {
|
||||
@ -876,7 +889,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||
params.forEach((k, v) -> {
|
||||
if (filter.test(k, v)) {
|
||||
if (StringUtils.checkValNotNull(v)) {
|
||||
if (StrUtils.checkValNotNull(v)) {
|
||||
eq(k, v);
|
||||
} else {
|
||||
if (null2IsNull) {
|
||||
|
@ -13,11 +13,11 @@ import com.github.yulichang.toolkit.support.ColumnCache;
|
||||
import com.github.yulichang.toolkit.support.FieldCache;
|
||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||
import com.github.yulichang.wrapper.enums.DefaultFuncEnum;
|
||||
import com.github.yulichang.wrapper.interfaces.MFunction;
|
||||
import com.github.yulichang.wrapper.segments.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -115,7 +115,7 @@ public interface Query<Children> extends Serializable {
|
||||
/**
|
||||
* 别名查询
|
||||
*/
|
||||
default <S> Children selectAs(Column column, String alias) {
|
||||
default Children selectAs(Column column, String alias) {
|
||||
Map<String, SelectCache> cacheMap = ColumnCache.getMapField(column.getClazz());
|
||||
SelectCache cache = cacheMap.get(column.getProperty());
|
||||
getSelectColum().add(new SelectApt(cache, column, alias));
|
||||
@ -165,27 +165,24 @@ public interface Query<Children> extends Serializable {
|
||||
* @param column 函数作用的字段
|
||||
* @param alias 别名
|
||||
*/
|
||||
default <S> Children selectFunc(BaseFuncEnum funcEnum, Column column, String alias) {
|
||||
default Children selectFunc(BaseFuncEnum funcEnum, Column column, String alias) {
|
||||
Map<String, SelectCache> cacheMap = ColumnCache.getMapField(column.getClazz());
|
||||
getSelectColum().add(new SelectApt(cacheMap.get(column.getProperty()), column, funcEnum, alias));
|
||||
return getChildren();
|
||||
}
|
||||
|
||||
default <S, X> Children selectFunc(BaseFuncEnum funcEnum, Column column, SFunction<X, ?> alias) {
|
||||
default <X> Children selectFunc(BaseFuncEnum funcEnum, Column column, SFunction<X, ?> alias) {
|
||||
return selectFunc(funcEnum, column, LambdaUtils.getName(alias));
|
||||
}
|
||||
|
||||
default <S> Children selectFunc(BaseFuncEnum funcEnum, Column column) {
|
||||
default Children selectFunc(BaseFuncEnum funcEnum, Column column) {
|
||||
return selectFunc(funcEnum, column, column.getProperty());
|
||||
}
|
||||
|
||||
|
||||
default <X> Children selectFunc(String sql, Function<AptConsumer, Column[]> column, String alias) {
|
||||
getSelectColum().add(new SelectApt(column.apply(AptConsumer.func), () -> sql, alias));
|
||||
return getChildren();
|
||||
}
|
||||
Children selectFunc(String sql, MFunction<AptConsumer> column, String alias);
|
||||
|
||||
default <X, S> Children selectFunc(String sql, Function<AptConsumer, Column[]> column, SFunction<S, ?> alias) {
|
||||
default <S> Children selectFunc(String sql, MFunction<AptConsumer> column, SFunction<S, ?> alias) {
|
||||
return selectFunc(sql, column, LambdaUtils.getName(alias));
|
||||
}
|
||||
|
||||
@ -194,90 +191,90 @@ public interface Query<Children> extends Serializable {
|
||||
/**
|
||||
* SUM()
|
||||
*/
|
||||
default <S> Children selectSum(Column column) {
|
||||
default Children selectSum(Column column) {
|
||||
return selectFunc(DefaultFuncEnum.SUM, column);
|
||||
}
|
||||
|
||||
default <S, X> Children selectSum(Column column, SFunction<X, ?> alias) {
|
||||
default <X> Children selectSum(Column column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.SUM, column, alias);
|
||||
}
|
||||
|
||||
default <S, X> Children selectSum(Column column, String alias) {
|
||||
default Children selectSum(Column column, String alias) {
|
||||
return selectFunc(DefaultFuncEnum.SUM, column, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* COUNT()
|
||||
*/
|
||||
default <S> Children selectCount(Column column) {
|
||||
default Children selectCount(Column column) {
|
||||
return selectFunc(DefaultFuncEnum.COUNT, column);
|
||||
}
|
||||
|
||||
default <S, X> Children selectCount(Column column, SFunction<X, ?> alias) {
|
||||
default <X> Children selectCount(Column column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.COUNT, column, alias);
|
||||
}
|
||||
|
||||
default <S, X> Children selectCount(Column column, String alias) {
|
||||
default Children selectCount(Column column, String alias) {
|
||||
return selectFunc(DefaultFuncEnum.COUNT, column, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* MAX()
|
||||
*/
|
||||
default <S> Children selectMax(Column column) {
|
||||
default Children selectMax(Column column) {
|
||||
return selectFunc(DefaultFuncEnum.MAX, column);
|
||||
}
|
||||
|
||||
default <S, X> Children selectMax(Column column, SFunction<X, ?> alias) {
|
||||
default <X> Children selectMax(Column column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.MAX, column, alias);
|
||||
}
|
||||
|
||||
default <S, X> Children selectMax(Column column, String alias) {
|
||||
default Children selectMax(Column column, String alias) {
|
||||
return selectFunc(DefaultFuncEnum.MAX, column, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* MIN()
|
||||
*/
|
||||
default <S> Children selectMin(Column column) {
|
||||
default Children selectMin(Column column) {
|
||||
return selectFunc(DefaultFuncEnum.MIN, column);
|
||||
}
|
||||
|
||||
default <S, X> Children selectMin(Column column, SFunction<X, ?> alias) {
|
||||
default <X> Children selectMin(Column column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.MIN, column, alias);
|
||||
}
|
||||
|
||||
default <S, X> Children selectMin(Column column, String alias) {
|
||||
default Children selectMin(Column column, String alias) {
|
||||
return selectFunc(DefaultFuncEnum.MIN, column, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* MIN()
|
||||
*/
|
||||
default <S> Children selectAvg(Column column) {
|
||||
default Children selectAvg(Column column) {
|
||||
return selectFunc(DefaultFuncEnum.AVG, column);
|
||||
}
|
||||
|
||||
default <S, X> Children selectAvg(Column column, SFunction<X, ?> alias) {
|
||||
default <X> Children selectAvg(Column column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.AVG, column, alias);
|
||||
}
|
||||
|
||||
default <S, X> Children selectAvg(Column column, String alias) {
|
||||
default Children selectAvg(Column column, String alias) {
|
||||
return selectFunc(DefaultFuncEnum.AVG, column, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* LEN()
|
||||
*/
|
||||
default <S> Children selectLen(Column column) {
|
||||
default Children selectLen(Column column) {
|
||||
return selectFunc(DefaultFuncEnum.LEN, column);
|
||||
}
|
||||
|
||||
default <S, X> Children selectLen(Column column, SFunction<X, ?> alias) {
|
||||
default <X> Children selectLen(Column column, SFunction<X, ?> alias) {
|
||||
return selectFunc(DefaultFuncEnum.LEN, column, alias);
|
||||
}
|
||||
|
||||
default <S, X> Children selectLen(Column column, String alias) {
|
||||
default Children selectLen(Column column, String alias) {
|
||||
return selectFunc(DefaultFuncEnum.LEN, column, alias);
|
||||
}
|
||||
}
|
||||
|
@ -1,89 +0,0 @@
|
||||
package com.github.yulichang.extension.apt.matedata;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* apt ognl表达式上下文
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.5.0
|
||||
*/
|
||||
@Getter
|
||||
public class OgnlRoot {
|
||||
|
||||
/**
|
||||
* 类名
|
||||
*/
|
||||
private final String className;
|
||||
|
||||
/**
|
||||
* 包名
|
||||
*/
|
||||
private final String classPackage;
|
||||
|
||||
private final StringHelper util = new StringHelper();
|
||||
|
||||
public OgnlRoot(String className, String classPackage) {
|
||||
this.className = className;
|
||||
this.classPackage = classPackage;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static final class StringHelper {
|
||||
/**
|
||||
* 移除后缀
|
||||
*
|
||||
* @param str 原字符串
|
||||
* @param suffix 指定后缀
|
||||
*/
|
||||
public String removeSuffix(String str, String suffix) {
|
||||
if (isBlank(str) || isBlank(suffix)) {
|
||||
return str;
|
||||
}
|
||||
if (str.endsWith(suffix)) {
|
||||
return str.substring(0, str.length() - suffix.length());
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换后缀
|
||||
*
|
||||
* @param str 原字符串
|
||||
* @param suffix 指定后缀
|
||||
* @param replacement 新后缀
|
||||
*/
|
||||
public String replaceSuffix(String str, String suffix, String replacement) {
|
||||
if (isBlank(str)) {
|
||||
return str;
|
||||
}
|
||||
String rep = Objects.isNull(replacement) ? "" : replacement;
|
||||
if (isBlank(suffix)) {
|
||||
return str + rep;
|
||||
}
|
||||
if (str.endsWith(suffix)) {
|
||||
return str.substring(0, str.length() - suffix.length()) + rep;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上级包名
|
||||
*
|
||||
* @param pk 报名
|
||||
* @return 上级报名
|
||||
*/
|
||||
public String getParentPackage(String pk) {
|
||||
if (pk.lastIndexOf(".") > -1) {
|
||||
return pk;
|
||||
}
|
||||
return pk.substring(0, pk.lastIndexOf('.'));
|
||||
}
|
||||
|
||||
private boolean isBlank(String str) {
|
||||
return str == null || str.trim().isEmpty();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package com.github.yulichang.extension.apt.resultmap;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.extension.apt.matedata.BaseColumn;
|
||||
import com.github.yulichang.extension.apt.matedata.Column;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||
import com.github.yulichang.wrapper.resultmap.IResult;
|
||||
import com.github.yulichang.wrapper.segments.SelectCache;
|
||||
@ -93,7 +93,7 @@ public class Result implements IResult {
|
||||
SelectCache normal = normalMap.get(column.getProperty());
|
||||
result.selectNormal = normal;
|
||||
result.column = column;
|
||||
if (StringUtils.isBlank(result.property)) {
|
||||
if (StrUtils.isBlank(result.property)) {
|
||||
result.property = normal.getColumProperty();
|
||||
}
|
||||
if (Objects.isNull(result.javaType)) {
|
||||
|
@ -4,12 +4,12 @@ import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.adapter.AdapterHelper;
|
||||
import com.github.yulichang.extension.apt.AptQueryWrapper;
|
||||
import com.github.yulichang.toolkit.LogicInfoUtils;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.extension.apt.AptQueryWrapper;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
@ -26,18 +26,18 @@ public class AptWrapperUtils {
|
||||
String first = Optional.ofNullable(wrapper.getSqlFirst()).orElse(StringPool.EMPTY);
|
||||
boolean hasWhere = false;
|
||||
String entityWhere = getEntitySql(tableInfo, wrapper);
|
||||
if (StringUtils.isNotBlank(entityWhere)) {
|
||||
if (StrUtils.isNotBlank(entityWhere)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String mainLogic = mainLogic(hasWhere, clazz, wrapper);
|
||||
if (StringUtils.isNotBlank(mainLogic)) {
|
||||
if (StrUtils.isNotBlank(mainLogic)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String subLogic = subLogic(hasWhere, wrapper);
|
||||
if (StringUtils.isNotBlank(subLogic)) {
|
||||
if (StrUtils.isNotBlank(subLogic)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String sqlSegment = (wrapper.getSqlSegment() != null && StringUtils.isNotBlank(wrapper.getSqlSegment())) ?
|
||||
String sqlSegment = (wrapper.getSqlSegment() != null && StrUtils.isNotBlank(wrapper.getSqlSegment())) ?
|
||||
((wrapper.isEmptyOfNormal() ? StringPool.EMPTY : (hasWhere ? " AND " : " WHERE ")) + wrapper.getSqlSegment()) : StringPool.EMPTY;
|
||||
|
||||
String sqlComment = Optional.ofNullable(wrapper.getSqlComment()).orElse(StringPool.EMPTY);
|
||||
@ -59,18 +59,18 @@ public class AptWrapperUtils {
|
||||
String first = Optional.ofNullable(wrapper.getSqlFirst()).orElse(StringPool.EMPTY);
|
||||
boolean hasWhere = false;
|
||||
String entityWhere = getEntitySql(tableInfo, wrapper);
|
||||
if (StringUtils.isNotBlank(entityWhere)) {
|
||||
if (StrUtils.isNotBlank(entityWhere)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String mainLogic = mainLogic(hasWhere, clazz, wrapper);
|
||||
if (StringUtils.isNotBlank(mainLogic)) {
|
||||
if (StrUtils.isNotBlank(mainLogic)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String subLogic = subLogic(hasWhere, wrapper);
|
||||
if (StringUtils.isNotBlank(subLogic)) {
|
||||
if (StrUtils.isNotBlank(subLogic)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String sqlSegment = (wrapper.getSqlSegment() != null && StringUtils.isNotBlank(wrapper.getSqlSegment())) ?
|
||||
String sqlSegment = (wrapper.getSqlSegment() != null && StrUtils.isNotBlank(wrapper.getSqlSegment())) ?
|
||||
((wrapper.isEmptyOfNormal() ? StringPool.EMPTY : (hasWhere ? " AND " : " WHERE ")) + wrapper.getSqlSegment()) : StringPool.EMPTY;
|
||||
|
||||
String sqlComment = Optional.ofNullable(wrapper.getSqlComment()).orElse(StringPool.EMPTY);
|
||||
@ -129,7 +129,7 @@ public class AptWrapperUtils {
|
||||
return StringPool.EMPTY;
|
||||
}
|
||||
String info = LogicInfoUtils.getLogicInfo(null, clazz, true, wrapper.getAlias());
|
||||
if (StringUtils.isNotBlank(info)) {
|
||||
if (StrUtils.isNotBlank(info)) {
|
||||
if (hasWhere) {
|
||||
return " AND " + info;
|
||||
}
|
||||
@ -140,7 +140,7 @@ public class AptWrapperUtils {
|
||||
|
||||
private static String subLogic(boolean hasWhere, AptQueryWrapper<?> wrapper) {
|
||||
String sql = wrapper.getSubLogicSql();
|
||||
if (StringUtils.isNotBlank(sql)) {
|
||||
if (StrUtils.isNotBlank(sql)) {
|
||||
if (hasWhere) {
|
||||
return sql;
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.adapter.AdapterHelper;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
||||
@ -363,10 +362,10 @@ public abstract class KtAbstractLambdaWrapper<T, Children extends KtAbstractLamb
|
||||
* 获取连表部分语句
|
||||
*/
|
||||
public String getFrom() {
|
||||
if (StringUtils.isBlank(from.getStringValue())) {
|
||||
if (StrUtils.isBlank(from.getStringValue())) {
|
||||
StringBuilder value = new StringBuilder();
|
||||
for (Children wrapper : onWrappers) {
|
||||
if (StringUtils.isBlank(wrapper.from.getStringValue())) {
|
||||
if (StrUtils.isBlank(wrapper.from.getStringValue())) {
|
||||
if (this.subLogicSql && this.logicDelType == LogicDelTypeEnum.ON) {
|
||||
TableInfo tableInfo = TableHelper.getAssert(wrapper.getJoinClass());
|
||||
if (AdapterHelper.getAdapter().mpjHasLogic(tableInfo)) {
|
||||
@ -408,7 +407,7 @@ public abstract class KtAbstractLambdaWrapper<T, Children extends KtAbstractLamb
|
||||
instance.isNo = true;
|
||||
instance.isMain = false;
|
||||
onWrappers.add(instance);
|
||||
if (StringUtils.isBlank(tableAlias)) {
|
||||
if (StrUtils.isBlank(tableAlias)) {
|
||||
tableList.put(oldIndex, clazz, false, subTableAlias, newIndex);
|
||||
instance.alias = subTableAlias;
|
||||
instance.hasAlias = false;
|
||||
@ -436,10 +435,10 @@ public abstract class KtAbstractLambdaWrapper<T, Children extends KtAbstractLamb
|
||||
* @param joinSql sql
|
||||
*/
|
||||
@Override
|
||||
public Children join(String keyWord, boolean condition, String joinSql) {
|
||||
public Children join(String keyWord, boolean condition, String joinSql,Object... args) {
|
||||
if (condition) {
|
||||
Children wrapper = instanceEmpty();
|
||||
wrapper.from.setStringValue(joinSql);
|
||||
wrapper.from.setStringValue(formatSqlMaybeWithParam(joinSql,args));
|
||||
wrapper.keyWord = keyWord;
|
||||
onWrappers.add(wrapper);
|
||||
}
|
||||
@ -453,7 +452,7 @@ public abstract class KtAbstractLambdaWrapper<T, Children extends KtAbstractLamb
|
||||
*/
|
||||
public boolean isUseAnnotationOrderBy() {
|
||||
final String _sqlSegment = this.getSqlSegment();
|
||||
if (StringUtils.isBlank(_sqlSegment)) {
|
||||
if (StrUtils.isBlank(_sqlSegment)) {
|
||||
return true;
|
||||
}
|
||||
final String _sqlSegmentToUpperCase = _sqlSegment.toUpperCase();
|
||||
|
@ -16,10 +16,7 @@ import com.github.yulichang.extension.kt.interfaces.CompareIfExists;
|
||||
import com.github.yulichang.extension.kt.interfaces.Func;
|
||||
import com.github.yulichang.extension.kt.interfaces.OnCompare;
|
||||
import com.github.yulichang.extension.kt.segments.FuncArgs;
|
||||
import com.github.yulichang.toolkit.KtUtils;
|
||||
import com.github.yulichang.toolkit.MPJSqlInjectionUtils;
|
||||
import com.github.yulichang.toolkit.Ref;
|
||||
import com.github.yulichang.toolkit.TableList;
|
||||
import com.github.yulichang.toolkit.*;
|
||||
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
||||
@ -34,6 +31,8 @@ import lombok.Getter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.baomidou.mybatisplus.core.enums.SqlKeyword.*;
|
||||
import static com.baomidou.mybatisplus.core.enums.WrapperKeyword.APPLY;
|
||||
@ -195,7 +194,7 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
public Children allEq(boolean condition, Map<KProperty<?>, ?> params, boolean null2IsNull) {
|
||||
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||
params.forEach((k, v) -> {
|
||||
if (StringUtils.checkValNotNull(v)) {
|
||||
if (StrUtils.checkValNotNull(v)) {
|
||||
eq(k, v);
|
||||
} else {
|
||||
if (null2IsNull) {
|
||||
@ -307,7 +306,7 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
@Override
|
||||
public Children apply(boolean condition, String applySql, Object... values) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(APPLY,
|
||||
() -> formatSqlMaybeWithParam(applySql, null, values)));
|
||||
() -> formatSqlMaybeWithParam(applySql, values)));
|
||||
}
|
||||
|
||||
public Children applyFunc(String applySql, Function<FuncArgs, SelectFunc.Arg[]> consumerFunction, Object... values) {
|
||||
@ -319,7 +318,8 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
return maybeDo(condition, () -> appendSqlSegments(APPLY,
|
||||
() -> formatSqlMaybeWithParam(String.format(applySql,
|
||||
Arrays.stream(consumerFunction.apply(new FuncArgs())).map(func ->
|
||||
columnToString(index, null, (KProperty<?>) func.getProperty(), false, PrefixEnum.CD_FIRST)).toArray()), null, values)));
|
||||
columnToString(index, null, (KProperty<?>) func.getProperty(),
|
||||
false, PrefixEnum.CD_FIRST)).toArray()), values)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -356,7 +356,7 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
@Override
|
||||
public Children exists(boolean condition, String existsSql, Object... values) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(EXISTS,
|
||||
() -> String.format("(%s)", formatSqlMaybeWithParam(existsSql, null, values))));
|
||||
() -> String.format("(%s)", formatSqlMaybeWithParam(existsSql, values))));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -495,7 +495,7 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
@Override
|
||||
public Children having(boolean condition, String sqlHaving, Object... params) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(HAVING,
|
||||
() -> formatSqlMaybeWithParam(sqlHaving, null, params)));
|
||||
() -> formatSqlMaybeWithParam(sqlHaving, params)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -594,21 +594,28 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
* <p>
|
||||
* 支持 "{0}" 这种,或者 "sql {0} sql" 这种
|
||||
*
|
||||
* @param sqlStr 可能是sql片段
|
||||
* @param mapping 例如: "javaType=int,jdbcType=NUMERIC,typeHandler=xxx.xxx.MyTypeHandler" 这种
|
||||
* @param params 参数
|
||||
* @param sqlStr 可能是sql片段
|
||||
* @param params 参数
|
||||
* @return sql片段
|
||||
*/
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
protected final String formatSqlMaybeWithParam(String sqlStr, String mapping, Object... params) {
|
||||
if (StringUtils.isBlank(sqlStr)) {
|
||||
// todo 何时会这样?
|
||||
protected final String formatSqlMaybeWithParam(String sqlStr, Object... params) {
|
||||
if (StrUtils.isBlank(sqlStr)) {
|
||||
return null;
|
||||
}
|
||||
if (ArrayUtils.isNotEmpty(params)) {
|
||||
for (int i = 0; i < params.length; ++i) {
|
||||
final String target = Constants.LEFT_BRACE + i + Constants.RIGHT_BRACE;
|
||||
sqlStr = sqlStr.replace(target, formatParam(mapping, params[i]));
|
||||
String target = Constants.LEFT_BRACE + i + Constants.RIGHT_BRACE;
|
||||
if (sqlStr.contains(target)) {
|
||||
sqlStr = sqlStr.replace(target, formatParam(null, params[i]));
|
||||
} else {
|
||||
Matcher matcher = Pattern.compile("[{]" + i + ",[a-zA-Z0-9.,=]+}").matcher(sqlStr);
|
||||
if (!matcher.find()) {
|
||||
throw ExceptionUtils.mpe("Please check the syntax correctness! sql not contains: \"%s\"", target);
|
||||
}
|
||||
String group = matcher.group();
|
||||
sqlStr = sqlStr.replace(group, formatParam(group.substring(target.length(), group.length() - 1), params[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return sqlStr;
|
||||
@ -703,7 +710,7 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
|
||||
@Override
|
||||
public String getSqlComment() {
|
||||
if (StringUtils.isNotBlank(sqlComment.getStringValue())) {
|
||||
if (StrUtils.isNotBlank(sqlComment.getStringValue())) {
|
||||
return "/*" + StringEscape.escapeRawString(sqlComment.getStringValue()) + "*/";
|
||||
}
|
||||
return null;
|
||||
@ -711,7 +718,7 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
|
||||
@Override
|
||||
public String getSqlFirst() {
|
||||
if (StringUtils.isNotBlank(sqlFirst.getStringValue())) {
|
||||
if (StrUtils.isNotBlank(sqlFirst.getStringValue())) {
|
||||
return StringEscape.escapeRawString(sqlFirst.getStringValue());
|
||||
}
|
||||
return null;
|
||||
@ -839,7 +846,7 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
public <V> Children allEqStr(boolean condition, Map<String, V> params, boolean null2IsNull) {
|
||||
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||
params.forEach((k, v) -> {
|
||||
if (StringUtils.checkValNotNull(v)) {
|
||||
if (StrUtils.checkValNotNull(v)) {
|
||||
eq(k, v);
|
||||
} else {
|
||||
if (null2IsNull) {
|
||||
@ -856,7 +863,7 @@ public abstract class KtAbstractWrapper<T, Children extends KtAbstractWrapper<T,
|
||||
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||
params.forEach((k, v) -> {
|
||||
if (filter.test(k, v)) {
|
||||
if (StringUtils.checkValNotNull(v)) {
|
||||
if (StrUtils.checkValNotNull(v)) {
|
||||
eq(k, v);
|
||||
} else {
|
||||
if (null2IsNull) {
|
||||
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.github.yulichang.adapter.AdapterHelper;
|
||||
import com.github.yulichang.toolkit.LogicInfoUtils;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.TableList;
|
||||
import com.github.yulichang.wrapper.interfaces.DeleteChain;
|
||||
@ -71,7 +72,7 @@ public class KtDeleteJoinWrapper<T> extends KtAbstractLambdaWrapper<T, KtDeleteJ
|
||||
*/
|
||||
@Override
|
||||
public String getDeleteSql() {
|
||||
if (StringUtils.isNotBlank(this.deleteSql.getStringValue())) {
|
||||
if (StrUtils.isNotBlank(this.deleteSql.getStringValue())) {
|
||||
return this.deleteSql.getStringValue();
|
||||
}
|
||||
String delete = null;
|
||||
@ -89,7 +90,7 @@ public class KtDeleteJoinWrapper<T> extends KtAbstractLambdaWrapper<T, KtDeleteJ
|
||||
if (CollectionUtils.isNotEmpty(deleteTableName)) {
|
||||
delete = delete + StringPool.COMMA + String.join(StringPool.COMMA, deleteTableName);
|
||||
}
|
||||
if (StringUtils.isBlank(delete)) {
|
||||
if (StrUtils.isBlank(delete)) {
|
||||
delete = this.alias;
|
||||
}
|
||||
deleteSql.setStringValue(delete);
|
||||
@ -101,7 +102,7 @@ public class KtDeleteJoinWrapper<T> extends KtAbstractLambdaWrapper<T, KtDeleteJ
|
||||
*/
|
||||
@Override
|
||||
public String getDeleteLogicSql() {
|
||||
if (StringUtils.isNotBlank(this.deleteSql.getStringValue())) {
|
||||
if (StrUtils.isNotBlank(this.deleteSql.getStringValue())) {
|
||||
return this.deleteSql.getStringValue();
|
||||
}
|
||||
String delete = null;
|
||||
@ -119,7 +120,7 @@ public class KtDeleteJoinWrapper<T> extends KtAbstractLambdaWrapper<T, KtDeleteJ
|
||||
if (CollectionUtils.isNotEmpty(deleteTableName)) {
|
||||
delete = delete + StringPool.COMMA + String.join(StringPool.COMMA, deleteTableName);
|
||||
}
|
||||
if (StringUtils.isNotBlank(delete)) {
|
||||
if (StrUtils.isNotBlank(delete)) {
|
||||
delete = StringPool.COMMA + delete;
|
||||
} else {
|
||||
delete = StringPool.EMPTY;
|
||||
|
@ -7,11 +7,16 @@ import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.extension.kt.interfaces.Query;
|
||||
import com.github.yulichang.extension.kt.interfaces.QueryLabel;
|
||||
import com.github.yulichang.extension.kt.segments.FuncArgs;
|
||||
import com.github.yulichang.extension.kt.toolkit.KtWrapperUtils;
|
||||
import com.github.yulichang.extension.kt.toolkit.KtWrappers;
|
||||
import com.github.yulichang.toolkit.*;
|
||||
import com.github.yulichang.toolkit.Constant;
|
||||
import com.github.yulichang.toolkit.KtUtils;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import com.github.yulichang.toolkit.TableList;
|
||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||
import com.github.yulichang.wrapper.interfaces.Chain;
|
||||
import com.github.yulichang.wrapper.interfaces.MFunction;
|
||||
import com.github.yulichang.wrapper.interfaces.SelectWrapper;
|
||||
import com.github.yulichang.wrapper.resultmap.Label;
|
||||
import com.github.yulichang.wrapper.segments.*;
|
||||
@ -204,11 +209,16 @@ public class KtLambdaWrapper<T> extends KtAbstractLambdaWrapper<T, KtLambdaWrapp
|
||||
return selectSub(clazz, ConfigProperties.subQueryAlias, consumer, alias);
|
||||
}
|
||||
|
||||
|
||||
public <E, F> KtLambdaWrapper<T> selectSub(Class<E> clazz, String st, Consumer<KtLambdaWrapper<?>> consumer, KProperty<?> alias) {
|
||||
return selectSub(clazz, st, consumer, alias.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 子查询
|
||||
*/
|
||||
public KtLambdaWrapper<T> selectSub(Class<?> clazz, String st,
|
||||
Consumer<KtLambdaWrapper<?>> consumer, KProperty<?> alias) {
|
||||
Consumer<KtLambdaWrapper<?>> consumer, String alias) {
|
||||
KtLambdaWrapper<?> wrapper = new KtLambdaWrapper(null, clazz, SharedString.emptyString(), paramNameSeq,
|
||||
paramNameValuePairs, new MergeSegments(), new SharedString(this.paramAlias.getStringValue()),
|
||||
SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(), new TableList(),
|
||||
@ -222,7 +232,21 @@ public class KtLambdaWrapper<T> extends KtAbstractLambdaWrapper<T, KtLambdaWrapp
|
||||
consumer.accept(wrapper);
|
||||
addCustomWrapper(wrapper);
|
||||
this.selectColumns.add(new SelectSub(() -> KtWrapperUtils.buildSubSqlByWrapper(
|
||||
clazz, wrapper, alias.getName()), hasAlias, this.alias, alias.getName()));
|
||||
clazz, wrapper, alias), hasAlias, this.alias, alias));
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KtLambdaWrapper<T> selectFunc(String sql, MFunction<FuncArgs> column, String alias) {
|
||||
FuncArgs apply = column.apply(new FuncArgs());
|
||||
String formatSql;
|
||||
if (ArrayUtils.isEmpty(apply.getValues())) {
|
||||
formatSql = sql;
|
||||
} else {
|
||||
formatSql = formatSqlMaybeWithParam(sql, apply.getValues());
|
||||
}
|
||||
getSelectColum().add(new SelectFunc(alias, getIndex(), () -> formatSql, apply.getFuncArg(),
|
||||
isHasAlias(), getAlias()));
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@ -340,7 +364,7 @@ public class KtLambdaWrapper<T> extends KtAbstractLambdaWrapper<T, KtLambdaWrapp
|
||||
*/
|
||||
@Override
|
||||
public String getSqlSelect() {
|
||||
if (StringUtils.isBlank(sqlSelect.getStringValue()) && CollectionUtils.isNotEmpty(selectColumns)) {
|
||||
if (StrUtils.isBlank(sqlSelect.getStringValue()) && CollectionUtils.isNotEmpty(selectColumns)) {
|
||||
String s = selectColumns.stream().map(i -> {
|
||||
if (i.isStr()) {
|
||||
return i.getColumn();
|
||||
|
@ -7,11 +7,8 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.github.yulichang.adapter.AdapterHelper;
|
||||
import com.github.yulichang.extension.kt.interfaces.Update;
|
||||
import com.github.yulichang.toolkit.Constant;
|
||||
import com.github.yulichang.toolkit.KtUtils;
|
||||
import com.github.yulichang.toolkit.*;
|
||||
import com.github.yulichang.toolkit.ReflectionKit;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.TableList;
|
||||
import com.github.yulichang.wrapper.interfaces.UpdateChain;
|
||||
import kotlin.reflect.KProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -142,7 +139,7 @@ public class KtUpdateJoinWrapper<T> extends KtAbstractLambdaWrapper<T, KtUpdateJ
|
||||
|
||||
@Override
|
||||
public KtUpdateJoinWrapper<T> setSql(boolean condition, String sql) {
|
||||
if (condition && StringUtils.isNotBlank(sql)) {
|
||||
if (condition && StrUtils.isNotBlank(sql)) {
|
||||
if (Objects.isNull(sqlSet)) {
|
||||
sqlSet = new ArrayList<>();
|
||||
}
|
||||
@ -153,7 +150,7 @@ public class KtUpdateJoinWrapper<T> extends KtAbstractLambdaWrapper<T, KtUpdateJ
|
||||
|
||||
@Override
|
||||
public String getSqlSet() {
|
||||
if (StringUtils.isNotBlank(sqlSetStr.getStringValue())) {
|
||||
if (StrUtils.isNotBlank(sqlSetStr.getStringValue())) {
|
||||
return sqlSetStr.getStringValue();
|
||||
}
|
||||
StringBuilder set = new StringBuilder(StringPool.EMPTY);
|
||||
|
@ -12,6 +12,7 @@ import com.github.yulichang.toolkit.support.ColumnCache;
|
||||
import com.github.yulichang.toolkit.support.FieldCache;
|
||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||
import com.github.yulichang.wrapper.enums.DefaultFuncEnum;
|
||||
import com.github.yulichang.wrapper.interfaces.MFunction;
|
||||
import com.github.yulichang.wrapper.segments.*;
|
||||
import kotlin.reflect.KProperty;
|
||||
|
||||
@ -19,7 +20,6 @@ import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -216,16 +216,10 @@ public interface Query<Children> extends Serializable {
|
||||
}
|
||||
|
||||
|
||||
default Children selectFunc(String sql, Function<FuncArgs, SelectFunc.Arg[]> column, String alias) {
|
||||
getSelectColum().add(new SelectFunc(alias, getIndex(), () -> sql, column.apply(new FuncArgs()),
|
||||
isHasAlias(), getAlias()));
|
||||
return getChildren();
|
||||
}
|
||||
Children selectFunc(String sql, MFunction<FuncArgs> column, String alias);
|
||||
|
||||
default Children selectFunc(String sql, Function<FuncArgs, SelectFunc.Arg[]> column, KProperty<?> alias) {
|
||||
getSelectColum().add(new SelectFunc(alias.getName(), getIndex(), () -> sql,
|
||||
column.apply(new FuncArgs()), isHasAlias(), getAlias()));
|
||||
return getChildren();
|
||||
default Children selectFunc(String sql, MFunction<FuncArgs> column, KProperty<?> alias) {
|
||||
return selectFunc(sql, column, alias.getName());
|
||||
}
|
||||
|
||||
/* 默认聚合函数扩展 */
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.github.yulichang.extension.kt.interfaces;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.extension.kt.resultmap.MybatisLabel;
|
||||
import com.github.yulichang.extension.kt.resultmap.MybatisLabelFree;
|
||||
import com.github.yulichang.toolkit.KtUtils;
|
||||
import com.github.yulichang.toolkit.MPJReflectionKit;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import com.github.yulichang.toolkit.support.FieldCache;
|
||||
import com.github.yulichang.wrapper.interfaces.MFunction;
|
||||
import com.github.yulichang.wrapper.resultmap.Label;
|
||||
@ -137,7 +137,7 @@ public interface QueryLabel<Children> {
|
||||
FieldCache field = fieldMap.get(dtoFieldName);
|
||||
Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类");
|
||||
MybatisLabel.Builder<?, ?> builder;
|
||||
builder = new MybatisLabel.Builder<>(StringUtils.isBlank(prefix) ? null : prefix,
|
||||
builder = new MybatisLabel.Builder<>(StrUtils.isBlank(prefix) ? null : prefix,
|
||||
dtoFieldName, child, field.getType(), (Class<?>) field.getType(), true);
|
||||
addLabel(builder.build(), false);
|
||||
return getChildren();
|
||||
@ -169,7 +169,7 @@ public interface QueryLabel<Children> {
|
||||
String dtoFieldName = dtoField.getName();
|
||||
FieldCache field = MPJReflectionKit.getFieldMap(KtUtils.ref(dtoField)).get(dtoFieldName);
|
||||
Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类");
|
||||
MybatisLabel.Builder<?, ?> builder = new MybatisLabel.Builder<>(StringUtils.isBlank(prefix) ? null : prefix,
|
||||
MybatisLabel.Builder<?, ?> builder = new MybatisLabel.Builder<>(StrUtils.isBlank(prefix) ? null : prefix,
|
||||
dtoFieldName, child, field.getType(), (Class<?>) field.getType(), false);
|
||||
MybatisLabel.Builder<?, ?> cfBuilder = collection.apply(builder);
|
||||
addLabel(cfBuilder.build(), false);
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.github.yulichang.extension.kt.resultmap;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.toolkit.KtUtils;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||
import com.github.yulichang.wrapper.resultmap.IResult;
|
||||
import com.github.yulichang.wrapper.segments.SelectCache;
|
||||
@ -71,7 +71,7 @@ public class Result implements IResult {
|
||||
String name = column.getName();
|
||||
SelectCache normal = normalMap.get(name);
|
||||
result.selectNormal = normal;
|
||||
if (StringUtils.isBlank(result.property)) {
|
||||
if (StrUtils.isBlank(result.property)) {
|
||||
result.property = normal.getColumProperty();
|
||||
}
|
||||
if (Objects.isNull(result.javaType)) {
|
||||
|
@ -3,6 +3,7 @@ package com.github.yulichang.extension.kt.segments;
|
||||
import com.github.yulichang.toolkit.KtUtils;
|
||||
import com.github.yulichang.wrapper.segments.SelectFunc;
|
||||
import kotlin.reflect.KProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -12,12 +13,27 @@ import java.util.Arrays;
|
||||
* @author yulichang
|
||||
* @since 1.4.6
|
||||
*/
|
||||
@Data
|
||||
@SuppressWarnings("unused")
|
||||
public class FuncArgs {
|
||||
|
||||
public SelectFunc.Arg[] accept(KProperty<?>... kProperty) {
|
||||
return Arrays.stream(kProperty).map(i ->
|
||||
new SelectFunc.Arg(KtUtils.ref(i), i.getName(), false, null, i))
|
||||
private KProperty<?>[] args;
|
||||
|
||||
private Object[] values;
|
||||
|
||||
public FuncArgs accept(KProperty<?>... kProperty) {
|
||||
this.args = kProperty;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FuncArgs values(Object... values) {
|
||||
this.values = values;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SelectFunc.Arg[] getFuncArg() {
|
||||
return Arrays.stream(args).map(i ->
|
||||
new SelectFunc.Arg(KtUtils.ref(i), i.getName(), false, null, i,false,null))
|
||||
.toArray(SelectFunc.Arg[]::new);
|
||||
}
|
||||
|
||||
|
@ -4,10 +4,10 @@ import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.adapter.AdapterHelper;
|
||||
import com.github.yulichang.extension.kt.KtLambdaWrapper;
|
||||
import com.github.yulichang.toolkit.LogicInfoUtils;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
||||
|
||||
@ -26,18 +26,18 @@ public class KtWrapperUtils {
|
||||
String first = Optional.ofNullable(wrapper.getSqlFirst()).orElse(StringPool.EMPTY);
|
||||
boolean hasWhere = false;
|
||||
String entityWhere = getEntitySql(tableInfo, wrapper);
|
||||
if (StringUtils.isNotBlank(entityWhere)) {
|
||||
if (StrUtils.isNotBlank(entityWhere)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String mainLogic = mainLogic(hasWhere, clazz, wrapper);
|
||||
if (StringUtils.isNotBlank(mainLogic)) {
|
||||
if (StrUtils.isNotBlank(mainLogic)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String subLogic = subLogic(hasWhere, wrapper);
|
||||
if (StringUtils.isNotBlank(subLogic)) {
|
||||
if (StrUtils.isNotBlank(subLogic)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String sqlSegment = (wrapper.getSqlSegment() != null && StringUtils.isNotBlank(wrapper.getSqlSegment())) ?
|
||||
String sqlSegment = (wrapper.getSqlSegment() != null && StrUtils.isNotBlank(wrapper.getSqlSegment())) ?
|
||||
((wrapper.isEmptyOfNormal() ? StringPool.EMPTY : (hasWhere ? " AND " : " WHERE ")) + wrapper.getSqlSegment()) : StringPool.EMPTY;
|
||||
|
||||
String sqlComment = Optional.ofNullable(wrapper.getSqlComment()).orElse(StringPool.EMPTY);
|
||||
@ -59,18 +59,18 @@ public class KtWrapperUtils {
|
||||
String first = Optional.ofNullable(wrapper.getSqlFirst()).orElse(StringPool.EMPTY);
|
||||
boolean hasWhere = false;
|
||||
String entityWhere = getEntitySql(tableInfo, wrapper);
|
||||
if (StringUtils.isNotBlank(entityWhere)) {
|
||||
if (StrUtils.isNotBlank(entityWhere)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String mainLogic = mainLogic(hasWhere, clazz, wrapper);
|
||||
if (StringUtils.isNotBlank(mainLogic)) {
|
||||
if (StrUtils.isNotBlank(mainLogic)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String subLogic = subLogic(hasWhere, wrapper);
|
||||
if (StringUtils.isNotBlank(subLogic)) {
|
||||
if (StrUtils.isNotBlank(subLogic)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String sqlSegment = (wrapper.getSqlSegment() != null && StringUtils.isNotBlank(wrapper.getSqlSegment())) ?
|
||||
String sqlSegment = (wrapper.getSqlSegment() != null && StrUtils.isNotBlank(wrapper.getSqlSegment())) ?
|
||||
((wrapper.isEmptyOfNormal() ? StringPool.EMPTY : (hasWhere ? " AND " : " WHERE ")) + wrapper.getSqlSegment()) : StringPool.EMPTY;
|
||||
|
||||
String sqlComment = Optional.ofNullable(wrapper.getSqlComment()).orElse(StringPool.EMPTY);
|
||||
@ -128,7 +128,7 @@ public class KtWrapperUtils {
|
||||
return StringPool.EMPTY;
|
||||
}
|
||||
String info = LogicInfoUtils.getLogicInfo(null, clazz, true, wrapper.getAlias());
|
||||
if (StringUtils.isNotBlank(info)) {
|
||||
if (StrUtils.isNotBlank(info)) {
|
||||
if (hasWhere) {
|
||||
return " AND " + info;
|
||||
}
|
||||
@ -139,7 +139,7 @@ public class KtWrapperUtils {
|
||||
|
||||
private static String subLogic(boolean hasWhere, KtLambdaWrapper<?> wrapper) {
|
||||
String sql = wrapper.getSubLogicSql();
|
||||
if (StringUtils.isNotBlank(sql)) {
|
||||
if (StrUtils.isNotBlank(sql)) {
|
||||
if (hasWhere) {
|
||||
return sql;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.yulichang.injector;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
||||
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
|
||||
import com.baomidou.mybatisplus.core.injector.AbstractSqlInjector;
|
||||
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
||||
@ -9,14 +8,13 @@ import com.baomidou.mybatisplus.core.injector.methods.*;
|
||||
import com.baomidou.mybatisplus.core.mapper.Mapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
||||
import com.github.yulichang.adapter.v3431.AbstractMethodV3431;
|
||||
import com.github.yulichang.method.*;
|
||||
import com.github.yulichang.toolkit.MPJTableMapperHelper;
|
||||
import com.github.yulichang.toolkit.ReflectionKit;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.reflect.GenericTypeUtils;
|
||||
import lombok.Getter;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
@ -60,7 +58,7 @@ public class MPJSqlInjector extends DefaultSqlInjector {
|
||||
@Deprecated
|
||||
@SuppressWarnings({"unused", "DeprecatedIsStillUsed"})
|
||||
public List<AbstractMethod> getMethodList(Class<?> mapperClass) {
|
||||
if (VersionUtils.compare(MybatisPlusVersion.getVersion(), "3.4.3.2") >= 0) {
|
||||
if (VersionUtils.compare(VersionUtils.getVersion(), "3.4.3.2") >= 0) {
|
||||
throw ExceptionUtils.mpe("DefaultSqlInjector 的 getMethodList(Class<?> mapperClass) 方法已在 3.4.3.2+ 改为" +
|
||||
"getMethodList(Class<?> mapperClass, TableInfo tableInfo)\n");
|
||||
}
|
||||
@ -129,7 +127,7 @@ public class MPJSqlInjector extends DefaultSqlInjector {
|
||||
|
||||
private List<AbstractMethod> getJoinMethod() {
|
||||
List<AbstractMethod> list = new ArrayList<>();
|
||||
if (VersionUtils.compare(MybatisPlusVersion.getVersion(), "3.5.0") >= 0) {
|
||||
if (VersionUtils.compare(VersionUtils.getVersion(), "3.5.0") >= 0) {
|
||||
list.add(new DeleteJoin(SqlMethod.DELETE_JOIN.getMethod()));
|
||||
list.add(new UpdateJoin(SqlMethod.UPDATE_JOIN.getMethod()));
|
||||
list.add(new UpdateJoinAndNull(SqlMethod.UPDATE_JOIN_AND_NULL.getMethod()));
|
||||
@ -137,9 +135,6 @@ public class MPJSqlInjector extends DefaultSqlInjector {
|
||||
list.add(new SelectJoinOne(SqlMethod.SELECT_JOIN_ONE.getMethod()));
|
||||
list.add(new SelectJoinList(SqlMethod.SELECT_JOIN_LIST.getMethod()));
|
||||
list.add(new SelectJoinPage(SqlMethod.SELECT_JOIN_PAGE.getMethod()));
|
||||
list.add(new SelectJoinMap(SqlMethod.SELECT_JOIN_MAP.getMethod()));
|
||||
list.add(new SelectJoinMaps(SqlMethod.SELECT_JOIN_MAPS.getMethod()));
|
||||
list.add(new SelectJoinMapsPage(SqlMethod.SELECT_JOIN_MAPS_PAGE.getMethod()));
|
||||
} else {
|
||||
list.add(new DeleteJoin());
|
||||
list.add(new UpdateJoin());
|
||||
@ -148,9 +143,6 @@ public class MPJSqlInjector extends DefaultSqlInjector {
|
||||
list.add(new SelectJoinOne());
|
||||
list.add(new SelectJoinList());
|
||||
list.add(new SelectJoinPage());
|
||||
list.add(new SelectJoinMap());
|
||||
list.add(new SelectJoinMaps());
|
||||
list.add(new SelectJoinMapsPage());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@ -179,7 +171,7 @@ public class MPJSqlInjector extends DefaultSqlInjector {
|
||||
|
||||
@Override
|
||||
public void inspectInject(MapperBuilderAssistant builderAssistant, Class<?> mapperClass) {
|
||||
Class<?> modelClass = getSuperClassGenericType(mapperClass, Mapper.class, 0);
|
||||
Class<?> modelClass = ReflectionKit.getSuperClassGenericType(mapperClass, Mapper.class, 0);
|
||||
super.inspectInject(builderAssistant, mapperClass);
|
||||
MPJTableMapperHelper.init(modelClass, mapperClass);
|
||||
Supplier<Class<?>> supplier = () -> {
|
||||
@ -192,11 +184,6 @@ public class MPJSqlInjector extends DefaultSqlInjector {
|
||||
TableHelper.init(modelClass, supplier.get());
|
||||
}
|
||||
|
||||
public static Class<?> getSuperClassGenericType(final Class<?> clazz, final Class<?> genericIfc, final int index) {
|
||||
Class<?>[] typeArguments = GenericTypeUtils.resolveTypeArguments(ClassUtils.getUserClass(clazz), genericIfc);
|
||||
return null == typeArguments ? null : typeArguments[index];
|
||||
}
|
||||
|
||||
@SuppressWarnings("IfStatementWithIdenticalBranches")
|
||||
protected Class<?> extractModelClassOld(Class<?> mapperClass) {
|
||||
Type[] types = mapperClass.getGenericInterfaces();
|
||||
|
@ -1,12 +1,10 @@
|
||||
package com.github.yulichang.interceptor;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.adapter.AdapterHelper;
|
||||
import com.github.yulichang.adapter.base.tookit.VersionUtils;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
@ -46,7 +44,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
@Intercepts(@Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}))
|
||||
public class MPJInterceptor implements Interceptor {
|
||||
|
||||
private static final boolean v = VersionUtils.compare(MybatisPlusVersion.getVersion(), "3.4.3.1") > 0;
|
||||
private static final boolean v = VersionUtils.compare(VersionUtils.getVersion(), "3.4.3.1") > 0;
|
||||
|
||||
private static final List<ResultMapping> EMPTY_RESULT_MAPPING = new ArrayList<>(0);
|
||||
|
||||
@ -57,35 +55,34 @@ public class MPJInterceptor implements Interceptor {
|
||||
|
||||
@Override
|
||||
public Object intercept(Invocation invocation) throws Throwable {
|
||||
Object ew = null;
|
||||
Object[] args = invocation.getArgs();
|
||||
if (args[0] instanceof MappedStatement) {
|
||||
MappedStatement ms = (MappedStatement) args[0];
|
||||
if (args[1] instanceof Map) {
|
||||
Map<String, Object> map = (Map<String, Object>) args[1];
|
||||
Object ew = map.getOrDefault(Constants.WRAPPER, null);
|
||||
ew = map.getOrDefault(Constants.WRAPPER, null);
|
||||
if (Objects.nonNull(ew) && ew instanceof MPJBaseJoin) {
|
||||
if (CollectionUtils.isNotEmpty(map)) {
|
||||
Class<?> rt = null;
|
||||
if (map.containsKey(Constant.CLAZZ)) {
|
||||
rt = (Class<?>) map.get(Constant.CLAZZ);
|
||||
} else {
|
||||
if (CollectionUtils.isNotEmpty(ms.getResultMaps())) {
|
||||
Class<?> entity = MPJTableMapperHelper.getEntity(getMapper(ms.getId(), ms.getResource()));
|
||||
Class<?> type = ms.getResultMaps().get(0).getType();
|
||||
if (Objects.nonNull(entity) && Objects.nonNull(type)
|
||||
&& !MPJReflectionKit.isPrimitiveOrWrapper(type) && entity == type) {
|
||||
rt = type;
|
||||
}
|
||||
Class<?> rt = null;
|
||||
if (map.containsKey(Constant.CLAZZ) && map.get(Constant.CLAZZ) != null) {
|
||||
rt = (Class<?>) map.get(Constant.CLAZZ);
|
||||
} else {
|
||||
if (CollectionUtils.isNotEmpty(ms.getResultMaps())) {
|
||||
Class<?> entity = MPJTableMapperHelper.getEntity(getMapper(ms.getId(), ms.getResource()));
|
||||
Class<?> type = ms.getResultMaps().get(0).getType();
|
||||
if (Objects.nonNull(entity) && Objects.nonNull(type)
|
||||
&& !MPJReflectionKit.isPrimitiveOrWrapper(type) && (entity == type)) {
|
||||
rt = type;
|
||||
}
|
||||
}
|
||||
if (Objects.nonNull(rt)) {
|
||||
args[0] = getMappedStatement(ms, rt, ew, map);
|
||||
}
|
||||
}
|
||||
if (Objects.nonNull(rt)) {
|
||||
args[0] = getMappedStatement(ms, rt, ew, map);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return invocation.proceed();
|
||||
return fill(ew, invocation.proceed());
|
||||
}
|
||||
|
||||
|
||||
@ -169,7 +166,7 @@ public class MPJInterceptor implements Interceptor {
|
||||
}
|
||||
} else {
|
||||
FieldCache field = fieldMap.get(i.getColumProperty());
|
||||
if (StringUtils.isNotBlank(i.getTagColumn())) {
|
||||
if (StrUtils.isNotBlank(i.getTagColumn())) {
|
||||
columnSet.add(i.getTagColumn());
|
||||
if (Objects.nonNull(field)) {
|
||||
ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), i.getColumProperty(),
|
||||
@ -178,7 +175,7 @@ public class MPJInterceptor implements Interceptor {
|
||||
}
|
||||
} else if (wrapper.isResultMap()) {
|
||||
AdapterHelper.getAdapter().parserColum(wrapper.getAlias(), wrapper.getFrom(), i.getColumn(), col -> {
|
||||
String tagCol = MPJStringUtils.getTargetColumn(col);
|
||||
String tagCol = StrUtils.getTargetColumn(col);
|
||||
FieldCache strField = fieldMap.get(tagCol);
|
||||
columnSet.add(tagCol);
|
||||
if (Objects.nonNull(strField)) {
|
||||
@ -242,10 +239,10 @@ public class MPJInterceptor implements Interceptor {
|
||||
String index = r.getIndex();
|
||||
if (columnSet.contains(columnName)) {
|
||||
columnName = getColumn(columnSet, columnName, 0);
|
||||
label = new SelectLabel(r.getSelectNormal(), null, mybatisLabel.getOfType(), columnName, StringUtils.isNotBlank(index), index, r.getBaseColumn());
|
||||
label = new SelectLabel(r.getSelectNormal(), null, mybatisLabel.getOfType(), columnName, StrUtils.isNotBlank(index), index, r.getBaseColumn());
|
||||
} else {
|
||||
columnSet.add(columnName);
|
||||
label = new SelectLabel(r.getSelectNormal(), null, mybatisLabel.getOfType(), StringUtils.isNotBlank(index), index, r.getBaseColumn());
|
||||
label = new SelectLabel(r.getSelectNormal(), null, mybatisLabel.getOfType(), StrUtils.isNotBlank(index), index, r.getBaseColumn());
|
||||
}
|
||||
columnList.add(label);
|
||||
ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), r.getProperty(), columnName, r.getJavaType());
|
||||
@ -362,6 +359,24 @@ public class MPJInterceptor implements Interceptor {
|
||||
}
|
||||
}
|
||||
|
||||
private Object fill(Object ew, Object proceed) {
|
||||
if (Objects.isNull(ew) || !(ew instanceof SelectWrapper<?, ?>) || MPJReflectionKit.isPrimitiveOrWrapper(proceed.getClass())) {
|
||||
return proceed;
|
||||
}
|
||||
if (proceed instanceof List) {
|
||||
List<?> list = (List<?>) proceed;
|
||||
if (!list.isEmpty()) {
|
||||
Object o = list.stream().filter(Objects::nonNull).findFirst().orElse(null);
|
||||
if (o == null || MPJReflectionKit.isPrimitiveOrWrapper(o.getClass())) {
|
||||
return proceed;
|
||||
}
|
||||
}
|
||||
}
|
||||
SelectWrapper<?, ?> selectWrapper = (SelectWrapper<?, ?>) ew;
|
||||
selectWrapper.doFill(proceed);
|
||||
return proceed;
|
||||
}
|
||||
|
||||
private Class<?> getMapper(String id, String resource) {
|
||||
Class<?> clazz = MS_MAPPER_CACHE.computeIfAbsent(id, key -> {
|
||||
try {
|
||||
|
@ -94,7 +94,7 @@ public class PageInnerInterceptorWrapper extends PaginationInnerInterceptor {
|
||||
* 添加分页方言
|
||||
*/
|
||||
@Override
|
||||
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
|
||||
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
|
||||
if (unusedPage(parameter)) {
|
||||
paginationInnerInterceptor.beforeQuery(executor, ms, parameter, rowBounds, resultHandler, boundSql);
|
||||
return;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.github.yulichang.interceptor.pagination;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.github.yulichang.toolkit.ReflectionKit;
|
||||
import com.github.yulichang.toolkit.MPJReflectionKit;
|
||||
import org.apache.ibatis.mapping.ParameterMapping;
|
||||
import org.apache.ibatis.mapping.SqlSource;
|
||||
import org.apache.ibatis.scripting.xmltags.DynamicSqlSource;
|
||||
@ -102,8 +102,8 @@ public final class ParseHelper {
|
||||
public static String getOriginalSql(Object parameter, DynamicSqlSource sqlSource) {
|
||||
Assert.notNull(sqlSource, "sqlSource must not be null");
|
||||
SqlSourceWrapper sqlSourceWrapper = SQL_SOURCE_CACHE.computeIfAbsent(sqlSource, key -> {
|
||||
Configuration configuration = ReflectionKit.getFieldValue(sqlSource, "configuration");
|
||||
SqlNode sqlNode = ReflectionKit.getFieldValue(sqlSource, "rootSqlNode");
|
||||
Configuration configuration = MPJReflectionKit.getFieldValue(sqlSource, "configuration");
|
||||
SqlNode sqlNode = MPJReflectionKit.getFieldValue(sqlSource, "rootSqlNode");
|
||||
return new SqlSourceWrapper(configuration, sqlNode);
|
||||
});
|
||||
return ParseHelper.decode(sqlSourceWrapper.getSql(parameter), null, ParseHelper.format.apply(""));
|
||||
|
@ -6,18 +6,18 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.adapter.AdapterHelper;
|
||||
import com.github.yulichang.adapter.base.metadata.OrderFieldInfo;
|
||||
import com.github.yulichang.annotation.DynamicTableName;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
@ -103,7 +103,7 @@ public interface MPJBaseMethod extends Constants {
|
||||
return true;
|
||||
})
|
||||
.map(i -> getSqlWhere(i, newPrefix)).filter(Objects::nonNull).collect(joining(NEWLINE));
|
||||
if (!withId || StringUtils.isBlank(tableInfo.getKeyProperty())) {
|
||||
if (!withId || StrUtils.isBlank(tableInfo.getKeyProperty())) {
|
||||
return filedSqlScript;
|
||||
}
|
||||
String newKeyProperty = newPrefix + tableInfo.getKeyProperty();
|
||||
@ -123,11 +123,15 @@ public interface MPJBaseMethod extends Constants {
|
||||
tableFieldInfo.getWhereStrategy());
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
default String convertIf(TableFieldInfo tableFieldInfo, final String sqlScript, final String property, final FieldStrategy fieldStrategy) {
|
||||
if (fieldStrategy == FieldStrategy.NEVER) {
|
||||
return null;
|
||||
}
|
||||
if (AdapterHelper.getAdapter().mpjIsPrimitive(tableFieldInfo) || fieldStrategy == FieldStrategy.IGNORED) {
|
||||
FieldStrategy strategy = Optional.ofNullable(fieldStrategy).orElse(FieldStrategy.DEFAULT);
|
||||
if (AdapterHelper.getAdapter().mpjIsPrimitive(tableFieldInfo)
|
||||
|| strategy.name().equalsIgnoreCase("ALWAYS")
|
||||
|| strategy.name().equalsIgnoreCase("IGNORED")) {
|
||||
return sqlScript;
|
||||
}
|
||||
if (fieldStrategy == FieldStrategy.NOT_EMPTY && tableFieldInfo.isCharSequence()) {
|
||||
@ -138,7 +142,7 @@ public interface MPJBaseMethod extends Constants {
|
||||
}
|
||||
|
||||
default String convertIfProperty(String prefix, String property) {
|
||||
return StringUtils.isNotBlank(prefix) ? prefix.substring(0, prefix.length() - 1) + "['" + property + "']" : property;
|
||||
return StrUtils.isNotBlank(prefix) ? prefix.substring(0, prefix.length() - 1) + "['" + property + "']" : property;
|
||||
}
|
||||
|
||||
|
||||
@ -183,10 +187,6 @@ public interface MPJBaseMethod extends Constants {
|
||||
* 获取表名
|
||||
*/
|
||||
default String mpjTableName(TableInfo tableInfo) {
|
||||
DynamicTableName dynamicTableName = tableInfo.getEntityType().getAnnotation(DynamicTableName.class);
|
||||
if (Objects.isNull(dynamicTableName)) {
|
||||
return tableInfo.getTableName();
|
||||
}
|
||||
String tableName = tableInfo.getTableName(), encode;
|
||||
try {
|
||||
encode = URLEncoder.encode(tableName, "UTF-8");
|
||||
@ -253,7 +253,7 @@ public interface MPJBaseMethod extends Constants {
|
||||
final String newPrefix = prefix == null ? EMPTY : prefix;
|
||||
// 默认: column=
|
||||
String sqlSet = "${ew.alias}." + tableFieldInfo.getColumn() + EQUALS;
|
||||
if (StringUtils.isNotBlank(tableFieldInfo.getUpdate())) {
|
||||
if (StrUtils.isNotBlank(tableFieldInfo.getUpdate())) {
|
||||
sqlSet += String.format(tableFieldInfo.getUpdate(), tableFieldInfo.getColumn());
|
||||
} else {
|
||||
sqlSet += SqlScriptUtils.safeParam(newPrefix + tableFieldInfo.getEl());
|
||||
@ -262,7 +262,7 @@ public interface MPJBaseMethod extends Constants {
|
||||
if (ignoreIf) {
|
||||
return sqlSet;
|
||||
}
|
||||
if (tableFieldInfo.isWithUpdateFill()) {
|
||||
if (AdapterHelper.getAdapter().isWithUpdateFill(tableFieldInfo)) {
|
||||
// 不进行 if 包裹
|
||||
return sqlSet;
|
||||
}
|
||||
@ -270,7 +270,7 @@ public interface MPJBaseMethod extends Constants {
|
||||
}
|
||||
|
||||
default String mpjConvertIfProperty(String prefix, String property) {
|
||||
return StringUtils.isNotBlank(prefix) ? prefix.substring(0, prefix.length() - 1) + "['" + property + "']" : property;
|
||||
return StrUtils.isNotBlank(prefix) ? prefix.substring(0, prefix.length() - 1) + "['" + property + "']" : property;
|
||||
}
|
||||
|
||||
default String mpjConvertIf(TableFieldInfo tableFieldInfo, final String sqlScript, final String property, final FieldStrategy fieldStrategy) {
|
||||
|
@ -1,11 +0,0 @@
|
||||
package com.github.yulichang.method;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* result type 标识类
|
||||
*
|
||||
* @author yulichang
|
||||
*/
|
||||
public class MPJResultType implements Serializable {
|
||||
}
|
@ -32,7 +32,7 @@ public class SelectJoinList extends MPJAbstractMethod {
|
||||
String sql = String.format(sqlMethod.getSql(), sqlFirst(), sqlDistinct(), sqlSelectColumns(tableInfo, true),
|
||||
mpjTableName(tableInfo), sqlAlias(), sqlFrom(), sqlWhereEntityWrapper(true, tableInfo), mpjSqlOrderBy(tableInfo), sqlComment());
|
||||
SqlSource sqlSource = languageDriver.createSqlSource(configuration, removeExtraWhitespaces(sql), modelClass);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, MPJResultType.class);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, tableInfo.getEntityType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,44 +0,0 @@
|
||||
package com.github.yulichang.method;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.mapping.SqlSource;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* copy {@link com.baomidou.mybatisplus.core.injector.methods.SelectMaps}
|
||||
*
|
||||
* @author yulichang
|
||||
*/
|
||||
public class SelectJoinMap extends MPJAbstractMethod {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public SelectJoinMap() {
|
||||
super();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public SelectJoinMap(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
||||
SqlMethod sqlMethod = SqlMethod.SELECT_JOIN_MAP;
|
||||
String sql = String.format(sqlMethod.getSql(), sqlFirst(), sqlDistinct(), sqlSelectColumns(tableInfo, true),
|
||||
mpjTableName(tableInfo), sqlAlias(), sqlFrom(), sqlWhereEntityWrapper(true, tableInfo), sqlComment());
|
||||
SqlSource sqlSource = languageDriver.createSqlSource(configuration, removeExtraWhitespaces(sql), modelClass);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, Map.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String sqlComment() {
|
||||
return super.sqlComment() + StringPool.NEWLINE + SqlScriptUtils.convertIf("${ew.unionSql}", String.format("%s != null and (%s instanceof %s)",
|
||||
Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), true);
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.github.yulichang.method;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.mapping.SqlSource;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* copy {@link com.baomidou.mybatisplus.core.injector.methods.SelectMaps}
|
||||
*
|
||||
* @author yulichang
|
||||
*/
|
||||
public class SelectJoinMaps extends MPJAbstractMethod {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public SelectJoinMaps() {
|
||||
super();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public SelectJoinMaps(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
||||
SqlMethod sqlMethod = SqlMethod.SELECT_JOIN_MAPS;
|
||||
String sql = String.format(sqlMethod.getSql(), sqlFirst(), sqlDistinct(), sqlSelectColumns(tableInfo, true),
|
||||
mpjTableName(tableInfo), sqlAlias(), sqlFrom(), sqlWhereEntityWrapper(true, tableInfo), mpjSqlOrderBy(tableInfo), sqlComment());
|
||||
SqlSource sqlSource = languageDriver.createSqlSource(configuration, removeExtraWhitespaces(sql), modelClass);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, Map.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String sqlComment() {
|
||||
return super.sqlComment() + StringPool.NEWLINE + SqlScriptUtils.convertIf("${ew.unionSql}", String.format("%s != null and (%s instanceof %s)",
|
||||
Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), true);
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.github.yulichang.method;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.mapping.SqlSource;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* copy {@link com.baomidou.mybatisplus.core.injector.methods.SelectMaps}
|
||||
*
|
||||
* @author yulichang
|
||||
*/
|
||||
public class SelectJoinMapsPage extends MPJAbstractMethod {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public SelectJoinMapsPage() {
|
||||
super();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public SelectJoinMapsPage(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
|
||||
SqlMethod sqlMethod = SqlMethod.SELECT_JOIN_MAPS_PAGE;
|
||||
String sql = String.format(sqlMethod.getSql(), sqlFirst(), sqlDistinct(), sqlSelectColumns(tableInfo, true),
|
||||
mpjTableName(tableInfo), sqlAlias(), sqlFrom(), sqlWhereEntityWrapper(true, tableInfo), mpjSqlOrderBy(tableInfo), sqlComment());
|
||||
SqlSource sqlSource = languageDriver.createSqlSource(configuration, removeExtraWhitespaces(sql), modelClass);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, Map.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String sqlComment() {
|
||||
return super.sqlComment() + StringPool.NEWLINE + SqlScriptUtils.convertIf("${ew.unionSql}", String.format("%s != null and (%s instanceof %s)",
|
||||
Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()), true);
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ public class SelectJoinOne extends MPJAbstractMethod {
|
||||
String sql = String.format(sqlMethod.getSql(), sqlFirst(), sqlDistinct(), sqlSelectColumns(tableInfo, true),
|
||||
mpjTableName(tableInfo), sqlAlias(), sqlFrom(), sqlWhereEntityWrapper(true, tableInfo), sqlComment());
|
||||
SqlSource sqlSource = languageDriver.createSqlSource(configuration, removeExtraWhitespaces(sql), modelClass);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, MPJResultType.class);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, tableInfo.getEntityType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +32,7 @@ public class SelectJoinPage extends MPJAbstractMethod {
|
||||
String sql = String.format(sqlMethod.getSql(), sqlFirst(), sqlDistinct(), sqlSelectColumns(tableInfo, true),
|
||||
mpjTableName(tableInfo), sqlAlias(), sqlFrom(), sqlWhereEntityWrapper(true, tableInfo), mpjSqlOrderBy(tableInfo), sqlComment());
|
||||
SqlSource sqlSource = languageDriver.createSqlSource(configuration, removeExtraWhitespaces(sql), modelClass);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, MPJResultType.class);
|
||||
return this.addSelectMappedStatementForOther(mapperClass, sqlMethod.getMethod(), sqlSource, tableInfo.getEntityType());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.github.yulichang.method;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@ -9,6 +11,7 @@ import java.util.stream.Collectors;
|
||||
* @see com.baomidou.mybatisplus.core.enums.SqlMethod
|
||||
* @since 2021/1/15
|
||||
*/
|
||||
@Getter
|
||||
public enum SqlMethod {
|
||||
/**
|
||||
* 连表查询
|
||||
@ -22,18 +25,9 @@ public enum SqlMethod {
|
||||
SELECT_JOIN_LIST("selectJoinList", "返回List集合",
|
||||
"<script>\n%s SELECT %s %s FROM %s %s %s %s %s %s\n</script>"),
|
||||
|
||||
SELECT_JOIN_MAP("selectJoinMap", "返回一个Map",
|
||||
"<script>\n%s SELECT %s %s FROM %s %s %s %s %s\n</script>"),
|
||||
|
||||
SELECT_JOIN_MAPS("selectJoinMaps", "返回Map集合",
|
||||
"<script>\n%s SELECT %s %s FROM %s %s %s %s %s %s\n</script>"),
|
||||
|
||||
SELECT_JOIN_PAGE("selectJoinPage", "连表查询并分页",
|
||||
"<script>\n%s SELECT %s %s FROM %s %s %s %s %s %s\n</script>"),
|
||||
|
||||
SELECT_JOIN_MAPS_PAGE("selectJoinMapsPage", "返回Map集合并分页",
|
||||
"<script>\n%s SELECT %s %s FROM %s %s %s %s %s %s\n</script>"),
|
||||
|
||||
/**
|
||||
* 连表删除
|
||||
*/
|
||||
@ -64,15 +58,6 @@ public enum SqlMethod {
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
|
||||
public static final List<String> collect = Arrays.stream(SqlMethod.values()).map(SqlMethod::getMethod).collect(Collectors.toList());
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import com.github.yulichang.adapter.AdapterHelper;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.mapping.SqlSource;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* copy {@link com.baomidou.mybatisplus.core.injector.methods.Update}
|
||||
*
|
||||
@ -59,12 +61,16 @@ public class UpdateJoin extends MPJAbstractMethod {
|
||||
* @param fieldStrategy 验证策略
|
||||
* @return if 脚本片段
|
||||
*/
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
@Override
|
||||
public String mpjConvertIf(TableFieldInfo tableFieldInfo, final String sqlScript, final String property, final FieldStrategy fieldStrategy) {
|
||||
if (fieldStrategy == FieldStrategy.NEVER) {
|
||||
return null;
|
||||
}
|
||||
if (AdapterHelper.getAdapter().mpjIsPrimitive(tableFieldInfo) || fieldStrategy == FieldStrategy.IGNORED) {
|
||||
FieldStrategy strategy = Optional.ofNullable(fieldStrategy).orElse(FieldStrategy.DEFAULT);
|
||||
if (AdapterHelper.getAdapter().mpjIsPrimitive(tableFieldInfo)
|
||||
|| strategy.name().equalsIgnoreCase("ALWAYS")
|
||||
|| strategy.name().equalsIgnoreCase("IGNORED")) {
|
||||
return sqlScript;
|
||||
}
|
||||
if (fieldStrategy == FieldStrategy.NOT_EMPTY && tableFieldInfo.isCharSequence()) {
|
||||
|
@ -3,9 +3,9 @@ package com.github.yulichang.method.mp;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
|
||||
/**
|
||||
@ -37,7 +37,7 @@ public class SelectList extends com.baomidou.mybatisplus.core.injector.methods.S
|
||||
@Override
|
||||
protected String sqlOrderBy(TableInfo table) {
|
||||
String orderBy = super.sqlOrderBy(table);
|
||||
if (StringUtils.isBlank(orderBy)) {
|
||||
if (StrUtils.isBlank(orderBy)) {
|
||||
return orderBy;
|
||||
}
|
||||
return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()),
|
||||
|
@ -3,9 +3,9 @@ package com.github.yulichang.method.mp;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
|
||||
/**
|
||||
@ -37,7 +37,7 @@ public class SelectMaps extends com.baomidou.mybatisplus.core.injector.methods.S
|
||||
@Override
|
||||
protected String sqlOrderBy(TableInfo table) {
|
||||
String orderBy = super.sqlOrderBy(table);
|
||||
if (StringUtils.isBlank(orderBy)) {
|
||||
if (StrUtils.isBlank(orderBy)) {
|
||||
return orderBy;
|
||||
}
|
||||
return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()),
|
||||
|
@ -3,9 +3,9 @@ package com.github.yulichang.method.mp;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
|
||||
/**
|
||||
@ -37,7 +37,7 @@ public class SelectMapsPage extends com.baomidou.mybatisplus.core.injector.metho
|
||||
@Override
|
||||
protected String sqlOrderBy(TableInfo table) {
|
||||
String orderBy = super.sqlOrderBy(table);
|
||||
if (StringUtils.isBlank(orderBy)) {
|
||||
if (StrUtils.isBlank(orderBy)) {
|
||||
return orderBy;
|
||||
}
|
||||
return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()),
|
||||
|
@ -3,9 +3,9 @@ package com.github.yulichang.method.mp;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
|
||||
/**
|
||||
@ -52,7 +52,7 @@ public class SelectObjs extends com.baomidou.mybatisplus.core.injector.methods.S
|
||||
@Override
|
||||
protected String sqlOrderBy(TableInfo table) {
|
||||
String orderBy = super.sqlOrderBy(table);
|
||||
if (StringUtils.isBlank(orderBy)) {
|
||||
if (StrUtils.isBlank(orderBy)) {
|
||||
return orderBy;
|
||||
}
|
||||
return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()),
|
||||
|
@ -3,9 +3,9 @@ package com.github.yulichang.method.mp;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
|
||||
/**
|
||||
@ -49,7 +49,7 @@ public class SelectOne extends com.baomidou.mybatisplus.core.injector.methods.Se
|
||||
@Override
|
||||
protected String sqlOrderBy(TableInfo table) {
|
||||
String orderBy = super.sqlOrderBy(table);
|
||||
if (StringUtils.isBlank(orderBy)) {
|
||||
if (StrUtils.isBlank(orderBy)) {
|
||||
return orderBy;
|
||||
}
|
||||
return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()),
|
||||
|
@ -3,9 +3,9 @@ package com.github.yulichang.method.mp;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
|
||||
/**
|
||||
@ -37,7 +37,7 @@ public class SelectPage extends com.baomidou.mybatisplus.core.injector.methods.S
|
||||
@Override
|
||||
protected String sqlOrderBy(TableInfo table) {
|
||||
String orderBy = super.sqlOrderBy(table);
|
||||
if (StringUtils.isBlank(orderBy)) {
|
||||
if (StrUtils.isBlank(orderBy)) {
|
||||
return orderBy;
|
||||
}
|
||||
return SqlScriptUtils.convertChoose(String.format("%s == null or !(%s instanceof %s)", Constants.WRAPPER, Constants.WRAPPER, MPJBaseJoin.class.getName()),
|
||||
|
@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.query.interfaces.CompareIfExists;
|
||||
import com.github.yulichang.query.interfaces.StringJoin;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.ThrowOptional;
|
||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||
@ -23,6 +24,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -237,7 +240,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
|
||||
@Override
|
||||
public String getSqlSelect() {
|
||||
if (StringUtils.isBlank(sqlSelect.getStringValue())) {
|
||||
if (StrUtils.isBlank(sqlSelect.getStringValue())) {
|
||||
if (CollectionUtils.isNotEmpty(ignoreColumns)) {
|
||||
selectColumns.removeIf(ignoreColumns::contains);
|
||||
}
|
||||
@ -260,7 +263,7 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
}
|
||||
|
||||
public MPJLambdaQueryWrapper<T> setAlias(String alias) {
|
||||
Assert.isTrue(StringUtils.isNotBlank(alias), "别名不能为空");
|
||||
Assert.isTrue(StrUtils.isNotBlank(alias), "别名不能为空");
|
||||
this.alias = alias;
|
||||
return typedThis;
|
||||
}
|
||||
@ -302,11 +305,9 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
|
||||
/**
|
||||
* 动态表名
|
||||
* 如果主表需要动态表名,主表实体必须添加 @DynamicTableName 注解
|
||||
* 关联表则不需要 加不加注解都会生效
|
||||
* <p>
|
||||
*
|
||||
* @see com.github.yulichang.annotation.DynamicTableName
|
||||
* 如果主表需要动态表名
|
||||
* <p>
|
||||
*/
|
||||
public MPJLambdaQueryWrapper<T> setTableName(Function<String, String> func) {
|
||||
this.tableNameFunc = func;
|
||||
@ -392,10 +393,33 @@ public class MPJLambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, MPJLambda
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPJLambdaQueryWrapper<T> join(String keyWord, boolean condition, String joinSql) {
|
||||
public MPJLambdaQueryWrapper<T> join(String keyWord, boolean condition, String joinSql, Object... args) {
|
||||
if (condition) {
|
||||
from.setStringValue(from.getStringValue() + keyWord + joinSql);
|
||||
from.setStringValue(from.getStringValue() + keyWord + mpjFormatSqlMaybeWithParam(joinSql, args));
|
||||
}
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
protected final String mpjFormatSqlMaybeWithParam(String sqlStr, Object... params) {
|
||||
if (StrUtils.isBlank(sqlStr)) {
|
||||
return null;
|
||||
}
|
||||
if (ArrayUtils.isNotEmpty(params)) {
|
||||
for (int i = 0; i < params.length; ++i) {
|
||||
String target = Constants.LEFT_BRACE + i + Constants.RIGHT_BRACE;
|
||||
if (sqlStr.contains(target)) {
|
||||
sqlStr = sqlStr.replace(target, formatParam(null, params[i]));
|
||||
} else {
|
||||
Matcher matcher = Pattern.compile("[{]" + i + ",[a-zA-Z0-9.,=]+}").matcher(sqlStr);
|
||||
if (!matcher.find()) {
|
||||
throw ExceptionUtils.mpe("Please check the syntax correctness! sql not contains: \"%s\"", target);
|
||||
}
|
||||
String group = matcher.group();
|
||||
sqlStr = sqlStr.replace(group, formatParam(group.substring(target.length(), group.length() - 1), params[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return sqlStr;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.yulichang.query;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisPlusVersion;
|
||||
import com.baomidou.mybatisplus.core.conditions.AbstractWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.SharedString;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.Query;
|
||||
@ -15,6 +14,7 @@ import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.query.interfaces.CompareIfExists;
|
||||
import com.github.yulichang.query.interfaces.StringJoin;
|
||||
import com.github.yulichang.toolkit.MPJSqlInjectionUtils;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.ThrowOptional;
|
||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||
@ -31,6 +31,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -102,7 +104,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
try {
|
||||
super.setEntityClass(clazz);
|
||||
} catch (NoSuchMethodError error) {
|
||||
if (VersionUtils.compare(MybatisPlusVersion.getVersion(), "3.3.0") > 0) {
|
||||
if (VersionUtils.compare(VersionUtils.getVersion(), "3.3.0") > 0) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@ -250,7 +252,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
|
||||
@Override
|
||||
public String getSqlSelect() {
|
||||
if (StringUtils.isBlank(sqlSelect.getStringValue())) {
|
||||
if (StrUtils.isBlank(sqlSelect.getStringValue())) {
|
||||
if (CollectionUtils.isNotEmpty(ignoreColumns)) {
|
||||
selectColumns.removeIf(ignoreColumns::contains);
|
||||
}
|
||||
@ -278,7 +280,7 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
* @param alias 主表别名
|
||||
*/
|
||||
public MPJQueryWrapper<T> setAlias(String alias) {
|
||||
Assert.isTrue(StringUtils.isNotBlank(alias), "别名不能为空");
|
||||
Assert.isTrue(StrUtils.isNotBlank(alias), "别名不能为空");
|
||||
this.alias = alias;
|
||||
return this;
|
||||
}
|
||||
@ -315,11 +317,9 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
|
||||
/**
|
||||
* 动态表名
|
||||
* 如果主表需要动态表名,主表实体必须添加 @DynamicTableName 注解
|
||||
* 关联表则不需要 加不加注解都会生效
|
||||
* <p>
|
||||
*
|
||||
* @see com.github.yulichang.annotation.DynamicTableName
|
||||
* 如果主表需要动态表名
|
||||
* <p>
|
||||
*/
|
||||
public MPJQueryWrapper<T> setTableName(Function<String, String> func) {
|
||||
this.tableNameFunc = func;
|
||||
@ -352,7 +352,8 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
*/
|
||||
public MPJLambdaQueryWrapper<T> lambda() {
|
||||
return new MPJLambdaQueryWrapper<>(getEntity(), getEntityClass(), from, sqlSelect, paramNameSeq, paramNameValuePairs,
|
||||
expression, lastSql, sqlComment, getSqlFirstField(), selectColumns, ignoreColumns, selectDistinct, ifExists);
|
||||
expression, lastSql, sqlComment, getSqlFirstField(), selectColumns, ignoreColumns, selectDistinct, ifExists)
|
||||
.setAlias(this.alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -409,10 +410,34 @@ public class MPJQueryWrapper<T> extends AbstractWrapper<T, String, MPJQueryWrapp
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPJQueryWrapper<T> join(String keyWord, boolean condition, String joinSql) {
|
||||
public MPJQueryWrapper<T> join(String keyWord, boolean condition, String joinSql, Object... params) {
|
||||
if (condition) {
|
||||
from.setStringValue(from.getStringValue() + StringPool.SPACE + keyWord + StringPool.SPACE + joinSql);
|
||||
from.setStringValue(from.getStringValue() + StringPool.SPACE + keyWord +
|
||||
StringPool.SPACE + mpjFormatSqlMaybeWithParam(joinSql, params));
|
||||
}
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
protected final String mpjFormatSqlMaybeWithParam(String sqlStr, Object... params) {
|
||||
if (StrUtils.isBlank(sqlStr)) {
|
||||
return null;
|
||||
}
|
||||
if (ArrayUtils.isNotEmpty(params)) {
|
||||
for (int i = 0; i < params.length; ++i) {
|
||||
String target = Constants.LEFT_BRACE + i + Constants.RIGHT_BRACE;
|
||||
if (sqlStr.contains(target)) {
|
||||
sqlStr = sqlStr.replace(target, formatParam(null, params[i]));
|
||||
} else {
|
||||
Matcher matcher = Pattern.compile("[{]" + i + ",[a-zA-Z0-9.,=]+}").matcher(sqlStr);
|
||||
if (!matcher.find()) {
|
||||
throw ExceptionUtils.mpe("Please check the syntax correctness! sql not contains: \"%s\"", target);
|
||||
}
|
||||
String group = matcher.group();
|
||||
sqlStr = sqlStr.replace(group, formatParam(group.substring(target.length(), group.length() - 1), params[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return sqlStr;
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,19 @@ public interface StringJoin<Children, T> extends MPJBaseJoin<T> {
|
||||
return leftJoin(true, joinSql);
|
||||
}
|
||||
|
||||
default Children leftJoin(String joinSql, Object... args) {
|
||||
return leftJoin(true, joinSql, args);
|
||||
}
|
||||
|
||||
|
||||
default Children leftJoin(boolean condition, String joinSql) {
|
||||
return join(Constant.LEFT_JOIN, condition, joinSql);
|
||||
}
|
||||
|
||||
default Children leftJoin(boolean condition, String joinSql, Object... args) {
|
||||
return join(Constant.LEFT_JOIN, condition, joinSql, args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* right join
|
||||
@ -28,10 +37,17 @@ public interface StringJoin<Children, T> extends MPJBaseJoin<T> {
|
||||
return rightJoin(true, joinSql);
|
||||
}
|
||||
|
||||
default Children rightJoin(String joinSql, Object... args) {
|
||||
return rightJoin(true, joinSql, args);
|
||||
}
|
||||
|
||||
default Children rightJoin(boolean condition, String joinSql) {
|
||||
return join(Constant.RIGHT_JOIN, condition, joinSql);
|
||||
}
|
||||
|
||||
default Children rightJoin(boolean condition, String joinSql, Object... args) {
|
||||
return join(Constant.RIGHT_JOIN, condition, joinSql, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* inner join
|
||||
@ -40,10 +56,18 @@ public interface StringJoin<Children, T> extends MPJBaseJoin<T> {
|
||||
return innerJoin(true, joinSql);
|
||||
}
|
||||
|
||||
default Children innerJoin(String joinSql, Object... args) {
|
||||
return innerJoin(true, joinSql, args);
|
||||
}
|
||||
|
||||
default Children innerJoin(boolean condition, String joinSql) {
|
||||
return join(Constant.INNER_JOIN, condition, joinSql);
|
||||
}
|
||||
|
||||
default Children innerJoin(boolean condition, String joinSql, Object... args) {
|
||||
return join(Constant.INNER_JOIN, condition, joinSql, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* full join
|
||||
*/
|
||||
@ -51,9 +75,23 @@ public interface StringJoin<Children, T> extends MPJBaseJoin<T> {
|
||||
return fullJoin(true, joinSql);
|
||||
}
|
||||
|
||||
default Children fullJoin(String joinSql, Object... args) {
|
||||
return fullJoin(true, joinSql, args);
|
||||
}
|
||||
|
||||
default Children fullJoin(boolean condition, String joinSql) {
|
||||
return join(Constant.FULL_JOIN, condition, joinSql);
|
||||
}
|
||||
|
||||
Children join(String keyWord, boolean condition, String joinSql);
|
||||
default Children fullJoin(boolean condition, String joinSql, Object... args) {
|
||||
return join(Constant.FULL_JOIN, condition, joinSql, args);
|
||||
}
|
||||
|
||||
default Children join(String keyWord, boolean condition, String joinSql) {
|
||||
return join(keyWord, condition, joinSql, new Object[0]);
|
||||
}
|
||||
|
||||
default Children join(String keyWord, boolean condition, String joinSql, Object... args){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.github.yulichang.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.repository.AbstractRepository;
|
||||
|
||||
/**
|
||||
* {@link AbstractRepository}
|
||||
* {@link JoinRepository}
|
||||
*
|
||||
* @auther yulichang
|
||||
* @since 1.5.2
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class JoinAbstractRepository<M extends BaseMapper<T>, T> extends AbstractRepository<M, T> implements JoinRepository<T> {
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.github.yulichang.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.repository.CrudRepository;
|
||||
|
||||
/**
|
||||
* {@link CrudRepository}
|
||||
* {@link JoinRepository}
|
||||
*
|
||||
* @auther yulichang
|
||||
* @since 1.5.2
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class JoinCrudRepository<M extends BaseMapper<T>, T> extends CrudRepository<M, T> implements JoinRepository<T> {
|
||||
}
|
@ -1,23 +1,22 @@
|
||||
package com.github.yulichang.mybatisplusjoin.solon.plugin.base;
|
||||
package com.github.yulichang.repository;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.solon.service.IService;
|
||||
import com.baomidou.mybatisplus.solon.toolkit.SqlHelper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.repository.IRepository;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||
import com.github.yulichang.base.JoinMapper;
|
||||
import com.github.yulichang.interfaces.MPJBaseJoin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 基础service
|
||||
* 目前包含两个模块 连表查询 和 关系映射
|
||||
* {@link IRepository}
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 1.5.2
|
||||
*/
|
||||
@SuppressWarnings({"unused"})
|
||||
public interface MPJBaseService<T> extends IService<T> {
|
||||
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public interface JoinRepository<T> extends IRepository<T> {
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,连表删除
|
||||
@ -25,7 +24,7 @@ public interface MPJBaseService<T> extends IService<T> {
|
||||
* @param wrapper joinWrapper
|
||||
*/
|
||||
default boolean deleteJoin(MPJBaseJoin<T> wrapper) {
|
||||
return SqlHelper.retBool(((MPJBaseMapper<T>) getBaseMapper()).deleteJoin(wrapper));
|
||||
return SqlHelper.retBool(((JoinMapper<T>) getBaseMapper()).deleteJoin(wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,7 +34,7 @@ public interface MPJBaseService<T> extends IService<T> {
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
default boolean updateJoin(T entity, MPJBaseJoin<T> wrapper) {
|
||||
return SqlHelper.retBool(((MPJBaseMapper<T>) getBaseMapper()).updateJoin(entity, wrapper));
|
||||
return SqlHelper.retBool(((JoinMapper<T>) getBaseMapper()).updateJoin(entity, wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,55 +44,55 @@ public interface MPJBaseService<T> extends IService<T> {
|
||||
* @param wrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
|
||||
*/
|
||||
default boolean updateJoinAndNull(T entity, MPJBaseJoin<T> wrapper) {
|
||||
return SqlHelper.retBool(((MPJBaseMapper<T>) getBaseMapper()).updateJoinAndNull(entity, wrapper));
|
||||
return SqlHelper.retBool(((JoinMapper<T>) getBaseMapper()).updateJoinAndNull(entity, wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 Wrapper 条件,查询总记录数
|
||||
*/
|
||||
default Long selectJoinCount(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinCount(wrapper);
|
||||
return ((JoinMapper<T>) getBaseMapper()).selectJoinCount(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回一条记录
|
||||
*/
|
||||
default <DTO> DTO selectJoinOne(Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinOne(clazz, wrapper);
|
||||
return ((JoinMapper<T>) getBaseMapper()).selectJoinOne(clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回集合
|
||||
*/
|
||||
default <DTO> List<DTO> selectJoinList(Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinList(clazz, wrapper);
|
||||
return ((JoinMapper<T>) getBaseMapper()).selectJoinList(clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回集合并分页
|
||||
*/
|
||||
default <DTO, P extends IPage<DTO>> P selectJoinListPage(P page, Class<DTO> clazz, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinPage(page, clazz, wrapper);
|
||||
return ((JoinMapper<T>) getBaseMapper()).selectJoinPage(page, clazz, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map
|
||||
*/
|
||||
default Map<String, Object> selectJoinMap(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMap(wrapper);
|
||||
return ((JoinMapper<T>) getBaseMapper()).selectJoinMap(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map集合
|
||||
*/
|
||||
default List<Map<String, Object>> selectJoinMaps(MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMaps(wrapper);
|
||||
return ((JoinMapper<T>) getBaseMapper()).selectJoinMaps(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接查询返回Map集合并分页
|
||||
*/
|
||||
default <P extends IPage<Map<String, Object>>> P selectJoinMapsPage(P page, MPJBaseJoin<T> wrapper) {
|
||||
return ((MPJBaseMapper<T>) getBaseMapper()).selectJoinMapsPage(page, wrapper);
|
||||
return ((JoinMapper<T>) getBaseMapper()).selectJoinMapsPage(page, wrapper);
|
||||
}
|
||||
}
|
@ -130,8 +130,7 @@ public final class ClassUtils {
|
||||
Constructor<T> constructor = clazz.getDeclaredConstructor();
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
|
||||
NoSuchMethodException e) {
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
throw ExceptionUtils.mpe("实例化对象时出现错误,请尝试给 %s 添加无参的构造方法", e, clazz.getName());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,162 @@
|
||||
package com.github.yulichang.toolkit;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.toolkit.support.FieldCache;
|
||||
import com.github.yulichang.toolkit.support.LambdaMeta;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.github.yulichang.wrapper.interfaces.MConsumer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 填充
|
||||
*
|
||||
* @auther yulichang
|
||||
* @since 1.5.1
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public final class FillUtils {
|
||||
|
||||
public static void fill(Object data, SFunction<?, ?> field, SFunction<?, ?> tagField) {
|
||||
fill(data, field, tagField, (MConsumer<MPJLambdaWrapper<?>>) null);
|
||||
}
|
||||
|
||||
public static void fill(Object data, SFunction<?, ?> field, SFunction<?, ?> tagField, MConsumer<MPJLambdaWrapper<?>> consumer) {
|
||||
LambdaMeta meta = LambdaUtils.getMeta(tagField);
|
||||
FieldCache fieldCache = MPJReflectionKit.getFieldMap(meta.getInstantiatedClass()).get(meta.getName());
|
||||
fill(data, field, getTagClass(fieldCache.getField()), tagField, consumer);
|
||||
}
|
||||
|
||||
public static void fill(Object data, SFunction<?, ?> field, Class<?> oneClass, SFunction<?, ?> tagField) {
|
||||
fill(data, field, oneClass, tagField, null);
|
||||
}
|
||||
|
||||
public static void fill(Object data, SFunction<?, ?> field, Class<?> oneClass, SFunction<?, ?> tagField, MConsumer<MPJLambdaWrapper<?>> consumer) {
|
||||
TableInfo tableInfo = TableHelper.getAssert(oneClass);
|
||||
Assert.notNull(tableInfo.getKeyProperty(), "not found key property by class %s", oneClass.getName());
|
||||
fill(data, field, new SF(oneClass, tableInfo.getKeyProperty()), tagField, consumer);
|
||||
}
|
||||
|
||||
public static void fill(Object data, SFunction<?, ?> field, SFunction<?, ?> oneField, SFunction<?, ?> tagField) {
|
||||
fill(data, field, oneField, tagField, null);
|
||||
}
|
||||
|
||||
public static void fill(Object data, SFunction<?, ?> field, SFunction<?, ?> oneField, SFunction<?, ?> tagField, MConsumer<MPJLambdaWrapper<?>> consumer) {
|
||||
doFill(data, field, oneField, tagField, consumer);
|
||||
}
|
||||
|
||||
private static <W> void doFill(Object data, SFunction<?, ?> field, SFunction<?, ?> oneField, SFunction<?, ?> tagField, MConsumer<MPJLambdaWrapper<?>> consumer) {
|
||||
if (data == null || field == null || oneField == null || tagField == null) {
|
||||
return;
|
||||
}
|
||||
if (data instanceof IPage) {
|
||||
doFill(((IPage<?>) data).getRecords(), field, oneField, tagField, consumer);
|
||||
return;
|
||||
}
|
||||
if (data instanceof Collection) {
|
||||
Collection<?> collection = (Collection<?>) data;
|
||||
if (collection.isEmpty() || collection.stream().allMatch(Objects::isNull)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LambdaMeta sourceMeta = LambdaUtils.getMeta(field);
|
||||
FieldCache sourceCache = MPJReflectionKit.getFieldMap(sourceMeta.getInstantiatedClass()).get(sourceMeta.getName());
|
||||
|
||||
LambdaMeta tagMeta = LambdaUtils.getMeta(tagField);
|
||||
FieldCache tagCache = MPJReflectionKit.getFieldMap(tagMeta.getInstantiatedClass()).get(tagMeta.getName());
|
||||
|
||||
FieldCache oneCache;
|
||||
if (oneField instanceof SF) {
|
||||
SF sf = (SF) oneField;
|
||||
oneCache = MPJReflectionKit.getFieldMap(sf.getClazz()).get(sf.getName());
|
||||
} else {
|
||||
LambdaMeta oneMeta = LambdaUtils.getMeta(oneField);
|
||||
oneCache = MPJReflectionKit.getFieldMap(oneMeta.getInstantiatedClass()).get(oneMeta.getName());
|
||||
}
|
||||
|
||||
Class<?> wrapperClass = (oneField instanceof SF) ? ((SF) oneField).clazz : LambdaUtils.getEntityClass(oneField);
|
||||
MPJLambdaWrapper<W> wrapper = new MPJLambdaWrapper<W>((Class<W>) wrapperClass) {
|
||||
|
||||
@Override
|
||||
public <R> MPJLambdaWrapper<W> in(SFunction<R, ?> column, Collection<?> coll) {
|
||||
if (column instanceof SF) {
|
||||
SF sf = (SF) column;
|
||||
TableInfo tableInfo = TableHelper.getAssert(sf.getClazz());
|
||||
return super.in(alias + StringPool.DOT + tableInfo.getKeyColumn(), coll);
|
||||
}
|
||||
return super.in(column, coll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> MPJLambdaWrapper<W> eq(SFunction<R, ?> column, Object val) {
|
||||
if (column instanceof SF) {
|
||||
SF sf = (SF) column;
|
||||
TableInfo tableInfo = TableHelper.getAssert(sf.getClazz());
|
||||
return super.eq(alias + StringPool.DOT + tableInfo.getKeyColumn(), val);
|
||||
}
|
||||
return super.eq(column, val);
|
||||
}
|
||||
};
|
||||
|
||||
boolean many = Collection.class.isAssignableFrom(tagCache.getType());
|
||||
|
||||
if (data instanceof Collection) {
|
||||
List<?> collection = ((Collection<?>) data).stream().filter(Objects::nonNull).collect(Collectors.toList());
|
||||
Set<Object> sourceSet = collection.stream().map(sourceCache::getFieldValue).collect(Collectors.toSet());
|
||||
if (!sourceSet.isEmpty()) {
|
||||
wrapper.in(oneField, sourceSet);
|
||||
if (consumer != null) {
|
||||
consumer.accept(wrapper);
|
||||
}
|
||||
List<?> list = wrapper.list();
|
||||
Map<Object, ?> map;
|
||||
if (many)
|
||||
map = list.stream().collect(Collectors.groupingBy(oneCache::getFieldValue));
|
||||
else
|
||||
map = list.stream().collect(Collectors.toMap(oneCache::getFieldValue, i -> i));
|
||||
//匹配
|
||||
collection.forEach(item -> tagCache.setFieldValue(item, map.get(sourceCache.getFieldValue(item))));
|
||||
}
|
||||
} else {
|
||||
Object sourceVal = sourceCache.getFieldValue(data);
|
||||
wrapper.eq(oneField, sourceVal);
|
||||
if (consumer != null) {
|
||||
consumer.accept(wrapper);
|
||||
}
|
||||
Object x = many ? wrapper.list(tagCache.getType()) : wrapper.one(tagCache.getType());
|
||||
if (x != null) {
|
||||
tagCache.setFieldValue(data, x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static <X> Class<X> getTagClass(Field field) {
|
||||
if (Collection.class.isAssignableFrom(field.getType())) {
|
||||
return (Class<X>) MPJReflectionKit.getGenericType(field);
|
||||
} else {
|
||||
return (Class<X>) field.getType();
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
private static class SF implements SFunction<Object, Object> {
|
||||
private Class<?> clazz;
|
||||
private String name;
|
||||
|
||||
|
||||
@Override
|
||||
public Object apply(Object o) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
@ -28,6 +28,10 @@ public final class LambdaUtils {
|
||||
return (Class<T>) extract(fn).getInstantiatedClass();
|
||||
}
|
||||
|
||||
public static <T> LambdaMeta getMeta(SFunction<T, ?> fn) {
|
||||
return extract(fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* 该缓存可能会在任意不定的时间被清除
|
||||
*
|
||||
@ -35,7 +39,7 @@ public final class LambdaUtils {
|
||||
* @param <T> 类型,被调用的 Function 对象的目标类型
|
||||
* @return 返回解析后的结果
|
||||
*/
|
||||
public static <T> LambdaMeta extract(SFunction<T, ?> func) {
|
||||
private static <T> LambdaMeta extract(SFunction<T, ?> func) {
|
||||
// 1. IDEA 调试模式下 lambda 表达式是一个代理
|
||||
if (func instanceof Proxy) {
|
||||
return new IdeaProxyLambdaMeta((Proxy) func);
|
||||
|
@ -110,4 +110,15 @@ public final class MPJReflectionKit {
|
||||
Assert.notNull(clazz, "Class must not be null");
|
||||
return (clazz.isPrimitive() || PRIMITIVE_WRAPPER_TYPE_MAP.containsKey(clazz));
|
||||
}
|
||||
|
||||
public static <T> T getFieldValue(Object object, String fieldName) {
|
||||
try {
|
||||
Field field = object.getClass().getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
//noinspection unchecked
|
||||
return (T) field.get(object);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.github.yulichang.toolkit;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.base.JoinMapper;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -21,9 +21,11 @@ public class MPJTableMapperHelper {
|
||||
|
||||
public static void init(Class<?> clazz, Class<?> mapper) {
|
||||
if (clazz != null && mapper != null) {
|
||||
CACHE.put(clazz, mapper);
|
||||
CACHE_REVERSE.put(mapper, clazz);
|
||||
CACHE_MAPPER.put(mapper.getName(), mapper);
|
||||
if (!CACHE.containsKey(clazz) || JoinMapper.class.isAssignableFrom(mapper)) {
|
||||
CACHE.put(clazz, mapper);
|
||||
CACHE_REVERSE.put(mapper, clazz);
|
||||
CACHE_MAPPER.put(mapper.getName(), mapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +38,7 @@ public class MPJTableMapperHelper {
|
||||
}
|
||||
|
||||
public static Class<?> getMapperForName(String name) {
|
||||
if (StringUtils.isBlank(name)) {
|
||||
if (StrUtils.isBlank(name)) {
|
||||
return null;
|
||||
}
|
||||
return CACHE_MAPPER.get(name);
|
||||
|
@ -0,0 +1,53 @@
|
||||
package com.github.yulichang.toolkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.security.CodeSource;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
* copy {@link com.baomidou.mybatisplus.core.MybatisPlusVersion}
|
||||
*
|
||||
* @since 1.5.2
|
||||
*/
|
||||
public class MybatisJoinPlusVersion {
|
||||
|
||||
private MybatisJoinPlusVersion() {
|
||||
}
|
||||
|
||||
public static String getVersion() {
|
||||
return determineSpringBootVersion();
|
||||
}
|
||||
|
||||
private static String determineSpringBootVersion() {
|
||||
final Package pkg = MybatisJoinPlusVersion.class.getPackage();
|
||||
if (pkg != null && pkg.getImplementationVersion() != null) {
|
||||
return pkg.getImplementationVersion();
|
||||
}
|
||||
CodeSource codeSource = MybatisJoinPlusVersion.class.getProtectionDomain().getCodeSource();
|
||||
if (codeSource == null) {
|
||||
return null;
|
||||
}
|
||||
URL codeSourceLocation = codeSource.getLocation();
|
||||
try {
|
||||
URLConnection connection = codeSourceLocation.openConnection();
|
||||
if (connection instanceof JarURLConnection) {
|
||||
return getImplementationVersion(((JarURLConnection) connection).getJarFile());
|
||||
}
|
||||
try (JarFile jarFile = new JarFile(new File(codeSourceLocation.toURI()))) {
|
||||
return getImplementationVersion(jarFile);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getImplementationVersion(JarFile jarFile) throws IOException {
|
||||
return jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION);
|
||||
}
|
||||
|
||||
}
|
@ -19,6 +19,7 @@ import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||
import com.github.yulichang.toolkit.reflect.GenericTypeUtils;
|
||||
import com.github.yulichang.toolkit.reflect.TypeParameterResolver;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
@ -70,14 +71,19 @@ public final class ReflectionKit {
|
||||
* @param entity 实体
|
||||
* @param fieldName 字段名称
|
||||
* @return 属性值
|
||||
* @deprecated 3.5.4
|
||||
*/
|
||||
public static <T> T getFieldValue(Object entity, String fieldName) {
|
||||
@Deprecated
|
||||
public static Object getFieldValue(Object entity, String fieldName) {
|
||||
Class<?> cls = entity.getClass();
|
||||
Map<String, Field> fieldMaps = getFieldMap(cls);
|
||||
try {
|
||||
Field field = entity.getClass().getDeclaredField(fieldName);
|
||||
Field field = fieldMaps.get(fieldName);
|
||||
Assert.notNull(field, "Error: NoSuchField in %s for %s. Cause:", cls.getSimpleName(), fieldName);
|
||||
field.setAccessible(true);
|
||||
return (T) field.get(entity);
|
||||
return field.get(entity);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw ExceptionUtils.mpe("Error: Cannot read field in %s. Cause:", e, entity.getClass().getSimpleName());
|
||||
throw ExceptionUtils.mpe("Error: Cannot read field in %s. Cause:", e, cls.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,9 +98,13 @@ public final class ReflectionKit {
|
||||
* @return Class
|
||||
*/
|
||||
public static Class<?> getSuperClassGenericType(final Class<?> clazz, final Class<?> genericIfc, final int index) {
|
||||
//update by noear @2021-09-03
|
||||
Class<?>[] typeArguments = GenericTypeUtils.resolveTypeArguments(ClassUtils.getUserClass(clazz), genericIfc);
|
||||
return null == typeArguments ? null : typeArguments[index];
|
||||
// 这里泛型逻辑提取进行了调整,如果在Spring项目情况或者自定义了泛型提取,那就优先走这里,否则使用框架内置的进行泛型提取.
|
||||
Class<?> userClass = ClassUtils.getUserClass(clazz);
|
||||
if (GenericTypeUtils.hasGenericTypeResolver()) {
|
||||
Class<?>[] typeArguments = GenericTypeUtils.resolveTypeArguments(userClass, genericIfc);
|
||||
return null == typeArguments ? null : typeArguments[index];
|
||||
}
|
||||
return (Class<?>) TypeParameterResolver.resolveClassIndexedParameter(userClass, genericIfc, index);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,7 +130,7 @@ public final class ReflectionKit {
|
||||
if (Objects.isNull(clazz)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return computeIfAbsent(CLASS_FIELD_CACHE, clazz, k -> {
|
||||
return CLASS_FIELD_CACHE.computeIfAbsent(clazz, k -> {
|
||||
Field[] fields = k.getDeclaredFields();
|
||||
List<Field> superFields = new ArrayList<>();
|
||||
Class<?> currentClass = k.getSuperclass();
|
||||
@ -180,12 +190,4 @@ public final class ReflectionKit {
|
||||
public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
|
||||
return (clazz.isPrimitive() && clazz != void.class ? PRIMITIVE_TYPE_TO_WRAPPER_MAP.get(clazz) : clazz);
|
||||
}
|
||||
|
||||
public static <K, V> V computeIfAbsent(Map<K, V> concurrentHashMap, K key, Function<? super K, ? extends V> mappingFunction) {
|
||||
V v = concurrentHashMap.get(key);
|
||||
if (v != null) {
|
||||
return v;
|
||||
}
|
||||
return concurrentHashMap.computeIfAbsent(key, mappingFunction);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.github.yulichang.toolkit;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.github.yulichang.base.JoinMapper;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@ -13,11 +13,11 @@ import java.util.function.Function;
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class SqlHelper {
|
||||
|
||||
public static <R, T> R exec(Class<T> entityClass, Function<MPJBaseMapper<T>, R> function) {
|
||||
public static <R, T> R exec(Class<T> entityClass, Function<JoinMapper<T>, R> function) {
|
||||
Assert.notNull(entityClass, "请使用 new MPJLambdaWrapper(主表.class) 或 JoinWrappers.lambda(主表.class) 构造方法");
|
||||
Object mapper = SpringContentUtils.getMapper(entityClass);
|
||||
Assert.notNull(mapper, "mapper not init <%s>", entityClass.getSimpleName());
|
||||
Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> not extends MPJBaseMapper ", entityClass.getSimpleName());
|
||||
return function.apply((MPJBaseMapper<T>) mapper);
|
||||
Assert.isTrue(mapper instanceof JoinMapper, "mapper <%s> not extends MPJBaseMapper ", entityClass.getSimpleName());
|
||||
return function.apply((JoinMapper<T>) mapper);
|
||||
}
|
||||
}
|
||||
|
@ -33,14 +33,14 @@ import static java.util.stream.Collectors.joining;
|
||||
* @author hcl
|
||||
* @since 2016-08-18
|
||||
*/
|
||||
@SuppressWarnings("ALL")
|
||||
public final class MPJStringUtils {
|
||||
@SuppressWarnings("unused")
|
||||
public final class StrUtils {
|
||||
|
||||
/**
|
||||
* 判断是否是中文
|
||||
*/
|
||||
public static boolean isChinese(String str) {
|
||||
if(isBlank(str))
|
||||
if (isBlank(str))
|
||||
return false;
|
||||
char c = str.charAt(0);
|
||||
return c >= 0x4E00 && c <= 0x9FA5;
|
||||
@ -70,13 +70,6 @@ public final class MPJStringUtils {
|
||||
*/
|
||||
private static final Pattern CAPITAL_MODE = Pattern.compile("^[0-9A-Z/_]+$");
|
||||
|
||||
/**
|
||||
* 字符串去除空白内容
|
||||
*
|
||||
* <ul> <li>'"<>&*+=#-; sql注入黑名单</li> <li>\n 回车</li> <li>\t 水平制表符</li> <li>\s 空格</li> <li>\r 换行</li> </ul>
|
||||
*/
|
||||
private static final Pattern REPLACE_BLANK = Pattern.compile("'|\"|\\<|\\>|&|\\*|\\+|=|#|-|;|\\s*|\t|\r|\n");
|
||||
|
||||
/**
|
||||
* 判断字符串中是否全是空白字符
|
||||
*
|
||||
@ -99,7 +92,6 @@ public final class MPJStringUtils {
|
||||
* 对象转为字符串去除左右空格
|
||||
*
|
||||
* @param o 带转换对象
|
||||
* @return
|
||||
*/
|
||||
public static String toStringTrim(Object o) {
|
||||
return String.valueOf(o).trim();
|
||||
@ -150,7 +142,7 @@ public final class MPJStringUtils {
|
||||
* @return 字段名
|
||||
*/
|
||||
public static String getTargetColumn(String column) {
|
||||
if(isChinese(column)){
|
||||
if (isChinese(column)) {
|
||||
return column;
|
||||
}
|
||||
if (isNotColumnName(column)) {
|
||||
@ -245,7 +237,7 @@ public final class MPJStringUtils {
|
||||
* @param args 填充参数
|
||||
*/
|
||||
public static String sqlArgsFill(String content, Object... args) {
|
||||
if (MPJStringUtils.isNotBlank(content) && ArrayUtils.isNotEmpty(args)) {
|
||||
if (StrUtils.isNotBlank(content) && ArrayUtils.isNotEmpty(args)) {
|
||||
// 索引不能使用,因为 SQL 中的占位符数字与索引不相同
|
||||
BiIntFunction<Matcher, CharSequence> handler = (m, i) -> sqlParam(args[Integer.parseInt(m.group("idx"))]);
|
||||
return replace(content, MP_SQL_PLACE_HOLDER, handler).toString();
|
||||
@ -288,9 +280,9 @@ public final class MPJStringUtils {
|
||||
public static String sqlParam(Object obj) {
|
||||
String repStr;
|
||||
if (obj instanceof Collection) {
|
||||
repStr = MPJStringUtils.quotaMarkList((Collection<?>) obj);
|
||||
repStr = StrUtils.quotaMarkList((Collection<?>) obj);
|
||||
} else {
|
||||
repStr = MPJStringUtils.quotaMark(obj);
|
||||
repStr = StrUtils.quotaMark(obj);
|
||||
}
|
||||
return repStr;
|
||||
}
|
||||
@ -317,7 +309,7 @@ public final class MPJStringUtils {
|
||||
* @return 单引号包含的原字符串的集合形式
|
||||
*/
|
||||
public static String quotaMarkList(Collection<?> coll) {
|
||||
return coll.stream().map(MPJStringUtils::quotaMark)
|
||||
return coll.stream().map(StrUtils::quotaMark)
|
||||
.collect(joining(StringPool.COMMA, StringPool.LEFT_BRACKET, StringPool.RIGHT_BRACKET));
|
||||
}
|
||||
|
||||
@ -328,7 +320,7 @@ public final class MPJStringUtils {
|
||||
if (isBlank(concatStr)) {
|
||||
concatStr = StringPool.EMPTY;
|
||||
}
|
||||
if (str == null || str.length() == 0) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -400,33 +392,6 @@ public final class MPJStringUtils {
|
||||
return matches(".*[A-Z]+.*", word) && matches(".*[/_]+.*", word);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否以某个字符串结尾(区分大小写)
|
||||
* Check if a String ends with a specified suffix.
|
||||
* <p>
|
||||
* <code>null</code>s are handled without exceptions. Two <code>null</code>
|
||||
* references are considered to be equal. The comparison is case sensitive.
|
||||
* </p>
|
||||
* <p>
|
||||
* <pre>
|
||||
* StringUtils.endsWith(null, null) = true
|
||||
* StringUtils.endsWith(null, "abcdef") = false
|
||||
* StringUtils.endsWith("def", null) = false
|
||||
* StringUtils.endsWith("def", "abcdef") = true
|
||||
* StringUtils.endsWith("def", "ABCDEF") = false
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @param str the String to check, may be null
|
||||
* @param suffix the suffix to find, may be null
|
||||
* @return <code>true</code> if the String ends with the suffix, case
|
||||
* sensitive, or both <code>null</code>
|
||||
* @see String#endsWith(String)
|
||||
* @since 2.4
|
||||
*/
|
||||
public static boolean endsWith(String str, String suffix) {
|
||||
return endsWith(str, suffix, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a String ends with a specified suffix (optionally case
|
||||
@ -469,16 +434,14 @@ public final class MPJStringUtils {
|
||||
* @return ignore
|
||||
*/
|
||||
public static String prefixToLower(String rawString, int index) {
|
||||
StringBuilder field = new StringBuilder();
|
||||
field.append(rawString.substring(0, index).toLowerCase());
|
||||
field.append(rawString.substring(index));
|
||||
return field.toString();
|
||||
return rawString.substring(0, index).toLowerCase() +
|
||||
rawString.substring(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除字符前缀之后,首字母小写,之后字符大小写的不变
|
||||
* <p>StringUtils.removePrefixAfterPrefixToLower( "isUser", 2 ) = user</p>
|
||||
* <p>StringUtils.removePrefixAfterPrefixToLower( "isUserInfo", 2 ) = userInfo</p>
|
||||
* <p>StrUtils.removePrefixAfterPrefixToLower( "isUser", 2 ) = user</p>
|
||||
* <p>StrUtils.removePrefixAfterPrefixToLower( "isUserInfo", 2 ) = userInfo</p>
|
||||
*
|
||||
* @param rawString 需要处理的字符串
|
||||
* @param index 删除多少个字符(从左至右)
|
||||
@ -490,7 +453,7 @@ public final class MPJStringUtils {
|
||||
|
||||
/**
|
||||
* 驼峰转连字符
|
||||
* <p>StringUtils.camelToHyphen( "managerAdminUserService" ) = manager-admin-user-service</p>
|
||||
* <p>StrUtils.camelToHyphen( "managerAdminUserService" ) = manager-admin-user-service</p>
|
||||
*
|
||||
* @param input ignore
|
||||
* @return 以'-'分隔
|
||||
@ -562,11 +525,11 @@ public final class MPJStringUtils {
|
||||
* <p>对字符串大小写敏感</p>
|
||||
*
|
||||
* <pre>
|
||||
* StringUtils.equals(null, null) = true
|
||||
* StringUtils.equals(null, "abc") = false
|
||||
* StringUtils.equals("abc", null) = false
|
||||
* StringUtils.equals("abc", "abc") = true
|
||||
* StringUtils.equals("abc", "ABC") = false
|
||||
* StrUtils.equals(null, null) = true
|
||||
* StrUtils.equals(null, "abc") = false
|
||||
* StrUtils.equals("abc", null) = false
|
||||
* StrUtils.equals("abc", "abc") = true
|
||||
* StrUtils.equals("abc", "ABC") = false
|
||||
* </pre>
|
||||
*
|
||||
* @param cs1 第一个字符串, 可为 {@code null}
|
||||
@ -596,42 +559,4 @@ public final class MPJStringUtils {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* SQL 注入字符串去除空白内容:
|
||||
* <ul>
|
||||
* <li>\n 回车</li>
|
||||
* <li>\t 水平制表符</li>
|
||||
* <li>\s 空格</li>
|
||||
* <li>\r 换行</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param str 字符串
|
||||
*/
|
||||
public static String sqlInjectionReplaceBlank(String str) {
|
||||
if (MPJSqlInjectionUtils.check(str)) {
|
||||
/**
|
||||
* 过滤sql黑名单字符,存在 SQL 注入,去除空白内容
|
||||
*/
|
||||
str = replaceAllBlank(str);
|
||||
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串去除空白内容:
|
||||
* <ul>
|
||||
* <li>\n 回车</li>
|
||||
* <li>\t 水平制表符</li>
|
||||
* <li>\s 空格</li>
|
||||
* <li>\r 换行</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param str 字符串
|
||||
*/
|
||||
public static String replaceAllBlank(String str) {
|
||||
Matcher matcher = REPLACE_BLANK.matcher(str);
|
||||
return matcher.replaceAll("");
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.adapter.AdapterHelper;
|
||||
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
@ -17,71 +16,61 @@ import java.util.Optional;
|
||||
* @since 1.4.5
|
||||
*/
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public class WrapperUtils {
|
||||
public class WrapperUtils implements StringPool {
|
||||
|
||||
public static <T> String buildSubSqlByWrapper(Class<T> clazz, MPJLambdaWrapper<T> wrapper, String alias) {
|
||||
TableInfo tableInfo = TableHelper.getAssert(clazz);
|
||||
String first = Optional.ofNullable(wrapper.getSqlFirst()).orElse(StringPool.EMPTY);
|
||||
boolean hasWhere = false;
|
||||
String entityWhere = getEntitySql(tableInfo, wrapper);
|
||||
if (StringUtils.isNotBlank(entityWhere)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String mainLogic = mainLogic(hasWhere, clazz, wrapper);
|
||||
if (StringUtils.isNotBlank(mainLogic)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String subLogic = subLogic(hasWhere, wrapper);
|
||||
if (StringUtils.isNotBlank(subLogic)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String sqlSegment = (wrapper.getSqlSegment() != null && StringUtils.isNotBlank(wrapper.getSqlSegment())) ?
|
||||
((wrapper.isEmptyOfNormal() ? StringPool.EMPTY : (hasWhere ? " AND " : " WHERE ")) + wrapper.getSqlSegment()) : StringPool.EMPTY;
|
||||
|
||||
String sqlComment = Optional.ofNullable(wrapper.getSqlComment()).orElse(StringPool.EMPTY);
|
||||
return String.format(" (%s SELECT %s FROM %s %s %s %s %s %s %s) AS %s ",
|
||||
first,
|
||||
wrapper.getSqlSelect(),
|
||||
wrapper.getTableName(tableInfo.getTableName()),
|
||||
wrapper.getAlias(),
|
||||
wrapper.getFrom(),
|
||||
mainLogic,
|
||||
subLogic,
|
||||
sqlSegment,
|
||||
sqlComment,
|
||||
alias);
|
||||
return String.format("%s AS %s", buildUnionSqlByWrapper(clazz, wrapper), alias);
|
||||
}
|
||||
|
||||
public static String buildUnionSqlByWrapper(Class<?> clazz, MPJLambdaWrapper<?> wrapper) {
|
||||
return buildUnionSqlByWrapper(clazz, true, wrapper);
|
||||
}
|
||||
|
||||
public static String buildUnionSqlByWrapper(Class<?> clazz, boolean brackets, MPJLambdaWrapper<?> wrapper) {
|
||||
TableInfo tableInfo = TableHelper.getAssert(clazz);
|
||||
String first = Optional.ofNullable(wrapper.getSqlFirst()).orElse(StringPool.EMPTY);
|
||||
String first = Optional.ofNullable(wrapper.getSqlFirst()).orElse(EMPTY);
|
||||
boolean hasWhere = false;
|
||||
String entityWhere = getEntitySql(tableInfo, wrapper);
|
||||
if (StringUtils.isNotBlank(entityWhere)) {
|
||||
if (StrUtils.isNotBlank(entityWhere)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String mainLogic = mainLogic(hasWhere, clazz, wrapper);
|
||||
if (StringUtils.isNotBlank(mainLogic)) {
|
||||
if (StrUtils.isNotBlank(mainLogic)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String subLogic = subLogic(hasWhere, wrapper);
|
||||
if (StringUtils.isNotBlank(subLogic)) {
|
||||
if (StrUtils.isNotBlank(subLogic)) {
|
||||
hasWhere = true;
|
||||
}
|
||||
String sqlSegment = (wrapper.getSqlSegment() != null && StringUtils.isNotBlank(wrapper.getSqlSegment())) ?
|
||||
((wrapper.isEmptyOfNormal() ? StringPool.EMPTY : (hasWhere ? " AND " : " WHERE ")) + wrapper.getSqlSegment()) : StringPool.EMPTY;
|
||||
|
||||
String sqlComment = Optional.ofNullable(wrapper.getSqlComment()).orElse(StringPool.EMPTY);
|
||||
return String.format(" %s SELECT %s FROM %s %s %s %s %s %s %s ",
|
||||
first,
|
||||
wrapper.getSqlSelect(),
|
||||
wrapper.getTableName(tableInfo.getTableName()),
|
||||
wrapper.getAlias(),
|
||||
wrapper.getFrom(),
|
||||
mainLogic,
|
||||
subLogic,
|
||||
sqlSegment,
|
||||
sqlComment);
|
||||
String sqlSegment = (wrapper.getSqlSegment() != null && StrUtils.isNotBlank(wrapper.getSqlSegment())) ?
|
||||
((wrapper.isEmptyOfNormal() ? EMPTY : (hasWhere ? " AND " : " WHERE ")) + wrapper.getSqlSegment()) : EMPTY;
|
||||
String sqlComment = Optional.ofNullable(wrapper.getSqlComment()).orElse(EMPTY);
|
||||
String sqlUnion = wrapper.getUnionSql();
|
||||
StringBuilder sb = new StringBuilder(SPACE)
|
||||
.append(first)
|
||||
.append(" SELECT ")
|
||||
.append(wrapper.getSqlSelect())
|
||||
.append(" FROM ")
|
||||
.append(wrapper.getTableName(tableInfo.getTableName()))
|
||||
.append(SPACE)
|
||||
.append(wrapper.getAlias())
|
||||
.append(SPACE)
|
||||
.append(wrapper.getFrom())
|
||||
.append(SPACE)
|
||||
.append(mainLogic)
|
||||
.append(SPACE)
|
||||
.append(subLogic)
|
||||
.append(SPACE)
|
||||
.append(sqlSegment)
|
||||
.append(SPACE)
|
||||
.append(sqlComment)
|
||||
.append(SPACE)
|
||||
.append(sqlUnion)
|
||||
.append(SPACE);
|
||||
if (brackets) {
|
||||
sb.insert(0, "(").append(")");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static <T> String formatParam(MPJLambdaWrapper<T> wrapper, Object param) {
|
||||
@ -126,7 +115,7 @@ public class WrapperUtils {
|
||||
return StringPool.EMPTY;
|
||||
}
|
||||
String info = LogicInfoUtils.getLogicInfo(null, clazz, true, wrapper.getAlias());
|
||||
if (StringUtils.isNotBlank(info)) {
|
||||
if (StrUtils.isNotBlank(info)) {
|
||||
if (hasWhere) {
|
||||
return " AND " + info;
|
||||
}
|
||||
@ -137,7 +126,7 @@ public class WrapperUtils {
|
||||
|
||||
private static String subLogic(boolean hasWhere, MPJLambdaWrapper<?> wrapper) {
|
||||
String sql = wrapper.getSubLogicSql();
|
||||
if (StringUtils.isNotBlank(sql)) {
|
||||
if (StrUtils.isNotBlank(sql)) {
|
||||
if (hasWhere) {
|
||||
return sql;
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.github.yulichang.toolkit.reflect;
|
||||
|
||||
import com.github.yulichang.toolkit.ClassUtils;
|
||||
|
||||
/**
|
||||
* 泛型类工具(用于隔离Spring的代码)
|
||||
*
|
||||
@ -24,6 +26,22 @@ package com.github.yulichang.toolkit.reflect;
|
||||
*/
|
||||
@SuppressWarnings("ALL")
|
||||
public class GenericTypeUtils {
|
||||
|
||||
/**
|
||||
* 能否加载SpringCore包
|
||||
*
|
||||
* @since 3.5.4
|
||||
*/
|
||||
private static boolean loadSpringCore = false;
|
||||
|
||||
static {
|
||||
try {
|
||||
ClassUtils.toClassConfident("org.springframework.core.GenericTypeResolver");
|
||||
loadSpringCore = true;
|
||||
} catch (Exception exception) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
private static IGenericTypeResolver GENERIC_TYPE_RESOLVER;
|
||||
|
||||
/**
|
||||
@ -43,4 +61,15 @@ public class GenericTypeUtils {
|
||||
public static void setGenericTypeResolver(IGenericTypeResolver genericTypeResolver) {
|
||||
GENERIC_TYPE_RESOLVER = genericTypeResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有自定泛型提取类或能否加载SpringCore进行泛型提取
|
||||
*
|
||||
* @return 是否有实现
|
||||
* @since 3.5.4
|
||||
*/
|
||||
public static boolean hasGenericTypeResolver() {
|
||||
return GENERIC_TYPE_RESOLVER != null || loadSpringCore;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2024, baomidou (jobob@qq.com).
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package com.github.yulichang.toolkit.reflect;
|
||||
|
||||
import java.lang.reflect.GenericDeclaration;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 类型参数实现收集器,采集类型实现中各个类型参数的实际值
|
||||
* <p>
|
||||
* Create by hcl at 2023/9/25
|
||||
*/
|
||||
public class TypeParameterResolver {
|
||||
private final Map<TypeVariable<?>, Type> map;
|
||||
private final Set<Type> distinct;
|
||||
|
||||
protected TypeParameterResolver(Map<TypeVariable<?>, Type> map) {
|
||||
this.map = map;
|
||||
this.distinct = new HashSet<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类型上指定索引位置参数的实现信息
|
||||
*
|
||||
* @param source 类型
|
||||
* @param index 索引
|
||||
* @param type 实现类型
|
||||
* @return 返回类型实现或者 null
|
||||
*/
|
||||
public static Type resolveClassIndexedParameter(Type type, Class<?> source, int index) {
|
||||
return calculateParameterValue(resolveParameterValues(type), source.getTypeParameters()[index]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算参数值
|
||||
*
|
||||
* @param map 变量 Map
|
||||
* @param parameter 参数
|
||||
* @return 返回参数值
|
||||
*/
|
||||
public static Type calculateParameterValue(Map<TypeVariable<?>, Type> map, TypeVariable<?> parameter) {
|
||||
Type res = map.get(parameter);
|
||||
while (res instanceof TypeVariable<?>) {
|
||||
res = map.get(res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析指定类型下的泛型参数实现信息
|
||||
*
|
||||
* @param from 起始类型
|
||||
* @return 返回全部的泛型参数及其映射类型值
|
||||
*/
|
||||
public static Map<TypeVariable<?>, Type> resolveParameterValues(Type from) {
|
||||
Map<TypeVariable<?>, Type> map = new HashMap<>();
|
||||
new TypeParameterResolver(map).visitType(from);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 访问类型,类型中需要关注两个:{@link Class} 和 {@link ParameterizedType}
|
||||
*
|
||||
* @param type 类型
|
||||
*/
|
||||
public void visitType(Type type) {
|
||||
if (!distinct.add(type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (type instanceof Class<?>) {
|
||||
visitClass((Class<?>) type);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type instanceof ParameterizedType) {
|
||||
visitParameterizedType((ParameterizedType) type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 访问类型,类型的树可以分解为父类和接口,这两个地方都要解析。
|
||||
*
|
||||
* @param c 类
|
||||
*/
|
||||
private void visitClass(Class<?> c) {
|
||||
visitType(c.getGenericSuperclass());
|
||||
for (Type i : c.getGenericInterfaces()) {
|
||||
visitType(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 访问参数化类型,类型参数映射的主要逻辑就在这里
|
||||
*
|
||||
* @param parameterized 参数化类型
|
||||
*/
|
||||
private void visitParameterizedType(ParameterizedType parameterized) {
|
||||
Type raw = parameterized.getRawType();
|
||||
visitType(raw);
|
||||
|
||||
if (raw instanceof GenericDeclaration) {
|
||||
GenericDeclaration declaration = (GenericDeclaration) raw;
|
||||
TypeVariable<?>[] parameters = declaration.getTypeParameters();
|
||||
Type[] arguments = parameterized.getActualTypeArguments();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
TypeVariable<?> parameter = parameters[i];
|
||||
Type argument = arguments[i];
|
||||
map.put(parameter, argument);
|
||||
visitType(argument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.github.yulichang.toolkit.sql;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
|
||||
@ -42,16 +42,16 @@ public abstract class SqlScriptUtils implements Constants {
|
||||
public static String convertTrim(final String sqlScript, final String prefix, final String suffix,
|
||||
final String prefixOverrides, final String suffixOverrides) {
|
||||
StringBuilder sb = new StringBuilder("<trim");
|
||||
if (StringUtils.isNotBlank(prefix)) {
|
||||
if (StrUtils.isNotBlank(prefix)) {
|
||||
sb.append(" prefix=\"").append(prefix).append(QUOTE);
|
||||
}
|
||||
if (StringUtils.isNotBlank(suffix)) {
|
||||
if (StrUtils.isNotBlank(suffix)) {
|
||||
sb.append(" suffix=\"").append(suffix).append(QUOTE);
|
||||
}
|
||||
if (StringUtils.isNotBlank(prefixOverrides)) {
|
||||
if (StrUtils.isNotBlank(prefixOverrides)) {
|
||||
sb.append(" prefixOverrides=\"").append(prefixOverrides).append(QUOTE);
|
||||
}
|
||||
if (StringUtils.isNotBlank(suffixOverrides)) {
|
||||
if (StrUtils.isNotBlank(suffixOverrides)) {
|
||||
sb.append(" suffixOverrides=\"").append(suffixOverrides).append(QUOTE);
|
||||
}
|
||||
return sb.append(RIGHT_CHEV).append(NEWLINE).append(sqlScript).append(NEWLINE).append("</trim>").toString();
|
||||
@ -89,16 +89,16 @@ public abstract class SqlScriptUtils implements Constants {
|
||||
public static String convertForeach(final String sqlScript, final String collection, final String index,
|
||||
final String item, final String separator) {
|
||||
StringBuilder sb = new StringBuilder("<foreach");
|
||||
if (StringUtils.isNotBlank(collection)) {
|
||||
if (StrUtils.isNotBlank(collection)) {
|
||||
sb.append(" collection=\"").append(collection).append(QUOTE);
|
||||
}
|
||||
if (StringUtils.isNotBlank(index)) {
|
||||
if (StrUtils.isNotBlank(index)) {
|
||||
sb.append(" index=\"").append(index).append(QUOTE);
|
||||
}
|
||||
if (StringUtils.isNotBlank(item)) {
|
||||
if (StrUtils.isNotBlank(item)) {
|
||||
sb.append(" item=\"").append(item).append(QUOTE);
|
||||
}
|
||||
if (StringUtils.isNotBlank(separator)) {
|
||||
if (StrUtils.isNotBlank(separator)) {
|
||||
sb.append(" separator=\"").append(separator).append(QUOTE);
|
||||
}
|
||||
return sb.append(RIGHT_CHEV).append(NEWLINE).append(sqlScript).append(NEWLINE).append("</foreach>").toString();
|
||||
@ -151,7 +151,7 @@ public abstract class SqlScriptUtils implements Constants {
|
||||
*/
|
||||
public static String safeParam(final String param, final String mapping) {
|
||||
String target = HASH_LEFT_BRACE + param;
|
||||
if (StringUtils.isBlank(mapping)) {
|
||||
if (StrUtils.isBlank(mapping)) {
|
||||
return target + RIGHT_BRACE;
|
||||
}
|
||||
return target + COMMA + mapping + RIGHT_BRACE;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.github.yulichang.toolkit.support;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
|
||||
import lombok.Data;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@ -16,4 +17,30 @@ public class FieldCache {
|
||||
public Field field;
|
||||
|
||||
public Class<?> type;
|
||||
|
||||
public boolean isAccessible = false;
|
||||
|
||||
public Object getFieldValue(Object object) {
|
||||
try {
|
||||
if (!isAccessible) {
|
||||
isAccessible = true;
|
||||
field.setAccessible(true);
|
||||
}
|
||||
return field.get(object);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw ExceptionUtils.mpe(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFieldValue(Object source, Object value) {
|
||||
try {
|
||||
if (!isAccessible) {
|
||||
isAccessible = true;
|
||||
field.setAccessible(true);
|
||||
}
|
||||
field.set(source, value);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw ExceptionUtils.mpe(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.github.yulichang.toolkit.support;
|
||||
|
||||
import org.apache.ibatis.reflection.property.PropertyNamer;
|
||||
|
||||
/**
|
||||
* Lambda 信息
|
||||
* <p>
|
||||
@ -22,6 +24,10 @@ package com.github.yulichang.toolkit.support;
|
||||
*/
|
||||
public interface LambdaMeta {
|
||||
|
||||
default String getName() {
|
||||
return PropertyNamer.methodToProperty(getImplMethodName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 lambda 表达式实现方法的名称
|
||||
*
|
||||
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.github.yulichang.adapter.AdapterHelper;
|
||||
import com.github.yulichang.toolkit.LogicInfoUtils;
|
||||
import com.github.yulichang.toolkit.StrUtils;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.TableList;
|
||||
import com.github.yulichang.wrapper.interfaces.DeleteChain;
|
||||
@ -71,7 +72,7 @@ public class DeleteJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, DeleteJoi
|
||||
@Override
|
||||
@SuppressWarnings({"UnusedReturnValue", "DuplicatedCode"})
|
||||
public String getDeleteSql() {
|
||||
if (StringUtils.isNotBlank(this.deleteSql.getStringValue())) {
|
||||
if (StrUtils.isNotBlank(this.deleteSql.getStringValue())) {
|
||||
return this.deleteSql.getStringValue();
|
||||
}
|
||||
String delete = null;
|
||||
@ -89,7 +90,7 @@ public class DeleteJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, DeleteJoi
|
||||
if (CollectionUtils.isNotEmpty(deleteTableName)) {
|
||||
delete = delete + StringPool.COMMA + String.join(StringPool.COMMA, deleteTableName);
|
||||
}
|
||||
if (StringUtils.isBlank(delete)) {
|
||||
if (StrUtils.isBlank(delete)) {
|
||||
delete = this.alias;
|
||||
}
|
||||
deleteSql.setStringValue(delete);
|
||||
@ -102,7 +103,7 @@ public class DeleteJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, DeleteJoi
|
||||
@Override
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public String getDeleteLogicSql() {
|
||||
if (StringUtils.isNotBlank(this.deleteSql.getStringValue())) {
|
||||
if (StrUtils.isNotBlank(this.deleteSql.getStringValue())) {
|
||||
return this.deleteSql.getStringValue();
|
||||
}
|
||||
String delete = null;
|
||||
@ -120,7 +121,7 @@ public class DeleteJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, DeleteJoi
|
||||
if (CollectionUtils.isNotEmpty(deleteTableName)) {
|
||||
delete = delete + StringPool.COMMA + String.join(StringPool.COMMA, deleteTableName);
|
||||
}
|
||||
if (StringUtils.isNotBlank(delete)) {
|
||||
if (StrUtils.isNotBlank(delete)) {
|
||||
delete = StringPool.COMMA + delete;
|
||||
} else {
|
||||
delete = StringPool.EMPTY;
|
||||
|
@ -4,9 +4,9 @@ import com.baomidou.mybatisplus.annotation.OrderBy;
|
||||
import com.baomidou.mybatisplus.core.conditions.SharedString;
|
||||
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.adapter.AdapterHelper;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
@ -14,6 +14,8 @@ import com.github.yulichang.config.enums.LogicDelTypeEnum;
|
||||
import com.github.yulichang.toolkit.*;
|
||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
||||
import com.github.yulichang.wrapper.ext.Ext;
|
||||
import com.github.yulichang.wrapper.interfaces.MConsumer;
|
||||
import com.github.yulichang.wrapper.interfaces.MFunction;
|
||||
import com.github.yulichang.wrapper.interfaces.QueryJoin;
|
||||
import com.github.yulichang.wrapper.segments.PageInfo;
|
||||
@ -39,17 +41,8 @@ import static java.util.stream.Collectors.joining;
|
||||
*/
|
||||
@SuppressWarnings({"DuplicatedCode", "unused"})
|
||||
public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstractLambdaWrapper<T, Children>>
|
||||
extends JoinAbstractWrapper<T, Children> implements QueryJoin<Children, T> {
|
||||
extends JoinAbstractWrapper<T, Children> implements QueryJoin<Children, T>, Ext<Children> {
|
||||
|
||||
/**
|
||||
* 主表别名
|
||||
*/
|
||||
@Getter
|
||||
protected String alias = ConfigProperties.tableAlias;
|
||||
/**
|
||||
* 副表别名
|
||||
*/
|
||||
protected String subTableAlias = ConfigProperties.tableAlias;
|
||||
/**
|
||||
* 是否存在对一或对多
|
||||
*/
|
||||
@ -177,6 +170,12 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
||||
}
|
||||
}
|
||||
|
||||
public Children setAlias(String alias) {
|
||||
this.alias = alias;
|
||||
tableList.setAlias(alias);
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主表分页
|
||||
*/
|
||||
@ -221,6 +220,9 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
||||
|
||||
public String getTableName(String tableName) {
|
||||
if (isMain) {
|
||||
if (this.tableName != null) {
|
||||
return this.tableName;
|
||||
}
|
||||
if (dynamicTableName) {
|
||||
return tableFunc.apply(tableName);
|
||||
}
|
||||
@ -231,6 +233,9 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
||||
|
||||
|
||||
public String getTableNameEnc(String tableName) {
|
||||
if (this.tableName != null) {
|
||||
return this.tableName;
|
||||
}
|
||||
Class<T> entityClass = getEntityClass();
|
||||
if (entityClass != null) {
|
||||
TableInfo tableInfo = TableHelper.get(entityClass);
|
||||
@ -253,7 +258,6 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
||||
return decode;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SafeVarargs
|
||||
protected final <X> String columnsToString(Integer index, PrefixEnum prefixEnum, String alias, SFunction<X, ?>... columns) {
|
||||
@ -276,7 +280,10 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
||||
protected SelectCache getCache(SFunction<?, ?> fn) {
|
||||
Class<?> aClass = LambdaUtils.getEntityClass(fn);
|
||||
Map<String, SelectCache> cacheMap = ColumnCache.getMapField(aClass);
|
||||
return cacheMap.get(LambdaUtils.getName(fn));
|
||||
String name = LambdaUtils.getName(fn);
|
||||
SelectCache cache = cacheMap.get(name);
|
||||
Assert.notNull(cache, "column not found " + name);
|
||||
return cache;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -373,10 +380,10 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
||||
* 获取连表部分语句
|
||||
*/
|
||||
public String getFrom() {
|
||||
if (StringUtils.isBlank(from.getStringValue())) {
|
||||
if (StrUtils.isBlank(from.getStringValue())) {
|
||||
StringBuilder value = new StringBuilder();
|
||||
for (Children wrapper : onWrappers) {
|
||||
if (StringUtils.isBlank(wrapper.from.getStringValue())) {
|
||||
if (StrUtils.isBlank(wrapper.from.getStringValue())) {
|
||||
if (this.subLogicSql && this.logicDelType == LogicDelTypeEnum.ON) {
|
||||
TableInfo tableInfo = TableHelper.getAssert(wrapper.getJoinClass());
|
||||
if (AdapterHelper.getAdapter().mpjHasLogic(tableInfo)) {
|
||||
@ -423,19 +430,37 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
||||
});
|
||||
}
|
||||
|
||||
public Children from(MFunction<MPJLambdaWrapper<T>> fromWrapper) {
|
||||
Assert.notNull(getEntityClass(), "main table is null please use JoinWrapper.lambda(Class) or new MPJLambdaWrapper(Class)");
|
||||
MPJLambdaWrapper<T> wrapper = fromWrapper.apply(fromInstance(getEntityClass()));
|
||||
this.tableName = WrapperUtils.buildUnionSqlByWrapper(getEntityClass(), wrapper);
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
/**
|
||||
* 内部调用, 不建议使用
|
||||
*/
|
||||
@Override
|
||||
public <R> Children join(String keyWord, Class<R> clazz, String tableAlias, BiConsumer<JoinAbstractLambdaWrapper<T, ?>, Children> consumer) {
|
||||
public <R> Children join(String keyWord, Class<R> clazz, MConsumer<MPJLambdaWrapper<R>> table, String tableAlias, BiConsumer<JoinAbstractLambdaWrapper<T, ?>, Children> consumer) {
|
||||
String tabName;
|
||||
if (table != null) {
|
||||
MPJLambdaWrapper<R> tableWrapper = fromInstance(clazz);
|
||||
table.accept(tableWrapper);
|
||||
if (StrUtils.isBlank(tableWrapper.getSqlSelect())) {
|
||||
tableWrapper.selectAll();
|
||||
}
|
||||
tabName = WrapperUtils.buildUnionSqlByWrapper(clazz, tableWrapper);
|
||||
} else {
|
||||
TableInfo info = TableHelper.getAssert(clazz);
|
||||
tabName = info.getTableName();
|
||||
}
|
||||
Integer oldIndex = this.getIndex();
|
||||
int newIndex = tableIndex;
|
||||
TableInfo info = TableHelper.getAssert(clazz);
|
||||
Children instance = instance(newIndex, keyWord, clazz, info.getTableName());
|
||||
Children instance = instance(newIndex, keyWord, clazz, tabName);
|
||||
instance.isOn = true;
|
||||
instance.isMain = false;
|
||||
onWrappers.add(instance);
|
||||
if (StringUtils.isBlank(tableAlias)) {
|
||||
if (StrUtils.isBlank(tableAlias)) {
|
||||
tableList.put(oldIndex, clazz, false, subTableAlias, newIndex);
|
||||
instance.alias = subTableAlias;
|
||||
instance.hasAlias = false;
|
||||
@ -463,10 +488,10 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
||||
* @param joinSql sql
|
||||
*/
|
||||
@Override
|
||||
public Children join(String keyWord, boolean condition, String joinSql) {
|
||||
public Children join(String keyWord, boolean condition, String joinSql, Object... args) {
|
||||
if (condition) {
|
||||
Children wrapper = instanceEmpty();
|
||||
wrapper.from.setStringValue(joinSql);
|
||||
wrapper.from.setStringValue(formatSqlMaybeWithParam(joinSql, args));
|
||||
wrapper.keyWord = keyWord;
|
||||
onWrappers.add(wrapper);
|
||||
}
|
||||
@ -480,7 +505,7 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
||||
*/
|
||||
public boolean isUseAnnotationOrderBy() {
|
||||
final String _sqlSegment = this.getSqlSegment();
|
||||
if (StringUtils.isBlank(_sqlSegment)) {
|
||||
if (StrUtils.isBlank(_sqlSegment)) {
|
||||
return true;
|
||||
}
|
||||
final String _sqlSegmentToUpperCase = _sqlSegment.toUpperCase();
|
||||
|
@ -3,7 +3,6 @@ package com.github.yulichang.wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.ISqlSegment;
|
||||
import com.baomidou.mybatisplus.core.conditions.SharedString;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.interfaces.Nested;
|
||||
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
|
||||
import com.baomidou.mybatisplus.core.enums.SqlKeyword;
|
||||
import com.baomidou.mybatisplus.core.enums.SqlLike;
|
||||
@ -14,9 +13,7 @@ import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
import com.github.yulichang.toolkit.MPJSqlInjectionUtils;
|
||||
import com.github.yulichang.toolkit.Ref;
|
||||
import com.github.yulichang.toolkit.TableList;
|
||||
import com.github.yulichang.toolkit.*;
|
||||
import com.github.yulichang.toolkit.sql.SqlScriptUtils;
|
||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||
import com.github.yulichang.wrapper.enums.PrefixEnum;
|
||||
@ -27,7 +24,11 @@ import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.*;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.baomidou.mybatisplus.core.enums.SqlKeyword.*;
|
||||
import static com.baomidou.mybatisplus.core.enums.WrapperKeyword.APPLY;
|
||||
@ -44,6 +45,15 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
implements CompareIfExists<Children>, Nested<Children, Children>, Join<Children>, Func<Children>, OnCompare<Children>,
|
||||
CompareStrIfExists<Children, String>, FuncStr<Children, String> {
|
||||
|
||||
/**
|
||||
* 主表别名
|
||||
*/
|
||||
@Getter
|
||||
protected String alias = ConfigProperties.tableAlias;
|
||||
/**
|
||||
* 副表别名
|
||||
*/
|
||||
protected String subTableAlias = ConfigProperties.tableAlias;
|
||||
/**
|
||||
* 占位符
|
||||
*/
|
||||
@ -152,19 +162,35 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为子类,方便自定义继承扩展
|
||||
*/
|
||||
public <C extends Children> C toChildren(Ref<C> children) {
|
||||
return (C) this;
|
||||
protected <E> MPJLambdaWrapper<E> subInstance(Class<E> clazz, String st) {
|
||||
MPJLambdaWrapper<E> wrapper = new MPJLambdaWrapper<E>(null, clazz, SharedString.emptyString(),
|
||||
paramNameSeq, paramNameValuePairs, new MergeSegments(), new SharedString(this.paramAlias
|
||||
.getStringValue()), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||
new TableList(), null, null, null, null, ifExists) {
|
||||
};
|
||||
wrapper.tableList.setAlias(st);
|
||||
wrapper.tableList.setRootClass(clazz);
|
||||
wrapper.tableList.setParent(this.tableList);
|
||||
wrapper.alias = st;
|
||||
wrapper.subTableAlias = st;
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转为子类,方便自定义继承扩展
|
||||
* 需要子类自定义字段
|
||||
*/
|
||||
public <C extends Children> C toChildren(Supplier<C> s) {
|
||||
return (C) this;
|
||||
protected <E> MPJLambdaWrapper<E> fromInstance(Class<E> clazz) {
|
||||
MPJLambdaWrapper<E> wrapper = new MPJLambdaWrapper<E>(null, clazz, SharedString.emptyString(),
|
||||
paramNameSeq, paramNameValuePairs, new MergeSegments(), new SharedString(this.paramAlias
|
||||
.getStringValue()), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||
new TableList(), null, null, null, null, ifExists) {
|
||||
};
|
||||
wrapper.tableList.setAlias(ConfigProperties.tableAlias);
|
||||
wrapper.tableList.setRootClass(clazz);
|
||||
wrapper.alias = ConfigProperties.tableAlias;
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
protected <E> MPJLambdaWrapper<E> subInstance(Class<E> clazz) {
|
||||
return subInstance(clazz, ConfigProperties.subQueryAlias);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -182,7 +208,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
|
||||
/**
|
||||
* 设置 IfExists
|
||||
* .IfExists(val -> val != null && StringUtils.isNotBlank(val))
|
||||
* .IfExists(val -> val != null && StrUtils.isNotBlank(val))
|
||||
*
|
||||
* @param IfExists 判断
|
||||
* @return Children
|
||||
@ -196,7 +222,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
public <X, V> Children allEq(boolean condition, Map<SFunction<X, ?>, V> params, boolean null2IsNull) {
|
||||
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||
params.forEach((k, v) -> {
|
||||
if (StringUtils.checkValNotNull(v)) {
|
||||
if (StrUtils.checkValNotNull(v)) {
|
||||
eq(k, v);
|
||||
} else {
|
||||
if (null2IsNull) {
|
||||
@ -213,7 +239,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||
params.forEach((k, v) -> {
|
||||
if (filter.test(k, v)) {
|
||||
if (StringUtils.checkValNotNull(v)) {
|
||||
if (StrUtils.checkValNotNull(v)) {
|
||||
eq(k, v);
|
||||
} else {
|
||||
if (null2IsNull) {
|
||||
@ -231,31 +257,61 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
return addCondition(condition, alias, column, EQ, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X, Y> Children eq(boolean condition, String alias, SFunction<X, ?> column, Class<Y> clazz, MFunction<MPJLambdaWrapper<Y>> wrapper) {
|
||||
return addCondition(condition, alias, column, EQ, clazz, wrapper.apply(subInstance(clazz)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children ne(boolean condition, String alias, SFunction<X, ?> column, Object val) {
|
||||
return addCondition(condition, alias, column, NE, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X, Y> Children ne(boolean condition, String alias, SFunction<X, ?> column, Class<Y> clazz, MFunction<MPJLambdaWrapper<Y>> wrapper) {
|
||||
return addCondition(condition, alias, column, NE, clazz, wrapper.apply(subInstance(clazz)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children gt(boolean condition, String alias, SFunction<X, ?> column, Object val) {
|
||||
return addCondition(condition, alias, column, GT, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X, Y> Children gt(boolean condition, String alias, SFunction<X, ?> column, Class<Y> clazz, MFunction<MPJLambdaWrapper<Y>> wrapper) {
|
||||
return addCondition(condition, alias, column, GT, clazz, wrapper.apply(subInstance(clazz)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children ge(boolean condition, String alias, SFunction<X, ?> column, Object val) {
|
||||
return addCondition(condition, alias, column, GE, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X, Y> Children ge(boolean condition, String alias, SFunction<X, ?> column, Class<Y> clazz, MFunction<MPJLambdaWrapper<Y>> wrapper) {
|
||||
return addCondition(condition, alias, column, GE, clazz, wrapper.apply(subInstance(clazz)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children lt(boolean condition, String alias, SFunction<X, ?> column, Object val) {
|
||||
return addCondition(condition, alias, column, LT, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X, Y> Children lt(boolean condition, String alias, SFunction<X, ?> column, Class<Y> clazz, MFunction<MPJLambdaWrapper<Y>> wrapper) {
|
||||
return addCondition(condition, alias, column, LT, clazz, wrapper.apply(subInstance(clazz)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children le(boolean condition, String alias, SFunction<X, ?> column, Object val) {
|
||||
return addCondition(condition, alias, column, LE, val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X, Y> Children le(boolean condition, String alias, SFunction<X, ?> column, Class<Y> clazz, MFunction<MPJLambdaWrapper<Y>> wrapper) {
|
||||
return addCondition(condition, alias, column, LE, clazz, wrapper.apply(subInstance(clazz)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children like(boolean condition, String alias, SFunction<X, ?> column, Object val) {
|
||||
return likeValue(condition, LIKE, alias, column, val, SqlLike.DEFAULT);
|
||||
@ -326,24 +382,33 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
@Override
|
||||
public Children apply(boolean condition, String applySql, Object... values) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(APPLY,
|
||||
() -> formatSqlMaybeWithParam(applySql, null, values)));
|
||||
() -> formatSqlMaybeWithParam(applySql, values)));
|
||||
}
|
||||
|
||||
public Children applyFunc(String applySql, SFunction<FuncConsumer, SFunction<?, ?>[]> consumerFunction, Object... values) {
|
||||
public Children applyFunc(String applySql, MFunction<FuncConsumer> consumerFunction, Object... values) {
|
||||
return applyFunc(true, applySql, consumerFunction, values);
|
||||
}
|
||||
|
||||
public Children applyFunc(boolean condition, String applySql,
|
||||
Function<FuncConsumer, SFunction<?, ?>[]> consumerFunction, Object... values) {
|
||||
MFunction<FuncConsumer> consumerFunction, Object... values) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(APPLY,
|
||||
() -> formatSqlMaybeWithParam(String.format(applySql,
|
||||
Arrays.stream(consumerFunction.apply(FuncConsumer.func)).map(func -> {
|
||||
if (func instanceof Fun) {
|
||||
Fun<?, ?> fun = (Fun<?, ?>) func;
|
||||
return columnToString(index, fun.getAlias(), fun.getFunc(), false, PrefixEnum.CD_FIRST, false);
|
||||
}
|
||||
return columnToString(index, null, func, false, PrefixEnum.CD_FIRST, false);
|
||||
}).toArray()), null, values)));
|
||||
() -> {
|
||||
FuncConsumer funcConsumer = consumerFunction.apply(new FuncConsumer());
|
||||
return formatSqlMaybeWithParam(String.format(applySql,
|
||||
Arrays.stream(funcConsumer.getArgs()).map(func -> {
|
||||
if (func instanceof Fun) {
|
||||
Fun<?, ?> fun = (Fun<?, ?>) func;
|
||||
if (fun.isSub()) {
|
||||
@SuppressWarnings("rawtypes")
|
||||
MPJLambdaWrapper wrapper = fun.getSub().apply((MPJLambdaWrapper) subInstance(fun.getClazz()));
|
||||
return WrapperUtils.buildUnionSqlByWrapper(fun.getClazz(),
|
||||
fun.getSub().apply(wrapper));
|
||||
}
|
||||
return columnToString(index, fun.getAlias(), fun.getFunc(), false, PrefixEnum.CD_FIRST, false);
|
||||
}
|
||||
return columnToString(index, null, func, false, PrefixEnum.CD_FIRST, false);
|
||||
}).toArray()), ArrayUtils.isEmpty(values) ? funcConsumer.getValues() : values);
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -380,7 +445,13 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
@Override
|
||||
public Children exists(boolean condition, String existsSql, Object... values) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(EXISTS,
|
||||
() -> String.format("(%s)", formatSqlMaybeWithParam(existsSql, null, values))));
|
||||
() -> String.format("(%s)", formatSqlMaybeWithParam(existsSql, values))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children exists(boolean condition, Class<X> clazz, MFunction<MPJLambdaWrapper<X>> wrapper) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(EXISTS,
|
||||
() -> WrapperUtils.buildUnionSqlByWrapper(clazz, wrapper.apply(subInstance(clazz)))));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -388,21 +459,44 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
return not(condition).exists(condition, existsSql, values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children notExists(boolean condition, Class<X> clazz, MFunction<MPJLambdaWrapper<X>> wrapper) {
|
||||
return not(condition).exists(condition, clazz, wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children isNull(boolean condition, String alias, SFunction<X, ?> column) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, alias, column, false), IS_NULL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children isNull(boolean condition, String alias, Class<X> clazz, MFunction<MPJLambdaWrapper<X>> wrapper) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(() ->
|
||||
WrapperUtils.buildUnionSqlByWrapper(clazz, wrapper.apply(fromInstance(clazz))), IS_NULL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children isNotNull(boolean condition, String alias, SFunction<X, ?> column) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, alias, column, false), IS_NOT_NULL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children isNotNull(boolean condition, String alias, Class<X> clazz, MFunction<MPJLambdaWrapper<X>> wrapper) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(() ->
|
||||
WrapperUtils.buildUnionSqlByWrapper(clazz, wrapper.apply(fromInstance(clazz))), IS_NOT_NULL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children in(boolean condition, String alias, SFunction<X, ?> column, Collection<?> coll) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, alias, column, false), IN, inExpression(coll)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X, Y> Children in(boolean condition, String alias, SFunction<X, ?> column, Class<Y> clazz, MFunction<MPJLambdaWrapper<Y>> wrapper) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, alias, column, false), IN, () ->
|
||||
WrapperUtils.buildUnionSqlByWrapper(clazz, wrapper.apply(fromInstance(clazz)))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children in(boolean condition, String alias, SFunction<X, ?> column, Object... values) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, alias, column, false), IN, inExpression(values)));
|
||||
@ -413,6 +507,12 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, alias, column, false), NOT_IN, inExpression(coll)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X, Y> Children notIn(boolean condition, String alias, SFunction<X, ?> column, Class<Y> clazz, MFunction<MPJLambdaWrapper<Y>> wrapper) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, alias, column, false), NOT_IN, () ->
|
||||
WrapperUtils.buildUnionSqlByWrapper(clazz, wrapper.apply(fromInstance(clazz)))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> Children notIn(boolean condition, String alias, SFunction<X, ?> column, Object... values) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, alias, column, false), NOT_IN, inExpression(values)));
|
||||
@ -619,7 +719,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
@Override
|
||||
public Children having(boolean condition, String sqlHaving, Object... params) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(HAVING,
|
||||
() -> formatSqlMaybeWithParam(sqlHaving, null, params)));
|
||||
() -> formatSqlMaybeWithParam(sqlHaving, params)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -676,6 +776,11 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
() -> formatParam(null, val)));
|
||||
}
|
||||
|
||||
protected <X, R> Children addCondition(boolean condition, String alias, SFunction<X, ?> column, SqlKeyword sqlKeyword, Class<R> clazz, MPJLambdaWrapper<R> val) {
|
||||
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(index, alias, column, false), sqlKeyword,
|
||||
() -> WrapperUtils.buildUnionSqlByWrapper(clazz, val)));
|
||||
}
|
||||
|
||||
protected <X, S> Children addCondition(boolean condition, String alias, SFunction<X, ?> column,
|
||||
SqlKeyword sqlKeyword, String rightAlias, SFunction<S, ?> val) {
|
||||
Class<X> c = LambdaUtils.getEntityClass(column);
|
||||
@ -718,21 +823,27 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
* <p>
|
||||
* 支持 "{0}" 这种,或者 "sql {0} sql" 这种
|
||||
*
|
||||
* @param sqlStr 可能是sql片段
|
||||
* @param mapping 例如: "javaType=int,jdbcType=NUMERIC,typeHandler=xxx.xxx.MyTypeHandler" 这种
|
||||
* @param params 参数
|
||||
* @param sqlStr 可能是sql片段
|
||||
* @param params 参数
|
||||
* @return sql片段
|
||||
*/
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
protected final String formatSqlMaybeWithParam(String sqlStr, String mapping, Object... params) {
|
||||
if (StringUtils.isBlank(sqlStr)) {
|
||||
// todo 何时会这样?
|
||||
protected final String formatSqlMaybeWithParam(String sqlStr, Object... params) {
|
||||
if (StrUtils.isBlank(sqlStr)) {
|
||||
return null;
|
||||
}
|
||||
if (ArrayUtils.isNotEmpty(params)) {
|
||||
for (int i = 0; i < params.length; ++i) {
|
||||
final String target = Constants.LEFT_BRACE + i + Constants.RIGHT_BRACE;
|
||||
sqlStr = sqlStr.replace(target, formatParam(mapping, params[i]));
|
||||
String target = Constants.LEFT_BRACE + i + Constants.RIGHT_BRACE;
|
||||
if (sqlStr.contains(target)) {
|
||||
sqlStr = sqlStr.replace(target, formatParam(null, params[i]));
|
||||
} else {
|
||||
Matcher matcher = Pattern.compile("[{]" + i + ",[a-zA-Z0-9.,=]+}").matcher(sqlStr);
|
||||
if (!matcher.find()) {
|
||||
throw ExceptionUtils.mpe("Please check the syntax correctness! sql not contains: \"%s\"", target);
|
||||
}
|
||||
String group = matcher.group();
|
||||
sqlStr = sqlStr.replace(group, formatParam(group.substring(target.length(), group.length() - 1), params[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return sqlStr;
|
||||
@ -827,7 +938,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
|
||||
@Override
|
||||
public String getSqlComment() {
|
||||
if (StringUtils.isNotBlank(sqlComment.getStringValue())) {
|
||||
if (StrUtils.isNotBlank(sqlComment.getStringValue())) {
|
||||
return "/*" + StringEscape.escapeRawString(sqlComment.getStringValue()) + "*/";
|
||||
}
|
||||
return null;
|
||||
@ -835,7 +946,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
|
||||
@Override
|
||||
public String getSqlFirst() {
|
||||
if (StringUtils.isNotBlank(sqlFirst.getStringValue())) {
|
||||
if (StrUtils.isNotBlank(sqlFirst.getStringValue())) {
|
||||
return StringEscape.escapeRawString(sqlFirst.getStringValue());
|
||||
}
|
||||
return null;
|
||||
@ -962,7 +1073,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
public <V> Children allEqStr(boolean condition, Map<String, V> params, boolean null2IsNull) {
|
||||
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||
params.forEach((k, v) -> {
|
||||
if (StringUtils.checkValNotNull(v)) {
|
||||
if (StrUtils.checkValNotNull(v)) {
|
||||
eq(k, v);
|
||||
} else {
|
||||
if (null2IsNull) {
|
||||
@ -979,7 +1090,7 @@ public abstract class JoinAbstractWrapper<T, Children extends JoinAbstractWrappe
|
||||
if (condition && CollectionUtils.isNotEmpty(params)) {
|
||||
params.forEach((k, v) -> {
|
||||
if (filter.test(k, v)) {
|
||||
if (StringUtils.checkValNotNull(v)) {
|
||||
if (StrUtils.checkValNotNull(v)) {
|
||||
eq(k, v);
|
||||
} else {
|
||||
if (null2IsNull) {
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.github.yulichang.wrapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.SharedString;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.config.ConfigProperties;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
import com.github.yulichang.toolkit.*;
|
||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||
import com.github.yulichang.wrapper.enums.IfExistsSqlKeyWordEnum;
|
||||
@ -27,7 +28,7 @@ import java.util.stream.Collectors;
|
||||
* @author yulichang
|
||||
*/
|
||||
@SuppressWarnings({"unused", "DuplicatedCode"})
|
||||
public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaWrapper<T>> implements
|
||||
public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaWrapper<T>> implements Fill<MPJLambdaWrapper<T>>,
|
||||
Query<MPJLambdaWrapper<T>>, QueryLabel<MPJLambdaWrapper<T>>, Chain<T>, SelectWrapper<T, MPJLambdaWrapper<T>> {
|
||||
|
||||
/**
|
||||
@ -54,16 +55,7 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
*/
|
||||
private SharedString unionSql;
|
||||
|
||||
/**
|
||||
* 自定义wrapper索引
|
||||
*/
|
||||
private AtomicInteger wrapperIndex;
|
||||
|
||||
/**
|
||||
* 自定义wrapper
|
||||
*/
|
||||
@Getter
|
||||
private Map<String, Wrapper<?>> wrapperMap;
|
||||
private List<MConsumer<Object>> fill;
|
||||
|
||||
/**
|
||||
* 推荐使用 带 class 的构造方法
|
||||
@ -232,6 +224,20 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
return selectAll(getEntityClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPJLambdaWrapper<T> selectFunc(String sql, MFunction<FuncConsumer> column, String alias) {
|
||||
FuncConsumer funcConsumer = column.apply(new FuncConsumer());
|
||||
String formatSql;
|
||||
if (ArrayUtils.isEmpty(funcConsumer.getValues())) {
|
||||
formatSql = sql;
|
||||
} else {
|
||||
formatSql = formatSqlMaybeWithParam(sql, funcConsumer.getValues());
|
||||
}
|
||||
getSelectColum().add(new SelectFunc(alias, getIndex(), () -> formatSql,
|
||||
funcConsumer.getArgs(), isHasAlias(), getAlias()));
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
/**
|
||||
* 子查询
|
||||
*/
|
||||
@ -239,27 +245,24 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
return selectSub(clazz, ConfigProperties.subQueryAlias, consumer, alias);
|
||||
}
|
||||
|
||||
public <E, F> MPJLambdaWrapper<T> selectSub(Class<E> clazz, String st, Consumer<MPJLambdaWrapper<E>> consumer, SFunction<F, ?> alias) {
|
||||
return selectSub(clazz, st, consumer, LambdaUtils.getName(alias));
|
||||
}
|
||||
|
||||
/**
|
||||
* 子查询
|
||||
*/
|
||||
public <E, F> MPJLambdaWrapper<T> selectSub(Class<E> clazz, String st, Consumer<MPJLambdaWrapper<E>> consumer, SFunction<F, ?> alias) {
|
||||
MPJLambdaWrapper<E> wrapper = new MPJLambdaWrapper<E>(null, clazz, SharedString.emptyString(),
|
||||
paramNameSeq, paramNameValuePairs, new MergeSegments(), new SharedString(this.paramAlias
|
||||
.getStringValue()), SharedString.emptyString(), SharedString.emptyString(), SharedString.emptyString(),
|
||||
new TableList(), null, null, null, null, ifExists) {
|
||||
};
|
||||
wrapper.tableList.setAlias(st);
|
||||
wrapper.tableList.setRootClass(clazz);
|
||||
wrapper.tableList.setParent(this.tableList);
|
||||
wrapper.alias = st;
|
||||
wrapper.subTableAlias = st;
|
||||
public <E, F> MPJLambdaWrapper<T> selectSub(Class<E> clazz, String st, Consumer<MPJLambdaWrapper<E>> consumer, String alias) {
|
||||
MPJLambdaWrapper<E> wrapper = subInstance(clazz, st);
|
||||
consumer.accept(wrapper);
|
||||
addCustomWrapper(wrapper);
|
||||
String name = LambdaUtils.getName(alias);
|
||||
this.selectColumns.add(new SelectSub(() -> WrapperUtils.buildSubSqlByWrapper(clazz, wrapper, name), hasAlias, this.alias, name));
|
||||
this.selectColumns.add(new SelectSub(() -> WrapperUtils.buildSubSqlByWrapper(clazz, wrapper, alias), hasAlias, this.alias, alias));
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
public <U> MPJLambdaWrapper<T> union(Class<U> clazz, Consumer<MPJLambdaWrapper<U>> consumer) {
|
||||
return union(clazz, true, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* union
|
||||
* <p>
|
||||
@ -268,13 +271,10 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
* @param clazz union语句的主表类型
|
||||
* @since 1.4.8
|
||||
*/
|
||||
public <U> MPJLambdaWrapper<T> union(Class<U> clazz, Consumer<MPJLambdaWrapper<U>> consumer) {
|
||||
MPJLambdaWrapper<U> unionWrapper = JoinWrappers.lambda(clazz);
|
||||
addCustomWrapper(unionWrapper);
|
||||
public <U> MPJLambdaWrapper<T> union(Class<U> clazz, boolean brackets, Consumer<MPJLambdaWrapper<U>> consumer) {
|
||||
MPJLambdaWrapper<U> unionWrapper = fromInstance(clazz);
|
||||
consumer.accept(unionWrapper);
|
||||
|
||||
String sb = " UNION " + WrapperUtils.buildUnionSqlByWrapper(clazz, unionWrapper);
|
||||
|
||||
if (Objects.isNull(unionSql)) {
|
||||
unionSql = SharedString.emptyString();
|
||||
}
|
||||
@ -282,6 +282,25 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPJLambdaWrapper<T> addFill(MConsumer<Object> consumer) {
|
||||
if (this.fill == null) {
|
||||
this.fill = new ArrayList<>();
|
||||
}
|
||||
this.fill.add(consumer);
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFill(Object obj) {
|
||||
if (this.fill != null) {
|
||||
this.fill.forEach(c -> c.accept(obj));
|
||||
}
|
||||
}
|
||||
|
||||
public <U> MPJLambdaWrapper<T> unionAll(Class<U> clazz, Consumer<MPJLambdaWrapper<U>> consumer) {
|
||||
return unionAll(clazz, true, consumer);
|
||||
}
|
||||
|
||||
/**
|
||||
* union
|
||||
@ -291,13 +310,10 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
* @param clazz union语句的主表类型
|
||||
* @since 1.4.8
|
||||
*/
|
||||
public <U> MPJLambdaWrapper<T> unionAll(Class<U> clazz, Consumer<MPJLambdaWrapper<U>> consumer) {
|
||||
MPJLambdaWrapper<U> unionWrapper = JoinWrappers.lambda(clazz);
|
||||
addCustomWrapper(unionWrapper);
|
||||
public <U> MPJLambdaWrapper<T> unionAll(Class<U> clazz, boolean brackets, Consumer<MPJLambdaWrapper<U>> consumer) {
|
||||
MPJLambdaWrapper<U> unionWrapper = fromInstance(clazz);
|
||||
consumer.accept(unionWrapper);
|
||||
|
||||
String sb = " UNION ALL " + WrapperUtils.buildUnionSqlByWrapper(clazz, unionWrapper);
|
||||
|
||||
String sb = " UNION ALL " + WrapperUtils.buildUnionSqlByWrapper(clazz, brackets, unionWrapper);
|
||||
if (Objects.isNull(unionSql)) {
|
||||
unionSql = SharedString.emptyString();
|
||||
}
|
||||
@ -305,25 +321,12 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
return typedThis;
|
||||
}
|
||||
|
||||
private void addCustomWrapper(MPJLambdaWrapper<?> wrapper) {
|
||||
if (Objects.isNull(wrapperIndex)) {
|
||||
wrapperIndex = new AtomicInteger(0);
|
||||
}
|
||||
int index = wrapperIndex.incrementAndGet();
|
||||
if (Objects.isNull(wrapperMap)) {
|
||||
wrapperMap = new HashMap<>();
|
||||
}
|
||||
String key = "ew" + index;
|
||||
wrapper.setParamAlias(wrapper.getParamAlias() + ".wrapperMap." + key);
|
||||
wrapperMap.put(key, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询条件 SQL 片段
|
||||
*/
|
||||
@Override
|
||||
public String getSqlSelect() {
|
||||
if (StringUtils.isBlank(sqlSelect.getStringValue()) && CollectionUtils.isNotEmpty(selectColumns)) {
|
||||
if (StrUtils.isBlank(sqlSelect.getStringValue()) && CollectionUtils.isNotEmpty(selectColumns)) {
|
||||
String s = selectColumns.stream().map(i -> {
|
||||
if (i.isStr()) {
|
||||
return i.getColumn();
|
||||
@ -341,10 +344,15 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
return String.format(i.getFunc().getSql(), str) + Constant.AS + i.getAlias();
|
||||
} else {
|
||||
return String.format(i.getFunc().getSql(), Arrays.stream(args).map(arg -> {
|
||||
String pf = arg.isHasTableAlias() ? arg.getTableAlias() : tableList.getPrefixByClass(arg.getClazz());
|
||||
Map<String, SelectCache> mapField = ColumnCache.getMapField(arg.getClazz());
|
||||
SelectCache cache = mapField.get(arg.getProp());
|
||||
return pf + StringPool.DOT + cache.getColumn();
|
||||
if (arg.isSub()) {
|
||||
Object o = arg.getSubFunc().apply(subInstance(arg.getClazz()));
|
||||
return WrapperUtils.buildUnionSqlByWrapper(arg.getClazz(), (MPJLambdaWrapper<?>) o);
|
||||
} else {
|
||||
String pf = arg.isHasTableAlias() ? arg.getTableAlias() : tableList.getPrefixByClass(arg.getClazz());
|
||||
Map<String, SelectCache> mapField = ColumnCache.getMapField(arg.getClazz());
|
||||
SelectCache cache = mapField.get(arg.getProp());
|
||||
return pf + StringPool.DOT + cache.getColumn();
|
||||
}
|
||||
}).toArray()) + Constant.AS + i.getAlias();
|
||||
}
|
||||
} else {
|
||||
@ -392,10 +400,9 @@ public class MPJLambdaWrapper<T> extends JoinAbstractLambdaWrapper<T, MPJLambdaW
|
||||
selectDistinct = false;
|
||||
sqlSelect.toNull();
|
||||
selectColumns.clear();
|
||||
wrapperIndex = new AtomicInteger(0);
|
||||
if (Objects.nonNull(wrapperMap)) wrapperMap.clear();
|
||||
if (Objects.nonNull(unionSql)) unionSql.toEmpty();
|
||||
resultMapMybatisLabel.clear();
|
||||
ifExists = ConfigProperties.ifExists;
|
||||
fill = null;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import com.github.yulichang.adapter.AdapterHelper;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
import com.github.yulichang.toolkit.ReflectionKit;
|
||||
import com.github.yulichang.toolkit.*;
|
||||
import com.github.yulichang.wrapper.interfaces.MFunction;
|
||||
import com.github.yulichang.wrapper.interfaces.Update;
|
||||
import com.github.yulichang.wrapper.interfaces.UpdateChain;
|
||||
import com.github.yulichang.wrapper.segments.FuncConsumer;
|
||||
@ -127,14 +128,14 @@ public class UpdateJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, UpdateJoi
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateJoinWrapper<T> setApply(boolean condition, String applySql, SFunction<FuncConsumer, SFunction<?, ?>[]> consumerFunction, Object... values) {
|
||||
if (condition && StringUtils.isNotBlank(applySql)) {
|
||||
SFunction<?, ?>[] arg = consumerFunction.apply(FuncConsumer.func);
|
||||
public UpdateJoinWrapper<T> setApply(boolean condition, String applySql, MFunction<FuncConsumer> consumerFunction, Object... values) {
|
||||
if (condition && StrUtils.isNotBlank(applySql)) {
|
||||
FuncConsumer funcConsumer = consumerFunction.apply(new FuncConsumer());
|
||||
UpdateSet set = new UpdateSet();
|
||||
set.setApply(true);
|
||||
set.setFormat(applySql);
|
||||
set.setColumns(arg);
|
||||
set.setArgs(values);
|
||||
set.setColumns(funcConsumer.getArgs());
|
||||
set.setArgs(ArrayUtils.isNotEmpty(values) ? values : funcConsumer.getValues());
|
||||
getUpdateSet().add(set);
|
||||
}
|
||||
return typedThis;
|
||||
@ -142,7 +143,7 @@ public class UpdateJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, UpdateJoi
|
||||
|
||||
@Override
|
||||
public UpdateJoinWrapper<T> setSql(boolean condition, String sql) {
|
||||
if (condition && StringUtils.isNotBlank(sql)) {
|
||||
if (condition && StrUtils.isNotBlank(sql)) {
|
||||
if (Objects.isNull(sqlSet)) {
|
||||
sqlSet = new ArrayList<>();
|
||||
}
|
||||
@ -154,7 +155,7 @@ public class UpdateJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, UpdateJoi
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
@Override
|
||||
public String getSqlSet() {
|
||||
if (StringUtils.isNotBlank(sqlSetStr.getStringValue())) {
|
||||
if (StrUtils.isNotBlank(sqlSetStr.getStringValue())) {
|
||||
return sqlSetStr.getStringValue();
|
||||
}
|
||||
StringBuilder set = new StringBuilder(StringPool.EMPTY);
|
||||
@ -164,7 +165,7 @@ public class UpdateJoinWrapper<T> extends JoinAbstractLambdaWrapper<T, UpdateJoi
|
||||
String col = String.format(i.format, Arrays.stream(i.columns).map(f ->
|
||||
tableList.getPrefixByClass(LambdaUtils.getEntityClass(f)) +
|
||||
Constants.DOT + getCache(f).getColumn()).toArray());
|
||||
return formatSqlMaybeWithParam(col, null, i.args);
|
||||
return formatSqlMaybeWithParam(col, i.args);
|
||||
} else {
|
||||
String col = tableList.getPrefixByClass(LambdaUtils.getEntityClass(i.getColumn())) +
|
||||
Constants.DOT + getCache(i.getColumn()).getColumn();
|
||||
|
@ -2,7 +2,6 @@ package com.github.yulichang.wrapper.interfaces;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
@ -12,7 +11,7 @@ import java.util.function.BiPredicate;
|
||||
* {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface Compare<Children> extends Serializable {
|
||||
public interface Compare<Children> extends CompareWrapper<Children> {
|
||||
|
||||
|
||||
default <R, V> Children allEq(Map<SFunction<R, ?>, V> params) {
|
||||
|
@ -0,0 +1,151 @@
|
||||
package com.github.yulichang.wrapper.interfaces;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 将原来的泛型R改成SFunction<R, ?>
|
||||
* <p>
|
||||
* {@link com.baomidou.mybatisplus.core.conditions.interfaces.Compare}
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface CompareWrapper<Children> extends Serializable {
|
||||
|
||||
default <R, T> Children eq(SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return eq(true, null, column, clazz, val);
|
||||
}
|
||||
|
||||
default <R, T> Children eq(String alias, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return eq(true, alias, column, clazz, val);
|
||||
}
|
||||
|
||||
default <R, T> Children eq(boolean condition, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return eq(condition, null, column, clazz, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 等于 =
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
<R, T> Children eq(boolean condition, String alias, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val);
|
||||
|
||||
default <R, T> Children ne(SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return ne(true, null, column, clazz, val);
|
||||
}
|
||||
|
||||
default <R, T> Children ne(String alias, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return ne(true, alias, column, clazz, val);
|
||||
}
|
||||
|
||||
default <R, T> Children ne(boolean condition, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return ne(condition, null, column, clazz, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 不等于 <>
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param alias 字段别名
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
<R, T> Children ne(boolean condition, String alias, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val);
|
||||
|
||||
|
||||
default <R, T> Children gt(SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return gt(true, null, column, clazz, val);
|
||||
}
|
||||
|
||||
default <R, T> Children gt(String alias, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return gt(true, alias, column, clazz, val);
|
||||
}
|
||||
|
||||
default <R, T> Children gt(boolean condition, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return gt(condition, null, column, clazz, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 大于 >
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
<R, T> Children gt(boolean condition, String alias, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val);
|
||||
|
||||
default <R, T> Children ge(SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return ge(true, null, column, clazz, val);
|
||||
}
|
||||
|
||||
default <R, T> Children ge(String alias, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return ge(true, alias, column, clazz, val);
|
||||
}
|
||||
|
||||
default <R, T> Children ge(boolean condition, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return ge(condition, null, column, clazz, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 大于等于 >=
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
<R, T> Children ge(boolean condition, String alias, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val);
|
||||
|
||||
|
||||
default <R, T> Children lt(SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return lt(true, null, column, clazz, val);
|
||||
}
|
||||
|
||||
default <R, T> Children lt(String alias, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return lt(true, alias, column, clazz, val);
|
||||
}
|
||||
|
||||
default <R, T> Children lt(boolean condition, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return lt(condition, null, column, clazz, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小于 <
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
<R, T> Children lt(boolean condition, String alias, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val);
|
||||
|
||||
|
||||
default <R, T> Children le(SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return le(true, null, column, clazz, val);
|
||||
}
|
||||
|
||||
default <R, T> Children le(String alias, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return le(true, alias, column, clazz, val);
|
||||
}
|
||||
|
||||
default <R, T> Children le(boolean condition, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val) {
|
||||
return le(condition, null, column, clazz, val);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小于等于 <=
|
||||
*
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param val 值
|
||||
* @return children
|
||||
*/
|
||||
<R, T> Children le(boolean condition, String alias, SFunction<R, ?> column, Class<T> clazz, MFunction<MPJLambdaWrapper<T>> val);
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.github.yulichang.wrapper.interfaces;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.toolkit.FillUtils;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
|
||||
|
||||
/**
|
||||
* 填充
|
||||
*
|
||||
* @auther yulichang
|
||||
* @since 1.5.1
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "unused", "UnusedReturnValue"})
|
||||
public interface Fill<Children> {
|
||||
|
||||
Children addFill(MConsumer<Object> consumer);
|
||||
|
||||
default <R> Children fill(SFunction<R, ?> field, SFunction<R, ?> tagField) {
|
||||
return addFill(c -> FillUtils.fill(c, field, tagField));
|
||||
}
|
||||
|
||||
default <T, X> Children fill(SFunction<T, ?> field, SFunction<T, X> tagField, MConsumer<MPJLambdaWrapper<X>> consumer) {
|
||||
return addFill(c -> FillUtils.fill(c, field, tagField, (MConsumer<MPJLambdaWrapper<?>>) ((Object) consumer)));
|
||||
}
|
||||
|
||||
default <T, X> Children fill(SFunction<T, ?> field, Class<X> oneClass, SFunction<T, ?> tagField) {
|
||||
return addFill(c -> FillUtils.fill(c, field, oneClass, tagField));
|
||||
}
|
||||
|
||||
default <T, X> Children fill(SFunction<T, ?> field, Class<X> oneClass, SFunction<T, ?> tagField, MConsumer<MPJLambdaWrapper<X>> consumer) {
|
||||
return addFill(c -> FillUtils.fill(c, field, oneClass, tagField, (MConsumer<MPJLambdaWrapper<?>>) ((Object) consumer)));
|
||||
}
|
||||
|
||||
default <T, X> Children fill(SFunction<T, ?> field, SFunction<X, ?> oneField, SFunction<T, ?> tagField) {
|
||||
return addFill(c -> FillUtils.fill(c, field, oneField, tagField));
|
||||
}
|
||||
|
||||
default <T, X> Children fill(SFunction<T, ?> field, SFunction<X, ?> oneField, SFunction<T, ?> tagField, MConsumer<MPJLambdaWrapper<X>> consumer) {
|
||||
return addFill(c -> FillUtils.fill(c, field, oneField, tagField, (MConsumer<MPJLambdaWrapper<?>>) ((Object) consumer)));
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ package com.github.yulichang.wrapper.interfaces;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
@ -13,7 +12,7 @@ import java.util.function.Consumer;
|
||||
* copy {@link com.baomidou.mybatisplus.core.conditions.interfaces.Func}
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public interface Func<Children> extends Serializable {
|
||||
public interface Func<Children> extends FuncWrapper<Children> {
|
||||
|
||||
|
||||
default <R> Children isNull(SFunction<R, ?> column) {
|
||||
@ -514,7 +513,6 @@ public interface Func<Children> extends Serializable {
|
||||
*/
|
||||
Children having(boolean condition, String sqlHaving, Object... params);
|
||||
|
||||
|
||||
default Children func(Consumer<Children> consumer) {
|
||||
return func(true, consumer);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import java.util.List;
|
||||
*
|
||||
* @since 1.3.12
|
||||
*/
|
||||
@SuppressWarnings("ALL")
|
||||
@SuppressWarnings({"unused", "unchecked"})
|
||||
public interface FuncStr<Children, R> extends Serializable {
|
||||
|
||||
/**
|
||||
@ -164,10 +164,10 @@ public interface FuncStr<Children, R> extends Serializable {
|
||||
* <p>例1: gtSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||
* <p>例1: gtSql("id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param condition
|
||||
* @param column
|
||||
* @param inValue
|
||||
* @return
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param inValue sql语句
|
||||
* @return children
|
||||
*/
|
||||
Children gtSql(boolean condition, R column, String inValue);
|
||||
|
||||
@ -183,10 +183,10 @@ public interface FuncStr<Children, R> extends Serializable {
|
||||
* <p>例1: geSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||
* <p>例1: geSql("id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param condition
|
||||
* @param column
|
||||
* @param inValue
|
||||
* @return
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param inValue sql语句
|
||||
* @return children
|
||||
*/
|
||||
Children geSql(boolean condition, R column, String inValue);
|
||||
|
||||
@ -202,10 +202,10 @@ public interface FuncStr<Children, R> extends Serializable {
|
||||
* <p>例1: ltSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||
* <p>例1: ltSql("id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param condition
|
||||
* @param column
|
||||
* @param inValue
|
||||
* @return
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param inValue sql语句
|
||||
* @return children
|
||||
*/
|
||||
Children ltSql(boolean condition, R column, String inValue);
|
||||
|
||||
@ -221,10 +221,10 @@ public interface FuncStr<Children, R> extends Serializable {
|
||||
* <p>例1: leSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||
* <p>例1: leSql("id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param condition
|
||||
* @param column
|
||||
* @param inValue
|
||||
* @return
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param inValue sql语句
|
||||
* @return children
|
||||
*/
|
||||
Children leSql(boolean condition, R column, String inValue);
|
||||
|
||||
@ -240,10 +240,10 @@ public interface FuncStr<Children, R> extends Serializable {
|
||||
* <p>例1: eqSql("id", "1, 2, 3, 4, 5, 6")</p>
|
||||
* <p>例1: eqSql("id", "select id from table where name = 'JunJun'")</p>
|
||||
*
|
||||
* @param condition
|
||||
* @param column
|
||||
* @param inValue
|
||||
* @return
|
||||
* @param condition 执行条件
|
||||
* @param column 字段
|
||||
* @param inValue sql语句
|
||||
* @return children
|
||||
*/
|
||||
Children eqSql(boolean condition, R column, String inValue);
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user