浏览代码

部件接口

lvxianyun 3 年之前
父节点
当前提交
e403e49f03

+ 12 - 14
src/main/java/com/persagy/proxy/adm/controller/AdmComponentController.java

@@ -1,14 +1,12 @@
 package com.persagy.proxy.adm.controller;
 
 import cn.hutool.core.collection.CollUtil;
-import com.alibaba.fastjson.JSONArray;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
-import com.persagy.proxy.adm.model.AdmEquipment;
+import com.persagy.proxy.adm.model.AdmComponent;
 import com.persagy.proxy.adm.request.AdmCreateRequest;
 import com.persagy.proxy.adm.request.AdmQueryCriteria;
 import com.persagy.proxy.adm.request.AdmResponse;
-import com.persagy.proxy.adm.service.IAdmEquipmentService;
-import com.persagy.proxy.common.entity.DmpResult;
+import com.persagy.proxy.adm.service.IAdmComponentService;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -30,7 +28,7 @@ import java.util.List;
 @RequestMapping("/object/component")
 public class AdmComponentController {
     @Autowired
-    private IAdmEquipmentService service;
+    private IAdmComponentService service;
     @Value("${middleware.group.code}")
     private String groupCode;
 
@@ -48,7 +46,7 @@ public class AdmComponentController {
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
         request.setName("component");
         request.setOnlyCount(true);
-        return service.doQuery(context, request, AdmEquipment.class);
+        return service.doQuery(context, request, AdmComponent.class);
     }
     /**
      * 创建
@@ -57,11 +55,11 @@ public class AdmComponentController {
      * @throws Exception
      */
     @PostMapping("/create")
-    public AdmResponse create(@RequestBody AdmCreateRequest<AdmEquipment> createRequest, @QueryParam("projectId") String projectId) throws Exception {
+    public AdmResponse create(@RequestBody AdmCreateRequest<AdmComponent> createRequest, @QueryParam("projectId") String projectId) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
-        vos = service.doInsert(context, AdmEquipment.class, vos);
+        List<AdmComponent> vos = CollUtil.newArrayList(createRequest.getContent());
+        vos = service.doInsertExt(context, AdmComponent.class, vos);
         return AdmResponse.success(vos);
     }
 
@@ -72,7 +70,7 @@ public class AdmComponentController {
      * @throws Exception
      */
     @PostMapping("/delete")
-    public AdmResponse delete(@QueryParam("projectId") String projectId, @RequestBody List<AdmEquipment> vos) throws Exception {
+    public AdmResponse delete(@QueryParam("projectId") String projectId, @RequestBody List<AdmComponent> vos) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
         service.doDelete(context, vos);
@@ -86,11 +84,11 @@ public class AdmComponentController {
      * @throws Exception
      */
     @PostMapping("/update")
-    public AdmResponse update(@RequestBody AdmCreateRequest<AdmEquipment> createRequest, @QueryParam("projectId") String projectId) throws Exception {
+    public AdmResponse update(@RequestBody AdmCreateRequest<AdmComponent> createRequest, @QueryParam("projectId") String projectId) throws Exception {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
-        List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
-        vos = service.doUpdate(context, AdmEquipment.class, vos);
+        List<AdmComponent> vos = CollUtil.newArrayList(createRequest.getContent());
+        vos = service.doUpdate(context, AdmComponent.class, vos);
         return AdmResponse.success(vos);
     }
 
@@ -107,6 +105,6 @@ public class AdmComponentController {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
         request.setName("component");
-        return service.doQuery(context, request, AdmEquipment.class);
+        return service.doQuery(context, request, AdmComponent.class);
     }
 }

+ 1 - 1
src/main/java/com/persagy/proxy/adm/model/AdmComponent.java

@@ -88,7 +88,7 @@ public class AdmComponent {
         /** 最后更新日期 */
         private Date lastUpdate;
         /** 对象类型 */
-        private String objectType = "equipment";
+        private String objectType = "component";
 
         /** 信息点 */
         private Map<String, Object> infos;

+ 49 - 0
src/main/java/com/persagy/proxy/adm/service/IAdmComAndEquipService.java

@@ -0,0 +1,49 @@
+package com.persagy.proxy.adm.service;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSONArray;
+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.define.entity.ObjectTypeDefine;
+import com.persagy.proxy.common.entity.DmpResult;
+import com.persagy.proxy.common.entity.InstanceUrlParam;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author lvxy
+ * @date 2021/9/2
+ */
+
+public interface IAdmComAndEquipService {
+    default QueryCriteria getDmpCriteria(InstanceUrlParam context, Set<String> classCodes, String objType){
+        QueryCriteria criteriaObject = new QueryCriteria();
+        ObjectNode criteriaEq = JsonNodeFactory.instance.objectNode();
+
+        ArrayNode array = criteriaEq.putObject("code").putArray("$in");
+        classCodes.forEach(code -> array.add(code));
+
+        criteriaEq.put("objType", objType);
+        criteriaObject.setCriteria(criteriaEq);
+        criteriaObject.setSize(classCodes.size() * 1L);
+        criteriaObject.setPage(1L);
+        criteriaObject.setWithoutCount(true);
+        return criteriaObject;
+    }
+
+    default Map<String, ObjectTypeDefine> getDefineMap(DmpResult<JSONArray> resultDef){
+        Map<String, ObjectTypeDefine> defClassMap = new HashMap<String, ObjectTypeDefine>();
+        if(resultDef.getResult().equals(DmpResult.SUCCESS)){
+            JSONArray defArr = resultDef.getData();
+            List<ObjectTypeDefine> defineList = JSONUtil.toList(defArr.toString(), ObjectTypeDefine.class);
+            defClassMap = CollUtil.fieldValueMap(defineList, "code");
+        }
+        return defClassMap;
+    }
+}

+ 11 - 0
src/main/java/com/persagy/proxy/adm/service/IAdmComponentService.java

@@ -1,6 +1,9 @@
 package com.persagy.proxy.adm.service;
 
 import com.persagy.proxy.adm.model.AdmComponent;
+import com.persagy.proxy.common.entity.InstanceUrlParam;
+
+import java.util.List;
 
 /**
  * ADM 组件 接口
@@ -8,4 +11,12 @@ import com.persagy.proxy.adm.model.AdmComponent;
  * @date 2021/8/19
  */
 public interface IAdmComponentService extends IAdmBaseService<AdmComponent>{
+    /**
+     * 新增
+     * @param context
+     * @param clazz
+     * @param voList
+     * @return
+     */
+    List<AdmComponent> doInsertExt(InstanceUrlParam context, Class<AdmComponent> clazz, List<AdmComponent> voList);
 }

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

@@ -1,14 +1,68 @@
 package com.persagy.proxy.adm.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.persagy.dmp.basic.model.QueryCriteria;
+import com.persagy.dmp.define.entity.ObjectTypeDefine;
 import com.persagy.proxy.adm.model.AdmComponent;
+import com.persagy.proxy.adm.service.IAdmComAndEquipService;
 import com.persagy.proxy.adm.service.IAdmComponentService;
+import com.persagy.proxy.adm.utils.ObjectNameUtil;
+import com.persagy.proxy.common.client.DmpRwdClient;
+import com.persagy.proxy.common.entity.DmpResult;
+import com.persagy.proxy.common.entity.InstanceUrlParam;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
 /**
  * ADM 组件 服务
  * @author lvxy
  * @date 2021/8/19
  */
 @Service
-public class AdmComponentServiceImpl extends AbstractAdmBaseServiceImpl<AdmComponent> implements IAdmComponentService {
+public class AdmComponentServiceImpl extends AbstractAdmBaseServiceImpl<AdmComponent> implements IAdmComponentService, IAdmComAndEquipService {
+
+    @Autowired
+    private DmpRwdClient rwdClient;
+    @Autowired
+    private ObjectMapper objectMapper;
+
+    @Override
+    public List<AdmComponent> doInsertExt(InstanceUrlParam context, Class<AdmComponent> clazz, List<AdmComponent> voList) {
+        if(CollUtil.isEmpty(voList)) {
+            return null;
+        }
+        Set<String> classCodes = voList.stream().map(AdmComponent::getClassCode).collect(Collectors.toSet());
+        //查询定义类型
+        QueryCriteria criteriaObject = getDmpCriteria(context, classCodes, "component");
+        JSONObject paraPe = null;
+        try {
+            String paraStr = objectMapper.writeValueAsString(criteriaObject);
+            paraPe = JSONObject.parseObject(paraStr);
+        } catch (JsonProcessingException e) {
+            throw new RuntimeException("转换查询条件出错:" + e.getMessage());
+        }
+        DmpResult<JSONArray> resultDef = rwdClient.queryDefClass(context, paraPe);
+        Map<String, ObjectTypeDefine> finalDefClassMap = getDefineMap(resultDef);
+        // 设备名字处理
+        voList.forEach(component -> {
+            if (StrUtil.isNotEmpty(component.getName()) && CollUtil.isNotEmpty(finalDefClassMap) && finalDefClassMap.containsKey(component.getClassCode())) {
+                ObjectTypeDefine defclass = finalDefClassMap.get(component.getClassCode());
+                component.setName(ObjectNameUtil.objectName(defclass.getName()+"-"));
+            }else{
+                component.setName(ObjectNameUtil.objectName("部件-"));
+            }
+        });
+        return doInsert(context, clazz, voList);
+    }
+
 }

+ 16 - 33
src/main/java/com/persagy/proxy/adm/service/impl/AdmEquipmentServiceImpl.java

@@ -2,7 +2,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.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -18,6 +17,7 @@ import com.persagy.dmp.digital.entity.ObjectRelation;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
 import com.persagy.proxy.adm.model.AdmEquipment;
 import com.persagy.proxy.adm.model.AdmProperty;
+import com.persagy.proxy.adm.service.IAdmComAndEquipService;
 import com.persagy.proxy.adm.service.IAdmEquipmentService;
 import com.persagy.proxy.adm.utils.AdmEntityTransferUtil;
 import com.persagy.proxy.adm.utils.ObjectNameUtil;
@@ -29,7 +29,10 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 /**
@@ -39,7 +42,7 @@ import java.util.stream.Collectors;
  */
 @Slf4j
 @Service
-public class AdmEquipmentServiceImpl extends AbstractAdmBaseServiceImpl<AdmEquipment> implements IAdmEquipmentService {
+public class AdmEquipmentServiceImpl extends AbstractAdmBaseServiceImpl<AdmEquipment> implements IAdmEquipmentService, IAdmComAndEquipService {
 
     @Autowired
     private DmpRwdClient rwdClient;
@@ -53,7 +56,16 @@ public class AdmEquipmentServiceImpl extends AbstractAdmBaseServiceImpl<AdmEquip
         }
         Set<String> classCodes = voList.stream().map(AdmEquipment::getClassCode).collect(Collectors.toSet());
         //查询定义类型
-        Map<String, ObjectTypeDefine> finalDefClassMap = queryDefineType(context, classCodes);
+        QueryCriteria criteriaObject = getDmpCriteria(context, classCodes, "equipment");
+        JSONObject paraPe = null;
+        try {
+            String paraStr = objectMapper.writeValueAsString(criteriaObject);
+            paraPe = JSONObject.parseObject(paraStr);
+        } catch (JsonProcessingException e) {
+            throw new RuntimeException("转换查询条件出错:" + e.getMessage());
+        }
+        DmpResult<JSONArray> resultDef = rwdClient.queryDefClass(context, paraPe);
+        Map<String, ObjectTypeDefine> finalDefClassMap = getDefineMap(resultDef);
         // 设备名字处理
         voList.forEach(equip -> {
             if (StrUtil.isNotEmpty(equip.getName())) {
@@ -124,36 +136,7 @@ public class AdmEquipmentServiceImpl extends AbstractAdmBaseServiceImpl<AdmEquip
     }
 
 
-    private Map<String, ObjectTypeDefine> queryDefineType(InstanceUrlParam context, Set<String> classCodes){
-        QueryCriteria criteriaObject = new QueryCriteria();
-        ObjectNode criteriaEq = JsonNodeFactory.instance.objectNode();
-
-        ArrayNode array = criteriaEq.putObject("code").putArray("$in");
-        classCodes.forEach(code -> array.add(code));
 
-        criteriaEq.put("objType", "equipment");
-        criteriaObject.setCriteria(criteriaEq);
-        criteriaObject.setSize(classCodes.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;
-        }
-        DmpResult<JSONArray> resultDef = rwdClient.queryDefClass(context, paraPe);
-        Map<String, ObjectTypeDefine> defClassMap = new HashMap<String, ObjectTypeDefine>();
-        if(resultDef.getResult().equals(DmpResult.SUCCESS)){
-            JSONArray defArr = resultDef.getData();
-            List<ObjectTypeDefine> defineList = JSONUtil.toList(defArr.toString(), ObjectTypeDefine.class);
-            defClassMap = CollUtil.fieldValueMap(defineList, "code");
-        }
-        return defClassMap;
-    }
 
     private DmpResult<List<ObjRelationDTO>> queryRelation(InstanceUrlParam context, Map<String, AdmEquipment> voMap){
         QueryCriteria dmpRequest = new QueryCriteria();