增加物理删除

This commit is contained in:
cuijiawang 2025-09-22 17:54:33 +08:00
parent d379f79869
commit 59e5777e28
4 changed files with 103 additions and 0 deletions

View File

@ -0,0 +1,25 @@
package com.agileboot.common.mybatis.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import java.io.Serializable;
import java.util.Collection;
/**
* @Author cuiJiaWang
* @Create 2025-09-22 16:41
*/
public interface BaseMapperDelete<T> extends BaseMapper<T> {
/**
* 物理删除
*/
int deleteAbsoluteById(Serializable id);
/**
* 批量物理删除
*/
int deleteAbsoluteByIds(@Param(Constants.COLL) Collection<?> idList);
}

View File

@ -0,0 +1,21 @@
package com.agileboot.common.mybatis.mapper;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import java.util.List;
/**
* @Author cuiJiaWang
* @Create 2025-09-22 16:46
*/
public class CustomSqlInjector extends DefaultSqlInjector {
@Override
public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
methodList.add(new DeleteAbsoluteById());
methodList.add(new DeleteAbsoluteByIds());
return methodList;
}
}

View File

@ -0,0 +1,28 @@
package com.agileboot.common.mybatis.mapper;
import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
/**
* @Author cuiJiaWang
* @Create 2025-09-22 16:45
*/
public class DeleteAbsoluteById extends AbstractMethod {
private static final String method = "deleteAbsoluteById";
public DeleteAbsoluteById() {
super(method);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
SqlMethod sqlMethod = SqlMethod.DELETE_BY_ID;
String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), tableInfo.getKeyColumn(), tableInfo.getKeyProperty());
SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sql, Object.class);
return this.addDeleteMappedStatement(mapperClass, method, sqlSource);
}
}

View File

@ -0,0 +1,29 @@
package com.agileboot.common.mybatis.mapper;
import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.sql.SqlScriptUtils;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
/**
* @Author cuiJiaWang
* @Create 2025-09-22 16:49
*/
public class DeleteAbsoluteByIds extends AbstractMethod {
private static final String method = "deleteAbsoluteByIds";
public DeleteAbsoluteByIds() {
super(method);
}
@Override
public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
SqlMethod sqlMethod = SqlMethod.DELETE_BY_IDS;
String sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), tableInfo.getKeyColumn(), SqlScriptUtils.convertForeach(SqlScriptUtils.convertChoose("@org.apache.ibatis.type.SimpleTypeRegistry@isSimpleType(item.getClass())", "#{item}", "#{item." + tableInfo.getKeyProperty() + "}"), "coll", (String) null, "item", ","));
SqlSource sqlSource = this.languageDriver.createSqlSource(this.configuration, sql, Object.class);
return this.addDeleteMappedStatement(mapperClass, method, sqlSource);
}
}