【fix sonar】 QuartzJobServiceImpl.java 文件
This commit is contained in:
+9
-10
@@ -48,12 +48,10 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
|
|||||||
// DB设置修改
|
// DB设置修改
|
||||||
quartzJob.setDelFlag(CommonConstant.DEL_FLAG_0);
|
quartzJob.setDelFlag(CommonConstant.DEL_FLAG_0);
|
||||||
boolean success = this.save(quartzJob);
|
boolean success = this.save(quartzJob);
|
||||||
if (success) {
|
if (success && CommonConstant.STATUS_NORMAL.equals(quartzJob.getStatus())) {
|
||||||
if (CommonConstant.STATUS_NORMAL.equals(quartzJob.getStatus())) {
|
|
||||||
// 定时器添加
|
// 定时器添加
|
||||||
this.schedulerAdd(quartzJob.getId(), quartzJob.getJobClassName().trim(), quartzJob.getCronExpression().trim(), quartzJob.getParameter());
|
this.schedulerAdd(quartzJob.getId(), quartzJob.getJobClassName().trim(), quartzJob.getCronExpression().trim(), quartzJob.getParameter());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +69,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑&启停定时任务
|
* 编辑&启停定时任务
|
||||||
|
*
|
||||||
* @throws SchedulerException
|
* @throws SchedulerException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -79,7 +78,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
|
|||||||
if (CommonConstant.STATUS_NORMAL.equals(quartzJob.getStatus())) {
|
if (CommonConstant.STATUS_NORMAL.equals(quartzJob.getStatus())) {
|
||||||
schedulerDelete(quartzJob.getId());
|
schedulerDelete(quartzJob.getId());
|
||||||
schedulerAdd(quartzJob.getId(), quartzJob.getJobClassName().trim(), quartzJob.getCronExpression().trim(), quartzJob.getParameter());
|
schedulerAdd(quartzJob.getId(), quartzJob.getJobClassName().trim(), quartzJob.getCronExpression().trim(), quartzJob.getParameter());
|
||||||
}else{
|
} else {
|
||||||
scheduler.pauseJob(JobKey.jobKey(quartzJob.getId()));
|
scheduler.pauseJob(JobKey.jobKey(quartzJob.getId()));
|
||||||
}
|
}
|
||||||
return this.updateById(quartzJob);
|
return this.updateById(quartzJob);
|
||||||
@@ -92,22 +91,22 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
|
|||||||
@Transactional(rollbackFor = JeroBootException.class)
|
@Transactional(rollbackFor = JeroBootException.class)
|
||||||
public boolean deleteAndStopJob(QuartzJob job) {
|
public boolean deleteAndStopJob(QuartzJob job) {
|
||||||
schedulerDelete(job.getId());
|
schedulerDelete(job.getId());
|
||||||
boolean ok = this.removeById(job.getId());
|
// boolean ok = this.removeById(job.getId());
|
||||||
return ok;
|
return this.removeById(job.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(QuartzJob quartzJob) throws Exception {
|
public void execute(QuartzJob quartzJob) throws Exception {
|
||||||
String jobName = quartzJob.getJobClassName().trim();
|
String jobName = quartzJob.getJobClassName().trim();
|
||||||
Date startDate = new Date();
|
Date startDate = new Date();
|
||||||
String ymd = DateUtils.date2Str(startDate,DateUtils.yyyymmddhhmmss.get());
|
String ymd = DateUtils.date2Str(startDate, DateUtils.yyyymmddhhmmss.get());
|
||||||
String identity = jobName + ymd;
|
String identity = jobName + ymd;
|
||||||
//3秒后执行 只执行一次
|
//3秒后执行 只执行一次
|
||||||
// update-begin--author:sunjianlei ---- date:20210511--- for:定时任务立即执行,延迟3秒改成0.1秒-------
|
// update-begin--author:sunjianlei ---- date:20210511--- for:定时任务立即执行,延迟3秒改成0.1秒-------
|
||||||
startDate.setTime(startDate.getTime() + 100L);
|
startDate.setTime(startDate.getTime() + 100L);
|
||||||
// update-end--author:sunjianlei ---- date:20210511--- for:定时任务立即执行,延迟3秒改成0.1秒-------
|
// update-end--author:sunjianlei ---- date:20210511--- for:定时任务立即执行,延迟3秒改成0.1秒-------
|
||||||
// 定义一个Trigger
|
// 定义一个Trigger
|
||||||
SimpleTrigger trigger = (SimpleTrigger)TriggerBuilder.newTrigger()
|
SimpleTrigger trigger = (SimpleTrigger) TriggerBuilder.newTrigger()
|
||||||
.withIdentity(identity, JOB_TEST_GROUP)
|
.withIdentity(identity, JOB_TEST_GROUP)
|
||||||
.startAt(startDate)
|
.startAt(startDate)
|
||||||
.build();
|
.build();
|
||||||
@@ -121,7 +120,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = JeroBootException.class)
|
@Transactional(rollbackFor = JeroBootException.class)
|
||||||
public void pause(QuartzJob quartzJob){
|
public void pause(QuartzJob quartzJob) {
|
||||||
schedulerDelete(quartzJob.getId());
|
schedulerDelete(quartzJob.getId());
|
||||||
quartzJob.setStatus(CommonConstant.STATUS_DISABLE);
|
quartzJob.setStatus(CommonConstant.STATUS_DISABLE);
|
||||||
this.updateById(quartzJob);
|
this.updateById(quartzJob);
|
||||||
@@ -153,7 +152,7 @@ public class QuartzJobServiceImpl extends ServiceImpl<QuartzJobMapper, QuartzJob
|
|||||||
throw new JeroBootException("创建定时任务失败", e);
|
throw new JeroBootException("创建定时任务失败", e);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
throw new JeroBootException(e.getMessage(), e);
|
throw new JeroBootException(e.getMessage(), e);
|
||||||
}catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new JeroBootException("后台找不到该类名:" + jobClassName, e);
|
throw new JeroBootException("后台找不到该类名:" + jobClassName, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user