Browse Source

用户可用报告类型接口优化

lixing 3 years ago
parent
commit
3045d52d15

+ 15 - 15
src/main/java/com/persagy/apm/energy/report/monthly/config/type/service/impl/ReportTypeServiceImpl.java

@@ -1,36 +1,36 @@
 package com.persagy.apm.energy.report.monthly.config.type.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.common.base.CaseFormat;
+import com.persagy.apm.common.constant.enums.ValidEnum;
 import com.persagy.apm.common.context.poems.PoemsContext;
+import com.persagy.apm.common.model.dto.Sort;
 import com.persagy.apm.common.model.vo.EnumVO;
 import com.persagy.apm.energy.report.monthly.config.type.constant.enums.BelongTypeEnum;
 import com.persagy.apm.energy.report.monthly.config.type.dao.ReportTypeMapper;
+import com.persagy.apm.energy.report.monthly.config.type.model.ConvertReportTypeTool;
+import com.persagy.apm.energy.report.monthly.config.type.model.ReportType;
+import com.persagy.apm.energy.report.monthly.config.type.model.dto.AddReportTypeDTO;
+import com.persagy.apm.energy.report.monthly.config.type.model.dto.PageQueryReportTypeDTO;
+import com.persagy.apm.energy.report.monthly.config.type.model.dto.QueryReportTypeDTO;
+import com.persagy.apm.energy.report.monthly.config.type.model.dto.UpdateReportTypeDTO;
 import com.persagy.apm.energy.report.monthly.config.type.model.vo.ResponseReportTypeListItemVO;
 import com.persagy.apm.energy.report.monthly.config.type.service.IReportTypeEnumService;
 import com.persagy.apm.energy.report.monthly.config.type.service.IReportTypeService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.persagy.apm.energy.report.saasweb.model.vo.PartitionVO;
-import com.persagy.apm.energy.report.saasweb.model.vo.PoemsProjectVO;
 import com.persagy.apm.energy.report.saasweb.model.vo.SimpleProjectVO;
 import com.persagy.apm.energy.report.saasweb.service.ISaasWebService;
+import org.apache.commons.lang.StringUtils;
 import org.assertj.core.util.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.apache.commons.lang.StringUtils;
-import com.persagy.apm.common.constant.enums.ValidEnum;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.persagy.apm.energy.report.monthly.config.type.model.*;
-import com.persagy.apm.energy.report.monthly.config.type.model.dto.*;
+import org.springframework.util.CollectionUtils;
 
-import java.util.ArrayList;
 import java.util.List;
-import java.util.stream.Collectors;
-
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.google.common.base.CaseFormat;
-import com.persagy.apm.common.model.dto.Sort;
-import org.springframework.util.CollectionUtils;
 
 /**
  * 报告类型(ReportType) service层

+ 12 - 0
src/main/java/com/persagy/apm/energy/report/monthly/outline/controller/ReportOutlineController.java

@@ -21,6 +21,7 @@ import com.persagy.apm.energy.report.monthly.outline.model.ReportOutline;
 import com.persagy.apm.energy.report.monthly.outline.model.dto.*;
 import com.persagy.apm.energy.report.monthly.outline.model.vo.ResponseReportOutlineListItemVO;
 import com.persagy.apm.energy.report.monthly.outline.service.IReportOutlineService;
+import com.persagy.apm.energy.report.saasweb.model.vo.PartitionProjectVO;
 import com.persagy.apm.energy.report.saasweb.model.vo.PartitionVO;
 import com.persagy.apm.energy.report.saasweb.model.vo.SimpleProjectVO;
 import com.persagy.apm.energy.report.saasweb.service.ISaasWebService;
@@ -118,6 +119,17 @@ public class ReportOutlineController {
         return ResultHelper.multi(resultList);
     }
 
+    @ApiOperation(value = "查询用户可选项目树")
+    @PostMapping("/queryAvailableProjectTree")
+    public CommonResult<PageList<PartitionProjectVO>> queryAvailableProjectTree(
+            @Valid @RequestBody QueryAvailableBelongsDTO queryAvailableBelongsDTO) {
+        List<PartitionProjectVO> availableProjectTree = saasWebService.getAvailableProjectTree(queryAvailableBelongsDTO.getBuildingType());
+        IPage<PartitionProjectVO> resultList = new Page<>();
+        resultList.setRecords(availableProjectTree);
+        resultList.setTotal(availableProjectTree.size());
+        return ResultHelper.multi(resultList);
+    }
+
     @ApiOperation(value = "查询用户可选分区范围")
     @PostMapping("/queryAvailableAreas")
     public CommonResult<PageList<PartitionVO>> queryAvailableAreas(

+ 18 - 0
src/main/java/com/persagy/apm/energy/report/saasweb/constants/SaaswebConstants.java

@@ -0,0 +1,18 @@
+package com.persagy.apm.energy.report.saasweb.constants;
+
+/**
+ * 运维平台常量定义
+ *
+ * @author lixing
+ * @version V1.0 2021/6/18 11:00 上午
+ **/
+public class SaaswebConstants {
+    /**
+     * 项目标识符
+     */
+    public static final String PROJECT_FLAG = "0";
+    /**
+     * 分区标识符
+     */
+    public static final String AREA_FLAG = "1";
+}

+ 4 - 0
src/main/java/com/persagy/apm/energy/report/saasweb/model/vo/PoemsProjectVO.java

@@ -19,8 +19,12 @@ public class PoemsProjectVO {
     private String projectLocalID;
     @ApiModelProperty(value = "项目本地名称")
     private String projectLocalName;
+    @ApiModelProperty(value = "项目功能类型")
+    private String functionType;
     @ApiModelProperty(value = "项目功能类型名称")
     private String functionTypeName;
     @ApiModelProperty(value = "项目开业时间")
     private String businessOpeningTime;
+    @ApiModelProperty(value = "气候区")
+    private String climateZone;
 }

+ 10 - 0
src/main/java/com/persagy/apm/energy/report/saasweb/service/ISaasWebService.java

@@ -44,6 +44,16 @@ public interface ISaasWebService {
     ReportProjectVO getReportProjectInfo(String projectId);
 
     /**
+     * 根据业态获取用户可用的分区项目树
+     *
+     * @param buildingType 业态
+     * @return 用户可用的分区项目树
+     * @author lixing
+     * @version V1.0 2021/6/17 2:48 下午
+     */
+    List<PartitionProjectVO> getAvailableProjectTree(String buildingType);
+
+    /**
      * 获取一组项目的总的商业面积
      *
      * @param projectIds 一组项目id

+ 96 - 30
src/main/java/com/persagy/apm/energy/report/saasweb/service/impl/SaasWebServiceImpl.java

@@ -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<>();