提交 e8479c03 编写于 作者: lengyu's avatar lengyu

工作流多实例、下一步条件

上级 a0f8852c
...@@ -53,8 +53,14 @@ import org.flowable.ui.modeler.serviceapi.AppDefinitionService; ...@@ -53,8 +53,14 @@ import org.flowable.ui.modeler.serviceapi.AppDefinitionService;
import org.flowable.ui.modeler.serviceapi.ModelService; import org.flowable.ui.modeler.serviceapi.ModelService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.expression.MapAccessor;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
...@@ -119,6 +125,7 @@ public class WFCoreService ...@@ -119,6 +125,7 @@ public class WFCoreService
private Map<String,List<Map<String,Object>>> taskMap = new ConcurrentHashMap<>(); private Map<String,List<Map<String,Object>>> taskMap = new ConcurrentHashMap<>();
private final ExpressionParser parser = new SpelExpressionParser();
private AuthenticationContext createAuthenticationContext() private AuthenticationContext createAuthenticationContext()
{ {
...@@ -1271,6 +1278,93 @@ public class WFCoreService ...@@ -1271,6 +1278,93 @@ public class WFCoreService
return strUsers; return strUsers;
} }
/**
* 返回组成员,用于多实例会签( wfroleid = groupid +deptid )
* @param groupIds
* @param delegateExecution
* @return
*/
public List<WFMember> getGroupUsers2(String groupIds, DelegateExecution delegateExecution)
{
List<WFMember> users= new ArrayList<>();
if(StringUtils.isEmpty(groupIds))
return users;
String[] groups=groupIds.split(",");
for(String groupId:groups)
{
String userData="";
String userData2="";
String orgid="";
String deptid="";
if(groupId.indexOf("|")>0)
{
String[] arg=groupId.split("[|]");
if(arg.length==3)
{
groupId=arg[0];
if(arg[1]!=null)
userData=arg[1].toLowerCase();
if(arg[2]!=null)
userData2=arg[2].toLowerCase();
}
}
if((!StringUtils.isEmpty(userData))&&(!StringUtils.isEmpty(userData2)))
{
if(userData2.indexOf("srf")==0)
{
FlowUser curUser=FlowUser.getCurUser();
if(curUser!=null&&curUser.getUser()!=null)
{
Object sessionValue=curUser.getUser().getSessionParams().get(userData2);
if(sessionValue!=null)
userData2=sessionValue.toString();
else
userData2="";
}
else
userData2="";
}
else
{
Object activedata=delegateExecution.getVariable("activedata");
if(activedata!=null&&activedata instanceof Map) {
Map entity = (Map) activedata;
if(entity.get(userData2)!=null)
userData2=entity.get(userData2).toString();
else
userData2="";
}
else
userData2="";
}
if(!StringUtils.isEmpty(userData2))
{
if(userData.indexOf("dept")>=0||userData.indexOf("orgsec")>=0)
deptid=userData2;
else if(userData.indexOf("org")>=0)
orgid=userData2;
}
}
WFGroup group=iwfGroupService.get(groupId);
List<WFMember> list=group.getWfmember();
if (list!=null)
{
for(WFMember member : list)
{
if((!StringUtils.isEmpty(deptid))&&(!deptid.equals(member.getMdeptid())))
continue;
if((!StringUtils.isEmpty(orgid))&&(!orgid.equals(member.getOrgid())))
continue;
users.add(member);
}
}
}
return users;
}
private ByteArrayOutputStream getBpmnFile(InputStream input) { private ByteArrayOutputStream getBpmnFile(InputStream input) {
try { try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
...@@ -1359,4 +1453,139 @@ public class WFCoreService ...@@ -1359,4 +1453,139 @@ public class WFCoreService
} }
return dynainstid; return dynainstid;
} }
/**
* 判断是否退出会签
* @param execution
* @return
*/
public boolean accessCondition(DelegateExecution execution) {
Object allRolesCnt = execution.getVariable("all_roles_cnt");
Object completeRolesCnt = execution.getVariable("complete_roles_cnt");
Object completeInstance = execution.getVariable("nrOfCompletedInstances");
Object allInstance = execution.getVariable("nrOfInstances");
Object sequenceFlowId = execution.getVariable("sequenceFlowId");
String flowAccessCond = getNextCondition(execution, sequenceFlowId); // role : any || all
if (!ObjectUtils.isEmpty(allInstance) && !ObjectUtils.isEmpty(completeInstance) && !ObjectUtils.isEmpty(flowAccessCond)) {
if("ANY".equalsIgnoreCase(flowAccessCond)){
return true;
}
else if ("ALL|ROLE:ANY".equalsIgnoreCase(flowAccessCond) && allRolesCnt == completeRolesCnt) {
return true;
}
else{
return (int) completeInstance / (int) allInstance == 1;
}
} else {
return false;
}
}
/**
* 获取连接线条件 (all/any/all|role:any)
*
* @param execution
* @param sequenceFlowId
* @return
*/
private 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()) {
if (sequenceFlowId.equals(flow.getId()) && !ObjectUtils.isEmpty(flow.getExtensionElements().get("form"))) {
for (ExtensionElement formProp : flow.getExtensionElements().get("form")) {
for (String attribute : formProp.getAttributes().keySet()) {
List<ExtensionAttribute> attributes = formProp.getAttributes().get(attribute);
if (!ObjectUtils.isEmpty(attributes)) {
for (ExtensionAttribute param : attributes) {
if (param.getName().equalsIgnoreCase("nextCondition")) {
return param.getValue();
}
}
}
}
}
}
}
}
return null;
}
/**
* role:any 认领当前任务,挂起将role中其他人任务
* @param execution
*/
public void ClaimTask(DelegateExecution execution) {
}
/**
* 获取用户所属的工作流角色
* @param userId
* @param execution
* @return
*/
public Set<String> getRoleByUserId(String userId, DelegateExecution execution) {
Set roles = new HashSet();
if(!ObjectUtils.isEmpty(userId)){
UserTask task = (UserTask) execution.getCurrentFlowElement();
List fieldList = task.getExtensionElements().get("field");
String strCandidate = "";
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")){
strCandidate = ((ExtensionElement) field).getChildElements().get("string").get(0).getElementText();
break;
}
}
}
}
}
LinkedHashMap executionMap = (LinkedHashMap) execution.getVariable("activedata");
String[] groups = strCandidate.split("\\|\\|");
if (groups.length > 0) {
for (String group : groups) {
if (group.contains("activedata")) {
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) && processUserId.contains(userId)){
roles.add(group);
}
}
}
if (group.contains("wfCoreService.getGroupUsers")) {
String exp = group;
EvaluationContext oldContext = new StandardEvaluationContext();
oldContext.setVariable("wfCoreService", this);
oldContext.setVariable("execution", execution);
Expression oldExp = parser.parseExpression(exp);
List<WFMember> users = oldExp.getValue(oldContext, List.class);
if (!StringUtils.isEmpty(users)) {
users.forEach(groupMember->{
if(!ObjectUtils.isEmpty(groupMember.getUserid()) && userId.equals(groupMember.getUserid())){
String roleId;
if(!ObjectUtils.isEmpty(groupMember.getMdeptid())){
roleId = String.format("%s_%s",groupMember.getGroupid(),groupMember.getMdeptid());
}
else{
roleId = groupMember.getGroupid();
}
roles.add(roleId);
}
});
}
}
}
}
}
return roles;
}
} }
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册