1、流程重新定义
动态改变流程指向,创建新的节点
2、后加签环节及后加签属性设置
流程持久化、克隆活动、独立CMD
3、原始流程操作及后加签环节操作
4、流程场景遍历
5、流程图元体现
BPM后加签V1.0版说明。
效果图示:
功能说明:
1、支持同一环节多次后加签
2、支持弃审撤回后加签任务
3、后加签活动支持操作:审批、改派、驳回、后加签、前加签
4、设计器扩展:可否前/后加签标示
5、API扩展:可否前/后加签标示
示例代码:
{//流程引擎ProcessEngineConfiguration processEngine=commandContext.getProcessEngineConfiguration();//流程服务RepositoryService repositoryService=processEngine.getRepositoryService();RuntimeService runtimeService=processEngine.getRuntimeService();//1、创建新流程定义Model model=null;model=processEngine.getRepositoryService().getModel(getProcessId(task.getProcessDefinitionId()));logger.debug("流程模型ID:{},流程部署ID:{}",model.getId(),model.getDeploymentId());//查询流程定义BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());//流程定义查流程模型FlowElement currentElement=bpmnModel.getMainProcess().getFlowElement(task.getTaskDefinitionKey());Execution execution=runtimeService.createExecutionQuery().executionId(task.getExecutionId()).singleResult();logger.debug("活动{}",execution.getId());//图元处理Map<String, GraphicInfo> graphInfos=bpmnModel.getLocationMap();GraphicInfo graphicInfo=graphInfos.get(currentElement.getId());Double x=0.0;Double y=0.0;x=graphInfos.get(currentElement.getId()).getX()+90;y=graphInfos.get(currentElement.getId()).getY()+15;//加一个节点ApproveUserTask approveUserTask = new ApproveUserTask();//加出来的活动权限跟前面的活动权限相同if(currentElement instanceof ApproveUserTask){ApproveUserTask currentApprove=(ApproveUserTask) currentElement;//后加签出来的环节加签属性approveUserTask.setAddsignAble(currentApprove.getAddsignAble());//后加签出来的环节不允许指派approveUserTask.setAssignAble(false);//approveUserTask.setAssignAll(false);approveUserTask.setAssignSingle(false);approveUserTask.setRejectAble(currentApprove.getRejectAble());approveUserTask.setCanBeRejected(currentApprove.getCanBeRejected());approveUserTask.setDelegateAble(currentApprove.getDelegateAble());approveUserTask.setSamepostApprove(currentApprove.getSamepostApprove());approveUserTask.setSendRejectMesToEvery(currentApprove.getSendRejectMesToEvery());approveUserTask.setApproveType(currentApprove.getApproveType());approveUserTask.setAsynchronous(currentApprove.isAsynchronous());approveUserTask.setAttributes(currentApprove.getAttributes());approveUserTask.setCategory(currentApprove.getCategory());approveUserTask.setCopyToOrgManagers(currentApprove.getCopyToOrgManagers());approveUserTask.setCopyToUsers(currentApprove.getCopyToUsers());//approveUserTask.setDuedateStrategy(currentApprove.getDuedateStrategy());approveUserTask.setExecutionListeners(currentApprove.getExecutionListeners());approveUserTask.setExtensionElements(currentApprove.getExtensionElements());approveUserTask.setExtendAttributes(currentApprove.getExtendAttributes());approveUserTask.setForCompensation(currentApprove.isForCompensation());approveUserTask.setFormKey(currentApprove.getFormKey());approveUserTask.setFormProperties(currentApprove.getFormProperties());approveUserTask.setMultipleTypeoperations(currentApprove.getMultipleTypeoperations());approveUserTask.setNotExclusive(currentApprove.isNotExclusive());approveUserTask.setOperations(currentApprove.getOperations());approveUserTask.setOperationsUnselected(currentApprove.getOperationsUnselected());approveUserTask.setTaskListeners(currentApprove.getTaskListeners());//标志是后加签产生的approveUserTask.setApproveType("addsignBehind");}//后加签出来的环节不能再次后加签//approveUserTask.setAddsignBehindAble(false);//ID、名称设置String newApproveUserId="approveUserTask"+"_"+ this.getUUID().substring(0,10);approveUserTask.setId(newApproveUserId);approveUserTask.setName("后加签");//参与人设置List <ProcessParticipantItem> processParticipantItemList=new ArrayList<ProcessParticipantItem>();ProcessParticipantItem participantXmlNode=new ProcessParticipantItem();Collection<String> col=getCollection();ProcessParticipantDetail[] details=new ProcessParticipantDetail[col.size()];participantXmlNode.setType("USER");int k=0;for(String userId:col){details[k]=new ProcessParticipantDetail();details[k].setId(userId);k++;}participantXmlNode.setDetails(details);processParticipantItemList.add(participantXmlNode);ProcessParticipant processParticipant=new ProcessParticipant();processParticipant.setProcessParticipantItems(processParticipantItemList.toArray(new ProcessParticipantItem[processParticipantItemList.size()]));String participantjson=processParticipant.toJSONStr().replaceAll("\"", "'");String allUser="${bpmBean.getUser(\""+participantjson+"\",execution)}";approveUserTask.setAssignee("${assignee}");//审批类型MultiInstanceLoopCharacteristics multiInstanceObject = new MultiInstanceLoopCharacteristics();String multiInstance=(String)getActivity().getProperty("multiInstance");//环节设置为多人会签multiInstanceObject.setCompletionCondition("${nrOfCompletedInstances/nrOfInstances==1}");multiInstanceObject.setInputDataItem(allUser);multiInstanceObject.setElementVariable("assignee");approveUserTask.setLoopCharacteristics(multiInstanceObject);//图元位置及新活动设置graphicInfo = new GraphicInfo();graphicInfo.setX(x);graphicInfo.setY(y);graphicInfo.setWidth(65);graphicInfo.setHeight(35);bpmnModel.addGraphicInfo(newApproveUserId, graphicInfo);// getBpmnModelString(bpmnModel);// 修改当前节点的流出线为新节点的流出线List<SequenceFlow> currentOutgoingFlows=((ApproveUserTask) currentElement).getOutgoingFlows();for(int i=0;i<currentOutgoingFlows.size();i++){currentOutgoingFlows.get(i).setSourceRef(newApproveUserId);}// 加一条线,从当前节点到新创建的节点SequenceFlow sequenceFlow = new SequenceFlow();JSONObject json = new JSONObject();json.put("type", "sequenceFlow");String sequenceFlowId="SequenceFlow"+"_"+ this.getUUID().substring(0,10);sequenceFlow.setId(sequenceFlowId);sequenceFlow.setSourceRef(currentElement.getId());sequenceFlow.setTargetRef(newApproveUserId);Process process=bpmnModel.getProcesses().get(0);process.addFlowElement(sequenceFlow);String addSignProcessId="process"+"_"+ this.getUUID().substring(0,10);process.setId(addSignProcessId);List<GraphicInfo> graphicInfoList = new ArrayList<GraphicInfo>();//修改当前节点的连出线if(currentElement instanceof ApproveUserTask){List<SequenceFlow> outgoingFlows=new ArrayList<SequenceFlow>();outgoingFlows.add(sequenceFlow);((ApproveUserTask)currentElement).setOutgoingFlows(outgoingFlows);graphicInfoList.add(createGraphicInfo(12, 12));}graphicInfoList.add(createGraphicInfo(12, 12));bpmnModel.addFlowGraphicInfoList(sequenceFlowId, graphicInfoList);// 设置新增活动的连入和连出线List<SequenceFlow> incomingFlows=new ArrayList<SequenceFlow>();incomingFlows.add(sequenceFlow);approveUserTask.setIncomingFlows(incomingFlows);approveUserTask.setOutgoingFlows(currentOutgoingFlows);bpmnModel.getProcesses().get(0).addFlowElement(approveUserTask);//2、部署新流程定义String deploymentId=publishProcess(model,bpmnModel,false);//3、异步启动新流程定义new BpmThread(processEngine,deploymentId,taskId).start();//5、源任务记录状态task.setVariableLocal(COUNTERSIGN_BEHIND_ING, Boolean.TRUE);//添加评论if(comments != null && !"".equals(comments))commandContext.getProcessEngineConfiguration().getTaskService().addComment(task.getId(), task.getProcessInstanceId(), comments);}