Browse Source

fix bug:添加/rel/sy-in-eq/unlinks-sy-eq和/rel/sy-in-eq/batch/equip两个接口

lijie 3 years ago
parent
commit
24ddf65425

+ 1 - 1
src/main/java/com/persagy/proxy/adm/constant/AdmRelationTypeEnum.java

@@ -40,7 +40,7 @@ public enum AdmRelationTypeEnum {
     /**空调回风-空调回风相关设备,沿气流方向-*/
     EQ2EQ_ACAIRNETWORK_2("eq2eq_ACAirNetwork_2","ACAirNetwork","Return",AdmObjectType.EQUIPMENT.getIndex(),AdmObjectType.EQUIPMENT.getIndex(),false,true,false,false,false,false),
     /**系统下的设备-系统→设备-【系统台账】,【设备台账】*/
-    EQ2SY("eq2sy","SystemEquip","Sy2Eq",AdmObjectType.SYSTEM.getIndex(),AdmObjectType.EQUIPMENT.getIndex(),false,false,false,false,false,false),
+    EQ2SY("eq2sy","MechSubset","Sy2Eq",AdmObjectType.SYSTEM.getIndex(),AdmObjectType.EQUIPMENT.getIndex(),false,false,false,false,false,false),
     /**空调冷冻水补水-空调冷冻水补水相关设备,沿水流方向-*/
     EQ2EQ_CHILLWATERLOOP_4("eq2eq_ChillWaterLoop_4","ChillWaterLoop","Fill",AdmObjectType.EQUIPMENT.getIndex(),AdmObjectType.EQUIPMENT.getIndex(),false,true,false,false,false,false),
     /**设备服务于建筑-设备→建筑-【设备台账】*/

+ 175 - 5
src/main/java/com/persagy/proxy/relation/controller/RelationSyEqController.java

@@ -4,21 +4,42 @@ 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.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.netflix.discovery.CommonConstants;
 import com.persagy.dmp.basic.model.QueryCriteria;
+import com.persagy.dmp.basic.model.QueryOperator;
+import com.persagy.dmp.basic.utils.QueryCriteriaHelper;
+import com.persagy.dmp.common.constant.CommonConstant;
+import com.persagy.dmp.common.context.AppContext;
+import com.persagy.dmp.common.helper.SpringHelper;
+import com.persagy.dmp.common.model.response.CommonResult;
+import com.persagy.dmp.digital.client.DigitalObjectFacade;
+import com.persagy.dmp.digital.client.DigitalRelationFacade;
+import com.persagy.dmp.digital.entity.ObjectDigital;
+import com.persagy.dmp.digital.entity.ObjectRelation;
+import com.persagy.proxy.adm.constant.AdmDictCategoryEnum;
+import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
+import com.persagy.proxy.adm.request.AdmCreateResponse;
 import com.persagy.proxy.adm.request.AdmResponse;
 import com.persagy.proxy.adm.service.IAdmRelationService;
 import com.persagy.proxy.adm.utils.AdmContextUtil;
 import com.persagy.proxy.common.entity.InstanceUrlParam;
 import com.persagy.proxy.common.entity.RelationDTO;
+import com.persagy.proxy.object.model.AdmEquipment;
+import com.persagy.proxy.object.service.IAdmEquipmentService;
+import com.persagy.proxy.relation.model.AdmBatchSyEqRequest;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * @description:系统下的设备设施
@@ -31,6 +52,8 @@ public class RelationSyEqController {
 
     @Autowired
     private IAdmRelationService service;
+    @Autowired
+    private IAdmEquipmentService equipmentService;
     @Value("${middleware.group.code}")
     private String groupCode;
 
@@ -164,30 +187,177 @@ public class RelationSyEqController {
      * @param   entytyList           根据对象删除系统和设备的关系
      * @return                  创建结果信息
      */
+    @PostMapping("/unlinks-sy-eq")
     public AdmResponse deleteBatch(@RequestBody JSONArray entytyList) {
         if(CollUtil.isEmpty(entytyList)) {
             return AdmResponse.success();
         }
         // 组装上下文条件
         InstanceUrlParam context = AdmContextUtil.toDmpContext();
+        // 2021年11月25日14:53:16 优化:by lijie
+        Set<String> objFromIds = CollUtil.newHashSet();
+        Set<String> objToIds = CollUtil.newHashSet();
         for (int i = 0; i < entytyList.size(); i++) {
             JSONObject entity = entytyList.getJSONObject(i);
             // 组装条件
-            QueryCriteria criteria = new QueryCriteria();
             String equipId = entity.getString("equipId");
             String sysID = entity.getString("sysId");
             if(!StrUtil.isAllNotEmpty(equipId,sysID)) {
                 continue;
             }
+            objFromIds.add(sysID);
+            objToIds.add(equipId);
+        }
+        // 2.批量删除关系
+        if (CollUtil.isNotEmpty(objFromIds) && CollUtil.isNotEmpty(objToIds)){
+            QueryCriteria criteria = new QueryCriteria();
             ObjectNode node = JsonNodeFactory.instance.objectNode();
-            node.put("graphCode", "MechSubset");
-            node.put("relCode", "Sy2Eq");
-            node.put("objFrom", sysID);
-            node.put("objTo", equipId);
+            node.put(ObjectRelation.GRAPH_CODE_HUM, AdmRelationTypeEnum.EQ2SY.getGraphCode());
+            node.put(ObjectRelation.REL_CODE_HUM, AdmRelationTypeEnum.EQ2SY.getRelCode());
+            node.putPOJO(ObjectRelation.OBJ_FROM_HUM, objFromIds);
+            node.putPOJO(ObjectRelation.OBJ_TO_HUM, objToIds);
             criteria.setCriteria(node);
             service.doDelete(context, criteria);
         }
         return AdmResponse.success();
     }
+    /**
+     * 根据条件筛选 批量添加关系
+     * 建筑和楼层 未明确使用 isnull
+     * @param   admBatchSyEqRequest  批量添加系统和设备的关系
+     * @return                  创建结果信息
+     */
+    @PostMapping("/batch/equip")
+    public AdmResponse batchAddRels(@RequestBody AdmBatchSyEqRequest admBatchSyEqRequest) {
+        if (StrUtil.isBlank(admBatchSyEqRequest.getClassCode())){
+            return AdmCreateResponse.failure("设备类型不可以为空");
+        }
+        if (StrUtil.isBlank(admBatchSyEqRequest.getSysId())){
+            return AdmCreateResponse.failure("系统id不可以为空");
+        }
+        // 1.组装查询条件
+        QueryCriteria queryCriteria = new QueryCriteria();
+        ObjectMapper objectMapper = SpringHelper.getBean(ObjectMapper.class);
+        ObjectNode objectNode = objectMapper.createObjectNode();
+        handleBuildAndFloorQueryParam(objectMapper,objectNode,admBatchSyEqRequest.getBuildingId(),admBatchSyEqRequest.getFloorId());
+        objectNode.put(ObjectDigital.CLASS_CODE_HUM,admBatchSyEqRequest.getClassCode());
+        objectNode.put(CommonConstant.QUERY_PROJECTID, AppContext.getContext().getProjectId());
+        String name = admBatchSyEqRequest.getVague();
+        if (StrUtil.isNotBlank(name)){
+            ObjectNode localObj = objectMapper.createObjectNode();
+            ObjectNode localNameLikeObj = objectMapper.createObjectNode();
+            ObjectNode localIdLikeObj = objectMapper.createObjectNode();
+            ObjectNode nameLikeObj = objectMapper.createObjectNode();
+            ObjectNode digitalDeliveryIdLikeObj = objectMapper.createObjectNode();
+            localIdLikeObj.put(QueryOperator.LIKE.getIndex(),name);
+            localNameLikeObj.put(QueryOperator.LIKE.getIndex(),name);
+            nameLikeObj.put(QueryOperator.LIKE.getIndex(),name);
+            digitalDeliveryIdLikeObj.put(QueryOperator.LIKE.getIndex(),name);
+            localObj.set("localId",localIdLikeObj);
+            localObj.set("localName",localNameLikeObj);
+            localObj.set("name",nameLikeObj);
+            localObj.set("digitalDeliveryID",digitalDeliveryIdLikeObj);
+            objectNode.put(QueryOperator.AND_OR.getIndex(),localObj);
+        }
+        objectNode.put(ObjectDigital.OBJ_TYPE_HUM, AdmDictCategoryEnum.EQUIPMENT.getValue());
+        objectNode.put(ObjectDigital.PROP_VALID,Boolean.TRUE);
+        queryCriteria.setCriteria(objectNode);
+        // 2.查询设备
+        AdmResponse admResponse = equipmentService.doQuery(AdmContextUtil.toDmpContext(), queryCriteria, AdmEquipment.class);
+        if (!CommonConstant.QUERY_SUCCESS.equals(admResponse.getResult())){
+            return admResponse;
+        }
+        if (CollUtil.isEmpty(admResponse.getContent())){
+            return admResponse;
+        }
+        List<AdmEquipment> content = (List<AdmEquipment>) admResponse.getContent();
+        CommonResult<List<ObjectRelation>> commonResult = queryRelationBySysId(objectMapper, admBatchSyEqRequest.getSysId());
+        if (!CommonConstant.QUERY_SUCCESS.equals(commonResult.getResult())){
+            return AdmCreateResponse.success(new ArrayList<>());
+        }
+        List<ObjectRelation> relations = commonResult.getData();
+        Set<String> equipIds = CollUtil.newHashSet();
+        if (CollUtil.isNotEmpty(relations)){
+            equipIds.addAll(relations.stream().map(ObjectRelation::getObjTo).collect(Collectors.toSet()));
+        }
+        List<ObjectNode> relationList = new ArrayList<>();
+        for (AdmEquipment admEquipment : content) {
+            if (equipIds.contains(admEquipment.getId())){
+                continue;
+            }
+            ObjectRelation objectRelation = new ObjectRelation();
+            objectRelation.setGroupCode(AppContext.getContext().getGroupCode());
+            objectRelation.setProjectId(AppContext.getContext().getProjectId());
+            objectRelation.setGraphId(StrUtil.format(CommonConstant.DEFAULT_GRAPH_ID_FORMAT,AppContext.getContext().getGroupCode()));
+            objectRelation.setGraphCode(AdmRelationTypeEnum.EQ2SY.getGraphCode());
+            objectRelation.setRelCode(AdmRelationTypeEnum.EQ2SY.getRelCode());
+            objectRelation.setObjFrom(admBatchSyEqRequest.getSysId());
+            objectRelation.setObjTo(admEquipment.getId());
+            objectRelation.setCreateApp(AppContext.getContext().getAppId());
+            objectRelation.setUpdateApp(AppContext.getContext().getAppId());
+            objectRelation.setCreator(AppContext.getContext().getAccountId());
+            objectRelation.setModifier(AppContext.getContext().getAccountId());
+            objectRelation.setValid(1);
+            relationList.add(objectMapper.convertValue(objectRelation,ObjectNode.class));
+        }
+        if (CollUtil.isNotEmpty(relationList)){
+            DigitalRelationFacade.create(AppContext.getContext().getGroupCode(),AppContext.getContext().getProjectId(),
+                    AppContext.getContext().getAppId(),AppContext.getContext().getAccountId(),relationList);
+        }
+        return AdmCreateResponse.success(new ArrayList<>());
+    }
+    /***
+     * Description: 查询系统已关联的设备id
+     * @param sysId : 系统id
+     * @return : java.util.Set<java.lang.String>
+     * @author : lijie
+     * @date :2021/11/25 12:27
+     * Update By lijie 2021/11/25 12:27
+     */
+    private CommonResult<List<ObjectRelation>> queryRelationBySysId(ObjectMapper objectMapper,String sysId) {
+        QueryCriteria queryCriteria = new QueryCriteria();
+        ObjectNode objectNode = objectMapper.createObjectNode();
+        objectNode.put(ObjectRelation.PROP_VALID,Boolean.TRUE);
+        objectNode.put(ObjectRelation.GRAPH_CODE_HUM, AdmRelationTypeEnum.EQ2SY.getGraphCode());
+        objectNode.put(ObjectRelation.REL_CODE_HUM, AdmRelationTypeEnum.EQ2SY.getRelCode());
+        objectNode.put(ObjectRelation.OBJ_FROM_HUM, sysId);
+        queryCriteria.setCriteria(objectNode);
+        return DigitalRelationFacade
+                .queryPrototype(AppContext.getContext().getGroupCode(), AppContext.getContext().getProjectId(),
+                        AppContext.getContext().getAppId(), AppContext.getContext().getAccountId(), queryCriteria);
+    }
+
+    /***
+     * Description: 处理查询条件
+     * @param objectNode : 查询参数
+     * @param buildingId : 建筑id
+     * @param floorId : 楼层id
+     * @return : void
+     * @author : lijie
+     * @date :2021/11/25 11:44
+     * Update By lijie 2021/11/25 11:44
+     */
+    private void handleBuildAndFloorQueryParam(ObjectMapper objectMapper,ObjectNode objectNode,
+                                               String buildingId, String floorId) {
+        if (StrUtil.isBlank(buildingId) && StrUtil.isBlank(floorId)){
+            return;
+        }
+        if (StrUtil.isNotBlank(floorId) && !"isnull".equals(floorId)){
+            objectNode.put("floorId",floorId);
+        }
+        if (StrUtil.isNotBlank(buildingId) && !"isnull".equals(buildingId)){
+            objectNode.put("buildingId",buildingId);
+        }
+        if (StrUtil.isNotBlank(buildingId) && "isnull".equals(buildingId)){
+            ObjectNode buildObj = objectMapper.createObjectNode();
+            buildObj.put(QueryOperator.NULL.getIndex(),Boolean.TRUE);
+            objectNode.set("buildingId",buildObj);
+        }
+        if (StrUtil.isNotBlank(floorId) && "isnull".equals(floorId)){
+            ObjectNode floorObj = objectMapper.createObjectNode();
+            floorObj.put(QueryOperator.NULL.getIndex(),Boolean.TRUE);
+            objectNode.set("floorId",floorObj);
+        }
+    }
 
 }

+ 18 - 0
src/main/java/com/persagy/proxy/relation/model/AdmBatchSyEqRequest.java

@@ -0,0 +1,18 @@
+package com.persagy.proxy.relation.model;
+
+import lombok.Data;
+
+@Data
+public class AdmBatchSyEqRequest {
+    /**建筑id*/
+    private String buildingId;
+    /**楼层id*/
+    private String floorId;
+    /**设备类型*/
+    private String classCode;
+    /**关键词*/
+    private String vague;
+    /**系统id*/
+    private String sysId;
+
+}