公文流程
保存
//省略其他业务逻辑......
//获取公文的工作流程类型
String processDefinitionKey=docDTO.getDocDocType().getDocType().getWorkflowId();
//启动流程
//将工作流程类型作为流程实例id,公文id 作为流程中业务id
this.runtimeService.startProcessInstanceByKey(processDefinitionKey,doc.getId());
//省略其他业务逻辑......
发送
//构建流程实例变量
Map<String,Object> vars=new HashMap<String,Object>();
vars.put("action", "doSend");//当前公文动作 发送
this.executeWorkFlow(operateInfo, docDTO, vars);
//流程实例key
String processDefinitionKey=docDTO.getDocDocType().getDocType().getWorkflowId();
//创建流程任务查询对象
TaskQuery tq=this.taskService.createTaskQuery();
//设置查询条件 流程实例key
tq.processDefinitionKey(processDefinitionKey);
//设置业务id
tq.processInstanceBusinessKey(docDTO.getId());
//拿到流程任务
List<Task> ts=tq.list();
vars.put("operateInfo", operateInfo);
for (Task t : ts) {//执行完成任务this.taskService.complete(t.getId(),vars);
}
Condition
# 跟上面的 vars.put("action", "doSend") 遥相呼应
${execution.getVariable('action')=='doSend'}
# 发送之后,需要处理我们的业务逻辑
${docBpmnFacade.sendDoc(execution,true)}
//发送公文public void sendDoc(DelegateExecution execution, boolean toFinish) {//业务idString docId=execution.getBusinessKey();//获取公文Doc doc=this.docRepository.getDocById(docId);//当前用户OperateInfo operateInfo=(OperateInfo)execution.getVariable("operateInfo");//其他变量Boolean sendMsg=(Boolean)execution.getVariable("sendMsg");//处理在发送公文之后我们自己的业务逻辑this.docDomainService.sendDoc(operateInfo, doc, toFinish,sendMsg);}
发送消息
${docBpmnFacade.sendDocFinishMsgWithProjs(execution,null,'_finish_with_proj')}
//发送公文完成消息public void sendDocFinishMsgWithProjs(DelegateExecution execution, String msgNamePrefix, String msgNameSuffix) {String docId=execution.getBusinessKey();Doc doc=this.docRepository.getDocById(docId);OperateInfo operateInfo=(OperateInfo)execution.getVariable("operateInfo");if(StringUtils.isBlank(msgNamePrefix)) msgNamePrefix="";if(StringUtils.isBlank(msgNameSuffix)) msgNameSuffix="";String msgName=msgNamePrefix+doc.getCreateInfo().getDocCategory()+msgNameSuffix;String relId = (String) execution.getVariable("relId");String eventType = null;//处理 信访 发送公文 监听if(doc.getBasicInfo().getValidRelateProjs().stream().anyMatch(r -> RelateProjConstants.PROJTYPE_CMP_PRC.equals(r.getRelateProj().getProjType()))){eventType = "Handle_CmpSendDoc";}//省略其他逻辑......//向办理记录发送消息for (DocRelateProj relProj : doc.getBasicInfo().getValidRelateProjs()) {String projId=relProj.getRelateProj().getProjId();//拿到流程实例//projId 业务id 这里是公文idProcessInstance prcIns = this.runtimeService.createProcessInstanceQuery().active().leafProcessInstances().processInstanceBusinessKey(projId).singleResult();if(prcIns == null) continue;//获取能够执行的流程实例List<MsgSubscriber> msgSubs = this.commonService.queryMsgSubscribers(prcIns.getProcessInstanceId(), msgName,null);if(CollectionUtils.isEmpty(msgSubs)){msgSubs = this.commonService.queryMsgSubscribers(prcIns.getProcessInstanceId(), "prc_finish",null);}//改为 逐个触发 查询出的事件 执行流程实例Map<String,Object> processVariables=Utils.buildMap("docId", docId, "operateInfo", operateInfo);this.commonService.msgReceived(msgSubs, processVariables);//省略其他逻辑....
}