Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzwf
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzwf
提交
2e315112
提交
2e315112
编写于
3月 21, 2021
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
下一步条件(清除role其余用户待办)
上级
9825bc5e
变更
2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
185 行增加
和
99 行删除
+185
-99
ProcessInstanceListener.java
...workflow/extensions/listener/ProcessInstanceListener.java
+74
-74
WFCoreService.java
...izlab/core/workflow/extensions/service/WFCoreService.java
+111
-25
未找到文件。
ibzwf-core/src/main/java/cn/ibizlab/core/workflow/extensions/listener/ProcessInstanceListener.java
浏览文件 @
2e315112
...
...
@@ -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,83 +137,87 @@ 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
;
// 多实例(会签)
if
(
event
.
getType
()
==
FlowableEngineEventType
.
MULTI_INSTANCE_ACTIVITY_STARTED
){
UserTask
task
=
(
UserTask
)
event
.
getExecution
().
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
;
try
{
FlowableMultiInstanceActivityEventImpl
event
=
(
FlowableMultiInstanceActivityEventImpl
)
evt
;
// 多实例(会签)
if
(
event
.
getType
()
==
FlowableEngineEventType
.
MULTI_INSTANCE_ACTIVITY_STARTED
){
UserTask
task
=
(
UserTask
)
event
.
getExecution
().
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
;
}
}
}
}
}
}
DelegateExecution
execution
=
event
.
getExecution
();
Set
processRoles
=
new
HashSet
();
Set
processUserIds
=
new
HashSet
();
DelegateExecution
execution
=
event
.
getExecution
();
Set
processRoles
=
new
HashSet
();
Set
processUserIds
=
new
HashSet
();
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
userId
=
exp
.
getValue
(
context
,
String
.
class
);
if
(!
StringUtils
.
isEmpty
(
userId
))
{
processUserIds
.
add
(
userId
);
// TODO : 默认为单人,需优化为多人
processRoles
.
add
(
group
);
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
userId
=
exp
.
getValue
(
context
,
String
.
class
);
if
(!
StringUtils
.
isEmpty
(
userId
))
{
processUserIds
.
add
(
userId
);
// TODO : 默认为单人,需优化为多人
processRoles
.
add
(
group
);
}
}
}
}
if
(
group
.
contains
(
"wfCoreService.getGroupUsers"
))
{
String
exp
=
group
;
EvaluationContext
oldContext
=
new
StandardEvaluationContext
(
);
oldContext
.
setVariable
(
"wfCoreService"
,
wfCoreService
);
oldContext
.
setVariable
(
"execution"
,
execution
);
Expression
oldExp
=
parser
.
parseExpression
(
exp
);
List
<
WFMember
>
users
=
oldExp
.
getValue
(
oldContext
,
List
.
class
);
if
(!
StringUtils
.
isEmpty
(
users
))
{
users
.
forEach
(
groupMember
->{
String
roleId
;
if
(!
ObjectUtils
.
isEmpty
(
groupMember
.
getMdeptid
())){
roleId
=
String
.
format
(
"%s_%s"
,
groupMember
.
getGroupid
(),
groupMember
.
getMdeptid
());
}
else
{
roleId
=
groupMember
.
getGroupid
();
}
processRoles
.
add
(
roleId
);
processUserIds
.
add
(
groupMember
.
getUserid
()
);
}
);
if
(
group
.
contains
(
"wfCoreService.getGroupUsers"
))
{
String
exp
=
group
;
EvaluationContext
oldContext
=
new
StandardEvaluationContext
()
;
oldContext
.
setVariable
(
"wfCoreService"
,
wfCoreService
);
oldContext
.
setVariable
(
"execution"
,
execution
);
Expression
oldExp
=
parser
.
parseExpression
(
exp
);
List
<
WFMember
>
users
=
oldExp
.
getValue
(
oldContext
,
List
.
class
);
if
(!
StringUtils
.
isEmpty
(
users
))
{
users
.
forEach
(
groupMember
->
{
String
roleId
;
if
(!
ObjectUtils
.
isEmpty
(
groupMember
.
getMdeptid
())){
roleId
=
String
.
format
(
"%s_%s"
,
groupMember
.
getGroupid
(),
groupMember
.
getMdeptid
());
}
else
{
roleId
=
groupMember
.
getGroupid
();
}
processRoles
.
add
(
roleId
);
processUserIds
.
add
(
groupMember
.
getUserid
()
);
}
);
}
}
}
}
}
//设置会签用户
if
(!
ObjectUtils
.
isEmpty
(
processUserIds
)){
event
.
getExecution
().
setVariableLocal
(
"candidateUsersList"
,
processUserIds
);
}
else
{
throw
new
BadRequestAlertException
(
String
.
format
(
"工作流操作失败,无法获取[%s]步骤用户"
,
task
.
getName
()),
"ProcessInstanceListener"
,
"getStepUsers"
);
}
//计算角色
if
(!
ObjectUtils
.
isEmpty
(
processRoles
)
&&
ObjectUtils
.
isEmpty
(
event
.
getExecution
().
getVariable
(
"all_roles"
))){
event
.
getExecution
().
setVariableLocal
(
"all_roles_cnt"
,
processRoles
.
size
());
//设置会签用户
if
(!
ObjectUtils
.
isEmpty
(
processUserIds
)){
event
.
getExecution
().
setVariableLocal
(
"candidateUsersList"
,
processUserIds
);
}
else
{
throw
new
BadRequestAlertException
(
String
.
format
(
"工作流操作失败,无法获取[%s]步骤用户"
,
task
.
getName
()),
"ProcessInstanceListener"
,
"getStepUsers"
);
}
//计算角色
if
(!
ObjectUtils
.
isEmpty
(
processRoles
)
&&
ObjectUtils
.
isEmpty
(
event
.
getExecution
().
getVariable
(
"all_roles"
))){
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
()
);
}
}
}
...
...
ibzwf-core/src/main/java/cn/ibizlab/core/workflow/extensions/service/WFCoreService.java
浏览文件 @
2e315112
...
...
@@ -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
*/
p
rivate
String
getNextCondition
(
DelegateExecution
execution
,
Object
sequenceFlowId
)
{
p
ublic
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
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录