Quellcode durchsuchen

查询对象中已存在的系统设备类树

linhuili vor 3 Jahren
Ursprung
Commit
82cc58e624

+ 10 - 0
src/main/java/com/persagy/proxy/common/client/DmpRwdClient.java

@@ -204,4 +204,14 @@ public interface DmpRwdClient {
     @PostMapping(DmpUrlConstant.DEF_FUNCID_COLLECT_SET)
     DmpResult batchUpdateObjectInfoCollect(@SpringQueryMap InstanceUrlParam objectUrlParam, @RequestBody JSONArray objectArr);
 
+
+    /**
+     * 查询对象下已有的类型
+     * @param objectUrlParam
+     * @param criteria
+     * @return
+     */
+    @PostMapping(DmpUrlConstant.QUERY_OBJECT_CLASS_CODE)
+    DmpResult<List<String>> queryObjectClassCode(@SpringQueryMap InstanceUrlParam objectUrlParam, @RequestBody JSONObject criteria);
+
 }

+ 5 - 0
src/main/java/com/persagy/proxy/common/constant/DmpUrlConstant.java

@@ -159,4 +159,9 @@ public class DmpUrlConstant {
     public final static String DEF_FUNCID_COLLECT_SET = "/rwd/def/funcid/collect/updateBatch";
 
 
+    /**
+     * 查询对象下已有的类型
+     */
+    public static final String QUERY_OBJECT_CLASS_CODE = "/rwd/instance/object/queryObjectClassCode";
+
 }

+ 2 - 5
src/main/java/com/persagy/proxy/dictionary/controller/AdmDictController.java

@@ -155,11 +155,8 @@ public class AdmDictController {
      */
     @PostMapping("/system/equip/category")
     @Deprecated
-    public AdmResponse querySystemEquipCategory(@RequestBody AdmDict request) throws Exception {
-        // 组装上下文条件
-        InstanceUrlParam context = AdmContextUtil.toDmpContext();
-        request.setType(AdmDictCategoryEnum.SYSTEM_EQUIP.getValue());
-        return service.queryCategory(context,request,AdmObjectType.class);
+    public AdmResponse querySystemEquipTree(@RequestBody AdmDictQueryCriteria request) throws Exception {
+        return service.querySystemEquipTree(AdmContextUtil.toDmpContext(),request,AdmObjectType.class);
     }
 
     /**

+ 8 - 1
src/main/java/com/persagy/proxy/dictionary/service/IAdmDictBaseService.java

@@ -80,5 +80,12 @@ public interface IAdmDictBaseService<T>{
      */
     List<T> doSetObjectInfoCollect(InstanceUrlParam context, Class<T> clazz, List<T> voList);
 
-
+    /**
+     * 查询对象类型
+     * @param context
+     * @param request
+     * @param clazz
+     * @return
+     */
+    AdmResponse queryObjectClassCode(InstanceUrlParam context, AdmQueryCriteria request, Class<T> clazz);
 }

+ 12 - 0
src/main/java/com/persagy/proxy/dictionary/service/IAdmDictService.java

@@ -75,4 +75,16 @@ public interface IAdmDictService<T> extends IAdmDictBaseService<T>{
      * @return
      */
     AdmResponse queryDictDeliveredInfos(InstanceUrlParam context, AdmDictDeliverieInfosRequest request, Class<T> clazz);
+
+
+    /**
+     * 查询项目下已有的系统设备类型树
+     * @param context
+     * @param request
+     * @return
+     * @throws Exception
+     */
+    AdmResponse querySystemEquipTree(InstanceUrlParam context , AdmDictQueryCriteria request, Class<T> clazz) throws Exception;
+
+
 }

+ 27 - 0
src/main/java/com/persagy/proxy/dictionary/service/impl/AbstractAdmDictBaseServiceImpl.java

@@ -388,4 +388,31 @@ public class AbstractAdmDictBaseServiceImpl<T> implements IAdmDictBaseService<T>
         return AdmEntityTransferUtil.toAdmMultiEntity(response.getData(), null, clazz);
     }
 
+    /**
+     * 查询对象类型
+     * @param request
+     * @return
+     */
+    @Override
+    public AdmResponse queryObjectClassCode(InstanceUrlParam context, AdmQueryCriteria request, Class<T> clazz) {
+        // 转换为数据中台查询条件
+        QueryCriteria dmpRequest = AdmQueryCriteriaHelper.toDmpCriteria(request);
+        // 转换参数
+        JSONObject para = null;
+        try {
+            para = JsonHelper.toJsonObject(dmpRequest);
+        } catch (IOException e) {
+            log.error(e.getMessage(), e);
+            return AdmResponse.failure("参数格式有误");
+        }
+        log.info("request:{},dmpRequest:{}, dmp-param: {}", request.toString(), dmpRequest.toString(), para.toString());
+        // 调用中台查询
+        DmpResult<List<String>> dmpResult = rwdClient.queryObjectClassCode(context, para);
+        // 设置返回值
+        AdmResponse response = AdmResponse.success(dmpResult.getData());
+        Long total = dmpResult.getCount() == null ? null : dmpResult.getCount().longValue();
+        response.setTotal(total);
+        return response;
+    }
+
 }

+ 56 - 0
src/main/java/com/persagy/proxy/dictionary/service/impl/AdmDictServiceImpl.java

@@ -55,6 +55,7 @@ public class AdmDictServiceImpl<T> extends AbstractAdmDictBaseServiceImpl<T> imp
     @Autowired
     private IAdmShaftService shaftService;
 
+
     /**
      * 字典类型查询:所有设备类型、部件类型、系统类型、专业类型
      * 查询类型:输入设备类型:equipment,输入部件类型:component,输入系统类型:system,输入专业类型:major,业务空间类型 space ,资产 property,
@@ -745,6 +746,61 @@ public class AdmDictServiceImpl<T> extends AbstractAdmDictBaseServiceImpl<T> imp
         return AdmResponse.success(deliveredInfos);
     }
 
+    /**
+     * 查询项目下已有的系统设备类型树
+     * @param context
+     * @param request
+     * @param clazz
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public AdmResponse querySystemEquipTree(InstanceUrlParam context, AdmDictQueryCriteria request, Class<T> clazz) throws Exception {
+        //查询项目下已有的设备类型
+        request.setName("equipment");
+        AdmResponse dictResponse = queryObjectClassCode(context, request, clazz);
+        List<String> classCodes = (List<String>)dictResponse.getContent();
+        if(CollUtil.isEmpty(classCodes)){
+            return AdmResponse.success(new ArrayList<>());
+        }
+        Map<String, List<String>> classCodeMap = classCodes.stream().collect(Collectors.groupingBy(item->item.substring(0,4),Collectors.toList()));
+        //查询所有的对象类型
+        AdmResponse allDictResponse = doQueryObjectType(context, new QueryCriteria(), clazz);
+        List<AdmObjectType> objectTypes = (List<AdmObjectType>) allDictResponse.getContent();
+        Map<String, AdmObjectType> allObjTypeMap = objectTypes.stream().collect(Collectors.toMap(AdmObjectType::getCode, admObjectType -> admObjectType, (k1, k2) -> k1));
+        if(CollUtil.isEmpty(allObjTypeMap)){
+            return AdmResponse.success(new ArrayList<>());
+        }
+        //结果集封装
+        List<AdmObjectType> admObjectTypeList = new ArrayList<>();
+        for (Map.Entry<String, List<String>> map : classCodeMap.entrySet()) {
+            String systemCode = map.getKey();
+            List<String> classCodeList = map.getValue();
+            if(CollUtil.isEmpty(classCodeList)){
+                continue;
+            }
+            //设置系统类型
+            AdmObjectType systemType = allObjTypeMap.get(systemCode);
+            if(systemType == null){
+                continue;
+            }
+            //设置系统子级:设备类型
+            List<AdmObjectType> children = new ArrayList<>();
+            for (String classCode: classCodeList) {
+                AdmObjectType admObjectType = allObjTypeMap.get(classCode);
+                if(admObjectType!=null){
+                    children.add(admObjectType);
+                }
+            }
+            if(CollUtil.isEmpty(children)){
+                continue;
+            }
+            systemType.setChildren(children);
+            admObjectTypeList.add(systemType);
+        }
+        return AdmResponse.success(admObjectTypeList);
+    }
+
 
     /**
      * 组装通用对象查询条件