修复quartz 任务启停

This commit is contained in:
LionCity
2020-07-11 16:05:18 +08:00
parent 5801701d98
commit 1b1c565741
2 changed files with 38 additions and 38 deletions

View File

@ -17,32 +17,32 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* @author hupeng * @author hupeng
* @date 2020-05-13 * @date 2020-05-13
*/ */
public interface QuartzJobService extends BaseService<QuartzJob>{ public interface QuartzJobService extends BaseService<QuartzJob>{
/** /**
* 查询数据分页 * 查询数据分页
* @param criteria 条件 * @param criteria 条件
* @param pageable 分页参数 * @param pageable 分页参数
* @return Map<String,Object> * @return Map<String,Object>
*/ */
Map<String,Object> queryAll(QuartzJobQueryCriteria criteria, Pageable pageable); Map<String,Object> queryAll(QuartzJobQueryCriteria criteria, Pageable pageable);
/** /**
* 查询所有数据不分页 * 查询所有数据不分页
* @param criteria 条件参数 * @param criteria 条件参数
* @return List<QuartzJobDto> * @return List<QuartzJobDto>
*/ */
List<QuartzJob> queryAll(QuartzJobQueryCriteria criteria); List<QuartzJob> queryAll(QuartzJobQueryCriteria criteria);
/** /**
* 导出数据 * 导出数据
* @param all 待导出的数据 * @param all 待导出的数据
* @param response / * @param response /
* @throws IOException / * @throws IOException /
*/ */
void download(List<QuartzJobDto> all, HttpServletResponse response) throws IOException; void download(List<QuartzJobDto> all, HttpServletResponse response) throws IOException;
@ -63,4 +63,5 @@ public interface QuartzJobService extends BaseService<QuartzJob>{
* @return List * @return List
*/ */
List<QuartzJob> findByIsPauseIsFalse(); List<QuartzJob> findByIsPauseIsFalse();
void removeByIds(List<Integer> idList);
} }

View File

@ -1,7 +1,6 @@
/** /**
* Copyright (C) 2018-2020 * Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co * All rights reserved, Designed By www.yixiang.co
*/ */
package co.yixiang.modules.quartz.service.impl; package co.yixiang.modules.quartz.service.impl;
@ -25,10 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
// 默认不使用缓存 // 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig; //import org.springframework.cache.annotation.CacheConfig;
@ -36,9 +32,9 @@ import java.util.Map;
//import org.springframework.cache.annotation.Cacheable; //import org.springframework.cache.annotation.Cacheable;
/** /**
* @author hupeng * @author hupeng
* @date 2020-05-13 * @date 2020-05-13
*/ */
@Service @Service
@AllArgsConstructor @AllArgsConstructor
//@CacheConfig(cacheNames = "quartzJob") //@CacheConfig(cacheNames = "quartzJob")
@ -62,7 +58,7 @@ public class QuartzJobServiceImpl extends BaseServiceImpl<QuartzJobMapper, Quart
@Override @Override
//@Cacheable //@Cacheable
public List<QuartzJob> queryAll(QuartzJobQueryCriteria criteria){ public List<QuartzJob> queryAll(QuartzJobQueryCriteria criteria) {
return baseMapper.selectList(QueryHelpPlus.getPredicate(QuartzJob.class, criteria)); return baseMapper.selectList(QueryHelpPlus.getPredicate(QuartzJob.class, criteria));
} }
@ -71,7 +67,7 @@ public class QuartzJobServiceImpl extends BaseServiceImpl<QuartzJobMapper, Quart
public void download(List<QuartzJobDto> all, HttpServletResponse response) throws IOException { public void download(List<QuartzJobDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>(); List<Map<String, Object>> list = new ArrayList<>();
for (QuartzJobDto quartzJob : all) { for (QuartzJobDto quartzJob : all) {
Map<String,Object> map = new LinkedHashMap<>(); Map<String, Object> map = new LinkedHashMap<>();
map.put("Spring Bean名称", quartzJob.getBeanName()); map.put("Spring Bean名称", quartzJob.getBeanName());
map.put("cron 表达式", quartzJob.getCronExpression()); map.put("cron 表达式", quartzJob.getCronExpression());
map.put("状态1暂停、0启用", quartzJob.getIsPause()); map.put("状态1暂停、0启用", quartzJob.getIsPause());
@ -108,7 +104,7 @@ public class QuartzJobServiceImpl extends BaseServiceImpl<QuartzJobMapper, Quart
*/ */
@Override @Override
public void updateIsPause(QuartzJob quartzJob) { public void updateIsPause(QuartzJob quartzJob) {
if(quartzJob.getId().equals(1L)){ if (quartzJob.getId().equals(1L)) {
throw new BadRequestException("该任务不可操作"); throw new BadRequestException("该任务不可操作");
} }
if (quartzJob.getIsPause()) { if (quartzJob.getIsPause()) {
@ -123,19 +119,13 @@ public class QuartzJobServiceImpl extends BaseServiceImpl<QuartzJobMapper, Quart
@Override @Override
public boolean save(QuartzJob quartzJob) { public boolean save(QuartzJob quartzJob) {
if (quartzJob.getIsPause()) { quartzManage.addJob(quartzJob);
quartzManage.pauseJob(quartzJob);
}
return retBool(baseMapper.insert(quartzJob)); return retBool(baseMapper.insert(quartzJob));
} }
@Override @Override
public boolean updateById(QuartzJob quartzJob) { public boolean updateById(QuartzJob quartzJob) {
if (quartzJob.getIsPause()) { quartzManage.updateJobCron(quartzJob);
quartzManage.pauseJob(quartzJob);
} else {
quartzManage.resumeJob(quartzJob);
}
return retBool(baseMapper.updateById(quartzJob)); return retBool(baseMapper.updateById(quartzJob));
} }
@ -146,7 +136,7 @@ public class QuartzJobServiceImpl extends BaseServiceImpl<QuartzJobMapper, Quart
*/ */
@Override @Override
public void execution(QuartzJob quartzJob) { public void execution(QuartzJob quartzJob) {
if(quartzJob.getId().equals(1L)){ if (quartzJob.getId().equals(1L)) {
throw new BadRequestException("该任务不可操作"); throw new BadRequestException("该任务不可操作");
} }
quartzManage.runJobNow(quartzJob); quartzManage.runJobNow(quartzJob);
@ -163,4 +153,13 @@ public class QuartzJobServiceImpl extends BaseServiceImpl<QuartzJobMapper, Quart
criteria.setIsPause(false); criteria.setIsPause(false);
return baseMapper.selectList(QueryHelpPlus.getPredicate(QuartzJob.class, criteria)); return baseMapper.selectList(QueryHelpPlus.getPredicate(QuartzJob.class, criteria));
} }
@Override
public void removeByIds(List<Integer> idList) {
idList.forEach(id -> {
QuartzJob quartzJob = baseMapper.selectById(id);
quartzManage.deleteJob(quartzJob);
});
baseMapper.deleteBatchIds(idList);
}
} }