构建model

This commit is contained in:
jinqiming 2020-12-04 19:00:09 +08:00
parent c707c9c62a
commit 5cdbbf4550
4 changed files with 106 additions and 22 deletions

View File

@ -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);
}
}

View File

@ -59,6 +59,8 @@
<script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('system:model:edit')}]];
var removeFlag = [[${@permission.hasPermi('system:model:remove')}]];
var deploymentFlag = [[${@permission.hasPermi('system:model:deployment')}]];
var exportXmlFlag = [[${@permission.hasPermi('system:model:exportXml')}]];
var flowModelTypes = [[${@dict.getType('flow_model_type')}]];
var prefix = ctx + "system/model";
@ -83,7 +85,10 @@
},
{
field: 'name',
title: '模型名称'
title: '模型名称',
formatter: function(value, row, index) {
return '<a class="success" href="../system/model/showXml/' + row.id + '" target="_blank">'+value+'</a> ';
}
},
{
field: 'version',
@ -120,7 +125,8 @@
formatter: function(value, row, index) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.parentDetail(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑模型</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.deployment(\'' + row.id + '\')"><i class="fa fa-dashboard"></i>发布</a> ');
actions.push('<a class="btn btn-warning btn-xs ' + deploymentFlag + '" href="javascript:void(0)" onclick="$.operate.deployment(\'' + row.id + '\')"><i class="fa fa-dashboard"></i>发布</a> ');
actions.push('<a class="btn btn-info btn-xs ' + exportXmlFlag + '" href="javascript:void(0)" onclick="getXmlUrl(\'' + row.id + '\')"><i class="fa fa-expand"></i>导出</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
return actions.join('');
}
@ -128,6 +134,10 @@
};
$.table.init(options);
});
//导出
function getXmlUrl(id) {
window.location.href =prefix+'/exportXml/'+id;
}
</script>
</body>
</html>

View File

@ -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

View File

@ -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文件失败,流程为nullmodelId={}", 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文件失败,流程为nullmodelId={}", modelId);
}
} catch (Exception e) {
log.error("获取model的xml文件失败modelId={}", modelId, e);
}
}
@Override
public PageModel<DeploymentVO> getDeploymentList(DeploymentQueryDTO deploymentQueryDTO) {