io.github.dengchen2020.mybatis.methods.SoftDeleteMethod Maven / Gradle / Ivy
package io.github.dengchen2020.mybatis.methods;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import io.github.dengchen2020.mybatis.base.BaseMybatisRepository;
import org.apache.ibatis.mapping.MappedStatement;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Field;
/**
* 逻辑删除
*
* @author dengchen
* @since 2024/6/22
*/
public class SoftDeleteMethod extends AbstractMethod {
public SoftDeleteMethod(String methodName) {
super(methodName);
}
/**
* 获取软删除的值
*/
private Object getSoftDeletedValue(Class> entityClass) {
Field field = ReflectionUtils.findField(entityClass, "deleted");
if (field != null && field.getType().equals(Boolean.class)) return Boolean.TRUE;
return 1;
}
@Override
public MappedStatement injectMappedStatement(Class> mapperClass, Class> modelClass, TableInfo tableInfo) {
String sql = """";
return addUpdateMappedStatement(BaseMybatisRepository.class, Iterable.class, languageDriver.createSqlSource(configuration, sql, Iterable.class));
}
}