提交 2e315112 编写于 作者: zhouweidong's avatar zhouweidong

下一步条件(清除role其余用户待办)

上级 9825bc5e
......@@ -31,9 +31,7 @@ import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.expression.MapAccessor;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.*;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.stereotype.Component;
......@@ -139,7 +137,8 @@ public class ProcessInstanceListener extends AbstractFlowableEventListener {
}
}
else if (evt instanceof org.flowable.engine.delegate.event.impl.FlowableMultiInstanceActivityEventImpl){
org.flowable.engine.delegate.event.impl.FlowableMultiInstanceActivityEventImpl event = (FlowableMultiInstanceActivityEventImpl) evt;
try {
FlowableMultiInstanceActivityEventImpl event = (FlowableMultiInstanceActivityEventImpl) evt;
// 多实例(会签)
if(event.getType() == FlowableEngineEventType.MULTI_INSTANCE_ACTIVITY_STARTED){
UserTask task = (UserTask) event.getExecution().getCurrentFlowElement();
......@@ -217,6 +216,9 @@ public class ProcessInstanceListener extends AbstractFlowableEventListener {
event.getExecution().setVariableLocal("all_roles_cnt",processRoles.size());
}
}
} catch (Exception e) {
log.error("工作流操作失败"+e);
}
}
else if(evt instanceof FlowableEntityWithVariablesEventImpl )
{
......@@ -249,11 +251,9 @@ public class ProcessInstanceListener extends AbstractFlowableEventListener {
//会签节点
if(!ObjectUtils.isEmpty(allRolesCnt)){
String userId = null;
String taskId = null;
for(IdentityLinkEntity link : taskEntity.getIdentityLinks()){
if(IdentityLinkType.CANDIDATE.equalsIgnoreCase(link.getType())){
userId = link.getUserId();
taskId = link.getTaskId();
break;
}
}
......@@ -262,14 +262,14 @@ public class ProcessInstanceListener extends AbstractFlowableEventListener {
if(ObjectUtils.isEmpty(userRoles)){
return ;
}
String nextCondition = wfCoreService.getNextCondition(event.getExecution(), event.getExecution().getVariable("sequenceFlowId"));
//统计当前节点工作流角色提交情况
if(ObjectUtils.isEmpty(completeRolesCnt) && ObjectUtils.isEmpty(completeRoles)){ //首次提交
event.getExecution().getParent().setVariableLocal("complete_roles_cnt",userRoles.size());
event.getExecution().getParent().setVariableLocal("complete_roles",userRoles);
if(wfCoreService.accessCondition(event.getExecution())){
wfCoreService.ClaimTask(taskId,userId);
if("ALL|ROLE:ANY".equalsIgnoreCase(nextCondition) && (int)allRolesCnt > 1 && (int)allRolesCnt != userRoles.size()){
wfCoreService.deleteRoleTask(userRoles,event.getExecution());
}
return;
}
else{
Set complete_roles = mapper.readValue(mapper.writeValueAsString(completeRoles), Set.class);
......@@ -284,8 +284,8 @@ public class ProcessInstanceListener extends AbstractFlowableEventListener {
complete_roles.addAll(user_complete_roles);
event.getExecution().getParent().setVariableLocal("complete_roles",complete_roles);
event.getExecution().getParent().setVariableLocal("complete_roles_cnt",complete_roles.size());
if(wfCoreService.accessCondition(event.getExecution())) {
wfCoreService.ClaimTask(taskId, userId);
if("ALL|ROLE:ANY".equalsIgnoreCase(nextCondition) && (int)allRolesCnt > 1 && (int)allRolesCnt != complete_roles.size()){
wfCoreService.deleteRoleTask(userRoles,event.getExecution());
}
}
}
......
......@@ -1577,23 +1577,6 @@ public class WFCoreService
return false;
}
}
/**
* 判断是否需要挂起
* @param execution
* @return
*/
public boolean accessClaim(DelegateExecution execution) {
Object sequenceFlowId = execution.getVariable("sequenceFlowId");
String flowAccessCond = getNextCondition(execution, sequenceFlowId); // role : any || all
if(!ObjectUtils.isEmpty(flowAccessCond) && "ANY".equalsIgnoreCase(flowAccessCond)){
return true;
}
else if (!ObjectUtils.isEmpty(flowAccessCond) && "ALL|ROLE:ANY".equalsIgnoreCase(flowAccessCond)) {
return true;
} else {
return false;
}
}
/**
* 获取连接线条件 (all/any/all|role:any)
......@@ -1602,7 +1585,7 @@ public class WFCoreService
* @param sequenceFlowId
* @return
*/
private String getNextCondition(DelegateExecution execution, Object sequenceFlowId) {
public String getNextCondition(DelegateExecution execution, Object sequenceFlowId) {
if (!ObjectUtils.isEmpty(execution.getCurrentFlowElement()) && execution.getCurrentFlowElement() instanceof UserTask) {
UserTask userTask = (UserTask) execution.getCurrentFlowElement();
for (SequenceFlow flow : userTask.getOutgoingFlows()) {
......@@ -1625,13 +1608,6 @@ public class WFCoreService
return null;
}
/**
* role:any 认领当前任务,挂起将role中其他人任务
*/
public void ClaimTask(String taskId,String userId) {
taskService.claim(taskId,userId);
}
/**
* 获取用户所属的工作流角色
* @param userId
......@@ -1726,4 +1702,114 @@ public class WFCoreService
}
return task;
}
/**
* 清除角色中其他成员待办任务
* @param userRoles
* @param execution
*/
public void deleteRoleTask(Set userRoles, DelegateExecution execution) {
Object processInstanceId = execution.getProcessInstanceId();
if(ObjectUtils.isEmpty(processInstanceId)){
throw new BadRequestAlertException("无法获取流程实例","","");
}
Set<String> roleUserIds = getUsersByRole(userRoles,execution);
if(roleUserIds.size()>0){
Map param = new HashMap();
param.put("userids",roleUserIds);
param.put("processinstanceid",processInstanceId);
List<Map> tasks = wfCoreMapper.searchUserTask(param);
if(tasks.size()>0){
for(Map task : tasks){
Object executionId = task.get("execution");
if(!StringUtils.isEmpty(executionId)){
runtimeService.deleteMultiInstanceExecution(String.valueOf(executionId),false);
}
}
}
}
}
/**
* 获取角色成员
* @param roles
* @param execution
* @return
*/
public Set<String> getUsersByRole(Set roles, DelegateExecution execution) {
Set userIds = new HashSet();
if (!ObjectUtils.isEmpty(roles)) {
String candidateUsers = getCandidateUsers(execution);
if (!StringUtils.isEmpty(candidateUsers)) {
LinkedHashMap executionMap = (LinkedHashMap) execution.getVariable("activedata");
String[] groups = candidateUsers.split("\\|\\|");
if (groups.length > 0) {
for (String group : groups) {
if (group.contains("activedata") && roles.contains(group)) {
for (String elUserId : group.split("\\|")) {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
Expression exp = parser.parseExpression(elUserId);
context.addPropertyAccessor(new MapAccessor());
context.setVariable("activedata", executionMap);
String processUserId = exp.getValue(context, String.class);
if (StringUtils.isEmpty(processUserId)) {
userIds.add(processUserId);
}
}
}
if (group.contains("wfCoreService.getGroupUsers")) {
EvaluationContext oldContext = new StandardEvaluationContext();
oldContext.setVariable("wfCoreService", this);
oldContext.setVariable("execution", execution);
Expression oldExp = parser.parseExpression(group);
List<WFMember> users = oldExp.getValue(oldContext, List.class);
if (!StringUtils.isEmpty(users)) {
users.forEach(groupMember -> {
if (!ObjectUtils.isEmpty(groupMember.getUserid())) {
String roleId;
if (!ObjectUtils.isEmpty(groupMember.getMdeptid())) {
roleId = String.format("%s_%s", groupMember.getGroupid(), groupMember.getMdeptid());
} else {
roleId = groupMember.getGroupid();
}
if (roles.contains(roleId)) {
userIds.add(groupMember.getUserid());
}
}
});
}
}
}
}
}
}
return userIds;
}
/**
* 获取步骤审批用户
* @param execution
* @return
*/
private String getCandidateUsers(DelegateExecution execution){
String strCandidateUsers ="";
UserTask task = (UserTask) execution.getCurrentFlowElement();
List fieldList = task.getExtensionElements().get("field");
if(!ObjectUtils.isEmpty(fieldList)){
for (Object field : fieldList) {
if(!ObjectUtils.isEmpty(((ExtensionElement) field).getAttributes())){
List<ExtensionAttribute> attributes = ((ExtensionElement) field).getAttributes().get("name");
if(attributes.size() > 0){
if(attributes.get(0).getValue().equals("candidateUsersList")){
strCandidateUsers = ((ExtensionElement) field).getChildElements().get("string").get(0).getElementText();
break;
}
}
}
}
}
return strCandidateUsers;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册