@Component
public class DpReportServiceFactory {
@Autowired
private DpReportDataServiceGovImpl dpReportDataServiceGov;
public DpReportDataService createService(String requestType) {
DpReportDataService service = null;
if ("gov".equals(requestType)) {
service = dpReportDataServiceGov;
}
return service;
}
}
public interface DpReportJobService {
Boolean reportData(ReportConfigDataDTO reportConfigDataDTO);
}
@Slf4j
@RequiredArgsConstructor
@Service
public class DpReportJobServiceImpl implements DpReportJobService {
@Resource
private DpReportServiceFactory dpReportServiceFactory;
@Override
public Boolean reportData(ReportConfigDataDTO reportConfigDataDTO) {
DpReportDataService dpReportService = dpReportServiceFactory.createService(reportConfigDataDTO.getReportType());
dpReportService.reportData(reportConfigDataDTO);
return true;
}
}
public interface DpReportDataService {
Boolean reportData(ReportConfigDataDTO reportConfigDataDTO);
}
@Service
@Slf4j
public class DpReportDataServiceGovImpl implements DpReportDataService {
@Override
public Boolean reportData(ReportConfigDataDTO dto) {
return true;
}
}
@Component
@Slf4j
public class ScheduledTaskDpReport {
@Resource
private DpReportJobService dpReportJobService;
@Resource
private ReportConfigDataList reportConfigList;
@Scheduled(cron = "0 0 1 * * ? ")
public ResultBean<Boolean> reportData() {
for (ReportConfigDataDTO dto : reportConfigList.getReportConfigData()) {
log.info("定时任务上报数据:{}", JSONUtil.toJsonStr(dto));
dpReportJobService.reportData(dto);
}
log.info("定时任务上报数据结束");
return ResultBean.ok(true);
}
}