Browse Source

fix bug:
1.调用/space-bd-fl-data接口报404问题
2.调用/space-bd-fl接口返回的统计数有误问题

lijie 3 years ago
parent
commit
b2b5ebea56

+ 19 - 0
src/main/java/com/persagy/proxy/object/service/IAdmSpaceService.java

@@ -7,6 +7,7 @@ import com.persagy.proxy.object.model.AdmSpace;
 import com.persagy.proxy.adm.request.AdmResponse;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -72,4 +73,22 @@ public interface IAdmSpaceService extends IAdmBaseService<AdmSpace> {
      */
     Map<String, Set<String>> queryTrafficSpaceMap(InstanceUrlParam context, Iterable<String> spaceIds, String spaceType);
     void ensureSpecialValues(InstanceUrlParam context, List<AdmSpace> vos);
+    /***
+     * Description: 查询多建筑楼层下的空间id
+     * @param request : 请求参数
+     * @return : java.util.Set<java.lang.String>
+     * @author : lijie
+     * @date :2021/10/28 17:56
+     * Update By lijie 2021/10/28 17:56
+     */
+    Set<String> queryMultiBuildingOrFloorSpaceIds(HttpServletRequest request);
+    /***
+     * Description: 查询多建筑楼层下的空间列表
+     * @param request : 请求参数
+     * @return : java.util.Set<java.lang.String>
+     * @author : lijie
+     * @date :2021/10/28 17:56
+     * Update By lijie 2021/10/28 17:56
+     */
+    AdmResponse queryMultiBuildingOrFloorSpaces(HttpServletRequest request);
 }

+ 80 - 0
src/main/java/com/persagy/proxy/object/service/impl/AdmSpaceServiceImpl.java

@@ -10,12 +10,19 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.Sets;
 import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.common.context.AppContext;
+import com.persagy.dmp.common.helper.SpringHelper;
+import com.persagy.dmp.common.model.response.CommonResult;
 import com.persagy.dmp.define.entity.ObjectTypeDefine;
 import com.persagy.dmp.digital.client.DigitalObjectFacade;
+import com.persagy.dmp.digital.entity.ObjectDigital;
 import com.persagy.dmp.digital.entity.ObjectRelation;
+import com.persagy.dmp.simple.client.DigitalObjectSimpleFacade;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
+import com.persagy.proxy.adm.constant.GraphCodeEnum;
+import com.persagy.proxy.adm.constant.RelCodeEnum;
 import com.persagy.proxy.adm.request.AdmDCSQueryRequest;
 import com.persagy.proxy.adm.request.AdmQueryCriteria;
 import com.persagy.proxy.adm.request.AdmResponse;
@@ -36,6 +43,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -268,6 +276,78 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
         loadTrafficSpace(context, spaceIds, spaceType, false, result);
         return result;
     }
+    /***
+     * Description: 查询多建筑楼层下的空间id
+     * @param request : 请求参数
+     * @return : java.util.Set<java.lang.String>
+     * @author : lijie
+     * @date :2021/10/28 17:56
+     * Update By lijie 2021/10/28 17:56
+     */
+    @Override
+    public Set<String> queryMultiBuildingOrFloorSpaceIds(HttpServletRequest request) {
+        String groupCode = AppContext.getContext().getGroupCode();
+        String projectId = AppContext.getContext().getProjectId();
+        // 1.查询楼层下的空间的关系统计数据
+        CommonResult<List<ObjectRelation>> floorCountByObjIds = DigitalObjectSimpleFacade
+                .queryRelationCountByObjIds(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID,
+                        getMultiBuildingOrFloorQueryWrapper(request,RelCodeEnum.Fl2Sp.name()));
+        List<ObjectRelation> floorSpaceData = floorCountByObjIds.getData();
+        // 2.查询建筑下的空间的关系统计数据
+        CommonResult<List<ObjectRelation>> buildingCountByObjIds = DigitalObjectSimpleFacade
+                .queryRelationCountByObjIds(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID,
+                        getMultiBuildingOrFloorQueryWrapper(request, RelCodeEnum.Bd2Sp.name()));
+        List<ObjectRelation> buildingSpaceData = buildingCountByObjIds.getData();
+        Set<String> spaceIds = CollUtil.newHashSet(CollUtil.isNotEmpty(floorSpaceData), floorSpaceData
+                .stream().map(ObjectRelation::getObjTo).collect(Collectors.toSet()));
+        spaceIds.addAll(CollUtil.newHashSet(CollUtil.isNotEmpty(buildingSpaceData),
+                buildingSpaceData.stream().map(ObjectRelation::getObjTo).collect(Collectors.toSet())));
+        return spaceIds;
+    }
+    /***
+     * Description: 查询多建筑楼层下的空间列表
+     * @param request : 请求参数
+     * @return : java.util.Set<java.lang.String>
+     * @author : lijie
+     * @date :2021/10/28 17:56
+     * Update By lijie 2021/10/28 17:56
+     */
+    @Override
+    public AdmResponse queryMultiBuildingOrFloorSpaces(HttpServletRequest request) {
+        // 1.查询多建筑楼层下的空间id列表
+        Set<String> spaceIds = queryMultiBuildingOrFloorSpaceIds(request);
+        AdmQueryCriteria spaceCriteria = new AdmQueryCriteria();
+        String filters = " id in ['"+ String.join("', '", spaceIds) +"'] ";
+        spaceCriteria.setFilters(filters);
+        AdmQueryCriteria floorCriteria = new AdmQueryCriteria();
+        floorCriteria.setName("floorList");
+        AdmQueryCriteria buildingCriteria = new AdmQueryCriteria();
+        buildingCriteria.setName("building");
+        floorCriteria.setCascade(CollUtil.newArrayList(buildingCriteria));
+        spaceCriteria.setCascade(CollUtil.newArrayList(floorCriteria));
+        return super.doQuery(AdmContextUtil.toDmpContext(), spaceCriteria, AdmSpace.class);
+    }
+
+    /***
+     * Description: 获得多建筑楼层下的空间的查询条件
+     * @param request : 请求参数
+     * @param relCode : 边类型
+     * @return : com.fasterxml.jackson.databind.node.ObjectNode
+     * @author : lijie
+     * @date :2021/10/28 17:55
+     * Update By lijie 2021/10/28 17:55
+     */
+    private ObjectNode getMultiBuildingOrFloorQueryWrapper(HttpServletRequest request,String relCode) {
+        ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+        ObjectNode objectNode = objectMapper.createObjectNode();
+        if (StrUtil.isNotBlank(AppContext.getContext().getProjectId())){
+            objectNode.putPOJO("projectIds", Sets.newHashSet(AppContext.getContext().getProjectId()));
+        }
+        objectNode.putPOJO("graphCodes", Sets.newHashSet(GraphCodeEnum.ArchSubset.name()));
+        objectNode.putPOJO("relCodes", Sets.newHashSet(relCode));
+        objectNode.putPOJO("groups", Sets.newHashSet("objTo"));
+        return objectNode;
+    }
 
     /**
      * 装载交通关系

+ 19 - 32
src/main/java/com/persagy/proxy/report/controller/AdmSpaceInfoController.java

@@ -1,10 +1,19 @@
 package com.persagy.proxy.report.controller;
 
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.QueryParam;
 
+import cn.hutool.core.collection.CollUtil;
+import com.persagy.dmp.basic.dto.RequestData;
+import com.persagy.dmp.digital.client.DigitalObjectFacade;
+import com.persagy.dmp.digital.entity.ObjectDigital;
+import com.persagy.proxy.object.model.AdmSpace;
+import com.persagy.proxy.object.service.IAdmSpaceService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -51,12 +60,11 @@ import lombok.RequiredArgsConstructor;
 @RequestMapping("/space")
 public class AdmSpaceInfoController {
 
-	@Autowired
-	private IAdmISpaceService ispaceService;
-	@Autowired
-	private IAdmSystemService systemService;
-	@Autowired
-	private IAdmEquipmentService equipmentService;
+	private final IAdmISpaceService ispaceService;
+	private final IAdmSystemService systemService;
+	private final IAdmEquipmentService equipmentService;
+	private final IAdmSpaceService spaceService;
+
 	/**
 	 * 统计 属于多建筑楼层的空间
 	 *
@@ -65,34 +73,14 @@ public class AdmSpaceInfoController {
 	 */
 	@RequestMapping("/space-bd-fl")
 	public JSONObject queryCount(HttpServletRequest request) {
-		String groupCode = AppContext.getContext().getGroupCode();
-		String projectId = AppContext.getContext().getProjectId();
-		
-		ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
-		ObjectNode objectNode = objectMapper.createObjectNode();
-		objectNode.putPOJO("projectIds", Sets.newHashSet(projectId));
-		objectNode.putPOJO("graphCodes", Sets.newHashSet(GraphCodeEnum.ArchSubset.name()));
-		objectNode.putPOJO("relCodes", Sets.newHashSet(RelCodeEnum.Fl2Sp.name(), RelCodeEnum.Bd2Sp.name()));
-		objectNode.putPOJO("groups", Sets.newHashSet("objTo"));
-		CommonResult<List<ObjectRelation>> countByObjIds = DigitalObjectSimpleFacade.queryRelationCountByObjIds(groupCode, projectId, AdmCommonConstant.APP_ID, AdmCommonConstant.USER_ID, objectNode);
-		List<ObjectRelation> data = countByObjIds.getData();
-		
-		int count = 0;
+		Set<String> spaceIds = spaceService.queryMultiBuildingOrFloorSpaceIds(request);
 		JSONObject result = new JSONObject();
-		result.put("count", count);
+		result.put("count", spaceIds.size());
 		result.put("message", "");
 		result.put("result", "success");
-		if (CollectionUtil.isEmpty(data)) {
-			return result;
-		}
-		for (ObjectRelation objectRelation : data) {
-			if (objectRelation.getCount() != null && objectRelation.getCount() > 1) {
-				count++;
-			}
-		}
-		result.put("count", count);
 		return result;
 	}
+
 	/**
 	 * 统计 属于多建筑楼层的空间数据
 	 *
@@ -101,9 +89,7 @@ public class AdmSpaceInfoController {
 	 */
 	@RequestMapping("/space-bd-fl-data")
 	public AdmResponse querySpaceBdFlObj(HttpServletRequest request) {
-		AdmResponse response = AdmResponse.success();
-		response.setCount(0L);
-		return response;
+		return spaceService.queryMultiBuildingOrFloorSpaces(request);
 	}
 
 	/**
@@ -191,4 +177,5 @@ public class AdmSpaceInfoController {
 		request.resetRelationCond(true, graphCode, "Eq2Sp", type, spaceId, false);
 		return equipmentService.doQuery(AdmContextUtil.toDmpContext(), request, AdmEquipment.class);
 	}
+
 }