| | |
| | | package com.example.scheudleds; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.example.config.db.DataSourceConfig; |
| | | import com.example.config.db.DataSourceContextHolder; |
| | | import com.example.domain.DictHosp; |
| | | import com.example.factory.ServiceFactory; |
| | | import com.example.mapper.SqlMapper; |
| | | import com.example.service.DictHospService; |
| | | import com.example.service.HisService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | @Autowired |
| | | private DictHospService dictHospService; |
| | | @Autowired |
| | | private SqlMapper sqlMapper; |
| | | @Autowired |
| | | private DataSourceConfig dataSourceConfig; |
| | | |
| | | @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()); |
| | | // List<String> list = dictHospService.list(new LambdaQueryWrapper<DictHosp>().isNotNull(DictHosp::getBeanName)) |
| | | // .stream().map(DictHosp::getBeanName).collect(Collectors.toList()); |
| | | List<DictHosp> list = dictHospService.list(new LambdaQueryWrapper<DictHosp>().isNotNull(DictHosp::getBeanName)); |
| | | log.info("开始执行定时任务:{}", System.currentTimeMillis()); |
| | | try { |
| | | for (String hosp : list) { |
| | | for (DictHosp hosp : list) { |
| | | executorService.submit(() -> { |
| | | try { |
| | | log.info("开始同步医院数据:{}", hosp); |
| | | HisService hisService = serviceFactory.getService(hosp); |
| | | hisService.syncDict(hosp); |
| | | log.info("完成同步医院数据:{}", hosp); |
| | | String beanName = hosp.getBeanName(); |
| | | log.info("开始同步医院数据:{}", beanName); |
| | | HisService hisService = serviceFactory.getService(beanName); |
| | | hisService.syncDict(beanName); |
| | | log.info("完成同步医院数据:{}", beanName); |
| | | } catch (Exception e) { |
| | | log.error("同步医院数据失败,医院:{},异常:{}", hosp, e.getMessage()); |
| | | log.error("同步医院数据失败,医院:{}", hosp.getBeanName(), e); |
| | | } |
| | | if (hosp.getIsTbHisProject() != null && hosp.getIsTbHisProject() == 1) { |
| | | try { |
| | | dataSourceConfig.addDataSource(hosp.getDbname()); |
| | | DataSourceContextHolder.setDataSourceKey(hosp.getDbname()); |
| | | sqlMapper.pro_tb_his_project(); |
| | | } catch (Exception e) { |
| | | log.error("调用同步存储过程失败,医院:{}", hosp.getBeanName(), e); |
| | | }finally { |
| | | DataSourceContextHolder.clear(); |
| | | } |
| | | } |
| | | }); |
| | | } |