Quellcode durchsuchen

空间接口:查询项目定义的空间

lvxianyun vor 3 Jahren
Ursprung
Commit
94fa122ea2

+ 7 - 10
src/main/java/com/persagy/proxy/adm/controller/AdmSpaceController.java

@@ -2,6 +2,8 @@ package com.persagy.proxy.adm.controller;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
 import com.persagy.proxy.adm.model.*;
 import com.persagy.proxy.adm.request.AdmCreateRequest;
@@ -118,11 +120,10 @@ public class AdmSpaceController {
      */
     @PostMapping("/query")
     public AdmResponse query(@QueryParam("projectId") String projectId,
-                             @RequestBody AdmQueryCriteria request) throws Exception {
+                             @RequestBody AdmDCSQueryRequest request) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName("space");
-        return service.doQuery(context, request, AdmSpace.class);
+        return service.doQuerySpaces(context, request);
     }
 
     /**
@@ -224,24 +225,21 @@ public class AdmSpaceController {
         list.add("infos");
         list.add("properties");
         request.setProjection(list);
-        return service.doQuerySpaces(context, request, AdmSpace.class);
+        return service.doQuery(context, request, AdmSpace.class);
     }
 
 
     /**
      * 获取项目下已有的空间类型
      * @param projectId
-     * @param request
      * @return
      * @throws Exception
      */
     @PostMapping("/space-type")
-    public AdmResponse querySpaceType(@QueryParam("projectId") String projectId,
-                                 @RequestBody AdmQueryCriteria request) throws Exception {
+    public List<JSONObject> querySpaceType(@QueryParam("projectId") String projectId) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        request.setName("space");
-        return service.doQuery(context,request,AdmSpace.class);
+        return service.doQuerySpaceTypes(context);
     }
 
     /**
@@ -256,7 +254,6 @@ public class AdmSpaceController {
                              @RequestBody AdmDCSQueryRequest request) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-
         return service.doQueryType(context, request);
     }
 

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

@@ -1,13 +1,12 @@
 package com.persagy.proxy.adm.service;
 
-import com.persagy.proxy.adm.model.AdmBuilding;
+import com.alibaba.fastjson.JSONArray;
+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;
-import org.apache.poi.ss.formula.functions.T;
 
 import java.util.List;
 
@@ -70,7 +69,8 @@ public interface IAdmSpaceService extends IAdmBaseService<AdmSpace>{
 
 
     /**
-     * 查询业务空间
+     * 查询业务空间 级联查询:建筑(buildingList),楼层(floorlList),空间类型(objectType)未明确楼层(isnull),未明确建筑(isnull)
      */
-    AdmResponse doQuerySpaces(InstanceUrlParam context, AdmQueryCriteria request, Class<AdmSpace> clazz);
+    AdmResponse doQuerySpaces(InstanceUrlParam context, AdmDCSQueryRequest request);
+    List<JSONObject> doQuerySpaceTypes(InstanceUrlParam context);
 }

+ 94 - 5
src/main/java/com/persagy/proxy/adm/service/impl/AdmSpaceServiceImpl.java

@@ -6,12 +6,15 @@ 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;
@@ -21,6 +24,7 @@ import com.persagy.proxy.common.entity.DmpResult;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 import com.persagy.proxy.common.entity.ObjRelationDTO;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.ss.formula.functions.T;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -97,7 +101,9 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
     @Override
     public AdmResponse doQueryType(InstanceUrlParam context, AdmDCSQueryRequest request) {
         //查询定义类型
-        DmpResult<JSONArray> resultDef = queryDefineType(context);
+        ObjectNode criteriaEq = JsonNodeFactory.instance.objectNode();
+        criteriaEq.put("parentCode", "space");
+        DmpResult<JSONArray> resultDef = queryDefineType(context, criteriaEq);
         List<JSONObject> defineList = null;
         if(resultDef.getResult().equals(DmpResult.SUCCESS)){
             defineList = JSONUtil.toList(resultDef.getData().toString(), JSONObject.class);
@@ -115,10 +121,95 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
     }
 
     @Override
-    public AdmResponse doQuerySpaces(InstanceUrlParam context, AdmQueryCriteria request, Class<AdmSpace> clazz) {
+    public AdmResponse doQuerySpaces(InstanceUrlParam context, AdmDCSQueryRequest request) {
         return null;
     }
 
+    /**
+     * 空间的类型是根据项目自定义的
+     * 参见中心
+     * @Select("SELECT s.object_type as type,d.name  FROM zone_space_base s
+     * LEFT JOIN dict.dict_space_project d ON s.object_type = d.id WHERE s.project_id = #{projectId} AND d.project_id = #{projectId}
+     * GROUP BY object_type, d.name")
+     * @param context
+     * @return
+     */
+    @Override
+    public List<JSONObject> doQuerySpaceTypes(InstanceUrlParam context) {
+        //根据项目id查询空间类型
+        Map<String, String> codeNameMap = queryProjectDefineType(context);
+        if(CollUtil.isNotEmpty(codeNameMap)){
+            //查询object
+            JSONArray demObjs = queryAndDealObjs(context, codeNameMap.keySet());
+            if(CollUtil.isNotEmpty(demObjs)){
+                List<AdmSpace> spaceList = JSONArray.parseArray(JSONUtil.toJsonStr(demObjs), AdmSpace.class);
+                Set<String> classCodes = spaceList.stream().map(space -> space.getClassCode()).collect(Collectors.toSet());
+                if(CollUtil.isNotEmpty(classCodes)){
+                    codeNameMap.keySet().removeIf(code -> !classCodes.contains(code));
+                }
+            }
+        }
+        if(CollUtil.isNotEmpty(codeNameMap)){
+            List<JSONObject> list = new ArrayList<>(codeNameMap.size());
+            codeNameMap.keySet().stream().forEach(code ->{
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("name",codeNameMap.get(code));
+                jsonObject.put("code",code);
+                list.add(jsonObject);
+            });
+            return  list;
+        }else{
+            return null;
+        }
+    }
+
+    private DmpResult<JSONArray> queryObj(InstanceUrlParam context, QueryCriteria criteriaObject){
+        JSONObject paraPe = null;
+        try {
+            String paraStr = objectMapper.writeValueAsString(criteriaObject);
+            paraPe = JSONObject.parseObject(paraStr);
+        } catch (JsonProcessingException e) {
+            throw new RuntimeException("转换查询条件出错:" + e.getMessage());
+        }
+        return rwdClient.queryObject(context, paraPe);
+    }
+
+    private JSONArray queryAndDealObjs(InstanceUrlParam context, Set<String> codes){
+        QueryCriteria criteriaObject = new QueryCriteria();
+        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);
+
+        DmpResult<JSONArray> dmpResult = queryObj(context, criteriaObject);
+        if(CollUtil.isEmpty(dmpResult.getData())){
+            return null;
+        }
+        JSONArray demObjs = dmpResult.getData();
+        if(dmpResult.getCount() > criteriaObject.getSize()){
+            for(int page = 2; page < dmpResult.getCount()/criteriaObject.getSize()+1; page++){
+                criteriaObject.setPage(page*1L);
+                demObjs.addAll(queryObj(context, criteriaObject).getData());
+            }
+        }
+        return demObjs;
+    }
+
+    private Map<String, String> queryProjectDefineType(InstanceUrlParam context){
+        Map<String, String> codeNameMap = null;
+        ObjectNode criteriaEq = JsonNodeFactory.instance.objectNode();
+        criteriaEq.put("projectId", context.getProjectId());
+        criteriaEq.put("objType", "space");
+        DmpResult<JSONArray> resultDef = queryDefineType(context, criteriaEq);
+        if(resultDef.getResult().equals(DmpResult.SUCCESS) && CollUtil.isNotEmpty(resultDef.getData())){
+            List<ObjectTypeDefine> defineList = JSONUtil.toList(resultDef.getData().toString(), ObjectTypeDefine.class);
+            codeNameMap = defineList.stream().collect(Collectors.toMap(ObjectTypeDefine::getCode, ObjectTypeDefine::getName, (k1,k2)->k1));
+        }
+        return codeNameMap;
+    }
 
     /**
      * 查询空间flooId对应的infos中height存在的 flool
@@ -303,10 +394,8 @@ public class AdmSpaceServiceImpl extends AbstractAdmBaseServiceImpl<AdmSpace> im
     }
 
 
-    private DmpResult<JSONArray> queryDefineType(InstanceUrlParam context){
+    private DmpResult<JSONArray> queryDefineType(InstanceUrlParam context, ObjectNode criteriaEq){
         QueryCriteria criteriaObject = new QueryCriteria();
-        ObjectNode criteriaEq = JsonNodeFactory.instance.objectNode();
-        criteriaEq.put("parentCode", "space");
         criteriaObject.setCriteria(criteriaEq);
         JSONObject paraPe = null;
         try {