diff --git a/blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/controller/ProcessController.java b/blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/controller/ProcessController.java index a9ea3a16..383659e3 100644 --- a/blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/controller/ProcessController.java +++ b/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); + } } } diff --git a/blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/filter/UserHandlerInterceptor.java b/blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/filter/UserHandlerInterceptor.java index 18273dd2..8188a019 100644 --- a/blade-ops/blade-flowdesign/src/main/java/org/springblade/flowable/filter/UserHandlerInterceptor.java +++ b/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"); diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/FlowableConfiguration.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/FlowableConfiguration.java index fa453234..baeb2dd3 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/config/FlowableConfiguration.java +++ b/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 { */ IPage selectManagerPage(IPage page, String category); + + /** + * 资源展示 + * + * @param processId 流程定义ID + * @param instanceId 流程实例ID + * @param resourceType 资源类型(xml|image) + * @return + */ + InputStream resource(String processId, String instanceId, String resourceType); + /** * 部署流程 * diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java index 2325956a..3540d819 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java +++ b/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 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 selectFlowPage(IPage page, FlowModel flowModel) { @@ -69,16 +75,12 @@ public class FlowServiceImpl extends ServiceImpl implemen @Override public IPage selectManagerPage(IPage 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 processDefinitionList = processDefinitionQuery.listPage(Func.toInt(page.getCurrent() - 1), Func.toInt(page.getSize())); - List flowProcessList = new ArrayList<>(); for (ProcessDefinition processDefinition : processDefinitionList) { String deploymentId = processDefinition.getDeploymentId(); @@ -92,6 +94,22 @@ public class FlowServiceImpl extends ServiceImpl 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) { diff --git a/doc/sql/bladex-update-RC9.sql b/doc/sql/bladex-update-RC9.sql index 0d550d51..2378a150 100644 --- a/doc/sql/bladex-update-RC9.sql +++ b/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);