Browse Source

空间接口:/object/zone/type

lvxianyun 3 years ago
parent
commit
5acc357096

+ 31 - 45
src/main/java/com/persagy/proxy/adm/service/impl/AdmSpaceServiceImpl.java

@@ -3,7 +3,6 @@ package com.persagy.proxy.adm.service.impl;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -13,7 +12,6 @@ import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.common.model.entity.BaseEntity;
-import com.persagy.dmp.define.entity.ObjectTypeDefine;
 import com.persagy.proxy.adm.model.*;
 import com.persagy.proxy.adm.request.AdmQueryCriteria;
 import com.persagy.proxy.adm.request.AdmResponse;
@@ -104,18 +102,8 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
         if(resultDef.getResult().equals(DmpResult.SUCCESS)){
             defineList = JSONUtil.toList(resultDef.getData().toString(), JSONObject.class);
             //获取实际空间对象的数量
-            Map<String, JSONObject> classCodeMap = CollUtil.fieldValueMap(defineList, "code");
-            if(StrUtil.isNotEmpty(request.getFloorId())){
-                //根据classCode floorId 查询查询实际存在的空间
-                //根据floorId查询关系 Fl2Sp
-                DmpResult<List<ObjRelationDTO>> relationDmpResult = queryRelationByFloorId(context, "Fl2Sp",  request.getFloorId());
-                //根据关系查询结果中的spaceId查询存在的空间数量
-                Map<String, ObjRelationDTO> relationMap = new HashMap<>(16);
-                if(CollUtil.isEmpty(relationDmpResult.getData())){
-                    relationMap = CollUtil.fieldValueMap(relationDmpResult.getData(), "objTo");
-                }
-                transTo(context, defineList, relationMap.keySet());
-            }
+            //根据classCode floorId 查询查询实际存在的空间
+            assembleDefineTypes(context, defineList, request.getFloorId());
             // 设置返回值
             AdmResponse response = AdmResponse.success(defineList);
             Long total = resultDef.getCount() == null ? null : resultDef.getCount().longValue();
@@ -254,56 +242,53 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
     private void deleteRelation(InstanceUrlParam context, String relCode, String ObjType){
     }
 
-    /** 根据floorId查询关系 Fl2Sp
-     * @return*/
-    private DmpResult<List<ObjRelationDTO>> queryRelationByFloorId(InstanceUrlParam context, String relCode, String objFrom){
-        QueryCriteria dmpRequest = new QueryCriteria();
-        ObjectNode criteria = JsonNodeFactory.instance.objectNode();
-        criteria.put("relCode", relCode);
-        if(StrUtil.isNotEmpty(objFrom)){
-            criteria.put("objFrom", objFrom);
-        }
-        dmpRequest.setCriteria(criteria);
-        dmpRequest.setPage(1L);
-        dmpRequest.setWithoutCount(true);
-        // 转换参数
-        JSONObject paraRel = null;
-        try {
-            String paraStr = objectMapper.writeValueAsString(dmpRequest);
-            paraRel = JSONObject.parseObject(paraStr);
-        } catch (JsonProcessingException e) {
-            log.error(e.getMessage(), e);
-        }
-        return rwdClient.queryRelation(context, dmpRequest);
-    }
 
     /**
      * 转换为目标实体,并增加属性
      */
-    private void transTo(InstanceUrlParam context, List<JSONObject> defineList, Set<String> relations){
+    private void assembleDefineTypes(InstanceUrlParam context, List<JSONObject> defineList, String floorId){
         boolean needCount = true;
         defineList.stream().forEach(defineType -> {
             //查询空间数量
-            int count = needCount ? countSpace(context, defineType.getString("code"), relations) : 0;
-            defineType.put("count", count);
-            defineType.put("projectId", context.getProjectId());
+            int count = needCount ? countSpace(context, defineType.getString("code"), floorId) : 0;
+            //处理单个对象
+            assembleDefineObj(defineType, count, context.getProjectId());
         });
     }
 
     /**
-     * 查询存在空间的数量
+     * 单个转换为目标实体,并增加属性
+     */
+    private void assembleDefineObj(JSONObject defineType, int count, String projectId){
+        defineType.put("count", count);
+        defineType.put("projectId", projectId);
+        defineType.remove("aliasName");
+        defineType.remove("aliasCode");
+        defineType.remove("valid");
+        defineType.remove("objType");
+        defineType.remove("groupCode");
+        defineType.remove("parentCode");
+        defineType.remove("id");
+    }
+
+    /**
+     *  查询存在空间的数量
      * @param context
      * @param classCode
-     * @param spaceIds
+     * @param objFrom
      * @return
      */
-    private int countSpace(InstanceUrlParam context, String classCode, Set<String> spaceIds){
+    private int countSpace(InstanceUrlParam context, String classCode, String objFrom){
         QueryCriteria rwdQueryCriteria = new QueryCriteria();
         ObjectNode rwdCriteria = JsonNodeFactory.instance.objectNode();
-        ArrayNode arrayIds = rwdCriteria.putObject("id").putArray("$in");
-        spaceIds.forEach(spaceId -> arrayIds.add(spaceId));
         rwdCriteria.put("objType", "space");
         rwdCriteria.put("classCode", classCode);
+        ObjectNode relationTO = JsonNodeFactory.instance.objectNode();
+        relationTO.put("relCode", "Fl2Sp");
+        if(StrUtil.isNotEmpty(objFrom)){
+            relationTO.put("objFrom", objFrom);
+        }
+        rwdCriteria.putPOJO("relationTo", relationTO);
         rwdQueryCriteria.setCriteria(rwdCriteria);
         rwdQueryCriteria.setOnlyCount(true);
         // 转换参数
@@ -322,6 +307,7 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
         QueryCriteria criteriaObject = new QueryCriteria();
         ObjectNode criteriaEq = JsonNodeFactory.instance.objectNode();
         criteriaEq.put("parentCode", "space");
+        criteriaObject.setCriteria(criteriaEq);
         JSONObject paraPe = null;
         try {
             String paraStr = objectMapper.writeValueAsString(criteriaObject);