From 1d585f0eadede9ac9c23df14710d869677def78d Mon Sep 17 00:00:00 2001 From: WenG <450292408@qq.com> Date: Tue, 13 Jul 2021 00:16:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=9C=A8=E7=BA=BF=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apis/activiti/ActivitiController.java | 5 - .../activiti/ActivitiModelController.java | 59 ++++++++ .../activiti/IActivitiModelService.java | 27 ++++ .../impl/ActivitiModelServiceImpl.java | 99 ++++++++++++++ .../resources/static/editor-app/app-cfg.js | 2 +- .../configuration/toolbar-default-actions.js | 6 +- .../editor-app/configuration/toolbar.js | 18 +-- .../editor-app/configuration/url-config.js | 6 +- .../static/editor-app/css/style-common.css | 2 +- .../static/editor-app/editor/oryx.debug.js | 2 +- .../resources/static/editor-app/i18n/en.json | 42 +++--- .../resources/static/route/activiti/list.html | 30 ++--- .../resources/static/route/activiti/save.html | 101 ++++++++++++++ .../static/route/activiti/update.html | 127 ++++++++++++++++++ 14 files changed, 465 insertions(+), 61 deletions(-) create mode 100644 src/main/java/com/cm/inspection/controller/apis/activiti/ActivitiModelController.java create mode 100644 src/main/java/com/cm/inspection/service/activiti/IActivitiModelService.java create mode 100644 src/main/java/com/cm/inspection/service/activiti/impl/ActivitiModelServiceImpl.java create mode 100644 src/main/resources/static/route/activiti/save.html create mode 100644 src/main/resources/static/route/activiti/update.html diff --git a/src/main/java/com/cm/inspection/controller/apis/activiti/ActivitiController.java b/src/main/java/com/cm/inspection/controller/apis/activiti/ActivitiController.java index 7cd642a..f26fc72 100644 --- a/src/main/java/com/cm/inspection/controller/apis/activiti/ActivitiController.java +++ b/src/main/java/com/cm/inspection/controller/apis/activiti/ActivitiController.java @@ -3,13 +3,11 @@ package com.cm.inspection.controller.apis.activiti; import com.cm.common.annotation.CheckRequestBodyAnnotation; import com.cm.common.base.AbstractController; import com.cm.common.constants.ISystemConstant; -import com.cm.common.exception.SearchException; import com.cm.common.pojo.ListPage; import com.cm.common.result.ErrorResult; import com.cm.common.result.SuccessResult; import com.cm.common.result.SuccessResultData; import com.cm.common.result.SuccessResultList; -import com.cm.inspection.pojo.dtos.check.CheckDTO; import com.cm.inspection.pojo.vos.activiti.ActivitiVO; import com.cm.inspection.service.activiti.IActivitiService; import io.swagger.annotations.*; @@ -17,12 +15,9 @@ import org.activiti.engine.repository.Model; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import javax.management.ObjectName; import java.io.IOException; import java.io.UnsupportedEncodingException; -import java.util.Arrays; import java.util.List; -import java.util.Map; /** * When you feel like quitting. Think about why you started diff --git a/src/main/java/com/cm/inspection/controller/apis/activiti/ActivitiModelController.java b/src/main/java/com/cm/inspection/controller/apis/activiti/ActivitiModelController.java new file mode 100644 index 0000000..c98699c --- /dev/null +++ b/src/main/java/com/cm/inspection/controller/apis/activiti/ActivitiModelController.java @@ -0,0 +1,59 @@ +package com.cm.inspection.controller.apis.activiti; + +import com.alibaba.fastjson.JSONObject; +import com.cm.common.base.AbstractController; +import com.cm.common.constants.ISystemConstant; +import com.cm.common.result.SuccessResult; +import com.cm.inspection.service.activiti.IActivitiModelService; +import com.cm.inspection.service.activiti.IActivitiService; +import com.fasterxml.jackson.databind.node.ObjectNode; +import io.swagger.annotations.Api; +import org.activiti.engine.ActivitiException; +import org.activiti.engine.repository.Model; +import org.apache.batik.transcoder.TranscoderException; +import org.apache.batik.transcoder.TranscoderInput; +import org.apache.batik.transcoder.TranscoderOutput; +import org.apache.batik.transcoder.image.PNGTranscoder; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import java.io.*; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: ActivitiModelController + * @Description: 流程模型 + * @Author: WangGeng + * @Date: 2021/7/12 21:56 + * @Version: 1.0 + **/ +@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "流程模型接口") +@RestController +@RequestMapping(ISystemConstant.API_PREFIX + "/activiti/model") +public class ActivitiModelController extends AbstractController { + + @Autowired + private IActivitiModelService activitiModelService; + + @PutMapping("save/{modelId}") + public SuccessResult saveModel(@PathVariable String modelId, String name, String description, String json_xml, String svg_xml) throws Exception { + activitiModelService.saveModel(modelId, name, description, json_xml, svg_xml); + return new SuccessResult(); + } + + @GetMapping("json/{modelId}") + public JSONObject getEditorJson(@PathVariable String modelId) throws UnsupportedEncodingException { + return activitiModelService.getEditorJson(modelId); + } + + @GetMapping("editor/stencilset") + public JSONObject getStencilset() throws IOException { + return activitiModelService.getStencilset(); + } + +} diff --git a/src/main/java/com/cm/inspection/service/activiti/IActivitiModelService.java b/src/main/java/com/cm/inspection/service/activiti/IActivitiModelService.java new file mode 100644 index 0000000..4491f67 --- /dev/null +++ b/src/main/java/com/cm/inspection/service/activiti/IActivitiModelService.java @@ -0,0 +1,27 @@ +package com.cm.inspection.service.activiti; + +import com.alibaba.fastjson.JSONObject; +import com.cm.common.result.SuccessResult; +import org.apache.batik.transcoder.TranscoderException; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: IActivitiModelService + * @Description: 流程模型 + * @Author: WangGeng + * @Date: 2021/7/12 22:01 + * @Version: 1.0 + **/ +public interface IActivitiModelService { + + void saveModel(String modelId, String name, String description, String json_xml, String svg_xml) throws Exception; + + JSONObject getEditorJson(String modelId) throws UnsupportedEncodingException; + + JSONObject getStencilset() throws IOException; +} diff --git a/src/main/java/com/cm/inspection/service/activiti/impl/ActivitiModelServiceImpl.java b/src/main/java/com/cm/inspection/service/activiti/impl/ActivitiModelServiceImpl.java new file mode 100644 index 0000000..a88c72f --- /dev/null +++ b/src/main/java/com/cm/inspection/service/activiti/impl/ActivitiModelServiceImpl.java @@ -0,0 +1,99 @@ +package com.cm.inspection.service.activiti.impl; + +import com.alibaba.fastjson.JSONObject; +import com.cm.common.base.AbstractService; +import com.cm.common.constants.ISystemConstant; +import com.cm.common.exception.SearchException; +import com.cm.common.result.SuccessResult; +import com.cm.inspection.service.activiti.IActivitiModelService; +import com.cm.inspection.service.activiti.IActivitiService; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.activiti.editor.constants.ModelDataJsonConstants; +import org.activiti.engine.ActivitiException; +import org.activiti.engine.RepositoryService; +import org.activiti.engine.repository.Model; +import org.apache.batik.transcoder.TranscoderException; +import org.apache.batik.transcoder.TranscoderInput; +import org.apache.batik.transcoder.TranscoderOutput; +import org.apache.batik.transcoder.image.PNGTranscoder; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.io.*; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: ActivitiModelServiceImpl + * @Description: 流程模型 + * @Author: WangGeng + * @Date: 2021/7/12 22:01 + * @Version: 1.0 + **/ +@Service +public class ActivitiModelServiceImpl extends AbstractService implements IActivitiModelService, ModelDataJsonConstants { + + @Autowired + private RepositoryService repositoryService; + + @Override + public void saveModel(String modelId, String name, String description, String json_xml, String svg_xml) throws Exception { + Model model = repositoryService.getModel(modelId); + if (model == null) { + throw new SearchException("模型不存在"); + } + JSONObject modelObject = JSONObject.parseObject(model.getMetaInfo()); + + modelObject.put(MODEL_NAME, name); + modelObject.put(MODEL_DESCRIPTION, description); + model.setMetaInfo(modelObject.toString()); + model.setName(name); + repositoryService.saveModel(model); + repositoryService.addModelEditorSource(model.getId(), json_xml.getBytes(ISystemConstant.CHARSET_UTF8)); + + InputStream svgStream = new ByteArrayInputStream(svg_xml.getBytes(ISystemConstant.CHARSET_UTF8)); + TranscoderInput input = new TranscoderInput(svgStream); + + PNGTranscoder transcoder = new PNGTranscoder(); + // Setup output + ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + TranscoderOutput output = new TranscoderOutput(outStream); + + // Do the transformation + transcoder.transcode(input, output); + final byte[] result = outStream.toByteArray(); + repositoryService.addModelEditorSourceExtra(model.getId(), result); + outStream.close(); + + } + + @Override + public JSONObject getEditorJson(String modelId) throws UnsupportedEncodingException { + Model model = repositoryService.getModel(modelId); + if (model == null) { + throw new SearchException("模型不存在"); + } + JSONObject result; + if (StringUtils.isNotEmpty(model.getMetaInfo())) { + result = JSONObject.parseObject(model.getMetaInfo()); + } else { + result = new JSONObject(); + result.put(MODEL_NAME, model.getName()); + } + result.put(MODEL_ID, model.getId()); + String readTree = new String(repositoryService.getModelEditorSource(model.getId()), ISystemConstant.CHARSET_UTF8); + JSONObject editorJson = JSONObject.parseObject(readTree); + result.put("model", editorJson); + return result; + } + + @Override + public JSONObject getStencilset() throws IOException { + InputStream stencilsetStream = this.getClass().getClassLoader().getResourceAsStream("stencilset.json"); + String result = IOUtils.toString(stencilsetStream, ISystemConstant.CHARSET_UTF8); + return JSONObject.parseObject(result); + } +} diff --git a/src/main/resources/static/editor-app/app-cfg.js b/src/main/resources/static/editor-app/app-cfg.js index 01f5be2..6de1249 100644 --- a/src/main/resources/static/editor-app/app-cfg.js +++ b/src/main/resources/static/editor-app/app-cfg.js @@ -22,5 +22,5 @@ var ACTIVITI = ACTIVITI || {}; ACTIVITI.CONFIG = { - 'contextRoot' : 'service', + 'contextRoot' : 'api/activiti', }; diff --git a/src/main/resources/static/editor-app/configuration/toolbar-default-actions.js b/src/main/resources/static/editor-app/configuration/toolbar-default-actions.js index 01f29fe..28c86bf 100644 --- a/src/main/resources/static/editor-app/configuration/toolbar-default-actions.js +++ b/src/main/resources/static/editor-app/configuration/toolbar-default-actions.js @@ -261,7 +261,8 @@ KISBPM.TOOLBAR = { }, closeEditor: function(services) { - window.location.href = "./"; + parent.layer.close(parent.layer.getFrameIndex(window.name)); + // window.location.href = "./"; }, /** @@ -326,7 +327,8 @@ var SaveModelCtrl = [ '$rootScope', '$scope', '$http', '$route', '$location', $scope.saveAndClose = function () { $scope.save(function() { - window.location.href = "./"; + parent.layer.close(parent.layer.getFrameIndex(window.name)); + // window.location.href = "./"; }); }; $scope.save = function (successCallback) { diff --git a/src/main/resources/static/editor-app/configuration/toolbar.js b/src/main/resources/static/editor-app/configuration/toolbar.js index f091598..ec02801 100644 --- a/src/main/resources/static/editor-app/configuration/toolbar.js +++ b/src/main/resources/static/editor-app/configuration/toolbar.js @@ -162,14 +162,14 @@ KISBPM.TOOLBAR_CONFIG = { "action" : "KISBPM.TOOLBAR.ACTIONS.removeBendPoint", "id" : "remove-bendpoint-button" } - ], - - "secondaryItems" : [ - { - "type" : "button", - "title" : "Close", - "cssClass" : "editor-icon editor-icon-close", - "action" : "KISBPM.TOOLBAR.ACTIONS.closeEditor" - } ] + + // "secondaryItems" : [ + // { + // "type" : "button", + // "title" : "Close", + // "cssClass" : "editor-icon editor-icon-close", + // "action" : "KISBPM.TOOLBAR.ACTIONS.closeEditor" + // } + // ] }; \ No newline at end of file diff --git a/src/main/resources/static/editor-app/configuration/url-config.js b/src/main/resources/static/editor-app/configuration/url-config.js index e0eb851..cb81193 100644 --- a/src/main/resources/static/editor-app/configuration/url-config.js +++ b/src/main/resources/static/editor-app/configuration/url-config.js @@ -21,14 +21,14 @@ var KISBPM = KISBPM || {}; KISBPM.URL = { getModel: function(modelId) { - return ACTIVITI.CONFIG.contextRoot + '/model/' + modelId + '/json'; + return ACTIVITI.CONFIG.contextRoot + '/model/json/' + modelId; }, getStencilSet: function() { - return ACTIVITI.CONFIG.contextRoot + '/editor/stencilset?version=' + Date.now(); + return ACTIVITI.CONFIG.contextRoot + '/model/editor/stencilset?version=' + Date.now(); }, putModel: function(modelId) { - return ACTIVITI.CONFIG.contextRoot + '/model/' + modelId + '/save'; + return ACTIVITI.CONFIG.contextRoot + '/model/save/' + modelId; } }; \ No newline at end of file diff --git a/src/main/resources/static/editor-app/css/style-common.css b/src/main/resources/static/editor-app/css/style-common.css index 07aab31..afe91a0 100644 --- a/src/main/resources/static/editor-app/css/style-common.css +++ b/src/main/resources/static/editor-app/css/style-common.css @@ -936,7 +936,7 @@ a.dropdown-toggle { } .wrapper.full { - padding: 40px 0px 0px 0px; + padding: 0px 0px 0px 0px; overflow: hidden; max-width: 100%; min-width: 100%; diff --git a/src/main/resources/static/editor-app/editor/oryx.debug.js b/src/main/resources/static/editor-app/editor/oryx.debug.js index 6ce4343..5804227 100644 --- a/src/main/resources/static/editor-app/editor/oryx.debug.js +++ b/src/main/resources/static/editor-app/editor/oryx.debug.js @@ -8187,7 +8187,7 @@ ORYX.Core.StencilSet.StencilSet = Clazz.extend({ this._baseUrl = "editor/stencilsets/bpmn2.0/"; this._source = "stencilsets/bpmn2.0/bpmn2.0.json"; - new Ajax.Request(ACTIVITI.CONFIG.contextRoot + '/editor/stencilset?version=' + Date.now(), { + new Ajax.Request(ACTIVITI.CONFIG.contextRoot + '/model/editor/stencilset?version=' + Date.now(), { asynchronous: false, method: 'get', onSuccess: this._init.bind(this), diff --git a/src/main/resources/static/editor-app/i18n/en.json b/src/main/resources/static/editor-app/i18n/en.json index 06ab3f1..a35ea88 100644 --- a/src/main/resources/static/editor-app/i18n/en.json +++ b/src/main/resources/static/editor-app/i18n/en.json @@ -4,10 +4,10 @@ "PAGE.HEADER" : "Orchestration Details", "ACTION.OK" : "Ok", - "ACTION.SAVE" : "Save", - "ACTION.SAVE-AND-CLOSE" : "Save and close editor", + "ACTION.SAVE" : "保存", + "ACTION.SAVE-AND-CLOSE" : "保存并关闭", "ACTION.SEND" : "Send", - "ACTION.CANCEL" : "Cancel", + "ACTION.CANCEL" : "取消", "ACTION.SELECT" : "Select", "ACTION.ADD" : "Add", "ACTION.REMOVE" : "Remove", @@ -20,25 +20,25 @@ "MAIN_NAVIGATION_SOLUTIONS" : "Solutions", "TOOLBAR.ACTION.CLOSE" : "Close the editor and go back to the overview page", - "TOOLBAR.ACTION.SAVE" : "Save the model", + "TOOLBAR.ACTION.SAVE" : "保存模型", "TOOLBAR.ACTION.VALIDATE": "Validate the model", - "TOOLBAR.ACTION.CUT" : "Cut (select one or more elements in your business process)", - "TOOLBAR.ACTION.COPY" : "Copy (select one or more elements in your business process)", - "TOOLBAR.ACTION.PASTE" : "Paste", - "TOOLBAR.ACTION.DELETE" : "Delete the selected element", - "TOOLBAR.ACTION.UNDO" : "Undo", - "TOOLBAR.ACTION.REDO" : "Redo", - "TOOLBAR.ACTION.ZOOMIN" : "Zoom in", - "TOOLBAR.ACTION.ZOOMOUT" : "Zoom out", - "TOOLBAR.ACTION.ZOOMACTUAL" : "Zoom to actual size", - "TOOLBAR.ACTION.ZOOMFIT" : "Zoom to fit", + "TOOLBAR.ACTION.CUT" : "剪切 (在流程中选择一个或多个节点)", + "TOOLBAR.ACTION.COPY" : "复制 (在流程中选择一个或多个节点)", + "TOOLBAR.ACTION.PASTE" : "粘贴", + "TOOLBAR.ACTION.DELETE" : "删除选择的元素", + "TOOLBAR.ACTION.UNDO" : "下一步", + "TOOLBAR.ACTION.REDO" : "上一步", + "TOOLBAR.ACTION.ZOOMIN" : "放大", + "TOOLBAR.ACTION.ZOOMOUT" : "缩小", + "TOOLBAR.ACTION.ZOOMACTUAL" : "复原", + "TOOLBAR.ACTION.ZOOMFIT" : "填充", "TOOLBAR.ACTION.MOVE" : "Move", "TOOLBAR.ACTION.IMPORT" : "Import", "TOOLBAR.ACTION.EXPORT" : "Export", - "TOOLBAR.ACTION.BENDPOINT.ADD" : "Add bend-point to the selected sequence flow", - "TOOLBAR.ACTION.BENDPOINT.REMOVE" : "Remove bend-point from the selected sequence flow", - "TOOLBAR.ACTION.ALIGNHORIZONTAL" : "Align model horizontal", - "TOOLBAR.ACTION.ALIGNVERTICAL" : "Align model vertical", + "TOOLBAR.ACTION.BENDPOINT.ADD" : "增加流程连线节点", + "TOOLBAR.ACTION.BENDPOINT.REMOVE" : "删除流程连线节点", + "TOOLBAR.ACTION.ALIGNHORIZONTAL" : "水平对齐", + "TOOLBAR.ACTION.ALIGNVERTICAL" : "垂直对齐", "TOOLBAR.ACTION.SAMESIZE" : "Same size", "TOOLBAR.ACTION.HELP": "Start the guided tour", "TOOLBAR.ACTION.FEEDBACK": "Provide feedback", @@ -267,9 +267,9 @@ "PROPERTY.SEQUENCEFLOW.CONDITION.VARIABLE.NO-OUTCOMES-AVAILABLE" : "No outcomes available", "PROPERTY.SEQUENCEFLOW.CONDITION.NO-CONDITION-DISPLAY" : "No condition", - "MODEL.SAVE.TITLE" : "Save model", - "MODEL.NAME" : "Name", - "MODEL.DESCRIPTION" : "Description", + "MODEL.SAVE.TITLE" : "保存模型", + "MODEL.NAME" : "名称", + "MODEL.DESCRIPTION" : "描述", "MODEL.SAVE.NEWVERSION" : "Save this as a new version? This means you can always go back to a previous version", "MODEL.SAVE.COMMENT" : "Comment", "MODEL.SAVE.SAVING" : "Saving model", diff --git a/src/main/resources/static/route/activiti/list.html b/src/main/resources/static/route/activiti/list.html index 1da883b..8717701 100644 --- a/src/main/resources/static/route/activiti/list.html +++ b/src/main/resources/static/route/activiti/list.html @@ -167,15 +167,12 @@ var checkStatus = table.checkStatus('dataTable'); var checkDatas = checkStatus.data; if(layEvent === 'saveEvent') { - layer.open({ - type: 2, - title: false, - closeBtn: 0, - area: ['100%', '100%'], - shadeClose: true, - anim: 2, - content: top.restAjax.path('route/activiti/create.html', []), - end: function() { + top.dialog.open({ + url: top.restAjax.path('route/activiti/save.html', []), + title: '新增流程图', + width: '400px', + height: '300px', + onClose: function() { reloadTable(); } }); @@ -185,15 +182,12 @@ } else if(checkDatas.length > 1) { top.dialog.msg(top.dataMessage.table.selectOneEdit); } else { - layer.open({ - type: 2, - title: false, - closeBtn: 0, - area: ['100%', '100%'], - shadeClose: true, - anim: 2, - content: top.restAjax.path('route/activiti/update.html?modelId={modelId}', [checkDatas[0].id]), - end: function() { + top.dialog.open({ + url: top.restAjax.path('route/activiti/update.html?modelId={modelId}', [checkDatas[0].id]), + title: '编辑流程图', + width: '90%', + height: '90%', + onClose: function() { reloadTable(); } }); diff --git a/src/main/resources/static/route/activiti/save.html b/src/main/resources/static/route/activiti/save.html new file mode 100644 index 0000000..0023672 --- /dev/null +++ b/src/main/resources/static/route/activiti/save.html @@ -0,0 +1,101 @@ + + + + + + + + + + + + + +
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+ +
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/src/main/resources/static/route/activiti/update.html b/src/main/resources/static/route/activiti/update.html new file mode 100644 index 0000000..0bcd45a --- /dev/null +++ b/src/main/resources/static/route/activiti/update.html @@ -0,0 +1,127 @@ + + + + + + + + + + + Activiti Editor + + + + + + + + + + + + + + + + +
+
+ + {{alerts.current.message}} + +
+ {{alerts.queue.length + 1}} +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +