|
@@ -4,6 +4,7 @@ import com.google.common.collect.Maps;
|
|
|
import com.persagy.apm.common.model.dto.PoemsFeignBaseDTO;
|
|
|
import com.persagy.apm.common.response.PoemsFeignResponse;
|
|
|
import com.persagy.apm.energy.report.common.utils.DateUtils;
|
|
|
+import com.persagy.apm.energy.report.saasweb.constants.SaaswebConstants;
|
|
|
import com.persagy.apm.energy.report.saasweb.model.ConvertSaasWebTool;
|
|
|
import com.persagy.apm.energy.report.saasweb.model.dto.QueryByProjectIdDTO;
|
|
|
import com.persagy.apm.energy.report.saasweb.model.dto.QueryPartitionDTO;
|
|
@@ -207,7 +208,7 @@ public class SaasWebServiceImpl implements ISaasWebService {
|
|
|
return allProjects.stream().
|
|
|
filter(
|
|
|
poemsProjectVO -> satisfyBuildingTypeAndClimateZone(
|
|
|
- buildingTypeCodes, climateZoneCode, poemsProjectVO.getProjectId())
|
|
|
+ buildingTypeCodes, climateZoneCode, poemsProjectVO)
|
|
|
).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
@@ -228,7 +229,7 @@ public class SaasWebServiceImpl implements ISaasWebService {
|
|
|
return projectsByArea.stream().
|
|
|
filter(
|
|
|
poemsProjectVO -> satisfyBuildingTypeAndClimateZone(
|
|
|
- buildingTypes, null, poemsProjectVO.getProjectId())
|
|
|
+ buildingTypes, null, poemsProjectVO)
|
|
|
).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
@@ -237,30 +238,29 @@ public class SaasWebServiceImpl implements ISaasWebService {
|
|
|
*
|
|
|
* @param allBuildingTypes 所有用来筛选的业态
|
|
|
* @param climateZoneCode 用来筛选的气候区
|
|
|
- * @param projectId 项目id
|
|
|
+ * @param projectVO PoemsProjectVO对象
|
|
|
* @return 是否满足条件
|
|
|
* @author lixing
|
|
|
* @version V1.0 2021/6/15 5:12 下午
|
|
|
*/
|
|
|
private boolean satisfyBuildingTypeAndClimateZone(
|
|
|
- List<String> allBuildingTypes, String climateZoneCode, String projectId) {
|
|
|
+ List<String> allBuildingTypes, String climateZoneCode, PoemsProjectVO projectVO) {
|
|
|
|
|
|
|
|
|
- if (StringUtils.isBlank(projectId)) {
|
|
|
+ if (projectVO == null) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- SimpleProjectVO simpleProjectInfo = getSimpleProjectInfo(projectId);
|
|
|
boolean result = true;
|
|
|
// 如果要过滤的建筑类型不为空,根据建筑类型过滤
|
|
|
if (!CollectionUtils.isEmpty(allBuildingTypes)) {
|
|
|
- result = result && StringUtils.isNotBlank(simpleProjectInfo.getFunctionType()) &&
|
|
|
- allBuildingTypes.contains(simpleProjectInfo.getFunctionType());
|
|
|
+ result = result && StringUtils.isNotBlank(projectVO.getFunctionType()) &&
|
|
|
+ allBuildingTypes.contains(projectVO.getFunctionType());
|
|
|
}
|
|
|
|
|
|
// 如果要过滤的气候区不为空,根据气候区过滤
|
|
|
if (StringUtils.isNotBlank(climateZoneCode)) {
|
|
|
- result = result && climateZoneCode.equals(simpleProjectInfo.getClimateZone());
|
|
|
+ result = result && climateZoneCode.equals(projectVO.getClimateZone());
|
|
|
}
|
|
|
|
|
|
return result;
|
|
@@ -283,7 +283,7 @@ public class SaasWebServiceImpl implements ISaasWebService {
|
|
|
List<PoemsProjectVO> projects = userProjectsInfoVO.getProjects();
|
|
|
projects = projects.stream().filter(
|
|
|
poemsProjectVO -> satisfyBuildingTypeAndClimateZone(
|
|
|
- buildingTypes, null, poemsProjectVO.getProjectId())
|
|
|
+ buildingTypes, null, poemsProjectVO)
|
|
|
).collect(Collectors.toList());
|
|
|
List<SimpleProjectVO> simpleProjectVOList = ConvertSaasWebTool.INSTANCE.convert2SimpleProjectVOList(projects);
|
|
|
result.addAll(simpleProjectVOList);
|
|
@@ -378,6 +378,91 @@ public class SaasWebServiceImpl implements ISaasWebService {
|
|
|
return filterPartitionMap2Tree(filterPartitionMap);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<PartitionProjectVO> getAvailableProjectTree(String buildingType) {
|
|
|
+ // 查询用户权限范围内的分区和项目
|
|
|
+ List<PartitionProjectVO> availableProjectTree = getAvailableProjectTree();
|
|
|
+ if (CollectionUtils.isEmpty(availableProjectTree)) {
|
|
|
+ return Lists.newArrayList();
|
|
|
+ }
|
|
|
+ // 遍历用户所有可选分区树,标记分区父节点及分区拥有的项目
|
|
|
+ List<FilterPartitionVO> partitions = partitionProjectTree2FilterPartitionList();
|
|
|
+ // 根据建筑业态筛选分区
|
|
|
+ Map<String, FilterPartitionVO> filterPartitionMap = filterPartitions(partitions, buildingType);
|
|
|
+ if (CollectionUtils.isEmpty(filterPartitionMap)) {
|
|
|
+ return Lists.newArrayList();
|
|
|
+ }
|
|
|
+ // 根据建筑业态筛选用户权限范围内的项目
|
|
|
+ List<SimpleProjectVO> availableProjects = getAvailableProjects(buildingType);
|
|
|
+ if (CollectionUtils.isEmpty(availableProjects)) {
|
|
|
+ return Lists.newArrayList();
|
|
|
+ }
|
|
|
+ Map<String, String> filterProjectMap = availableProjects.stream().collect(
|
|
|
+ Collectors.toMap(SimpleProjectVO::getProjectId, SimpleProjectVO::getProjectName, (k1, k2) -> k1));
|
|
|
+
|
|
|
+ return cascadeFilterAvailablePartitionAndProject(
|
|
|
+ availableProjectTree, filterPartitionMap, filterProjectMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归过滤用户可用的分区和项目
|
|
|
+ *
|
|
|
+ * @param treeBeforeFilter 需要过滤的树
|
|
|
+ * @param availablePartitionMap 可用分区map
|
|
|
+ * @param availableProjectMap 可用项目map
|
|
|
+ * @return 用户可用的分区项目树
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/6/18 11:12 上午
|
|
|
+ */
|
|
|
+ private List<PartitionProjectVO> cascadeFilterAvailablePartitionAndProject(
|
|
|
+ List<PartitionProjectVO> treeBeforeFilter, Map<String, FilterPartitionVO> availablePartitionMap,
|
|
|
+ Map<String, String> availableProjectMap) {
|
|
|
+ List<PartitionProjectVO> filteredTree = Lists.newArrayList(treeBeforeFilter);
|
|
|
+ for (PartitionProjectVO partitionProjectVO : treeBeforeFilter) {
|
|
|
+ // 节点为项目,但不满足业态条件,从树中剔除
|
|
|
+ if (SaaswebConstants.PROJECT_FLAG.equals(partitionProjectVO.getType()) &&
|
|
|
+ availableProjectMap.get(partitionProjectVO.getId()) == null) {
|
|
|
+ filteredTree.remove(partitionProjectVO);
|
|
|
+ } else if (SaaswebConstants.AREA_FLAG.equals(partitionProjectVO.getType()) &&
|
|
|
+ availablePartitionMap.get(partitionProjectVO.getId()) == null) {
|
|
|
+ // 节点为分区,但不满足业态条件,从树中剔除
|
|
|
+ filteredTree.remove(partitionProjectVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(filteredTree)) {
|
|
|
+ return filteredTree;
|
|
|
+ }
|
|
|
+ for (PartitionProjectVO partitionProjectVO : filteredTree) {
|
|
|
+ // 递归处理下级节点
|
|
|
+ List<PartitionProjectVO> sonNodes = partitionProjectVO.getContents();
|
|
|
+ if (!CollectionUtils.isEmpty(sonNodes)) {
|
|
|
+ List<PartitionProjectVO> filterSonNodes = cascadeFilterAvailablePartitionAndProject(
|
|
|
+ sonNodes, availablePartitionMap, availableProjectMap);
|
|
|
+ partitionProjectVO.setContents(filterSonNodes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return filteredTree;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 当前用户拥有的分区项目树
|
|
|
+ *
|
|
|
+ * @return 分区项目树
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/6/17 2:48 下午
|
|
|
+ */
|
|
|
+ private List<PartitionProjectVO> getAvailableProjectTree() {
|
|
|
+ PoemsFeignBaseDTO poemsFeignBaseDTO = new PoemsFeignBaseDTO();
|
|
|
+ poemsFeignBaseDTO.setDefaultValue();
|
|
|
+ PoemsFeignResponse<UserPartitionProjectsInfoVO> partitionsResponse = saasWebClientWrapper.getCurrentUserPartitionProjectsInfo(poemsFeignBaseDTO);
|
|
|
+ List<UserPartitionProjectsInfoVO> userPartitionProjects = partitionsResponse.getContent();
|
|
|
+ if (CollectionUtils.isEmpty(userPartitionProjects)) {
|
|
|
+ return Lists.newArrayList();
|
|
|
+ }
|
|
|
+ return userPartitionProjects.get(0).getPartitionProjects();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 将筛选后的分区组装成树
|
|
|
*
|
|
@@ -434,18 +519,6 @@ public class SaasWebServiceImpl implements ISaasWebService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- private void setChildren(Map<String, List<FilterPartitionVO>> parentIdMap, List<PartitionVO> rootNodes) {
|
|
|
- if (!CollectionUtils.isEmpty(rootNodes)) {
|
|
|
- for (PartitionVO rootNode : rootNodes) {
|
|
|
- List<FilterPartitionVO> filterPartitionVOList = parentIdMap.get(rootNode.getAreaId());
|
|
|
- List<PartitionVO> partitionVOList = ConvertSaasWebTool.INSTANCE.convert2PartitionVOList(filterPartitionVOList);
|
|
|
- rootNode.setChildren(partitionVOList);
|
|
|
- setChildren(parentIdMap, partitionVOList);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 遍历用户所有可选分区树,标记分区父节点及分区拥有的项目
|
|
|
*
|
|
@@ -455,14 +528,7 @@ public class SaasWebServiceImpl implements ISaasWebService {
|
|
|
*/
|
|
|
private List<FilterPartitionVO> partitionProjectTree2FilterPartitionList() {
|
|
|
// 获取用户所有可选的分区信息
|
|
|
- PoemsFeignBaseDTO poemsFeignBaseDTO = new PoemsFeignBaseDTO();
|
|
|
- poemsFeignBaseDTO.setDefaultValue();
|
|
|
- PoemsFeignResponse<UserPartitionProjectsInfoVO> partitionsResponse = saasWebClientWrapper.getCurrentUserPartitionProjectsInfo(poemsFeignBaseDTO);
|
|
|
- List<UserPartitionProjectsInfoVO> userPartitionProjects = partitionsResponse.getContent();
|
|
|
- if (CollectionUtils.isEmpty(userPartitionProjects)) {
|
|
|
- return Lists.newArrayList();
|
|
|
- }
|
|
|
- List<PartitionProjectVO> partitionProjects = userPartitionProjects.get(0).getPartitionProjects();
|
|
|
+ List<PartitionProjectVO> partitionProjects = getAvailableProjectTree();
|
|
|
|
|
|
// 筛选出分区列表
|
|
|
List<PartitionProjectVO> partitions = new ArrayList<>();
|