!216 fix: 构建逻辑删除查询正常值错误。

Merge pull request !216 from 王帅/main
This commit is contained in:
Michael Yang 2023-07-30 10:22:20 +00:00 committed by Gitee
commit 388d6506da
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 55 additions and 40 deletions

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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;
import com.mybatisflex.core.dialect.IDialect;
import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.table.TableInfo;
/**
* 数据列默认值为 {@code null} 值的逻辑删除处理器
*
* @author 王帅
* @since 2023-07-30
*/
public abstract class NullableColumnLogicDeleteProcessor extends AbstractLogicDeleteProcessor {
@Override
public String buildLogicNormalCondition(String logicColumn, TableInfo tableInfo, IDialect dialect) {
return dialect.wrap(logicColumn) + " IS NULL";
}
@Override
public void buildQueryCondition(QueryWrapper queryWrapper, TableInfo tableInfo) {
QueryColumn queryColumn = new QueryColumn(tableInfo.getSchema(), tableInfo.getTableName(), tableInfo.getLogicDeleteColumn());
queryWrapper.and(queryColumn.isNull());
}
/**
* 逻辑删除字段值为 {@code null} 表示数据未删除
*/
@Override
public Object getLogicNormalValue() {
return null;
}
}

View File

@ -16,11 +16,7 @@
package com.mybatisflex.core.logicdelete.impl;
import com.mybatisflex.core.dialect.IDialect;
import com.mybatisflex.core.logicdelete.AbstractLogicDeleteProcessor;
import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.table.TableInfo;
import com.mybatisflex.core.logicdelete.NullableColumnLogicDeleteProcessor;
/**
* {@link java.time.LocalDateTime} 类型的属性对应的逻辑删除处理器
@ -28,26 +24,7 @@ import com.mybatisflex.core.table.TableInfo;
* @author 王帅
* @since 2023-06-20
*/
public class DateTimeLogicDeleteProcessor extends AbstractLogicDeleteProcessor {
@Override
public String buildLogicNormalCondition(String logicColumn, TableInfo tableInfo, IDialect dialect) {
return dialect.wrap(logicColumn) + " IS NULL";
}
@Override
public void buildQueryCondition(QueryWrapper queryWrapper, TableInfo tableInfo) {
QueryColumn queryColumn = new QueryColumn(tableInfo.getSchema(), tableInfo.getTableName(), tableInfo.getLogicDeleteColumn());
queryWrapper.and(queryColumn.isNull());
}
/**
* 逻辑删除字段值为 {@code null} 表示数据未删除
*/
@Override
public Object getLogicNormalValue() {
return null;
}
public class DateTimeLogicDeleteProcessor extends NullableColumnLogicDeleteProcessor {
/**
* 逻辑删除字段值为 {@code NOW()} 表示数据删除并记录删除时间

View File

@ -18,7 +18,7 @@ package com.mybatisflex.core.logicdelete.impl;
import com.mybatisflex.core.dialect.IDialect;
import com.mybatisflex.core.exception.FlexAssert;
import com.mybatisflex.core.logicdelete.AbstractLogicDeleteProcessor;
import com.mybatisflex.core.logicdelete.NullableColumnLogicDeleteProcessor;
import com.mybatisflex.core.table.IdInfo;
import com.mybatisflex.core.table.TableInfo;
@ -33,12 +33,7 @@ import static com.mybatisflex.core.constant.SqlConsts.EQUALS;
* @see <a href="https://gitee.com/mybatis-flex/mybatis-flex/issues/I7O1VV">I7O1VV</a>
* @since 2023-07-26
*/
public class PrimaryKeyLogicDeleteProcessor extends AbstractLogicDeleteProcessor {
@Override
public String buildLogicNormalCondition(String logicColumn, TableInfo tableInfo, IDialect dialect) {
return dialect.wrap(logicColumn) + " IS NULL";
}
public class PrimaryKeyLogicDeleteProcessor extends NullableColumnLogicDeleteProcessor {
@Override
public String buildLogicDeletedSet(String logicColumn, TableInfo tableInfo, IDialect dialect) {
@ -48,14 +43,6 @@ public class PrimaryKeyLogicDeleteProcessor extends AbstractLogicDeleteProcessor
return dialect.wrap(logicColumn) + EQUALS + dialect.wrap(column);
}
/**
* 正常未删除的值为 {@code null}兼容不同的主键类型
*/
@Override
public Object getLogicNormalValue() {
return null;
}
/**
* 逻辑删除后则更新逻辑删除字段值为主键的值
*/