修复树级数据无法逐级删除数据问题

v1.4.1
Parker 4 years ago
parent 60d4a4cc4b
commit 090991f823

@ -38,6 +38,8 @@ public final class MyBatisConstants {
/** ID */ /** ID */
public static final String FIELD_ID = "id"; public static final String FIELD_ID = "id";
/** PID */
public static final String FIELD_PARENT_ID = "parentId";
/** 创建人 */ /** 创建人 */
public static final String FIELD_CREATE_BY = "createBy"; public static final String FIELD_CREATE_BY = "createBy";
/** 更新时间 */ /** 更新时间 */

@ -197,8 +197,7 @@ public abstract class CrudServiceImpl<M extends BaseMapper<T>, T extends BaseEnt
@Override @Override
public List<T> findList(QueryWrapper<T> queryWrapper) { public List<T> findList(QueryWrapper<T> queryWrapper) {
// 多租户处理 // 多租户处理
TenantHandler tenantHandler = new TenantHandler(); QueryWrapper<T> qWrapper = new TenantHandler().handler(entityClazz, queryWrapper);
QueryWrapper<T> qWrapper = tenantHandler.handler(entityClazz, queryWrapper);
return super.list(qWrapper); return super.list(qWrapper);
} }
@ -206,8 +205,7 @@ public abstract class CrudServiceImpl<M extends BaseMapper<T>, T extends BaseEnt
public List<T> findAllList() { public List<T> findAllList() {
QueryBuilder<T> queryBuilder = new GenQueryBuilder<>(); QueryBuilder<T> queryBuilder = new GenQueryBuilder<>();
// 多租户处理 // 多租户处理
TenantHandler tenantHandler = new TenantHandler(); QueryWrapper<T> qWrapper = new TenantHandler().handler(entityClazz, queryBuilder.build());
QueryWrapper<T> qWrapper = tenantHandler.handler(entityClazz, queryBuilder.build());
return super.list(qWrapper); return super.list(qWrapper);
} }

@ -21,6 +21,7 @@ import org.apache.commons.lang3.StringUtils;
import org.opsli.api.wrapper.system.menu.MenuModel; import org.opsli.api.wrapper.system.menu.MenuModel;
import org.opsli.common.constants.MyBatisConstants; import org.opsli.common.constants.MyBatisConstants;
import org.opsli.common.exception.ServiceException; import org.opsli.common.exception.ServiceException;
import org.opsli.common.utils.HumpUtil;
import org.opsli.common.utils.WrapperUtil; import org.opsli.common.utils.WrapperUtil;
import org.opsli.core.base.service.impl.CrudServiceImpl; import org.opsli.core.base.service.impl.CrudServiceImpl;
import org.opsli.core.persistence.querybuilder.GenQueryBuilder; import org.opsli.core.persistence.querybuilder.GenQueryBuilder;
@ -120,9 +121,14 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public boolean delete(String id) { public boolean delete(String id) {
MenuModel menuModel = super.get(id); MenuModel menuModel = super.get(id);
boolean ret = super.delete(id); boolean ret = super.delete(id);
// 删除子数据
this.deleteByParentId(id);
if(ret){ if(ret){
// 清空编号缓存 // 清空编号缓存
MenuUtil.refreshMenu(menuModel); MenuUtil.refreshMenu(menuModel);
@ -141,6 +147,7 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public boolean deleteAll(String[] ids) { public boolean deleteAll(String[] ids) {
QueryBuilder<SysMenu> queryBuilder = new GenQueryBuilder<>(); QueryBuilder<SysMenu> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysMenu> queryWrapper = queryBuilder.build(); QueryWrapper<SysMenu> queryWrapper = queryBuilder.build();
@ -148,6 +155,11 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
List<SysMenu> menuList = super.findList(queryWrapper); List<SysMenu> menuList = super.findList(queryWrapper);
boolean ret = super.deleteAll(ids); boolean ret = super.deleteAll(ids);
// 删除子数据
for (String id : ids) {
this.deleteByParentId(id);
}
if(ret){ if(ret){
// 清空编号缓存 // 清空编号缓存
for (SysMenu sysMenu : menuList) { for (SysMenu sysMenu : menuList) {
@ -171,6 +183,27 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
} }
return ret; return ret;
} }
/**
*
* @param parentId
* @return
*/
@Transactional(rollbackFor = Exception.class)
public boolean deleteByParentId(String parentId) {
boolean ret = false;
QueryBuilder<SysMenu> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysMenu> queryWrapper = queryBuilder.build();
queryWrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId);
List<SysMenu> menuList = super.findList(queryWrapper);
for (SysMenu sysMenu : menuList) {
super.delete(sysMenu.getId());
// 逐级删除子数据
ret = this.deleteByParentId(sysMenu.getId());
}
return ret;
}
} }

Loading…
Cancel
Save