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 e34c15b0
authored
Sep 14, 2023
by
tiger
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
job
1 parent
d9cf876e
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
852 additions
and
63 deletions
.gitignore
platform-process-api/pom.xml
platform-process-api/src/main/java/cn/com/glsx/process/modules/entity/SopInstNode.java
platform-process-api/src/main/java/cn/com/glsx/process/modules/model/SopStruct.java
platform-process/src/main/java/cn/com/glsx/process/job/DynamicTaskService.java
platform-process/src/main/java/cn/com/glsx/process/job/instance/SopInstExecuteJob.java
platform-process/src/main/java/cn/com/glsx/process/job/instance/SopInstNodeJob.java
platform-process/src/main/java/cn/com/glsx/process/job/instance/SopInstNodeParam.java
platform-process/src/main/java/cn/com/glsx/process/modules/controller/Controller.java
platform-process/src/main/java/cn/com/glsx/process/modules/controller/TestJobController.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/SopNodeExecutor.java
platform-process/src/main/java/cn/com/glsx/process/plugin/java/DynamicEngine.java
platform-process/src/main/resources/application.properties_standalone
platform-process/src/main/resources/bootstrap.properties
platform-process/src/test/java/cn/com/glsx/cn/com/glsx/util/FlowSortUtil.java
platform-process/src/test/java/cn/com/glsx/cn/com/glsx/util/JacksonUtils.java
platform-process/src/test/java/cn/com/glsx/cn/com/glsx/util/Pair.java
scripts/sql/platform_process_dev.sql
.gitignore
View file @
e34c15b
...
@@ -9,3 +9,5 @@
...
@@ -9,3 +9,5 @@
*.container
*.container
*.name
*.name
/platform-process-api/*.factorypath
/platform-process-api/*.factorypath
/platform-process/*.path_IS_UNDEFINED
/platform-process/*.gz
platform-process-api/pom.xml
View file @
e34c15b
...
@@ -22,6 +22,16 @@
...
@@ -22,6 +22,16 @@
<groupId>
com.glsx
</groupId>
<groupId>
com.glsx
</groupId>
<artifactId>
rest-admin-feign
</artifactId>
<artifactId>
rest-admin-feign
</artifactId>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
32.1.2-jre
</version>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
platform-process-api/src/main/java/cn/com/glsx/process/modules/entity/SopInstNode.java
View file @
e34c15b
package
cn
.
com
.
glsx
.
process
.
modules
.
entity
;
package
cn
.
com
.
glsx
.
process
.
modules
.
entity
;
import
javax.persistence.*
;
import
javax.persistence.Column
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
@Table
(
name
=
"sop_inst_node"
)
@Table
(
name
=
"sop_inst_node"
)
public
class
SopInstNode
{
public
class
SopInstNode
{
...
...
platform-process-api/src/main/java/cn/com/glsx/process/modules/model/SopStruct.java
View file @
e34c15b
package
cn
.
com
.
glsx
.
process
.
modules
.
model
;
package
cn
.
com
.
glsx
.
process
.
modules
.
model
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
com.google.common.collect.Sets
;
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
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
...
@@ -38,4 +42,39 @@ public class SopStruct {
...
@@ -38,4 +42,39 @@ public class SopStruct {
/** 实例当前批次 */
/** 实例当前批次 */
private
SopInstBatch
batch
;
private
SopInstBatch
batch
;
/** 所有节点执行顺序 */
public
List
<
Integer
>
getNodeSort
()
{
List
<
Integer
>
sort
=
new
ArrayList
<>();
Set
<
Integer
>
keys
=
Sets
.
newHashSet
();
int
i
=
0
;
while
(
keys
.
size
()
<
instLinkMap
.
keySet
().
size
())
{
Set
<
Integer
>
sets
=
instLinkMap
.
keySet
();
for
(
Integer
key
:
sets
)
{
i
++;
Pair
<
Set
<
Integer
>,
Set
<
Integer
>>
pair
=
instLinkMap
.
get
(
key
);
if
(!
keys
.
contains
(
key
))
{
// 第一个节点:直接执行
if
(
pair
.
getKey
().
isEmpty
())
{
keys
.
add
(
key
);
sort
.
add
(
key
);
continue
;
}
// 非第一个节点:判断前置节点
if
(
keys
.
containsAll
(
pair
.
getKey
()))
{
keys
.
add
(
key
);
sort
.
add
(
key
);
continue
;
}
}
else
{
// 进入后置节点
sets
=
pair
.
getValue
();
continue
;
}
}
if
(
i
++
>
1000
)
{
throw
new
RuntimeException
(
"Sop实例:【"
+
inst
.
getInstId
()
+
"-"
+
inst
.
getInstName
()
+
"】节点不闭环,请检查!"
);
}
}
return
sort
;
}
}
}
platform-process/src/main/java/cn/com/glsx/process/job/DynamicTaskService.java
View file @
e34c15b
...
@@ -58,6 +58,13 @@ public class DynamicTaskService {
...
@@ -58,6 +58,13 @@ public class DynamicTaskService {
log
.
info
(
"【动态任务】{},创建:cron:{}, job:{}"
,
jobName
,
cron
,
instance
.
getClass
().
getSimpleName
());
log
.
info
(
"【动态任务】{},创建:cron:{}, job:{}"
,
jobName
,
cron
,
instance
.
getClass
().
getSimpleName
());
}
}
public
void
create
(
String
jobName
,
String
cron
,
SimpleJob
instance
,
String
description
,
String
param
,
boolean
enabled
)
{
LiteJobConfiguration
jobConfig
=
simpleJobConfigBuilder
(
jobName
,
instance
.
getClass
(),
1
,
cron
,
description
,
param
).
overwrite
(
true
)
.
disabled
(!
enabled
).
build
();
new
SpringJobScheduler
(
instance
,
zookeeperRegistryCenter
,
jobConfig
,
elasticJobListener
).
init
();
log
.
info
(
"【动态任务】{},创建:cron:{},job:{},enabled:{}"
,
jobName
,
cron
,
instance
.
getClass
().
getSimpleName
(),
enabled
);
}
/**
/**
* 更新定时任务
* 更新定时任务
*
*
...
...
platform-process/src/main/java/cn/com/glsx/process/job/instance/SopInstExecuteJob.java
View file @
e34c15b
package
cn
.
com
.
glsx
.
process
.
job
.
instance
;
package
cn
.
com
.
glsx
.
process
.
job
.
instance
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.Set
;
import
com.dangdang.ddframe.job.api.ShardingContext
;
import
com.dangdang.ddframe.job.api.ShardingContext
;
import
com.dangdang.ddframe.job.api.simple.SimpleJob
;
import
com.dangdang.ddframe.job.api.simple.SimpleJob
;
...
@@ -11,7 +12,9 @@ import cn.com.glsx.process.modules.entity.SopInstNode;
...
@@ -11,7 +12,9 @@ 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.SopService
;
import
cn.com.glsx.process.modules.service.SopService
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.lang.Pair
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
/**
/**
...
@@ -40,14 +43,25 @@ public class SopInstExecuteJob implements SimpleJob {
...
@@ -40,14 +43,25 @@ public class SopInstExecuteJob implements SimpleJob {
// TODO 创建所有节点任务
// TODO 创建所有节点任务
for
(
SopInstNode
node
:
sop
.
getInstNodeMap
().
values
())
{
for
(
SopInstNode
node
:
sop
.
getInstNodeMap
().
values
())
{
// 前置节点,后置节点
Pair
<
Set
<
Integer
>,
Set
<
Integer
>>
linkPair
=
sop
.
getInstLinkMap
().
get
(
node
.
getNodeId
());
boolean
enabled
=
linkPair
==
null
||
linkPair
.
getKey
().
isEmpty
();
SopInstNodeParam
param
=
new
SopInstNodeParam
();
param
.
setInstNodeId
(
node
.
getInstNodeId
());
param
.
setPreIds
(
linkPair
.
getKey
());
String
paramJson
=
JSONUtil
.
toJsonStr
(
param
);
if
(
StrUtil
.
isNotBlank
(
node
.
getNodeCron
()))
{
if
(
StrUtil
.
isNotBlank
(
node
.
getNodeCron
()))
{
taskService
.
create
(
SopInstLoadJob
.
jobName
(
sop
.
getInst
(),
node
),
node
.
getNodeCron
(),
1
,
new
SopInstNodeJob
(),
// 按cron表达式执行
sop
.
getInst
().
getInstName
()
+
"-"
+
node
.
getNodeName
(),
node
.
getInstNodeId
()
+
""
);
taskService
.
create
(
SopInstLoadJob
.
jobName
(
sop
.
getInst
(),
node
),
node
.
getNodeCron
(),
new
SopInstNodeJob
(),
sop
.
getInst
().
getInstName
()
+
"-"
+
node
.
getNodeName
(),
paramJson
,
enabled
);
}
else
{
}
else
{
// 1分钟后执行: 11 12 8 2 3 ? 2024
//
// 立即执行: 1分钟后执行: 11 12 8 2 3 ? 2024
String
cron
=
DateUtil
.
format
(
org
.
apache
.
commons
.
lang
.
time
.
DateUtils
.
addMinutes
(
new
Date
(),
1
),
"s m H d M ? yyyy"
);
String
cron
=
DateUtil
.
format
(
org
.
apache
.
commons
.
lang
.
time
.
DateUtils
.
addMinutes
(
new
Date
(),
1
),
"s m H d M ? yyyy"
);
taskService
.
create
(
SopInstLoadJob
.
jobName
(
sop
.
getInst
(),
node
),
cron
,
1
,
new
SopInstNodeJob
(),
taskService
.
create
(
SopInstLoadJob
.
jobName
(
sop
.
getInst
(),
node
),
cron
,
new
SopInstNodeJob
(),
sop
.
getInst
().
getInstName
()
+
"-"
+
node
.
getNodeName
(),
node
.
getInstNodeId
()
+
""
);
sop
.
getInst
().
getInstName
()
+
"-"
+
node
.
getNodeName
(),
paramJson
,
enabled
);
}
}
}
}
...
...
platform-process/src/main/java/cn/com/glsx/process/job/instance/SopInstNodeJob.java
View file @
e34c15b
package
cn
.
com
.
glsx
.
process
.
job
.
instance
;
package
cn
.
com
.
glsx
.
process
.
job
.
instance
;
import
java.util.Date
;
import
java.util.Set
;
import
java.util.Set
;
import
com.dangdang.ddframe.job.api.ShardingContext
;
import
com.dangdang.ddframe.job.api.ShardingContext
;
...
@@ -7,8 +8,13 @@ import com.dangdang.ddframe.job.api.simple.SimpleJob;
...
@@ -7,8 +8,13 @@ import com.dangdang.ddframe.job.api.simple.SimpleJob;
import
com.glsx.plat.context.utils.SpringUtils
;
import
com.glsx.plat.context.utils.SpringUtils
;
import
cn.com.glsx.process.job.DynamicTaskService
;
import
cn.com.glsx.process.job.DynamicTaskService
;
import
cn.com.glsx.process.modules.entity.SopInstNode
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.service.SopService
;
import
cn.com.glsx.process.modules.service.SopService
;
import
lombok.Data
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.lang.Pair
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
/**
/**
...
@@ -23,22 +29,51 @@ public class SopInstNodeJob implements SimpleJob {
...
@@ -23,22 +29,51 @@ public class SopInstNodeJob implements SimpleJob {
@Override
@Override
public
void
execute
(
ShardingContext
shardingContext
)
{
public
void
execute
(
ShardingContext
shardingContext
)
{
// 参数
// 参数
String
instNodeId
=
shardingContext
.
getJobParameter
();
String
json
=
shardingContext
.
getJobParameter
();
log
.
info
(
"---------SopInstNodeJob------------- instNodeId:{}"
,
instNodeId
);
SopInstNodeParam
param
=
JSONUtil
.
toBean
(
json
,
SopInstNodeParam
.
class
);
log
.
info
(
"---------SopInstNodeJob------------- param:{}"
,
json
);
SopService
sopService
=
SpringUtils
.
getBean
(
SopService
.
class
);
SopService
sopService
=
SpringUtils
.
getBean
(
SopService
.
class
);
DynamicTaskService
taskService
=
SpringUtils
.
getBean
(
DynamicTaskService
.
class
);
DynamicTaskService
taskService
=
SpringUtils
.
getBean
(
DynamicTaskService
.
class
);
SopStruct
sop
=
sopService
.
loadSopByInstNodeId
(
param
.
getInstNodeId
());
if
(
taskService
.
isJobStoped
(
SopInstLoadJob
.
jobName
(
sop
.
getInst
())))
{
// TODO 停止sop所有子任务
return
;
}
}
// trigger next node???
SopInstNode
node
=
sop
.
getInstNodeMap
().
get
(
param
.
getInstNodeId
());
handleNode
(
node
);
triggerNext
(
sop
,
node
,
param
);
}
public
void
triggerNext
(
SopStruct
sop
,
SopInstNode
node
,
SopInstNodeParam
param
)
{
// 前置节点,后置节点
Pair
<
Set
<
Integer
>,
Set
<
Integer
>>
linkPair
=
sop
.
getInstLinkMap
().
get
(
node
.
getNodeId
());
// TODO 加载后置节点对应的任务列表
boolean
enabled
=
linkPair
==
null
||
linkPair
.
getKey
().
isEmpty
();
param
.
setInstNodeId
(
node
.
getInstNodeId
());
param
.
setPreIds
(
linkPair
.
getKey
());
String
paramJson
=
JSONUtil
.
toJsonStr
(
param
);
@Data
String
cron
=
DateUtil
.
format
(
org
.
apache
.
commons
.
lang
.
time
.
DateUtils
.
addMinutes
(
new
Date
(),
1
),
"s m H d M ? yyyy"
);
public
static
class
SopInstNodeParam
{
cron
=
StrUtil
.
isBlank
(
node
.
getNodeCron
())
?
cron
:
node
.
getNodeCron
();
/** 实例节点id */
private
String
instNodeId
;
DynamicTaskService
taskService
=
SpringUtils
.
getBean
(
DynamicTaskService
.
class
);
// 按cron表达式执行
taskService
.
create
(
SopInstLoadJob
.
jobName
(
sop
.
getInst
(),
node
),
node
.
getNodeCron
(),
new
SopInstNodeJob
(),
sop
.
getInst
().
getInstName
()
+
"-"
+
node
.
getNodeName
(),
paramJson
,
enabled
);
}
// 执行本节点
public
void
handleNode
(
SopInstNode
node
)
{
/** 实例节点前置节点id */
private
Set
<
Integer
>
preIds
;
}
}
}
}
platform-process/src/main/java/cn/com/glsx/process/job/instance/SopInstNodeParam.java
0 → 100644
View file @
e34c15b
package
cn
.
com
.
glsx
.
process
.
job
.
instance
;
import
java.util.Set
;
import
com.alibaba.nacos.shaded.com.google.common.collect.Sets
;
import
lombok.Data
;
@Data
public
class
SopInstNodeParam
{
/** 实例节点id */
private
Integer
instNodeId
;
/** 实例节点前置节点id */
private
Set
<
Integer
>
preIds
=
Sets
.
newHashSet
();
/** 已完成的前置节点,当所有前置节点已完成时,触发本任务 */
private
Set
<
Integer
>
finishedIds
=
Sets
.
newHashSet
();
}
\ No newline at end of file
\ No newline at end of file
platform-process/src/main/java/cn/com/glsx/process/modules/controller/Controller.java
deleted
100644 → 0
View file @
d9cf876
package
cn
.
com
.
glsx
.
process
.
modules
.
controller
;
import
com.alibaba.fastjson.JSON
;
public
class
Controller
{
public
JSON
execute
(
JSON
param
)
{
System
.
out
.
println
(
"测试java"
);
return
param
;
}
}
platform-process/src/main/java/cn/com/glsx/process/modules/controller/TestJobController.java
View file @
e34c15b
...
@@ -43,7 +43,7 @@ public class TestJobController {
...
@@ -43,7 +43,7 @@ public class TestJobController {
@PostMapping
(
"/jobtestdel"
)
@PostMapping
(
"/jobtestdel"
)
@Operation
(
summary
=
"动态任务删除"
,
description
=
"动态任务删除"
)
@Operation
(
summary
=
"动态任务删除"
,
description
=
"动态任务删除"
)
public
void
deltest
(
@RequestParam
(
"jobName"
)
String
jobName
)
{
public
void
deltest
(
@RequestParam
(
"jobName"
)
String
jobName
)
{
dynamicTaskAdd
.
removeJob
(
jobName
);
dynamicTaskAdd
.
removeJob
(
jobName
);
}
}
}
}
platform-process/src/main/java/cn/com/glsx/process/modules/service/SopService.java
View file @
e34c15b
...
@@ -12,7 +12,6 @@ import org.springframework.stereotype.Service;
...
@@ -12,7 +12,6 @@ import org.springframework.stereotype.Service;
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.jwt.util.JwtUtils
;
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
;
...
@@ -49,9 +48,6 @@ public class SopService {
...
@@ -49,9 +48,6 @@ public class SopService {
private
StringRedisTemplate
stringRedisTemplate
;
private
StringRedisTemplate
stringRedisTemplate
;
@Resource
@Resource
private
JwtUtils
jwtUtils
;
@Resource
private
SopTplMapper
tplMapper
;
private
SopTplMapper
tplMapper
;
@Resource
@Resource
...
@@ -85,6 +81,11 @@ public class SopService {
...
@@ -85,6 +81,11 @@ public class SopService {
return
all
;
return
all
;
}
}
public
SopStruct
loadSopByInstNodeId
(
Integer
instNodeId
)
{
SopInstNode
instNode
=
instNodeMapper
.
selectByPrimaryKey
(
instNodeId
);
return
loadSop
(
instNode
.
getInstId
());
}
public
SopStruct
loadSop
(
String
instId
)
{
public
SopStruct
loadSop
(
String
instId
)
{
SopStruct
sop
=
new
SopStruct
();
SopStruct
sop
=
new
SopStruct
();
...
@@ -137,4 +138,53 @@ public class SopService {
...
@@ -137,4 +138,53 @@ public class SopService {
return
sop
;
return
sop
;
}
}
public
void
execute
()
{
// String flowInstanceId = Tools.genFlowInstanceId(session.getId(), webStruct.getFlowId());
//
// ConcurrentHashMap<String, RunResult> runResultMap = new ConcurrentHashMap<String, RunResult>();
// FlowRunSort flowRunSort = new FlowRunSort();
// ExecuteStruct executeStruct = new ExecuteStruct();
// executeStruct.setMcgWebScoketCode(webStruct.getMcgWebScoketCode());
// executeStruct.setFlowId(webStruct.getFlowId());
// executeStruct.setFlowInstanceId(flowInstanceId);
// executeStruct.setDataMap(flowRunSort.init(flowStruct));
// executeStruct.setOrders(flowRunSort.getFlowSort());
// executeStruct.setRunResultMap(runResultMap);
// executeStruct.setSession(session);
// executeStruct.setTopology(curTopology);
// executeStruct.setSubFlag(subFlag);
// executeStruct.setRunStatus(runStatus);
//
// notifyBody.setContent("【" + curTopology.getName() + "】流程执行开始!");
// notifyBody.setType(LogTypeEnum.INFO.getValue());
// message.setBody(notifyBody);
// MessagePlugin.push(webStruct.getMcgWebScoketCode(), session.getId(), message);
//
// try {
// FlowTask flowTask = new FlowTask(webStruct.getMcgWebScoketCode(), session.getId(), executeStruct, subFlag);
//
// FlowInstancesUtils.executeStructMap.put(flowInstanceId, executeStruct);
// Future<RunStatus> future = ThreadPoolUtils.FLOW_WORK_EXECUTOR.submit(flowTask);
//
// FlowInstancesUtils.executeStructMap.get(flowInstanceId).getFlowTaskFutureList().add(future);
// if(subFlag) {
//
// String subFlowInstanceId = Tools.genFlowInstanceId(session.getId(), parentFlowId);
// ExecuteStruct parentExecuteStruct = FlowInstancesUtils.executeStructMap.get(subFlowInstanceId);
// executeStruct.setParentParam(parentParam);
// parentExecuteStruct.setChildExecuteStruct(executeStruct);
// }
// runStatus = future.get();
// logger.debug("流程:{}, 执行结果:{}", JSON.toJSONString(curTopology), JSON.toJSONString(runStatus));
// return runStatus;
//
// } catch(CancellationException e) {
// executeStruct.getRunStatus().setInterrupt(true);
// logger.error("流程执行中断,抛出CancellationException,异常信息:", e);
// } catch (InterruptedException e) {
// executeStruct.getRunStatus().setInterrupt(true);
// logger.error("流程执行中断,抛出InterruptedException,异常信息:", e);
// }
}
}
}
platform-process/src/main/java/cn/com/glsx/process/modules/sop/SopNodeExecutor.java
deleted
100644 → 0
View file @
d9cf876
package
cn
.
com
.
glsx
.
process
.
modules
.
sop
;
import
cn.hutool.json.JSON
;
/**
* 节点执行器
*
* @author kome
* @date 2023年9月10日 下午3:18:31
*/
public
abstract
class
SopNodeExecutor
{
/**
* 判断依赖的执行条件是否都满足了
*
* @return
*/
public
abstract
boolean
executeAble
();
public
abstract
void
prepare
();
public
abstract
JSON
execute
(
JSON
param
);
}
platform-process/src/main/java/cn/com/glsx/process/plugin/java/DynamicEngine.java
View file @
e34c15b
...
@@ -16,9 +16,6 @@
...
@@ -16,9 +16,6 @@
package
cn
.
com
.
glsx
.
process
.
plugin
.
java
;
package
cn
.
com
.
glsx
.
process
.
plugin
.
java
;
import
cn.com.glsx.process.common.constant.Constants
;
import
javax.tools.*
;
import
java.io.File
;
import
java.io.File
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
...
@@ -27,18 +24,29 @@ import java.net.URLClassLoader;
...
@@ -27,18 +24,29 @@ import java.net.URLClassLoader;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
javax.tools.Diagnostic
;
import
javax.tools.DiagnosticCollector
;
import
javax.tools.JavaCompiler
;
import
javax.tools.JavaFileObject
;
import
javax.tools.ToolProvider
;
import
cn.com.glsx.process.common.constant.Constants
;
public
class
DynamicEngine
{
public
class
DynamicEngine
{
private
static
DynamicEngine
ourInstance
=
new
DynamicEngine
();
private
static
DynamicEngine
ourInstance
=
new
DynamicEngine
();
public
static
DynamicEngine
getInstance
()
{
public
static
DynamicEngine
getInstance
()
{
return
ourInstance
;
return
ourInstance
;
}
}
private
URLClassLoader
parentClassLoader
;
private
URLClassLoader
parentClassLoader
;
private
String
classpath
;
private
String
classpath
;
private
DynamicEngine
()
{
private
DynamicEngine
()
{
this
.
parentClassLoader
=
(
URLClassLoader
)
this
.
getClass
().
getClassLoader
();
this
.
parentClassLoader
=
(
URLClassLoader
)
this
.
getClass
().
getClassLoader
();
this
.
buildClassPath
();
this
.
buildClassPath
();
}
}
private
void
buildClassPath
()
{
private
void
buildClassPath
()
{
this
.
classpath
=
null
;
this
.
classpath
=
null
;
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
...
@@ -51,6 +59,7 @@ public class DynamicEngine {
...
@@ -51,6 +59,7 @@ public class DynamicEngine {
/**
/**
* 调用类方法
* 调用类方法
*
* @param cls 类
* @param cls 类
* @param methodName 方法名
* @param methodName 方法名
* @param paramsCls 方法参数类型
* @param paramsCls 方法参数类型
...
@@ -63,7 +72,8 @@ public class DynamicEngine {
...
@@ -63,7 +72,8 @@ public class DynamicEngine {
* @throws InvocationTargetException
* @throws InvocationTargetException
* @throws IllegalArgumentException
* @throws IllegalArgumentException
*/
*/
public
Object
invoke
(
Class
<?>
cls
,
String
methodName
,
Class
<?>[]
paramsCls
,
Object
[]
params
)
throws
NoSuchMethodException
,
SecurityException
,
InstantiationException
,
IllegalAccessException
,
IllegalArgumentException
,
InvocationTargetException
{
public
Object
invoke
(
Class
<?>
cls
,
String
methodName
,
Class
<?>[]
paramsCls
,
Object
[]
params
)
throws
NoSuchMethodException
,
SecurityException
,
InstantiationException
,
IllegalAccessException
,
IllegalArgumentException
,
InvocationTargetException
{
Object
result
=
null
;
Object
result
=
null
;
Method
method
=
cls
.
getDeclaredMethod
(
methodName
,
paramsCls
);
Method
method
=
cls
.
getDeclaredMethod
(
methodName
,
paramsCls
);
Object
obj
=
cls
.
newInstance
();
Object
obj
=
cls
.
newInstance
();
...
@@ -71,7 +81,7 @@ public class DynamicEngine {
...
@@ -71,7 +81,7 @@ public class DynamicEngine {
return
result
;
return
result
;
}
}
public
Object
execute
(
String
fullClassName
,
String
javaCode
,
String
method
,
Class
<?>[]
paramsCls
,
Object
[]
params
)
throws
Exception
{
public
Object
execute
(
String
fullClassName
,
String
javaCode
,
String
method
,
Class
<?>[]
paramsCls
,
Object
[]
params
)
throws
Exception
{
Object
result
=
null
;
Object
result
=
null
;
JavaCompiler
compiler
=
ToolProvider
.
getSystemJavaCompiler
();
JavaCompiler
compiler
=
ToolProvider
.
getSystemJavaCompiler
();
DiagnosticCollector
<
JavaFileObject
>
diagnostics
=
new
DiagnosticCollector
<
JavaFileObject
>();
DiagnosticCollector
<
JavaFileObject
>
diagnostics
=
new
DiagnosticCollector
<
JavaFileObject
>();
...
@@ -92,7 +102,7 @@ public class DynamicEngine {
...
@@ -92,7 +102,7 @@ public class DynamicEngine {
if
(
success
)
{
if
(
success
)
{
JavaClassObject
jco
=
fileManager
.
getJavaClassObject
();
JavaClassObject
jco
=
fileManager
.
getJavaClassObject
();
DynamicClassLoader
dynamicClassLoader
=
new
DynamicClassLoader
(
this
.
parentClassLoader
);
DynamicClassLoader
dynamicClassLoader
=
new
DynamicClassLoader
(
this
.
parentClassLoader
);
Class
<?>
clazz
=
dynamicClassLoader
.
loadClass
(
fullClassName
,
jco
);
Class
<?>
clazz
=
dynamicClassLoader
.
loadClass
(
fullClassName
,
jco
);
result
=
invoke
(
clazz
,
method
,
paramsCls
,
params
);
result
=
invoke
(
clazz
,
method
,
paramsCls
,
params
);
// instance = clazz.newInstance();
// instance = clazz.newInstance();
...
@@ -122,4 +132,3 @@ public class DynamicEngine {
...
@@ -122,4 +132,3 @@ public class DynamicEngine {
return
res
.
toString
();
return
res
.
toString
();
}
}
}
}
platform-process/src/main/resources/application.properties_standalone
View file @
e34c15b
...
@@ -3,9 +3,21 @@ server.servlet.context-path=/process
...
@@ -3,9 +3,21 @@ server.servlet.context-path=/process
# database
# database
spring.datasource.url=jdbc:mysql://192.168.3.222:3308/platform_process_dev?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&allowMultiQueries=true
spring.datasource.url=jdbc:mysql://192.168.3.222:3308/platform_process_dev?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&allowMultiQueries=true
spring.datasource.username=
root
spring.datasource.username=
user_zhouhb
spring.datasource.password=
manager
spring.datasource.password=
WoWP7N1u
elaticjob.zookeeper.server-lists=192.168.3.101:2181
elaticjob.zookeeper.server-lists=192.168.3.101:2181
elaticjob.zookeeper.dynamiczk=192.168.3.101:2181
elaticjob.zookeeper.dynamiczk=192.168.3.101:2181
elaticjob.zookeeper.namespace=glsx_sop
elaticjob.zookeeper.namespace=glsx_sop
xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
xxl.job.accessToken=default_token
xxl.job.executor.appname=xxl-job-executor-test
xxl.job.executor.address=
xxl.job.executor.ip=127.0.0.1
xxl.job.executor.port=8080
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler
xxl.job.executor.logretentiondays=30
xxl.job.executor.groupId=1
platform-process/src/main/resources/bootstrap.properties
View file @
e34c15b
...
@@ -2,6 +2,13 @@ spring.application.name=platform-process
...
@@ -2,6 +2,13 @@ spring.application.name=platform-process
logging.path
=
/data/java_log/jetty/${spring.application.name}/${spring.application.name}.log
logging.path
=
/data/java_log/jetty/${spring.application.name}/${spring.application.name}.log
### 禁用nacos,启用本地配置文件
#spring.cloud.nacos.config.enabled=false
#spring.cloud.nacos.config.refresh-enabled=false
#spring.cloud.nacos.discovery.enabled=false
#spring.cloud.nacos.discovery.instance-enabled=false
spring.cloud.nacos.config.server-
addr
=
192.168.0.63:8868
spring.cloud.nacos.config.server-
addr
=
192.168.0.63:8868
spring.cloud.nacos.config.group
=
PLATFORM_GROUP
spring.cloud.nacos.config.group
=
PLATFORM_GROUP
...
@@ -18,3 +25,7 @@ spring.cloud.nacos.config.shared-configs[1].data-id=platform-share-dev.propertie
...
@@ -18,3 +25,7 @@ spring.cloud.nacos.config.shared-configs[1].data-id=platform-share-dev.propertie
spring.cloud.nacos.config.shared-configs[1]
.refresh
=
true
spring.cloud.nacos.config.shared-configs[1]
.refresh
=
true
#@PropertySource("file:${env.properties.path}/${env.profile}/application.properties")
#spring.config.location=application.properties_standalone
platform-process/src/test/java/cn/com/glsx/cn/com/glsx/util/FlowSortUtil.java
0 → 100644
View file @
e34c15b
package
cn
.
com
.
glsx
.
cn
.
com
.
glsx
.
util
;
import
java.util.Map
;
import
java.util.Set
;
import
com.alibaba.nacos.shaded.com.google.common.collect.Sets
;
import
com.fasterxml.jackson.core.type.TypeReference
;
/**
* 遍历流程所有节点
*
* @author kome
* @date 2023年9月13日 下午3:24:28
*/
public
class
FlowSortUtil
{
public
static
void
main
(
String
[]
args
)
{
String
json
=
"{\"1\":{\"value\":[10],\"key\":[]},\"2\":{\"value\":[3,4],\"key\":[10]},\"3\":{\"value\":[9],\"key\":[2]},\"4\":{\"value\":[9],\"key\":[2]},\"5\":{\"value\":[9],\"key\":[8]},\"6\":{\"value\":[9],\"key\":[8]},\"7\":{\"value\":[],\"key\":[9]},\"8\":{\"value\":[5,6],\"key\":[10]},\"9\":{\"value\":[7],\"key\":[3,4,5,6]},\"10\":{\"value\":[2,8],\"key\":[1]}}"
;
Map
<
Integer
,
Pair
<
Set
<
Integer
>,
Set
<
Integer
>>>
instLinkMap
=
JacksonUtils
.
fromJson
(
json
,
new
TypeReference
<
Map
<
Integer
,
Pair
<
Set
<
Integer
>,
Set
<
Integer
>>>>()
{
});
Set
<
Integer
>
keys
=
Sets
.
newHashSet
();
int
i
=
0
;
while
(
keys
.
size
()
<
instLinkMap
.
keySet
().
size
())
{
Set
<
Integer
>
sets
=
instLinkMap
.
keySet
();
for
(
Integer
key
:
sets
)
{
// System.out.println("i:" + i++);
Pair
<
Set
<
Integer
>,
Set
<
Integer
>>
pair
=
instLinkMap
.
get
(
key
);
if
(!
keys
.
contains
(
key
))
{
// 第一个节点:直接执行
if
(
pair
.
getKey
().
isEmpty
())
{
keys
.
add
(
key
);
System
.
out
.
println
(
key
);
continue
;
}
// 非第一个节点:判断前置节点
if
(
keys
.
containsAll
(
pair
.
getKey
()))
{
keys
.
add
(
key
);
System
.
out
.
println
(
key
);
continue
;
}
}
else
{
// 进入后置节点
sets
=
pair
.
getValue
();
}
}
}
}
}
platform-process/src/test/java/cn/com/glsx/cn/com/glsx/util/JacksonUtils.java
0 → 100644
View file @
e34c15b
package
cn
.
com
.
glsx
.
cn
.
com
.
glsx
.
util
;
import
java.io.IOException
;
import
java.lang.reflect.Type
;
import
java.text.SimpleDateFormat
;
import
java.time.LocalDateTime
;
import
java.time.ZonedDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
org.apache.commons.lang3.StringUtils
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.BeanProperty
;
import
com.fasterxml.jackson.databind.DeserializationContext
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.JavaType
;
import
com.fasterxml.jackson.databind.JsonDeserializer
;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.fasterxml.jackson.databind.JsonSerializer
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.PropertyNamingStrategy
;
import
com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.databind.SerializerProvider
;
import
com.fasterxml.jackson.databind.cfg.MapperConfig
;
import
com.fasterxml.jackson.databind.deser.ContextualDeserializer
;
import
com.fasterxml.jackson.databind.deser.std.StdDeserializer
;
import
com.fasterxml.jackson.databind.introspect.AnnotatedField
;
import
com.fasterxml.jackson.databind.introspect.AnnotatedMethod
;
import
com.fasterxml.jackson.databind.module.SimpleModule
;
import
com.fasterxml.jackson.databind.ser.std.StdSerializer
;
import
com.fasterxml.jackson.databind.util.JSONPObject
;
import
cn.hutool.core.codec.Base64
;
import
cn.hutool.core.date.DatePattern
;
import
lombok.val
;
import
lombok.extern.slf4j.Slf4j
;
import
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
;
@SuppressWarnings
(
"restriction"
)
public
class
JacksonUtils
{
// 转换全部字段
public
final
static
JsonMapper
normalMapper
=
JsonMapper
.
buildNormalBinder
();
// 不转换默认值的字段
public
final
static
JsonMapper
nodefaultMapper
=
JsonMapper
.
buildNonDefaultBinder
();
// 不转换空字段
public
final
static
JsonMapper
noemptyMapper
=
JsonMapper
.
buildNonEmptyBinder
();
// 不转换null字段
public
final
static
JsonMapper
nonullMapper
=
JsonMapper
.
buildNonNullBinder
();
// 不转换null字段
public
final
static
JsonMapper
null2emptyMapper
=
JsonMapper
.
buildNull2EmptyBinder
();
// 首字母大写
public
final
static
JsonMapper
downCaseMapper
=
JsonMapper
.
buildDownCaseBinder
();
// 下划线
public
final
static
JsonMapper
snakeMapper
=
JsonMapper
.
buildSnakeCaseBinder
();
// // 下划线+base64 decode
// public final static JsonMapper wxMapper = JsonMapper.buildWxCaseBinder();
public
static
<
T
>
String
toJson
(
T
t
)
{
return
normalMapper
.
toJson
(
t
);
}
public
static
<
T
>
T
fromJson
(
String
json
,
Class
<
T
>
clazz
)
{
return
normalMapper
.
fromJson
(
json
,
clazz
);
}
public
static
<
T
,
S
>
T
fromJson
(
String
json
,
Class
<
T
>
owner
,
Class
<
S
>
subClass
)
{
return
normalMapper
.
fromJson
(
json
,
owner
,
subClass
);
}
/**
* <code>
* List<String> list = JsonUtil.fromJson(json, new TypeReference<ArrayList<String>>() {});
* </code>
*
* @param <T>
* @param json
* @param t
* @return
*/
public
static
<
T
>
T
fromJson
(
String
json
,
TypeReference
<
T
>
t
)
{
return
normalMapper
.
fromJson
(
json
,
t
);
}
public
static
<
T
>
T
convertJsonClazz
(
Object
object
,
Class
<
T
>
clazz
)
{
return
normalMapper
.
convertJsonClazz
(
object
,
clazz
);
}
/**
* 构造函数
*/
private
JacksonUtils
()
{
}
@Slf4j
public
static
class
JsonMapper
{
private
ObjectMapper
mapper
;
protected
JsonMapper
()
{
this
(
JsonInclude
.
Include
.
ALWAYS
);
}
public
JsonMapper
(
JsonInclude
.
Include
include
)
{
mapper
=
new
ObjectMapper
();
// 设置输出时包含属性的风格
mapper
.
setSerializationInclusion
(
include
);
// 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性
mapper
.
disable
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
);
// 空的bean不解析
mapper
.
disable
(
SerializationFeature
.
FAIL_ON_EMPTY_BEANS
);
// 设置日期格式
mapper
.
setDateFormat
(
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
));
//
mapper
.
registerModule
(
simpleModule
());
}
/** 创建输出全部属性到Json字符串的Binder. */
public
static
JsonMapper
buildNormalBinder
()
{
return
new
JsonMapper
(
JsonInclude
.
Include
.
ALWAYS
);
}
/** 创建只输出非空属性到Json字符串的Binder. */
public
static
JsonMapper
buildNonNullBinder
()
{
return
new
JsonMapper
(
JsonInclude
.
Include
.
NON_NULL
);
}
public
static
JsonMapper
buildNull2EmptyBinder
()
{
JsonMapper
m
=
new
JsonMapper
(
JsonInclude
.
Include
.
ALWAYS
);
m
.
mapper
.
getSerializerProvider
().
setNullValueSerializer
(
new
JsonSerializer
<
Object
>()
{
@Override
public
void
serialize
(
Object
value
,
JsonGenerator
jgen
,
SerializerProvider
provider
)
throws
IOException
,
JsonProcessingException
{
jgen
.
writeString
(
""
);
}
});
return
m
;
}
/** 创建只输出初始值被改变的属性到Json字符串的Binder. */
public
static
JsonMapper
buildNonDefaultBinder
()
{
return
new
JsonMapper
(
JsonInclude
.
Include
.
NON_DEFAULT
);
}
/** 创建只输出非Null且非Empty(如List.isEmpty)的属性到Json字符串的Binder */
public
static
JsonMapper
buildNonEmptyBinder
()
{
return
new
JsonMapper
(
JsonInclude
.
Include
.
NON_EMPTY
);
}
/** 首字母大写 */
public
static
JsonMapper
buildDownCaseBinder
()
{
// 首字母默认小写
JsonMapper
mapper
=
new
JsonMapper
(
JsonInclude
.
Include
.
ALWAYS
);
mapper
.
mapper
.
setPropertyNamingStrategy
(
new
JacksonInitialDownCaseStrategy
());
return
mapper
;
}
/** 下划线连接 */
public
static
JsonMapper
buildSnakeCaseBinder
()
{
// 下划线
JsonMapper
mapper
=
new
JsonMapper
(
JsonInclude
.
Include
.
NON_NULL
);
mapper
.
mapper
.
setPropertyNamingStrategy
(
new
SnakeCaseStrategy
());
return
mapper
;
}
// /** 下划线连接+Base64 */
// public static JsonMapper buildWxCaseBinder() {
// // 下划线
// JsonMapper mapper = new JsonMapper(JsonInclude.Include.ALWAYS);
// mapper.mapper.setPropertyNamingStrategy(new SnakeCaseStrategy());
// mapper.mapper.setBase64Variant(Base64Variants.MIME_NO_LINEFEEDS);
// return mapper;
// }
/**
* 反序列化POJO或简单Collection如List<String>. 如果JSON字符串为null或"null"字符串,返回null. 如果JSON字符串为"[]",返回空集合.
* 如需读取集合如List/Map,且不是List<String>这种简单类型时,使用後面的函數.
*/
public
<
T
>
T
fromJson
(
String
jsonString
,
Class
<
T
>
clazz
)
{
if
(
StringUtils
.
isEmpty
(
jsonString
))
{
return
null
;
}
try
{
return
mapper
.
readValue
(
jsonString
,
clazz
);
}
catch
(
IOException
e
)
{
log
.
warn
(
"parse json string error:"
+
jsonString
,
e
);
return
null
;
}
}
public
<
T
>
T
fromJson
(
String
jsonString
,
TypeReference
<
T
>
type
)
{
if
(
StringUtils
.
isEmpty
(
jsonString
))
{
return
null
;
}
try
{
return
mapper
.
readValue
(
jsonString
,
type
);
}
catch
(
IOException
e
)
{
log
.
warn
(
"parse json string error:"
+
jsonString
,
e
);
return
null
;
}
}
public
<
T
,
S
>
T
fromJson
(
String
json
,
Class
<
T
>
owner
,
Class
<
S
>
subClass
)
{
if
(
subClass
==
null
)
{
return
fromJson
(
json
,
owner
);
}
Type
[]
types
=
new
Type
[
1
];
types
[
0
]
=
subClass
;
final
ParameterizedTypeImpl
type
=
ParameterizedTypeImpl
.
make
(
owner
,
types
,
owner
.
getDeclaringClass
());
TypeReference
<
T
>
typeReference
=
new
TypeReference
<
T
>()
{
@Override
public
Type
getType
()
{
return
type
;
}
};
return
fromJson
(
json
,
typeReference
);
}
/**
* 反序列化复杂Collection如List<Bean>, 先使用函數createCollectionType构造类型,然后调. 如果JSON字符串为null或"null"字符串,返回null. 如果JSON字符串为"[]",返回空集合.
*/
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
fromJson
(
String
jsonString
,
JavaType
javaType
)
{
if
(
StringUtils
.
isEmpty
(
jsonString
))
{
return
null
;
}
try
{
return
(
T
)
mapper
.
readValue
(
jsonString
,
javaType
);
}
catch
(
IOException
e
)
{
log
.
warn
(
"parse json string error:"
+
jsonString
,
e
);
return
null
;
}
}
/** 構造泛型的Type如List<MyBean>, Map<String,MyBean> */
public
JavaType
createCollectionType
(
Class
<?>
collectionClass
,
Class
<?>...
elementClasses
)
{
return
mapper
.
getTypeFactory
().
constructParametricType
(
collectionClass
,
elementClasses
);
}
/**
* Object可以是POJO,也可以是Collection或数组. 如果对象为null,返回"null". 如果集合为空集合,返回"[]".
*/
public
String
toJson
(
Object
object
)
{
try
{
if
(
object
==
null
)
{
return
null
;
}
return
mapper
.
writeValueAsString
(
object
);
}
catch
(
IOException
e
)
{
log
.
warn
(
"write to json string error:"
+
object
,
e
);
return
null
;
}
}
// 转换类型
public
<
T
>
T
convertJsonClazz
(
Object
object
,
Class
<
T
>
clazz
)
{
String
json
=
toJson
(
object
);
return
fromJson
(
json
,
clazz
);
}
/** 當JSON裡只含有Bean的部分屬性時,更新一個已存在Bean,只覆蓋該部分的屬性. */
@SuppressWarnings
(
"unchecked"
)
public
<
T
>
T
update
(
String
jsonString
,
T
object
)
{
try
{
return
(
T
)
mapper
.
readerForUpdating
(
object
).
readValue
(
jsonString
);
}
catch
(
Exception
e
)
{
log
.
warn
(
"parse json string"
+
jsonString
+
" to object:"
+
object
+
" error."
,
e
);
}
return
null
;
}
/** 輸出JSONP格式數據. */
public
String
toJsonP
(
String
functionName
,
Object
object
)
{
return
toJson
(
new
JSONPObject
(
functionName
,
object
));
}
/** 设定是否使用Enum的toString函數來读写Enum, */
public
void
enableEnumUseToString
()
{
mapper
.
enable
(
SerializationFeature
.
WRITE_ENUMS_USING_TO_STRING
);
mapper
.
enable
(
DeserializationFeature
.
READ_ENUMS_USING_TO_STRING
);
}
}
public
static
SimpleModule
simpleModule
()
{
val
bean
=
new
SimpleModule
();
bean
.
addDeserializer
(
ZonedDateTime
.
class
,
new
JsonDeserializer
<
ZonedDateTime
>()
{
@Override
public
ZonedDateTime
deserialize
(
JsonParser
jsonParser
,
DeserializationContext
deserializationContext
)
throws
IOException
,
JsonProcessingException
{
return
ZonedDateTime
.
parse
(
jsonParser
.
getValueAsString
(),
DateTimeFormatter
.
ISO_ZONED_DATE_TIME
);
}
});
bean
.
addDeserializer
(
LocalDateTime
.
class
,
new
MyLocalDatetimeDeserializer
());
bean
.
addSerializer
(
ZonedDateTime
.
class
,
new
JsonSerializer
<
ZonedDateTime
>()
{
@Override
public
void
serialize
(
ZonedDateTime
zonedDateTime
,
JsonGenerator
jsonGenerator
,
SerializerProvider
serializerProvider
)
throws
IOException
{
jsonGenerator
.
writeString
(
DateTimeFormatter
.
ISO_ZONED_DATE_TIME
.
format
(
zonedDateTime
));
}
});
bean
.
addSerializer
(
LocalDateTime
.
class
,
new
MyLocalDatetimeSerializer
());
return
bean
;
}
@SuppressWarnings
(
"serial"
)
static
class
JacksonInitialDownCaseStrategy
extends
PropertyNamingStrategy
{
@Override
public
String
nameForField
(
@SuppressWarnings
(
"rawtypes"
)
MapperConfig
config
,
AnnotatedField
field
,
String
defaultName
)
{
return
convert
(
defaultName
);
}
@Override
public
String
nameForGetterMethod
(
@SuppressWarnings
(
"rawtypes"
)
MapperConfig
config
,
AnnotatedMethod
method
,
String
defaultName
)
{
return
convert
(
defaultName
);
}
@Override
public
String
nameForSetterMethod
(
@SuppressWarnings
(
"rawtypes"
)
MapperConfig
config
,
AnnotatedMethod
method
,
String
defaultName
)
{
String
a
=
convert
(
defaultName
);
return
a
;
}
public
String
convert
(
String
defaultName
)
{
char
[]
arr
=
defaultName
.
toCharArray
();
if
(
arr
.
length
!=
0
)
{
if
(
Character
.
isLowerCase
(
arr
[
0
]))
{
char
upper
=
Character
.
toUpperCase
(
arr
[
0
]);
arr
[
0
]
=
upper
;
}
}
return
new
StringBuilder
().
append
(
arr
).
toString
();
}
}
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
public
static
class
Base64Deserializer
extends
JsonDeserializer
implements
ContextualDeserializer
{
@Override
public
JsonDeserializer
createContextual
(
DeserializationContext
context
,
BeanProperty
property
)
throws
JsonMappingException
{
return
this
;
}
@Override
public
Object
deserialize
(
JsonParser
parser
,
DeserializationContext
context
)
throws
IOException
,
JsonProcessingException
{
String
value
=
parser
.
getValueAsString
();
try
{
if
(
Base64
.
isBase64
(
value
))
{
// 判断是否切换编码格式
// value = Base64.decodeStr(value);
String
decode
=
new
String
(
org
.
apache
.
commons
.
codec
.
binary
.
Base64
.
decodeBase64
(
value
));
// 解码后不是乱码才解码,对emoji表情单独处理
// if (StrUtils.hasNormalCode(decode)) {
// value = decode;
// }
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
value
;
}
}
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
public
static
class
GBKBase64Deserializer
extends
JsonDeserializer
implements
ContextualDeserializer
{
@Override
public
JsonDeserializer
createContextual
(
DeserializationContext
context
,
BeanProperty
property
)
throws
JsonMappingException
{
return
this
;
}
@Override
public
Object
deserialize
(
JsonParser
parser
,
DeserializationContext
context
)
throws
IOException
,
JsonProcessingException
{
String
value
=
parser
.
getValueAsString
();
try
{
if
(
Base64
.
isBase64
(
value
))
{
// TODO 判断是否切换编码格式
// value = new String(Base64.decode(value.getBytes()), "GBK");
value
=
new
String
(
org
.
apache
.
commons
.
codec
.
binary
.
Base64
.
decodeBase64
(
value
),
"GBK"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
value
;
}
}
public
static
class
MyLocalDatetimeDeserializer
extends
StdDeserializer
<
LocalDateTime
>
{
private
static
final
long
serialVersionUID
=
1L
;
protected
MyLocalDatetimeDeserializer
()
{
super
(
LocalDateTime
.
class
);
}
@Override
public
LocalDateTime
deserialize
(
JsonParser
jp
,
DeserializationContext
ctxt
)
throws
IOException
,
JsonProcessingException
{
return
LocalDateTime
.
parse
(
jp
.
readValueAs
(
String
.
class
),
DateTimeFormatter
.
ofPattern
(
DatePattern
.
NORM_DATETIME_PATTERN
));
}
}
public
static
class
MyLocalDatetimeSerializer
extends
StdSerializer
<
LocalDateTime
>
{
private
static
final
long
serialVersionUID
=
1L
;
public
MyLocalDatetimeSerializer
()
{
super
(
LocalDateTime
.
class
);
}
@Override
public
void
serialize
(
LocalDateTime
value
,
JsonGenerator
gen
,
SerializerProvider
sp
)
throws
IOException
,
JsonProcessingException
{
gen
.
writeString
(
value
.
format
(
DateTimeFormatter
.
ofPattern
(
DatePattern
.
NORM_DATETIME_PATTERN
)));
}
}
// @SuppressWarnings({ "rawtypes" })
// public static class Base64Serializer extends JsonSerializer implements ContextualSerializer {
//
// @Override
// public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException {
// return this;
// }
//
// @Override
// public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
// if (!Base64.isBase64Pattern((String) value)) {
// value = Base64.decodeStr((String) value);
// }
// gen.writeObject(value);
// }
//
// }
@SuppressWarnings
(
"unchecked"
)
public
static
void
main
(
String
[]
args
)
{
String
json
=
"[\"A\",\"B\"]"
;
List
<
String
>
list
=
JacksonUtils
.
fromJson
(
json
,
ArrayList
.
class
);
System
.
out
.
println
(
list
.
get
(
0
));
list
=
JacksonUtils
.
fromJson
(
json
,
new
TypeReference
<
ArrayList
<
String
>>()
{
});
System
.
out
.
println
(
list
.
get
(
0
));
System
.
out
.
println
(
new
Date
(
10000000000000L
));
}
}
\ No newline at end of file
\ No newline at end of file
platform-process/src/test/java/cn/com/glsx/cn/com/glsx/util/Pair.java
0 → 100644
View file @
e34c15b
package
cn
.
com
.
glsx
.
cn
.
com
.
glsx
.
util
;
import
java.io.Serializable
;
@SuppressWarnings
(
"serial"
)
public
class
Pair
<
K
,
V
>
implements
Serializable
{
private
K
key
;
private
V
value
;
public
Pair
()
{
}
public
Pair
(
K
key
,
V
value
)
{
this
.
key
=
key
;
this
.
value
=
value
;
}
/**
* @return the key
*/
public
final
K
getKey
()
{
return
key
;
}
/**
* @param key the key to set
*/
public
final
void
setKey
(
K
key
)
{
this
.
key
=
key
;
}
/**
* @return the value
*/
public
final
V
getValue
()
{
return
value
;
}
/**
* @param value the value to set
*/
public
final
void
setValue
(
V
value
)
{
this
.
value
=
value
;
}
/**
* @return
* @see java.lang.Object#toString()
*/
@Override
public
String
toString
()
{
return
"["
+
key
+
" : "
+
value
+
"]"
;
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
((
key
==
null
)
?
0
:
key
.
hashCode
());
result
=
prime
*
result
+
((
value
==
null
)
?
0
:
value
.
hashCode
());
return
result
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
{
return
true
;
}
if
(
obj
==
null
)
{
return
false
;
}
if
(
getClass
()
!=
obj
.
getClass
())
{
return
false
;
}
Pair
<?,
?>
other
=
(
Pair
<?,
?>)
obj
;
if
(
key
==
null
)
{
if
(
other
.
key
!=
null
)
{
return
false
;
}
}
else
if
(!
key
.
equals
(
other
.
key
))
{
return
false
;
}
if
(
value
==
null
)
{
if
(
other
.
value
!=
null
)
{
return
false
;
}
}
else
if
(!
value
.
equals
(
other
.
value
))
{
return
false
;
}
return
true
;
}
public
K
first
()
{
return
getKey
();
}
public
V
second
()
{
return
getValue
();
}
}
\ No newline at end of file
\ No newline at end of file
scripts/sql/platform_process_dev.sql
0 → 100644
View file @
e34c15b
This diff could not be displayed because it is too large.
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