From 34e4acdc6ac39867f4b59b3533625d16e3a80203 Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Wed, 17 Jan 2024 16:48:51 +0800 Subject: [PATCH] =?UTF-8?q?update=E5=92=8Cdelete=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=93=BE=E5=BC=8F=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yulichang/wrapper/DeleteJoinWrapper.java | 3 +- .../yulichang/wrapper/UpdateJoinWrapper.java | 3 +- .../wrapper/interfaces/DeleteChain.java | 36 +++++++++ .../wrapper/interfaces/UpdateChain.java | 78 +++++++++++++++++++ 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/DeleteChain.java create mode 100644 mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/UpdateChain.java diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/DeleteJoinWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/DeleteJoinWrapper.java index 887c7d9..21e136b 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/DeleteJoinWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/DeleteJoinWrapper.java @@ -9,6 +9,7 @@ import com.github.yulichang.toolkit.Asserts; import com.github.yulichang.toolkit.LogicInfoUtils; import com.github.yulichang.toolkit.TableHelper; import com.github.yulichang.toolkit.TableList; +import com.github.yulichang.wrapper.interfaces.DeleteChain; import java.util.ArrayList; import java.util.Arrays; @@ -21,7 +22,7 @@ import java.util.stream.Collectors; * @author yulichang * @since 1.4.5 */ -public class DeleteJoinWrapper extends JoinAbstractLambdaWrapper> { +public class DeleteJoinWrapper extends JoinAbstractLambdaWrapper> implements DeleteChain { /** * 删除表 diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/UpdateJoinWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/UpdateJoinWrapper.java index 36f221d..478ddfc 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/UpdateJoinWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/UpdateJoinWrapper.java @@ -12,6 +12,7 @@ import com.github.yulichang.toolkit.LambdaUtils; import com.github.yulichang.toolkit.TableHelper; import com.github.yulichang.toolkit.TableList; import com.github.yulichang.wrapper.interfaces.Update; +import com.github.yulichang.wrapper.interfaces.UpdateChain; import lombok.AllArgsConstructor; import lombok.Data; @@ -29,7 +30,7 @@ import java.util.stream.Collectors; */ @SuppressWarnings("unused") public class UpdateJoinWrapper extends JoinAbstractLambdaWrapper> - implements Update> { + implements Update>, UpdateChain { /** * SQL 更新字段内容,例如:name='1', age=2 */ diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/DeleteChain.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/DeleteChain.java new file mode 100644 index 0000000..47ebf02 --- /dev/null +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/DeleteChain.java @@ -0,0 +1,36 @@ +package com.github.yulichang.wrapper.interfaces; + +import com.baomidou.mybatisplus.core.toolkit.Assert; +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.interfaces.MPJBaseJoin; +import com.github.yulichang.toolkit.SqlHelper; + +/** + * 链式调用 + *

+ * 构造方法必须传 class 或 entity 否则会报错
+ * new DeleteJoinWrapper(User.class)
+ * JoinWrappers.delete(User.class)
+ * + * @author yulichang + * @since 1.4.10 + */ +public interface DeleteChain { + + Class getEntityClass(); + + /** + * 链式调用 + *

+ * 构造方法必须传 class 或 entity 否则会报错
+ * new DeleteJoinWrapper(User.class)
+ * JoinWrappers.delete(User.class)
+ */ + @SuppressWarnings({"unused", "unchecked"}) + default int deleteJoin() { + return SqlHelper.exec(getEntityClass(), mapper -> { + Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName()); + return ((MPJBaseMapper) mapper).deleteJoin((MPJBaseJoin) this); + }); + } +} diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/UpdateChain.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/UpdateChain.java new file mode 100644 index 0000000..30fb8eb --- /dev/null +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/UpdateChain.java @@ -0,0 +1,78 @@ +package com.github.yulichang.wrapper.interfaces; + +import com.baomidou.mybatisplus.core.toolkit.Assert; +import com.github.yulichang.base.MPJBaseMapper; +import com.github.yulichang.interfaces.MPJBaseJoin; +import com.github.yulichang.toolkit.SqlHelper; + +/** + * 链式调用 + *

+ * 构造方法必须传 class 或 entity 否则会报错
+ * new UpdateJoinWrapper(User.class)
+ * JoinWrappers.update(User.class)
+ * + * @author yulichang + * @since 1.4.10 + */ +@SuppressWarnings({"unchecked", "unused"}) +public interface UpdateChain { + + Class getEntityClass(); + + /** + * 链式调用 + *

+ * 构造方法必须传 class 或 entity 否则会报错
+ * new UpdateJoinWrapper(User.class)
+ * JoinWrappers.update(User.class)
+ */ + default int update() { + return SqlHelper.exec(getEntityClass(), mapper -> { + Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName()); + return ((MPJBaseMapper) mapper).updateJoin(null, (MPJBaseJoin) this); + }); + } + + /** + * 链式调用 + *

+ * 构造方法必须传 class 或 entity 否则会报错
+ * new UpdateJoinWrapper(User.class)
+ * JoinWrappers.update(User.class)
+ */ + default int update(T entity) { + return SqlHelper.exec(getEntityClass(), mapper -> { + Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName()); + return ((MPJBaseMapper) mapper).updateJoin(entity, (MPJBaseJoin) this); + }); + } + + /** + * 链式调用 + *

+ * 构造方法必须传 class 或 entity 否则会报错
+ * new UpdateJoinWrapper(User.class)
+ * JoinWrappers.update(User.class)
+ */ + default int updateAndNull() { + return SqlHelper.exec(getEntityClass(), mapper -> { + Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName()); + return ((MPJBaseMapper) mapper).updateJoinAndNull(null, (MPJBaseJoin) this); + }); + } + + /** + * 链式调用 + *

+ * 构造方法必须传 class 或 entity 否则会报错
+ * new UpdateJoinWrapper(User.class)
+ * JoinWrappers.update(User.class)
+ */ + default int updateAndNull(T entity) { + return SqlHelper.exec(getEntityClass(), mapper -> { + Assert.isTrue(mapper instanceof MPJBaseMapper, "mapper <%s> is not extends MPJBaseMapper", mapper.getClass().getSimpleName()); + return ((MPJBaseMapper) mapper).updateJoinAndNull(entity, (MPJBaseJoin) this); + }); + } +}