Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
workflow
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
2
议题
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
workflow
Commits
47afe3db
提交
47afe3db
authored
3月 24, 2021
作者:
黄夏豪
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[工作流引擎] 修复了流程结束后无法调用回调函数的BUG
上级
555b6ecc
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
33 行增加
和
112 行删除
+33
-112
ProcessEndListener.java
...flowcore/workflow_editer/listener/ProcessEndListener.java
+22
-15
WorkFlowServiceImpl.java
...ore/workflow_editer/service/impl/WorkFlowServiceImpl.java
+11
-97
没有找到文件。
src/main/java/com/tykj/workflowcore/workflow_editer/listener/ProcessEndListener.java
浏览文件 @
47afe3db
package
com
.
tykj
.
workflowcore
.
workflow_editer
.
listener
;
import
com.alibaba.fastjson.JSONObject
;
import
com.tykj.workflowcore.api.controller.ApiController
;
import
com.tykj.workflowcore.api.entity.InvokeRequest
;
import
com.tykj.workflowcore.api.entity.Parameter
;
import
com.tykj.workflowcore.workflow_editer.entity.CommandGetValue
;
...
...
@@ -8,11 +9,14 @@ import com.tykj.workflowcore.workflow_editer.entity.VariableStorage;
import
com.tykj.workflowcore.workflow_editer.entity.vo.InvokeRequestVo
;
import
com.tykj.workflowcore.workflow_editer.entity.vo.SearchVariableStorageVo
;
import
com.tykj.workflowcore.workflow_editer.service.VariableStorageService
;
import
liquibase.pro.packaged.A
;
import
org.flowable.common.engine.api.delegate.Expression
;
import
org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent
;
import
org.flowable.common.engine.api.delegate.event.FlowableEvent
;
import
org.flowable.engine.*
;
import
org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener
;
import
org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl
;
import
org.flowable.engine.impl.persistence.entity.ExecutionEntity
;
import
org.flowable.engine.runtime.ProcessInstance
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
...
...
@@ -46,25 +50,25 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener {
ProcessEngineConfigurationImpl
processEngineConfiguration
;
@Autowired
ProcessEngine
processEngine
;
ApiController
apiController
;
@Override
protected
void
processCompleted
(
FlowableEngineEntityEvent
event
)
{
//流程结束了
if
(
event
.
getEntity
()
instanceof
ProcessInstance
){
ProcessInstance
processInstance
=
(
ProcessInstance
)
event
.
getEntity
();
String
processInstanceId
=
processInstance
.
getProcessInstanceId
();
String
processDefinitionId
=
processInstance
.
getProcessDefinitionId
();
String
flowKey
=
processDefinitionId
.
substring
(
0
,
processDefinitionId
.
indexOf
(
":"
));
List
<
VariableStorage
>
variableStorageList
=
variableStorageService
.
searchVariableStorageList
(
new
SearchVariableStorageVo
(
flowKey
));
for
(
VariableStorage
variableStorage
:
variableStorageList
)
{
InvokeRequestVo
variableInfo
=
variableStorage
.
getInvokeRequest
();
variableInfo
.
setProcessInstance
(
processInstance
);
//调用服务接口
variableInfo
.
setProcessInstanceId
(
processInstanceId
);
getApiInvokeParam
(
variableInfo
);
//1. 获取调用的具体数值
apiController
.
invoke
(
getApiInvokeParam
(
variableInfo
)
);
}
}
// throw new ApiException("强行报错");
}
@Override
...
...
@@ -72,6 +76,12 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener {
super
.
taskCompleted
(
event
);
}
@Override
public
void
onEvent
(
FlowableEvent
flowableEvent
)
{
System
.
out
.
println
(
flowableEvent
.
getType
());
super
.
onEvent
(
flowableEvent
);
}
/**
* 获取调用Api用的参数
*
...
...
@@ -80,37 +90,34 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener {
*/
public
InvokeRequest
getApiInvokeParam
(
InvokeRequestVo
invokeRequestVo
)
{
//拿出taskId
String
processInstanceId
=
invokeRequestVo
.
getProcessInstanceId
();
List
<
Parameter
>
parameterList
=
invokeRequestVo
.
getParam
eterList
();
ProcessInstance
processInstance
=
invokeRequestVo
.
getProcessInstance
();
List
<
Parameter
>
parameterList
=
invokeRequestVo
.
getParam
s
();
List
<
Parameter
>
newParameterList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
parameterList
.
size
();
i
++)
{
Parameter
parameter
=
parameterList
.
get
(
i
);
if
(!
StringUtils
.
isEmpty
(
parameter
.
getExp
()))
{
//如果是表示式 如:${people}
parameter
.
setInstance
((
Map
<
String
,
Object
>)
getProcessValue
(
processInstance
Id
,
parameter
.
getExp
()));
parameter
.
setInstance
((
Map
<
String
,
Object
>)
getProcessValue
(
processInstance
,
parameter
.
getExp
()));
}
else
{
Map
<
String
,
Object
>
instance
=
parameter
.
getInstance
();
JSONObject
newInstance
=
new
JSONObject
();
//遍历param的key
Set
<
String
>
oldInstanceKey
=
instance
.
keySet
();
for
(
String
key
:
oldInstanceKey
)
{
newInstance
.
put
(
key
,
getProcessValue
(
processInstance
Id
,
(
String
)
instance
.
get
(
key
)));
newInstance
.
put
(
key
,
getProcessValue
(
processInstance
,
(
String
)
instance
.
get
(
key
)));
}
parameter
.
setInstance
(
newInstance
);
}
newParameterList
.
add
(
i
,
parameter
);
}
invokeRequestVo
.
setParam
eterList
(
newParameterList
);
invokeRequestVo
.
setParam
s
(
newParameterList
);
return
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
invokeRequestVo
),
InvokeRequest
.
class
);
}
public
Object
getProcessValue
(
String
processInstanceId
,
String
exp
)
{
public
Object
getProcessValue
(
ProcessInstance
processInstance
,
String
exp
)
{
// processInstance -> ExecutionEntity
Expression
expression
=
processEngineConfiguration
.
getExpressionManager
().
createExpression
(
exp
);
ManagementService
managementService
=
processEngine
.
getManagementService
();
CommandGetValue
test
=
new
CommandGetValue
(
processInstanceId
,
expression
);
Object
o
=
managementService
.
executeCommand
(
test
);
return
o
;
return
expression
.
getValue
((
ExecutionEntity
)
processInstance
);
}
}
src/main/java/com/tykj/workflowcore/workflow_editer/service/impl/WorkFlowServiceImpl.java
浏览文件 @
47afe3db
...
...
@@ -33,6 +33,7 @@ import org.flowable.image.ProcessDiagramGenerator;
import
org.flowable.task.api.Task
;
import
org.flowable.task.api.TaskQuery
;
import
org.flowable.task.api.history.HistoricTaskInstance
;
import
org.hibernate.engine.transaction.internal.TransactionImpl
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -57,6 +58,7 @@ import java.util.regex.Pattern;
@Service
public
class
WorkFlowServiceImpl
implements
WorkFlowService
{
private
final
RepositoryService
repositoryService
;
private
final
RuntimeService
runtimeService
;
private
final
TaskService
taskService
;
...
...
@@ -285,63 +287,16 @@ public class WorkFlowServiceImpl implements WorkFlowService {
if
(
taskVo
.
getComments
()
!=
null
)
{
taskService
.
addComment
(
task
.
getId
(),
processInstanceId
,
taskVo
.
getComments
());
}
// //先判断是不是表达式
// if (taskVo.getConditionalExpression() != null) {
// claimTask(task.getId(), userService.getCurrentUser().getId());
// taskService.complete(task.getId());
//
// } else {
// map.put("handlingOpinion", taskVo.getHandlingOpinion());
// claimTask(task.getId(), userService.getCurrentUser().getId());
// taskService.complete(task.getId(), map);
// }
taskService
.
complete
(
task
.
getId
());
// 流程结束了
// ProcessInstance processInstance =
// runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
// if (processInstance == null){
// //通过processInstanceId查询出flowKey
// FlowsInfo flowsInfo = flowsInfoMapper.findByProcessInstanceId(processInstanceId);
// //查询调用接口的配置
// List<VariableStorage> variableStorageList = variableStorageService.searchVariableStorageList(new
// SearchVariableStorageVo(flowsInfo.getFlowKey()));
// for (VariableStorage variableStorage : variableStorageList) {
// InvokeRequestVo variableInfo = variableStorage.getInvokeRequest();
// //调用服务接口
// getApiInvokeParam(variableInfo);
// }
// }
//查询是否为最后一个节点
// ExecutionEntity ee = (ExecutionEntity) processEngine.getRuntimeService().createExecutionQuery()
// .executionId(task.getExecutionId()).singleResult();
// BpmnModel bpmnModel = processEngine.getRepositoryService().getBpmnModel(task.getProcessDefinitionId());
// FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(ee.getActivityId());
// List<SequenceFlow> outFlows = flowNode.getOutgoingFlows();
// for (SequenceFlow sequenceFlow : outFlows) {
// FlowElement targetFlow = sequenceFlow.getTargetFlowElement();
// // 如果下个审批节点为结束节点
// if (targetFlow instanceof EndEvent) {
// System.out.println("下一节点为结束节点:id=" + targetFlow.getId() + ",name=" + targetFlow.getName());
// }
// }
//先判断是不是表达式
if
(
taskVo
.
getConditionalExpression
()
!=
null
)
{
claimTask
(
task
.
getId
(),
userService
.
getCurrentUser
().
getId
());
taskService
.
complete
(
task
.
getId
());
// if (taskVo.getTaskId() == null){
// //流程结束了
// //通过processInstanceId查询出flowKey
// FlowsInfo flowsInfo = flowsInfoMapper.findByProcessInstanceId(processInstanceId);
// //查询调用接口的配置
// List<VariableStorage> variableStorageList = variableStorageService.searchVariableStorageList(new SearchVariableStorageVo(flowsInfo.getFlowKey()));
// for (VariableStorage variableStorage : variableStorageList) {
// InvokeRequestVo variableInfo = variableStorage.getInvokeRequest();
// //调用服务接口
// getApiInvokeParam(variableInfo);
// }
// }
}
else
{
map
.
put
(
"handlingOpinion"
,
taskVo
.
getHandlingOpinion
());
claimTask
(
task
.
getId
(),
userService
.
getCurrentUser
().
getId
());
taskService
.
complete
(
task
.
getId
(),
map
);
}
}
...
...
@@ -464,47 +419,6 @@ public class WorkFlowServiceImpl implements WorkFlowService {
return
null
;
}
/**
* 获取调用Api用的参数
*
* @param invokeRequestVo 调用服务接口vo
* @return 调用服务接口实体
*/
public
InvokeRequest
getApiInvokeParam
(
InvokeRequestVo
invokeRequestVo
)
{
//拿出taskId
String
processInstanceId
=
invokeRequestVo
.
getProcessInstanceId
();
List
<
Parameter
>
parameterList
=
invokeRequestVo
.
getParameterList
();
List
<
Parameter
>
newParameterList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
parameterList
.
size
();
i
++)
{
Parameter
parameter
=
parameterList
.
get
(
i
);
if
(!
StringUtils
.
isEmpty
(
parameter
.
getExp
()))
{
//如果是表示式 如:${people}
parameter
.
setInstance
((
Map
<
String
,
Object
>)
getProcessValue
(
processInstanceId
,
parameter
.
getExp
()));
}
else
{
Map
<
String
,
Object
>
instance
=
parameter
.
getInstance
();
JSONObject
newInstance
=
new
JSONObject
();
//遍历param的key
Set
<
String
>
oldInstanceKey
=
instance
.
keySet
();
for
(
String
key
:
oldInstanceKey
)
{
newInstance
.
put
(
key
,
getProcessValue
(
processInstanceId
,
(
String
)
instance
.
get
(
key
)));
}
parameter
.
setInstance
(
newInstance
);
}
newParameterList
.
add
(
i
,
parameter
);
}
invokeRequestVo
.
setParameterList
(
newParameterList
);
return
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
invokeRequestVo
),
InvokeRequest
.
class
);
}
public
Object
getProcessValue
(
String
processInstanceId
,
String
exp
)
{
Expression
expression
=
processEngineConfiguration
.
getExpressionManager
().
createExpression
(
exp
);
ManagementService
managementService
=
processEngine
.
getManagementService
();
CommandGetValue
test
=
new
CommandGetValue
(
processInstanceId
,
expression
);
Object
o
=
managementService
.
executeCommand
(
test
);
return
o
;
}
@Override
public
Map
<
String
,
Object
>
setVariables
(
@RequestBody
Map
<
String
,
Object
>
maxMap
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论