Browse Source

流程状态变更功能

test
smallchill 6 years ago
parent
commit
fe4dd2ce57
  1. 5
      blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/constant/FlowableConstant.java
  2. 25
      blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/controller/FlowManagerController.java
  3. 10
      blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/FlowService.java
  4. 34
      blade-service/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java
  5. 2
      doc/sql/bladex-update-RC9.sql

5
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";
}

25
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<IPage<FlowProcess>> list(@ApiParam("流程类型") String category, Query query) {
IPage<FlowProcess> 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];

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

@ -48,11 +48,19 @@ public interface FlowService extends IService<FlowModel> {
*/
IPage<FlowProcess> selectManagerPage(IPage<FlowProcess> 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

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

@ -94,6 +94,19 @@ public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> 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<FlowMapper, FlowModel> 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<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list();
StringBuilder logBuilder = new StringBuilder(500);
List<Object> logArgs = new ArrayList<>();
// 设置流程分类
@ -146,7 +147,6 @@ public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> 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<FlowMapper, FlowModel> implemen
}
private BpmnModel getBpmnModel(FlowModel model) {
BpmnModel bpmnModel = null;
BpmnModel bpmnModel;
try {
Map<String, FlowModel> formMap = new HashMap<>(16);
Map<String, FlowModel> decisionTableMap = new HashMap<>(16);

2
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);

Loading…
Cancel
Save