From 8b2b85d2e546cf2164c330d65c05d0bc99d38e62 Mon Sep 17 00:00:00 2001 From: Suomm <1474983351@qq.com> Date: Wed, 26 Jul 2023 18:33:10 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20998b6b7=20from=20https://gitee.com/Suom?= =?UTF-8?q?m/mybatis-flex/pulls/188=20feat:=20=E6=B7=BB=E5=8A=A0=E4=B8=BB?= =?UTF-8?q?=E9=94=AE=E9=80=BB=E8=BE=91=E5=88=A0=E9=99=A4=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=99=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/PrimaryKeyLogicDeleteProcessor.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/PrimaryKeyLogicDeleteProcessor.java diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/PrimaryKeyLogicDeleteProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/PrimaryKeyLogicDeleteProcessor.java new file mode 100644 index 00000000..40f041fa --- /dev/null +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/logicdelete/impl/PrimaryKeyLogicDeleteProcessor.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.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.mybatisflex.core.logicdelete.impl; + +import com.mybatisflex.core.FlexGlobalConfig; +import com.mybatisflex.core.dialect.IDialect; +import com.mybatisflex.core.exception.FlexAssert; +import com.mybatisflex.core.logicdelete.AbstractLogicDeleteProcessor; +import com.mybatisflex.core.table.IdInfo; +import com.mybatisflex.core.table.TableInfo; + +import java.util.List; + +import static com.mybatisflex.core.constant.SqlConsts.EQUALS; + +/** + * 主键逻辑删除处理器。 + * + * @author 王帅 + * @see I7O1VV + * @since 2023-07-26 + */ +public class PrimaryKeyLogicDeleteProcessor extends AbstractLogicDeleteProcessor { + + @Override + public String buildLogicDeletedSet(String logicColumn, TableInfo tableInfo, IDialect dialect) { + List primaryKeyList = tableInfo.getPrimaryKeyList(); + FlexAssert.notEmpty(primaryKeyList, "Must have one primary key."); + String column = primaryKeyList.get(0).getColumn(); + return dialect.wrap(logicColumn) + EQUALS + dialect.wrap(column); + } + + /** + * 正常未删除的值为 0 (或者可配置为其他值)。 + */ + @Override + public Object getLogicNormalValue() { + Object normalValueOfLogicDelete = FlexGlobalConfig.getDefaultConfig().getNormalValueOfLogicDelete(); + if (normalValueOfLogicDelete instanceof Number) { + return normalValueOfLogicDelete; + } + return 0; + } + + /** + * 逻辑删除后,则更新逻辑删除字段值为主键的值。 + */ + @Override + public Object getLogicDeletedValue() { + return null; + } + +}