2 Commits 9bd3776fb7 ... d10fd1e6a6

Auteur SHA1 Bericht Datum
  liyang d10fd1e6a6 Merge remote-tracking branch 'origin/develop' into develop 2 jaren geleden
  liyang f5d58498cb feat(adm-diagram): apm获取系统图列表接口增加返回图列对应的图标信息 2 jaren geleden

+ 15 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/controller/DiagramController.java

@@ -1,5 +1,6 @@
 package com.persagy.adm.diagram.controller;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.StrUtil;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.adm.diagram.core.ContentParser;
@@ -8,6 +9,7 @@ import com.persagy.adm.diagram.core.model.Diagram;
 import com.persagy.adm.diagram.core.model.template.DiagramTemplate;
 import com.persagy.adm.diagram.frame.BdtpRequest;
 import com.persagy.adm.diagram.manage.DiagramManager;
+import com.persagy.adm.diagram.service.IconService;
 import com.persagy.dmp.common.constant.ResponseCode;
 import com.persagy.dmp.common.exception.BusinessException;
 import com.persagy.dmp.common.model.response.CommonResult;
@@ -22,6 +24,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -42,6 +45,8 @@ public class DiagramController {
     private DiagramManager diagramManager;
     @Autowired
     private ContentParser parser;
+    @Autowired
+    private IconService iconService;
 
     /**
      * 系统图列表接口
@@ -77,10 +82,19 @@ public class DiagramController {
 
         List<Diagram> diagramList = dataStrategy.getDiagrams(null, projectId,
                 (String) diagram.get("systemId"), groupCode, null, false);
-        if (diagramList != null) { //TODO 批量处理会导致接口响应慢,优化为列表和内容拆分的方式
+        //TODO 批量处理会导致接口响应慢,优化为列表和内容拆分的方式
+        if (diagramList != null) {
             diagramList.forEach(d -> {
                 diagramManager.buildDiagram(d);
                 d.toAbsoluteLocation();
+
+                //TODO 批量处理会导致接口响应慢,优化为列表和内容拆分的方式
+                //没有nodes的话就不去查询了
+                if (CollectionUtil.isNotEmpty(d.getNodes())) {
+                    String[] legendIds = d.getLegendIds();
+                    Map<String, String> map = iconService.getIconsByLegendIds(Arrays.asList(legendIds));
+                    d.setExtraProp("legendIcons", map);
+                }
             });
         }
 

+ 7 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/dao/IconMapper.java

@@ -37,4 +37,11 @@ public interface IconMapper extends BaseMapper<IconEntity> {
      * @return
      */
     List<IconEntity> getIconsBySystemType(String systemType);
+
+    /**
+     * 根据图例id列表获取图标
+     * @param legendIds 图例id列表
+     * @return 图标列表
+     */
+    List<IconEntity> getIconsByLegendIds(List<String> legendIds);
 }

+ 9 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/service/IconService.java

@@ -3,6 +3,7 @@ package com.persagy.adm.diagram.service;
 import com.persagy.adm.diagram.entity.IconEntity;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 图标服务
@@ -51,4 +52,12 @@ public interface IconService {
      * @return
      */
     List<IconEntity> getIconsBySystemType(String system);
+
+    /**
+     * 根据图例id列表获取图标
+     *
+     * @param legendIds 图例id列表
+     * @return 图标列表
+     */
+    Map<String,String> getIconsByLegendIds(List<String> legendIds);
 }

+ 20 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/service/impl/IconServiceImpl.java

@@ -1,5 +1,6 @@
 package com.persagy.adm.diagram.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.StrUtil;
 import com.persagy.adm.diagram.dao.IconMapper;
@@ -8,7 +9,10 @@ import com.persagy.adm.diagram.service.IconService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
 public class IconServiceImpl implements IconService {
@@ -61,4 +65,20 @@ public class IconServiceImpl implements IconService {
     public List<IconEntity> getIconsBySystemType(String systemType) {
         return iconMapper.getIconsBySystemType(systemType);
     }
+
+    /**
+     * 根据图例id列表获取图标
+     *
+     * @param legendIds 图例id列表
+     * @return 图例id : icon id
+     */
+    @Override
+    public Map<String, String> getIconsByLegendIds(List<String> legendIds) {
+        List<IconEntity> icons = iconMapper.getIconsByLegendIds(legendIds);
+        if (CollectionUtil.isNotEmpty(icons)) {
+            return icons.stream().collect(
+                    Collectors.toMap(IconEntity::getLegendId, IconEntity::getId));
+        }
+        return new HashMap<>();
+    }
 }

+ 11 - 0
adm-business/adm-diagram/src/main/resources/mapper/DiagramIcon.xml

@@ -46,6 +46,17 @@
         FROM diagram_icon
         WHERE valid = 1 AND system_type=#{systemType}
     </select>
+    <select id="getIconsByLegendIds" resultMap="iconBaseMap">
+        SELECT
+        <include refid="baseSql"/>
+        FROM diagram_icon
+        WHERE valid = 1
+        <if test="legendIds !=null and legendIds.size()>0">
+            <foreach collection="legendIds" open="AND legend_id IN(" close=")" separator="," item="item">
+                #{item}
+            </foreach>
+        </if>
+    </select>
 </mapper>