修复quartz 任务启停
This commit is contained in:
@ -17,32 +17,32 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-05-13
|
||||
*/
|
||||
* @author hupeng
|
||||
* @date 2020-05-13
|
||||
*/
|
||||
public interface QuartzJobService extends BaseService<QuartzJob>{
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAll(QuartzJobQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<QuartzJobDto>
|
||||
*/
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<QuartzJobDto>
|
||||
*/
|
||||
List<QuartzJob> queryAll(QuartzJobQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param all 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
* 导出数据
|
||||
* @param all 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<QuartzJobDto> all, HttpServletResponse response) throws IOException;
|
||||
|
||||
|
||||
@ -63,4 +63,5 @@ public interface QuartzJobService extends BaseService<QuartzJob>{
|
||||
* @return List
|
||||
*/
|
||||
List<QuartzJob> findByIsPauseIsFalse();
|
||||
void removeByIds(List<Integer> idList);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2020
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
|
||||
*/
|
||||
package co.yixiang.modules.quartz.service.impl;
|
||||
|
||||
@ -25,10 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
// 默认不使用缓存
|
||||
//import org.springframework.cache.annotation.CacheConfig;
|
||||
@ -36,9 +32,9 @@ import java.util.Map;
|
||||
//import org.springframework.cache.annotation.Cacheable;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-05-13
|
||||
*/
|
||||
* @author hupeng
|
||||
* @date 2020-05-13
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
//@CacheConfig(cacheNames = "quartzJob")
|
||||
@ -62,7 +58,7 @@ public class QuartzJobServiceImpl extends BaseServiceImpl<QuartzJobMapper, Quart
|
||||
|
||||
@Override
|
||||
//@Cacheable
|
||||
public List<QuartzJob> queryAll(QuartzJobQueryCriteria criteria){
|
||||
public List<QuartzJob> queryAll(QuartzJobQueryCriteria 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 {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (QuartzJobDto quartzJob : all) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("Spring Bean名称", quartzJob.getBeanName());
|
||||
map.put("cron 表达式", quartzJob.getCronExpression());
|
||||
map.put("状态:1暂停、0启用", quartzJob.getIsPause());
|
||||
@ -108,7 +104,7 @@ public class QuartzJobServiceImpl extends BaseServiceImpl<QuartzJobMapper, Quart
|
||||
*/
|
||||
@Override
|
||||
public void updateIsPause(QuartzJob quartzJob) {
|
||||
if(quartzJob.getId().equals(1L)){
|
||||
if (quartzJob.getId().equals(1L)) {
|
||||
throw new BadRequestException("该任务不可操作");
|
||||
}
|
||||
if (quartzJob.getIsPause()) {
|
||||
@ -123,19 +119,13 @@ public class QuartzJobServiceImpl extends BaseServiceImpl<QuartzJobMapper, Quart
|
||||
|
||||
@Override
|
||||
public boolean save(QuartzJob quartzJob) {
|
||||
if (quartzJob.getIsPause()) {
|
||||
quartzManage.pauseJob(quartzJob);
|
||||
}
|
||||
quartzManage.addJob(quartzJob);
|
||||
return retBool(baseMapper.insert(quartzJob));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateById(QuartzJob quartzJob) {
|
||||
if (quartzJob.getIsPause()) {
|
||||
quartzManage.pauseJob(quartzJob);
|
||||
} else {
|
||||
quartzManage.resumeJob(quartzJob);
|
||||
}
|
||||
quartzManage.updateJobCron(quartzJob);
|
||||
return retBool(baseMapper.updateById(quartzJob));
|
||||
}
|
||||
|
||||
@ -146,7 +136,7 @@ public class QuartzJobServiceImpl extends BaseServiceImpl<QuartzJobMapper, Quart
|
||||
*/
|
||||
@Override
|
||||
public void execution(QuartzJob quartzJob) {
|
||||
if(quartzJob.getId().equals(1L)){
|
||||
if (quartzJob.getId().equals(1L)) {
|
||||
throw new BadRequestException("该任务不可操作");
|
||||
}
|
||||
quartzManage.runJobNow(quartzJob);
|
||||
@ -163,4 +153,13 @@ public class QuartzJobServiceImpl extends BaseServiceImpl<QuartzJobMapper, Quart
|
||||
criteria.setIsPause(false);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user