工作流Flowable实战 (二)流程模型管理


一、模型列表

在这里插入图片描述
flowable模型数据存储在act_de_model表中,这里需要查model_type=0的数据

二、新增编辑

新增页面跳转到 /components/flow/designer/index.html#/processes
修改页面跳转到 /components/flow/designer/index.html#/editor/ + 模型id;
后端需要重写设计器登录接口:

import org.flowable.ui.common.model.UserRepresentation;
import org.flowable.ui.common.security.DefaultPrivileges;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/app")
public class AccountResource {
	@RequestMapping(value = "/rest/account", method = RequestMethod.GET, produces = "application/json")
	public UserRepresentation getAccount() {
		UserRepresentation userRepresentation = new UserRepresentation();
		userRepresentation.setFirstName("admin");
		userRepresentation.setLastName("admin");
		userRepresentation.setFullName("admin");
		userRepresentation.setId("admin");
		List<String> pris = new ArrayList<>();
		pris.add(DefaultPrivileges.ACCESS_MODELER);
		pris.add(DefaultPrivileges.ACCESS_IDM);
		pris.add(DefaultPrivileges.ACCESS_ADMIN);
		pris.add(DefaultPrivileges.ACCESS_TASK);
		pris.add(DefaultPrivileges.ACCESS_REST_API);
		userRepresentation.setPrivileges(pris);
		return userRepresentation;
	}
}

新增页面跳转到了设计器的模型列表页面,在此页面点击创建流程即可;
在这里插入图片描述
在这里插入图片描述

三、删除和部署

1.删除

删除则直接根据模型id删除数据即可

2.部署

private static final BpmnXMLConverter BPMN_XML_CONVERTER = new BpmnXMLConverter();

public boolean deployModel(String modelId, String category, List<String> tenantIdList) {
	FlowModel model = this.getById(modelId);
	byte[] bytes = getBpmnXML(model);
	String processName = model.getName();
	if (!StringUtil.endsWithIgnoreCase(processName, FlowEngineConstant.SUFFIX)) {
		processName += FlowEngineConstant.SUFFIX;
	}
	String finalProcessName = processName;
	if (Func.isNotEmpty(tenantIdList)) {
		tenantIdList.forEach(tenantId -> {
			Deployment deployment = repositoryService.createDeployment().addBytes(finalProcessName, bytes).name(model.getName()).key(model.getModelKey()).tenantId(tenantId).deploy();
			deploy(deployment, category);
		});
	} else {
		Deployment deployment = repositoryService.createDeployment().addBytes(finalProcessName, bytes).name(model.getName()).key(model.getModelKey()).deploy();
		deploy(deployment, category);
	}
	return true;
}

private boolean deploy(Deployment deployment, String category) {
	List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list();
	// 设置流程分类
	for (ProcessDefinition processDefinition : list) {
		if (StringUtil.isNotBlank(category)) {
			repositoryService.setProcessDefinitionCategory(processDefinition.getId(), category);
		}
	}
	if (list.size() == 0) {
		throw new ServiceException("部署失败,未找到流程");
	} else {
		return true;
	}
}

private byte[] getBpmnXML(FlowModel model) {
	BpmnModel bpmnModel = getBpmnModel(model);
	return getBpmnXML(bpmnModel);
}

private byte[] getBpmnXML(BpmnModel bpmnModel) {
	for (Process process : bpmnModel.getProcesses()) {
		if (StringUtils.isNotEmpty(process.getId())) {
			char firstCharacter = process.getId().charAt(0);
			if (Character.isDigit(firstCharacter)) {
				process.setId("a" + process.getId());
			}
		}
	}
	return BPMN_XML_CONVERTER.convertToXML(bpmnModel);
}
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值