001/* 002 * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.mybatisflex.core.logicdelete.impl; 017 018import com.mybatisflex.core.FlexGlobalConfig; 019import com.mybatisflex.core.logicdelete.AbstractLogicDeleteProcessor; 020import com.mybatisflex.core.query.QueryCondition; 021import com.mybatisflex.core.query.QueryWrapper; 022import com.mybatisflex.core.table.TableInfo; 023 024import static com.mybatisflex.core.constant.SqlConsts.EQUALS; 025import static com.mybatisflex.core.constant.SqlConsts.SINGLE_QUOTE; 026 027/** 028 * 默认逻辑删除处理器。 029 */ 030public class DefaultLogicDeleteProcessor extends AbstractLogicDeleteProcessor { 031 032 @Override 033 public void buildQueryCondition(QueryWrapper queryWrapper, TableInfo tableInfo) { 034 queryWrapper.where(QueryCondition.create(tableInfo.getSchema(), tableInfo.getTableName(), tableInfo.getLogicDeleteColumn() 035 , EQUALS, FlexGlobalConfig.getDefaultConfig().getNormalValueOfLogicDelete())); 036 } 037 038 039 @Override 040 protected Object getLogicNormalValue() { 041 Object normalValueOfLogicDelete = FlexGlobalConfig.getDefaultConfig().getNormalValueOfLogicDelete(); 042 if (normalValueOfLogicDelete instanceof Number 043 || normalValueOfLogicDelete instanceof Boolean) { 044 return normalValueOfLogicDelete; 045 } 046 return SINGLE_QUOTE + normalValueOfLogicDelete + SINGLE_QUOTE; 047 } 048 049 050 @Override 051 protected Object getLogicDeletedValue() { 052 Object deletedValueOfLogicDelete = FlexGlobalConfig.getDefaultConfig().getDeletedValueOfLogicDelete(); 053 if (deletedValueOfLogicDelete instanceof Number 054 || deletedValueOfLogicDelete instanceof Boolean) { 055 return deletedValueOfLogicDelete; 056 } 057 return SINGLE_QUOTE + deletedValueOfLogicDelete + SINGLE_QUOTE; 058 } 059 060} 061 062