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 b8bd7677
authored
Sep 21, 2023
by
tiger
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
sql执行
1 parent
c88f694c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
100 additions
and
96 deletions
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/core/SopXxlJobUtil.java
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/core/XxlJobUtil.java
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/impl/SopInstLoadJobHandler.java
platform-process/src/main/java/cn/com/glsx/process/modules/service/SopService.java
platform-process/src/main/java/cn/com/glsx/process/modules/sop/execute/SnapshotStruct.java
platform-process/src/main/java/cn/com/glsx/process/modules/sop/execute/SopNodeExecutor.java
platform-process/src/main/java/cn/com/glsx/process/modules/sop/execute/executor/SqlExecutor.java
platform-process/src/main/java/cn/com/glsx/process/modules/sop/execute/executor/SqlQueryExecutor.java
platform-process/src/main/java/cn/com/glsx/process/modules/sop/java/example/ControllerXblcCustomerQuery.java
platform-process/src/main/java/cn/com/glsx/process/util/FreemarkerUtil.java
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/core/SopXxlJobUtil.java
View file @
b8bd767
...
@@ -61,9 +61,7 @@ public class SopXxlJobUtil {
...
@@ -61,9 +61,7 @@ public class SopXxlJobUtil {
if
(
job
==
null
)
{
if
(
job
==
null
)
{
job
=
new
XxlJobInfo
();
job
=
new
XxlJobInfo
();
}
}
job
.
setExecutorParam
(
""
);
job
.
setJobDesc
(
"加载所有SOP实例任务"
);
job
.
setJobDesc
(
"加载所有SOP实例任务"
);
job
.
setAuthor
(
"admin"
);
job
.
setScheduleConf
(
"10 */5 * * * ?"
);
job
.
setScheduleConf
(
"10 */5 * * * ?"
);
job
.
setExecutorHandler
(
SOP_LOAD_JOB_ID
);
job
.
setExecutorHandler
(
SOP_LOAD_JOB_ID
);
job
.
setBusKey
(
SOP_LOAD_JOB_ID
);
job
.
setBusKey
(
SOP_LOAD_JOB_ID
);
...
...
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/core/XxlJobUtil.java
View file @
b8bd767
...
@@ -66,6 +66,7 @@ public class XxlJobUtil {
...
@@ -66,6 +66,7 @@ public class XxlJobUtil {
**/
**/
public
static
String
add
(
XxlJobInfo
jobInfo
)
{
public
static
String
add
(
XxlJobInfo
jobInfo
)
{
jobInfo
.
setJobGroup
(
groupId
);
jobInfo
.
setJobGroup
(
groupId
);
jobInfo
.
setAuthor
(
"admin"
);
jobInfo
.
setGlueType
(
"BEAN"
);
jobInfo
.
setGlueType
(
"BEAN"
);
jobInfo
.
setExecutorBlockStrategy
(
"SERIAL_EXECUTION"
);
jobInfo
.
setExecutorBlockStrategy
(
"SERIAL_EXECUTION"
);
jobInfo
.
setExecutorRouteStrategy
(
"RANDOM"
);
jobInfo
.
setExecutorRouteStrategy
(
"RANDOM"
);
...
...
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/impl/SopInstLoadJobHandler.java
View file @
b8bd767
package
cn
.
com
.
glsx
.
process
.
job
.
xxljob
.
impl
;
package
cn
.
com
.
glsx
.
process
.
job
.
xxljob
.
impl
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
...
@@ -29,9 +30,13 @@ public class SopInstLoadJobHandler {
...
@@ -29,9 +30,13 @@ public class SopInstLoadJobHandler {
List
<
SopInst
>
all
=
sopService
.
loadAllInst
();
List
<
SopInst
>
all
=
sopService
.
loadAllInst
();
for
(
SopInst
inst
:
all
)
{
for
(
SopInst
inst
:
all
)
{
if
(
inst
.
getInstStatus
()
==
0
)
{
// 过期机制
// 停止实例任务以及所有子任务
if
(
inst
.
getExpireTime
()
!=
null
&&
inst
.
getExpireTime
().
before
(
new
Date
()))
{
inst
.
setInstStatus
((
byte
)
-
1
);
}
if
(
inst
.
getInstStatus
()
!=
1
)
{
// 停止实例任务以及所有子任务
SopStruct
sop
=
sopService
.
loadSop
(
inst
.
getInstId
());
SopStruct
sop
=
sopService
.
loadSop
(
inst
.
getInstId
());
SopXxlJobUtil
.
pauseSop
(
sop
);
SopXxlJobUtil
.
pauseSop
(
sop
);
continue
;
continue
;
...
...
platform-process/src/main/java/cn/com/glsx/process/modules/service/SopService.java
View file @
b8bd767
...
@@ -105,6 +105,11 @@ public class SopService {
...
@@ -105,6 +105,11 @@ public class SopService {
return
null
;
return
null
;
}
}
// 过期机制
if
(
inst
.
getExpireTime
()
!=
null
&&
inst
.
getExpireTime
().
before
(
new
Date
()))
{
inst
.
setInstStatus
((
byte
)
-
1
);
}
SopTplGrant
grant
=
grantMapper
.
selectByPrimaryKey
(
inst
.
getGrantId
());
SopTplGrant
grant
=
grantMapper
.
selectByPrimaryKey
(
inst
.
getGrantId
());
sop
.
setGrant
(
grant
);
sop
.
setGrant
(
grant
);
...
...
platform-process/src/main/java/cn/com/glsx/process/modules/sop/execute/SnapshotStruct.java
View file @
b8bd767
...
@@ -32,4 +32,10 @@ public class SnapshotStruct implements Serializable, Cloneable {
...
@@ -32,4 +32,10 @@ public class SnapshotStruct implements Serializable, Cloneable {
*/
*/
private
Map
<
String
,
Object
>
resultMap
=
Maps
.
newHashMap
();
private
Map
<
String
,
Object
>
resultMap
=
Maps
.
newHashMap
();
public
Map
<
String
,
Object
>
toMap
()
{
Map
<
String
,
Object
>
map
=
Maps
.
newHashMap
();
map
.
putAll
(
getInitMap
());
map
.
putAll
(
getResultMap
());
return
map
;
}
}
}
\ No newline at end of file
\ No newline at end of file
platform-process/src/main/java/cn/com/glsx/process/modules/sop/execute/SopNodeExecutor.java
View file @
b8bd767
...
@@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory;
...
@@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.util.FreemarkerUtil
;
import
cn.com.glsx.process.util.JacksonUtils
;
import
cn.com.glsx.process.util.JacksonUtils
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONObject
;
...
@@ -51,8 +52,11 @@ public interface SopNodeExecutor {
...
@@ -51,8 +52,11 @@ public interface SopNodeExecutor {
// 当前节点需要的参数
// 当前节点需要的参数
if
(
StrUtil
.
isNotEmpty
(
node
.
getNodeParam
()))
{
if
(
StrUtil
.
isNotEmpty
(
node
.
getNodeParam
()))
{
// 节点入参按freemarker语法替换
String
source
=
FreemarkerUtil
.
processContent
(
node
.
getNodeParam
(),
es
.
toMap
());
if
(
StrUtil
.
isNotEmpty
(
node
.
getNodeKey
()))
{
if
(
StrUtil
.
isNotEmpty
(
node
.
getNodeKey
()))
{
JSONObject
nodeParamObj
=
JSONUtil
.
parseObj
(
node
.
getNodeParam
()
);
JSONObject
nodeParamObj
=
JSONUtil
.
parseObj
(
source
);
es
.
getParamMap
().
put
(
node
.
getNodeKey
(),
nodeParamObj
);
es
.
getParamMap
().
put
(
node
.
getNodeKey
(),
nodeParamObj
);
}
else
{
}
else
{
log
.
warn
(
"【{}】nodeKey 为空!!!"
,
node
.
getInstId
()
+
"-"
+
node
.
getNodeId
());
log
.
warn
(
"【{}】nodeKey 为空!!!"
,
node
.
getInstId
()
+
"-"
+
node
.
getNodeId
());
...
...
platform-process/src/main/java/cn/com/glsx/process/modules/sop/execute/executor/SqlExecutor.java
View file @
b8bd767
package
cn
.
com
.
glsx
.
process
.
modules
.
sop
.
execute
.
executor
;
package
cn
.
com
.
glsx
.
process
.
modules
.
sop
.
execute
.
executor
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -12,83 +11,51 @@ import com.alibaba.fastjson.JSONObject;
...
@@ -12,83 +11,51 @@ import com.alibaba.fastjson.JSONObject;
import
cn.com.glsx.process.common.constant.Constants
;
import
cn.com.glsx.process.common.constant.Constants
;
import
cn.com.glsx.process.modules.entity.SopDataSource
;
import
cn.com.glsx.process.modules.entity.SopDataSource
;
import
cn.com.glsx.process.modules.entity.SopInst
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.service.SopDataSourceService
;
import
cn.com.glsx.process.modules.service.SopDataSourceService
;
import
cn.com.glsx.process.modules.sop.execute.SnapshotStruct
;
import
cn.com.glsx.process.modules.sop.execute.RunResult
;
import
cn.com.glsx.process.modules.sop.execute.RunResult
;
import
cn.com.glsx.process.modules.sop.execute.SnapshotStruct
;
import
cn.com.glsx.process.modules.sop.execute.SopNodeExecutor
;
import
cn.com.glsx.process.modules.sop.execute.SopNodeExecutor
;
import
cn.com.glsx.process.modules.sop.execute.plugin.dbconn.FlowDataAdapterImpl
;
import
cn.com.glsx.process.modules.sop.execute.plugin.dbconn.FlowDataAdapterImpl
;
import
cn.com.glsx.process.modules.sop.execute.plugin.dbconn.SopBizAdapter
;
import
cn.com.glsx.process.modules.sop.execute.plugin.dbconn.SopBizAdapter
;
import
cn.com.glsx.process.util.FreemarkerUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
@Slf4j
@Slf4j
@Service
@Service
public
class
SqlExecutor
implements
SopNodeExecutor
{
public
class
SqlExecutor
implements
SopNodeExecutor
{
@Autowired
@Autowired
private
SopDataSourceService
sopDataSourceService
;
private
SopDataSourceService
sopDataSourceService
;
@Override
@Override
public
RunResult
execute
(
SopStruct
sop
,
SopInstNode
node
,
SnapshotStruct
executeStruct
)
throws
Exception
{
public
RunResult
execute
(
SopStruct
sop
,
SopInstNode
node
,
SnapshotStruct
executeStruct
)
throws
Exception
{
Map
<
String
,
Object
>
resultMap
=
executeStruct
.
getResultMap
();
Map
<
String
,
Object
>
resultMap
=
executeStruct
.
getResultMap
();
try
{
try
{
// 获取配置参数信息
// 获取配置参数信息
String
nodeContent
=
node
.
getNodeContent
();
String
nodeContent
=
node
.
getNodeContent
();
JSONObject
paramMap
=
JSON
.
parseObject
(
nodeContent
);
JSONObject
paramMap
=
JSON
.
parseObject
(
nodeContent
);
String
sqlTemplate
=
paramMap
.
get
(
"source"
)
+
""
;
String
sqlcode
=
paramMap
.
get
(
"source"
)
+
""
;
String
dataSourceId
=
paramMap
.
get
(
"dataSourceId"
)
+
""
;
String
dataSourceId
=
paramMap
.
get
(
"dataSourceId"
)
+
""
;
// 执行sql插件
// 执行sql插件
SopDataSource
byId
=
sopDataSourceService
.
findByName
(
dataSourceId
);
SopDataSource
byId
=
sopDataSourceService
.
findByName
(
dataSourceId
);
SopBizAdapter
mcgBizAdapter
=
new
FlowDataAdapterImpl
(
byId
);
SopBizAdapter
mcgBizAdapter
=
new
FlowDataAdapterImpl
(
byId
);
String
sql
=
FreemarkerUtil
.
processContent
(
sqlTemplate
,
executeStruct
.
toMap
());
codeReplace
(
sqlcode
,
sop
,
node
);
int
i
=
mcgBizAdapter
.
executeUpdate
(
sql
);
int
i
=
mcgBizAdapter
.
executeUpdate
(
sqlcode
);
// 处理执行结果
// 处理执行结果
resultMap
.
put
(
Constants
.
RES_DATE_KEY
,
i
);
resultMap
.
put
(
Constants
.
RES_DATE_KEY
,
i
);
resultMap
.
put
(
Constants
.
RES_KEY
,
Constants
.
RES_SUCCESS
);
resultMap
.
put
(
Constants
.
RES_KEY
,
Constants
.
RES_SUCCESS
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
String
message
=
e
.
getMessage
();
String
message
=
e
.
getMessage
();
resultMap
.
put
(
Constants
.
RES_FAIL_MESSAGE
,
message
);
resultMap
.
put
(
Constants
.
RES_FAIL_MESSAGE
,
message
);
resultMap
.
put
(
Constants
.
RES_KEY
,
Constants
.
RES_FAIL
);
resultMap
.
put
(
Constants
.
RES_KEY
,
Constants
.
RES_FAIL
);
}
}
return
null
;
return
null
;
}
}
/**
* 替换sql里面的通配符
*
* @param sqlcode sql脚本
* @param sop sop实例
* @param node sop节点
*/
private
void
codeReplace
(
String
sqlcode
,
SopStruct
sop
,
SopInstNode
node
)
{
SopInst
inst
=
sop
.
getInst
();
String
instSnapshot
=
inst
.
getInstSnapshot
();
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
instSnapshot
);
// 替换关联业务的活动id
String
activityId
=
jsonObject
.
get
(
"activityId"
)
+
""
;
if
(
activityId
!=
null
)
{
sqlcode
.
replace
(
"#{activityId}"
,
activityId
);
}
// 替换关联的instId
if
(
activityId
!=
null
)
{
sqlcode
.
replace
(
"#{instId}"
,
inst
.
getInstId
());
}
String
nodeParam
=
node
.
getNodeParam
();
JSONObject
nodeJsonObject
=
JSONObject
.
parseObject
(
nodeParam
);
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
nodeJsonObject
.
entrySet
())
{
sqlcode
.
replace
(
"#{"
+
entry
.
getKey
()
+
"}"
,
entry
.
getValue
()
+
""
);
}
}
}
}
\ No newline at end of file
\ No newline at end of file
platform-process/src/main/java/cn/com/glsx/process/modules/sop/execute/executor/SqlQueryExecutor.java
View file @
b8bd767
...
@@ -12,15 +12,15 @@ import com.alibaba.fastjson.JSONObject;
...
@@ -12,15 +12,15 @@ import com.alibaba.fastjson.JSONObject;
import
cn.com.glsx.process.common.constant.Constants
;
import
cn.com.glsx.process.common.constant.Constants
;
import
cn.com.glsx.process.modules.entity.SopDataSource
;
import
cn.com.glsx.process.modules.entity.SopDataSource
;
import
cn.com.glsx.process.modules.entity.SopInst
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.service.SopDataSourceService
;
import
cn.com.glsx.process.modules.service.SopDataSourceService
;
import
cn.com.glsx.process.modules.sop.execute.SnapshotStruct
;
import
cn.com.glsx.process.modules.sop.execute.RunResult
;
import
cn.com.glsx.process.modules.sop.execute.RunResult
;
import
cn.com.glsx.process.modules.sop.execute.SnapshotStruct
;
import
cn.com.glsx.process.modules.sop.execute.SopNodeExecutor
;
import
cn.com.glsx.process.modules.sop.execute.SopNodeExecutor
;
import
cn.com.glsx.process.modules.sop.execute.plugin.dbconn.FlowDataAdapterImpl
;
import
cn.com.glsx.process.modules.sop.execute.plugin.dbconn.FlowDataAdapterImpl
;
import
cn.com.glsx.process.modules.sop.execute.plugin.dbconn.SopBizAdapter
;
import
cn.com.glsx.process.modules.sop.execute.plugin.dbconn.SopBizAdapter
;
import
cn.com.glsx.process.util.FreemarkerUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
@Slf4j
@Slf4j
...
@@ -37,14 +37,16 @@ public class SqlQueryExecutor implements SopNodeExecutor {
...
@@ -37,14 +37,16 @@ public class SqlQueryExecutor implements SopNodeExecutor {
// 获取配置参数信息
// 获取配置参数信息
String
nodeContent
=
node
.
getNodeContent
();
String
nodeContent
=
node
.
getNodeContent
();
JSONObject
paramMap
=
JSON
.
parseObject
(
nodeContent
);
JSONObject
paramMap
=
JSON
.
parseObject
(
nodeContent
);
String
sqlcod
e
=
paramMap
.
get
(
"source"
)
+
""
;
String
sqlTemplat
e
=
paramMap
.
get
(
"source"
)
+
""
;
String
dataSourceId
=
paramMap
.
get
(
"dataSourceId"
)
+
""
;
String
dataSourceId
=
paramMap
.
get
(
"dataSourceId"
)
+
""
;
// 执行sql插件
// 执行sql插件
SopDataSource
byId
=
sopDataSourceService
.
findByName
(
dataSourceId
);
SopDataSource
byId
=
sopDataSourceService
.
findByName
(
dataSourceId
);
SopBizAdapter
mcgBizAdapter
=
new
FlowDataAdapterImpl
(
byId
);
SopBizAdapter
mcgBizAdapter
=
new
FlowDataAdapterImpl
(
byId
);
List
<
Map
<
String
,
Object
>>
maps
=
mcgBizAdapter
.
tableQuery
(
sqlcode
);
codeReplace
(
sqlcode
,
sop
,
node
);
String
sql
=
FreemarkerUtil
.
processContent
(
sqlTemplate
,
executeStruct
.
toMap
());
List
<
Map
<
String
,
Object
>>
maps
=
mcgBizAdapter
.
tableQuery
(
sql
);
// 处理执行结果
// 处理执行结果
resultMap
.
put
(
Constants
.
RES_DATE_KEY
,
maps
);
resultMap
.
put
(
Constants
.
RES_DATE_KEY
,
maps
);
...
@@ -57,28 +59,5 @@ public class SqlQueryExecutor implements SopNodeExecutor {
...
@@ -57,28 +59,5 @@ public class SqlQueryExecutor implements SopNodeExecutor {
return
null
;
return
null
;
}
}
private
void
codeReplace
(
String
sqlcode
,
SopStruct
sop
,
SopInstNode
node
)
{
SopInst
inst
=
sop
.
getInst
();
String
instSnapshot
=
inst
.
getInstSnapshot
();
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
instSnapshot
);
// 替换关联业务的活动id
String
activityId
=
jsonObject
.
get
(
"activityId"
)
+
""
;
if
(
activityId
!=
null
)
{
sqlcode
.
replace
(
"#{activityId}"
,
activityId
);
}
// 替换关联的instId
if
(
activityId
!=
null
)
{
sqlcode
.
replace
(
"#{instId}"
,
inst
.
getInstId
());
}
String
nodeParam
=
node
.
getNodeParam
();
JSONObject
nodeJsonObject
=
JSONObject
.
parseObject
(
nodeParam
);
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
nodeJsonObject
.
entrySet
())
{
sqlcode
.
replace
(
"#{"
+
entry
.
getKey
()
+
"}"
,
entry
.
getValue
()
+
""
);
}
}
}
}
\ No newline at end of file
\ No newline at end of file
platform-process/src/main/java/cn/com/glsx/process/modules/sop/java/example/ControllerXblcCustomerQuery.java
0 → 100644
View file @
b8bd767
package
cn
.
com
.
glsx
.
process
.
modules
.
sop
.
java
.
example
;
import
org.springframework.web.client.RestTemplate
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
/**
* 续保旅程中,圈人节点,按输入参数中的标签来圈人
*
* @author kome
* @date 2023年9月21日 下午2:04:17
*/
public
class
ControllerXblcCustomerQuery
{
private
static
String
baseurl
=
"http://192.168.0.63:9823/process/sop/xxljob/testJava"
;
/**
* <code>
{
"merchantId": "M153312087",
"stages": {
...
},
"sopTag": "xblc" // select * from cdp_user where tag_xblc=1
}
* </code>
*
* @param param
* @return
*/
public
static
JSON
execute
(
JSON
param
)
{
// 走sql或http查询用户列表
RestTemplate
restTemplate
=
new
RestTemplate
();
Object
o
=
restTemplate
.
postForObject
(
baseurl
+
"?busKey="
+
11
,
param
,
Object
.
class
);
return
(
JSONObject
)
JSONObject
.
toJSON
(
o
);
}
}
\ No newline at end of file
\ No newline at end of file
platform-process/src/main/java/cn/com/glsx/process/util/FreemarkerUtil.java
0 → 100644
View file @
b8bd767
This diff is collapsed.
Click to expand it.
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