diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/ModelController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/ModelController.java index 4d661431a..54c8be38e 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/ModelController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/ModelController.java @@ -1,32 +1,21 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow; -import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.TodoTaskRespVO; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelCreateVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelPageReqVo; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelRespVo; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelUpdateVO; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelVO; import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.activiti.engine.*; import org.activiti.engine.repository.Model; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.io.UnsupportedEncodingException; /** * 工作流模型 @@ -49,14 +38,14 @@ public class ModelController { @PostMapping("/create") @ApiOperation(value = "新建模型") - public CommonResult newModel(@RequestBody ModelCreateVO modelCreateVO) { - return bpmModelService.newModel(modelCreateVO); + public CommonResult newModel(@RequestBody ModelVO modelVO) { + return bpmModelService.newModel(modelVO); } @PostMapping("/update") @ApiOperation(value = "修改模型属性") - public CommonResult updateModel(@RequestBody ModelUpdateVO modelUpdateVO) { - return bpmModelService.updateModel(modelUpdateVO); + public CommonResult updateModel(@RequestBody ModelVO modelVO) { + return bpmModelService.updateModel(modelVO); } @PostMapping("/delete") @@ -72,9 +61,9 @@ public class ModelController { } @GetMapping("/exportBpmnXml") - @ApiOperation(value = "导出模型") - public void export(@RequestParam String deploymentId, HttpServletResponse response) throws IOException { - FileResp fileResp = bpmModelService.exportBpmnXml(deploymentId); + @ApiOperation(value = "导出模型Xml") + public void export(@RequestParam String modelId, HttpServletResponse response) throws IOException { + FileResp fileResp = bpmModelService.exportBpmnXml(modelId); ServletUtils.writeAttachment(response, fileResp.getFileName(), fileResp.getFileByte()); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/vo/model/ModelCreateVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/vo/model/ModelCreateVO.java deleted file mode 100644 index 1600a75ae..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/vo/model/ModelCreateVO.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; - -/** - * 新增模型 VO - * @author yunlongn - */ -@Data -public class ModelCreateVO { - - @ApiModelProperty(value = "模型名字", required = true) - private String name; - - @ApiModelProperty(value = "模型描述") - private String description; - - @ApiModelProperty(value = "版本号") - private Integer revision; - - @ApiModelProperty(value = "key值") - private String key; -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/vo/model/ModelUpdateVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/vo/model/ModelVO.java similarity index 87% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/vo/model/ModelUpdateVO.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/vo/model/ModelVO.java index 59bdea827..9858b05ee 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/vo/model/ModelUpdateVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/workflow/vo/model/ModelVO.java @@ -8,9 +8,9 @@ import lombok.Data; * @author yunlongn */ @Data -public class ModelUpdateVO { +public class ModelVO { - @ApiModelProperty(value = "模型Id", required = true) + @ApiModelProperty(value = "模型Id") private String id; @ApiModelProperty(value = "模型名字", required = true) @@ -27,6 +27,4 @@ public class ModelUpdateVO { @ApiModelProperty(value = "bpmnXml") private String bpmnXml; - - } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/BpmModelService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/BpmModelService.java index f63bdca5a..1c07ce5f9 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/BpmModelService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/BpmModelService.java @@ -1,16 +1,12 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelCreateVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelPageReqVo; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelRespVo; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelUpdateVO; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelVO; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import org.activiti.engine.repository.Model; -import javax.servlet.http.HttpServletResponse; - /** * 工作流模型接口 * @author yunlongn @@ -27,16 +23,16 @@ public interface BpmModelService { /** * 新增一个模型 - * @param modelCreateVO 模型对象 + * @param modelVO 模型对象 * @return 返回成功 */ - CommonResult newModel(ModelCreateVO modelCreateVO); + CommonResult newModel(ModelVO modelVO); /** * 修改模型属性,填充bpmn数据 - * @param modelUpdateVO 模型对象 + * @param modelVO 模型对象 * @return 返回成功 */ - CommonResult updateModel(ModelUpdateVO modelUpdateVO); + CommonResult updateModel(ModelVO modelVO); /** * 部署模型 使模型成为一个 process diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmModelServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmModelServiceImpl.java index adf637aca..b368d6baa 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmModelServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/workflow/impl/BpmModelServiceImpl.java @@ -1,12 +1,9 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl; -import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelCreateVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelPageReqVo; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelRespVo; -import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelUpdateVO; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelVO; import cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants; import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; @@ -15,26 +12,20 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.activiti.api.runtime.shared.query.Pageable; import org.activiti.bpmn.converter.BpmnXMLConverter; import org.activiti.bpmn.model.BpmnModel; import org.activiti.engine.RepositoryService; import org.activiti.engine.repository.Deployment; import org.activiti.engine.repository.Model; import org.activiti.engine.repository.ModelQuery; -import org.activiti.engine.repository.ProcessDefinition; import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; -import javax.servlet.http.HttpServletResponse; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; -import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Optional; @@ -64,64 +55,67 @@ public class BpmModelServiceImpl implements BpmModelService { } @Override - public CommonResult newModel(ModelCreateVO modelCreateVO) { + public CommonResult newModel(ModelVO modelVO) { try { //初始化一个空模型 Model model = repositoryService.newModel(); - String name = Optional.ofNullable(modelCreateVO.getName()).orElse("new-process"); + String name = Optional.ofNullable(modelVO.getName()).orElse("new-process"); //设置一些默认信息 model.setName(name); - model.setKey(Optional.ofNullable(modelCreateVO.getKey()).orElse("processKey")); - model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO)); + model.setKey(Optional.ofNullable(modelVO.getKey()).orElse("processKey")); + model.setMetaInfo(JsonUtils.toJsonString(modelVO)); repositoryService.saveModel(model); - return CommonResult.success("保存成功"); + if (!ObjectUtils.isEmpty(modelVO.getBpmnXml())) { + repositoryService.addModelEditorSource(model.getId(), modelVO.getBpmnXml().getBytes(StandardCharsets.UTF_8)); + } + return CommonResult.success(model.getId()); }catch (Exception e){ - log.info("模型创建失败!modelCreateVO = {} e = {} ", modelCreateVO, ExceptionUtils.getStackTrace(e)); + log.info("模型创建失败!modelVO = {} e = {} ", modelVO, ExceptionUtils.getStackTrace(e)); throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); } } @Override - public CommonResult updateModel(ModelUpdateVO modelUpdateVO) { + public CommonResult updateModel(ModelVO modelVO) { try { - Model model = repositoryService.getModel(modelUpdateVO.getId()); + Model model = repositoryService.getModel(modelVO.getId()); if (ObjectUtils.isEmpty(model)) { throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); } // 只能修改名字跟描述 - ModelCreateVO modelCreateVO = JsonUtils.parseObject(model.getMetaInfo(), ModelCreateVO.class); + ModelVO modelCreateVO = JsonUtils.parseObject(model.getMetaInfo(), ModelVO.class); if (ObjectUtils.isEmpty(modelCreateVO)) { - modelCreateVO = new ModelCreateVO(); + modelCreateVO = new ModelVO(); } - modelCreateVO.setName(modelUpdateVO.getName()); - modelCreateVO.setDescription(modelUpdateVO.getDescription()); + modelCreateVO.setName(modelVO.getName()); + modelCreateVO.setDescription(modelVO.getDescription()); model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO)); - model.setName(modelUpdateVO.getName()); + model.setName(modelVO.getName()); + model.setKey(modelVO.getKey()); // 更新模型 repositoryService.saveModel(model); - repositoryService.addModelEditorSource(model.getId(), modelUpdateVO.getBpmnXml().getBytes(StandardCharsets.UTF_8)); + repositoryService.addModelEditorSource(model.getId(), modelVO.getBpmnXml().getBytes(StandardCharsets.UTF_8)); return CommonResult.success("保存成功"); }catch (Exception e){ - log.info("模型更新失败!modelUpdateVO = {} e = {} ", modelUpdateVO, ExceptionUtils.getStackTrace(e)); + log.info("模型更新失败!modelVO = {}", modelVO, e); throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); } } @Override public CommonResult deploy(String modelId) { - // 获取模型 - Model modelData = repositoryService.getModel(modelId); - if (ObjectUtils.isEmpty(modelData)) { - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); - } - byte[] bytes = repositoryService.getModelEditorSource(modelData.getId()); - if (bytes == null) { - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); - } try { + Model modelData = repositoryService.getModel(modelId); + if (ObjectUtils.isEmpty(modelData)) { + throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); + } + byte[] bytes = repositoryService.getModelEditorSource(modelData.getId()); + if (bytes == null) { + throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); + } // 将xml转换为流 ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); XMLInputFactory xif = XMLInputFactory.newInstance(); @@ -148,21 +142,21 @@ public class BpmModelServiceImpl implements BpmModelService { } @Override - public FileResp exportBpmnXml(String deploymentId) { - - // 查询流程定义 - ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult(); - if (ObjectUtils.isEmpty(pd)) { - throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_PROCESS_DEFINITION_NOT_EXISTS); + public FileResp exportBpmnXml(String modelId) { + try { + Model modelData = repositoryService.getModel(modelId); + if (ObjectUtils.isEmpty(modelData)) { + throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); + } + byte[] bytes = repositoryService.getModelEditorSource(modelData.getId()); + FileResp fileResp = new FileResp(); + fileResp.setFileName(String.format("%s.bpmn", Optional.ofNullable(modelData.getName()).orElse("流程图"))); + fileResp.setFileByte(bytes); + return fileResp; + } catch (Exception e) { + log.info("模型部署失败!modelId = {} e = {} ", modelId, ExceptionUtils.getStackTrace(e)); + throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); } - String resourceName = Optional.ofNullable(pd.getDiagramResourceName()).orElse(pd.getResourceName()); - InputStream inputStream = repositoryService.getResourceAsStream(deploymentId, - resourceName); - FileResp fileResp = new FileResp(); - - fileResp.setFileName(String.format("%s.bpmn", Optional.ofNullable(pd.getName()).orElse("流程图"))); - fileResp.setFileByte(IoUtil.readBytes(inputStream)); - return fileResp; } @Override diff --git a/yudao-admin-ui/src/api/bpm/model.js b/yudao-admin-ui/src/api/bpm/model.js index 46b886a8c..461bf38ba 100644 --- a/yudao-admin-ui/src/api/bpm/model.js +++ b/yudao-admin-ui/src/api/bpm/model.js @@ -8,3 +8,41 @@ export function page(query) { params: query }) } +export function exportBpmnXml(query) { + return request({ + url: '/workflow/models/exportBpmnXml', + method: 'get', + params: query + }) +} + +export function modelUpdate(data) { + return request({ + url: '/workflow/models/update', + method: 'POST', + data: data + }) +} + +export function modelSave(data) { + return request({ + url: '/workflow/models/create', + method: 'POST', + data: data + }) +} + +export function modelDelete(data) { + return request({ + url: '/workflow/models/delete?modelId='+ data.modelId, + method: 'POST', + data: data + }) +} +export function modelDeploy(data) { + return request({ + url: '/workflow/models/deploy?modelId='+ data.modelId, + method: 'POST', + data: data + }) +} diff --git a/yudao-admin-ui/src/components/bpmn/Header.vue b/yudao-admin-ui/src/components/bpmn/Header.vue index d33e76d3c..ee35ffd88 100644 --- a/yudao-admin-ui/src/components/bpmn/Header.vue +++ b/yudao-admin-ui/src/components/bpmn/Header.vue @@ -2,10 +2,7 @@
- 保存并发布 - - - 保存草稿 + 保存 @@ -32,10 +29,13 @@ - + + +
+
@@ -74,15 +74,15 @@ } _svg = svg; }) - that.post(this.Apis.deployProcess, { - processKey: "s1111", - processName: "阿达达", - resourceName: "test01", - xml: _xml, - svg: _svg - }, function (data) { - console.log(data) - }); + // that.post(this.Apis.deployProcess, { + // processKey: "s1111", + // processName: "阿达达", + // resourceName: "test01", + // xml: _xml, + // svg: _svg + // }, function (data) { + // console.log(data) + // }); }, save(){ let that = this; @@ -129,11 +129,24 @@ let newScale = !val ? 1.0 : ((this.scale + val) <= 0.2) ? 0.2 : (this.scale + val); this.modeler.get('canvas').zoom(newScale); this.scale = newScale; + }, + beforeClose(val) { + this.$emit("beforeClose"); } } } diff --git a/yudao-admin-ui/src/components/bpmn/VueBpmn.vue b/yudao-admin-ui/src/components/bpmn/VueBpmn.vue index 523b93a81..a0860c17c 100644 --- a/yudao-admin-ui/src/components/bpmn/VueBpmn.vue +++ b/yudao-admin-ui/src/components/bpmn/VueBpmn.vue @@ -4,7 +4,7 @@ + @handleExportSvg="handleExportSvg" @handleExportBpmn="handleExportBpmn" @processSave="processSave" @beforeClose="beforeClose"> @@ -61,6 +61,7 @@ }, props: { product: String, + bpmnData: Object, bpmnXml: { type: String, required: false @@ -80,8 +81,13 @@ mounted() { let processId = new Date().getTime(); this.initTemplate = templateXml.initTemplate(processId) - this.initData = {key: "process" + processId, name: "流程" + processId, xml: this.initTemplate} - if (this.bpmnXml != null) { + + this.initData = { + key: this.bpmnData.key ? this.bpmnData.key : "process" + processId, + name: this.bpmnData.name ? this.bpmnData.name : "流程" + processId, + description: this.bpmnData.metaInfo ? JSON.parse(this.bpmnData.metaInfo).description : "" , + xml: this.initTemplate} + if (this.bpmnXml != null && this.bpmnXml !== "") { this.initTemplate = this.bpmnXml } this.init(); @@ -205,14 +211,21 @@ }, processSave(data){ let initData = this.initData; - data.procId = initData.key; - data.name = initData.name; - this.$emit("processSave",data); + const dataXml = this.bpmnData + dataXml.bpmnXml = this.xmlShow; + dataXml.name = initData.name; + dataXml.key = initData.key; + dataXml.description = initData.description; + this.$emit("processSave",dataXml); }, restart() { let processId = new Date().getTime(); this.initTemplate = templateXml.initTemplate(processId) - this.initData = {key: "process" + processId, name: "流程" + processId, xml: this.initTemplate} + this.initData = { + key: this.bpmnData.key ? this.bpmnData.key : "process" + processId, + name: this.bpmnData.name ? this.bpmnData.name : "流程" + processId, + description: this.bpmnData.metaInfo ? JSON.parse(this.bpmnData.metaInfo).description : "" , + xml: this.initTemplate} this.initDiagram(this.initTemplate) }, importXml() { @@ -244,6 +257,9 @@ } } return moddleExtensions; + }, + beforeClose() { + this.$emit("beforeClose"); } } } diff --git a/yudao-admin-ui/src/views/bpm/model/index.vue b/yudao-admin-ui/src/views/bpm/model/index.vue index d62605234..2540b4f1c 100644 --- a/yudao-admin-ui/src/views/bpm/model/index.vue +++ b/yudao-admin-ui/src/views/bpm/model/index.vue @@ -10,17 +10,18 @@ 重置 - - 导出 - 新建 + 新建流程 - @@ -33,18 +34,30 @@ {{ JSON.parse(scope.row.metaInfo).description }} + + + + + + - - + +