Browse Source

模板编辑复制粘贴操作

zhaoyk 3 years ago
parent
commit
b74cb8ba43

+ 10 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/controller/TemplateController.java

@@ -106,4 +106,14 @@ public class TemplateController {
         return ResultHelper.single(templateManager.modifyDynGroup(params.getDynGroup(), params.getCurrentCompId(), params.getTemplateId()));
     }
 
+    @PostMapping("copyContent")
+    public CommonResult<String> copyContent(@RequestBody EditRequest params){
+        return ResultHelper.single(templateManager.getCopyContent(params.getCurrentCompId(), params.getTemplateId()));
+    }
+
+    @PostMapping("pasteContent")
+    public CommonResult<DiagramTemplate> pasteContent(@RequestBody EditRequest params){
+        return ResultHelper.single(templateManager.setPasteContent(params.getContent(), params.getCurrentCompId(), params.getTemplateId()));
+    }
+
 }

+ 2 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/frame/EditRequest.java

@@ -40,6 +40,8 @@ public class EditRequest {
 
 	private DynGroup dynGroup;
 
+	private String content;
+
 	@Data
 	public static class TemplatePropsData {
 

+ 61 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/TemplateManager.java

@@ -2,6 +2,7 @@ package com.persagy.adm.diagram.manage;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.adm.diagram.core.ContentParser;
 import com.persagy.adm.diagram.core.DataStrategy;
@@ -401,4 +402,64 @@ public class TemplateManager {
         return saveTemplate(template);
     }
 
+    public String getCopyContent(String compId, String templateId){
+        DiagramTemplate template = dataStrategy.getTemplate(templateId);
+        template.init();
+
+        Object obj;
+        if(StrUtil.isNotBlank(compId)) {
+            obj = template.getContainerById(compId);
+            if(obj == null){
+                obj = template.getMainPipeById(compId);
+            }
+        } else {
+            obj = template;
+        }
+        return obj != null ? contentParser.toJson(obj) : "";
+    }
+
+    public DiagramTemplate setPasteContent(String content, String compId, String templateId){
+        DiagramTemplate template = dataStrategy.getTemplate(templateId);
+        template.init();
+
+        if(StrUtil.isNotBlank(content)) {
+            Map<String, Object> map = contentParser.parseContent(content, Map.class);
+            Object o = null;
+            if(Container.TYPE.equals(map.get("compType"))){
+                o = contentParser.parseContent(content, Container.class);
+            } else if(MainPipe.TYPE.equals(map.get("compType"))) {
+                o = contentParser.parseContent(content, MainPipe.class);
+            } else if(map.containsKey("frame")) {
+                o = contentParser.parseContent(content, DiagramTemplate.class);
+            }
+
+            if(o != null) {
+                if(o instanceof DiagramTemplate){
+                    DiagramTemplate other = (DiagramTemplate)o;
+                    if(StrUtil.isBlank(compId)) {
+                        template.setFrame(other.getFrame());
+                        template.setMainPipes(other.getMainPipes());
+                        template.setScatteredContainers(other.getScatteredContainers());
+                    }
+                } else if(o instanceof Container) {
+                    Container target = null;
+                    if(StrUtil.isNotBlank(compId)) {
+                        Container con = template.getContainerById(compId);
+                        if(con != null){
+                            target = con;
+                        }
+                    } else {
+                      target = template.getFrame();
+                    }
+                    if(target != null){
+                        target.addComp((Container)o);
+                    }
+                } else {
+                    //暂不支持干管粘贴
+                }
+            }
+        }
+        return saveTemplate(template);
+    }
+
 }