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 55ba8505
authored
Sep 25, 2023
by
tiger
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
sop params
1 parent
c66bcbf0
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
474 additions
and
326 deletions
platform-process-api/src/main/java/cn/com/glsx/process/modules/mapper/SopInstMapper.java
platform-process-api/src/main/java/cn/com/glsx/process/modules/model/SopStruct.java
platform-process/src/main/java/cn/com/glsx/Application.java
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/impl/SopInstNodeExecuteJobHandler.java
platform-process/src/main/java/cn/com/glsx/process/modules/controller/SopController.java
platform-process/src/main/java/cn/com/glsx/process/modules/service/SopInstService.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/SopHelper.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/JavaExecutor.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/resources/mapper/SopInstMapper.xml
platform-process-api/src/main/java/cn/com/glsx/process/modules/mapper/SopInstMapper.java
View file @
55ba850
...
@@ -3,13 +3,13 @@ package cn.com.glsx.process.modules.mapper;
...
@@ -3,13 +3,13 @@ package cn.com.glsx.process.modules.mapper;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
cn.com.glsx.process.modules.model.SopInstDTO
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
import
com.glsx.plat.mybatis.mapper.CommonBaseMapper
;
import
com.glsx.plat.mybatis.mapper.CommonBaseMapper
;
import
cn.com.glsx.process.modules.entity.SopInst
;
import
cn.com.glsx.process.modules.entity.SopInst
;
import
cn.com.glsx.process.modules.model.SopInstDTO
;
import
cn.com.glsx.process.modules.model.SopInstSearch
;
import
cn.com.glsx.process.modules.model.SopInstSearch
;
@Mapper
@Mapper
...
@@ -41,7 +41,7 @@ public interface SopInstMapper extends CommonBaseMapper<SopInst> {
...
@@ -41,7 +41,7 @@ public interface SopInstMapper extends CommonBaseMapper<SopInst> {
*/
*/
void
updateInstStatus
(
@Param
(
"instId"
)
String
instId
,
@Param
(
"status"
)
Byte
status
);
void
updateInstStatus
(
@Param
(
"instId"
)
String
instId
,
@Param
(
"status"
)
Byte
status
);
void
updateInstBatchNo
(
@Param
(
"instId"
)
String
instId
,
@Param
(
"batchNo"
)
String
batchNo
);
void
updateInstBatchNo
(
@Param
(
"instId"
)
String
instId
,
@Param
(
"batchNo"
)
String
batchNo
,
@Param
(
"snapshot"
)
String
snapshot
);
/**
/**
* 分页查询模板实例列表
* 分页查询模板实例列表
...
...
platform-process-api/src/main/java/cn/com/glsx/process/modules/model/SopStruct.java
View file @
55ba850
...
@@ -11,25 +11,22 @@ import cn.com.glsx.process.modules.entity.SopInst;
...
@@ -11,25 +11,22 @@ import cn.com.glsx.process.modules.entity.SopInst;
import
cn.com.glsx.process.modules.entity.SopInstBatch
;
import
cn.com.glsx.process.modules.entity.SopInstBatch
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.entity.SopInstNodeBatch
;
import
cn.com.glsx.process.modules.entity.SopInstNodeBatch
;
import
cn.com.glsx.process.modules.entity.SopTpl
;
import
cn.com.glsx.process.modules.entity.SopTplGrant
;
import
cn.com.glsx.process.modules.entity.SopTplNode
;
import
cn.hutool.core.lang.Pair
;
import
cn.hutool.core.lang.Pair
;
import
lombok.Data
;
import
lombok.Data
;
@Data
@Data
public
class
SopStruct
{
public
class
SopStruct
{
/** 模板 */
/** 模板
,暂时不关注
*/
private
SopTpl
tpl
;
//
private SopTpl tpl;
/** 模板节点表 */
/** 模板节点表
,暂时不关注
*/
private
Map
<
Integer
,
SopTplNode
>
tplNodeMap
;
//
private Map<Integer, SopTplNode> tplNodeMap;
/** 模板节点连接关系: fromSet, toSet,暂时不关注 */
/** 模板节点连接关系: fromSet, toSet,暂时不关注 */
// private Map<Integer, Pair<Set<Integer>, Set<Integer>>> tplLinkMap;
// private Map<Integer, Pair<Set<Integer>, Set<Integer>>> tplLinkMap;
/** 模板分配 */
/** 模板分配 */
private
SopTplGrant
grant
;
//
private SopTplGrant grant;
/** 模板实例 */
/** 模板实例 */
private
SopInst
inst
;
private
SopInst
inst
;
...
...
platform-process/src/main/java/cn/com/glsx/Application.java
View file @
55ba850
...
@@ -14,6 +14,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
...
@@ -14,6 +14,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
import
org.springframework.context.annotation.EnableAspectJAutoProxy
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
com.glsx.plat.context.EnableRestAdmin
;
import
com.glsx.plat.context.EnableRestAdmin
;
...
@@ -28,6 +29,7 @@ import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil;
...
@@ -28,6 +29,7 @@ import cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil;
@EnableFeignClients
(
basePackages
=
{
"cn.com.glsx.*.api"
,
"cn.com.glsx.process.modules.client"
})
@EnableFeignClients
(
basePackages
=
{
"cn.com.glsx.*.api"
,
"cn.com.glsx.process.modules.client"
})
@SpringBootApplication
@SpringBootApplication
@EnableAspectJAutoProxy
@EnableAspectJAutoProxy
@EnableTransactionManagement
public
class
Application
implements
CommandLineRunner
{
public
class
Application
implements
CommandLineRunner
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/impl/SopInstNodeExecuteJobHandler.java
View file @
55ba850
...
@@ -145,6 +145,7 @@ public class SopInstNodeExecuteJobHandler {
...
@@ -145,6 +145,7 @@ public class SopInstNodeExecuteJobHandler {
}
}
private
void
updateNextNodes
(
SopStruct
sop
,
SopInstNode
node
)
{
private
void
updateNextNodes
(
SopStruct
sop
,
SopInstNode
node
)
{
// TODO 是否需要触发后续任务
SopXxlJobUtil
.
finishSopNodeJob
(
sop
,
node
);
SopXxlJobUtil
.
finishSopNodeJob
(
sop
,
node
);
}
}
...
...
platform-process/src/main/java/cn/com/glsx/process/modules/controller/SopController.java
View file @
55ba850
...
@@ -45,4 +45,14 @@ public class SopController {
...
@@ -45,4 +45,14 @@ public class SopController {
return
Result
.
success
(
"已刷新:"
+
rs
);
return
Result
.
success
(
"已刷新:"
+
rs
);
}
}
@Operation
(
summary
=
"从实例反推模板"
,
description
=
"注意先把模板清理掉"
)
@GetMapping
(
value
=
"/inst/to/tpl/{instId}"
)
public
Result
<
String
>
instToTpl
(
@PathVariable
(
"instId"
)
String
instId
)
{
SopStruct
sop
=
sopService
.
loadSop
(
instId
);
sopService
.
generateTplFromInst
(
sop
);
return
Result
.
success
(
"已生成模板!"
);
}
}
}
platform-process/src/main/java/cn/com/glsx/process/modules/service/SopInstService.java
View file @
55ba850
...
@@ -63,7 +63,7 @@ public class SopInstService {
...
@@ -63,7 +63,7 @@ public class SopInstService {
private
CustomerSopJourneyFeignClient_T
customerSopJourneyFeignClientT
;
private
CustomerSopJourneyFeignClient_T
customerSopJourneyFeignClientT
;
@Autowired
@Autowired
private
MsgProducer
msgProducer
;
private
MsgProducer
msgProducer
;
/**
/**
* 根据id查询
* 根据id查询
...
...
platform-process/src/main/java/cn/com/glsx/process/modules/service/SopService.java
View file @
55ba850
...
@@ -3,6 +3,7 @@ package cn.com.glsx.process.modules.service;
...
@@ -3,6 +3,7 @@ package cn.com.glsx.process.modules.service;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -10,10 +11,12 @@ import javax.annotation.Resource;
...
@@ -10,10 +11,12 @@ import javax.annotation.Resource;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.alibaba.nacos.shaded.com.google.common.collect.Maps
;
import
com.alibaba.nacos.shaded.com.google.common.collect.Maps
;
import
com.alibaba.nacos.shaded.com.google.common.collect.Sets
;
import
com.alibaba.nacos.shaded.com.google.common.collect.Sets
;
import
com.glsx.plat.common.utils.SnowFlake
;
import
com.glsx.plat.common.utils.SnowFlake
;
import
com.google.common.collect.Lists
;
import
cn.com.glsx.process.modules.entity.SopInst
;
import
cn.com.glsx.process.modules.entity.SopInst
;
import
cn.com.glsx.process.modules.entity.SopInstBatch
;
import
cn.com.glsx.process.modules.entity.SopInstBatch
;
...
@@ -21,7 +24,7 @@ import cn.com.glsx.process.modules.entity.SopInstLink;
...
@@ -21,7 +24,7 @@ import cn.com.glsx.process.modules.entity.SopInstLink;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.entity.SopInstNodeBatch
;
import
cn.com.glsx.process.modules.entity.SopInstNodeBatch
;
import
cn.com.glsx.process.modules.entity.SopTpl
;
import
cn.com.glsx.process.modules.entity.SopTpl
;
import
cn.com.glsx.process.modules.entity.SopTpl
Grant
;
import
cn.com.glsx.process.modules.entity.SopTpl
Link
;
import
cn.com.glsx.process.modules.entity.SopTplNode
;
import
cn.com.glsx.process.modules.entity.SopTplNode
;
import
cn.com.glsx.process.modules.mapper.SopInstBatchMapper
;
import
cn.com.glsx.process.modules.mapper.SopInstBatchMapper
;
import
cn.com.glsx.process.modules.mapper.SopInstLinkMapper
;
import
cn.com.glsx.process.modules.mapper.SopInstLinkMapper
;
...
@@ -33,8 +36,13 @@ import cn.com.glsx.process.modules.mapper.SopTplLinkMapper;
...
@@ -33,8 +36,13 @@ import cn.com.glsx.process.modules.mapper.SopTplLinkMapper;
import
cn.com.glsx.process.modules.mapper.SopTplMapper
;
import
cn.com.glsx.process.modules.mapper.SopTplMapper
;
import
cn.com.glsx.process.modules.mapper.SopTplNodeMapper
;
import
cn.com.glsx.process.modules.mapper.SopTplNodeMapper
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.sop.execute.SnapshotStruct
;
import
cn.com.glsx.process.util.JacksonUtils
;
import
cn.hutool.core.lang.Pair
;
import
cn.hutool.core.lang.Pair
;
import
cn.hutool.core.util.NumberUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
tk.mybatis.mapper.entity.Example
;
import
tk.mybatis.mapper.entity.Example
;
import
tk.mybatis.mapper.util.Sqls
;
import
tk.mybatis.mapper.util.Sqls
;
...
@@ -110,16 +118,16 @@ public class SopService {
...
@@ -110,16 +118,16 @@ public class SopService {
inst
.
setInstStatus
((
byte
)
-
1
);
inst
.
setInstStatus
((
byte
)
-
1
);
}
}
SopTplGrant
grant
=
grantMapper
.
selectByPrimaryKey
(
inst
.
getGrantId
());
//
SopTplGrant grant = grantMapper.selectByPrimaryKey(inst.getGrantId());
sop
.
setGrant
(
grant
);
//
sop.setGrant(grant);
SopTpl
tpl
=
tplMapper
.
selectByPrimaryKey
(
grant
.
getTplId
());
//
SopTpl tpl = tplMapper.selectByPrimaryKey(grant.getTplId());
sop
.
setTpl
(
tpl
);
//
sop.setTpl(tpl);
List
<
SopTplNode
>
tplNodes
=
tplNodeMapper
//
List<SopTplNode> tplNodes = tplNodeMapper
.
selectByExample
(
Example
.
builder
(
SopTplNode
.
class
).
where
(
Sqls
.
custom
().
andEqualTo
(
"tplId"
,
grant
.
getTplId
())).
build
());
//
.selectByExample(Example.builder(SopTplNode.class).where(Sqls.custom().andEqualTo("tplId", grant.getTplId())).build());
Map
<
Integer
,
SopTplNode
>
tplNodeMap
=
tplNodes
.
stream
().
collect
(
Collectors
.
toMap
(
SopTplNode:
:
getNodeId
,
obj
->
obj
,
(
key1
,
key2
)
->
key1
));
//
Map<Integer, SopTplNode> tplNodeMap = tplNodes.stream().collect(Collectors.toMap(SopTplNode::getNodeId, obj -> obj, (key1, key2) -> key1));
sop
.
setTplNodeMap
(
tplNodeMap
);
//
sop.setTplNodeMap(tplNodeMap);
List
<
SopInstNode
>
instNodes
=
instNodeMapper
List
<
SopInstNode
>
instNodes
=
instNodeMapper
.
selectByExample
(
Example
.
builder
(
SopInstNode
.
class
).
where
(
Sqls
.
custom
().
andEqualTo
(
"instId"
,
inst
.
getInstId
())).
build
());
.
selectByExample
(
Example
.
builder
(
SopInstNode
.
class
).
where
(
Sqls
.
custom
().
andEqualTo
(
"instId"
,
inst
.
getInstId
())).
build
());
...
@@ -159,11 +167,14 @@ public class SopService {
...
@@ -159,11 +167,14 @@ public class SopService {
batch
.
setCreateTime
(
new
Date
());
batch
.
setCreateTime
(
new
Date
());
batch
.
setUpdateTime
(
new
Date
());
batch
.
setUpdateTime
(
new
Date
());
batch
.
setInstId
(
sopInst
.
getInstId
());
batch
.
setInstId
(
sopInst
.
getInstId
());
batch
.
setSnapshot
(
StrUtil
.
blankToDefault
(
sopInst
.
getInstSnapshot
(),
"{}"
));
SnapshotStruct
ss
=
JacksonUtils
.
fromJson
(
StrUtil
.
blankToDefault
(
sopInst
.
getInstSnapshot
(),
"{}"
),
SnapshotStruct
.
class
);
ss
.
getResultMap
().
clear
();
batch
.
setSnapshot
(
JacksonUtils
.
toJson
(
ss
));
instBatchMapper
.
insert
(
batch
);
instBatchMapper
.
insert
(
batch
);
instMapper
.
updateInstBatchNo
(
sopInst
.
getInstId
(),
batch
.
getBatchNo
());
instMapper
.
updateInstBatchNo
(
sopInst
.
getInstId
(),
batch
.
getBatchNo
()
,
batch
.
getSnapshot
()
);
return
batch
;
return
batch
;
}
}
...
@@ -199,4 +210,133 @@ public class SopService {
...
@@ -199,4 +210,133 @@ public class SopService {
instNodeMapper
.
resetInstNodeDailyCount
(
sop
.
getInst
().
getInstId
());
instNodeMapper
.
resetInstNodeDailyCount
(
sop
.
getInst
().
getInstId
());
}
}
/** 从实例倒推出模板,主要用于开发阶段 */
@Transactional
public
void
generateTplFromInst
(
SopStruct
sop
)
{
// 预备模板
SopTpl
tpl
=
new
SopTpl
();
tpl
.
setCreateTime
(
new
Date
());
tpl
.
setTplCron
(
sop
.
getInst
().
getInstCron
());
tpl
.
setTplId
(
StrUtil
.
sub
(
SnowFlake
.
nextSerialNumber
(),
0
,
8
));
// 随机生成模板id
tpl
.
setTplName
(
sop
.
getInst
().
getInstName
());
// 生成参数定义
tpl
.
setTplParamDef
(
parseDef
(
sop
.
getInst
().
getInstParam
()));
tpl
.
setTplRemark
(
"从实例自动产生模板:"
+
sop
.
getInst
().
getInstName
());
tpl
.
setTplResultDef
(
sop
.
getInst
().
getInstSnapshot
());
tpl
.
setTplSingleton
((
byte
)
1
);
tpl
.
setTplStatus
((
byte
)
1
);
tpl
.
setUpdateTime
(
new
Date
());
tplMapper
.
insert
(
tpl
);
List
<
SopTplNode
>
nodes
=
Lists
.
newArrayList
();
for
(
SopInstNode
node
:
sop
.
getInstNodeMap
().
values
())
{
SopTplNode
tnode
=
new
SopTplNode
();
tnode
.
setDailyLimit
(
node
.
getDailyLimit
());
tnode
.
setNodeAsync
(
node
.
getNodeAsync
());
tnode
.
setNodeContentDef
(
node
.
getNodeContent
());
tnode
.
setNodeCron
(
node
.
getNodeCron
());
tnode
.
setNodeExpireCron
(
node
.
getNodeExpireCron
());
tnode
.
setNodeId
(
node
.
getNodeId
());
tnode
.
setNodeKey
(
node
.
getNodeKey
());
tnode
.
setNodeLabel
(
node
.
getNodeLabel
());
tnode
.
setNodeName
(
node
.
getNodeName
());
tnode
.
setNodeParamDef
(
parseDef
(
node
.
getNodeParam
()));
tnode
.
setNodeResultDef
(
node
.
getNodeContent
());
tnode
.
setNodeShow
(
node
.
getNodeShow
());
tnode
.
setNodeSkipable
(
node
.
getNodeSkip
());
tnode
.
setNodeType
(
node
.
getNodeType
());
tnode
.
setNodeVisible
(
node
.
getNodeVisible
());
tnode
.
setTplId
(
tpl
.
getTplId
());
nodes
.
add
(
tnode
);
}
tplNodeMapper
.
insertList
(
nodes
);
List
<
SopTplLink
>
links
=
Lists
.
newArrayList
();
for
(
Entry
<
Integer
,
Pair
<
Set
<
Integer
>,
Set
<
Integer
>>>
entry
:
sop
.
getInstLinkMap
().
entrySet
())
{
if
(
entry
.
getValue
().
getValue
().
isEmpty
())
{
continue
;
}
int
sourceId
=
entry
.
getKey
();
for
(
int
targetId
:
entry
.
getValue
().
getValue
())
{
SopTplLink
link
=
new
SopTplLink
();
link
.
setSourceId
(
sourceId
);
link
.
setTargetId
(
targetId
);
link
.
setTplId
(
tpl
.
getTplId
());
links
.
add
(
link
);
}
}
tplLinkMapper
.
insertList
(
links
);
}
/**
* <code>
{
"day": {
"paramName": "day",
"paramDesc": "有意向第?天",
"valueType": "Integer",
"defaultValue": "2",
"required": true
},
"textContent": {
"paramName": "textContent",
"paramDesc": "营销文案",
"valueType": "String",
"defaultValue": "尊敬的${userName},优惠券领取url.cn/c134dqwe",
"required": true
}
}
* </code>
*
* @param json
* @return
*/
private
static
String
parseDef
(
String
json
)
{
if
(
json
==
null
||
json
.
trim
().
length
()
<
1
)
{
return
null
;
}
JSONObject
def
=
new
JSONObject
();
try
{
JSONObject
parse
=
JSONUtil
.
parseObj
(
json
);
for
(
String
key
:
parse
.
keySet
())
{
Map
<
String
,
Object
>
map
=
Maps
.
newHashMap
();
map
.
put
(
"paramKey"
,
key
);
map
.
put
(
"paramDesc"
,
key
);
Object
value
=
parse
.
get
(
key
);
String
type
=
detectType
(
value
);
map
.
put
(
"valueType"
,
type
);
map
.
put
(
"defaultValue"
,
value
);
map
.
put
(
"required"
,
true
);
def
.
set
(
key
,
map
);
}
}
catch
(
Exception
e
)
{
log
.
warn
(
"json:{}"
,
json
,
e
);
}
return
def
.
toString
();
}
private
static
String
detectType
(
Object
value
)
{
String
v
=
value
.
toString
().
trim
();
if
(
NumberUtil
.
isNumber
(
v
))
{
return
"Number"
;
}
if
(
StrUtil
.
startWith
(
v
,
"{"
))
{
return
"Map"
;
}
if
(
StrUtil
.
startWith
(
v
,
"["
))
{
return
"Array"
;
}
return
"String"
;
}
}
}
platform-process/src/main/java/cn/com/glsx/process/modules/sop/SopHelper.java
View file @
55ba850
...
@@ -5,23 +5,29 @@ import java.lang.reflect.Field;
...
@@ -5,23 +5,29 @@ import java.lang.reflect.Field;
import
java.security.GeneralSecurityException
;
import
java.security.GeneralSecurityException
;
import
java.security.MessageDigest
;
import
java.security.MessageDigest
;
import
java.text.DateFormat
;
import
java.text.DateFormat
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
cn.com.glsx.process.modules.entity.SopInst
;
import
cn.com.glsx.process.modules.entity.SopInst
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.redis.DistributedLockUtils
;
import
cn.com.glsx.process.redis.DistributedLockUtils
;
/**
/**
...
@@ -32,262 +38,260 @@ import cn.com.glsx.process.redis.DistributedLockUtils;
...
@@ -32,262 +38,260 @@ import cn.com.glsx.process.redis.DistributedLockUtils;
*/
*/
public
class
SopHelper
{
public
class
SopHelper
{
private
static
final
String
SOP_INST_LOCK_NAMESPACE
=
"lock.sop.inst."
;
private
static
final
String
SOP_INST_LOCK_NAMESPACE
=
"lock.sop.inst."
;
private
final
static
String
appKey
=
"48e5e13229b82c1b4e6e8c96151f0637"
;
private
final
static
String
appKey
=
"48e5e13229b82c1b4e6e8c96151f0637"
;
private
final
static
String
secret
=
"c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b"
;
private
final
static
String
secret
=
"c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b"
;
public
static
boolean
lockInst
(
SopInst
inst
)
{
public
static
boolean
lockInst
(
SopInst
inst
)
{
String
key
=
SOP_INST_LOCK_NAMESPACE
+
inst
.
getInstId
();
String
key
=
SOP_INST_LOCK_NAMESPACE
+
inst
.
getInstId
();
return
DistributedLockUtils
.
lock
(
key
,
10
*
1000L
,
3
,
3
*
1000L
);
return
DistributedLockUtils
.
lock
(
key
,
10
*
1000L
,
3
,
3
*
1000L
);
}
}
public
static
void
unlockInst
(
SopInst
inst
)
{
public
static
void
unlockInst
(
SopInst
inst
)
{
String
key
=
SOP_INST_LOCK_NAMESPACE
+
inst
.
getInstId
();
String
key
=
SOP_INST_LOCK_NAMESPACE
+
inst
.
getInstId
();
DistributedLockUtils
.
unlock
(
key
);
DistributedLockUtils
.
unlock
(
key
);
}
}
public
static
boolean
diffDay
(
Date
date
,
Integer
diffdays
)
{
public
static
boolean
diffDay
(
Date
date
,
Integer
diffdays
)
{
DateFormat
dft
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
DateFormat
dft
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
String
end
=
dft
.
format
(
new
Date
());
String
end
=
dft
.
format
(
new
Date
());
String
star
=
dft
.
format
(
date
);
String
star
=
dft
.
format
(
date
);
String
[]
star1
=
star
.
split
(
"-"
);
String
[]
star1
=
star
.
split
(
"-"
);
String
[]
end1
=
end
.
split
(
"-"
);
String
[]
end1
=
end
.
split
(
"-"
);
int
days
=
0
;
int
days
=
0
;
if
(
Integer
.
parseInt
(
star1
[
0
])
<
Integer
.
parseInt
(
end1
[
0
]))
{
if
(
Integer
.
parseInt
(
star1
[
0
])
<
Integer
.
parseInt
(
end1
[
0
]))
{
for
(
int
i
=
Integer
.
parseInt
(
star1
[
0
]);
i
<
Integer
.
parseInt
(
end1
[
0
]);
i
++)
{
for
(
int
i
=
Integer
.
parseInt
(
star1
[
0
]);
i
<
Integer
.
parseInt
(
end1
[
0
]);
i
++)
{
//计算是否是瑞年
// 计算是否是瑞年
if
(
i
%
4
==
0
&&
i
%
100
!=
0
||
i
%
400
==
0
)
{
if
(
i
%
4
==
0
&&
i
%
100
!=
0
||
i
%
400
==
0
)
{
days
+=
366
;
days
+=
366
;
}
else
{
}
else
{
days
+=
365
;
days
+=
365
;
}
}
}
}
}
}
//得到开始那一年已过去的日期
// 得到开始那一年已过去的日期
int
starday
=
days
(
star1
[
0
],
star1
[
1
],
star1
[
2
]);
int
starday
=
days
(
star1
[
0
],
star1
[
1
],
star1
[
2
]);
//得到结束那一年已过去的日期
// 得到结束那一年已过去的日期
int
endday
=
days
(
end1
[
0
],
end1
[
1
],
end1
[
2
]);
int
endday
=
days
(
end1
[
0
],
end1
[
1
],
end1
[
2
]);
//减去开始那一年已过去的日期,加上结束那一年已过去的日期
// 减去开始那一年已过去的日期,加上结束那一年已过去的日期
days
=
days
-
starday
+
endday
;
days
=
days
-
starday
+
endday
;
return
days
==
diffdays
;
return
days
==
diffdays
;
}
}
/**
/**
* 获取构建的信息
* 获取构建的信息
*
*
* @param param 入参
* @param param 入参
* @return
* @return
*/
*/
public
static
SopExecutorResult
getExcustorParam
(
JSON
param
)
{
public
static
SopExecutorResult
getExcustorParam
(
JSON
param
)
{
JSONObject
jsonObject
=
(
JSONObject
)
param
;
JSONObject
jsonObject
=
(
JSONObject
)
param
;
SopInst
sopInst
=
(
SopInst
)
jsonObject
.
get
(
"sopInst"
);
SopInst
sopInst
=
(
SopInst
)
jsonObject
.
get
(
"sopInst"
);
SopInstNode
sopInstNode
=
(
SopInstNode
)
jsonObject
.
get
(
"sopInstNode"
);
SopInstNode
sopInstNode
=
(
SopInstNode
)
jsonObject
.
get
(
"sopInstNode"
);
Map
<
String
,
Object
>
resultData
=
(
Map
<
String
,
Object
>)
jsonObject
.
get
(
"instSnapshot"
);
Map
<
String
,
Object
>
resultData
=
(
Map
<
String
,
Object
>)
jsonObject
.
get
(
"instSnapshot"
);
return
new
SopExecutorResult
(
sopInst
,
sopInstNode
,
resultData
);
return
new
SopExecutorResult
(
sopInst
,
sopInstNode
,
resultData
);
}
}
/**
/**
* 获取匹配上的信息
* 获取匹配上的信息
*
*
* @param sopInstNode 节点信息
* @param sopInstNode 节点信息
* @param resultData 上个节点返回的信息
* @param resultData 上个节点返回的信息
* @return
* @return
*/
*/
public
static
List
<
CustomerInfo
>
getMeetWithCustomer
(
SopInstNode
sopInstNode
,
Map
<
String
,
Object
>
resultData
)
{
public
static
List
<
CustomerInfo
>
getMeetWithCustomer
(
SopInstNode
sopInstNode
,
Map
<
String
,
Object
>
resultData
)
{
String
nodeParam
=
sopInstNode
.
getNodeParam
();
String
nodeParam
=
sopInstNode
.
getNodeParam
();
String
key
=
"user"
+
getValueFromJsonString
(
nodeParam
,
"stageid"
);
String
key
=
"user"
+
getValueFromJsonString
(
nodeParam
,
"stageid"
);
// 拿到过滤出阶段的客户
// 拿到过滤出阶段的客户
List
<
CustomerInfo
>
customerInfoList
=
JSON
.
parseArray
(
JSON
.
toJSONString
(
resultData
.
get
(
key
)),
CustomerInfo
.
class
);
List
<
CustomerInfo
>
customerInfoList
=
JSON
.
parseArray
(
JSON
.
toJSONString
(
resultData
.
get
(
key
)),
CustomerInfo
.
class
);
String
diffday
=
SopHelper
.
getValueFromJsonString
(
nodeParam
,
"day"
);
String
diffday
=
SopHelper
.
getValueFromJsonString
(
nodeParam
,
"day"
);
if
(
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isEmpty
(
diffday
))
{
if
(
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isEmpty
(
diffday
))
{
return
null
;
return
null
;
}
}
if
(
CollectionUtils
.
isNotEmpty
(
customerInfoList
))
{
if
(
CollectionUtils
.
isNotEmpty
(
customerInfoList
))
{
// 距离旅程相差天数过滤
// 距离旅程相差天数过滤
return
customerInfoList
.
stream
().
filter
(
index
->
SopHelper
.
diffDay
(
index
.
getSopJourneyStageEnterTime
(),
Integer
.
parseInt
(
diffday
)))
return
customerInfoList
.
stream
().
filter
(
index
->
SopHelper
.
diffDay
(
index
.
getSopJourneyStageEnterTime
(),
Integer
.
parseInt
(
diffday
))).
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
}
}
return
null
;
return
null
;
}
}
public
static
Map
<
String
,
Object
>
objectToMap
(
Object
obj
)
{
public
static
Map
<
String
,
Object
>
objectToMap
(
Object
obj
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Class
<?>
clazz
=
obj
.
getClass
();
Class
<?>
clazz
=
obj
.
getClass
();
Field
[]
fields
=
clazz
.
getDeclaredFields
();
Field
[]
fields
=
clazz
.
getDeclaredFields
();
for
(
Field
field
:
fields
)
{
for
(
Field
field
:
fields
)
{
field
.
setAccessible
(
true
);
field
.
setAccessible
(
true
);
String
fieldName
=
field
.
getName
();
String
fieldName
=
field
.
getName
();
Object
fieldValue
=
null
;
Object
fieldValue
=
null
;
try
{
try
{
fieldValue
=
field
.
get
(
obj
);
fieldValue
=
field
.
get
(
obj
);
}
catch
(
IllegalAccessException
e
)
{
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
map
.
put
(
fieldName
,
fieldValue
);
map
.
put
(
fieldName
,
fieldValue
);
}
}
return
map
;
return
map
;
}
}
public
static
String
getValueFromJsonString
(
String
jsonString
,
String
objectName
,
String
fieldName
)
{
public
static
String
getValueFromJsonString
(
String
jsonString
,
String
objectName
,
String
fieldName
)
{
try
{
try
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
JsonNode
rootNode
=
objectMapper
.
readTree
(
jsonString
);
JsonNode
rootNode
=
objectMapper
.
readTree
(
jsonString
);
JsonNode
objectNode
=
rootNode
.
get
(
objectName
);
JsonNode
objectNode
=
rootNode
.
get
(
objectName
);
JsonNode
fieldNode
=
objectNode
.
get
(
fieldName
);
JsonNode
fieldNode
=
objectNode
.
get
(
fieldName
);
return
fieldNode
.
asText
();
return
fieldNode
.
asText
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
return
null
;
return
null
;
}
}
public
static
String
getValueFromJsonString
(
String
jsonString
,
String
objectName
,
String
objectNameTwo
,
String
fieldName
)
{
try
{
public
static
String
getValueFromJsonString
(
String
jsonString
,
String
objectName
,
String
objectNameTwo
,
String
fieldName
)
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
try
{
JsonNode
rootNode
=
objectMapper
.
readTree
(
jsonString
);
ObjectMapper
objectMapper
=
new
ObjectMapper
();
JsonNode
objectNode
=
rootNode
.
get
(
objectName
);
JsonNode
rootNode
=
objectMapper
.
readTree
(
jsonString
);
JsonNode
objectNodeTwo
=
objectNode
.
get
(
objectNameTwo
);
JsonNode
objectNode
=
rootNode
.
get
(
objectName
);
JsonNode
fieldNode
=
objectNodeTwo
.
get
(
fieldName
);
JsonNode
objectNodeTwo
=
objectNode
.
get
(
objectNameTwo
);
return
fieldNode
.
asText
();
JsonNode
fieldNode
=
objectNodeTwo
.
get
(
fieldName
);
}
catch
(
Exception
e
)
{
return
fieldNode
.
asText
();
e
.
printStackTrace
();
}
catch
(
Exception
e
)
{
}
e
.
printStackTrace
();
return
null
;
}
}
return
null
;
}
public
static
String
getValueFromJsonString
(
String
jsonString
,
String
fieldName
)
{
public
static
String
getValueFromJsonString
(
String
jsonString
,
String
fieldName
)
{
try
{
try
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
JsonNode
rootNode
=
objectMapper
.
readTree
(
jsonString
);
JsonNode
rootNode
=
objectMapper
.
readTree
(
jsonString
);
JsonNode
fieldNode
=
rootNode
.
get
(
fieldName
);
JsonNode
fieldNode
=
rootNode
.
get
(
fieldName
);
if
(
fieldNode
!=
null
)
{
if
(
fieldNode
!=
null
)
{
return
fieldNode
.
asText
();
return
fieldNode
.
asText
();
}
else
{
}
else
{
return
null
;
return
null
;
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
return
null
;
return
null
;
}
}
public
static
<
T
>
T
post
(
MultiValueMap
<
String
,
String
>
paramsMap
,
Class
<
T
>
responseType
,
String
baseurl
,
String
method
)
throws
Exception
{
public
static
<
T
>
T
post
(
MultiValueMap
<
String
,
String
>
paramsMap
,
Class
<
T
>
responseType
,
String
baseurl
,
String
method
)
throws
Exception
{
addBaseParam
(
paramsMap
,
method
);
addBaseParam
(
paramsMap
,
method
);
MultiValueMap
<
String
,
String
>
params
=
getSysParams
();
MultiValueMap
<
String
,
String
>
params
=
getSysParams
();
params
.
putAll
(
paramsMap
);
params
.
putAll
(
paramsMap
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
params
.
toSingleValueMap
().
entrySet
())
{
for
(
Map
.
Entry
<
String
,
String
>
entry
:
params
.
toSingleValueMap
().
entrySet
())
{
if
(
StringUtils
.
isEmpty
(
entry
.
getValue
()))
{
if
(
StringUtils
.
isEmpty
(
entry
.
getValue
()))
{
params
.
remove
(
entry
.
getKey
());
params
.
remove
(
entry
.
getKey
());
}
}
}
}
String
sign
=
sign
(
params
.
toSingleValueMap
(),
secret
);
String
sign
=
sign
(
params
.
toSingleValueMap
(),
secret
);
params
.
add
(
"sign"
,
sign
);
params
.
add
(
"sign"
,
sign
);
return
new
RestTemplate
().
postForObject
(
baseurl
,
params
,
responseType
);
return
new
RestTemplate
().
postForObject
(
baseurl
,
params
,
responseType
);
}
}
public
static
MultiValueMap
<
String
,
String
>
getSysParams
()
{
public
static
MultiValueMap
<
String
,
String
>
getSysParams
()
{
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<
String
,
String
>(
16
);
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<
String
,
String
>(
16
);
params
.
add
(
"appKey"
,
appKey
);
params
.
add
(
"appKey"
,
appKey
);
params
.
add
(
"format"
,
"json"
);
params
.
add
(
"format"
,
"json"
);
return
params
;
return
params
;
}
}
public
static
String
sign
(
Map
<
String
,
String
>
paramValues
,
String
secret
)
{
public
static
String
sign
(
Map
<
String
,
String
>
paramValues
,
String
secret
)
{
return
sign
(
paramValues
,
(
List
)
null
,
secret
);
return
sign
(
paramValues
,
(
List
)
null
,
secret
);
}
}
public
static
String
sign
(
Map
<
String
,
String
>
paramValues
,
List
<
String
>
ignoreParamNames
,
String
secret
)
{
public
static
String
sign
(
Map
<
String
,
String
>
paramValues
,
List
<
String
>
ignoreParamNames
,
String
secret
)
{
try
{
try
{
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
List
<
String
>
paramNames
=
new
ArrayList
(
paramValues
.
size
());
List
<
String
>
paramNames
=
new
ArrayList
(
paramValues
.
size
());
paramNames
.
addAll
(
paramValues
.
keySet
());
paramNames
.
addAll
(
paramValues
.
keySet
());
Iterator
var5
;
Iterator
var5
;
String
paramName
;
String
paramName
;
if
(
ignoreParamNames
!=
null
&&
ignoreParamNames
.
size
()
>
0
)
{
if
(
ignoreParamNames
!=
null
&&
ignoreParamNames
.
size
()
>
0
)
{
var5
=
ignoreParamNames
.
iterator
();
var5
=
ignoreParamNames
.
iterator
();
while
(
var5
.
hasNext
())
{
while
(
var5
.
hasNext
())
{
paramName
=
(
String
)
var5
.
next
();
paramName
=
(
String
)
var5
.
next
();
paramNames
.
remove
(
paramName
);
paramNames
.
remove
(
paramName
);
}
}
}
}
Collections
.
sort
(
paramNames
);
Collections
.
sort
(
paramNames
);
sb
.
append
(
secret
);
sb
.
append
(
secret
);
var5
=
paramNames
.
iterator
();
var5
=
paramNames
.
iterator
();
while
(
var5
.
hasNext
())
{
while
(
var5
.
hasNext
())
{
paramName
=
(
String
)
var5
.
next
();
paramName
=
(
String
)
var5
.
next
();
sb
.
append
(
paramName
).
append
(
paramValues
.
get
(
paramName
));
sb
.
append
(
paramName
).
append
(
paramValues
.
get
(
paramName
));
}
}
sb
.
append
(
secret
);
sb
.
append
(
secret
);
byte
[]
sha1Digest
=
getSHA1Digest
(
sb
.
toString
());
byte
[]
sha1Digest
=
getSHA1Digest
(
sb
.
toString
());
return
byte2hex
(
sha1Digest
);
return
byte2hex
(
sha1Digest
);
}
catch
(
IOException
var7
)
{
}
catch
(
IOException
var7
)
{
return
null
;
return
null
;
}
}
}
}
private
static
byte
[]
getSHA1Digest
(
String
data
)
throws
IOException
{
private
static
byte
[]
getSHA1Digest
(
String
data
)
throws
IOException
{
Object
var1
=
null
;
Object
var1
=
null
;
try
{
try
{
MessageDigest
md
=
MessageDigest
.
getInstance
(
"SHA-1"
);
MessageDigest
md
=
MessageDigest
.
getInstance
(
"SHA-1"
);
byte
[]
bytes
=
md
.
digest
(
data
.
getBytes
(
"UTF-8"
));
byte
[]
bytes
=
md
.
digest
(
data
.
getBytes
(
"UTF-8"
));
return
bytes
;
return
bytes
;
}
catch
(
GeneralSecurityException
var3
)
{
}
catch
(
GeneralSecurityException
var3
)
{
throw
new
IOException
(
var3
);
throw
new
IOException
(
var3
);
}
}
}
}
private
static
String
byte2hex
(
byte
[]
bytes
)
{
private
static
String
byte2hex
(
byte
[]
bytes
)
{
StringBuilder
sign
=
new
StringBuilder
();
StringBuilder
sign
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
bytes
.
length
;
++
i
)
{
for
(
int
i
=
0
;
i
<
bytes
.
length
;
++
i
)
{
String
hex
=
Integer
.
toHexString
(
bytes
[
i
]
&
255
);
String
hex
=
Integer
.
toHexString
(
bytes
[
i
]
&
255
);
if
(
hex
.
length
()
==
1
)
{
if
(
hex
.
length
()
==
1
)
{
sign
.
append
(
"0"
);
sign
.
append
(
"0"
);
}
}
sign
.
append
(
hex
.
toUpperCase
());
sign
.
append
(
hex
.
toUpperCase
());
}
}
return
sign
.
toString
();
return
sign
.
toString
();
}
}
private
static
void
addBaseParam
(
MultiValueMap
<
String
,
String
>
paramsMap
,
String
method
)
{
private
static
void
addBaseParam
(
MultiValueMap
<
String
,
String
>
paramsMap
,
String
method
)
{
paramsMap
.
add
(
"v"
,
"1.0.0"
);
paramsMap
.
add
(
"v"
,
"1.0.0"
);
paramsMap
.
add
(
"method"
,
method
);
paramsMap
.
add
(
"method"
,
method
);
paramsMap
.
add
(
"name"
,
"zhouhb"
);
paramsMap
.
add
(
"name"
,
"zhouhb"
);
}
}
public
static
int
days
(
String
year
,
String
month
,
String
day
)
{
int
days
=
0
;
public
static
int
days
(
String
year
,
String
month
,
String
day
)
{
int
nowyear
=
Integer
.
parseInt
(
year
);
int
days
=
0
;
int
[]
monthday
=
{
0
,
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
};
int
nowyear
=
Integer
.
parseInt
(
year
);
int
[]
monthday1
=
{
0
,
31
,
29
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
};
int
[]
monthday
=
{
0
,
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
};
boolean
flag
=
true
;
int
[]
monthday1
=
{
0
,
31
,
29
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
};
if
(
nowyear
%
4
==
0
&&
nowyear
%
100
!=
0
||
nowyear
%
400
==
0
)
{
boolean
flag
=
true
;
}
else
{
if
(
nowyear
%
4
==
0
&&
nowyear
%
100
!=
0
||
nowyear
%
400
==
0
)
{
flag
=
false
;
}
else
{
}
flag
=
false
;
for
(
int
i
=
0
;
i
<
Integer
.
parseInt
(
month
);
i
++)
{
}
if
(
flag
)
{
for
(
int
i
=
0
;
i
<
Integer
.
parseInt
(
month
);
i
++)
{
days
+=
monthday1
[
i
];
if
(
flag
)
{
}
else
{
days
+=
monthday1
[
i
];
days
+=
monthday
[
i
];
}
else
{
}
days
+=
monthday
[
i
];
}
}
days
+=
Integer
.
parseInt
(
day
);
}
return
days
;
days
+=
Integer
.
parseInt
(
day
);
}
return
days
;
}
}
}
platform-process/src/main/java/cn/com/glsx/process/modules/sop/execute/SopNodeExecutor.java
View file @
55ba850
...
@@ -39,16 +39,13 @@ public interface SopNodeExecutor {
...
@@ -39,16 +39,13 @@ public interface SopNodeExecutor {
* @return
* @return
*/
*/
default
SnapshotStruct
prepare
(
SopStruct
sop
,
SopInstNode
node
)
{
default
SnapshotStruct
prepare
(
SopStruct
sop
,
SopInstNode
node
)
{
SnapshotStruct
es
=
new
SnapshotStruct
();
SnapshotStruct
es
=
JacksonUtils
.
fromJson
(
sop
.
getInst
().
getInstSnapshot
(),
SnapshotStruct
.
class
);
if
(
StrUtil
.
length
(
sop
.
getInst
().
getInstSnapshot
())
>
4
)
{
// 启动参数
// 继承参数
if
(
StrUtil
.
isNotEmpty
(
sop
.
getInst
().
getInstParam
()))
{
es
=
JacksonUtils
.
fromJson
(
sop
.
getInst
().
getInstSnapshot
(),
SnapshotStruct
.
class
);
es
.
getInitMap
().
clear
();
}
else
{
// 重新生成初始化参数
// 启动参数
JSONObject
paramObj
=
JSONUtil
.
parseObj
(
sop
.
getInst
().
getInstParam
());
if
(
StrUtil
.
isNotEmpty
(
sop
.
getInst
().
getInstParam
()))
{
es
.
getInitMap
().
putAll
(
paramObj
);
JSONObject
paramObj
=
JSONUtil
.
parseObj
(
sop
.
getInst
().
getInstParam
());
es
.
getInitMap
().
putAll
(
paramObj
);
}
}
}
es
.
getInitMap
().
put
(
"instId"
,
sop
.
getInst
().
getInstId
());
es
.
getInitMap
().
put
(
"instId"
,
sop
.
getInst
().
getInstId
());
...
...
platform-process/src/main/java/cn/com/glsx/process/modules/sop/execute/executor/JavaExecutor.java
View file @
55ba850
...
@@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
...
@@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil
;
import
cn.com.glsx.process.modules.entity.SopInst
;
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
;
...
@@ -46,7 +47,7 @@ public class JavaExecutor implements SopNodeExecutor {
...
@@ -46,7 +47,7 @@ public class JavaExecutor implements SopNodeExecutor {
// 处理返回结果
// 处理返回结果
return
instance
;
return
instance
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
(
);
SopXxlJobUtil
.
log
(
log
,
"【{}】{}"
,
getClass
().
getSimpleName
(),
e
.
getMessage
(),
e
);
}
}
return
null
;
return
null
;
...
...
platform-process/src/main/java/cn/com/glsx/process/modules/sop/execute/executor/SqlExecutor.java
View file @
55ba850
package
cn
.
com
.
glsx
.
process
.
modules
.
sop
.
execute
.
executor
;
package
cn
.
com
.
glsx
.
process
.
modules
.
sop
.
execute
.
executor
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
cn.com.glsx.process.
common.constant.Constants
;
import
cn.com.glsx.process.
job.xxljob.core.SopXxlJobUtil
;
import
cn.com.glsx.process.modules.entity.SopDataSource
;
import
cn.com.glsx.process.modules.entity.SopDataSource
;
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
;
...
@@ -24,35 +22,32 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -24,35 +22,32 @@ import lombok.extern.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
Object
execute
(
SopStruct
sop
,
SopInstNode
node
,
SnapshotStruct
executeStruct
)
throws
Exception
{
public
Object
execute
(
SopStruct
sop
,
SopInstNode
node
,
SnapshotStruct
executeStruct
)
throws
Exception
{
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
sqlTemplate
=
paramMap
.
get
(
"source"
)
+
""
;
String
dataSourceId
=
paramMap
.
get
(
"dataSourceId"
)
+
""
;
String
dataSourceId
=
paramMap
.
get
(
"dataSourceId"
)
+
""
;
// 执行sql插件
// 执行sql插件
SopDataSource
byId
=
sopDataSourceService
.
findByDataSourceId
(
dataSourceId
);
SopDataSource
byId
=
sopDataSourceService
.
findByDataSourceId
(
dataSourceId
);
SopBizAdapter
mcgBizAdapter
=
new
FlowDataAdapterImpl
(
byId
);
SopBizAdapter
mcgBizAdapter
=
new
FlowDataAdapterImpl
(
byId
);
String
sql
=
FreemarkerUtil
.
processContent
(
sqlTemplate
,
executeStruct
.
toMap
());
String
sql
=
FreemarkerUtil
.
processContent
(
sqlTemplate
,
executeStruct
.
toMap
());
int
i
=
mcgBizAdapter
.
executeUpdate
(
sql
);
int
i
=
mcgBizAdapter
.
executeUpdate
(
sql
);
return
"更新成功条数"
+
i
;
return
"更新成功条数"
+
i
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
String
message
=
e
.
getMessage
();
SopXxlJobUtil
.
log
(
log
,
"【{}】{}"
,
getClass
().
getSimpleName
(),
e
.
getMessage
(),
e
);
resultMap
.
put
(
Constants
.
RES_FAIL_MESSAGE
,
message
);
}
resultMap
.
put
(
Constants
.
RES_KEY
,
Constants
.
RES_FAIL
);
return
null
;
}
}
return
null
;
}
}
}
\ 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 @
55ba850
...
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
...
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
cn.com.glsx.process.job.xxljob.core.SopXxlJobUtil
;
import
cn.com.glsx.process.modules.entity.SopDataSource
;
import
cn.com.glsx.process.modules.entity.SopDataSource
;
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
;
...
@@ -48,7 +49,7 @@ public class SqlQueryExecutor implements SopNodeExecutor {
...
@@ -48,7 +49,7 @@ public class SqlQueryExecutor implements SopNodeExecutor {
// 处理执行结果
// 处理执行结果
return
maps
;
return
maps
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
(
);
SopXxlJobUtil
.
log
(
log
,
"【{}】{}"
,
getClass
().
getSimpleName
(),
e
.
getMessage
(),
e
);
}
}
return
null
;
return
null
;
}
}
...
...
platform-process/src/main/resources/mapper/SopInstMapper.xml
View file @
55ba850
...
@@ -38,7 +38,7 @@
...
@@ -38,7 +38,7 @@
</update>
</update>
<update
id=
"updateInstBatchNo"
>
<update
id=
"updateInstBatchNo"
>
UPDATE sop_inst SET batch_no = #{batchNo} WHERE inst_id = #{instId}
UPDATE sop_inst SET batch_no = #{batchNo}
, inst_snapshot=#{snapshot}
WHERE inst_id = #{instId}
</update>
</update>
<select
id=
"selectByGroupId"
resultMap=
"BaseResultMap"
>
<select
id=
"selectByGroupId"
resultMap=
"BaseResultMap"
>
...
...
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