From e61495cc6bbb0587e09a1e2c17777e52aee9c734 Mon Sep 17 00:00:00 2001 From: "Wang.Huan" Date: Fri, 21 Feb 2025 12:29:35 +0800 Subject: [PATCH] =?UTF-8?q?mapper=E5=B0=81=E8=A3=85=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=9A=84=E6=96=B9=E6=B3=95:=20=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1Mapper=E7=B1=BB=E9=9C=80=E8=A6=81=E7=BB=A7=E6=89=BFHis?= =?UTF-8?q?BaseMapper,=E4=B8=94=E5=8A=A0=E4=B8=8A@TableName=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3=E6=8C=87=E5=AE=9A=E8=A1=A8=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/core/common/biz/HisBaseMapper.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 openhis-server/core-common/src/main/java/com/core/common/biz/HisBaseMapper.java 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(); + } +}