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 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 processParticipantItemList=new ArrayList();
ProcessParticipantItem participantXmlNode=new ProcessParticipantItem();
Collection 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 currentOutgoingFlows=((ApproveUserTask) currentElement).getOutgoingFlows();
for(int i=0;i graphicInfoList = new ArrayList();
//修改当前节点的连出线
if(currentElement instanceof ApproveUserTask)
{
List outgoingFlows=new ArrayList();
outgoingFlows.add(sequenceFlow);
((ApproveUserTask)currentElement).setOutgoingFlows(outgoingFlows);
graphicInfoList.add(createGraphicInfo(12, 12));
}
graphicInfoList.add(createGraphicInfo(12, 12));
bpmnModel.addFlowGraphicInfoList(sequenceFlowId, graphicInfoList);
// 设置新增活动的连入和连出线
List incomingFlows=new ArrayList();
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);
}