package com.example.scheudleds;
|
|
import com.example.factory.ServiceFactory;
|
import com.example.service.HisService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.Executors;
|
|
@Slf4j
|
@Component
|
public class DictSyncCommon {
|
|
private final ServiceFactory serviceFactory;
|
|
@Autowired
|
public DictSyncCommon(ServiceFactory serviceFactory) {
|
this.serviceFactory = serviceFactory;
|
}
|
|
private final ExecutorService executorService = Executors.newFixedThreadPool(40);
|
|
@Scheduled(cron = "0 0 22 * * ?")
|
public void executeTasks() {
|
List<String> list = Arrays.asList("shanxiqinxamjyy","shanxiqinpbkwyy","shanxiqinjdczgzyy");
|
log.info("开始执行定时任务:{}", System.currentTimeMillis());
|
try {
|
for (String hosp : list) {
|
executorService.submit(() -> {
|
try {
|
log.info("开始同步医院数据:{}", hosp);
|
HisService hisService = serviceFactory.getService(hosp);
|
hisService.syncDict(hosp);
|
log.info("完成同步医院数据:{}", hosp);
|
} catch (Exception e) {
|
log.error("同步医院数据失败,医院:{},异常:{}", hosp, e.getMessage());
|
}
|
});
|
}
|
} catch (Exception e) {
|
log.error("定时任务执行异常:", e);
|
}
|
}
|
}
|