执行逻辑删除的时候,同时修改主键字段值增加删除标识,方便再次使用这个主键值

This commit is contained in:
thinkgem
2023-05-18 09:25:10 +08:00
parent 7a11c061e4
commit 82f223687f
12 changed files with 55 additions and 36 deletions

View File

@@ -560,7 +560,14 @@ mybatis:
# 批量插入和更新的分批默认大小防止库一次性接受不了太大的sql语句
defaultBatchSize: 500
# 执行逻辑删除的时候,同时修改主键字段值,方便再次使用这个主键值 v5.4.0+
# 案例分析(角色管理场景):
# 1.如果是逻辑删除数据,并非物理删除,所以删除了角色 abc 再次新增时,会提示 abc 编号已存在
# 2.使用方法为:在 super.delete(entity); 前调用entity.sqlMap().markIdDelete();
# 3.一般在手动填写主键业务中使用,启用后将会在删除后,修改 ID 值数据例如abc__del_随机串
markIdDeleteFlag: __del_
# Mapper文件刷新线程
mapper:
refresh:

View File

@@ -259,6 +259,9 @@ public class ${ClassName}Service extends ${table.isTreeEntity?'Tree':'Crud'}Serv
@Override
@Transactional
public void delete(${ClassName} ${className}) {
<% if (table.pkList.~size > 0 && table.pkList[0].showType == 'input') { %>
${className}.sqlMap().markIdDelete(); // 逻辑删除时标记ID值
<% } %>
super.delete(${className});
<% for (child in table.childList) { %>
${@StringUtils.cap(child.className)} ${@StringUtils.uncap(child.className)} = new ${@StringUtils.cap(child.className)}();

View File

@@ -269,6 +269,9 @@ public class ${ClassName}Service extends ${table.isTreeEntity?'Tree':'Crud'}Serv
@GlobalTransactional
@Transactional
public void delete(${ClassName} ${className}) {
<% if (table.pkList.~size > 0 && table.pkList[0].showType == 'input') { %>
${className}.sqlMap().markIdDelete(); // 逻辑删除时标记ID值
<% } %>
super.delete(${className});
<% for (child in table.childList) { %>
${@StringUtils.cap(child.className)} ${@StringUtils.uncap(child.className)} = new ${@StringUtils.cap(child.className)}();