feat:动态调整cron和开关
This commit is contained in:
@@ -81,4 +81,9 @@ public class JobConfigDO implements Serializable {
|
||||
* 上次执行时间
|
||||
*/
|
||||
private LocalDateTime lastRunningTime;
|
||||
|
||||
/**
|
||||
* 版本
|
||||
*/
|
||||
private Integer version;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ public interface IQuartzConfigManage extends IService<JobConfigDO> {
|
||||
|
||||
|
||||
List<JobConfigDO> selectByAppName(String name);
|
||||
List<JobConfigDO> selectByAppNameAndVersion(String name, Integer version);
|
||||
|
||||
List<JobConfigDO> loadEnabledJobs();
|
||||
|
||||
|
||||
@@ -25,6 +25,15 @@ public class QuartzConfigManageImpl extends ServiceImpl<IQuartzConfigMapper, Job
|
||||
return baseMapper.selectList(lqw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JobConfigDO> selectByAppNameAndVersion(String name, Integer version) {
|
||||
LambdaQueryWrapper<JobConfigDO> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(JobConfigDO::getApplicationName, name);
|
||||
lqw.eq(JobConfigDO::getDelFlag, 0);
|
||||
lqw.gt(JobConfigDO::getVersion, version);
|
||||
return baseMapper.selectList(lqw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JobConfigDO> loadEnabledJobs() {
|
||||
LambdaQueryWrapper<JobConfigDO> lqw = Wrappers.lambdaQuery();
|
||||
|
||||
@@ -26,4 +26,9 @@ public class XxzJobFetchController {
|
||||
List<JobConfigDO> jobsByAppName = taskConfigService.getJobsByAppName(appName);
|
||||
return Result.success(jobsByAppName);
|
||||
}
|
||||
|
||||
@GetMapping("/listByVersion")
|
||||
public Result<JobConfigDO> listByVersion(@RequestParam("appName") String appName, @RequestParam("currVersion") Integer currVersion) {
|
||||
return Result.success(taskConfigService.getJobsByAppNameAndVersion(appName, currVersion));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,5 +25,18 @@ public interface ITaskConfigService {
|
||||
*/
|
||||
boolean registerTasks(List<TaskRegisterRequest> request);
|
||||
|
||||
/**
|
||||
* 根据应用获取任务
|
||||
* @param appName
|
||||
* @return
|
||||
*/
|
||||
List<JobConfigDO> getJobsByAppName(String appName);
|
||||
|
||||
/**
|
||||
* 根据应用名称和版本获取任务
|
||||
* @param appName
|
||||
* @param version
|
||||
* @return
|
||||
*/
|
||||
List<JobConfigDO> getJobsByAppNameAndVersion(String appName, Integer version);
|
||||
}
|
||||
|
||||
@@ -72,6 +72,29 @@ public class TaskConfigServiceImpl implements ITaskConfigService {
|
||||
return quartzConfigManage.selectByAppName(appName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<JobConfigDO> getJobsByAppNameAndVersion(String appName, Integer version) {
|
||||
List<JobConfigDO> jobConfigDOS = quartzConfigManage.selectByAppName(appName);
|
||||
Map<String, List<JobConfigDO>> map = Maps.newHashMap();
|
||||
if (CollectionUtils.isNotEmpty(jobConfigDOS)) {
|
||||
map.putAll(jobConfigDOS.stream().collect(Collectors.groupingBy(JobConfigDO::getBeanName)));
|
||||
}
|
||||
Map<String, JobConfigDO> result = Maps.newHashMap();
|
||||
map.forEach((k, v) -> {
|
||||
v.forEach(item -> {
|
||||
if (result.containsKey(k)) {
|
||||
JobConfigDO jobConfigDO = result.get(k);
|
||||
if (item.getVersion() > jobConfigDO.getVersion()) {
|
||||
result.put(k, item);
|
||||
}
|
||||
} else {
|
||||
result.put(k, item);
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.values().stream().toList();
|
||||
}
|
||||
|
||||
private static void putDataIntoDo(TaskRegisterRequest item, JobConfigDO jobConfigDO, String applicationName) {
|
||||
jobConfigDO.setApplicationName(applicationName);
|
||||
jobConfigDO.setApplicationAddress(item.getApplicationAddress());
|
||||
|
||||
Reference in New Issue
Block a user