From 5cdbbf4550045ac7313117e3723c9c01a0dc60f4 Mon Sep 17 00:00:00 2001 From: jinqiming <45981669@qq.com> Date: Fri, 4 Dec 2020 19:00:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=84=E5=BB=BAmodel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flowable/ActDeModelController.java | 56 ++++++++++++------- .../templates/system/model/model.html | 14 ++++- .../flowable/service/FlowableService.java | 15 +++++ .../service/impl/FlowableServiceImpl.java | 43 ++++++++++++++ 4 files changed, 106 insertions(+), 22 deletions(-) diff --git a/snow-admin/src/main/java/com/snow/web/controller/flowable/ActDeModelController.java b/snow-admin/src/main/java/com/snow/web/controller/flowable/ActDeModelController.java index cae2b45..f9e480f 100644 --- a/snow-admin/src/main/java/com/snow/web/controller/flowable/ActDeModelController.java +++ b/snow-admin/src/main/java/com/snow/web/controller/flowable/ActDeModelController.java @@ -1,30 +1,26 @@ package com.snow.web.controller.flowable; -import java.util.List; - +import com.snow.common.annotation.Log; +import com.snow.common.core.controller.BaseController; +import com.snow.common.core.domain.AjaxResult; +import com.snow.common.core.page.TableDataInfo; +import com.snow.common.enums.BusinessType; +import com.snow.common.utils.poi.ExcelUtil; import com.snow.flowable.service.impl.FlowablePublishServiceImpl; import com.snow.flowable.service.impl.FlowableServiceImpl; import com.snow.framework.util.ShiroUtils; -import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.flowable.engine.repository.Deployment; -import org.flowable.ui.modeler.domain.Model; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ui.ModelMap; -import org.springframework.util.CollectionUtils; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; -import com.snow.common.annotation.Log; -import com.snow.common.enums.BusinessType; -import org.springframework.stereotype.Controller; import com.snow.system.domain.ActDeModel; import com.snow.system.service.IActDeModelService; -import com.snow.common.core.controller.BaseController; -import com.snow.common.core.domain.AjaxResult; -import com.snow.common.utils.poi.ExcelUtil; -import com.snow.common.core.page.TableDataInfo; +import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.flowable.engine.repository.Deployment; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.util.CollectionUtils; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; /** * 设计器modelController @@ -167,4 +163,24 @@ public class ActDeModelController extends BaseController } return AjaxResult.success("发布成功"); } + + + /** + * 导出model的xml文件 + */ + @Log(title = "导出流程XML", businessType = BusinessType.EXPORT) + @RequiresPermissions("system:model:exportXml") + @GetMapping(value = "/exportXml/{modelId}") + public void exportXml(@PathVariable("modelId") String modelId, HttpServletResponse response) { + flowableService.exportModelXml(modelId,response); + } + + /** + * 展示model的xml文件 + */ + @RequiresPermissions("system:model:showXml") + @GetMapping(value = "/showXml/{modelId}") + public void showXml(@PathVariable("modelId") String modelId, HttpServletResponse response) { + flowableService.showModelXml(modelId,response); + } } diff --git a/snow-admin/src/main/resources/templates/system/model/model.html b/snow-admin/src/main/resources/templates/system/model/model.html index 3449059..52615a6 100644 --- a/snow-admin/src/main/resources/templates/system/model/model.html +++ b/snow-admin/src/main/resources/templates/system/model/model.html @@ -59,6 +59,8 @@ \ No newline at end of file diff --git a/snow-flowable/src/main/java/com/snow/flowable/service/FlowableService.java b/snow-flowable/src/main/java/com/snow/flowable/service/FlowableService.java index 7169290..3933f2f 100644 --- a/snow-flowable/src/main/java/com/snow/flowable/service/FlowableService.java +++ b/snow-flowable/src/main/java/com/snow/flowable/service/FlowableService.java @@ -9,6 +9,7 @@ import org.flowable.engine.runtime.ProcessInstance; import org.flowable.task.api.Task; import org.flowable.task.api.history.HistoricTaskInstance; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; @@ -31,6 +32,20 @@ public interface FlowableService { * @param modelId */ void deleteModel(String modelId); + + /** + * 导出XML + * @param modelId + * @param response + */ + void exportModelXml(String modelId, HttpServletResponse response); + + /** + * 展示XML + * @param modelId + * @param response + */ + void showModelXml(String modelId, HttpServletResponse response); /** * 查询发布列表(分页) * @param deploymentQueryDTO diff --git a/snow-flowable/src/main/java/com/snow/flowable/service/impl/FlowableServiceImpl.java b/snow-flowable/src/main/java/com/snow/flowable/service/impl/FlowableServiceImpl.java index 531ee2f..74cbb66 100644 --- a/snow-flowable/src/main/java/com/snow/flowable/service/impl/FlowableServiceImpl.java +++ b/snow-flowable/src/main/java/com/snow/flowable/service/impl/FlowableServiceImpl.java @@ -3,6 +3,7 @@ package com.snow.flowable.service.impl; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson.JSON; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.collect.Lists; @@ -20,10 +21,12 @@ import com.snow.system.service.ISysRoleService; import com.snow.system.service.impl.SysUserServiceImpl; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; +import org.flowable.bpmn.converter.BpmnXMLConverter; import org.flowable.bpmn.model.*; import org.flowable.bpmn.model.Process; import org.flowable.common.engine.impl.identity.Authentication; import org.flowable.common.engine.impl.util.IoUtil; +import org.flowable.editor.language.json.converter.BpmnJsonConverter; import org.flowable.engine.*; import org.flowable.engine.history.HistoricActivityInstance; import org.flowable.engine.history.HistoricProcessInstance; @@ -36,6 +39,7 @@ import org.flowable.task.api.Task; import org.flowable.task.api.TaskQuery; import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.task.api.history.HistoricTaskInstanceQuery; +import org.flowable.ui.modeler.domain.Model; import org.flowable.ui.modeler.repository.ModelRepository; import org.flowable.ui.modeler.service.ModelServiceImpl; import org.flowable.ui.modeler.serviceapi.ModelService; @@ -47,6 +51,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -138,6 +143,44 @@ public class FlowableServiceImpl implements FlowableService { } + @Override + public void exportModelXml(String modelId, HttpServletResponse response) { + try { + Model modelData = modelService.getModel(modelId); + BpmnModel bpmnModel = modelService.getBpmnModel(modelData); + // 流程非空判断 + if (!CollectionUtils.isEmpty(bpmnModel.getProcesses())) { + byte[] bpmnXML = modelService.getBpmnXML(modelData); + ByteArrayInputStream in = new ByteArrayInputStream(bpmnXML); + String filename = bpmnModel.getMainProcess().getId() + ".bpmn"; + response.setHeader("Content-Disposition", "attachment; filename=" + filename); + IOUtils.copy(in, response.getOutputStream()); + response.flushBuffer(); + }else { + log.warn("导出model的xml文件失败,流程为null:modelId={}", modelId); + } + } catch (Exception e) { + log.error("导出model的xml文件失败:modelId={}", modelId, e); + } + } + + @Override + public void showModelXml(String modelId, HttpServletResponse response) { + try { + Model modelData = modelService.getModel(modelId); + BpmnModel bpmnModel = modelService.getBpmnModel(modelData); + // 流程非空判断 + if (!CollectionUtils.isEmpty(bpmnModel.getProcesses())) { + byte[] bpmnXML = modelService.getBpmnXML(modelData); + response.setHeader("Content-type", "text/xml;charset=UTF-8"); + response.getOutputStream().write(bpmnXML); + }else { + log.warn("获取model的xml文件失败,流程为null:modelId={}", modelId); + } + } catch (Exception e) { + log.error("获取model的xml文件失败:modelId={}", modelId, e); + } + } @Override public PageModel getDeploymentList(DeploymentQueryDTO deploymentQueryDTO) {