Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
byit-myth-job
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyuan
byit-myth-job
Commits
591c3b52
Commit
591c3b52
authored
Dec 14, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
脚本类数据
parent
82ecd236
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
412 additions
and
84 deletions
+412
-84
NodeTypeEnum.java
...admin-core/src/main/java/com/byit/enums/NodeTypeEnum.java
+1
-1
RunRecordingMapper.java
...ore/src/main/java/com/byit/mapper/RunRecordingMapper.java
+1
-1
RunRecordingService.java
...e/src/main/java/com/byit/service/RunRecordingService.java
+1
-1
RunRecordingServiceImpl.java
...n/java/com/byit/service/impl/RunRecordingServiceImpl.java
+2
-2
RunRecordingAndJobTaskServiceImpl.java
...ce/mapservice/impl/RunRecordingAndJobTaskServiceImpl.java
+1
-1
TaskRunTheLifeCycleCallback.java
...n/java/com/byit/strategy/TaskRunTheLifeCycleCallback.java
+36
-0
RpcCallbackInstanceRunTheLifeCycleCallback.java
...instances/RpcCallbackInstanceRunTheLifeCycleCallback.java
+1
-1
RunRecordingRunRedisRemoveTheLifeCycleCallback.java
...ances/RunRecordingRunRedisRemoveTheLifeCycleCallback.java
+1
-1
WorkflowCommonParameterAggregation.java
...trategy/instances/WorkflowCommonParameterAggregation.java
+1
-1
ScriptCommandTaskRunTheLifeCycleCallback.java
...rategy/task/ScriptCommandTaskRunTheLifeCycleCallback.java
+85
-0
ScriptParamMergeTaskRunTheLifeCycleCallback.java
...egy/task/ScriptParamMergeTaskRunTheLifeCycleCallback.java
+122
-0
ScriptSpecialParametersTaskRunTheLifeCycleCallback.java
...k/ScriptSpecialParametersTaskRunTheLifeCycleCallback.java
+140
-0
ScriptExecutorJobTask.java
...re/src/main/java/com/byit/task/ScriptExecutorJobTask.java
+15
-71
RunRecordingMapper.xml
...min-core/src/main/resources/mapper/RunRecordingMapper.xml
+2
-2
ScriptParamAndPlaceholderDto.java
...a/com/byit/dto/executor/ScriptParamAndPlaceholderDto.java
+3
-2
No files found.
byit-myth-core/myth-admin-core/src/main/java/com/byit/enums/NodeTypeEnum.java
View file @
591c3b52
...
...
@@ -29,7 +29,7 @@ public enum NodeTypeEnum {
return
this
.
code
;
}
public
NodeTypeEnum
getTypeByCode
(
String
code
){
public
static
NodeTypeEnum
getTypeByCode
(
String
code
){
for
(
NodeTypeEnum
typeEnum
:
NodeTypeEnum
.
values
())
{
if
(
typeEnum
.
getCode
().
equals
(
code
)){
return
typeEnum
;
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/mapper/RunRecordingMapper.java
View file @
591c3b52
...
...
@@ -79,7 +79,7 @@ public interface RunRecordingMapper {
* @param runId
* @return
*/
RunRecording
findAllByRunID
(
String
runId
);
RunRecording
findAllByRunID
AndFlowName
(
@Param
(
"runId"
)
String
runId
,
@Param
(
"flowName"
)
String
flowName
);
/**
*根据运行标识查询对应的运行实例
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/service/RunRecordingService.java
View file @
591c3b52
...
...
@@ -75,7 +75,7 @@ public interface RunRecordingService {
* @param runId
* @return
*/
RunRecording
findAllByRunID
(
String
runId
);
RunRecording
findAllByRunID
AndFlowName
(
String
runId
,
String
flowName
);
/**
* 根据工作流ID查询 是否有正在运行中的实例
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/service/impl/RunRecordingServiceImpl.java
View file @
591c3b52
...
...
@@ -124,8 +124,8 @@ public class RunRecordingServiceImpl implements RunRecordingService {
}
@Override
public
RunRecording
findAllByRunID
(
String
runId
)
{
return
runRecordingMapper
.
findAllByRunID
(
runId
);
public
RunRecording
findAllByRunID
AndFlowName
(
String
runId
,
String
flowName
)
{
return
runRecordingMapper
.
findAllByRunID
AndFlowName
(
runId
,
flowName
);
}
/**
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/service/mapservice/impl/RunRecordingAndJobTaskServiceImpl.java
View file @
591c3b52
...
...
@@ -238,7 +238,7 @@ public class RunRecordingAndJobTaskServiceImpl implements RunRecordingAndJobTask
@Transactional
(
rollbackFor
=
Exception
.
class
,
propagation
=
Propagation
.
REQUIRED
)
public
void
updateRunRecordingAndTask
(
WaitingRecord
waitingRecord
)
{
log
.
debug
(
"---------开始查询等待工作流{}对应的数据-------------"
,
waitingRecord
);
RunRecording
runRecording
=
runRecordingService
.
findAllByRunID
(
waitingRecord
.
getRunId
());
RunRecording
runRecording
=
runRecordingService
.
findAllByRunID
AndFlowName
(
waitingRecord
.
getRunId
(),
waitingRecord
.
getFlowName
());
log
.
info
(
"-------修改运行实例表成功,查询对应等待实例{},的等待节点-------"
,
waitingRecord
);
List
<
WaitingTask
>
allByWaitId
=
taskService
.
findAllByWaitId
(
waitingRecord
.
getWaitId
());
if
(
waitingRecord
.
getFlowNodeCount
()
!=
allByWaitId
.
size
()){
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/strategy/TaskRunTheLifeCycleCallback.java
0 → 100644
View file @
591c3b52
package
com
.
byit
.
strategy
;
import
com.byit.model.JobTaskSchedule
;
/**
* 任务执行生命周期
*
* @author huangfu
* @date 2020年12月14日18:24:11
*/
public
interface
TaskRunTheLifeCycleCallback
{
/**
* 实例执行前
*
* @param jobTaskSchedule 任务对象
*/
default
void
postProcessAfterInitialization
(
JobTaskSchedule
jobTaskSchedule
)
{
}
/**
* 后置处理器
*
* @param jobTaskSchedule 任务对象
*/
default
void
postProcessBeforeInitialization
(
JobTaskSchedule
jobTaskSchedule
)
{
}
/**
* 判断是否匹配类型
*
* @param jobTaskSchedule 任务对象
* @return 是否匹配本次的执行对象
*/
boolean
matchType
(
JobTaskSchedule
jobTaskSchedule
);
}
byit-myth-core/myth-admin-core/src/main/java/com/byit/strategy/i
mpl
/RpcCallbackInstanceRunTheLifeCycleCallback.java
→
byit-myth-core/myth-admin-core/src/main/java/com/byit/strategy/i
nstances
/RpcCallbackInstanceRunTheLifeCycleCallback.java
View file @
591c3b52
package
com
.
byit
.
strategy
.
i
mpl
;
package
com
.
byit
.
strategy
.
i
nstances
;
import
com.alibaba.fastjson.JSON
;
import
com.byit.annotations.MythRankOrder
;
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/strategy/i
mpl
/RunRecordingRunRedisRemoveTheLifeCycleCallback.java
→
byit-myth-core/myth-admin-core/src/main/java/com/byit/strategy/i
nstances
/RunRecordingRunRedisRemoveTheLifeCycleCallback.java
View file @
591c3b52
package
com
.
byit
.
strategy
.
i
mpl
;
package
com
.
byit
.
strategy
.
i
nstances
;
import
com.alibaba.fastjson.JSON
;
import
com.byit.annotations.MythRankOrder
;
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/strategy/i
mpl
/WorkflowCommonParameterAggregation.java
→
byit-myth-core/myth-admin-core/src/main/java/com/byit/strategy/i
nstances
/WorkflowCommonParameterAggregation.java
View file @
591c3b52
package
com
.
byit
.
strategy
.
i
mpl
;
package
com
.
byit
.
strategy
.
i
nstances
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.alibaba.fastjson.JSON
;
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/strategy/task/ScriptCommandTaskRunTheLifeCycleCallback.java
0 → 100644
View file @
591c3b52
package
com
.
byit
.
strategy
.
task
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.byit.annotations.MythRankOrder
;
import
com.byit.dto.executor.RunParamWrapped
;
import
com.byit.dto.executor.ScriptParamAndPlaceholderDto
;
import
com.byit.enums.NodeTypeEnum
;
import
com.byit.enums.PlaceholderEnum
;
import
com.byit.enums.ScheduleTypeEnum
;
import
com.byit.job.utils.PlaceholderUtils
;
import
com.byit.model.JobTaskSchedule
;
import
com.byit.strategy.TaskRunTheLifeCycleCallback
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
/**
* 脚本命令参数替换
*
* @author huangfu
* @date 2020年12月14日20:39:53
*/
@Component
@Slf4j
@MythRankOrder
(
10
)
public
class
ScriptCommandTaskRunTheLifeCycleCallback
implements
TaskRunTheLifeCycleCallback
{
public
static
final
String
JAVA_TYPE
=
"java"
;
/**
* 脚本类型的数据
*/
public
static
final
String
SCRIPT
=
"SCRIPT"
;
/**
* 任务执行前
*
* @param jobTaskSchedule 任务对象
*/
@Override
public
void
postProcessAfterInitialization
(
JobTaskSchedule
jobTaskSchedule
)
{
String
runParam
=
jobTaskSchedule
.
getRunParam
();
RunParamWrapped
runParamWrapped
=
JSON
.
parseObject
(
runParam
,
RunParamWrapped
.
class
);
String
privateParam
=
runParamWrapped
.
getPrivateParam
();
ScriptParamAndPlaceholderDto
scriptParamAndPlaceholderDto
=
JSON
.
parseObject
(
privateParam
,
ScriptParamAndPlaceholderDto
.
class
);
String
command
=
jobTaskSchedule
.
getRunCommand
();
//脚本参数不为空的时候
if
(
scriptParamAndPlaceholderDto
!=
null
)
{
Map
<
String
,
String
>
param
=
scriptParamAndPlaceholderDto
.
getParam
();
if
(
CollectionUtil
.
isNotEmpty
(
param
))
{
//将参数追加到命令上
command
=
PlaceholderUtils
.
commandReplace
(
command
,
param
);
}
//补批的
if
(
ScheduleTypeEnum
.
REPAIR
.
getCode
().
equals
(
jobTaskSchedule
.
getScheduleType
()))
{
if
(
command
.
startsWith
(
JAVA_TYPE
))
{
//去替换时间
command
=
PlaceholderUtils
.
commandDateReplace
(
param
,
command
,
param
.
get
(
PlaceholderEnum
.
DATE_PLACEHOLDER
.
getName
()),
param
.
get
(
PlaceholderEnum
.
NOW_DATE_PLACEHOLDER
.
getName
()));
}
}
jobTaskSchedule
.
setRunCommand
(
command
);
}
}
/**
* 判断是否匹配类型
*
* @param jobTaskSchedule 任务对象
* @return 是否匹配本次的执行对象
*/
@Override
public
boolean
matchType
(
JobTaskSchedule
jobTaskSchedule
)
{
String
jobType
=
jobTaskSchedule
.
getJobType
();
NodeTypeEnum
typeByCode
=
NodeTypeEnum
.
getTypeByCode
(
jobType
);
if
(
typeByCode
==
null
)
{
throw
new
RuntimeException
(
String
.
format
(
"调度暂不支持此种类型的任务:%s"
,
jobType
));
}
return
typeByCode
.
getType
().
equals
(
SCRIPT
);
}
}
byit-myth-core/myth-admin-core/src/main/java/com/byit/strategy/task/ScriptParamMergeTaskRunTheLifeCycleCallback.java
0 → 100644
View file @
591c3b52
package
com
.
byit
.
strategy
.
task
;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.byit.annotations.MythRankOrder
;
import
com.byit.dto.executor.RunParamWrapped
;
import
com.byit.dto.executor.ScriptParamAndPlaceholderDto
;
import
com.byit.dto.plugin.FlowExtendedConfiguration
;
import
com.byit.enums.NodeTypeEnum
;
import
com.byit.model.JobTaskSchedule
;
import
com.byit.model.RunRecording
;
import
com.byit.service.RunRecordingService
;
import
com.byit.strategy.TaskRunTheLifeCycleCallback
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
/**
* 脚本参数合并 私有参数与共有参数合并
*
* @author huangfu
* @date 2020年12月14日19:43:30
*/
@Component
@Slf4j
@MythRankOrder
(
5
)
public
class
ScriptParamMergeTaskRunTheLifeCycleCallback
implements
TaskRunTheLifeCycleCallback
{
private
final
StringRedisTemplate
stringRedisTemplate
;
private
final
RunRecordingService
runRecordingService
;
/**
* 脚本类型的数据
*/
public
static
final
String
SCRIPT
=
"SCRIPT"
;
public
ScriptParamMergeTaskRunTheLifeCycleCallback
(
StringRedisTemplate
stringRedisTemplate
,
RunRecordingService
runRecordingService
)
{
this
.
stringRedisTemplate
=
stringRedisTemplate
;
this
.
runRecordingService
=
runRecordingService
;
}
/**
* 实例执行前
*
* @param jobTaskSchedule 任务对象
*/
@Override
public
void
postProcessAfterInitialization
(
JobTaskSchedule
jobTaskSchedule
)
{
String
runId
=
jobTaskSchedule
.
getRunId
();
String
flowName
=
jobTaskSchedule
.
getFlowName
();
RunRecording
runRecording
=
runRecordingService
.
findAllByRunIDAndFlowName
(
runId
,
flowName
);
String
extendedConfiguration
=
runRecording
.
getExtendedConfiguration
();
FlowExtendedConfiguration
flowExtendedConfiguration
=
JSON
.
parseObject
(
extendedConfiguration
,
FlowExtendedConfiguration
.
class
);
String
publicParam
=
flowExtendedConfiguration
.
getPublicParam
();
Map
<
String
,
String
>
publicMap
=
JSON
.
parseObject
(
publicParam
,
Map
.
class
);
String
runParam
=
jobTaskSchedule
.
getRunParam
();
RunParamWrapped
runParamWrapped
=
JSON
.
parseObject
(
runParam
,
RunParamWrapped
.
class
);
if
(
runParamWrapped
==
null
)
{
runParamWrapped
=
new
RunParamWrapped
();
}
String
privateParam
=
runParamWrapped
.
getPrivateParam
();
Map
<
String
,
String
>
publicParamMap
=
runParamWrapped
.
getPublicParamMap
();
publicParamMap
.
putAll
(
publicMap
);
ScriptParamAndPlaceholderDto
scriptParamAndPlaceholderDto
=
JSON
.
parseObject
(
privateParam
,
ScriptParamAndPlaceholderDto
.
class
);
if
(
scriptParamAndPlaceholderDto
==
null
)
{
scriptParamAndPlaceholderDto
=
new
ScriptParamAndPlaceholderDto
();
}
//处理命令参数
Map
<
String
,
String
>
commandParam
=
scriptParamAndPlaceholderDto
.
getParam
();
Map
<
String
,
String
>
placeholder
=
scriptParamAndPlaceholderDto
.
getPlaceholder
();
if
(
CollectionUtil
.
isEmpty
(
commandParam
)){
commandParam
.
putAll
(
publicMap
);
}
else
{
publicMap
.
forEach
((
key
,
value
)
->{
if
(!
commandParam
.
containsKey
(
key
))
{
commandParam
.
put
(
key
,
value
);
}
});
}
//处理替换参数
if
(
CollectionUtil
.
isEmpty
(
placeholder
)){
placeholder
.
putAll
(
publicMap
);
}
else
{
publicMap
.
forEach
((
key
,
value
)
->{
if
(!
placeholder
.
containsKey
(
key
))
{
placeholder
.
put
(
key
,
value
);
}
});
}
//重新设置值
String
privateParamNew
=
JSON
.
toJSONString
(
scriptParamAndPlaceholderDto
);
runParamWrapped
.
setPrivateParam
(
privateParamNew
);
runParamWrapped
.
setPublicParamMap
(
publicParamMap
);
//设置运行参数
jobTaskSchedule
.
setRunParam
(
JSON
.
toJSONString
(
runParamWrapped
));
}
/**
* 判断是否匹配类型
*
* @param jobTaskSchedule 任务对象
* @return 是否匹配本次的执行对象
*/
@Override
public
boolean
matchType
(
JobTaskSchedule
jobTaskSchedule
)
{
String
jobType
=
jobTaskSchedule
.
getJobType
();
NodeTypeEnum
typeByCode
=
NodeTypeEnum
.
getTypeByCode
(
jobType
);
if
(
typeByCode
==
null
)
{
throw
new
RuntimeException
(
String
.
format
(
"调度暂不支持此种类型的任务:%s"
,
jobType
));
}
return
typeByCode
.
getType
().
equals
(
SCRIPT
);
}
}
byit-myth-core/myth-admin-core/src/main/java/com/byit/strategy/task/ScriptSpecialParametersTaskRunTheLifeCycleCallback.java
0 → 100644
View file @
591c3b52
package
com
.
byit
.
strategy
.
task
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.core.date.DateField
;
import
cn.hutool.core.date.DateTime
;
import
cn.hutool.core.date.DateUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.byit.annotations.MythRankOrder
;
import
com.byit.dto.executor.RunParamWrapped
;
import
com.byit.dto.executor.ScriptParamAndPlaceholderDto
;
import
com.byit.enums.NodeTypeEnum
;
import
com.byit.enums.PlaceholderEnum
;
import
com.byit.enums.ScheduleTypeEnum
;
import
com.byit.model.JobTaskSchedule
;
import
com.byit.strategy.TaskRunTheLifeCycleCallback
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Component
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 脚本执行的生命周期
* 脚本类型的任务特殊参数的替换
*
* @author huangfu
* @date 2020年12月14日18:28:08
*/
@Component
@Slf4j
@MythRankOrder
(
1
)
public
class
ScriptSpecialParametersTaskRunTheLifeCycleCallback
implements
TaskRunTheLifeCycleCallback
{
/**
* 脚本类型的数据
*/
public
static
final
String
SCRIPT
=
"SCRIPT"
;
public
static
final
String
DEFAULT_DATE_FORMAT
=
"yyyyMMdd"
;
/**
* 正常流程的情况下 进行特殊参数的替换
*
* @param jobTaskSchedule 任务对象
* @return 是否匹配
*/
@Override
public
boolean
matchType
(
JobTaskSchedule
jobTaskSchedule
)
{
String
jobType
=
jobTaskSchedule
.
getJobType
();
NodeTypeEnum
typeByCode
=
NodeTypeEnum
.
getTypeByCode
(
jobType
);
if
(
typeByCode
==
null
)
{
throw
new
RuntimeException
(
String
.
format
(
"调度暂不支持此种类型的任务:%s"
,
jobType
));
}
//是否是脚本类型的
boolean
isScript
=
typeByCode
.
getType
().
equals
(
SCRIPT
);
//是否是正常
boolean
isNormal
=
ScheduleTypeEnum
.
NORMAL
.
getCode
().
equals
(
jobTaskSchedule
.
getScheduleType
())
||
ScheduleTypeEnum
.
REAL
.
getCode
().
equals
(
jobTaskSchedule
.
getScheduleType
());
return
isScript
&&
isNormal
;
}
/**
* 实例执行前 特殊参数的替换
*
* @param jobTaskSchedule 任务对象
* @return 两者的包装对象
*/
@Override
public
void
postProcessAfterInitialization
(
JobTaskSchedule
jobTaskSchedule
)
{
String
runParam
=
jobTaskSchedule
.
getRunParam
();
//转换参数对象为参数包装体
RunParamWrapped
runParamWrapped
=
JSON
.
parseObject
(
runParam
,
RunParamWrapped
.
class
);
if
(
runParamWrapped
==
null
)
{
runParamWrapped
=
new
RunParamWrapped
();
}
String
privateParam
=
runParamWrapped
.
getPrivateParam
();
//处理私有参数
ScriptParamAndPlaceholderDto
scriptParamAndPlaceholderDto
=
JSON
.
parseObject
(
privateParam
,
ScriptParamAndPlaceholderDto
.
class
);
if
(
scriptParamAndPlaceholderDto
==
null
)
{
scriptParamAndPlaceholderDto
=
new
ScriptParamAndPlaceholderDto
();
}
//获取替换参数
Map
<
String
,
String
>
placeholder
=
scriptParamAndPlaceholderDto
.
getPlaceholder
();
//获取命令参数
Map
<
String
,
String
>
commandParam
=
scriptParamAndPlaceholderDto
.
getParam
();
//向前偏移一天
DateTime
dateTime
=
DateUtil
.
offset
(
new
Date
(),
DateField
.
HOUR_OF_DAY
,
-
1
);
//替换参数
if
(
CollectionUtil
.
isEmpty
(
placeholder
))
{
placeholder
=
new
HashMap
<>(
2
);
//替换 biz_date
placeholder
.
put
(
PlaceholderEnum
.
DATE_PLACEHOLDER
.
getName
(),
DateUtil
.
format
(
dateTime
,
DEFAULT_DATE_FORMAT
));
//替换 now_date
placeholder
.
put
(
PlaceholderEnum
.
NOW_DATE_PLACEHOLDER
.
getName
(),
DateUtil
.
format
(
new
Date
(),
DEFAULT_DATE_FORMAT
));
}
else
{
//替换 biz_date
String
bizDateFormat
=
placeholder
.
get
(
PlaceholderEnum
.
DATE_PLACEHOLDER
.
getName
());
if
(
StringUtils
.
isBlank
(
bizDateFormat
))
{
bizDateFormat
=
DEFAULT_DATE_FORMAT
;
}
placeholder
.
put
(
PlaceholderEnum
.
DATE_PLACEHOLDER
.
getName
(),
DateUtil
.
format
(
dateTime
,
bizDateFormat
));
//替换 now_date
String
nowDateFormat
=
placeholder
.
get
(
PlaceholderEnum
.
NOW_DATE_PLACEHOLDER
.
getName
());
if
(
StringUtils
.
isBlank
(
nowDateFormat
))
{
nowDateFormat
=
DEFAULT_DATE_FORMAT
;
}
placeholder
.
put
(
PlaceholderEnum
.
NOW_DATE_PLACEHOLDER
.
getName
(),
DateUtil
.
format
(
new
Date
(),
nowDateFormat
));
}
//命令参数
if
(
CollectionUtil
.
isEmpty
(
commandParam
))
{
commandParam
=
new
HashMap
<>(
4
);
//替换 biz_date
commandParam
.
put
(
PlaceholderEnum
.
DATE_PLACEHOLDER
.
getName
(),
DateUtil
.
format
(
dateTime
,
DEFAULT_DATE_FORMAT
));
//替换 now_date
commandParam
.
put
(
PlaceholderEnum
.
NOW_DATE_PLACEHOLDER
.
getName
(),
DateUtil
.
format
(
new
Date
(),
DEFAULT_DATE_FORMAT
));
}
else
{
//替换 biz_date
String
bizDateFormat
=
placeholder
.
get
(
PlaceholderEnum
.
DATE_PLACEHOLDER
.
getName
());
if
(
StringUtils
.
isBlank
(
bizDateFormat
))
{
bizDateFormat
=
DEFAULT_DATE_FORMAT
;
}
commandParam
.
put
(
PlaceholderEnum
.
DATE_PLACEHOLDER
.
getName
(),
DateUtil
.
format
(
dateTime
,
bizDateFormat
));
//替换 now_date
String
nowDateFormat
=
placeholder
.
get
(
PlaceholderEnum
.
NOW_DATE_PLACEHOLDER
.
getName
());
if
(
StringUtils
.
isBlank
(
nowDateFormat
))
{
nowDateFormat
=
DEFAULT_DATE_FORMAT
;
}
commandParam
.
put
(
PlaceholderEnum
.
NOW_DATE_PLACEHOLDER
.
getName
(),
DateUtil
.
format
(
new
Date
(),
nowDateFormat
));
}
scriptParamAndPlaceholderDto
.
setPlaceholder
(
placeholder
);
scriptParamAndPlaceholderDto
.
setParam
(
commandParam
);
//重新设置参数
runParamWrapped
.
setPrivateParam
(
JSON
.
toJSONString
(
scriptParamAndPlaceholderDto
));
jobTaskSchedule
.
setRunParam
(
JSON
.
toJSONString
(
runParamWrapped
));
}
}
byit-myth-core/myth-admin-core/src/main/java/com/byit/task/ScriptExecutorJobTask.java
View file @
591c3b52
...
...
@@ -3,6 +3,7 @@ package com.byit.task;
import
cn.hutool.core.collection.CollectionUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.byit.conf.MythJobAutoConfigure
;
import
com.byit.dto.BeanStrategyPackage
;
import
com.byit.dto.executor.DispatchResponseDto
;
import
com.byit.dto.executor.RunParamWrapped
;
import
com.byit.dto.executor.ScriptDto
;
...
...
@@ -22,6 +23,8 @@ import com.byit.service.FastRunLogService;
import
com.byit.service.FlowStatusService
;
import
com.byit.service.RunScriptService
;
import
com.byit.service.impl.JobTaskRunLogServiceImpl
;
import
com.byit.strategy.TaskRunTheLifeCycleCallback
;
import
com.byit.util.ClassSortUtil
;
import
com.byit.util.GetRegConfig
;
import
com.byit.util.SpringUtil
;
import
io.netty.util.Timeout
;
...
...
@@ -50,7 +53,7 @@ public class ScriptExecutorJobTask implements TimerTask {
private
static
final
Integer
INIT_SLEEP_TIME
=
100
;
public
static
final
String
JAVA_TYPE
=
"java"
;
private
JobTaskSchedule
mythJobTaskSchedule
;
private
final
JobTaskSchedule
mythJobTaskSchedule
;
public
ScriptExecutorJobTask
(
JobTaskSchedule
mythJobTaskSchedule
)
{
this
.
mythJobTaskSchedule
=
mythJobTaskSchedule
;
...
...
@@ -91,75 +94,6 @@ public class ScriptExecutorJobTask implements TimerTask {
return
bean
.
checkFlowStatusIsKill
(
flowId
,
runId
);
}
private
void
paramBuild
(
JobTaskSchedule
mythJobTaskSchedule
)
{
//获取参数
String
runParam
=
mythJobTaskSchedule
.
getRunParam
();
//获取命令
String
command
=
mythJobTaskSchedule
.
getRunCommand
();
command
=
PlaceholderUtils
.
formatJavaJarCommand
(
command
);
if
(!
command
.
startsWith
(
JAVA_TYPE
))
{
command
=
command
.
replaceAll
(
" "
,
"&&"
);
}
//转换参数对象为参数包装体
RunParamWrapped
runParamWrapped
=
JSON
.
parseObject
(
runParam
,
RunParamWrapped
.
class
);
//当参数包装体不为空时 证明存在参数 或私有或公有
if
(
runParamWrapped
!=
null
)
{
//获取到私有参数
String
privateParam
=
runParamWrapped
.
getPrivateParam
();
//替换运行参数中的时间参数 当为正常运行或者立即执行的时候
if
(
ScheduleTypeEnum
.
NORMAL
.
getCode
().
equals
(
mythJobTaskSchedule
.
getScheduleType
())
||
ScheduleTypeEnum
.
REAL
.
getCode
().
equals
(
mythJobTaskSchedule
.
getScheduleType
()))
{
privateParam
=
PlaceholderUtils
.
formatBizDateParam
(
privateParam
,
PlaceholderEnum
.
DATE_PLACEHOLDER
.
getName
(),
1
);
if
(
StringUtils
.
isNoneBlank
(
privateParam
))
{
ScriptParamAndPlaceholderDto
scriptParamAndPlaceholderDto
=
JSON
.
parseObject
(
privateParam
,
ScriptParamAndPlaceholderDto
.
class
);
Map
<
String
,
String
>
placeholder
=
scriptParamAndPlaceholderDto
.
getPlaceholder
();
if
(
CollectionUtil
.
isNotEmpty
(
placeholder
))
{
if
(
placeholder
.
containsKey
(
PlaceholderEnum
.
NOW_DATE_PLACEHOLDER
.
getName
()))
{
String
nowDateFormatName
=
placeholder
.
get
(
PlaceholderEnum
.
NOW_DATE_PLACEHOLDER
.
getName
());
String
dateFormat
=
DateUtil
.
dateFormat
(
new
Date
(),
nowDateFormatName
);
privateParam
=
PlaceholderUtils
.
formatBizDateParam
(
privateParam
,
PlaceholderEnum
.
NOW_DATE_PLACEHOLDER
.
getName
(),
dateFormat
,
0
);
}
}
runParamWrapped
.
setPrivateParam
(
privateParam
);
mythJobTaskSchedule
.
setRunParam
(
JSON
.
toJSONString
(
runParamWrapped
));
}
}
//获取到公有参数
Map
<
String
,
String
>
publicParam
=
runParamWrapped
.
getPublicParamMap
();
//将私有参数转换为对应的参数DTO
ScriptParamAndPlaceholderDto
scriptParamAndPlaceholderDto
=
null
;
if
(
StringUtils
.
isNoneBlank
(
privateParam
))
{
scriptParamAndPlaceholderDto
=
JSON
.
parseObject
(
privateParam
,
ScriptParamAndPlaceholderDto
.
class
);
}
//脚本参数不为空的时候
if
(
scriptParamAndPlaceholderDto
!=
null
)
{
Map
<
String
,
String
>
param
=
scriptParamAndPlaceholderDto
.
getParam
();
if
(
CollectionUtil
.
isNotEmpty
(
param
))
{
command
=
PlaceholderUtils
.
commandReplace
(
command
,
param
);
}
if
(
ScheduleTypeEnum
.
REPAIR
.
getCode
().
equals
(
mythJobTaskSchedule
.
getScheduleType
()))
{
if
(
command
.
startsWith
(
JAVA_TYPE
))
{
if
(
ScheduleTypeEnum
.
REPAIR
.
getCode
().
equals
(
mythJobTaskSchedule
.
getScheduleType
()))
{
command
=
PlaceholderUtils
.
commandDateReplace
(
param
,
command
,
param
.
get
(
PlaceholderEnum
.
DATE_PLACEHOLDER
.
getName
()),
param
.
get
(
PlaceholderEnum
.
NOW_DATE_PLACEHOLDER
.
getName
()));
}
else
{
command
=
PlaceholderUtils
.
commandDateReplace
(
param
,
command
);
}
}
}
}
//公共参数不为空的时候
if
(
CollectionUtil
.
isNotEmpty
(
publicParam
))
{
command
=
PlaceholderUtils
.
commandReplace
(
command
,
publicParam
);
}
mythJobTaskSchedule
.
setRunCommand
(
command
);
}
}
/**
* 运行任务
*
...
...
@@ -169,7 +103,17 @@ public class ScriptExecutorJobTask implements TimerTask {
DispatchResponseDto
dispatchResponseDto
=
new
DispatchResponseDto
();
String
uploadFilePath
=
null
;
try
{
paramBuild
(
mythJobTaskSchedule
);
//获取该节点的全部声明周期函数
Map
<
String
,
TaskRunTheLifeCycleCallback
>
stringTaskRunTheLifeCycleCallbackMap
=
SpringUtil
.
getBeansOfType
(
TaskRunTheLifeCycleCallback
.
class
);
//数据排序
List
<
BeanStrategyPackage
<
TaskRunTheLifeCycleCallback
>>
beanStrategyPackages
=
ClassSortUtil
.
objectSort
(
stringTaskRunTheLifeCycleCallbackMap
);
beanStrategyPackages
.
forEach
(
beanStrategyPackage
->{
log
.
info
(
"--------------脚本节点生命周期开始回调{}--------------"
,
beanStrategyPackage
.
getBeanName
());
TaskRunTheLifeCycleCallback
beanStrategyPackageBean
=
beanStrategyPackage
.
getBean
();
if
(
beanStrategyPackageBean
.
matchType
(
this
.
mythJobTaskSchedule
))
{
beanStrategyPackageBean
.
postProcessAfterInitialization
(
this
.
mythJobTaskSchedule
);
}
});
mythJobTaskSchedule
.
setRunCommand
(
mythJobTaskSchedule
.
getRunCommand
());
RunScriptService
runScriptService
=
SpringUtil
.
getBean
(
RunScriptService
.
class
);
JobTaskRunLogServiceImpl
jobTaskRunLogService
=
SpringUtil
.
getBean
(
JobTaskRunLogServiceImpl
.
class
);
...
...
byit-myth-core/myth-admin-core/src/main/resources/mapper/RunRecordingMapper.xml
View file @
591c3b52
...
...
@@ -131,11 +131,11 @@
where flow_status ='4' and is_alarm = '1' and schedule_type != 4
</select>
<!--and is_inner = '1'-->
<select
id=
"findAllByRunID"
resultMap=
"BaseResultMap"
>
<select
id=
"findAllByRunID
AndFlowName
"
resultMap=
"BaseResultMap"
>
select
<include
refid=
"Base_Column_List"
/>
from run_recording
where run_id=#{runId,jdbcType=VARCHAR} and schedule_type != 4
where run_id=#{runId,jdbcType=VARCHAR} and schedule_type != 4
and flow_name=#{flowName}
</select>
<select
id=
"findByRunID"
resultMap=
"BaseResultMap"
>
...
...
byit-myth-core/myth-dto-core/src/main/java/com/byit/dto/executor/ScriptParamAndPlaceholderDto.java
View file @
591c3b52
...
...
@@ -20,11 +20,11 @@ public class ScriptParamAndPlaceholderDto implements Serializable {
/**
* 参数的处理 命令参数
*/
private
Map
<
String
,
String
>
param
;
private
Map
<
String
,
String
>
param
=
new
HashMap
<>(
8
)
;
/**
* 占位符的处理
*/
private
Map
<
String
,
String
>
Placeholder
;
private
Map
<
String
,
String
>
Placeholder
=
new
HashMap
<>(
8
)
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment