浏览代码

优化建筑下未有楼层的空间查询

zhangqiankun 3 年之前
父节点
当前提交
d60c7a4121

+ 1 - 1
src/main/java/com/persagy/proxy/adm/service/impl/AbstractAdmBaseServiceImpl.java

@@ -112,7 +112,7 @@ public class AbstractAdmBaseServiceImpl<T> implements IAdmBaseService<T> {
      * @param name
      * @param cascades
      */
-    private void processCascade(InstanceUrlParam context, List admVOs, String name, List<AdmQueryCriteria> cascades) {
+    public void processCascade(InstanceUrlParam context, List admVOs, String name, List<AdmQueryCriteria> cascades) {
         if(CollUtil.isEmpty(admVOs) || CollUtil.isEmpty(cascades)) {
             return;
         }

+ 49 - 46
src/main/java/com/persagy/proxy/object/service/impl/AdmSpaceServiceImpl.java

@@ -16,6 +16,7 @@ import org.springframework.stereotype.Service;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ArrayNode;
@@ -25,7 +26,6 @@ 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.entity.BaseEntity;
 import com.persagy.dmp.common.model.response.CommonResult;
 import com.persagy.dmp.define.entity.ObjectTypeDefine;
 import com.persagy.dmp.digital.client.DigitalObjectFacade;
@@ -40,6 +40,8 @@ import com.persagy.proxy.adm.request.AdmResponse;
 import com.persagy.proxy.adm.service.IAdmRelationService;
 import com.persagy.proxy.adm.service.impl.AbstractAdmBaseServiceImpl;
 import com.persagy.proxy.adm.utils.AdmContextUtil;
+import com.persagy.proxy.adm.utils.AdmEntityTransferUtil;
+import com.persagy.proxy.adm.utils.AdmQueryCriteriaHelper;
 import com.persagy.proxy.common.client.DmpRwdClient;
 import com.persagy.proxy.common.entity.DmpResult;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
@@ -50,8 +52,10 @@ import com.persagy.proxy.object.model.AdmSystem;
 import com.persagy.proxy.object.service.IAdmEquipmentService;
 import com.persagy.proxy.object.service.IAdmSpaceService;
 import com.persagy.proxy.object.service.IAdmSystemService;
+import com.persagy.proxy.report.service.IRelationReportService;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -74,6 +78,8 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
     private IAdmEquipmentService equipmentService;
     @Autowired
     private IAdmSystemService systemService;
+    @Autowired
+    private IRelationReportService relationReportService;
 
     @Override
     public AdmResponse doQuery(InstanceUrlParam context, AdmQueryCriteria request, Class<AdmSpace> clazz) {
@@ -148,44 +154,11 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
             relationTo.put("objFrom", request.getFloorId());
             request.setRelationTo(relationTo);
         }else if(StrUtil.isNotEmpty(request.getBuildingId()) && StrUtil.isNotEmpty(request.getFloorId()) && request.getFloorId().equals("isnull")){
-            //明确建筑,不明确楼层
-            //查询建筑下的楼层
-            QueryCriteria queryCriteriaRelation = new QueryCriteria();
-            ObjectNode criteria = JsonNodeFactory.instance.objectNode();
-            criteria.put("relCode", "Bd2Fl");
-            criteria.put("graphCode", "ArchSubset");
-            criteria.put("objFrom", request.getBuildingId());
-            queryCriteriaRelation.setCriteria(criteria);
-            List<ObjectRelation> relations = relationService.queryByCondition(AdmContextUtil.toDmpContext(), queryCriteriaRelation);
-            if(CollUtil.isNotEmpty(relations)){
-                Map<String, ObjectRelation> objectRelationMap = CollUtil.fieldValueMap(relations, "objTo");
-                //查询 建筑 不在楼层下 的空间
-                //1 查询楼层下的空间 spaceIdList
-                ObjectNode relationTo = JsonNodeFactory.instance.objectNode();
-                relationTo.put("relCode", "Fl2Sp");
-                relationTo.put("graphCode", "ArchSubset");
-                ArrayNode arrayNode = relationTo.putObject("objFrom").putArray("$in");
-                objectRelationMap.keySet().stream().forEach(floorId -> arrayNode.add(floorId));
-                request.setRelationTo(relationTo);
-                AdmResponse spaceFl = doQuery(AdmContextUtil.toDmpContext(), request, AdmSpace.class);
-                request.setRelationTo(null);
-                //2 查询建筑下的空间 and space not in spaceIdList
-                if(CollUtil.isNotEmpty(spaceFl.getContent())){
-                    List<AdmSpace> admSpaceList = (List<AdmSpace>) spaceFl.getContent();
-                    Map<String, AdmSpace> admSpaceMap = CollUtil.fieldValueMap(admSpaceList, BaseEntity.PROP_ID);
-                    String ids = request.getFilters() +"; not id in ['"+ String.join("', '", admSpaceMap.keySet())+"']";
-                    request.setFilters(ids);
-                }
-                request.setFilters(request.getFilters() + "; buildingId = '"+request.getBuildingId()+"'");
-            }else{
-                //查询建筑下的空间
-                ObjectNode relationTo = JsonNodeFactory.instance.objectNode();
-                relationTo.put("relCode", "Bd2Sp");
-                relationTo.put("graphCode", "ArchSubset");
-                relationTo.put("objFrom", request.getBuildingId());
-                request.setRelationTo(relationTo);
-            }
-
+        	//查询此建筑下未关联楼层的空间
+        	AdmResponse response = this.query(request);
+        	//空间需要补充分类名称属性
+            ensureSpecialValues(context, (List<AdmSpace>) response.getContent());
+            return response;
         }else if(StrUtil.isNotEmpty(request.getBuildingId()) && StrUtil.isEmpty(request.getFloorId()) && !request.getBuildingId().equals("isnull")){
             //查询建筑下的空间
             ObjectNode relationTo = JsonNodeFactory.instance.objectNode();
@@ -358,6 +331,43 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
     }
 
     /***
+     * Description: 根据查询条件查询空间统计数据,定制接口,后续可优化口
+     * @param request : 请求参数
+     * @return : com.persagy.proxy.adm.request.AdmResponse
+     * @author : lijie
+     * @date :2021/10/28 21:07
+     * Update By lijie 2021/10/28 21:07
+     */
+    private AdmResponse query(AdmDCSQueryRequest request) {
+    	String orders = request.getOrders();
+    	List<OrderItem> orderItem = AdmQueryCriteriaHelper.toOrderItem(orders);
+    	Set<String> classCodes = StrUtil.isBlank(request.getZoneType()) ? request.getZoneTypeList() : Sets.newHashSet(request.getZoneType());
+    	ObjectNode objectNode = objectMapper.createObjectNode();
+    	ObjectNode condition = objectMapper.createObjectNode();
+    	condition.put("$null", true);
+    	objectNode.putPOJO("floorId", condition);
+    	List<ObjectNode> queryObjects = this.relationReportService.queryObjects(objectNode, AppContext.getContext().getGroupCode(), AppContext.getContext().getProjectId(), 
+    			null, classCodes, Sets.newHashSet("space"), orderItem);
+    	
+        List<AdmSpace> admVOs = AdmEntityTransferUtil.toAdmMultiEntity(queryObjects, request.getProjection(), AdmSpace.class);
+        // 级联查询
+        processCascade(AdmContextUtil.toDmpContext(), admVOs, request.getName(), request.getCascade());
+        // 设置返回值
+        AdmResponse response = AdmResponse.success(admVOs);
+        if(CollectionUtil.isEmpty(queryObjects)){
+            response.setTotal(0L);
+            response.setCount(0L);
+        }else {
+            response.setTotal((long) queryObjects.size());
+        }
+        response.setPageNumber(request.getPageNumber());
+        response.setPageSize(request.getPageSize());
+        // 系统需要补充分类名称属性
+        ensureSpecialValues(AdmContextUtil.toDmpContext(), admVOs);
+        return response;
+    }
+    
+    /***
      * Description: 子类重写,以便处理带buildingId
      * @param dmpRequest : 中台查询参数
      * @return : void
@@ -373,13 +383,6 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
         }
         
         ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
-        if (criteria.has("not id")) {
-    		ObjectNode objectNode = objectMapper.createObjectNode();
-    		objectNode.putPOJO("$not in", criteria.get("not id"));
-    		criteria.putPOJO("id", objectNode);
-    		criteria.remove("not id");
-		}
-        
         if (criteria.has("floorId")){
             // 有建筑id过滤
             ObjectNode relationTo = objectMapper.createObjectNode();