feat:任务模板方法

This commit is contained in:
xiang
2026-05-03 00:06:07 +08:00
parent fb48f447be
commit f36766112f
10 changed files with 318 additions and 6 deletions

View File

@@ -1,20 +1,39 @@
package com.xiang.service.module.domain.schedule;
import com.xiang.common.enums.ScheduleEnums;
import com.xiang.common.factory.schedule.BaseScheduleTaskTemplate;
import com.xiang.common.pojo.schedule.TaskResult;
import com.xiang.common.service.IScheduleOpeningConfigService;
import com.xiang.common.utils.IpUtils;
import com.xiang.service.module.domain.service.IDomainService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Slf4j
@RequiredArgsConstructor
public class DomainDynamicAnalysisTask {
@Component
public class DomainDynamicAnalysisTask extends BaseScheduleTaskTemplate {
private final IDomainService IDomainService;
@Scheduled(cron = "0 0/30 * * * ? ")
public void dynamicDomainSchedule() {
public DomainDynamicAnalysisTask(IScheduleOpeningConfigService scheduleOpeningConfigService, IDomainService IDomainService) {
super(scheduleOpeningConfigService);
this.IDomainService = IDomainService;
}
@Override
protected Integer getModule() {
return ScheduleEnums.DOMAIN_DYNAMIC_ANALYSIS_TASK.getModeleCode();
}
@Override
protected String getTaskName() {
return ScheduleEnums.DOMAIN_DYNAMIC_ANALYSIS_TASK.getTaskName();
}
@Override
protected TaskResult doExecute(Object validatedParams) {
String publicIp = "";
TaskResult taskResult = new TaskResult();
try {
publicIp = IpUtils.getPublicIp();
} catch (Exception e) {
@@ -27,5 +46,10 @@ public class DomainDynamicAnalysisTask {
log.error("动态解析公网ip失败, ip:{}", publicIp, e);
}
}
taskResult.setSuccess(true);
taskResult.setSummary("");
taskResult.setDetail(null);
return taskResult;
}
}

View File

@@ -0,0 +1,23 @@
package com.xiang.service.module.domain.schedule;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@Component
@Slf4j
@RequiredArgsConstructor
@RestController
public class DomainDynamicAnalysisTaskConfig {
private final DomainDynamicAnalysisTask domainDynamicAnalysisTask;
@Scheduled(cron = "0 0/30 * * * ? ")
@GetMapping("/test")
public void dynamicDomainSchedule() {
domainDynamicAnalysisTask.run();
}
}