Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
platform
/
platform-process-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 785a3662
authored
Sep 19, 2023
by
tiger
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
解决冲突
1 parent
072eb612
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
134 deletions
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/impl/SopInstNodeExecuteJobHandler.java
platform-process/src/main/java/cn/com/glsx/process/modules/sop/execute/executor/StartExecutor.java
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/impl/SopInstNodeExecuteJobHandler.java
View file @
785a366
...
@@ -29,121 +29,119 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -29,121 +29,119 @@ import lombok.extern.slf4j.Slf4j;
@Component
@Component
public
class
SopInstNodeExecuteJobHandler
{
public
class
SopInstNodeExecuteJobHandler
{
@Resource
@Resource
private
SopService
sopService
;
private
SopService
sopService
;
@XxlJob
(
SopXxlJobUtil
.
SOP_NODE_EXECUTE_JOB_ID
)
@XxlJob
(
SopXxlJobUtil
.
SOP_NODE_EXECUTE_JOB_ID
)
public
void
handler
(
String
param1
)
throws
Exception
{
public
void
handler
(
String
param1
)
throws
Exception
{
String
json
=
XxlJobHelper
.
getJobParam
();
String
json
=
XxlJobHelper
.
getJobParam
();
SopInstNodeParam
param
=
JSONUtil
.
toBean
(
json
,
SopInstNodeParam
.
class
);
SopInstNodeParam
param
=
JSONUtil
.
toBean
(
json
,
SopInstNodeParam
.
class
);
SopXxlJobUtil
.
log
(
log
,
"【执行Sop节点】{}"
,
param
);
SopXxlJobUtil
.
log
(
log
,
"【执行Sop节点】{}"
,
param
);
SopStruct
sop
=
sopService
.
loadSopByInstNodeId
(
param
.
getInstNodeId
());
SopStruct
sop
=
sopService
.
loadSopByInstNodeId
(
param
.
getInstNodeId
());
// 执行sop里面的instNodeId节点。
// 执行sop里面的instNodeId节点。
SopInstNode
node
=
sop
.
getInstNodeMap
().
get
(
param
.
getInstNodeId
());
SopInstNode
node
=
sop
.
getInstNodeMap
().
get
(
param
.
getInstNodeId
());
boolean
avaliable
=
checkPreIds
(
sop
,
node
,
param
);
boolean
avaliable
=
checkPreIds
(
sop
,
node
,
param
);
if
(!
avaliable
)
{
if
(!
avaliable
)
{
return
;
return
;
}
}
SopXxlJobUtil
.
log
(
log
,
"【执行Sop节点】{}【{}:{}】 开始执行......"
,
sop
.
getInst
().
getInstName
(),
node
.
getNodeId
(),
node
.
getNodeName
());
SopXxlJobUtil
.
log
(
log
,
"【执行Sop节点】{}【{}:{}】 开始执行......"
,
sop
.
getInst
().
getInstName
(),
node
.
getNodeId
(),
node
.
getNodeName
());
// 节点执行
// 节点执行
execute
(
sop
,
node
);
execute
(
sop
,
node
);
// 记录节点执行结果
// 记录节点执行结果
}
}
/**
/**
* 检查本节点的前置任务是否完成,如果前置任务是异步任务,则忽略
* 检查本节点的前置任务是否完成,如果前置任务是异步任务,则忽略
*
*
* @param sop
* @param sop
* @param node
* @param node
* @param param
* @param param
* @return
* @return
*/
*/
private
boolean
checkPreIds
(
SopStruct
sop
,
SopInstNode
node
,
SopInstNodeParam
param
)
{
private
boolean
checkPreIds
(
SopStruct
sop
,
SopInstNode
node
,
SopInstNodeParam
param
)
{
Pair
<
Set
<
Integer
>,
Set
<
Integer
>>
pair
=
sop
.
getInstLinkMap
().
get
(
node
.
getNodeId
());
Pair
<
Set
<
Integer
>,
Set
<
Integer
>>
pair
=
sop
.
getInstLinkMap
().
get
(
node
.
getNodeId
());
// 前置任务为空,直接执行
// 前置任务为空,直接执行
if
(
pair
.
getKey
().
isEmpty
())
{
if
(
pair
.
getKey
().
isEmpty
())
{
return
true
;
return
true
;
}
}
// 前置任务已完成,可以执行
// 前置任务已完成,可以执行
if
(
param
.
getFinishedIds
().
containsAll
(
pair
.
getKey
()))
{
if
(
param
.
getFinishedIds
().
containsAll
(
pair
.
getKey
()))
{
return
true
;
return
true
;
}
}
// 前置任务是异步任务,可以执行
// 前置任务是异步任务,可以执行
for
(
Integer
preId
:
pair
.
getKey
())
{
for
(
Integer
preId
:
pair
.
getKey
())
{
SopInstNode
preNode
=
sop
.
getInstNodeMap
().
get
(
preId
);
SopInstNode
preNode
=
sop
.
getInstNodeMap
().
get
(
preId
);
if
(
preNode
!=
null
&&
preNode
.
getNodeAsync
()
!=
1
&&
!
param
.
getFinishedIds
().
contains
(
preId
))
{
if
(
preNode
!=
null
&&
preNode
.
getNodeAsync
()
!=
1
&&
!
param
.
getFinishedIds
().
contains
(
preId
))
{
SopXxlJobUtil
.
log
(
log
,
"【执行Sop节点】【{}:{}】,存在前置任务未完成:【{}:{}】"
,
sop
.
getInst
().
getInstId
(),
sop
.
getInst
().
getInstName
(),
SopXxlJobUtil
.
log
(
log
,
"【执行Sop节点】【{}:{}】,存在前置任务未完成:【{}:{}】"
,
sop
.
getInst
().
getInstId
(),
sop
.
getInst
().
getInstName
(),
preNode
.
getInstId
(),
preNode
.
getNodeName
());
preNode
.
getInstId
(),
preNode
.
getNodeName
());
return
false
;
return
false
;
}
}
}
}
return
true
;
return
true
;
}
}
/**
/**
* 节点执行时,申请sop锁
* 节点执行时,申请sop锁
*
*
* @param node 节点信息
* @param node 节点信息
* @param sop 执行器
* @param sop 执行器
*/
*/
public
void
execute
(
SopStruct
sop
,
SopInstNode
node
)
{
public
void
execute
(
SopStruct
sop
,
SopInstNode
node
)
{
SopNodeType
type
=
SopNodeType
.
fromBusType
(
node
.
getNodeType
());
SopNodeType
type
=
SopNodeType
.
fromBusType
(
node
.
getNodeType
());
SopNodeExecutor
instance
=
SopNodeExecutorFactory
.
getInstance
(
type
.
getHanderImp
(),
SopNodeExecutor
.
class
);
SopNodeExecutor
instance
=
SopNodeExecutorFactory
.
getInstance
(
type
.
getHanderImp
(),
SopNodeExecutor
.
class
);
// 执行sop节点前,锁定sop
// 执行sop节点前,锁定sop
if
(
SopHelper
.
lockInst
(
sop
.
getInst
()))
{
if
(
SopHelper
.
lockInst
(
sop
.
getInst
()))
{
try
{
try
{
// 重新加载sop
// 重新加载sop
sop
=
reloadAndCreateBatch
(
sop
,
node
);
sop
=
reloadAndCreateBatch
(
sop
,
node
);
// 执行sop节点
// 执行sop节点
ExecuteStruct
result
=
instance
.
execute
(
sop
,
node
);
ExecuteStruct
result
=
instance
.
execute
(
sop
,
node
);
//更新节点批次快照信息
updateBatch
(
sop
,
node
,
result
);
updateBatch
(
sop
,
node
,
result
);
updateNextNodes
(
sop
,
node
);
// 更新下个节点信息
updateNextNodes
(
sop
,
node
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
Exception
e
)
{
}
finally
{
throw
new
RuntimeException
(
e
);
SopHelper
.
unlockInst
(
sop
.
getInst
());
}
finally
{
}
SopHelper
.
unlockInst
(
sop
.
getInst
());
}
}
else
{
SopXxlJobUtil
.
log
(
log
,
"【执行Sop节点】【{}:{}】,申请实例锁失败,本次不执行!"
,
sop
.
getInst
().
getInstId
(),
sop
.
getInst
().
getInstName
());
}
else
{
return
;
SopXxlJobUtil
.
log
(
log
,
"【执行Sop节点】【{}:{}】,申请实例锁失败,本次不执行!"
,
sop
.
getInst
().
getInstId
(),
sop
.
getInst
().
getInstName
());
}
return
;
}
}
}
private
void
updateNextNodes
(
SopStruct
sop
,
SopInstNode
node
)
{
SopXxlJobUtil
.
finishSopNodeJob
(
sop
,
node
);
private
void
updateNextNodes
(
SopStruct
sop
,
SopInstNode
node
)
{
}
SopXxlJobUtil
.
finishSopNodeJob
(
sop
,
node
);
}
private
void
updateBatch
(
SopStruct
sop
,
SopInstNode
node
,
ExecuteStruct
result
)
{
SopInstNodeBatch
nodeBatch
=
sop
.
getNodeBatch
();
private
void
updateBatch
(
SopStruct
sop
,
SopInstNode
node
,
ExecuteStruct
result
)
{
nodeBatch
.
setSnapshot
(
JSONUtil
.
toJsonStr
(
result
));
// TODO 这里需要考虑合并结果
SopInstNodeBatch
nodeBatch
=
sop
.
getNodeBatch
();
nodeBatch
.
setUpdateTime
(
new
Date
());
nodeBatch
.
setSnapshot
(
JSONUtil
.
toJsonStr
(
result
));
sopService
.
updateInstNodeBatch
(
nodeBatch
);
nodeBatch
.
setUpdateTime
(
new
Date
());
}
sopService
.
updateInstNodeBatch
(
nodeBatch
);
}
private
SopStruct
reloadAndCreateBatch
(
SopStruct
sop
,
SopInstNode
node
)
{
sop
=
sopService
.
loadSop
(
sop
.
getInst
().
getInstId
());
private
SopStruct
reloadAndCreateBatch
(
SopStruct
sop
,
SopInstNode
node
)
{
// 创建节点执行批次
sop
=
sopService
.
loadSop
(
sop
.
getInst
().
getInstId
());
SopInstNodeBatch
curBatch
=
sopService
.
createNodeBatch
(
sop
.
getInst
().
getBatchNo
(),
node
.
getInstNodeId
());
// 创建节点执行批次
sop
.
setNodeBatch
(
curBatch
);
SopInstNodeBatch
curBatch
=
sopService
.
createNodeBatch
(
sop
.
getInst
().
getBatchNo
(),
node
.
getInstNodeId
());
return
sop
;
sop
.
setNodeBatch
(
curBatch
);
}
return
sop
;
}
}
}
platform-process/src/main/java/cn/com/glsx/process/modules/sop/execute/executor/StartExecutor.java
View file @
785a366
...
@@ -3,7 +3,6 @@ package cn.com.glsx.process.modules.sop.execute.executor;
...
@@ -3,7 +3,6 @@ package cn.com.glsx.process.modules.sop.execute.executor;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
cn.com.glsx.process.common.constant.Constants
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
...
@@ -15,14 +14,12 @@ import cn.hutool.json.JSONObject;
...
@@ -15,14 +14,12 @@ import cn.hutool.json.JSONObject;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.Map
;
/**
/**
* 开始节点:
* 开始节点:
* 1.从SopInst提取初始化参数;
* 1.从SopInst提取初始化参数;
* 2.记录开始节点快照,更新Sop快照;
* 2.记录开始节点快照,更新Sop快照;
* 3.更新触发后置任务;
* 3.更新触发后置任务;
*
*
* @author kome
* @author kome
* @date 2023年9月19日 下午5:42:59
* @date 2023年9月19日 下午5:42:59
*/
*/
...
@@ -30,25 +27,27 @@ import java.util.Map;
...
@@ -30,25 +27,27 @@ import java.util.Map;
@Service
@Service
public
class
StartExecutor
implements
SopNodeExecutor
{
public
class
StartExecutor
implements
SopNodeExecutor
{
@Resource
@Resource
private
SopService
sopService
;
private
SopService
sopService
;
@Override
public
ExecuteStruct
execute
(
SopStruct
sop
,
SopInstNode
node
)
throws
Exception
{
ExecuteStruct
executeStruct
=
prepare
(
sop
,
node
);
@Override
return
executeStruct
;
public
ExecuteStruct
execute
(
SopStruct
sop
,
SopInstNode
node
)
throws
Exception
{
}
ExecuteStruct
executeStruct
=
prepare
(
sop
,
node
);
Map
<
String
,
Object
>
resultMap
=
executeStruct
.
getResultMap
();
public
void
updateBatch
()
{
resultMap
.
put
(
Constants
.
RES_KEY
,
Constants
.
RES_SUCCESS
);
return
executeStruct
;
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
String
json
=
"{\"merchantId\":{\"paramName\":\"merchantId\",\"paramDesc\":\"门店id,分配给门店时需要赋值\",\"valueType\":\"String\",\"defaultValue\":\"\",\"required\":true},\"stages\":{\"paramName\":\"stages\",\"paramDesc\":\"旅程阶段,值类型为Json\",\"valueType\":\"Json\",\"defaultValue\":{\"stage1\":{\"value\":\"潜客\",\"editable\":false,\"conditions\":[\"链接(#膨胀金活动名称#) 反馈\",\"链接(#膨胀金活动名称#) 反馈\"]},\"stage2\":{\"value\":\"高意向\",\"editable\":true,\"conditions\":[\"链接(#膨胀金活动名称#) 反馈\",\"链接(#膨胀金活动名称#) 反馈\"]},\"stage3\":{\"value\":\"下单\",\"editable\":false,\"conditions\":[\"链接(#膨胀金活动名称#) 反馈\",\"链接(#膨胀金活动名称#) 反馈\"]},\"stage4\":{\"value\":\"战败\",\"editable\":false,\"conditions\":[\"链接(#膨胀金活动名称#) 反馈\",\"链接(#膨胀金活动名称#) 反馈\"]}},\"required\":true},\"users\":{\"paramName\":\"users\",\"paramDesc\":\"通过膨胀金活动导入的用户信息\",\"valueType\":\"Json\",\"defaultValue\":{\"u0001\":{\"userId\":\"u0001\",\"userName\":\"张三\",\"followId\":\"跟进人id1\",\"textContent\":\"文案内容:尊敬的${userName},优惠券领取url.cn/dE32C1Ab7\"},\"u0002\":{\"userId\":\"u0002\",\"userName\":\"李四\",\"followId\":\"跟进人id2\",\"textContent\":\"文案内容:尊敬的${userName},优惠券领取url.cn/dE32C1Ab7\"}},\"required\":true}}"
;
String
json
=
"{\"merchantId\":{\"paramName\":\"merchantId\",\"paramDesc\":\"门店id,分配给门店时需要赋值\",\"valueType\":\"String\",\"defaultValue\":\"\",\"required\":true},\"stages\":{\"paramName\":\"stages\",\"paramDesc\":\"旅程阶段,值类型为Json\",\"valueType\":\"Json\",\"defaultValue\":{\"stage1\":{\"value\":\"潜客\",\"editable\":false,\"conditions\":[\"链接(#膨胀金活动名称#) 反馈\",\"链接(#膨胀金活动名称#) 反馈\"]},\"stage2\":{\"value\":\"高意向\",\"editable\":true,\"conditions\":[\"链接(#膨胀金活动名称#) 反馈\",\"链接(#膨胀金活动名称#) 反馈\"]},\"stage3\":{\"value\":\"下单\",\"editable\":false,\"conditions\":[\"链接(#膨胀金活动名称#) 反馈\",\"链接(#膨胀金活动名称#) 反馈\"]},\"stage4\":{\"value\":\"战败\",\"editable\":false,\"conditions\":[\"链接(#膨胀金活动名称#) 反馈\",\"链接(#膨胀金活动名称#) 反馈\"]}},\"required\":true},\"users\":{\"paramName\":\"users\",\"paramDesc\":\"通过膨胀金活动导入的用户信息\",\"valueType\":\"Json\",\"defaultValue\":{\"u0001\":{\"userId\":\"u0001\",\"userName\":\"张三\",\"followId\":\"跟进人id1\",\"textContent\":\"文案内容:尊敬的${userName},优惠券领取url.cn/dE32C1Ab7\"},\"u0002\":{\"userId\":\"u0002\",\"userName\":\"李四\",\"followId\":\"跟进人id2\",\"textContent\":\"文案内容:尊敬的${userName},优惠券领取url.cn/dE32C1Ab7\"}},\"required\":true}}"
;
JSONObject
paramObj
=
JSONUtil
.
parseObj
(
json
);
JSONObject
paramObj
=
JSONUtil
.
parseObj
(
json
);
System
.
out
.
println
(
paramObj
.
get
(
"merchantId"
));
System
.
out
.
println
(
paramObj
.
get
(
"merchantId"
));
}
}
}
}
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment