Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fgqyxxlr
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
yaru
fgqyxxlr
Commits
a44aa5db
Commit
a44aa5db
authored
Oct 27, 2018
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
校验cron表达式是否有效
parent
6ee8053a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
130 additions
and
4 deletions
+130
-4
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysJobController.java
+10
-0
ruoyi-admin/src/main/resources/templates/monitor/job/add.html
+18
-3
ruoyi-admin/src/main/resources/templates/monitor/job/edit.html
+19
-1
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobService.java
+8
-0
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java
+12
-0
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CronUtils.java
+63
-0
No files found.
ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysJobController.java
View file @
a44aa5db
...
...
@@ -149,4 +149,14 @@ public class SysJobController extends BaseController
job
.
setUpdateBy
(
ShiroUtils
.
getLoginName
());
return
toAjax
(
jobService
.
updateJobCron
(
job
));
}
/**
* 校验cron表达式是否有效
*/
@PostMapping
(
"/checkCronExpressionIsValid"
)
@ResponseBody
public
boolean
checkCronExpressionIsValid
(
SysJob
job
)
{
return
jobService
.
checkCronExpressionIsValid
(
job
.
getCronExpression
());
}
}
ruoyi-admin/src/main/resources/templates/monitor/job/add.html
View file @
a44aa5db
...
...
@@ -74,11 +74,26 @@
},
cronExpression
:{
required
:
true
,
remote
:
{
url
:
prefix
+
"/checkCronExpressionIsValid"
,
type
:
"post"
,
dataType
:
"json"
,
data
:
{
"cronExpression"
:
function
()
{
return
$
.
common
.
trim
(
$
(
"#cronExpression"
).
val
());
}
},
dataFilter
:
function
(
data
,
type
)
{
return
data
;
}
}
},
},
submitHandler
:
function
(
form
){
$
.
operate
.
save
(
prefix
+
"/add"
,
$
(
'#form-job-add'
).
serialize
());
}
messages
:
{
"cronExpression"
:
{
remote
:
"表达式不正确"
}
}
});
function
submitHandler
()
{
...
...
ruoyi-admin/src/main/resources/templates/monitor/job/edit.html
View file @
a44aa5db
...
...
@@ -75,8 +75,26 @@
},
cronExpression
:{
required
:
true
,
remote
:
{
url
:
prefix
+
"/checkCronExpressionIsValid"
,
type
:
"post"
,
dataType
:
"json"
,
data
:
{
"cronExpression"
:
function
()
{
return
$
.
common
.
trim
(
$
(
"#cronExpression"
).
val
());
}
},
dataFilter
:
function
(
data
,
type
)
{
return
data
;
}
}
},
}
},
messages
:
{
"cronExpression"
:
{
remote
:
"表达式不正确"
}
}
});
function
submitHandler
()
{
...
...
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/ISysJobService.java
View file @
a44aa5db
...
...
@@ -89,4 +89,12 @@ public interface ISysJobService
* @return 结果
*/
public
int
updateJobCron
(
SysJob
job
);
/**
* 校验cron表达式是否有效
*
* @param cronExpression 表达式
* @return 结果
*/
public
boolean
checkCronExpressionIsValid
(
String
cronExpression
);
}
ruoyi-quartz/src/main/java/com/ruoyi/quartz/service/impl/SysJobServiceImpl.java
View file @
a44aa5db
...
...
@@ -11,6 +11,7 @@ import com.ruoyi.common.support.Convert;
import
com.ruoyi.quartz.domain.SysJob
;
import
com.ruoyi.quartz.mapper.SysJobMapper
;
import
com.ruoyi.quartz.service.ISysJobService
;
import
com.ruoyi.quartz.util.CronUtils
;
import
com.ruoyi.quartz.util.ScheduleUtils
;
/**
...
...
@@ -204,4 +205,15 @@ public class SysJobServiceImpl implements ISysJobService
}
return
rows
;
}
/**
* 校验cron表达式是否有效
*
* @param cronExpression 表达式
* @return 结果
*/
public
boolean
checkCronExpressionIsValid
(
String
cronExpression
)
{
return
CronUtils
.
isValid
(
cronExpression
);
}
}
ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/CronUtils.java
0 → 100644
View file @
a44aa5db
package
com
.
ruoyi
.
quartz
.
util
;
import
java.text.ParseException
;
import
java.util.Date
;
import
org.quartz.CronExpression
;
/**
* cron表达式工具类
*
* @author ruoyi
*
*/
public
class
CronUtils
{
/**
* 返回一个布尔值代表一个给定的Cron表达式的有效性
*
* @param cronExpression Cron表达式
* @return boolean 表达式是否有效
*/
public
static
boolean
isValid
(
String
cronExpression
)
{
return
CronExpression
.
isValidExpression
(
cronExpression
);
}
/**
* 返回一个字符串值,表示该消息无效Cron表达式给出有效性
*
* @param cronExpression Cron表达式
* @return String 无效时返回表达式错误描述,如果有效返回null
*/
public
static
String
getInvalidMessage
(
String
cronExpression
)
{
try
{
new
CronExpression
(
cronExpression
);
return
null
;
}
catch
(
ParseException
pe
)
{
return
pe
.
getMessage
();
}
}
/**
* 返回下一个执行时间根据给定的Cron表达式
*
* @param cronExpression Cron表达式
* @return Date 下次Cron表达式执行时间
*/
public
static
Date
getNextExecution
(
String
cronExpression
)
{
try
{
CronExpression
cron
=
new
CronExpression
(
cronExpression
);
return
cron
.
getNextValidTimeAfter
(
new
Date
(
System
.
currentTimeMillis
()));
}
catch
(
ParseException
e
)
{
throw
new
IllegalArgumentException
(
e
.
getMessage
());
}
}
}
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