路泰机电科技体检——数据平台后端
zhaowenxuan
2025-04-15 c4ea4cf098ec9fb74aa82530970c9c2e98aec6b8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.example.scheudleds;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.domain.DictHosp;
import com.example.factory.ServiceFactory;
import com.example.service.DictHospService;
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;
import java.util.stream.Collectors;
 
@Slf4j
@Component
public class DictSyncCommon {
 
    private final ServiceFactory serviceFactory;
 
    @Autowired
    public DictSyncCommon(ServiceFactory serviceFactory) {
        this.serviceFactory = serviceFactory;
    }
 
    private final ExecutorService executorService = Executors.newFixedThreadPool(40);
 
    @Autowired
    private DictHospService dictHospService;
 
    @Scheduled(cron = "0 0 22 * * ?")
    public void executeTasks() {
//        List<String> list = Arrays.asList("shanxiqinxamjyy","shanxiqinpbkwyy","shanxiqinjdczgzyy","shanxiqinsqyy");
        List<String> list = dictHospService.list(new LambdaQueryWrapper<DictHosp>().isNotNull(DictHosp::getBeanName))
                .stream().map(DictHosp::getBeanName).collect(Collectors.toList());
        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);
        }
    }
}