diff --git a/openhis-server/core-common/src/main/java/com/core/common/biz/HisBaseMapper.java b/openhis-server/core-common/src/main/java/com/core/common/biz/HisBaseMapper.java new file mode 100644 index 00000000..cb6eaadb --- /dev/null +++ b/openhis-server/core-common/src/main/java/com/core/common/biz/HisBaseMapper.java @@ -0,0 +1,65 @@ +package com.core.common.biz; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.toolkit.Constants; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Update; +import org.springframework.core.annotation.AnnotationUtils; + +import java.util.List; + +public interface HisBaseMapper extends BaseMapper { + + /** + * 根据ID逻辑删除单条记录 + */ + default int logicalDelById(Long id) { + String tableName = getTableName(); + return logicalDelById(tableName, id); + } + + /** + * 根据ID列表批量逻辑删除记录 + */ + default int logicalDelByIds(List ids) { + String tableName = getTableName(); + return logicalDelByIds(tableName, ids); + } + + /** + * 根据 UpdateWrapper 逻辑删除记录 + */ + default int logicalDelByWrapper(UpdateWrapper updateWrapper) { + String tableName = getTableName(); + return logicalDelByWrapper(updateWrapper, tableName); + } + + @Update("UPDATE ${tableName} SET delete_flag = 1 WHERE id = #{id}") + int logicalDelById(@Param("tableName") String tableName, @Param("id") Long id); + + @Update({ + "" + }) + int logicalDelByIds(@Param("tableName") String tableName, @Param("ids") List ids); + + @Update("UPDATE ${tableName} SET delete_flag = 1 ${ew.customSqlSegment}") + int logicalDelByWrapper(@Param(Constants.WRAPPER) UpdateWrapper updateWrapper, @Param("tableName") String tableName); + + /** + * 获取表名 + */ + default String getTableName() { + TableName tableNameAnnotation = AnnotationUtils.findAnnotation(this.getClass(), TableName.class); + if (tableNameAnnotation == null) { + throw new RuntimeException("Table name annotation not found on Mapper interface"); + } + return tableNameAnnotation.value(); + } +}