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 4371d30e
authored
Oct 26, 2023
by
tiger
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
trigger携带基础参数
1 parent
5b0f7fc7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
66 deletions
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/core/SopXxlJobUtil.java
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/core/XxlJobUtil.java
platform-process/src/main/java/cn/com/glsx/process/modules/controller/TestXXLJobController.java
platform-process/src/test/java/cn/com/glsx/test/service/TestSopService.java
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/core/SopXxlJobUtil.java
View file @
4371d30
...
...
@@ -218,7 +218,18 @@ public class SopXxlJobUtil {
}
// 隐藏任务执行:
String
jobBusId
=
jobBusId
(
sop
.
getInst
(),
node
);
XxlJobUtil
.
trigger
(
jobBusId
);
// 前置节点,后置节点
Pair
<
Set
<
Integer
>,
Set
<
Integer
>>
linkPair
=
sop
.
getInstLinkMap
().
get
(
node
.
getNodeId
());
SopInstNodeParam
params
=
new
SopInstNodeParam
();
params
.
setInstId
(
node
.
getInstId
());
params
.
setNodeId
(
node
.
getNodeId
());
params
.
setPreIds
(
linkPair
.
getKey
());
params
.
setNextIds
(
linkPair
.
getValue
());
String
paramJson
=
JSONUtil
.
toJsonStr
(
params
);
XxlJobUtil
.
trigger
(
jobBusId
,
paramJson
);
log
.
info
(
"【{}】手动触发隐藏任务:{} - {}"
,
jobBusId
,
node
.
getNodeName
(),
node
.
getNodeCron
());
list
.
add
(
node
.
getNodeName
());
}
...
...
platform-process/src/main/java/cn/com/glsx/process/job/xxljob/core/XxlJobUtil.java
View file @
4371d30
...
...
@@ -142,10 +142,10 @@ public class XxlJobUtil {
* @param buskey 业务key
* @return {@link String}
**/
public
static
String
trigger
(
String
buskey
)
{
public
static
String
trigger
(
String
buskey
,
String
params
)
{
XxlJobInfo
byBusKey
=
findByBusKey
(
buskey
);
if
(
byBusKey
!=
null
)
{
return
doPost
(
adminAddresses
+
ADD_AND_START_URL
+
"?id="
+
byBusKey
.
getId
(),
null
,
String
.
class
);
return
doPost
(
adminAddresses
+
ADD_AND_START_URL
+
"?id="
+
byBusKey
.
getId
(),
params
,
String
.
class
);
}
return
null
;
}
...
...
platform-process/src/main/java/cn/com/glsx/process/modules/controller/TestXXLJobController.java
View file @
4371d30
package
cn
.
com
.
glsx
.
process
.
modules
.
controller
;
import
cn.com.glsx.process.common.sysenum.ResultEnum
;
import
cn.com.glsx.process.exception.AdminException
;
import
com.glsx.plat.exception.BusinessException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -13,8 +10,11 @@ import org.springframework.web.bind.annotation.RestController;
import
com.glsx.plat.core.annotation.ResponseResultBody
;
import
com.glsx.plat.core.web.R
;
import
cn.com.glsx.process.common.sysenum.ResultEnum
;
import
cn.com.glsx.process.exception.AdminException
;
import
cn.com.glsx.process.job.xxljob.core.XxlJobInfo
;
import
cn.com.glsx.process.job.xxljob.core.XxlJobUtil
;
import
cn.com.glsx.process.job.xxljob.impl.SopInstNodeExecuteJobHandler
;
import
cn.com.glsx.process.modules.service.UserDemoService
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
...
...
@@ -27,71 +27,84 @@ import lombok.extern.slf4j.Slf4j;
@ResponseResultBody
public
class
TestXXLJobController
{
@Autowired
private
UserDemoService
userDemoService
;
@Autowired
private
UserDemoService
userDemoService
;
@Autowired
private
SopInstNodeExecuteJobHandler
nodeExecutor
;
@GetMapping
(
"/jobtest"
)
@Operation
(
summary
=
"动态任务添加"
,
description
=
"动态任务添加"
)
public
void
addtest
(
@RequestParam
(
"cron"
)
String
cron
,
@RequestParam
(
"jobName"
)
String
jobName
,
@RequestParam
(
"param"
)
String
param
,
@RequestParam
(
"executorHandler"
)
String
executorHandler
,
@RequestParam
(
"busKey"
)
String
busKey
)
{
// cron表达式
XxlJobInfo
jobInfo
=
new
XxlJobInfo
();
jobInfo
.
setExecutorParam
(
param
);
jobInfo
.
setJobDesc
(
jobName
);
jobInfo
.
setAuthor
(
"admin"
);
jobInfo
.
setScheduleConf
(
cron
);
jobInfo
.
setExecutorHandler
(
executorHandler
);
jobInfo
.
setBusKey
(
busKey
);
XxlJobUtil
.
add
(
jobInfo
);
}
@GetMapping
(
"/jobtest"
)
@Operation
(
summary
=
"动态任务添加"
,
description
=
"动态任务添加"
)
public
void
addtest
(
@RequestParam
(
"cron"
)
String
cron
,
@RequestParam
(
"jobName"
)
String
jobName
,
@RequestParam
(
"param"
)
String
param
,
@RequestParam
(
"executorHandler"
)
String
executorHandler
,
@RequestParam
(
"busKey"
)
String
busKey
)
{
// cron表达式
XxlJobInfo
jobInfo
=
new
XxlJobInfo
();
jobInfo
.
setExecutorParam
(
param
);
jobInfo
.
setJobDesc
(
jobName
);
jobInfo
.
setAuthor
(
"admin"
);
jobInfo
.
setScheduleConf
(
cron
);
jobInfo
.
setExecutorHandler
(
executorHandler
);
jobInfo
.
setBusKey
(
busKey
);
XxlJobUtil
.
add
(
jobInfo
);
}
@PostMapping
(
"/jobtestupdate"
)
@Operation
(
summary
=
"动态任务更新"
,
description
=
"动态任务更新"
)
public
void
updatetest
(
@RequestParam
(
value
=
"cron"
,
required
=
false
)
String
cron
,
@RequestParam
(
"id"
)
String
id
,
@RequestParam
(
value
=
"executorParam"
,
required
=
false
)
String
executorParam
,
@RequestParam
(
value
=
"jobDesc"
,
required
=
false
)
String
jobDesc
,
@RequestParam
(
value
=
"triggerStatus"
,
required
=
false
)
Integer
triggerStatus
)
{
XxlJobInfo
jobInfo
=
new
XxlJobInfo
();
jobInfo
.
setBusKey
(
id
);
jobInfo
.
setScheduleConf
(
cron
);
jobInfo
.
setJobDesc
(
jobDesc
);
jobInfo
.
setExecutorParam
(
executorParam
);
jobInfo
.
setTriggerStatus
(
triggerStatus
);
XxlJobUtil
.
update
(
jobInfo
);
}
@PostMapping
(
"/jobtestupdate"
)
@Operation
(
summary
=
"动态任务更新"
,
description
=
"动态任务更新"
)
public
void
updatetest
(
@RequestParam
(
value
=
"cron"
,
required
=
false
)
String
cron
,
@RequestParam
(
"id"
)
String
id
,
@RequestParam
(
value
=
"executorParam"
,
required
=
false
)
String
executorParam
,
@RequestParam
(
value
=
"jobDesc"
,
required
=
false
)
String
jobDesc
,
@RequestParam
(
value
=
"triggerStatus"
,
required
=
false
)
Integer
triggerStatus
)
{
XxlJobInfo
jobInfo
=
new
XxlJobInfo
();
jobInfo
.
setBusKey
(
id
);
jobInfo
.
setScheduleConf
(
cron
);
jobInfo
.
setJobDesc
(
jobDesc
);
jobInfo
.
setExecutorParam
(
executorParam
);
jobInfo
.
setTriggerStatus
(
triggerStatus
);
XxlJobUtil
.
update
(
jobInfo
);
}
@PostMapping
(
"/jobtestdel"
)
@Operation
(
summary
=
"动态任务删除"
,
description
=
"动态任务删除"
)
public
void
deltest
(
@RequestParam
(
"id"
)
String
id
)
{
XxlJobUtil
.
remove
(
id
);
}
@PostMapping
(
"/jobtestdel
"
)
@Operation
(
summary
=
"动态任务删除"
,
description
=
"动态任务删除
"
)
public
void
deltest
(
@RequestParam
(
"id"
)
String
id
)
{
XxlJobUtil
.
remov
e
(
id
);
}
@PostMapping
(
"/pause
"
)
@Operation
(
summary
=
"动态任务暂停"
,
description
=
"动态任务暂停
"
)
public
void
pause
(
@RequestParam
(
"id"
)
String
id
)
{
XxlJobUtil
.
paus
e
(
id
);
}
@PostMapping
(
"/pause
"
)
@Operation
(
summary
=
"动态任务暂停"
,
description
=
"动态任务暂停
"
)
public
void
pause
(
@RequestParam
(
"id"
)
String
id
)
{
XxlJobUtil
.
pause
(
id
);
}
@PostMapping
(
"/start
"
)
@Operation
(
summary
=
"动态任务开启"
,
description
=
"动态任务开启
"
)
public
void
start
(
@RequestParam
(
"id"
)
String
id
)
{
XxlJobUtil
.
start
(
id
);
}
@PostMapping
(
"/start
"
)
@Operation
(
summary
=
"动态任务开启"
,
description
=
"动态任务开启
"
)
public
void
start
(
@RequestParam
(
"id"
)
String
id
)
{
XxlJobUtil
.
start
(
id
);
}
@PostMapping
(
"/trigger
"
)
@Operation
(
summary
=
"动态任务触发"
,
description
=
"动态任务触发
"
)
public
void
trigger
(
@RequestParam
(
"id"
)
String
id
)
{
XxlJobUtil
.
trigger
(
id
,
null
);
}
@PostMapping
(
"/trigger
"
)
@Operation
(
summary
=
"动态任务触发
"
,
description
=
"动态任务触发"
)
public
void
trigger
(
@RequestParam
(
"id"
)
String
id
)
{
XxlJobUtil
.
trigger
(
id
);
}
@PostMapping
(
"/findBybusKey
"
)
@Operation
(
summary
=
"任务查询
"
,
description
=
"动态任务触发"
)
public
R
findBybusKey
(
@RequestParam
(
"busKey"
)
String
busKey
)
{
return
R
.
ok
().
data
(
XxlJobUtil
.
findByBusKey
(
busKey
)
);
}
@PostMapping
(
"/findBybusKey"
)
@Operation
(
summary
=
"任务查询"
,
description
=
"动态任务触发"
)
public
R
findBybusKey
(
@RequestParam
(
"busKey"
)
String
busKey
)
{
return
R
.
ok
().
data
(
XxlJobUtil
.
findByBusKey
(
busKey
));
}
@PostMapping
(
"/testJava"
)
@Operation
(
summary
=
"测试java"
,
description
=
"动态任务触发"
)
public
R
testJava
(
@RequestParam
(
"busKey"
)
String
busKey
)
throws
Exception
{
if
(
true
)
{
throw
new
AdminException
(
ResultEnum
.
PARAM_ERROR
);
}
return
R
.
ok
().
data
(
userDemoService
.
testJava
(
busKey
));
}
@PostMapping
(
"/testJava"
)
@Operation
(
summary
=
"测试java"
,
description
=
"动态任务触发"
)
public
R
testJava
(
@RequestParam
(
"busKey"
)
String
busKey
)
throws
Exception
{
if
(
true
)
{
throw
new
AdminException
(
ResultEnum
.
PARAM_ERROR
);
}
return
R
.
ok
().
data
(
userDemoService
.
testJava
(
busKey
));
}
@PostMapping
(
"/testExecutor"
)
@Operation
(
summary
=
"测试Executor"
,
description
=
"动态任务触发"
)
public
R
testNodeExecutor
(
@RequestParam
(
"json"
)
String
json
)
throws
Exception
{
nodeExecutor
.
handler
(
json
);
return
R
.
ok
();
}
}
platform-process/src/test/java/cn/com/glsx/test/service/TestSopService.java
View file @
4371d30
package
cn
.
com
.
glsx
.
test
.
service
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -8,9 +7,11 @@ import org.springframework.boot.test.context.SpringBootTest;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
cn.com.glsx.Application
;
import
cn.com.glsx.process.job.xxljob.impl.SopInstNodeExecuteJobHandler
;
import
cn.com.glsx.process.modules.model.SopStruct
;
import
cn.com.glsx.process.modules.service.SopService
;
import
cn.hutool.json.JSONUtil
;
import
lombok.extern.slf4j.Slf4j
;
/**
* 测试spring cloud 服务调用方式
...
...
@@ -23,6 +24,9 @@ public class TestSopService {
@Autowired
private
SopService
sopService
;
@Autowired
private
SopInstNodeExecuteJobHandler
job
;
@Test
public
void
test
()
{
String
instId
=
"xblc7"
;
...
...
@@ -30,5 +34,16 @@ public class TestSopService {
System
.
out
.
println
(
JSONUtil
.
toJsonStr
(
sop
));
}
@Test
public
void
testNode
()
{
try
{
String
json
=
"{\"preIds\":[2],\"finishedIds\":[2],\"instId\":\"xblc172\",\"nextIds\":[9],\"nodeId\":12}"
;
job
.
handler
(
json
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment