组织结构修复更改租户无法逐级修改问题

v1.4.1
Parker 4 years ago
parent 78e3292b3f
commit 6d995308c4

@ -69,7 +69,9 @@ public enum SystemMsg implements BaseMsg {
* *
*/ */
EXCEPTION_ORG_UNIQUE(20500,"组织机构编号重复,已存在"), EXCEPTION_ORG_UNIQUE(20500,"组织机构编号重复,已存在"),
EXCEPTION_ORG_USE(20501,"组织机构已被引用,不能删除"), EXCEPTION_ORG_USE(20501,"组织机构已被引用,不能操作"),
EXCEPTION_ORG_USE_TENANT(20501,"组织机构已被引用,不能修改租户"),
/** /**
* *

@ -163,8 +163,7 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
* @return * @return
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean deleteByParentId(String parentId) { public void deleteByParentId(String parentId) {
boolean ret = false;
QueryBuilder<SysMenu> queryBuilder = new GenQueryBuilder<>(); QueryBuilder<SysMenu> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysMenu> queryWrapper = queryBuilder.build(); QueryWrapper<SysMenu> queryWrapper = queryBuilder.build();
queryWrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); queryWrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId);
@ -172,9 +171,8 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
for (SysMenu sysMenu : menuList) { for (SysMenu sysMenu : menuList) {
super.delete(sysMenu.getId()); super.delete(sysMenu.getId());
// 逐级删除子数据 // 逐级删除子数据
ret = this.deleteByParentId(sysMenu.getId()); this.deleteByParentId(sysMenu.getId());
} }
return ret;
} }
// ============ // ============

@ -116,6 +116,23 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
model.setTenantId(sysOrgModel.getTenantId()); model.setTenantId(sysOrgModel.getTenantId());
} }
SysOrgModel sysOrgModel = super.get(model);
// 如果 TenantId 发生变化 则需要更改 下级数据 租户ID
if(sysOrgModel != null && !sysOrgModel.getTenantId().equals(
model.getTenantId())){
QueryWrapper<SysOrg> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("org_id", sysOrgModel.getId());
Integer countTmp = mapper.hasUse(queryWrapper);
if(countTmp > 0){
// 组织机构已被引用,不能删除
throw new ServiceException(SystemMsg.EXCEPTION_ORG_USE_TENANT);
}
// 如果没有被引用 则逐级修改
this.updateTenantByParentId(sysOrgModel.getId(), model.getTenantId());
}
// 修改
return super.update(model); return super.update(model);
} }
@ -167,24 +184,41 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
return ret; return ret;
} }
/**
*
* @param parentId
* @return
*/
@Transactional(rollbackFor = Exception.class)
public void updateTenantByParentId(String parentId, String tenantId) {
QueryBuilder<SysOrg> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysOrg> queryWrapper = queryBuilder.build();
queryWrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId);
List<SysOrg> entityList = super.findList(queryWrapper);
for (SysOrg sysOrg : entityList) {
sysOrg.setTenantId(tenantId);
super.updateById(sysOrg);
// 逐级删除子数据
this.updateTenantByParentId(sysOrg.getId(), tenantId);
}
}
/** /**
* *
* @param parentId * @param parentId
* @return * @return
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean deleteByParentId(String parentId) { public void deleteByParentId(String parentId) {
boolean ret = false;
QueryBuilder<SysOrg> queryBuilder = new GenQueryBuilder<>(); QueryBuilder<SysOrg> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysOrg> queryWrapper = queryBuilder.build(); QueryWrapper<SysOrg> queryWrapper = queryBuilder.build();
queryWrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); queryWrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId);
List<SysOrg> menuList = super.findList(queryWrapper); List<SysOrg> entityList = super.findList(queryWrapper);
for (SysOrg sysOrg : menuList) { for (SysOrg sysOrg : entityList) {
super.delete(sysOrg.getId()); super.delete(sysOrg.getId());
// 逐级删除子数据 // 逐级删除子数据
ret = this.deleteByParentId(sysOrg.getId()); this.deleteByParentId(sysOrg.getId());
} }
return ret;
} }
/** /**

Loading…
Cancel
Save