fix 逻辑删除

This commit is contained in:
yulichang 2022-11-23 17:20:20 +08:00
parent 7afb9f6a1e
commit 01376dcc0c
2 changed files with 11 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
import com.baomidou.mybatisplus.core.toolkit.Assert; import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -28,11 +29,15 @@ public class LogicInfoUtils implements Constants {
} }
TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz); TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz);
Assert.notNull(tableInfo, "%s 不是数据库实体或没有注册到mybatis plus中", clazz.getName()); Assert.notNull(tableInfo, "%s 不是数据库实体或没有注册到mybatis plus中", clazz.getName());
final String value = tableInfo.getLogicDeleteFieldInfo().getLogicNotDeleteValue(); if (tableInfo.isWithLogicDelete() && Objects.nonNull(tableInfo.getLogicDeleteFieldInfo())) {
if (NULL.equalsIgnoreCase(value)) { final String value = tableInfo.getLogicDeleteFieldInfo().getLogicNotDeleteValue();
logicStr = Constant.TABLE_ALIAS + tableIndex + DOT + tableInfo.getLogicDeleteFieldInfo().getColumn() + " IS NULL"; if (NULL.equalsIgnoreCase(value)) {
logicStr = " AND " + Constant.TABLE_ALIAS + tableIndex + DOT + tableInfo.getLogicDeleteFieldInfo().getColumn() + " IS NULL";
} else {
logicStr = " AND " + Constant.TABLE_ALIAS + tableIndex + DOT + tableInfo.getLogicDeleteFieldInfo().getColumn() + EQUALS + String.format(tableInfo.getLogicDeleteFieldInfo().isCharSequence() ? "'%s'" : "%s", value);
}
} else { } else {
logicStr = Constant.TABLE_ALIAS + tableIndex + DOT + tableInfo.getLogicDeleteFieldInfo().getColumn() + EQUALS + String.format(tableInfo.getLogicDeleteFieldInfo().isCharSequence() ? "'%s'" : "%s", value); logicStr = StringPool.EMPTY;
} }
LOGIC_CACHE.put(clazz, logicStr); LOGIC_CACHE.put(clazz, logicStr);
return logicStr; return logicStr;

View File

@ -401,8 +401,8 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
if (CollectionUtils.isEmpty(subTable)) { if (CollectionUtils.isEmpty(subTable)) {
return StringPool.EMPTY; return StringPool.EMPTY;
} }
return "AND " + subTable.entrySet().stream().map(entry -> return subTable.entrySet().stream().map(entry -> LogicInfoUtils.getLogicInfo(entry.getValue(),
LogicInfoUtils.getLogicInfo(entry.getValue(), entry.getKey())).collect(Collectors.joining(" AND ")); entry.getKey())).collect(Collectors.joining(StringPool.SPACE));
} }
return StringPool.EMPTY; return StringPool.EMPTY;
} }