瀏覽代碼

空间接口:query

lvxianyun 3 年之前
父節點
當前提交
240bb2884d

+ 19 - 0
src/main/java/com/persagy/proxy/adm/model/AdmSpace.java

@@ -133,4 +133,23 @@ public class AdmSpace {
     //private T spaceOutline;
     /** 对象类型 */
     private String objectType = "space";
+
+    public String getZoneType(){
+        return zoneType;
+
+    }
+    public void setZoneType(String zoneType){
+        this.zoneType = zoneType;
+        this.classCode = zoneType;
+    }
+
+    public String getClassCode(){
+        return classCode;
+    }
+    public void setClassCode(String classCode){
+        this.zoneType = classCode;
+        this.classCode = classCode;
+    }
+
+
 }

+ 1 - 0
src/main/java/com/persagy/proxy/adm/service/IAdmSpaceService.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.persagy.proxy.adm.model.AdmDCSQueryRequest;
 import com.persagy.proxy.adm.model.AdmSpace;
 import com.persagy.proxy.adm.model.AdmUpDataFloorAndBuildingRequests;
+import com.persagy.proxy.adm.request.AdmQueryCriteria;
 import com.persagy.proxy.adm.request.AdmResponse;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 

+ 143 - 59
src/main/java/com/persagy/proxy/adm/service/impl/AdmSpaceServiceImpl.java

@@ -6,25 +6,25 @@ import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
 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.persagy.dmp.basic.model.QueryCriteria;
-import com.persagy.dmp.basic.utils.JsonNodeUtils;
 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;
 import com.persagy.proxy.adm.service.IAdmSpaceService;
+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;
 import com.persagy.proxy.common.entity.ObjRelationDTO;
+import com.sun.xml.internal.bind.v2.TODO;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.poi.ss.formula.functions.T;
+import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -49,8 +49,8 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
         Map<String, AdmSpace> spaceIdMap = CollUtil.fieldValueMap(voList, BaseEntity.PROP_ID);
         //key spid, value floorId
         Map<String, String> spId2FlId_map = voList.stream().filter(admSpace -> StrUtil.isNotEmpty(admSpace.getFloorId())).collect(Collectors.toMap(AdmSpace::getId,AdmSpace::getFloorId));
-        //查询空间中floorId 对应的flool
-        DmpResult<JSONArray> floors = queryFloors(context, spId2FlId_map);
+        //查询空间中floorId 对应的floor
+        DmpResult<JSONArray> floors = queryFloorsByFloorIds(context, spId2FlId_map.values());
         ArrayList<AdmFloor> floorList = CollUtil.newArrayList(JSONUtil.toList(floors.getData().toString(),AdmFloor.class));
         //space.height = floor.infos.height
         List<AdmSpace> vos = processHeight(spaceIdMap, floorList, spId2FlId_map);
@@ -122,7 +122,98 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
 
     @Override
     public AdmResponse doQuerySpaces(InstanceUrlParam context, AdmDCSQueryRequest request) {
-        return null;
+        QueryCriteria dmpRequest = AdmQueryCriteriaHelper.toDmpCriteria(request);
+        //查询的时候,floorId,buildingId 按照空间对象的自定义信息点处理
+        //TODO 这个ifelse判断是原来的代码实现,写此方法实现的时候不清楚实际业务,保留原来的判断,之后了解业务再根据业务调整
+        DmpResult<JSONArray> dmpResult = new DmpResult<>();
+        List spaceArray = new ArrayList();
+        List<String> zoneTypeList = StrUtil.isNotEmpty(request.getZoneType()) ? CollUtil.newArrayList(request.getZoneType()) : request.getZoneTypeList();
+        if(StrUtil.isNotEmpty(request.getBuildingId()) && StrUtil.isNotEmpty(request.getFloorId()) && !request.getFloorId().equals("isnull")){
+            querySpaceByFl(dmpRequest,context, spaceArray, zoneTypeList, request.getFloorId(), "Fl2Sp");
+
+        }else if(StrUtil.isNotEmpty(request.getBuildingId()) && StrUtil.isNotEmpty(request.getFloorId()) && request.getFloorId().equals("isnull")){
+            QueryCriteria queryFloor = ensureQueryCommParm(dmpRequest,context, Arrays.asList("floor"), "floor");
+            ObjectNode criteriaFl = queryFloor.getCriteria();
+            criteriaFl.put("buildingId", request.getBuildingId());
+            queryFloor.setCriteria(criteriaFl);
+            DmpResult<JSONArray> dmpResultFloors = queryObj(context, queryFloor);
+            List<AdmFloor> floorList = JSONUtil.toList(JSONUtil.toJsonStr(dmpResultFloors.getData()), AdmFloor.class);
+            Map<String, AdmFloor> floorMap = CollUtil.fieldValueMap(floorList, BaseEntity.PROP_ID);
+
+            if(CollUtil.isNotEmpty(floorMap)){
+                QueryCriteria queryCriteria = ensureQueryCommParm(dmpRequest, context, zoneTypeList, "space");
+                ObjectNode criteriaPe = queryCriteria.getCriteria();
+                JSONArray jsonArray = new JSONArray();
+                floorMap.keySet().forEach(floorId -> jsonArray.add(floorId));
+                criteriaPe.putPOJO("floorId", jsonArray);
+                queryCriteria.setCriteria(criteriaPe);
+                dmpResult = queryObj(context, queryCriteria);
+                if(CollUtil.isNotEmpty(dmpResult.getData())){
+                    spaceArray.addAll(dmpResult.getData());
+                }
+                querySpaceByFl(dmpRequest, context, spaceArray, zoneTypeList, request.getBuildingId(), "Bd2Sp");
+            }
+        }else if(StrUtil.isNotEmpty(request.getBuildingId()) && StrUtil.isEmpty(request.getFloorId()) && !request.getBuildingId().equals("isnull")){
+            querySpaceByFl(dmpRequest,context, spaceArray, zoneTypeList, request.getBuildingId(), "Bd2Sp");
+        }else if(StrUtil.isNotEmpty(request.getBuildingId()) && StrUtil.isEmpty(request.getFloorId()) && request.getBuildingId().equals("isnull")){
+            //未明确建筑
+            QueryCriteria queryCriteria = ensureQueryCommParm(dmpRequest, context, zoneTypeList, "space");
+            ObjectNode criteriaPe = queryCriteria.getCriteria();
+            JSONObject isnull = new JSONObject();
+            isnull.put("$null", true);
+            criteriaPe.putPOJO("buildingId", isnull);
+            queryCriteria.setCriteria(criteriaPe);
+            dmpResult = queryObj(context, queryCriteria);
+            if(CollUtil.isNotEmpty(dmpResult.getData())){
+                spaceArray.addAll(dmpResult.getData());
+            }
+        }else if(StrUtil.isEmpty(request.getBuildingId()) && StrUtil.isEmpty(request.getFloorId())){
+            QueryCriteria queryCriteria = ensureQueryCommParm(dmpRequest, context, zoneTypeList, "space");
+            ObjectNode criteriaPe = queryCriteria.getCriteria();
+            JSONObject isnull = new JSONObject();
+            isnull.put("$null", false);
+            criteriaPe.putPOJO("floorId", isnull);
+            queryCriteria.setCriteria(criteriaPe);
+            dmpResult = queryObj(context, queryCriteria);
+            if(CollUtil.isNotEmpty(dmpResult.getData())){
+                spaceArray.addAll(dmpResult.getData());
+            }
+        }
+        //处理查询结果转化为目标返回值
+        List<JSONObject> jsonObjects = new ArrayList<JSONObject>();
+        if(CollUtil.isNotEmpty(spaceArray)){
+            List<AdmSpace> spaceList = JSONUtil.toList(JSONUtil.toJsonStr(spaceArray), AdmSpace.class);
+            Map<String, AdmSpace> admSpaceMap = CollUtil.fieldValueMap(spaceList, BaseEntity.PROP_ID);
+            admSpaceMap.values().stream().forEach(admSpace -> {
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("zoneType", admSpace.getClassCode());
+                jsonObject.put("floorId", admSpace.getFloorId());
+                jsonObjects.add(jsonObject);
+            });
+        }
+        AdmResponse admResponse = new AdmResponse();
+        admResponse.setContent(jsonObjects);
+        admResponse.setTotal(jsonObjects.size()*1l);
+        admResponse.setPageSize(request.getPageSize());
+        admResponse.setPageNumber(request.getPageNumber());
+        return admResponse;
+    }
+
+    /**
+     * 根据信息点查询空间
+     * @param context
+     * @param spaceArray
+     * @param zoneTypeList
+     * @param objFrom  flooIds /  bulidingIds
+     * @param relCode
+     */
+    private void querySpaceByFl(QueryCriteria dmpRequest, InstanceUrlParam context, List spaceArray, List<String> zoneTypeList, String objFrom, String relCode){
+        QueryCriteria queryCriteria = ensureQueryCommParm(dmpRequest,context, zoneTypeList, "space");
+        addRelationTo(queryCriteria,objFrom,relCode);
+        DmpResult<JSONArray> dmpResult = queryObj(context, queryCriteria);
+        if(CollUtil.isNotEmpty(dmpResult.getData())){
+            spaceArray.addAll(dmpResult.getData());
+        }
     }
 
     /**
@@ -174,16 +265,20 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
         return rwdClient.queryObject(context, paraPe);
     }
 
-    private JSONArray queryAndDealObjs(InstanceUrlParam context, Set<String> codes){
-        QueryCriteria criteriaObject = new QueryCriteria();
+    private QueryCriteria ensureQueryCommParm(QueryCriteria dmpRequest, InstanceUrlParam context, Collection<String> classCodes, String objType){
         ObjectNode criteriaEq = JsonNodeFactory.instance.objectNode();
-        ArrayNode array = criteriaEq.putObject("classCode").putArray("$in");
-        codes.forEach(code -> array.add(code));
-        criteriaEq.put("objType", "space");
-        criteriaObject.setSize(1000L);
-        criteriaObject.setPage(1L);
-        criteriaObject.setCriteria(criteriaEq);
+        if(CollUtil.isNotEmpty(classCodes)){
+            ArrayNode array = criteriaEq.putObject("classCode").putArray("$in");
+            classCodes.forEach(code -> array.add(code));
+        }
+        criteriaEq.put("objType", objType);
+        dmpRequest.setCriteria(criteriaEq);
+        return dmpRequest;
+    }
 
+    private JSONArray queryAndDealObjs(InstanceUrlParam context, Set<String> codes){
+        QueryCriteria criteriaObject = ensureQueryCommParm(new QueryCriteria(), context, codes,"space");
+        criteriaObject.setSize(50L);
         DmpResult<JSONArray> dmpResult = queryObj(context, criteriaObject);
         if(CollUtil.isEmpty(dmpResult.getData())){
             return null;
@@ -214,35 +309,22 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
     /**
      * 查询空间flooId对应的infos中height存在的 flool
      * @param context
-     * @param spId2FlId_map
+     * @param floolIds
      * @return
      */
-    private DmpResult<JSONArray> queryFloors(InstanceUrlParam context, Map<String, String> spId2FlId_map){
-        QueryCriteria criteriaObject = new QueryCriteria();
-        ObjectNode criteriaPe = JsonNodeFactory.instance.objectNode();
-        ArrayNode array = criteriaPe.putObject("id").putArray("$in");
-        spId2FlId_map.values().forEach(floorId -> array.add(floorId));
-        criteriaPe.put("classCode", "floor");
-        criteriaPe.put("objType", "floor");
-
+    private DmpResult<JSONArray> queryFloorsByFloorIds(InstanceUrlParam context, Collection<String> floolIds){
+        QueryCriteria queryCriteria = ensureQueryCommParm(new QueryCriteria(),context, CollUtil.newArrayList("floor"),"floor");
+        ObjectNode criteriaPe = queryCriteria.getCriteria();
+        if(CollUtil.isNotEmpty(floolIds)){
+            ArrayNode array = criteriaPe.putObject("id").putArray("$in");
+            floolIds.forEach(floorId -> array.add(floorId));
+        }
         JSONObject height = new JSONObject();
         height.put("$gt", 0f);
         criteriaPe.putPOJO("height", height);
-
-        criteriaObject.setCriteria(criteriaPe);
-        criteriaObject.setSize(spId2FlId_map.size() * 1L);
-        criteriaObject.setPage(1L);
-        criteriaObject.setWithoutCount(true);
-        // 转换参数
-        JSONObject paraPe = null;
-        try {
-            String paraStr = objectMapper.writeValueAsString(criteriaObject);
-            paraPe = JSONObject.parseObject(paraStr);
-        } catch (JsonProcessingException e) {
-            log.error(e.getMessage(), e);
-            return null;
-        }
-        return rwdClient.queryObject(context, paraPe);
+        queryCriteria.setCriteria(criteriaPe);
+        queryCriteria.setWithoutCount(true);
+        return queryObj(context, queryCriteria);
     }
 
     /**
@@ -362,6 +444,24 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
         defineType.remove("id");
     }
 
+    private void addRelationTo(QueryCriteria rwdQueryCriteria, String objFrom, String relCode){
+        ObjectNode relationTO = JsonNodeFactory.instance.objectNode();
+        relationTO.put("relCode", relCode);
+        relationTO.put("objFrom", objFrom);
+        ObjectNode criteria = rwdQueryCriteria.getCriteria();
+        criteria.putPOJO("relationTo", relationTO);
+        rwdQueryCriteria.setCriteria(criteria);
+    }
+
+    private void addRelationFrom(QueryCriteria rwdQueryCriteria, String objTo, String relCode){
+        ObjectNode relationFrom = JsonNodeFactory.instance.objectNode();
+        if(StrUtil.isNotEmpty(objTo)){
+            relationFrom.put("objTo", objTo);
+        }
+        ObjectNode criteria = rwdQueryCriteria.getCriteria();
+        criteria.putPOJO("relationFrom", relationFrom);
+        rwdQueryCriteria.setCriteria(criteria);
+    }
     /**
      *  查询存在空间的数量
      * @param context
@@ -370,27 +470,11 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
      * @return
      */
     private int countSpace(InstanceUrlParam context, String classCode, String objFrom){
-        QueryCriteria rwdQueryCriteria = new QueryCriteria();
-        ObjectNode rwdCriteria = JsonNodeFactory.instance.objectNode();
-        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);
-        // 转换参数
-        JSONObject paraRel = null;
-        try {
-            String paraStr = objectMapper.writeValueAsString(rwdQueryCriteria);
-            paraRel = JSONObject.parseObject(paraStr);
-        } catch (JsonProcessingException e) {
-            log.error(e.getMessage(), e);
-        }
-        return rwdClient.queryObject(context, paraRel).getCount();
+        QueryCriteria queryCriteria = ensureQueryCommParm(new QueryCriteria(), context, CollUtil.newArrayList(classCode),"space");
+        addRelationTo(queryCriteria, objFrom,"Fl2Sp");
+        queryCriteria.setOnlyCount(true);
+        DmpResult<JSONArray> dmpResult = queryObj(context, queryCriteria);
+        return dmpResult.getCount();
     }