Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
twelvet
twelvet
提交
1f578f7b
twelvet
项目概览
twelvet
/
twelvet
10 个月 前同步成功
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
twelvet
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1f578f7b
编写于
7月 01, 2022
作者:
twelvet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化分布式任务添加限制
上级
9d70d9a8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
139 addition
and
132 deletion
+139
-132
twelvet-server/twelvet-server-job/src/main/java/com/twelvet/server/job/controller/SysJobController.java
...a/com/twelvet/server/job/controller/SysJobController.java
+139
-132
未找到文件。
twelvet-server/twelvet-server-job/src/main/java/com/twelvet/server/job/controller/SysJobController.java
浏览文件 @
1f578f7b
...
...
@@ -31,145 +31,152 @@ import java.util.List;
@RequestMapping
(
"/cron"
)
public
class
SysJobController
extends
TWTController
{
@Autowired
private
ISysJobService
jobService
;
@Autowired
private
ISysJobService
jobService
;
/**
* 查询定时任务列表
* @param sysJob SysJob
* @return AjaxResult
*/
@GetMapping
(
"/pageQuery"
)
@PreAuthorize
(
"@role.hasPermi('monitor:job:list')"
)
public
AjaxResult
pageQuery
(
SysJob
sysJob
)
{
PageUtils
.
startPage
();
List
<
SysJob
>
list
=
jobService
.
selectJobList
(
sysJob
);
return
AjaxResult
.
success
(
PageUtils
.
getDataTable
(
list
));
}
/**
* 查询定时任务列表
*
* @param sysJob SysJob
* @return AjaxResult
*/
@GetMapping
(
"/pageQuery"
)
@PreAuthorize
(
"@role.hasPermi('monitor:job:list')"
)
public
AjaxResult
pageQuery
(
SysJob
sysJob
)
{
PageUtils
.
startPage
();
List
<
SysJob
>
list
=
jobService
.
selectJobList
(
sysJob
);
return
AjaxResult
.
success
(
PageUtils
.
getDataTable
(
list
));
}
/**
* 导出定时任务列表
* @param response HttpServletResponse
* @param sysJob SysJob
*/
@Log
(
service
=
"定时任务"
,
businessType
=
BusinessType
.
EXPORT
)
@PostMapping
(
"/export"
)
@PreAuthorize
(
"@role.hasPermi('monitor:job:export')"
)
public
void
export
(
HttpServletResponse
response
,
@RequestBody
SysJob
sysJob
)
{
List
<
SysJob
>
list
=
jobService
.
selectJobList
(
sysJob
);
ExcelUtils
<
SysJob
>
excelUtils
=
new
ExcelUtils
<>(
SysJob
.
class
);
excelUtils
.
exportExcel
(
response
,
list
,
"定时任务"
);
}
/**
* 导出定时任务列表
*
* @param response HttpServletResponse
* @param sysJob SysJob
*/
@Log
(
service
=
"定时任务"
,
businessType
=
BusinessType
.
EXPORT
)
@PostMapping
(
"/export"
)
@PreAuthorize
(
"@role.hasPermi('monitor:job:export')"
)
public
void
export
(
HttpServletResponse
response
,
@RequestBody
SysJob
sysJob
)
{
List
<
SysJob
>
list
=
jobService
.
selectJobList
(
sysJob
);
ExcelUtils
<
SysJob
>
excelUtils
=
new
ExcelUtils
<>(
SysJob
.
class
);
excelUtils
.
exportExcel
(
response
,
list
,
"定时任务"
);
}
/**
* 获取定时任务详细信息
* @param jobId 定时任务ID
* @return AjaxResult
*/
@GetMapping
(
value
=
"/{jobId}"
)
@PreAuthorize
(
"@role.hasPermi('monitor:job:query')"
)
public
AjaxResult
getByJobId
(
@PathVariable
(
"jobId"
)
Long
jobId
)
{
return
AjaxResult
.
success
(
jobService
.
selectJobById
(
jobId
));
}
/**
* 获取定时任务详细信息
*
* @param jobId 定时任务ID
* @return AjaxResult
*/
@GetMapping
(
value
=
"/{jobId}"
)
@PreAuthorize
(
"@role.hasPermi('monitor:job:query')"
)
public
AjaxResult
getByJobId
(
@PathVariable
(
"jobId"
)
Long
jobId
)
{
return
AjaxResult
.
success
(
jobService
.
selectJobById
(
jobId
));
}
/**
* 新增定时任务
* @param sysJob SysJob
* @return AjaxResult
* @throws SchedulerException 表达式异常
* @throws TaskException 任务异常
*/
@Log
(
service
=
"定时任务"
,
businessType
=
BusinessType
.
INSERT
)
@PostMapping
@PreAuthorize
(
"@role.hasPermi('monitor:job:insert')"
)
public
AjaxResult
insert
(
@RequestBody
SysJob
sysJob
)
throws
SchedulerException
,
TaskException
{
if
(!
CronUtils
.
isValid
(
sysJob
.
getCronExpression
()))
{
return
error
(
"新增任务'"
+
sysJob
.
getJobName
()
+
"'失败,Cron表达式不正确"
);
}
else
if
(
StringUtils
.
containsIgnoreCase
(
sysJob
.
getInvokeTarget
(),
Constants
.
LOOKUP_RMI
))
{
return
error
(
"新增任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串不允许'rmi'调用"
);
}
else
if
(
StringUtils
.
containsAnyIgnoreCase
(
sysJob
.
getInvokeTarget
(),
new
String
[]
{
Constants
.
LOOKUP_LDAP
,
Constants
.
LOOKUP_LDAPS
}))
{
return
error
(
"新增任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串不允许'ldap(s)'调用"
);
}
else
if
(
StringUtils
.
containsAnyIgnoreCase
(
sysJob
.
getInvokeTarget
(),
new
String
[]
{
Constants
.
HTTP
,
Constants
.
HTTPS
}))
{
return
error
(
"新增任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串不允许'http(s)'调用"
);
}
else
if
(
StringUtils
.
containsAnyIgnoreCase
(
sysJob
.
getInvokeTarget
(),
Constants
.
JOB_ERROR_STR
))
{
return
error
(
"新增任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串存在违规"
);
}
else
if
(!
ScheduleUtils
.
whiteList
(
sysJob
.
getInvokeTarget
()))
{
return
error
(
"新增任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串不在白名单内"
);
}
sysJob
.
setCreateBy
(
SecurityUtils
.
getUsername
());
sysJob
.
setCreateBy
(
SecurityUtils
.
getUsername
());
return
json
(
jobService
.
insertJob
(
sysJob
));
}
/**
* 新增定时任务
*
* @param sysJob SysJob
* @return AjaxResult
* @throws SchedulerException 表达式异常
* @throws TaskException 任务异常
*/
@Log
(
service
=
"定时任务"
,
businessType
=
BusinessType
.
INSERT
)
@PostMapping
@PreAuthorize
(
"@role.hasPermi('monitor:job:insert')"
)
public
AjaxResult
insert
(
@RequestBody
SysJob
sysJob
)
throws
SchedulerException
,
TaskException
{
if
(!
CronUtils
.
isValid
(
sysJob
.
getCronExpression
()))
{
return
error
(
"新增任务'"
+
sysJob
.
getJobName
()
+
"'失败,Cron表达式不正确"
);
}
else
if
(
StringUtils
.
containsIgnoreCase
(
sysJob
.
getInvokeTarget
(),
Constants
.
LOOKUP_RMI
))
{
return
error
(
"新增任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串不允许'rmi'调用"
);
}
else
if
(
StringUtils
.
containsAnyIgnoreCase
(
sysJob
.
getInvokeTarget
(),
new
String
[]{
Constants
.
LOOKUP_LDAP
,
Constants
.
LOOKUP_LDAPS
}))
{
return
error
(
"新增任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串不允许'ldap(s)'调用"
);
}
else
if
(
StringUtils
.
containsAnyIgnoreCase
(
sysJob
.
getInvokeTarget
(),
new
String
[]{
Constants
.
HTTP
,
Constants
.
HTTPS
}))
{
return
error
(
"新增任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串不允许'http(s)'调用"
);
}
else
if
(
StringUtils
.
containsAnyIgnoreCase
(
sysJob
.
getInvokeTarget
(),
Constants
.
JOB_ERROR_STR
))
{
return
error
(
"新增任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串存在违规"
);
}
else
if
(!
ScheduleUtils
.
whiteList
(
sysJob
.
getInvokeTarget
()))
{
return
error
(
"新增任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串不在白名单内"
);
}
sysJob
.
setCreateBy
(
SecurityUtils
.
getUsername
());
sysJob
.
setCreateBy
(
SecurityUtils
.
getUsername
());
return
json
(
jobService
.
insertJob
(
sysJob
));
}
/**
* 修改定时任务
* @param sysJob SysJob
* @return AjaxResult
* @throws SchedulerException 表达式异常
* @throws TaskException 任务异常
*/
@Log
(
service
=
"定时任务"
,
businessType
=
BusinessType
.
UPDATE
)
@PutMapping
@PreAuthorize
(
"@role.hasPermi('monitor:job:update')"
)
public
AjaxResult
update
(
@RequestBody
SysJob
sysJob
)
throws
SchedulerException
,
TaskException
{
if
(!
CronUtils
.
isValid
(
sysJob
.
getCronExpression
()))
{
return
AjaxResult
.
error
(
"cron表达式不正确"
);
}
sysJob
.
setUpdateBy
(
SecurityUtils
.
getUsername
());
return
json
(
jobService
.
updateJob
(
sysJob
));
}
/**
* 修改定时任务
*
* @param sysJob SysJob
* @return AjaxResult
* @throws SchedulerException 表达式异常
* @throws TaskException 任务异常
*/
@Log
(
service
=
"定时任务"
,
businessType
=
BusinessType
.
UPDATE
)
@PutMapping
@PreAuthorize
(
"@role.hasPermi('monitor:job:update')"
)
public
AjaxResult
update
(
@RequestBody
SysJob
sysJob
)
throws
SchedulerException
,
TaskException
{
if
(!
CronUtils
.
isValid
(
sysJob
.
getCronExpression
()))
{
return
error
(
"修改任务'"
+
sysJob
.
getJobName
()
+
"'失败,Cron表达式不正确"
);
}
else
if
(
StringUtils
.
containsIgnoreCase
(
sysJob
.
getInvokeTarget
(),
Constants
.
LOOKUP_RMI
))
{
return
error
(
"修改任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串不允许'rmi'调用"
);
}
else
if
(
StringUtils
.
containsAnyIgnoreCase
(
sysJob
.
getInvokeTarget
(),
new
String
[]{
Constants
.
LOOKUP_LDAP
,
Constants
.
LOOKUP_LDAPS
}))
{
return
error
(
"修改任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串不允许'ldap(s)'调用"
);
}
else
if
(
StringUtils
.
containsAnyIgnoreCase
(
sysJob
.
getInvokeTarget
(),
new
String
[]{
Constants
.
HTTP
,
Constants
.
HTTPS
}))
{
return
error
(
"修改任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串不允许'http(s)'调用"
);
}
else
if
(
StringUtils
.
containsAnyIgnoreCase
(
sysJob
.
getInvokeTarget
(),
Constants
.
JOB_ERROR_STR
))
{
return
error
(
"修改任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串存在违规"
);
}
else
if
(!
ScheduleUtils
.
whiteList
(
sysJob
.
getInvokeTarget
()))
{
return
error
(
"修改任务'"
+
sysJob
.
getJobName
()
+
"'失败,目标字符串不在白名单内"
);
}
sysJob
.
setUpdateBy
(
SecurityUtils
.
getUsername
());
return
json
(
jobService
.
updateJob
(
sysJob
));
}
/**
* 定时任务状态修改
* @param job SysJob
* @return AjaxResult
* @throws SchedulerException 表达式异常
*/
@Log
(
service
=
"定时任务"
,
businessType
=
BusinessType
.
UPDATE
)
@PutMapping
(
"/changeStatus"
)
@PreAuthorize
(
"@role.hasPermi('monitor:job:update')"
)
public
AjaxResult
changeStatus
(
@RequestBody
SysJob
job
)
throws
SchedulerException
{
SysJob
newJob
=
jobService
.
selectJobById
(
job
.
getJobId
());
newJob
.
setStatus
(
job
.
getStatus
());
return
json
(
jobService
.
changeStatus
(
newJob
));
}
/**
* 定时任务状态修改
*
* @param job SysJob
* @return AjaxResult
* @throws SchedulerException 表达式异常
*/
@Log
(
service
=
"定时任务"
,
businessType
=
BusinessType
.
UPDATE
)
@PutMapping
(
"/changeStatus"
)
@PreAuthorize
(
"@role.hasPermi('monitor:job:update')"
)
public
AjaxResult
changeStatus
(
@RequestBody
SysJob
job
)
throws
SchedulerException
{
SysJob
newJob
=
jobService
.
selectJobById
(
job
.
getJobId
());
newJob
.
setStatus
(
job
.
getStatus
());
return
json
(
jobService
.
changeStatus
(
newJob
));
}
/**
* 定时任务立即执行一次
* @param job SysJob
* @return AjaxResult
* @throws SchedulerException 表达式异常
*/
@Log
(
service
=
"定时任务"
,
businessType
=
BusinessType
.
UPDATE
)
@PutMapping
(
"/run"
)
public
AjaxResult
run
(
@RequestBody
SysJob
job
)
throws
SchedulerException
{
jobService
.
run
(
job
);
return
AjaxResult
.
success
();
}
/**
* 定时任务立即执行一次
*
* @param job SysJob
* @return AjaxResult
* @throws SchedulerException 表达式异常
*/
@Log
(
service
=
"定时任务"
,
businessType
=
BusinessType
.
UPDATE
)
@PutMapping
(
"/run"
)
public
AjaxResult
run
(
@RequestBody
SysJob
job
)
throws
SchedulerException
{
jobService
.
run
(
job
);
return
AjaxResult
.
success
();
}
/**
* 删除定时任务
* @param jobIds 定时任务id数组
* @return AjaxResult
* @throws SchedulerException 表达式异常
*/
@Log
(
service
=
"定时任务"
,
businessType
=
BusinessType
.
DELETE
)
@DeleteMapping
(
"/{jobIds}"
)
@PreAuthorize
(
"@role.hasPermi('monitor:job:remove')"
)
public
AjaxResult
remove
(
@PathVariable
Long
[]
jobIds
)
throws
SchedulerException
{
jobService
.
deleteJobByIds
(
jobIds
);
return
AjaxResult
.
success
();
}
/**
* 删除定时任务
*
* @param jobIds 定时任务id数组
* @return AjaxResult
* @throws SchedulerException 表达式异常
*/
@Log
(
service
=
"定时任务"
,
businessType
=
BusinessType
.
DELETE
)
@DeleteMapping
(
"/{jobIds}"
)
@PreAuthorize
(
"@role.hasPermi('monitor:job:remove')"
)
public
AjaxResult
remove
(
@PathVariable
Long
[]
jobIds
)
throws
SchedulerException
{
jobService
.
deleteJobByIds
(
jobIds
);
return
AjaxResult
.
success
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录