一、模型列表
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);
}