Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzwf
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzwf
提交
a0f8852c
提交
a0f8852c
编写于
3月 15, 2021
作者:
lengyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
工作流多实例、下一步条件
上级
c184d25e
变更
1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
146 行增加
和
2 行删除
+146
-2
ProcessInstanceListener.java
...workflow/extensions/listener/ProcessInstanceListener.java
+146
-2
未找到文件。
ibzwf-core/src/main/java/cn/ibizlab/core/workflow/extensions/listener/ProcessInstanceListener.java
浏览文件 @
a0f8852c
package
cn
.
ibizlab
.
core
.
workflow
.
extensions
.
listener
;
import
cn.ibizlab.core.workflow.domain.WFMember
;
import
cn.ibizlab.core.workflow.extensions.domain.FlowUser
;
import
cn.ibizlab.core.workflow.extensions.service.WFCoreService
;
import
cn.ibizlab.core.workflow.extensions.service.WFModelService
;
import
cn.ibizlab.util.client.IBZNotifyFeignClient
;
import
cn.ibizlab.util.service.RemoteService
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.flowable.bpmn.model.ExtensionAttribute
;
import
org.flowable.bpmn.model.ExtensionElement
;
import
org.flowable.bpmn.model.FormProperty
;
import
org.flowable.bpmn.model.UserTask
;
import
org.flowable.common.engine.api.delegate.event.*
;
import
org.flowable.common.engine.api.delegate.event.FlowableEngineEventType
;
import
org.flowable.common.engine.impl.event.FlowableEntityEventImpl
;
import
org.flowable.engine.TaskService
;
import
org.flowable.engine.delegate.DelegateExecution
;
import
org.flowable.engine.delegate.event.impl.FlowableActivityEventImpl
;
import
org.flowable.engine.delegate.event.impl.FlowableEntityWithVariablesEventImpl
;
import
org.flowable.engine.delegate.event.impl.FlowableMultiInstanceActivityEventImpl
;
import
org.flowable.engine.delegate.event.impl.FlowableProcessStartedEventImpl
;
import
org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl
;
import
org.flowable.identitylink.api.IdentityLinkType
;
import
org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntity
;
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.spel.standard.SpelExpressionParser
;
import
org.springframework.expression.spel.support.StandardEvaluationContext
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.LinkedHashMap
;
import
java.util.
Map
;
import
java.util.
*
;
@Slf4j
@Component
...
...
@@ -51,6 +65,8 @@ public class ProcessInstanceListener extends AbstractFlowableEventListener {
// @Lazy
// IBZNotifyFeignClient notifyFeignClient;
private
final
ExpressionParser
parser
=
new
SpelExpressionParser
();
@Override
public
void
onEvent
(
FlowableEvent
evt
)
{
...
...
@@ -120,6 +136,83 @@ 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
;
}
}
}
}
}
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
);
}
}
}
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
(
processRoles
)
&&
ObjectUtils
.
isEmpty
(
event
.
getExecution
().
getVariable
(
"all_roles"
))){
event
.
getExecution
().
setVariableLocal
(
"all_roles_cnt"
,
processRoles
.
size
());
}
//设置会签用户
if
(!
StringUtils
.
isEmpty
(
processUserIds
)){
event
.
getExecution
().
setVariableLocal
(
"candidateUsersList"
,
processUserIds
);
}
}
}
else
if
(
evt
instanceof
FlowableEntityWithVariablesEventImpl
)
{
FlowableEntityWithVariablesEventImpl
event
=
(
FlowableEntityWithVariablesEventImpl
)
evt
;
...
...
@@ -140,6 +233,57 @@ public class ProcessInstanceListener extends AbstractFlowableEventListener {
taskService
.
addComment
(
taskEntity
.
getId
(),
taskEntity
.
getProcessInstanceId
(),
link
.
toString
(),
srfwfmemo
);
}
}
try
{
if
(
event
.
getExecution
().
getParent
()!=
null
){
ObjectMapper
mapper
=
new
ObjectMapper
();
Object
allRolesCnt
=
event
.
getExecution
().
getParent
().
getVariableLocal
(
"all_roles_cnt"
);
Object
completeRoles
=
event
.
getExecution
().
getParent
().
getVariableLocal
(
"complete_roles"
);
Object
completeRolesCnt
=
event
.
getExecution
().
getParent
().
getVariableLocal
(
"complete_roles_cnt"
);
//会签节点
if
(!
ObjectUtils
.
isEmpty
(
allRolesCnt
)){
String
userId
=
null
;
for
(
IdentityLinkEntity
link
:
taskEntity
.
getIdentityLinks
()){
if
(
IdentityLinkType
.
CANDIDATE
.
equalsIgnoreCase
(
link
.
getType
())){
userId
=
link
.
getUserId
();
break
;
}
}
//当前用户工作流角色
Set
userRoles
=
wfCoreService
.
getRoleByUserId
(
userId
,
event
.
getExecution
());
if
(
ObjectUtils
.
isEmpty
(
userRoles
)){
return
;
}
//统计当前节点工作流角色提交情况
if
(
ObjectUtils
.
isEmpty
(
completeRolesCnt
)
&&
ObjectUtils
.
isEmpty
(
completeRoles
)){
//首次提交
event
.
getExecution
().
getParent
().
setVariableLocal
(
"complete_roles_cnt"
,
userRoles
.
size
());
event
.
getExecution
().
getParent
().
setVariableLocal
(
"complete_roles"
,
userRoles
);
wfCoreService
.
ClaimTask
(
event
.
getExecution
());
//TODO : all|role:any 下,消除其余用户待办
return
;
}
else
{
Set
complete_roles
=
mapper
.
readValue
(
mapper
.
writeValueAsString
(
completeRoles
),
Set
.
class
);
Set
user_complete_roles
=
new
HashSet
();
if
(!
ObjectUtils
.
isEmpty
(
complete_roles
)){
userRoles
.
forEach
(
userRole
->{
if
(!
complete_roles
.
contains
(
userRole
)){
user_complete_roles
.
add
(
userRole
);
}
});
if
(!
ObjectUtils
.
isEmpty
(
user_complete_roles
)){
complete_roles
.
addAll
(
user_complete_roles
);
event
.
getExecution
().
getParent
().
setVariableLocal
(
"complete_roles"
,
complete_roles
);
event
.
getExecution
().
getParent
().
setVariableLocal
(
"complete_roles_cnt"
,
complete_roles
.
size
());
wfCoreService
.
ClaimTask
(
event
.
getExecution
());
}
}
}
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"工作流操作失败"
+
e
);
}
}
}
else
if
(
evt
instanceof
FlowableEntityEventImpl
&&
evt
.
getType
()
!=
null
&&
FlowableEngineEventType
.
PROCESS_COMPLETED
==
evt
.
getType
()
)
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录