Browse Source

feat(adm-diagram): 系统图查询逻辑变更

liyang 3 years ago
parent
commit
0333e8a282

+ 54 - 14
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/impl/DataStrategyImpl.java

@@ -2,10 +2,12 @@ package com.persagy.adm.diagram.core.impl;
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.StrUtil;
+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.adm.diagram.constant.Constants;
 import com.persagy.adm.diagram.core.DataStrategy;
 import com.persagy.adm.diagram.core.model.Diagram;
 import com.persagy.adm.diagram.core.model.legend.Legend;
@@ -23,6 +25,7 @@ import com.persagy.dmp.common.constant.ResponseCode;
 import com.persagy.dmp.common.exception.BusinessException;
 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 org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
@@ -242,13 +245,41 @@ public class DataStrategyImpl implements DataStrategy {
      */
     @Override
     public List<Diagram> getDiagrams(String diagramType, String projectId, String systemId, String groupCode, String name) {
+
+        Set<DiagramEntity> result = new HashSet<>();
+        //所有系统实例
+        List<ObjectNode> objectNodes = loadSystemInstance(projectId, groupCode);
+        //获取所有id
+        List<String> ids = objectNodes.stream().filter(node -> {
+            String objectName = Optional.ofNullable(node.get(Constants.NAME)).map(JsonNode::asText).orElse(StrUtil.EMPTY);
+            return objectName.contains(name);
+        }).map(jsonNodes -> jsonNodes.get(Constants.ID).asText()).collect(Collectors.toList());
+
+        if (CollectionUtil.isNotEmpty(ids)) {
+            //由系统实例名模糊匹配到的系统图列表
+            List<DiagramEntity> diagramsBySystemIds = diagramMapper.getDiagramsBySystemIds(ids);
+            //合并
+            result.addAll(diagramsBySystemIds);
+        }
+        //直接去系统图表根据名称模糊查询查出来的数据
         List<DiagramEntity> diagrams = diagramMapper.getDiagrams(diagramType,
                 projectId, systemId, groupCode, name);
-        if (CollectionUtil.isNotEmpty(diagrams)) {
-            return diagrams.stream().map(diagramEntity ->
-                    modelAdapter.toDiagram(diagramEntity)).collect(Collectors.toList());
-        }
-        return new ArrayList<>();
+        //合并
+        result.addAll(diagrams);
+
+        //转成map
+        Map<String, ObjectNode> map = objectNodes.stream().collect(Collectors.toMap(node
+                -> node.get(Constants.ID).asText(), node -> node));
+
+        return result.stream().map(diagramEntity -> {
+            Diagram diagram = modelAdapter.toDiagram(diagramEntity);
+            ObjectNode node = map.get(diagramEntity.getSystemId());
+            if (node != null) {
+                diagram.setSystemInstanceName(node.get(Constants.NAME).asText());
+            }
+            return diagram;
+        }).collect(Collectors.toList());
+
     }
 
     /**
@@ -299,9 +330,9 @@ public class DataStrategyImpl implements DataStrategy {
     @Override
     public List<ObjectNode> loadObjectsByType(List<String> equipmentTypes, String projectId,
                                               String systemId, String groupCode) {
-        QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, "equipment");
+        QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, Constants.EQUIPMENT);
         if (CollectionUtil.isNotEmpty(equipmentTypes)) {
-            ArrayNode types = criteria.getCriteria().putArray("classCode");
+            ArrayNode types = criteria.getCriteria().putArray(ObjectDigital.CLASS_CODE_HUM);
             equipmentTypes.forEach(types::add);
         }
 
@@ -348,19 +379,27 @@ public class DataStrategyImpl implements DataStrategy {
         return JsonNodeUtils.toListNode(allRelations, null, null);
     }
 
+    /**
+     * 查询obj_from 和 objTo 的数据
+     *
+     * @param projectId 项目id
+     * @param groupCode 集团code
+     * @param objectIds 对象id列表
+     * @return
+     */
     private List<ObjectRelation> queryRelationsByObjIds(String projectId, String groupCode, List<String> objectIds) {
         List<ObjectRelation> resultList = new ArrayList<>();
         //obj_from
         CompletableFuture<List<ObjectRelation>> fromFuture = CompletableFuture.supplyAsync(() -> {
             QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper);
-            ArrayNode objFrom = criteria.getCriteria().putArray("objFrom");
+            ArrayNode objFrom = criteria.getCriteria().putArray(ObjectRelation.OBJ_FROM_HUM);
             Optional.ofNullable(objectIds).ifPresent(strings -> strings.forEach(objFrom::add));
             return DigitalRelationFacade.query(groupCode, projectId, null, null, criteria);
         }, executor);
         //obj_to
         CompletableFuture<List<ObjectRelation>> toFuture = CompletableFuture.supplyAsync(() -> {
             QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper);
-            ArrayNode objTo = criteria.getCriteria().putArray("objTo");
+            ArrayNode objTo = criteria.getCriteria().putArray(ObjectRelation.OBJ_TO_HUM);
             Optional.ofNullable(objectIds).ifPresent(strings -> strings.forEach(objTo::add));
             return DigitalRelationFacade.query(groupCode, projectId, null, null, criteria);
         }, executor);
@@ -389,8 +428,8 @@ public class DataStrategyImpl implements DataStrategy {
         if (CollectionUtil.isEmpty(objectIds)) {
             throw new BusinessException(ResponseCode.A0400.getCode(), "objectIds不能为空");
         }
-        QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, "equipment");
-        ArrayNode arr = criteria.getCriteria().putArray("id");
+        QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, Constants.EQUIPMENT);
+        ArrayNode arr = criteria.getCriteria().putArray(Constants.ID);
         objectIds.forEach(arr::add);
 
         return DigitalObjectFacade.query(groupCode, projectId, null, null, criteria);
@@ -410,10 +449,11 @@ public class DataStrategyImpl implements DataStrategy {
             throw new BusinessException(ResponseCode.A0400.getCode(), "relationIds不能为空");
         }
         QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper);
-        ArrayNode nodes = criteria.getCriteria().putArray("id");
+        ArrayNode nodes = criteria.getCriteria().putArray(Constants.ID);
         relationIds.forEach(nodes::add);
 
-        List<ObjectRelation> result = DigitalRelationFacade.query(groupCode, projectId, null, null, criteria);
+        List<ObjectRelation> result = DigitalRelationFacade.query(groupCode, projectId,
+                null, null, criteria);
         return JsonNodeUtils.toListNode(result, null, null);
     }
 
@@ -426,7 +466,7 @@ public class DataStrategyImpl implements DataStrategy {
      */
     @Override
     public List<ObjectNode> loadSystemInstance(String projectId, String groupCode) {
-        QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, "system");
+        QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, Constants.SYSTEM);
         return DigitalObjectFacade.query(groupCode, projectId, null, null, criteria);
     }
 }

+ 247 - 233
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/Diagram.java

@@ -11,243 +11,257 @@ import java.util.List;
 
 /**
  * 系统图
+ *
  * @author zhaoyk
  */
 public class Diagram {
 
-	@Expose
-	private String id;
-
-	/**
-	 * 系统图名称
-	 */
-	@Expose
-	private String name;
-
-	/**
-	 * 描述信息
-	 */
-	@Expose
-	private String remark;
-
-	/**
-	 * 系统图类型编码
-	 */
-	@Expose
-	private String type;
-
-	/**
-	 * 引用的模板id
-	 */
-	@Expose
-	private String templateId;
-
-	/**
-	 * 所属的系统类型
-	 */
-	@Expose
-	private String system;
-
-	/**
-	 * 项目id
-	 */
-	@Expose
-	private String projectId;
-
-	/**
-	 * 对应的系统实例id
-	 */
-	@Expose
-	private String systemId;
-
-	/**
-	 * 集团编码
-	 */
-	@Expose
-	private String groupCode;
-
-	/**
-	 * 系统图状态
-	 */
-	@Expose
-	private String state;
-
-
-	/**
-	 * 节点列表
-	 */
-	@Expose
-	private List<DiagramNode> nodes = new ArrayList<>();
-
-	/**
-	 * 连线列表
-	 */
-	@Expose
-	private List lines = new ArrayList();
-
-	//运行时
-	private DiagramTemplate template;
-
-
-	public void init(){
-		if (template != null)
-			template.init();
-
-		nodes.sort(new Comparator<DiagramNode>() {
-			@Override
-			public int compare(DiagramNode o1, DiagramNode o2) {
-				return o1.getLayoutIndex() - o2.getLayoutIndex();
-			}
-		});
-		for (DiagramNode node : nodes) {
-			Container con = template.getContainerById(node.getContainerId());
-			if (con != null)
-				con.addComp(node);
-		}
-	}
-
-	public void layout(XY location){
-		this.layout(location, false);
-	}
-
-	public void layout(XY location, boolean absoluteLocation){
-		if(template != null) {
-			//TODO
-			template.layout(location);
-
-			if(absoluteLocation) {
-				for (DiagramNode node : nodes) {
-					node.setLocation(node.locationToRoot());
-					if(node instanceof EquipmentNode) {
-						EquipmentNode en = (EquipmentNode) node;
-						if(en.getAnchorLocations() != null) {
-							for(XY point : en.getAnchorLocations().values()){
-								point.x += en.getLocation().x;
-								point.y += en.getLocation().y;
-							}
-						}
-						if(en.getLabel() != null) {
-							XY point = en.getLabel().getLocation();
-							point.x += en.getLocation().x;
-							point.y += en.getLocation().y;
-						}
-					}
-				}
-			}
-		}
-	}
-
-	public List<String> getObjIds(){
-		List<String> ids = new ArrayList<>();
-		for(DiagramNode node : nodes) {
-			if(EquipmentNode.TYPE.equals(node.getCompType()))
-				ids.add(((EquipmentNode) node).getObjId());
-		}
-		return ids;
-	}
-
-	public String getId() {
-		return id;
-	}
-
-	public void setId(String id) {
-		this.id = id;
-	}
-
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	public String getRemark() {
-		return remark;
-	}
-
-	public void setRemark(String remark) {
-		this.remark = remark;
-	}
-
-	public String getType() {
-		return type;
-	}
-
-	public void setType(String type) {
-		this.type = type;
-	}
-
-	public String getTemplateId() {
-		return templateId;
-	}
-
-	public void setTemplateId(String templateId) {
-		this.templateId = templateId;
-	}
-
-	public List<DiagramNode> getNodes() {
-		return nodes;
-	}
-
-	public void setNodes(List<DiagramNode> nodes) {
-		this.nodes = nodes;
-	}
-
-	public List getLines() {
-		return lines;
-	}
-
-	public void setLines(List lines) {
-		this.lines = lines;
-	}
-
-	public String getSystem() {
-		return system;
-	}
-
-	public void setSystem(String system) {
-		this.system = system;
-	}
-
-	public String getProjectId() {
-		return projectId;
-	}
-
-	public void setProjectId(String projectId) {
-		this.projectId = projectId;
-	}
-
-	public String getSystemId() {
-		return systemId;
-	}
-
-	public void setSystemId(String systemId) {
-		this.systemId = systemId;
-	}
-
-	public String getGroupCode() {
-		return groupCode;
-	}
-
-	public void setGroupCode(String groupCode) {
-		this.groupCode = groupCode;
-	}
-
-	public String getState() {
-		return state;
-	}
-
-	public void setState(String state) {
-		this.state = state;
-	}
-
-	public DiagramTemplate getTemplate() {
-		return template;
-	}
+    @Expose
+    private String id;
+
+    /**
+     * 系统图名称
+     */
+    @Expose
+    private String name;
+
+    /**
+     * 描述信息
+     */
+    @Expose
+    private String remark;
+
+    /**
+     * 系统图类型编码
+     */
+    @Expose
+    private String type;
+
+    /**
+     * 引用的模板id
+     */
+    @Expose
+    private String templateId;
+
+    /**
+     * 所属的系统类型
+     */
+    @Expose
+    private String system;
+
+    /**
+     * 项目id
+     */
+    @Expose
+    private String projectId;
+
+    /**
+     * 对应的系统实例id
+     */
+    @Expose
+    private String systemId;
+
+    /**
+     * 对应的系统实例名称
+     */
+    @Expose
+    private String systemInstanceName;
+    /**
+     * 集团编码
+     */
+    @Expose
+    private String groupCode;
+
+    /**
+     * 系统图状态
+     */
+    @Expose
+    private String state;
+
+
+    /**
+     * 节点列表
+     */
+    @Expose
+    private List<DiagramNode> nodes = new ArrayList<>();
+
+    /**
+     * 连线列表
+     */
+    @Expose
+    private List lines = new ArrayList();
+
+    //运行时
+    private DiagramTemplate template;
+
+
+    public void init() {
+        if (template != null)
+            template.init();
+
+        nodes.sort(new Comparator<DiagramNode>() {
+            @Override
+            public int compare(DiagramNode o1, DiagramNode o2) {
+                return o1.getLayoutIndex() - o2.getLayoutIndex();
+            }
+        });
+        for (DiagramNode node : nodes) {
+            Container con = template.getContainerById(node.getContainerId());
+            if (con != null)
+                con.addComp(node);
+        }
+    }
+
+    public void layout(XY location) {
+        this.layout(location, false);
+    }
+
+    public void layout(XY location, boolean absoluteLocation) {
+        if (template != null) {
+            //TODO
+            template.layout(location);
+
+            if (absoluteLocation) {
+                for (DiagramNode node : nodes) {
+                    node.setLocation(node.locationToRoot());
+                    if (node instanceof EquipmentNode) {
+                        EquipmentNode en = (EquipmentNode) node;
+                        if (en.getAnchorLocations() != null) {
+                            for (XY point : en.getAnchorLocations().values()) {
+                                point.x += en.getLocation().x;
+                                point.y += en.getLocation().y;
+                            }
+                        }
+                        if (en.getLabel() != null) {
+                            XY point = en.getLabel().getLocation();
+                            point.x += en.getLocation().x;
+                            point.y += en.getLocation().y;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    public List<String> getObjIds() {
+        List<String> ids = new ArrayList<>();
+        for (DiagramNode node : nodes) {
+            if (EquipmentNode.TYPE.equals(node.getCompType()))
+                ids.add(((EquipmentNode) node).getObjId());
+        }
+        return ids;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getTemplateId() {
+        return templateId;
+    }
+
+    public void setTemplateId(String templateId) {
+        this.templateId = templateId;
+    }
+
+    public List<DiagramNode> getNodes() {
+        return nodes;
+    }
+
+    public void setNodes(List<DiagramNode> nodes) {
+        this.nodes = nodes;
+    }
+
+    public List getLines() {
+        return lines;
+    }
+
+    public void setLines(List lines) {
+        this.lines = lines;
+    }
+
+    public String getSystem() {
+        return system;
+    }
+
+    public void setSystem(String system) {
+        this.system = system;
+    }
+
+    public String getProjectId() {
+        return projectId;
+    }
+
+    public void setProjectId(String projectId) {
+        this.projectId = projectId;
+    }
+
+    public String getSystemId() {
+        return systemId;
+    }
+
+    public void setSystemId(String systemId) {
+        this.systemId = systemId;
+    }
+
+    public String getSystemInstanceName() {
+        return systemInstanceName;
+    }
+
+    public void setSystemInstanceName(String systemInstanceName) {
+        this.systemInstanceName = systemInstanceName;
+    }
+
+    public String getGroupCode() {
+        return groupCode;
+    }
+
+    public void setGroupCode(String groupCode) {
+        this.groupCode = groupCode;
+    }
+
+    public String getState() {
+        return state;
+    }
 
-	public void setTemplate(DiagramTemplate template) {
-		this.template = template;
-	}
+    public void setState(String state) {
+        this.state = state;
+    }
+
+    public DiagramTemplate getTemplate() {
+        return template;
+    }
+
+    public void setTemplate(DiagramTemplate template) {
+        this.template = template;
+    }
 
 }

+ 3 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/dao/DiagramMapper.java

@@ -22,6 +22,9 @@ public interface DiagramMapper extends BaseMapper<DiagramEntity> {
                                     @Param("groupCode") String groupCode,
                                     @Param("name") String name);
 
+    //按系统图类型查询
+    List<DiagramEntity> getDiagramsBySystemIds(@Param("systemIds") List<String> ids);
+
     void saveDiagram(DiagramEntity diagramEntity);
 
     boolean deleteByDiagramId(String diagramId);

+ 13 - 1
adm-business/adm-diagram/src/main/resources/mapper/Diagram.xml

@@ -54,7 +54,7 @@
         SELECT
         <include refid="baseSql"/>
         FROM diagram
-        WHERE 1=1
+        WHERE valid = 1
         <if test="null != diagramType and diagramType.length > 0">
             AND type=#{diagramType}
         </if>
@@ -72,6 +72,18 @@
         </if>
     </select>
 
+    <select id="getDiagramsBySystemIds" resultMap="diagramBaseMap">
+        SELECT
+        <include refid="baseSql"/>
+        FROM diagram
+        WHERE valid = 1
+        <if test="systemIds !=null and systemIds.size()>0">
+            <foreach collection="systemIds" open="AND system_id IN(" close=")" separator="," item="item">
+                #{item}
+            </foreach>
+        </if>
+    </select>
+
 </mapper>