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

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_USE(20501,"组织机构已被引用,不能删除"),
EXCEPTION_ORG_USE(20501,"组织机构已被引用,不能操作"),
EXCEPTION_ORG_USE_TENANT(20501,"组织机构已被引用,不能修改租户"),
/**
*

@ -163,8 +163,7 @@ public class MenuServiceImpl extends CrudServiceImpl<MenuMapper, SysMenu, MenuMo
* @return
*/
@Transactional(rollbackFor = Exception.class)
public boolean deleteByParentId(String parentId) {
boolean ret = false;
public void deleteByParentId(String parentId) {
QueryBuilder<SysMenu> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysMenu> queryWrapper = queryBuilder.build();
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) {
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());
}
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);
}
@ -167,24 +184,41 @@ public class SysOrgServiceImpl extends CrudServiceImpl<SysOrgMapper, SysOrg, Sys
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
* @return
*/
@Transactional(rollbackFor = Exception.class)
public boolean deleteByParentId(String parentId) {
boolean ret = false;
public void deleteByParentId(String parentId) {
QueryBuilder<SysOrg> queryBuilder = new GenQueryBuilder<>();
QueryWrapper<SysOrg> queryWrapper = queryBuilder.build();
queryWrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId);
List<SysOrg> menuList = super.findList(queryWrapper);
for (SysOrg sysOrg : menuList) {
List<SysOrg> entityList = super.findList(queryWrapper);
for (SysOrg sysOrg : entityList) {
super.delete(sysOrg.getId());
// 逐级删除子数据
ret = this.deleteByParentId(sysOrg.getId());
this.deleteByParentId(sysOrg.getId());
}
return ret;
}
/**

Loading…
Cancel
Save