2 Commits 318670b97e ... f5b89cbcd3

Tác giả SHA1 Thông báo Ngày
  liyang f5b89cbcd3 Merge remote-tracking branch 'origin/develop' into develop 2 năm trước cách đây
  liyang 69da2db907 feat(adm-diagram): 状态修改接口 2 năm trước cách đây

+ 23 - 8
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/controller/DiagramController.java

@@ -1,9 +1,11 @@
 package com.persagy.adm.diagram.controller;
 
+import cn.hutool.json.JSONUtil;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.adm.diagram.core.ContentParser;
 import com.persagy.adm.diagram.core.DataStrategy;
 import com.persagy.adm.diagram.core.model.Diagram;
+import com.persagy.adm.diagram.core.model.DiagramNode;
 import com.persagy.adm.diagram.core.model.template.DiagramTemplate;
 import com.persagy.adm.diagram.frame.BdtpRequest;
 import com.persagy.adm.diagram.manage.DemoDiagramManager;
@@ -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;
 import java.util.Optional;
@@ -69,7 +72,6 @@ public class DiagramController {
      *
      * @param params    参数集合
      * @param projectId 项目id
-     * @param systemId  系统实例id
      * @param groupCode 集团code
      * @return 系统图信息
      */
@@ -77,12 +79,10 @@ public class DiagramController {
     @PostMapping("/newDiagram")
     public CommonResult<Diagram> newDiagram(@RequestBody Map<String, Object> params,
                                             @RequestParam String projectId,
-                                            @RequestParam(required = false) String systemId,
                                             @RequestParam String groupCode) {
         Diagram diagram = new Diagram();
         diagram.setGroupCode(groupCode);
         diagram.setProjectId(projectId);
-        diagram.setSystemId(systemId);
 
         Optional.ofNullable(params).ifPresent(map -> {
             Optional.ofNullable(map.get("id")).ifPresent(o -> diagram.setId(String.valueOf(o)));
@@ -93,6 +93,7 @@ public class DiagramController {
                 diagram.setType(String.valueOf(o));
                 diagram.setSystem(String.valueOf(o).substring(0, 4));
             });
+            Optional.ofNullable(map.get("systemId")).ifPresent(o -> diagram.setSystemId(String.valueOf(o)));
             Optional.ofNullable(map.get("name")).ifPresent(o -> diagram.setName(String.valueOf(o)));
             Optional.ofNullable(map.get("remark")).ifPresent(o -> diagram.setRemark(String.valueOf(o)));
             Optional.ofNullable(map.get("templateId")).ifPresent(o -> diagram.setTemplateId(String.valueOf(o)));
@@ -102,10 +103,11 @@ public class DiagramController {
             });
             Optional.ofNullable(map.get("lines")).ifPresent(lines ->
                     diagram.setLines(parser.parseContent(parser.toJson(lines), List.class)));
-            Optional.ofNullable(map.get("nodes")).ifPresent(nodes ->
-                    diagram.setNodes(parser.parseContent(parser.toJson(nodes), List.class)));
-            Optional.ofNullable(map.get("template")).ifPresent(s ->
-                    diagram.setTemplate(parser.parseContent(parser.toJson(s), DiagramTemplate.class)));
+            Optional.ofNullable(map.get("nodes")).ifPresent(nodes -> {
+                DiagramNode[] diagramNodes = parser.parseContent(parser.toJson(nodes), DiagramNode[].class);
+                List<DiagramNode> asList = Arrays.asList(diagramNodes);
+                diagram.setNodes(asList);
+            });
         });
 
         return ResultHelper.single(dataStrategy.saveDiagram(diagram));
@@ -132,7 +134,9 @@ public class DiagramController {
     @ApiOperation("根据系统图id获取系统图信息")
     @GetMapping("/getDiagram")
     public CommonResult<Diagram> getDiagram(String diagramId) {
-        return ResultHelper.single(dataStrategy.getDiagram(diagramId));
+        Diagram diagram = dataStrategy.getDiagram(diagramId);
+        diagramManager.buildDiagram(diagram, true);
+        return ResultHelper.single(diagram);
     }
 
     /**
@@ -217,4 +221,15 @@ public class DiagramController {
     public CommonResult<Diagram> loadData(@RequestBody Diagram diagram) {
         return ResultHelper.single(diagramManager.loadData(diagram.getId(), true));
     }
+
+    /**
+     * 系统图转台变更
+     *
+     * @return 模板列表
+     */
+    @ApiOperation("获取所有的系统模板")
+    @PostMapping("/update/state")
+    public CommonResult<Boolean> updateState(@RequestBody Map<String,String> params) {
+        return ResultHelper.single(dataStrategy.updateState(params.get("state"),params.get("id")));
+    }
 }

+ 9 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DataStrategy.java

@@ -87,4 +87,13 @@ public interface DataStrategy {
      * @return
      */
     List<ObjectNode> loadSystemTypeTemplate(Diagram diagram);
+
+    /**
+     * 更新系统图状态
+     *
+     * @param state 状态
+     * @param id
+     * @return
+     */
+    boolean updateState(String state, String id);
 }

+ 22 - 8
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/impl/DataStrategyImpl.java

@@ -41,7 +41,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -434,9 +433,9 @@ public class DataStrategyImpl implements DataStrategy {
     /**
      * 查询obj_from 和 objTo 的数据
      *
-     * @param projectId 项目id
-     * @param groupCode 集团code
-     * @param objectIds 对象id列表
+     * @param projectId  项目id
+     * @param groupCode  集团code
+     * @param objectIds  对象id列表
      * @param graphTypes 关系的图类型(同时处理图类型和边类型不太可行,优选图类型过滤)
      * @return
      */
@@ -445,16 +444,18 @@ public class DataStrategyImpl implements DataStrategy {
 
         //graph_code
         ArrayNode graphCode = objectMapper.createArrayNode();
-        if(graphTypes.size() > 0)
-            graphTypes.forEach(code -> graphCode.add(code));
+        if (graphTypes.size() > 0) {
+            graphTypes.forEach(graphCode::add);
+        }
 
         //obj_from
         CompletableFuture<List<ObjectRelation>> fromFuture = CompletableFuture.supplyAsync(() -> {
             QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper);
             ArrayNode objFrom = criteria.getCriteria().putArray(ObjectRelation.OBJ_FROM_HUM);
             Optional.ofNullable(objectIds).ifPresent(strings -> strings.forEach(objFrom::add));
-            if(graphCode.size() > 0)
+            if (graphCode.size() > 0) {
                 criteria.getCriteria().set(ObjectRelation.GRAPH_CODE_HUM, graphCode);
+            }
             return DigitalRelationFacade.query(groupCode, projectId, null, null, criteria);
         }, executor);
         //obj_to
@@ -462,8 +463,9 @@ public class DataStrategyImpl implements DataStrategy {
             QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper);
             ArrayNode objTo = criteria.getCriteria().putArray(ObjectRelation.OBJ_TO_HUM);
             Optional.ofNullable(objectIds).ifPresent(strings -> strings.forEach(objTo::add));
-            if(graphCode.size() > 0)
+            if (graphCode.size() > 0) {
                 criteria.getCriteria().set(ObjectRelation.GRAPH_CODE_HUM, graphCode);
+            }
             return DigitalRelationFacade.query(groupCode, projectId, null, null, criteria);
         }, executor);
 
@@ -650,4 +652,16 @@ public class DataStrategyImpl implements DataStrategy {
 
         return objectNodes;
     }
+
+    @Override
+    public boolean updateState(String state, String id) {
+        if (StrUtil.isBlank(state) || StrUtil.isBlank(id)) {
+            throw new BusinessException(ResponseCode.A0400.getCode(), "主键id或者状态参数为空");
+        }
+        DiagramEntity entity = new DiagramEntity();
+        entity.setId(id);
+        entity.setState(state);
+        diagramMapper.updateById(entity);
+        return true;
+    }
 }

+ 6 - 2
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/entity/ModelAdapter.java

@@ -2,11 +2,13 @@ package com.persagy.adm.diagram.entity;
 
 import com.persagy.adm.diagram.core.ContentParser;
 import com.persagy.adm.diagram.core.model.Diagram;
+import com.persagy.adm.diagram.core.model.DiagramNode;
 import com.persagy.adm.diagram.core.model.legend.Legend;
 import com.persagy.adm.diagram.core.model.template.DiagramTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -68,8 +70,9 @@ public class ModelAdapter {
         Diagram diagram = new Diagram();
         Map map = parser.parseContent(diagramEntity.getDiagramContent(), Map.class);
         diagram.setLines(parser.parseContent(parser.toJson(map.get("lines")), List.class));
-        diagram.setNodes(parser.parseContent(parser.toJson(map.get("nodes")), List.class));
-        diagram.setTemplate(parser.parseContent(parser.toJson(map.get("template")), DiagramTemplate.class));
+        DiagramNode[] nodes = parser.parseContent(parser.toJson(map.get("nodes")), DiagramNode[].class);
+        List<DiagramNode> diagramNodes = Arrays.asList(nodes);
+        diagram.setNodes(diagramNodes);
 
         diagram.setId(diagramEntity.getId());
         diagram.setName(diagramEntity.getName());
@@ -80,6 +83,7 @@ public class ModelAdapter {
         diagram.setProjectId(diagramEntity.getProjectId());
         diagram.setSystemId(diagramEntity.getSystemId());
         diagram.setGroupCode(diagramEntity.getGroupCode());
+        diagram.setCreateTime(diagramEntity.getCreationTime());
         diagram.setExtraProp("state", diagramEntity.getState());
         return diagram;
     }

+ 1 - 1
adm-business/adm-diagram/src/main/resources/db.init/schema.sql

@@ -63,7 +63,7 @@ CREATE TABLE IF NOT EXISTS `diagram` (
   `project_id` varchar(40) DEFAULT NULL COMMENT '项目id',
   `system_id` varchar(100) DEFAULT NULL COMMENT '系统id',
   `group_code` varchar(40) DEFAULT NULL COMMENT '集团编码',
-  `state` tinyint DEFAULT 1 NOT NULL COMMENT '系统图状态',
+  `state` varchar(40) DEFAULT NULL NOT NULL COMMENT '系统图状态',
   `diagram_content` json DEFAULT NULL COMMENT '系统图内容,json格式',
   `creator` varchar(32) DEFAULT NULL COMMENT '创建人',
   `creation_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',

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

@@ -12,7 +12,7 @@
         <result column="project_id" property="projectId" jdbcType="VARCHAR"/>
         <result column="system_id" property="systemId" jdbcType="VARCHAR"/>
         <result column="group_code" property="groupCode" jdbcType="VARCHAR"/>
-        <result column="state" property="state" jdbcType="TINYINT"/>
+        <result column="state" property="state" jdbcType="VARCHAR"/>
         <result column="diagram_content" property="diagramContent" jdbcType="VARCHAR"/>
         <result column="creator" property="creator" jdbcType="VARCHAR"/>
         <result column="creation_time" property="creationTime" jdbcType="CHAR"/>
@@ -31,11 +31,11 @@
         INSERT INTO diagram
         (id,name,remark,type,bt_system,template_id,
         project_id,system_id,group_code,diagram_content,
-        creator,creation_time,modifier,modified_time)
+        creator,creation_time,modifier,modified_time,state)
         VALUES
         (#{id},#{name},#{remark},#{type},#{btSystem},#{templateId},
         #{projectId},#{systemId},#{groupCode},#{diagramContent},
-        #{creator}, #{creationTime},#{modifier},#{modifiedTime})
+        #{creator}, #{creationTime},#{modifier},#{modifiedTime},#{state})
     </insert>
 
     <delete id="deleteByDiagramId">