Commit 42bd5ace by 宋祥

1.修复查询用户厂区和公司BUG

parent e1bb9ffa
......@@ -125,13 +125,15 @@ public class UserSessionUtils extends UserSession {
if (CollectionUtils.isEmpty(orgs)) {
return new ArrayList<>();
}
List<String> orgIds = new ArrayList<>();
for (Org org : orgs) {
List<String> orgIds = orgs.stream().map(Org::getOrgId).collect(Collectors.toList());
List<Org> parentOrgs = HGXSTools.XsOrg.queryParent(orgIds);
List<String> results = new ArrayList<>();
for (Org org : parentOrgs) {
if (OrgTypeEnum.COMPANY.getCode().equals(org.getOrgType())) {
orgIds.add(org.getOrgId());
results.add(org.getOrgId());
}
}
return orgIds;
return results.stream().distinct().collect(Collectors.toList());
}
/**
......@@ -144,13 +146,15 @@ public class UserSessionUtils extends UserSession {
if (CollectionUtils.isEmpty(orgs)) {
return new ArrayList<>();
}
List<String> factoryCodes = new ArrayList<>();
for (Org org : orgs) {
List<String> orgIds = orgs.stream().map(Org::getOrgId).collect(Collectors.toList());
List<Org> parentOrgs = HGXSTools.XsOrg.queryParent(orgIds);
List<String> results = new ArrayList<>();
for (Org org : parentOrgs) {
if (OrgTypeEnum.FACTORY.getCode().equals(org.getOrgType())) {
factoryCodes.add(org.getOrgId());
results.add(org.getOrgId());
}
}
return factoryCodes;
return results.stream().distinct().collect(Collectors.toList());
}
/**
......@@ -163,13 +167,15 @@ public class UserSessionUtils extends UserSession {
if (CollectionUtils.isEmpty(orgs)) {
return new ArrayList<>();
}
List<String> factoryNames = new ArrayList<>();
for (Org org : orgs) {
List<String> orgIds = orgs.stream().map(Org::getOrgId).collect(Collectors.toList());
List<Org> parentOrgs = HGXSTools.XsOrg.queryParent(orgIds);
List<String> results = new ArrayList<>();
for (Org org : parentOrgs) {
if (OrgTypeEnum.FACTORY.getCode().equals(org.getOrgType())) {
factoryNames.add(org.getOrgCname());
results.add(org.getFactoryName());
}
}
return factoryNames;
return results.stream().distinct().collect(Collectors.toList());
}
/**
......
......@@ -295,9 +295,7 @@ public class HGXSTools {
AssertUtils.isNull(orgId, "组织ID不能为空");
Map queryMap = new HashMap();
queryMap.put("orgId", orgId);
List<Org> results = DaoBase.getInstance().query(HGSqlConstant.HgXsOrg.QUERY_PARENT, queryMap);
AssertUtils.isEmpty(results, String.format("组织[%s]不存在父级信息", orgId));
return results;
return DaoBase.getInstance().query(HGSqlConstant.HgXsOrg.QUERY_PARENT, queryMap);
}
/**
......@@ -440,6 +438,34 @@ public class HGXSTools {
// 去除重复组织机构
return childOrgIds.stream().distinct().collect(Collectors.toList());
}
/**
* 查询父级(包含自身)
*
* @param orgIds
* @return
*/
public static List<Org> queryParent(List<String> orgIds) {
List<Org> results = new ArrayList<>();
List<String> resultIds = new ArrayList<>();
for (String orgId : orgIds) {
// 已经存在不在重复查询
if (resultIds.contains(orgId)) {
continue;
}
// 查询组织子集
List<Org> dbOrgs = XsOrg.queryParent(orgId);
for (Org dbOrg : dbOrgs) {
if (!resultIds.contains(dbOrg.getOrgId())) {
resultIds.add(dbOrg.getOrgId());
results.add(dbOrg);
}
}
}
// 去除重复组织机构
return results.stream().distinct().collect(Collectors.toList());
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment