From fe4dd2ce57bc66b9e6195a0d3eabb3c73c56842a Mon Sep 17 00:00:00 2001 From: smallchill Date: Thu, 18 Apr 2019 23:27:14 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E6=B5=81=E7=A8=8B=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../engine/constant/FlowableConstant.java | 5 ++- .../controller/FlowManagerController.java | 25 ++++++++++---- .../flowable/engine/service/FlowService.java | 10 +++++- .../engine/service/impl/FlowServiceImpl.java | 34 +++++++++---------- doc/sql/bladex-update-RC9.sql | 2 +- 5 files changed, 49 insertions(+), 27 deletions(-) diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/constant/FlowableConstant.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/constant/FlowableConstant.java index 85bd6b93..56fcd6f8 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/constant/FlowableConstant.java +++ b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/constant/FlowableConstant.java @@ -25,7 +25,10 @@ public interface FlowableConstant { String FLOWABLE_BASE_PACKAGES = "org.flowable.ui"; - String suffix = ".bpmn20.xml"; + String SUFFIX = ".bpmn20.xml"; + String ACTIVE = "active"; + + String SUSPEND = "suspend"; } diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/controller/FlowManagerController.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/controller/FlowManagerController.java index 2cf31ee1..63f0f300 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/controller/FlowManagerController.java +++ b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/controller/FlowManagerController.java @@ -26,9 +26,7 @@ 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 org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.InputStream; @@ -48,13 +46,26 @@ public class FlowManagerController { /** * 分页 */ - @GetMapping("/list") - @ApiOperation(value = "分页", notes = "传入notice", position = 1) + @GetMapping("list") + @ApiOperation(value = "分页", notes = "传入流程类型", position = 1) public R> list(@ApiParam("流程类型") String category, Query query) { IPage pages = flowService.selectManagerPage(Condition.getPage(query), category); return R.data(pages); } + /** + * 变更流程状态 + * + * @param state 状态 + * @param processId 流程id + */ + @PostMapping("changeState") + @ApiOperation(value = "变更流程状态", notes = "传入state,processId", position = 2) + public R changeState(@RequestParam String state, @RequestParam String processId) { + String msg = flowService.changeState(state, processId); + return R.success(msg); + } + /** * 资源展示 * @@ -63,8 +74,8 @@ public class FlowManagerController { * @param resourceType 资源类型 * @param response 响应 */ - @GetMapping("/resource") - @ApiOperation(value = "分页", notes = "传入notice", position = 2) + @GetMapping("resource") + @ApiOperation(value = "资源展示", notes = "传入processId,instanceId,resourceType", position = 3) 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]; diff --git a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/FlowService.java b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/FlowService.java index bac08497..a2fbe458 100644 --- a/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/FlowService.java +++ b/blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/FlowService.java @@ -48,11 +48,19 @@ public interface FlowService extends IService { */ IPage selectManagerPage(IPage page, String category); + /** + * 变更流程状态 + * + * @param state 状态 + * @param processId 流程ID + * @return + */ + String changeState(String state, String processId); /** * 资源展示 * - * @param processId 流程定义ID + * @param processId 流程ID * @param instanceId 流程实例ID * @param resourceType 资源类型(xml|image) * @return 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 3540d819..6e63d77f 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 @@ -94,6 +94,19 @@ public class FlowServiceImpl extends ServiceImpl implemen return page; } + @Override + public String changeState(String state, String processId) { + if (state.equals(FlowableConstant.ACTIVE)) { + repositoryService.activateProcessDefinitionById(processId, true, null); + return StringUtil.format("激活ID为 [{}] 的流程成功", processId); + } else if (state.equals(FlowableConstant.SUSPEND)) { + repositoryService.suspendProcessDefinitionById(processId, true, null); + return StringUtil.format("挂起ID为 [{}] 的流程成功", processId); + } else { + return "暂无流程变更"; + } + } + @Override public InputStream resource(String processId, String instanceId, String resourceType) { if (StringUtils.isBlank(processId)) { @@ -112,30 +125,18 @@ public class FlowServiceImpl extends ServiceImpl implemen @Override public boolean deploy(String modelId, String category) { - FlowModel model = this.getById(modelId); - if (model == null) { throw new ServiceException("No model found with the given id: " + modelId); } - byte[] bytes = getBpmnXML(model); - String processName = model.getName(); - if (!StringUtil.endsWithIgnoreCase(processName, FlowableConstant.suffix)) { - processName += FlowableConstant.suffix; + if (!StringUtil.endsWithIgnoreCase(processName, FlowableConstant.SUFFIX)) { + processName += FlowableConstant.SUFFIX; } - - Deployment deployment = repositoryService.createDeployment() - .addBytes(processName, bytes) - .name(model.getName()) - .key(model.getModelKey()) - .deploy(); - + Deployment deployment = repositoryService.createDeployment().addBytes(processName, bytes).name(model.getName()).key(model.getModelKey()).deploy(); log.debug("流程部署--------deploy:" + deployment + " 分类---------->" + category); - List list = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list(); - StringBuilder logBuilder = new StringBuilder(500); List logArgs = new ArrayList<>(); // 设置流程分类 @@ -146,7 +147,6 @@ public class FlowServiceImpl extends ServiceImpl implemen logBuilder.append("部署成功,流程ID={} \n"); logArgs.add(processDefinition.getId()); } - if (list.size() == 0) { throw new ServiceException("部署失败,未找到流程"); } else { @@ -176,7 +176,7 @@ public class FlowServiceImpl extends ServiceImpl implemen } private BpmnModel getBpmnModel(FlowModel model) { - BpmnModel bpmnModel = null; + BpmnModel bpmnModel; try { Map formMap = new HashMap<>(16); Map decisionTableMap = new HashMap<>(16); diff --git a/doc/sql/bladex-update-RC9.sql b/doc/sql/bladex-update-RC9.sql index 2378a150..73fd7ca4 100644 --- a/doc/sql/bladex-update-RC9.sql +++ b/doc/sql/bladex-update-RC9.sql @@ -28,7 +28,7 @@ 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_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_manager_pause', '暂停', 'pause', '', 'plus', 2, 2, 2, 1, NULL, 0); +VALUES (@managerid, 'flow_manager_state', '变更状态', 'state', '', '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);