use of com.diboot.iam.entity.IamOrg in project diboot by dibo-software.
the class IamOrgServiceImpl method enhanceIamOrg.
/**
* 增强IamOrg的属性
* @param iamOrg
*/
private void enhanceIamOrg(IamOrg iamOrg) {
// 设置层级及公司ID
if (iamOrg.getParentId() != null && V.notEquals(iamOrg.getParentId(), 0L)) {
IamOrg parentOrg = getEntity(iamOrg.getParentId());
if (parentOrg != null) {
// 设置层级
int parentLevel = parentOrg.getDepth().intValue();
iamOrg.setDepth(parentLevel + 1);
// 设置公司ID
if (V.equals(parentOrg.getParentId(), 0) || V.isEmpty(parentOrg.getParentId())) {
iamOrg.setTopOrgId(parentOrg.getId());
} else {
iamOrg.setTopOrgId(parentOrg.getTopOrgId());
}
}
}
}
use of com.diboot.iam.entity.IamOrg in project diboot by dibo-software.
the class IamOrgServiceImpl method getParentOrgIds.
@Override
public List<Long> getParentOrgIds(Long orgId, boolean includeThis) {
if (orgId == null) {
return Collections.emptyList();
}
List<Long> scopeIds = new ArrayList<>();
if (includeThis) {
scopeIds.add(orgId);
}
// 查询所有上级
IamOrg org = getEntity(orgId);
if (org != null && org.getDepth() != null) {
if (org.getDepth() >= 2) {
scopeIds.add(org.getParentId());
if (org.getDepth() > 2) {
LambdaQueryWrapper<IamOrg> queryWrapper = Wrappers.<IamOrg>lambdaQuery().select(IamOrg::getId, IamOrg::getParentId).lt(IamOrg::getDepth, org.getDepth());
List<IamOrg> parentOrgs = getEntityList(queryWrapper);
if (V.isEmpty(parentOrgs)) {
Map<String, IamOrg> orgId2ParentIdMap = BeanUtils.convertToStringKeyObjectMap(parentOrgs, IamOrg::getId);
String parentOrgIdStr = S.valueOf(org.getParentId());
while (orgId2ParentIdMap.containsKey(parentOrgIdStr)) {
Long parentOrgId = orgId2ParentIdMap.get(parentOrgIdStr).getParentId();
scopeIds.add(parentOrgId);
parentOrgIdStr = S.valueOf(parentOrgId);
}
}
}
}
}
return scopeIds;
}
use of com.diboot.iam.entity.IamOrg in project diboot by dibo-software.
the class IamOrgServiceImpl method sortList.
@Override
public void sortList(List<IamOrg> orgList) {
if (V.isEmpty(orgList)) {
throw new BusinessException(Status.FAIL_OPERATION, "排序列表不能为空");
}
List<Long> sortIdList = new ArrayList();
// 先将所有序号重新设置为自身当前id
for (IamOrg item : orgList) {
item.setSortId(item.getId());
sortIdList.add(item.getSortId());
}
// 将序号列表倒序排序
sortIdList = sortIdList.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
// 整理需要更新的列表
List<IamOrg> updateList = new ArrayList<>();
for (int i = 0; i < orgList.size(); i++) {
IamOrg item = orgList.get(i);
IamOrg updateItem = new IamOrg();
updateItem.setId(item.getId());
updateItem.setSortId(sortIdList.get(i));
updateList.add(updateItem);
}
if (updateList.size() > 0) {
super.updateBatchById(updateList);
}
}
Aggregations