|
|
@ -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;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|