Browse Source

设备相关接口
1.资产相关的部分已经写好,暂时不使用,导出导入部分没有源代码,之后需要支持再增加
2.设备增加时,名词需要验证,新增调中台查询definetype接口

lvxianyun 3 years ago
parent
commit
52dced783a

+ 5 - 4
src/main/java/com/persagy/proxy/adm/controller/AdmEquipmentController.java

@@ -1,7 +1,7 @@
 package com.persagy.proxy.adm.controller;
 
 import cn.hutool.core.collection.CollUtil;
-import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import cn.hutool.core.util.StrUtil;
 import com.persagy.proxy.adm.constant.AdmCommonConstant;
 import com.persagy.proxy.adm.model.AdmEquipment;
 import com.persagy.proxy.adm.request.AdmCreateRequest;
@@ -58,7 +58,7 @@ public class AdmEquipmentController {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
         List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
-        vos = service.doInsert(context, AdmEquipment.class, vos);
+        vos = service.doInsertEuip(context, AdmEquipment.class, vos);
         return AdmResponse.success(vos);
     }
 
@@ -88,6 +88,7 @@ public class AdmEquipmentController {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
         List<AdmEquipment> vos = CollUtil.newArrayList(createRequest.getContent());
+        //vos = service.doUpdateEuip(context, AdmEquipment.class, vos);
         vos = service.doUpdate(context, AdmEquipment.class, vos);
         return AdmResponse.success(vos);
     }
@@ -152,7 +153,7 @@ public class AdmEquipmentController {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
         //request.setName("equipment");
-        if(StringUtils.isNotEmpty(request.getFilters())){
+        if(StrUtil.isNotEmpty(request.getFilters())){
             request.setFilters(String.join(";",request.getFilters(),"objType in ['equipment','component']"));
         }else{
             request.setFilters("objType in ['equipment','component']");
@@ -171,7 +172,7 @@ public class AdmEquipmentController {
         // 组装上下文条件
         InstanceUrlParam context = new InstanceUrlParam(groupCode, null, projectId, AdmCommonConstant.APP_ID);
         List<AdmEquipment> vos = CollUtil.newArrayList(admEquipment.getContent());
-        vos = service.doInsert(context, AdmEquipment.class, vos);
+        vos = service.doInsertExt(context, AdmEquipment.class, vos);
         return AdmResponse.success(vos);
     }
 

+ 27 - 5
src/main/java/com/persagy/proxy/adm/model/AdmEquipment.java

@@ -50,6 +50,27 @@ public class AdmEquipment {
     /** 设备关联的资产id */
     private String propertyId;
 
+    /** 参见 EquipmentProSy **/
+    /** 品牌型号id */
+    private String dpManufacturerId;
+
+    /** 供应商信息id */
+    private String dpSupplierId;
+
+    /** 维修商信息id */
+    private String dpMaintainerId;
+
+    /** 保险公司信息id */
+    private String dpInsurerId;
+
+    /** 设备型号id */
+    private String dpSpecificationId;
+
+    /** 品牌id */
+    private String dpBrandId;
+    
+    
+
     /** Revit族 */
     private String bimFamilyName;
     /** Revit族类型 */
@@ -95,8 +116,9 @@ public class AdmEquipment {
     private Map<String, Object> infos;
     /** 统计信息 */
     private Map<String, Object> statistics;
-    /** 资产信息实体类 */
-    @CascadeColumn
+
+    /** 资产信息实体类   资产对应设备设施关系 资产→设备设施*/
+    @CascadeColumn(graphCode = "Property2Mech", relCode = "Pe2Eq", selectToObj = false)
     private AdmProperty property;
     /** 建筑信息实体类 */
     @CascadeColumn(graphCode = "MechForArch", relCode = "Eq2Bd")
@@ -119,10 +141,10 @@ public class AdmEquipment {
     @CascadeColumn(graphCode = "MechInArch", relCode = "Eq2Sh")
     private List<AdmShaft> shaftList;
     /** 资产列表 */
-    @CascadeColumn
+    @CascadeColumn(graphCode = "Property2Mech", relCode = "Pe2Eq", selectToObj = false)
     private List<AdmProperty> propertyList;
     /** 级联-部件 */
-    @CascadeColumn
-    private List<AdmEquipment> component;
+    @CascadeColumn(graphCode = "MechSubset", relCode = "Eq2Ec")
+    private List<AdmComponent> component;
 
 }

+ 33 - 0
src/main/java/com/persagy/proxy/adm/service/IAdmEquipmentService.java

@@ -1,6 +1,9 @@
 package com.persagy.proxy.adm.service;
 
 import com.persagy.proxy.adm.model.AdmEquipment;
+import com.persagy.proxy.common.entity.InstanceUrlParam;
+
+import java.util.List;
 
 /**
  * ADM 设备接口
@@ -8,4 +11,34 @@ import com.persagy.proxy.adm.model.AdmEquipment;
  * @date 2021/8/18
  */
 public interface IAdmEquipmentService extends IAdmBaseService<AdmEquipment>{
+
+    /**
+     * 新增
+     * @param context
+     * @param clazz
+     * @param voList
+     * @return
+     */
+    List<AdmEquipment> doInsertEuip(InstanceUrlParam context, Class<AdmEquipment> clazz, List<AdmEquipment> voList);
+
+    /**
+     * 修改 资产现在前端隐藏
+     * @param context
+     * @param clazz
+     * @param voList
+     * @return
+     */
+    @Deprecated
+    List<AdmEquipment> doUpdateEuip(InstanceUrlParam context, Class<AdmEquipment> clazz, List<AdmEquipment> voList);
+
+    /**
+     * 删除 资产现在前端隐藏
+     * @param context
+     * @param voList
+     * @return
+     */
+    @Deprecated
+    void doDeleteEuip(InstanceUrlParam context, List<AdmEquipment> voList);
+    @Deprecated
+    public List<AdmEquipment> doInsertExt(InstanceUrlParam context, Class<AdmEquipment> clazz, List<AdmEquipment> voList);
 }

+ 288 - 0
src/main/java/com/persagy/proxy/adm/service/impl/AdmEquipmentServiceImpl.java

@@ -1,14 +1,302 @@
 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;
+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.common.model.entity.BaseEntity;
+import com.persagy.dmp.define.entity.ObjectTypeDefine;
+import com.persagy.dmp.digital.client.DigitalRelationFacade;
+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.IAdmEquipmentService;
+import com.persagy.proxy.adm.utils.AdmEntityTransferUtil;
+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 com.persagy.proxy.common.entity.ObjRelationDTO;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.*;
+import java.util.stream.Collectors;
+
 /**
  * ADM 设备 实现
  * @author lvxy
  * @date 2021/8/18
  */
+@Slf4j
 @Service
 public class AdmEquipmentServiceImpl extends AbstractAdmBaseServiceImpl<AdmEquipment> implements IAdmEquipmentService {
+
+    @Autowired
+    private DmpRwdClient rwdClient;
+    @Autowired
+    private ObjectMapper objectMapper;
+
+    @Override
+    public List<AdmEquipment> doInsertEuip(InstanceUrlParam context, Class<AdmEquipment> clazz, List<AdmEquipment> voList) {
+        if(CollUtil.isEmpty(voList)) {
+            return null;
+        }
+        Set<String> classCodes = voList.stream().map(AdmEquipment::getClassCode).collect(Collectors.toSet());
+        //查询定义类型
+        Map<String, ObjectTypeDefine> finalDefClassMap = queryDefineType(context, classCodes);
+        // 设备名字处理
+        voList.forEach(equip -> {
+            if (StrUtil.isNotEmpty(equip.getName())) {
+                if(CollUtil.isNotEmpty(finalDefClassMap) && finalDefClassMap.containsKey(equip.getClassCode())){
+                    ObjectTypeDefine defclass = finalDefClassMap.get(equip.getClassCode());
+                    equip.setName(ObjectNameUtil.objectName(defclass.getName()+"-"));
+                }else{
+                    equip.setName(ObjectNameUtil.objectName("设备-"));
+                }
+            }
+        });
+        return doInsert(context, clazz, voList);
+    }
+
+    @Override
+    public List<AdmEquipment> doUpdateEuip(InstanceUrlParam context, Class<AdmEquipment> clazz, List<AdmEquipment> voList) {
+        //TODO 处理关系标记
+        /*try {
+         *//** 处理关系标记 *//*
+            val listtype = ArrayList<String>()
+            listtype.add("pe2bd")
+            listtype.add("pe2fl")
+            listtype.add("pe2sh")
+            listtype.add("pe2sp")
+            for (type in listtype){
+                val entity = relationTypeProjectservice.select(SFilter.eq("projectId", Opt.projectId!!), SFilter.eq("relationType", type)).entity()
+                if (entity!=null){
+                    entity.computationalState = 2
+                    relationTypeProjectservice.update(entity)
+                }
+            }
+        } catch (e: Exception) {
+            e.printStackTrace()
+        }*/
+        Map<String, AdmEquipment> voMap = CollUtil.fieldValueMap(voList, BaseEntity.PROP_ID);
+        //查询设备对应的资产 关系 Pe2Eq (1:N,一个资产关联多个设备,设备是最小单位 by:lvxianyun)
+        DmpResult<List<ObjRelationDTO>> relationRes = queryRelation(context, voMap);
+        boolean isDealDataSucc = false;
+        //不是绑定关系,清理绑定关系,重新绑定
+        if(CollUtil.isNotEmpty(relationRes.getData())){
+            isDealDataSucc = updateRelation2Pe(context, relationRes, voMap);
+        }else {
+            //不存在关系,需要新绑定关系,更新per,插入关系
+            isDealDataSucc = insertRelation2Pe(context, voList, voMap);
+        }
+        return isDealDataSucc ? doUpdate(context, clazz, voList) : null;
+    }
+
+    @Override
+    public void doDeleteEuip(InstanceUrlParam context, List<AdmEquipment> voList) {
+        Map<String, AdmEquipment> voMap = CollUtil.fieldValueMap(voList, BaseEntity.PROP_ID);
+        DmpResult<List<ObjRelationDTO>> relationRes = queryRelation(context, voMap);
+        //清理绑定关系
+        if(CollUtil.isNotEmpty(relationRes.getData())){
+            updateRelation2Pe(context, relationRes, voMap);
+        }
+        doDelete(context,voList);
+    }
+
+    @Override
+    public List<AdmEquipment> doInsertExt(InstanceUrlParam context, Class<AdmEquipment> clazz, List<AdmEquipment> voList) {
+
+        //创建设备
+        List<AdmEquipment> vos = doInsert(context, AdmEquipment.class, voList);
+        //创建资产
+        //创建设备和系统关系 systemList
+        return null;
+    }
+
+
+    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();
+        ObjectNode criteria = JsonNodeFactory.instance.objectNode();
+        ArrayNode array = criteria.putObject("objTo").putArray("$in");
+        voMap.keySet().forEach(equipId -> array.add(equipId));
+        criteria.put("relCode", "Pe2Eq");
+        criteria.put("graphCode", "Property2Mech");
+        dmpRequest.setCriteria(criteria);
+        dmpRequest.setSize(voMap.size() * 1L);
+        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 null;
+        }
+        return rwdClient.queryRelation(context, dmpRequest);
+    }
+
+    private DmpResult<JSONArray> queryObject(InstanceUrlParam context, Map<String, AdmEquipment> peMap){
+        QueryCriteria criteriaObject = new QueryCriteria();
+        ObjectNode criteriaPe = JsonNodeFactory.instance.objectNode();
+        ArrayNode array = criteriaPe.putObject("id").putArray("$in");
+        peMap.keySet().forEach(equipId -> array.add(equipId));
+        criteriaPe.put("classCode", "property");
+        criteriaPe.put("objType", "property");
+        criteriaObject.setCriteria(criteriaPe);
+        criteriaObject.setSize(peMap.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);
+    }
+
+    private AdmProperty createPropertyObj(String id, String equipId, Boolean isBimIdNull){
+        AdmProperty admProperty = new AdmProperty();
+        admProperty.setId(id);
+        admProperty.setEquipId(equipId);
+        if(isBimIdNull){
+            admProperty.setBimId(null);
+        }
+        return admProperty;
+    }
+
+    private ObjectNode creatRelationObj(String objTo,String objFrom){
+        ObjectNode relationNew = JsonNodeFactory.instance.objectNode();
+        relationNew.put("relCode", "Pe2Eq");
+        relationNew.put("graphCode", "Property2Mech");
+        relationNew.put("graphCode", "Property2Mech001");
+        relationNew.put("objTo", objTo);
+        relationNew.put("objFrom", objFrom);
+        return relationNew;
+    }
+
+
+    /**
+     * 更新设备关联的资产(资产中的equipId 信息点) 以及设备资产关系
+     * @return
+     */
+    private Boolean updateRelation2Pe(InstanceUrlParam context, DmpResult<List<ObjRelationDTO>> relationRes, Map<String, AdmEquipment> voMap){
+        boolean isDealDataSucc = false;
+        List<AdmProperty> updatePropertyList = new ArrayList<AdmProperty>();
+        List<String> del_relationIds = new ArrayList<>(relationRes.getData().size());
+        Map<String, ObjRelationDTO> relationMap = CollUtil.fieldValueMap(relationRes.getData(), "objTo");
+        relationMap.keySet().forEach(euipId -> {
+            //存在绑定的资产
+            if(voMap.keySet().contains(euipId)){
+                AdmEquipment admEquipment = voMap.get(euipId);
+                ObjRelationDTO relation = relationMap.get(euipId);
+                String propertyId = relation.getObjFrom();
+                if(StrUtil.isNotEmpty(admEquipment.getPropertyId()) && StrUtil.isNotEmpty(propertyId)
+                        && !admEquipment.getPropertyId().equals(propertyId)){
+                    //1 与设备提供的资产绑定
+                    AdmProperty propertyFrom = createPropertyObj(admEquipment.getPropertyId(), euipId, false);
+                    propertyFrom.setId(admEquipment.getPropertyId());
+                    propertyFrom.setEquipId(euipId);
+                    updatePropertyList.add(propertyFrom);
+
+                    //2 从关系中查询出的资产与当前设备解绑
+                    //更新资产中的信息点
+                    AdmProperty property = createPropertyObj(propertyId, null, true);
+                    updatePropertyList.add(property);
+
+                    //更新关系
+                    del_relationIds.add(relation.getId());
+                }
+            }
+        });
+        DigitalRelationFacade.delete(context.getGroupCode(),context.getProjectId(), AdmCommonConstant.APP_ID,null,del_relationIds);
+        DmpResult propertyResult = rwdClient.updateObject(context, JSONArray.parseArray(updatePropertyList.toString()));
+        if(propertyResult.getResult().equals(DmpResult.SUCCESS)){
+            isDealDataSucc = true;
+        }
+        return isDealDataSucc;
+    }
+
+
+    /**
+     * 不存在关系,需要新绑定关系,更新per,插入关系
+     * @param context
+     * @param voList
+     * @param voMap
+     * @return
+     */
+    private Boolean insertRelation2Pe(InstanceUrlParam context, List<AdmEquipment> voList, Map<String, AdmEquipment> voMap){
+        boolean isDealDataSucc = false;
+        Map<String, AdmEquipment> peMap = CollUtil.fieldValueMap(voList, "propertyId");
+        //查询资产
+        DmpResult<JSONArray> resultPe = queryObject(context, peMap);
+        if (CollUtil.isNotEmpty(resultPe.getData())) {
+            //更新资产 创建资产设备关系
+            List<AdmProperty> propertyList = AdmEntityTransferUtil.toAdmMultiEntity(resultPe.getData(), null, AdmProperty.class);
+            List<ObjectNode> objRelationDTONews = new ArrayList<>();
+            propertyList.forEach(property -> {
+                //存在绑定的资产 更新
+                AdmEquipment admEquipment = peMap.get(property.getId());
+                property.setEquipId(admEquipment.getId());
+                //创建新的设备资产关系
+                ObjectNode relationNew = creatRelationObj( admEquipment.getId(), property.getId());
+                objRelationDTONews.add(relationNew);
+            });
+
+            List<ObjectRelation> relationList = DigitalRelationFacade.create(context.getGroupCode(),context.getProjectId(), AdmCommonConstant.APP_ID,null,objRelationDTONews);
+            if(CollUtil.isNotEmpty(relationList)){
+                DmpResult<JSONArray> propertyRes = rwdClient.updateObject(context, JSONArray.parseArray(propertyList.toString()));
+                if(propertyRes.getResult().equals(DmpResult.SUCCESS)){
+                    isDealDataSucc = true;
+                }
+            }
+        }
+        return isDealDataSucc;
+    }
 }

+ 39 - 0
src/main/java/com/persagy/proxy/adm/utils/ObjectNameUtil.java

@@ -0,0 +1,39 @@
+package com.persagy.proxy.adm.utils;
+
+import cn.hutool.core.util.RandomUtil;
+
+/**
+ * 根据中心数据规则生成对象名字
+ * 参见 datacenterShaftNameUtil
+ * @author lvxy
+ * @date 2021/8/31
+ */
+public class ObjectNameUtil {
+
+    /**
+     * 竖井名字
+     *
+     * @param   name    名字
+     */
+    public static String objectName(String name){
+        return name + getCode(5);
+    } // Function shaftName()
+
+    /**
+     * 字母和数字组合的随机数
+     *
+     * @param   n   随机数的位数
+     */
+    private static String getCode(int n) {
+        String str = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ";//保存数字0-9 和 大小写字母
+        char[] ch = new char[n]; //声明一个字符数组对象ch 保存 验证码
+        for (int i=0 ; i< n; i++) {
+            //创建一个新的随机数生成器
+            int index = RandomUtil.getRandom().nextInt(str.length());//返回[0,string.length)范围的int值    作用:保存下标
+            ch[i] = str.charAt(index);//charAt() : 返回指定索引处的 char 值   ==》保存到字符数组对象ch里面
+        }
+        //将char数组类型转换为String类型保存到result
+        return  String.valueOf(ch);
+    }
+
+}

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

@@ -40,6 +40,14 @@ public interface DmpRwdClient {
      */
     @PostMapping(DmpUrlConstant.OBJECT_QUERY)
     DmpResult<JSONArray> queryObject(@SpringQueryMap InstanceUrlParam objectUrlParam, @RequestBody JSONObject criteria);
+    /**
+     * @description: 查询定义类型
+     * @param: objectUrlParam 对象请求url通用参数
+     * @param: criteria post请求参数
+     * @return: com.persagy.dmp.common.DmpResult
+     */
+    @PostMapping(DmpUrlConstant.DEF_CLASS)
+    DmpResult<JSONArray> queryDefClass(@SpringQueryMap InstanceUrlParam objectUrlParam, @RequestBody JSONObject criteria);
 
     /**
      * @description: 创建对象