文章目录
- 配置规则
- 部署
- 使用
项目地址:https://gitee.com/lwj/flowable.git 分支flowable-base
视频地址:https://www.bilibili.com/video/av79774697/
DMN部署: dmn制定了规则之后,还需要部署好才能用
DMN部署,独立使用
配置规则
这边只是做了一个简单的规则判断,实际业务场景可以设置的更加复杂
这里我们为了简单就是使用first的模式,返回一个数据
部署
public DmnDeployment deploy(DmnModelVo params) {DmnDeployment deployment = null;try {Model model = modelService.getModel(params.getModelId());//Model转化为jsonNode对象JsonNode editorJsonNode = objectMapper.readTree(model.getModelEditorJson());String fileName = URLEncoder.encode(model.getName(), "UTF-8").replaceAll("\\+", "%20") + ".dmn";//通过jsonNode转化成DmnDefinition对象DmnDefinition dmnDefinition = dmnJsonConverter.convertToDmn(editorJsonNode, model.getId(), 1, null);ExtendModel extendModel = extendModelService.getExtendModelByModelKey(model.getKey());//必须指定文件后缀名否则部署不成功deployment = dmnRepositoryService.createDeployment().name(fileName).tenantId(extendModel.getSystemSn()).addDmnModel(model.getKey() + ".dmn", dmnDefinition).category(extendModel.getCategoryCode()).deploy();//修改状态为已发布extendModel.setStatus(ModelFormStatusEnum.YFB.getStatus());extendModelService.updateExtendModel(extendModel);} catch (Exception e) {e.printStackTrace();logger.error("部署DMN失败", e);}return deployment;}
使用
Map<String, Object> result = dmnRuleService.createExecuteDecisionBuilder().decisionKey("decision1").variable("departmentCode", "100001").variable("money", "5000").executeWithSingleResult();
assertThat(result).contains(entry("applyer", "李四"));