执行逻辑删除的时候,同时修改主键字段值增加删除标识,方便再次使用这个主键值
This commit is contained in:
@@ -106,6 +106,7 @@ public class CategoryService extends TreeService<CategoryDao, Category> {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Category category) {
|
public void delete(Category category) {
|
||||||
|
category.sqlMap().markIdDelete();
|
||||||
super.delete(category);
|
super.delete(category);
|
||||||
// 清理首页、栏目和文章页面缓存
|
// 清理首页、栏目和文章页面缓存
|
||||||
if (pageCacheService != null) {
|
if (pageCacheService != null) {
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ public class SiteService extends CrudService<SiteDao, Site> {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public void updateStatus(Site site) {
|
public void updateStatus(Site site) {
|
||||||
super.updateStatus(site);
|
super.updateStatus(site);
|
||||||
|
CmsUtils.removeCache("siteList");
|
||||||
// 清理首页、栏目和文章页面缓存
|
// 清理首页、栏目和文章页面缓存
|
||||||
if (pageCacheService != null) {
|
if (pageCacheService != null) {
|
||||||
pageCacheService.clearCache(site);
|
pageCacheService.clearCache(site);
|
||||||
@@ -88,24 +89,26 @@ public class SiteService extends CrudService<SiteDao, Site> {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Site site) {
|
public void delete(Site site) {
|
||||||
|
site.sqlMap().markIdDelete();
|
||||||
super.delete(site);
|
super.delete(site);
|
||||||
|
CmsUtils.removeCache("siteList");
|
||||||
// 清理首页、栏目和文章页面缓存
|
// 清理首页、栏目和文章页面缓存
|
||||||
if (pageCacheService != null) {
|
if (pageCacheService != null) {
|
||||||
pageCacheService.clearCache(site);
|
pageCacheService.clearCache(site);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 删除站点
|
// * 删除站点
|
||||||
* @param site
|
// * @param site
|
||||||
* @param isRe
|
// * @param isRe
|
||||||
*/
|
// */
|
||||||
@Transactional
|
// @Transactional
|
||||||
public void delete(Site site, Boolean isRe) {
|
// public void delete(Site site, Boolean isRe) {
|
||||||
site.setStatus(isRe != null && isRe ? Site.STATUS_NORMAL : Site.STATUS_DELETE);
|
// site.setStatus(isRe != null && isRe ? Site.STATUS_NORMAL : Site.STATUS_DELETE);
|
||||||
super.delete(site);
|
// super.delete(site);
|
||||||
CmsUtils.removeCache("siteList");
|
// CmsUtils.removeCache("siteList");
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重建索引
|
* 重建索引
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public class AreaServiceSupport extends TreeService<AreaDao, Area>
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Area area) {
|
public void delete(Area area) {
|
||||||
|
area.sqlMap().markIdDelete();
|
||||||
super.delete(area);
|
super.delete(area);
|
||||||
AreaUtils.clearCache();
|
AreaUtils.clearCache();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ public class EmployeeServiceSupport extends CrudService<EmployeeDao, Employee>
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Employee employee) {
|
public void delete(Employee employee) {
|
||||||
|
employee.sqlMap().markIdDelete();
|
||||||
super.delete(employee);
|
super.delete(employee);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.jeesite.modules.sys.service.support;
|
package com.jeesite.modules.sys.service.support;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.validation.ConstraintViolation;
|
|
||||||
import javax.validation.ConstraintViolationException;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import com.jeesite.common.config.Global;
|
import com.jeesite.common.config.Global;
|
||||||
import com.jeesite.common.service.ServiceException;
|
import com.jeesite.common.service.ServiceException;
|
||||||
import com.jeesite.common.service.TreeService;
|
import com.jeesite.common.service.TreeService;
|
||||||
@@ -23,6 +14,13 @@ import com.jeesite.modules.sys.entity.Office;
|
|||||||
import com.jeesite.modules.sys.service.DataScopeService;
|
import com.jeesite.modules.sys.service.DataScopeService;
|
||||||
import com.jeesite.modules.sys.service.OfficeService;
|
import com.jeesite.modules.sys.service.OfficeService;
|
||||||
import com.jeesite.modules.sys.utils.EmpUtils;
|
import com.jeesite.modules.sys.utils.EmpUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolation;
|
||||||
|
import javax.validation.ConstraintViolationException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 机构Service
|
* 机构Service
|
||||||
@@ -158,6 +156,7 @@ public class OfficeServiceSupport extends TreeService<OfficeDao, Office>
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Office office) {
|
public void delete(Office office) {
|
||||||
|
office.sqlMap().markIdDelete();
|
||||||
super.delete(office);
|
super.delete(office);
|
||||||
// 清理部门相关缓存
|
// 清理部门相关缓存
|
||||||
clearOfficeCache();
|
clearOfficeCache();
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ public class PostServiceSupport extends CrudService<PostDao, Post>
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Post post) {
|
public void delete(Post post) {
|
||||||
|
post.sqlMap().markIdDelete();
|
||||||
super.delete(post);
|
super.delete(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -561,6 +561,13 @@ mybatis:
|
|||||||
# 批量插入和更新的分批默认大小(防止库一次性接受不了太大的sql语句)
|
# 批量插入和更新的分批默认大小(防止库一次性接受不了太大的sql语句)
|
||||||
defaultBatchSize: 500
|
defaultBatchSize: 500
|
||||||
|
|
||||||
|
# 执行逻辑删除的时候,同时修改主键字段值,方便再次使用这个主键值 v5.4.0+
|
||||||
|
# 案例分析(角色管理场景):
|
||||||
|
# 1.如果是逻辑删除数据,并非物理删除,所以删除了角色 abc 再次新增时,会提示 abc 编号已存在
|
||||||
|
# 2.使用方法为:在 super.delete(entity); 前调用:entity.sqlMap().markIdDelete();
|
||||||
|
# 3.一般在手动填写主键业务中使用,启用后将会在删除后,修改 ID 值数据,例如:abc__del_随机串
|
||||||
|
markIdDeleteFlag: __del_
|
||||||
|
|
||||||
# Mapper文件刷新线程
|
# Mapper文件刷新线程
|
||||||
mapper:
|
mapper:
|
||||||
refresh:
|
refresh:
|
||||||
|
|||||||
@@ -259,6 +259,9 @@ public class ${ClassName}Service extends ${table.isTreeEntity?'Tree':'Crud'}Serv
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(${ClassName} ${className}) {
|
public void delete(${ClassName} ${className}) {
|
||||||
|
<% if (table.pkList.~size > 0 && table.pkList[0].showType == 'input') { %>
|
||||||
|
${className}.sqlMap().markIdDelete(); // 逻辑删除时标记ID值
|
||||||
|
<% } %>
|
||||||
super.delete(${className});
|
super.delete(${className});
|
||||||
<% for (child in table.childList) { %>
|
<% for (child in table.childList) { %>
|
||||||
${@StringUtils.cap(child.className)} ${@StringUtils.uncap(child.className)} = new ${@StringUtils.cap(child.className)}();
|
${@StringUtils.cap(child.className)} ${@StringUtils.uncap(child.className)} = new ${@StringUtils.cap(child.className)}();
|
||||||
|
|||||||
@@ -269,6 +269,9 @@ public class ${ClassName}Service extends ${table.isTreeEntity?'Tree':'Crud'}Serv
|
|||||||
@GlobalTransactional
|
@GlobalTransactional
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(${ClassName} ${className}) {
|
public void delete(${ClassName} ${className}) {
|
||||||
|
<% if (table.pkList.~size > 0 && table.pkList[0].showType == 'input') { %>
|
||||||
|
${className}.sqlMap().markIdDelete(); // 逻辑删除时标记ID值
|
||||||
|
<% } %>
|
||||||
super.delete(${className});
|
super.delete(${className});
|
||||||
<% for (child in table.childList) { %>
|
<% for (child in table.childList) { %>
|
||||||
${@StringUtils.cap(child.className)} ${@StringUtils.uncap(child.className)} = new ${@StringUtils.cap(child.className)}();
|
${@StringUtils.cap(child.className)} ${@StringUtils.uncap(child.className)} = new ${@StringUtils.cap(child.className)}();
|
||||||
|
|||||||
@@ -4,15 +4,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.jeesite.modules.test.service;
|
package com.jeesite.modules.test.service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import com.jeesite.common.service.TreeService;
|
import com.jeesite.common.service.TreeService;
|
||||||
import com.jeesite.modules.file.utils.FileUploadUtils;
|
import com.jeesite.modules.file.utils.FileUploadUtils;
|
||||||
import com.jeesite.modules.test.dao.TestTreeDao;
|
import com.jeesite.modules.test.dao.TestTreeDao;
|
||||||
import com.jeesite.modules.test.entity.TestTree;
|
import com.jeesite.modules.test.entity.TestTree;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试树表Service
|
* 测试树表Service
|
||||||
@@ -73,6 +72,7 @@ public class TestTreeService extends TreeService<TestTreeDao, TestTree> {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(TestTree testTree) {
|
public void delete(TestTree testTree) {
|
||||||
|
testTree.sqlMap().markIdDelete(); // 逻辑删除时标记ID值
|
||||||
super.delete(testTree);
|
super.delete(testTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.jeesite.modules.test.service;
|
package com.jeesite.modules.test.service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import com.jeesite.common.service.TreeService;
|
import com.jeesite.common.service.TreeService;
|
||||||
import com.jeesite.modules.file.utils.FileUploadUtils;
|
import com.jeesite.modules.file.utils.FileUploadUtils;
|
||||||
import com.jeesite.modules.test.dao.TestTreeDao;
|
import com.jeesite.modules.test.dao.TestTreeDao;
|
||||||
import com.jeesite.modules.test.entity.TestTree;
|
import com.jeesite.modules.test.entity.TestTree;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试树表Service
|
* 测试树表Service
|
||||||
@@ -73,6 +72,7 @@ public class TestTreeService extends TreeService<TestTreeDao, TestTree> {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(TestTree testTree) {
|
public void delete(TestTree testTree) {
|
||||||
|
testTree.sqlMap().markIdDelete(); // 逻辑删除时标记ID值
|
||||||
super.delete(testTree);
|
super.delete(testTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.jeesite.modules.test.service;
|
package com.jeesite.modules.test.service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import com.jeesite.common.service.TreeService;
|
import com.jeesite.common.service.TreeService;
|
||||||
import com.jeesite.modules.file.utils.FileUploadUtils;
|
import com.jeesite.modules.file.utils.FileUploadUtils;
|
||||||
import com.jeesite.modules.test.dao.TestTreeDao;
|
import com.jeesite.modules.test.dao.TestTreeDao;
|
||||||
import com.jeesite.modules.test.entity.TestTree;
|
import com.jeesite.modules.test.entity.TestTree;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试树表Service
|
* 测试树表Service
|
||||||
@@ -73,6 +72,7 @@ public class TestTreeService extends TreeService<TestTreeDao, TestTree> {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(TestTree testTree) {
|
public void delete(TestTree testTree) {
|
||||||
|
testTree.sqlMap().markIdDelete(); // 逻辑删除时标记ID值
|
||||||
super.delete(testTree);
|
super.delete(testTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user