Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzwf
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzwf
提交
fdc1990c
提交
fdc1990c
编写于
5月 09, 2020
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
callback
上级
00a34fb1
变更
3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
223 行增加
和
8 行删除
+223
-8
ProcessInstanceListener.java
...lab/core/extensions/listener/ProcessInstanceListener.java
+137
-3
WFCoreService.java
...ava/cn/ibizlab/core/extensions/service/WFCoreService.java
+73
-5
WFModelService.java
...va/cn/ibizlab/core/extensions/service/WFModelService.java
+13
-0
未找到文件。
ibzwf-core/src/main/java/cn/ibizlab/core/extensions/listener/ProcessInstanceListener.java
浏览文件 @
fdc1990c
package
cn
.
ibizlab
.
core
.
extensions
.
listener
;
import
cn.ibizlab.core.extensions.service.WFCoreService
;
import
cn.ibizlab.core.extensions.service.WFModelService
;
import
cn.ibizlab.util.security.AuthTokenUtil
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.service.RemoteService
;
import
lombok.extern.slf4j.Slf4j
;
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.delegate.event.impl.FlowableActivityEventImpl
;
import
org.flowable.engine.delegate.event.impl.FlowableProcessStartedEventImpl
;
import
org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl
;
import
org.flowable.task.service.impl.persistence.entity.TaskEntity
;
import
org.flowable.task.service.impl.persistence.entity.TaskEntityImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 流程实例监听器,监听流程实例启动、流转、结束状态
...
...
@@ -23,10 +36,74 @@ import java.util.List;
@Component
public
class
ProcessInstanceListener
implements
FlowableEventListener
{
@Autowired
@Lazy
private
WFCoreService
wfCoreService
;
@Autowired
@Lazy
private
WFModelService
wfModelService
;
@Autowired
@Lazy
private
RemoteService
remoteService
;
@Autowired
private
AuthTokenUtil
jwtTokenUtil
;
@Override
public
void
onEvent
(
FlowableEvent
evt
)
{
if
(
evt
instanceof
FlowableEntityEventImpl
)
if
(
evt
instanceof
FlowableProcessStartedEventImpl
)
{
FlowableProcessStartedEventImpl
event
=(
FlowableProcessStartedEventImpl
)
evt
;
if
(
event
.
getEntity
()
instanceof
ExecutionEntityImpl
){
ExecutionEntityImpl
executionEntity
=
(
ExecutionEntityImpl
)
event
.
getEntity
();
if
(
executionEntity
.
getVariable
(
"cloud-serviceid"
)==
null
)
return
;
String
businessKey
=(
String
)
executionEntity
.
getVariable
(
"businessKey"
);
AuthenticationUser
curUser
=(
AuthenticationUser
)
executionEntity
.
getVariable
(
"curuser"
);
String
entity
=
executionEntity
.
getVariable
(
"entitys"
).
toString
();
String
cloudServiceid
=
executionEntity
.
getVariable
(
"cloud-serviceid"
).
toString
();
Map
setting
=
wfModelService
.
getProcessGlobalSetting
(
executionEntity
.
getProcessDefinitionId
());
String
wfstepfield
=
""
;
if
(
setting
.
containsKey
(
"wfstepfield"
+
"_"
+
entity
))
wfstepfield
=
setting
.
get
(
"wfstepfield"
+
"_"
+
entity
).
toString
();
String
wfinstfield
=
""
;
if
(
setting
.
containsKey
(
"wfinstfield"
+
"_"
+
entity
))
wfinstfield
=
setting
.
get
(
"wfinstfield"
+
"_"
+
entity
).
toString
();
String
udstatefield
=
""
;
if
(
setting
.
containsKey
(
"udstatefield"
+
"_"
+
entity
))
udstatefield
=
setting
.
get
(
"udstatefield"
+
"_"
+
entity
).
toString
();
String
wfstate
=
""
;
if
(
setting
.
containsKey
(
"wfstate"
+
"_"
+
entity
))
wfstate
=
setting
.
get
(
"wfstate"
+
"_"
+
entity
).
toString
();
String
wfverfield
=
""
;
if
(
setting
.
containsKey
(
"wfverfield"
+
"_"
+
entity
))
wfverfield
=
setting
.
get
(
"wfverfield"
+
"_"
+
entity
).
toString
();
executionEntity
.
setVariable
(
"wfstepfield"
,
wfstepfield
);
executionEntity
.
setVariable
(
"wfinstfield"
,
wfinstfield
);
executionEntity
.
setVariable
(
"udstatefield"
,
udstatefield
);
executionEntity
.
setVariable
(
"wfstate"
,
wfstate
);
executionEntity
.
setVariable
(
"wfverfield"
,
wfverfield
);
Map
callbackArg
=
new
LinkedHashMap
();
if
(!
StringUtils
.
isEmpty
(
wfinstfield
))
callbackArg
.
put
(
wfinstfield
,
executionEntity
.
getProcessInstanceId
());
if
(!
StringUtils
.
isEmpty
(
wfstate
))
callbackArg
.
put
(
wfstate
,
1
);
if
(!
StringUtils
.
isEmpty
(
udstatefield
))
callbackArg
.
put
(
udstatefield
,
"20"
);
if
((!
StringUtils
.
isEmpty
(
wfverfield
))&&(
executionEntity
.
getVariable
(
"wfversion"
)!=
null
))
callbackArg
.
put
(
wfverfield
,
Integer
.
parseInt
(
executionEntity
.
getVariable
(
"wfversion"
).
toString
()));
if
(
callbackArg
.
size
()>
0
)
{
String
token
=
"Bearer "
+
jwtTokenUtil
.
generateToken
(
curUser
);
remoteService
.
getClient
(
cloudServiceid
).
put
(
entity
+
"/"
+
businessKey
,
token
,
callbackArg
);
}
}
}
else
if
(
evt
instanceof
FlowableEntityEventImpl
)
{
FlowableEntityEventImpl
event
=((
FlowableEntityEventImpl
)
evt
);
// 当前节点任务实体
...
...
@@ -34,9 +111,41 @@ public class ProcessInstanceListener implements FlowableEventListener {
// TODO 获取到了taskEntity 自己做每个节点的前置操作
FlowableEventType
eventType
=
event
.
getType
();
//待办创建
if
(
eventType
==
FlowableEngineEventType
.
TASK_CREATED
){
if
(
eventType
==
FlowableEngineEventType
.
PROCESS_COMPLETED
){
ExecutionEntityImpl
executionEntity
=
(
ExecutionEntityImpl
)
event
.
getEntity
();
if
(
executionEntity
.
getVariable
(
"cloud-serviceid"
)==
null
)
return
;
String
businessKey
=(
String
)
executionEntity
.
getVariable
(
"businessKey"
);
AuthenticationUser
curUser
=(
AuthenticationUser
)
executionEntity
.
getVariable
(
"curuser"
);
String
entity
=
executionEntity
.
getVariable
(
"entitys"
).
toString
();
String
cloudServiceid
=
executionEntity
.
getVariable
(
"cloud-serviceid"
).
toString
();
String
wfstepfield
=
executionEntity
.
getVariable
(
"wfstepfield"
).
toString
();
String
udstatefield
=
executionEntity
.
getVariable
(
"udstatefield"
).
toString
();
String
wfstate
=
executionEntity
.
getVariable
(
"wfstate"
).
toString
();
Map
callbackArg
=
new
LinkedHashMap
();
if
(!
StringUtils
.
isEmpty
(
wfstate
))
callbackArg
.
put
(
wfstate
,
2
);
if
(!
StringUtils
.
isEmpty
(
udstatefield
))
callbackArg
.
put
(
udstatefield
,
"30"
);
if
(!
StringUtils
.
isEmpty
(
wfstepfield
))
callbackArg
.
put
(
wfstepfield
,
""
);
if
(
callbackArg
.
size
()>
0
)
{
String
token
=
"Bearer "
+
jwtTokenUtil
.
generateToken
(
curUser
);
remoteService
.
getClient
(
cloudServiceid
).
put
(
entity
+
"/"
+
businessKey
,
token
,
callbackArg
);
}
System
.
out
.
println
(
"流程结束"
);
}
if
(
eventType
==
FlowableEngineEventType
.
PROCESS_COMPLETED_WITH_ERROR_END_EVENT
){
event
.
getEntity
();
System
.
out
.
println
(
"流程异常结束"
);
}
//待办分配
else
if
(
eventType
==
FlowableEngineEventType
.
TASK_CREATED
){
TaskEntity
taskEntity
=
(
TaskEntity
)
event
.
getEntity
();
System
.
out
.
println
(
"
创建
任务"
);
System
.
out
.
println
(
"
分配
任务"
);
}
//待办分配
else
if
(
eventType
==
FlowableEngineEventType
.
TASK_ASSIGNED
){
...
...
@@ -49,6 +158,31 @@ public class ProcessInstanceListener implements FlowableEventListener {
System
.
out
.
println
(
"完成任务"
);
}
}
else
if
(
evt
instanceof
FlowableActivityEventImpl
)
{
FlowableActivityEventImpl
event
=((
FlowableActivityEventImpl
)
evt
);
// 当前节点任务实体
// TODO 获取到了taskEntity 自己做每个节点的前置操作
FlowableEventType
eventType
=
event
.
getType
();
if
(
eventType
==
FlowableEngineEventType
.
ACTIVITY_STARTED
&&
"userTask"
.
equals
(
event
.
getActivityType
())){
if
(
event
.
getExecution
().
getVariable
(
"cloud-serviceid"
)==
null
)
return
;
String
businessKey
=(
String
)
event
.
getExecution
().
getVariable
(
"businessKey"
);
AuthenticationUser
curUser
=(
AuthenticationUser
)
event
.
getExecution
().
getVariable
(
"curuser"
);
String
entity
=
event
.
getExecution
().
getVariable
(
"entitys"
).
toString
();
String
cloudServiceid
=
event
.
getExecution
().
getVariable
(
"cloud-serviceid"
).
toString
();
String
wfstepfield
=
event
.
getExecution
().
getVariable
(
"wfstepfield"
).
toString
();
Map
callbackArg
=
new
LinkedHashMap
();
if
(!
StringUtils
.
isEmpty
(
wfstepfield
)&&
event
.
getActivityId
().
startsWith
(
"tid-"
))
callbackArg
.
put
(
wfstepfield
,
event
.
getActivityId
().
split
(
"-"
)[
1
]);
if
(
callbackArg
.
size
()>
0
)
{
String
token
=
"Bearer "
+
jwtTokenUtil
.
generateToken
(
curUser
);
remoteService
.
getClient
(
cloudServiceid
).
put
(
entity
+
"/"
+
businessKey
,
token
,
callbackArg
);
}
}
}
}
...
...
ibzwf-core/src/main/java/cn/ibizlab/core/extensions/service/WFCoreService.java
浏览文件 @
fdc1990c
...
...
@@ -5,7 +5,10 @@ import cn.ibizlab.core.workflow.service.IWFGroupService;
import
cn.ibizlab.core.workflow.service.IWFProcessDefinitionService
;
import
cn.ibizlab.util.domain.EntityBase
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.security.AuthTokenUtil
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
cn.ibizlab.util.service.RemoteService
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
org.flowable.bpmn.converter.BpmnXMLConverter
;
import
org.flowable.bpmn.model.*
;
...
...
@@ -135,12 +138,20 @@ public class WFCoreService
String
userId
=
AuthenticationUser
.
getAuthenticationUser
().
getUserid
();
if
(
StringUtils
.
isEmpty
(
userId
))
throw
new
BadRequestAlertException
(
"未传入当前用户"
,
entity
,
businessKey
);
Integer
version
=
1
;
String
processDefinitionKey
=
instance
.
getProcessdefinitionkey
();
if
(
StringUtils
.
isEmpty
(
processDefinitionKey
)){
List
<
String
>
definitionKeys
=
this
.
getWorkflowKey
(
system
,
appname
,
entity
);
if
(
definition
Key
s
.
size
()==
0
)
List
<
WFProcessDefinition
>
definitions
=
this
.
getWorkflow
(
system
,
appname
,
entity
);
if
(
definitions
.
size
()==
0
)
throw
new
BadRequestAlertException
(
"未找到对应的工作流配置"
,
entity
,
businessKey
);
processDefinitionKey
=
definitionKeys
.
get
(
0
);
processDefinitionKey
=
definitions
.
get
(
0
).
getDefinitionkey
();
version
=
definitions
.
get
(
0
).
getModelversion
();
}
else
{
WFProcessDefinition
definition
=
iwfProcessDefinitionService
.
getById
(
processDefinitionKey
);
if
(
definition
==
null
)
throw
new
BadRequestAlertException
(
"未找到对应的工作流配置"
,
entity
,
businessKey
);
version
=
definition
.
getModelversion
();
}
String
processInstanceBusinessKey
=
system
+
":"
+
entity
+
":k-"
+
businessKey
;
...
...
@@ -152,7 +163,10 @@ public class WFCoreService
variables
.
put
(
"activedata"
,
instance
.
get
(
"activedata"
));
variables
.
put
(
"curuser"
,
AuthenticationUser
.
getAuthenticationUser
());
variables
.
put
(
"cloud-serviceid"
,
system
+
"-app-"
+
appname
);
variables
.
put
(
"system"
,
system
);
variables
.
put
(
"appname"
,
appname
);
variables
.
put
(
"entitys"
,
entity
);
variables
.
put
(
"wfversion"
,
version
);
//根据流程定义启动流程
Authentication
.
setAuthenticatedUserId
(
userId
);
ProcessInstance
processInstance
=
runtimeService
.
startProcessInstanceByKey
(
processDefinitionKey
,
processInstanceBusinessKey
,
variables
);
//流程定时标识、业务标识、变量
...
...
@@ -273,10 +287,8 @@ public class WFCoreService
}
String
processInstanceBusinessKey
=
system
+
":"
+
entity
+
":k-"
+
businessKey
;
Map
<
String
,
Object
>
variables
=
new
LinkedHashMap
<>();
variables
.
put
(
"businessKey"
,
businessKey
);
variables
.
put
(
"sequenceFlowId"
,
taskWay
.
getSequenceflowid
());
variables
.
put
(
"cloud-serviceid"
,
system
+
"-app-"
+
appname
);
variables
.
put
(
"entitys"
,
entity
);
Map
<
String
,
Object
>
transientVariables
=
new
LinkedHashMap
<>();
transientVariables
.
put
(
"activedata"
,
taskWay
.
get
(
"activedata"
));
...
...
@@ -290,6 +302,7 @@ public class WFCoreService
return
instance
;
}
@Value
(
"${ibiz.filePath:/app/file/}"
)
private
String
fileRoot
;
...
...
@@ -461,9 +474,64 @@ public class WFCoreService
}
@Autowired
private
RemoteService
remoteService
;
@Autowired
private
AuthTokenUtil
jwtTokenUtil
;
public
void
execute
(
DelegateExecution
delegateExecution
,
Object
activedata
)
throws
Exception
{
//String entity = (String)delegateExecution.getVariable("pass");
if
(
delegateExecution
.
getCurrentFlowElement
()
instanceof
ServiceTask
&&
activedata
instanceof
Map
)
{
ServiceTask
task
=(
ServiceTask
)
delegateExecution
.
getCurrentFlowElement
();
AuthenticationUser
curUser
=(
AuthenticationUser
)
delegateExecution
.
getVariable
(
"curuser"
);
String
businessKey
=(
String
)
delegateExecution
.
getVariable
(
"businessKey"
);
String
cloudServiceId
=(
String
)
delegateExecution
.
getVariable
(
"cloud-serviceid"
);
Map
entity
=(
Map
)
activedata
;
String
serviceEntity
=
""
;
String
serviceDEAction
=
""
;
for
(
FieldExtension
fieldExtension
:
task
.
getFieldExtensions
())
{
if
(
"service-entity"
.
equals
(
fieldExtension
.
getFieldName
()))
{
serviceEntity
=
fieldExtension
.
getStringValue
();
}
else
if
(
"service-deaction"
.
equals
(
fieldExtension
.
getFieldName
()))
{
serviceDEAction
=
fieldExtension
.
getStringValue
();
}
else
if
(
fieldExtension
.
getFieldName
().
startsWith
(
"params-"
))
{
String
key
=
fieldExtension
.
getFieldName
().
split
(
"-"
)[
1
];
entity
.
put
(
key
,
fieldExtension
.
getStringValue
());
}
}
if
(
StringUtils
.
isEmpty
(
serviceEntity
)||
StringUtils
.
isEmpty
(
serviceDEAction
))
return
;
String
token
=
"Bearer "
+
jwtTokenUtil
.
generateToken
(
curUser
);
String
path
=
serviceEntity
;
//cloudServiceId="support5";
if
(
serviceDEAction
.
equalsIgnoreCase
(
"create"
))
remoteService
.
getClient
(
cloudServiceId
).
post
(
path
,
token
,
entity
);
else
if
(
serviceDEAction
.
equalsIgnoreCase
(
"update"
))
remoteService
.
getClient
(
cloudServiceId
).
put
(
path
+
"/"
+
businessKey
,
token
,
entity
);
else
if
(
serviceDEAction
.
equalsIgnoreCase
(
"remove"
))
remoteService
.
getClient
(
cloudServiceId
).
delete
(
path
+
"/"
+
businessKey
,
token
);
else
if
(
serviceDEAction
.
equalsIgnoreCase
(
"save"
))
remoteService
.
getClient
(
cloudServiceId
).
post
(
path
+
"/save"
,
token
,
entity
);
else
if
(
serviceDEAction
.
equalsIgnoreCase
(
"get"
))
remoteService
.
getClient
(
cloudServiceId
).
get
(
path
+
"/"
+
businessKey
,
token
);
else
if
(
serviceDEAction
.
equalsIgnoreCase
(
"getdraft"
)){}
else
if
(
serviceDEAction
.
equalsIgnoreCase
(
"checkkey"
)){}
else
remoteService
.
getClient
(
cloudServiceId
).
post
(
path
+
"/"
+
businessKey
+
"/"
+
serviceDEAction
,
token
,
entity
);
}
System
.
out
.
println
(
"test"
);
// Boolean val = (Boolean) pass.getValue(delegateExecution);
//logger.info("=ProductFactoryNewProductTask=>business:{} prossId:{} pass:{}",delegateExecution.getProcessInstanceBusinessKey(),delegateExecution.getProcessInstanceId(),val.toString());
...
...
ibzwf-core/src/main/java/cn/ibizlab/core/extensions/service/WFModelService.java
浏览文件 @
fdc1990c
...
...
@@ -4,7 +4,9 @@ import cn.ibizlab.core.workflow.domain.WFProcessDefinition;
import
cn.ibizlab.core.workflow.domain.WFProcessNode
;
import
cn.ibizlab.core.workflow.service.IWFProcessDefinitionService
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
org.flowable.bpmn.model.ExtensionElement
;
import
org.flowable.bpmn.model.FlowElement
;
import
org.flowable.bpmn.model.Process
;
import
org.flowable.bpmn.model.UserTask
;
import
org.flowable.engine.RepositoryService
;
import
org.flowable.engine.repository.ProcessDefinition
;
...
...
@@ -76,4 +78,15 @@ public class WFModelService
}
return
userTasks
;
}
public
Map
<
String
,
Object
>
getProcessGlobalSetting
(
String
definitionid
)
{
LinkedHashMap
<
String
,
Object
>
setting
=
new
LinkedHashMap
();
Process
process
=
repositoryService
.
getBpmnModel
(
definitionid
).
getMainProcess
();
for
(
ExtensionElement
field:
repositoryService
.
getBpmnModel
(
definitionid
).
getMainProcess
().
getExtensionElements
().
get
(
"field"
))
{
if
((!
StringUtils
.
isEmpty
(
field
.
getAttributes
().
get
(
"name"
).
get
(
0
).
getValue
()))&&(!
StringUtils
.
isEmpty
(
field
.
getChildElements
().
get
(
"string"
).
get
(
0
).
getElementText
())))
setting
.
put
(
field
.
getAttributes
().
get
(
"name"
).
get
(
0
).
getValue
(),
field
.
getChildElements
().
get
(
"string"
).
get
(
0
).
getElementText
());
}
return
setting
;
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录