更多ruoyi-nbcio功能请看演示系统
gitee源代码地址
前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio
演示地址:RuoYi-Nbcio后台管理系统
上一节把数据库与相关基础数据字典准备好,下面就来实现相应的功能,目前先针对自定义业务表单的规则。
1、前端部分
在流程模型的列表里增加配置,如下图
相应前端代码如下:
<el-buttontype="text"size="mini"icon="el-icon-setting"v-hasPermi="['workflow:model:config']"@click.native="handleConfig(scope.row)">配置</el-button>
下面的组件可以通过生成的流程配置代码修改,具体下一节再说。
<el-dialog :title="flowConfigData.title" :visible.sync="flowConfigOpen" append-to-body fullscreen><flow-config:key="flowConfigOpen"style="border:1px solid rgba(0, 0, 0, 0.1);"ref="flowConfig"v-loading="flowConfigData.loading":flowConfigData="flowConfigData"/></el-dialog>
/** 配置流程 */handleConfig(row) {this.loading = true;console.log("row=",row);getAppType(row.category).then(res => {console.log("res=",res);configModel(row.modelId,res.data[0].id).then(response => {this.$modal.msgSuccess(response.msg);this.flowConfigOpen = true;this.flowConfigData.modelId = row.modelId;console.log("response=",response);}).finally(() => {this.loading = false;})}).finally(() => {this.loading = false;})},
2、后端接口
@Override@Transactional(rollbackFor = Exception.class)public String configModel(String modelId, String appType) {// 获取流程模型Model model = repositoryService.getModel(modelId);if (ObjectUtil.isNull(model)) {throw new RuntimeException("流程模型不存在!");}// 获取流程图byte[] bpmnBytes = repositoryService.getModelEditorSource(modelId);if (ArrayUtil.isEmpty(bpmnBytes)) {throw new RuntimeException("请先设计流程图!");}String bpmnXml = StringUtils.toEncodedString(bpmnBytes, StandardCharsets.UTF_8);BpmnModel bpmnModel = ModelUtils.getBpmnModel(bpmnXml);String processName = model.getName();Process process = bpmnModel.getMainProcess();Collection<FlowElement> flowElements = process.getFlowElements();for (FlowElement flowElement : flowElements) {WfFlowConfigBo flowConfigBo = new WfFlowConfigBo();if (flowElement instanceof StartEvent) {StartEvent startEvent = (StartEvent)flowElement;WfFlowConfigVo flowConfigVo = new WfFlowConfigVo();flowConfigVo.setModelId(modelId);flowConfigVo.setNodeKey(startEvent.getId());if(ObjectUtils.isEmpty(flowConfigService.selectByModelIdAndNodeKey(flowConfigVo))) {flowConfigBo.setModelId(modelId);flowConfigBo.setAppType(appType);flowConfigBo.setFormKey(startEvent.getFormKey());flowConfigBo.setNodeName(startEvent.getName());flowConfigBo.setNodeKey(startEvent.getId());flowConfigService.insertByBo(flowConfigBo);}else {flowConfigVo.setAppType(appType);flowConfigVo.setFormKey(startEvent.getFormKey());flowConfigVo.setNodeName(startEvent.getName());flowConfigService.updateFlowConfig(flowConfigVo);}}if (flowElement instanceof UserTask) {UserTask userTask = (UserTask)flowElement;WfFlowConfigVo flowConfigVo = new WfFlowConfigVo();flowConfigVo.setModelId(modelId);flowConfigVo.setNodeKey(userTask.getId());if(ObjectUtils.isEmpty(flowConfigService.selectByModelIdAndNodeKey(flowConfigVo))) {flowConfigBo.setModelId(modelId);flowConfigBo.setAppType(appType);flowConfigBo.setFormKey(userTask.getFormKey());flowConfigBo.setNodeName(userTask.getName());flowConfigBo.setNodeKey(userTask.getId());flowConfigService.insertByBo(flowConfigBo);}else {flowConfigVo.setAppType(appType);flowConfigVo.setFormKey(userTask.getFormKey());flowConfigVo.setNodeName(userTask.getName());flowConfigService.updateFlowConfig(flowConfigVo);}}}return modelId;}
3、相应界面如下: