Переглянути джерело

feat(adm-diagram): 增加模板、系统实例获取接口

liyang 2 роки тому
батько
коміт
19784f8fd9

+ 60 - 14
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/controller/DiagramController.java

@@ -1,8 +1,9 @@
 package com.persagy.adm.diagram.controller;
 
-import cn.hutool.core.util.StrUtil;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.adm.diagram.core.DataStrategy;
 import com.persagy.adm.diagram.core.model.Diagram;
+import com.persagy.adm.diagram.core.model.template.DiagramTemplate;
 import com.persagy.dmp.common.model.response.CommonResult;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
@@ -17,6 +18,7 @@ import java.util.List;
  * @date 2022-01-04
  */
 @RestController
+@CrossOrigin
 @RequestMapping("/diagram")
 public class DiagramController {
 
@@ -26,20 +28,21 @@ public class DiagramController {
 
     /**
      * 系统图列表接口
-     * 根据系统图类型、项目id、系统实例id、集团code查询
+     * 根据系统图类型、项目id、系统实例id、集团code、系统图名称查询
      *
-     * @param diagram 参数对象
+     * @param projectId 项目id
+     * @param systemId  系统实例id
+     * @param groupCode 集团code
+     * @param name      系统图名称
      * @return 系统图列表
      */
-    @PostMapping("/list")
-    public CommonResult<List<Diagram>> list(@RequestBody Diagram diagram) {
-        String diagramType = diagram.getType();
-        if (StrUtil.isNotBlank(diagramType)) {
-            return CommonResult.success(dataStrategy.getDiagrams(diagramType, diagram.getProjectId(),
-                    diagram.getSystemId(), diagram.getGroupCode()));
-        }
-        return CommonResult.success(dataStrategy.getDiagrams(diagram.getProjectId(), diagram.getSystemId(),
-                diagram.getGroupCode()));
+    @RequestMapping("/getDiagrams")
+    public CommonResult<List<Diagram>> getDiagrams(@RequestParam String projectId,
+                                                   @RequestParam(required = false) String systemId,
+                                                   @RequestParam(required = false) String groupCode,
+                                                   @RequestParam(required = false) String name) {
+        return CommonResult.success(dataStrategy.getDiagrams(null, projectId, systemId,
+                groupCode, name));
     }
 
     /**
@@ -48,8 +51,8 @@ public class DiagramController {
      * @param diagram 系统图对象信息
      * @return 是否成功
      */
-    @PostMapping("/saveDiagram")
-    public CommonResult<Diagram> saveDiagram(@RequestBody Diagram diagram) {
+    @PostMapping("/newDiagram")
+    public CommonResult<Diagram> newDiagram(@RequestBody Diagram diagram) {
         return CommonResult.success(dataStrategy.saveDiagram(diagram));
     }
 
@@ -75,4 +78,47 @@ public class DiagramController {
         return CommonResult.success(dataStrategy.getDiagram(diagramId));
     }
 
+    /**
+     * 系统图实例查询
+     *
+     * @param projectId 项目id
+     * @param groupCode 集团code
+     * @return 系统实例
+     */
+    @GetMapping("/system/instance")
+    public CommonResult<List<ObjectNode>> loadSystemInstance(String projectId, String groupCode) {
+        return CommonResult.success(dataStrategy.loadSystemInstance(projectId, groupCode));
+    }
+
+    /**
+     * 根据系统图类型获取模板列表
+     *
+     * @param diagramType 系统图类型
+     * @return 模板列表
+     */
+    @GetMapping("/getTemplates/ByType")
+    public CommonResult<List<DiagramTemplate>> getTemplatesByType(String diagramType) {
+        return CommonResult.success(dataStrategy.getTemplates(diagramType));
+    }
+
+    /**
+     * 根据模板id获取系统模板信息
+     *
+     * @param templateId 模板id
+     * @return 模板信息
+     */
+    @GetMapping("/getTemplate/ById")
+    public CommonResult<DiagramTemplate> getTemplateById(String templateId) {
+        return CommonResult.success(dataStrategy.getTemplate(templateId));
+    }
+
+    /**
+     * 获取所有的系统模板
+     *
+     * @return 模板列表
+     */
+    @GetMapping("/getTemplates")
+    public CommonResult<List<DiagramTemplate>> getTemplates() {
+        return CommonResult.success(dataStrategy.getTemplates());
+    }
 }

+ 36 - 27
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DataStrategy.java

@@ -1,66 +1,75 @@
 package com.persagy.adm.diagram.core;
 
 import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.persagy.adm.diagram.core.model.template.DiagramTemplate;
-import com.persagy.adm.diagram.entity.DiagramType;
 import com.persagy.adm.diagram.core.model.Diagram;
 import com.persagy.adm.diagram.core.model.legend.Legend;
+import com.persagy.adm.diagram.core.model.template.DiagramTemplate;
+import com.persagy.adm.diagram.entity.DiagramType;
 
 import java.util.List;
 
 /**
  * IO策略接口
+ *
  * @author zhaoyk
  */
 public interface DataStrategy {
 
-	String implQualifier = "demo";
+    String implQualifier = "demo";
 
-	List<DiagramType> getDiagramTypes();
+    List<DiagramType> getDiagramTypes();
 
-	//模板
-	List<DiagramTemplate> getTemplates();
+    //模板
+    List<DiagramTemplate> getTemplates();
 
-	List<DiagramTemplate> getTemplates(String diagramType);
+    List<DiagramTemplate> getTemplates(String diagramType);
 
-	DiagramTemplate saveTemplate(DiagramTemplate template);
+    DiagramTemplate saveTemplate(DiagramTemplate template);
 
-	boolean deleteTemplate(String templateId);
+    boolean deleteTemplate(String templateId);
 
-	DiagramTemplate getTemplate(String templateId);
+    DiagramTemplate getTemplate(String templateId);
 
 
-	//图例
-	List<Legend> getLegends(String systemCode);
+    //图例
+    List<Legend> getLegends(String systemCode);
 
-	Legend saveLegend(Legend legend, String systemCode);
+    Legend saveLegend(Legend legend, String systemCode);
 
-	boolean deleteLegend(String legendId, String systemCode);
+    boolean deleteLegend(String legendId, String systemCode);
 
-	Legend getLegend(String legendId, String systemCode);
+    Legend getLegend(String legendId, String systemCode);
 
-	List<Legend> getLegendsForEquipment(String equipmentType);
+    List<Legend> getLegendsForEquipment(String equipmentType);
 
 
-	//系统图
-	List<Diagram> getDiagrams(String projectId, String systemId, String groupCode);
+    //系统图
+    List<Diagram> getDiagrams(String projectId, String systemId, String groupCode);
 
-	List<Diagram> getDiagrams(String diagramType, String projectId, String systemId, String groupCode); //按系统图类型查询
+    List<Diagram> getDiagrams(String diagramType, String projectId, String systemId, String groupCode, String name); //按系统图类型查询
 
-	Diagram saveDiagram(Diagram diagram);
+    Diagram saveDiagram(Diagram diagram);
 
-	boolean deleteDiagram(String diagramId);
+    boolean deleteDiagram(String diagramId);
 
-	Diagram getDiagram(String diagramId);
+    Diagram getDiagram(String diagramId);
 
 
-	//系统图数据
-	List<ObjectNode> loadObjectsByType(List<String> equipmentTypes, String projectId, String systemId, String groupCode);
+    //系统图数据
+    List<ObjectNode> loadObjectsByType(List<String> equipmentTypes, String projectId, String systemId, String groupCode);
 
-	List<ObjectNode> loadRelationsByType(List<String[]> relationTypes, List<String> objectIds, String projectId, String groupCode);
+    List<ObjectNode> loadRelationsByType(List<String[]> relationTypes, List<String> objectIds, String projectId, String groupCode);
 
-	List<ObjectNode> loadObjectsById(List<String> objectIds, String projectId, String groupCode);
+    List<ObjectNode> loadObjectsById(List<String> objectIds, String projectId, String groupCode);
 
-	List<ObjectNode> loadRelationsById(List<String> relationIds, String projectId, String groupCode);
+    List<ObjectNode> loadRelationsById(List<String> relationIds, String projectId, String groupCode);
 
+    /**
+     * 获取所有系统实例
+     *
+     * @param projectId 项目id
+     * @param groupCode 集团code
+     * @return 实例列表
+     */
+    List<ObjectNode> loadSystemInstance(String projectId, String groupCode);
 }

+ 17 - 3
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/impl/DataStrategyImpl.java

@@ -222,7 +222,7 @@ public class DataStrategyImpl implements DataStrategy {
      */
     @Override
     public List<Diagram> getDiagrams(String projectId, String systemId, String groupCode) {
-        List<DiagramEntity> diagrams = diagramMapper.getDiagrams(null, projectId, systemId, groupCode);
+        List<DiagramEntity> diagrams = diagramMapper.getDiagrams(null, projectId, systemId, groupCode, null);
         if (CollectionUtil.isNotEmpty(diagrams)) {
             return diagrams.stream().map(diagramEntity ->
                     modelAdapter.toDiagram(diagramEntity)).collect(Collectors.toList());
@@ -237,12 +237,13 @@ public class DataStrategyImpl implements DataStrategy {
      * @param projectId   项目id
      * @param systemId    系统id
      * @param groupCode   集团code
+     * @param name        系统图名称
      * @return 系统图列表
      */
     @Override
-    public List<Diagram> getDiagrams(String diagramType, String projectId, String systemId, String groupCode) {
+    public List<Diagram> getDiagrams(String diagramType, String projectId, String systemId, String groupCode, String name) {
         List<DiagramEntity> diagrams = diagramMapper.getDiagrams(diagramType,
-                projectId, systemId, groupCode);
+                projectId, systemId, groupCode, name);
         if (CollectionUtil.isNotEmpty(diagrams)) {
             return diagrams.stream().map(diagramEntity ->
                     modelAdapter.toDiagram(diagramEntity)).collect(Collectors.toList());
@@ -414,4 +415,17 @@ public class DataStrategyImpl implements DataStrategy {
         List<ObjectRelation> result = DigitalRelationFacade.query(groupCode, projectId, null, null, criteria);
         return JsonNodeUtils.toListNode(result, null, null);
     }
+
+    /**
+     * 获取系统实例列表
+     *
+     * @param projectId 项目id
+     * @param groupCode 集团code
+     * @return 系统实例列表
+     */
+    @Override
+    public List<ObjectNode> loadSystemInstance(String projectId, String groupCode) {
+        QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, "system");
+        return DigitalObjectFacade.query(groupCode, projectId, null, null, criteria);
+    }
 }

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

@@ -1,7 +1,6 @@
 package com.persagy.adm.diagram.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.persagy.adm.diagram.core.model.Diagram;
 import com.persagy.adm.diagram.entity.DiagramEntity;
 import org.apache.ibatis.annotations.Param;
 
@@ -20,7 +19,8 @@ public interface DiagramMapper extends BaseMapper<DiagramEntity> {
     List<DiagramEntity> getDiagrams(@Param("diagramType") String diagramType,
                                     @Param("projectId") String projectId,
                                     @Param("systemId") String systemId,
-                                    @Param("groupCode") String groupCode);
+                                    @Param("groupCode") String groupCode,
+                                    @Param("name") String name);
 
     void saveDiagram(DiagramEntity diagramEntity);
 

+ 6 - 2
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/demo/DemoDataStrategy.java

@@ -281,11 +281,11 @@ public class DemoDataStrategy implements DataStrategy {
 
 	@Override
 	public List<Diagram> getDiagrams(String projectId, String systemId, String groupCode) {
-		return getDiagrams(null, projectId, systemId, groupCode);
+		return getDiagrams(null, projectId, systemId, groupCode,null);
 	}
 
 	@Override
-	public List<Diagram> getDiagrams(String diagramType, String projectId, String systemId, String groupCode) {
+	public List<Diagram> getDiagrams(String diagramType, String projectId, String systemId, String groupCode,String name) {
 		ArrayList<Diagram> diagrams = new ArrayList<>();
 
 		File dir = new File(DIR_DIAGRAM);
@@ -377,4 +377,8 @@ public class DemoDataStrategy implements DataStrategy {
 		return null;
 	}
 
+	@Override
+	public List<ObjectNode> loadSystemInstance(String projectId, String groupCode) {
+		return null;
+	}
 }