Browse Source

流程管理流程图查看功能

test
smallchill 6 years ago
parent
commit
f77abd3dc7
  1. 60
      blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/controller/ProcessController.java
  2. 1
      blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/filter/UserHandlerInterceptor.java
  3. 10
      blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/FlowableConfiguration.java
  4. 23
      blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/controller/FlowManagerController.java
  5. 13
      blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/FlowService.java
  6. 30
      blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java
  7. 10
      doc/sql/bladex-update-RC9.sql

60
blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/controller/ProcessController.java

@ -1,12 +1,18 @@
package org.springblade.flowable.controller;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.DeploymentBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
/**
* 流程部署
@ -15,23 +21,43 @@ import org.springframework.web.bind.annotation.ResponseBody;
*/
@Controller
@RequestMapping("/process")
@AllArgsConstructor
public class ProcessController {
@Autowired
RepositoryService repositoryService;
@RequestMapping(value = "/deploy")
@ResponseBody
public Object deploy() {
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment()
.category("dataobject")
.key("dataobject")
.name("dataobject")
.addClasspathResource("dataobject.bpmn20.xml");
Deployment deploy = deploymentBuilder.deploy();
private static final String IMAGE_NAME = "image";
private static final String XML_NAME = "xml";
private static final Integer INT_1024 = 1024;
System.out.println("请假流程部署,流程ID: " + deploy.getId());
private RepositoryService repositoryService;
private RuntimeService runtimeService;
return deploy;
/**
* 资源展示
*
* @param processId 流程id
* @param instanceId 实例id
* @param resourceType 资源类型
* @param response 响应
*/
@GetMapping("resource")
public void resource(@RequestParam String processId, String instanceId, @RequestParam(defaultValue = IMAGE_NAME) String resourceType, HttpServletResponse response) throws Exception {
if (StringUtils.isBlank(processId)) {
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(instanceId).singleResult();
processId = processInstance.getProcessDefinitionId();
}
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processId).singleResult();
String resourceName = "";
if (resourceType.equals(IMAGE_NAME)) {
resourceName = processDefinition.getDiagramResourceName();
} else if (resourceType.equals(XML_NAME)) {
resourceName = processDefinition.getResourceName();
}
InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
byte[] b = new byte[1024];
int len;
while ((len = resourceAsStream.read(b, 0, INT_1024)) != -1) {
response.getOutputStream().write(b, 0, len);
}
}
}

1
blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/filter/UserHandlerInterceptor.java

@ -42,7 +42,6 @@ public class UserHandlerInterceptor implements HandlerInterceptor {
if (servletPath.endsWith(css) || servletPath.endsWith(js) || servletPath.endsWith(jpg) || servletPath.endsWith(png)) {
return true;
}
System.out.println(servletPath);
if (servletPath.startsWith(app)) {
User user = new UserEntityImpl();
user.setId("admin");

10
blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/FlowableConfiguration.java

@ -20,7 +20,9 @@ import lombok.AllArgsConstructor;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.flowable.spring.boot.FlowableProperties;
import org.springblade.core.secure.registry.SecureRegistry;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
@ -40,4 +42,12 @@ public class FlowableConfiguration implements EngineConfigurationConfigurer<Spri
engineConfiguration.setLabelFontName(flowableProperties.getLabelFontName());
engineConfiguration.setAnnotationFontName(flowableProperties.getAnnotationFontName());
}
@Bean
public SecureRegistry secureRegistry() {
SecureRegistry secureRegistry = new SecureRegistry();
secureRegistry.excludePathPatterns("/manager/resource");
return secureRegistry;
}
}

23
blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/controller/FlowManagerController.java

@ -23,12 +23,16 @@ import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.IntegerPool;
import org.springblade.flowable.engine.entity.FlowProcess;
import org.springblade.flowable.engine.service.FlowService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
/**
* 流程管理接口
*
@ -51,4 +55,23 @@ public class FlowManagerController {
return R.data(pages);
}
/**
* 资源展示
*
* @param processId 流程id
* @param instanceId 实例id
* @param resourceType 资源类型
* @param response 响应
*/
@GetMapping("/resource")
@ApiOperation(value = "分页", notes = "传入notice", position = 2)
public void resource(String processId, String instanceId, String resourceType, HttpServletResponse response) throws Exception {
InputStream resourceAsStream = flowService.resource(processId, instanceId, resourceType);
byte[] b = new byte[1024];
int len;
while ((len = resourceAsStream.read(b, 0, IntegerPool.INT_1024)) != -1) {
response.getOutputStream().write(b, 0, len);
}
}
}

13
blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/FlowService.java

@ -21,6 +21,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.flowable.engine.entity.FlowModel;
import org.springblade.flowable.engine.entity.FlowProcess;
import java.io.InputStream;
/**
* FlowService
*
@ -46,6 +48,17 @@ public interface FlowService extends IService<FlowModel> {
*/
IPage<FlowProcess> selectManagerPage(IPage<FlowProcess> page, String category);
/**
* 资源展示
*
* @param processId 流程定义ID
* @param instanceId 流程实例ID
* @param resourceType 资源类型(xml|image)
* @return
*/
InputStream resource(String processId, String instanceId, String resourceType);
/**
* 部署流程
*

30
blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java

@ -28,12 +28,15 @@ import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.Process;
import org.flowable.editor.language.json.converter.BpmnJsonConverter;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntityImpl;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.repository.ProcessDefinitionQuery;
import org.flowable.engine.runtime.ProcessInstance;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.flowable.engine.constant.FlowableConstant;
import org.springblade.flowable.engine.entity.FlowModel;
@ -42,6 +45,7 @@ import org.springblade.flowable.engine.mapper.FlowMapper;
import org.springblade.flowable.engine.service.FlowService;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -56,11 +60,13 @@ import java.util.Map;
@Service
@AllArgsConstructor
public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implements FlowService {
private static final String IMAGE_NAME = "image";
private static final String XML_NAME = "xml";
private static BpmnJsonConverter bpmnJsonConverter = new BpmnJsonConverter();
private static BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
private ObjectMapper objectMapper;
private RepositoryService repositoryService;
private RuntimeService runtimeService;
@Override
public IPage<FlowModel> selectFlowPage(IPage<FlowModel> page, FlowModel flowModel) {
@ -69,16 +75,12 @@ public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implemen
@Override
public IPage<FlowProcess> selectManagerPage(IPage<FlowProcess> page, String category) {
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().latestVersion().orderByProcessDefinitionKey().asc();
if (StringUtils.isNotEmpty(category)){
if (StringUtils.isNotEmpty(category)) {
processDefinitionQuery.processDefinitionCategory(category);
}
page.setTotal(processDefinitionQuery.count());
List<ProcessDefinition> processDefinitionList = processDefinitionQuery.listPage(Func.toInt(page.getCurrent() - 1), Func.toInt(page.getSize()));
List<FlowProcess> flowProcessList = new ArrayList<>();
for (ProcessDefinition processDefinition : processDefinitionList) {
String deploymentId = processDefinition.getDeploymentId();
@ -92,6 +94,22 @@ public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implemen
return page;
}
@Override
public InputStream resource(String processId, String instanceId, String resourceType) {
if (StringUtils.isBlank(processId)) {
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(instanceId).singleResult();
processId = processInstance.getProcessDefinitionId();
}
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processId).singleResult();
String resourceName = StringPool.EMPTY;
if (resourceType.equals(IMAGE_NAME)) {
resourceName = processDefinition.getDiagramResourceName();
} else if (resourceType.equals(XML_NAME)) {
resourceName = processDefinition.getResourceName();
}
return repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
}
@Override
public boolean deploy(String modelId, String category) {

10
doc/sql/bladex-update-RC9.sql

@ -9,9 +9,9 @@ INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`,
VALUES (@flowid, 'flow_model', '模型管理', 'menu', '/flow/model', NULL, 1, 1, 0, 1, NULL, 0);
set @modelid = (SELECT LAST_INSERT_ID());
INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
VALUES (@modelid, 'flow_model_create', '新增', 'create', 'http://localhost:9999/index.html', 'plus', 1, 2, 1, 1, NULL, 0);
VALUES (@modelid, 'flow_model_create', '创建', 'create', 'http://localhost:9999/index.html', 'plus', 1, 2, 1, 1, NULL, 0);
INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
VALUES (@modelid, 'flow_model_update', '修改', 'update', 'http://localhost:9999/index.html#/editor', 'form', 2, 2, 2, 1, NULL, 0);
VALUES (@modelid, 'flow_model_update', '编辑', 'update', 'http://localhost:9999/index.html#/editor', 'form', 2, 2, 2, 1, NULL, 0);
INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
VALUES (@modelid, 'flow_model_deploy', '部署', 'deploy', '', 'cloud-upload', 3, 2, 2, 1, NULL, 0);
INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
@ -26,9 +26,11 @@ INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`,
VALUES (@flowid, 'flow_manager', '流程管理', 'menu', '/flow/manager', NULL, 3, 1, 0, 1, NULL, 0);
set @managerid = (SELECT LAST_INSERT_ID());
INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
VALUES (@managerid, 'flow_manager_pause', '暂停', 'pause', '', 'plus', 1, 2, 3, 1, NULL, 0);
VALUES (@managerid, 'flow_manager_image', '流程图', 'image', 'http://localhost:9999/index.html#/processes', 'image', 1, 2, 2, 1, NULL, 0);
INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
VALUES (@managerid, 'flow_model_delete', '删除', 'delete', '', 'delete', 2, 2, 3, 1, NULL, 0);
VALUES (@managerid, 'flow_manager_pause', '暂停', 'pause', '', 'plus', 2, 2, 2, 1, NULL, 0);
INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
VALUES (@managerid, 'flow_model_delete', '删除', 'delete', '', 'delete', 3, 2, 3, 1, NULL, 0);
INSERT INTO `blade_menu`(`parent_id`, `code`, `name`, `alias`, `path`, `source`, `sort`, `category`, `action`, `is_open`, `remark`, `is_deleted`)
VALUES (@flowid, 'flow_status', '流程状态', 'menu', '/flow/status', NULL, 4, 1, 0, 1, NULL, 0);

Loading…
Cancel
Save