计划从flowable–ui-admin包下源码入手,分析flowable框架操作sql表情况。然后再看flowable-engine包下源码,最后根据理解设计出自己的工作流后台。
修改配置类 “flowable-default.properties” 文件
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/project_flowable?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root
启动admin后台
运行package org.flowable.ui.application
启动类FlowableUiApplication.java
1. Model类
UI应用,使用 Model类来存储BPM流程图、表单、流程应用。
创建BPM的XML流程图、表单、流程应用。都会创建到 act_de_model 表中
代码通过常量定义model的类型
public static final int MODEL_TYPE_BPMN = 0;
public static final int MODEL_TYPE_FORM = 2;
public static final int MODEL_TYPE_APP = 3;
public static final int MODEL_TYPE_DECISION_TABLE = 4;
public static final int MODEL_TYPE_CMMN = 5;
public static final int MODEL_TYPE_DECISION_SERVICE = 6;
持久化业务代码逻辑
protected Model persistModel(Model model) {
if (StringUtils.isNotEmpty(model.getModelEditorJson())) {
// Parse json to java
ObjectNode jsonNode = null;
try {
jsonNode = (ObjectNode) objectMapper.readTree(model.getModelEditorJson());
} catch (Exception e) {
LOGGER.error("Could not deserialize json model", e);
throw new InternalServerErrorException("Could not deserialize json model");
}
// 1.BPM流程图持久化方案
if ((model.getModelType() == null || model.getModelType().intValue() == Model.MODEL_TYPE_BPMN)) {
// Thumbnail
byte[] thumbnail = modelImageService.generateThumbnailImage(model, jsonNode);
if (thumbnail != null) {
model.setThumbnail(thumbnail);
}
modelRepository.save(model);
// Relations
handleBpmnProcessFormModelRelations(model, jsonNode);
handleBpmnProcessDecisionTaskModelRelations(model, jsonNode);
}
// 2.表单持久化方案
else if (model.getModelType().intValue() == Model.MODEL_TYPE_FORM ||
model.getModelType().intValue() == Model.MODEL_TYPE_DECISION_TABLE) {
jsonNode.put("name", model.getName());
jsonNode.put("key", model.getKey());
modelRepository.save(model);
} else if (model.getModelType().intValue() == Model.MODEL_TYPE_APP) {
modelRepository.save(model);
handleAppModelProcessRelations(model, jsonNode);
}
}
return model;
}
2. 创建BPM流程图
2.1 接口
/**
* 创建BPM流程模型
*
* @param modelRepresentation
* @return
*/
@PostMapping(value = "/rest/models", produces = "application/json")
public ModelRepresentation createModel(@RequestBody ModelRepresentation modelRepresentation) {
modelRepresentation.setKey(modelRepresentation.getKey().replaceAll(" ", ""));
checkForDuplicateKey(modelRepresentation);
String json = modelService.createModelJson(modelRepresentation);
Model newModel = modelService.createModel(modelRepresentation, json, SecurityUtils.getCurrentUserId());
return new ModelRepresentation(newModel);
}
2.2 BPM模型实体类封装。
@Override
public Model createModel(ModelRepresentation model, String editorJson, String createdBy) {
Model newModel = new Model();
newModel.setVersion(1);
newModel.setName(model.getName());
newModel.setKey(model.getKey());
newModel.setModelType(model.getModelType());
newModel.setCreated(Calendar.getInstance().getTime());
newModel.setCreatedBy(createdBy);
newModel.setDescription(model.getDescription());
newModel.setModelEditorJson(editorJson);
newModel.setLastUpdated(Calendar.getInstance().getTime());
newModel.setLastUpdatedBy(createdBy);
newModel.setTenantId(model.getTenantId());
//持久化
persistModel(newModel);
return newModel;
}
2.3 BPM持久化方案
// 1.BPM流程图持久化方案
if ((model.getModelType() == null || model.getModelType().intValue() == Model.MODEL_TYPE_BPMN)) {
// 生成缩略图
byte[] thumbnail = modelImageService.generateThumbnailImage(model, jsonNode);
if (thumbnail != null) {
model.setThumbnail(thumbnail);
}
// 入库持久化
modelRepository.save(model);
// Relations
handleBpmnProcessFormModelRelations(model, jsonNode);
handleBpmnProcessDecisionTaskModelRelations(model, jsonNode);
}