| | |
| | | package com.ltkj.web.config.timer; |
| | | |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ltkj.common.enums.DataSourceType; |
| | | import com.ltkj.db.DataSourceConfig; |
| | | import com.ltkj.db.DataSourceContextHolder; |
| | |
| | | import com.ltkj.system.service.ISysConfigService; |
| | | import jodd.util.StringUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Profile; |
| | | import org.springframework.scheduling.TaskScheduler; |
| | |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | @Slf4j |
| | |
| | | public void init() { |
| | | DataSourceContextHolder.setDataSourceKey(DataSourceType.MASTER.name()); |
| | | // 获取所有需要同步日志的用户列表 |
| | | List<DictHosp> hospList = dictHospService.list(); |
| | | LambdaQueryWrapper<DictHosp> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(DictHosp::getIsAutoAsyncJg,1); |
| | | List<DictHosp> hospList = dictHospService.list(wrapper); |
| | | hospList.forEach(this::createTask); // 为每个用户创建任务 |
| | | // 定时检查是否有新的用户需要添加任务 |
| | | schedulePeriodicTaskCheck(); |
| | |
| | | // 将该用户ID添加到已调度任务集合中 |
| | | scheduledTasks.add(dictHosp.getCode()); |
| | | // 创建定时任务,任务将在15分钟后执行 |
| | | taskScheduler.schedule(() -> { |
| | | /* taskScheduler.schedule(() -> { |
| | | try { |
| | | // 执行任务的超时控制 |
| | | taskScheduler.schedule(() -> { |
| | | executeTask(dictHosp); |
| | | }, Instant.now()); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("创建任务时发生异常:{}", e.getMessage()); |
| | | } |
| | | }, Instant.now().plus(15, ChronoUnit.MINUTES));*/ |
| | | log.info("任务创建成功 ->{}",dictHosp.getCode()); |
| | | // 执行任务的超时控制 |
| | | taskScheduler.schedule(() -> { |
| | | executeTask(dictHosp); |
| | | }, Instant.now().plus(15, ChronoUnit.MINUTES)); |
| | | } |
| | | |
| | |
| | | log.info("任务开始执行时间 -> {}", dateTimeFormat.format(new Date())); |
| | | long start = System.currentTimeMillis(); |
| | | // 查询任务数据 |
| | | log.info("开始执行同步 执行数量->{}", 0); |
| | | log.info("开始执行同步 执行院区->{}", dictHosp.getCode()); |
| | | List<String> jy = orderService.getDingShiTongBuJianYanTjNum(); |
| | | |
| | | List<String> jc = orderService.getDingShiTongBuJianChaTjNum(); |
| | |
| | | if (null != jy && !jy.isEmpty()) { |
| | | log.info("同步检验人员 执行数量->{}", jy.size()); |
| | | for (String s : jy) { |
| | | extractedjianyan(s); |
| | | extractedjianyan(s,dictHosp.getCode()); |
| | | } |
| | | } |
| | | |
| | |
| | | if (null != jc && !jc.isEmpty()) { |
| | | log.info("同步检查人员 执行数量->{}", jc.size()); |
| | | for (String s : jc) { |
| | | extractedjiancha(s); |
| | | extractedjiancha(s,dictHosp.getCode()); |
| | | } |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | |
| | | if(null !=list && !list.isEmpty()){ |
| | | for (LtkjExamJcsqd jcsqd : list) { |
| | | if(StringUtil.isNotBlank(jcsqd.getJgzt())){ |
| | | String[] split = jcsqd.getJgzt().replaceAll("\n", "").split("。|;|;"); |
| | | String regex = configService.selectConfigByKey("jcycxmzz"); |
| | | if(StringUtil.isBlank(regex)) regex= "。|;|;|,|,"; |
| | | String[] split = jcsqd.getJgzt().replaceAll("\n", "").split(regex); |
| | | for (String jg : split) { |
| | | if(StringUtil.isNotBlank(jg) && !jg.contains("未见异常") |
| | | && !jg.contains("未见明显异常") && !jg.contains("未见占位") && !jg.contains("未见") |
| | |
| | | |
| | | // 检查并添加新的用户任务 |
| | | public void checkAndAddNewTasks() { |
| | | DataSourceContextHolder.setDataSourceKey(DataSourceType.MASTER.name()); |
| | | // 获取所有需要同步日志的用户列表 |
| | | List<DictHosp> hospList = dictHospService.list(); |
| | | LambdaQueryWrapper<DictHosp> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(DictHosp::getIsAutoAsyncJg,1); |
| | | List<DictHosp> hospList = dictHospService.list(wrapper); |
| | | log.info("检查并添加需要同步的医院列表:{}", JSONUtil.toJsonStr(hospList)); |
| | | hospList.forEach(this::createTask); |
| | | taskScheduler.schedule(this::checkAndAddNewTasks, Instant.now().plus(2, ChronoUnit.MINUTES)); |
| | | } |
| | | |
| | | private void extractedjianyan(String s) { |
| | | private void extractedjianyan(String s,String hospId) { |
| | | try { |
| | | List<Aws> awsList = testMapper.getWsxmLtkjHysqdByLisViBySLAVEWS(s); |
| | | if(null !=awsList && !awsList.isEmpty()){ |
| | |
| | | awsService.saveBatch(awsList); |
| | | log.info("保存外送项目成功"); |
| | | } |
| | | List<LtkjHysqd> hysqdList = testMapper.getCcXZxYyLtkjHysqdByLisVi(s); |
| | | List<LtkjHysqd> wssq = testMapper.getWsxmLtkjHysqdByLisVi(s); |
| | | if(null !=wssq && !wssq.isEmpty())hysqdList.addAll(wssq); |
| | | if(null !=wssq && !wssq.isEmpty()){ |
| | | for (LtkjHysqd hysqd : wssq) { |
| | | LtkjHysqd jybgid = ltkjHysqdService.getLtkjHysqdByTjhAndTmh(hysqd.getTjh(), hysqd.getTmh()); |
| | | if (null != jybgid) { |
| | | ltkjHysqdService.deletedLtkjHysqdByTjhAndTmh(hysqd.getTjh(), hysqd.getTmh()); |
| | | ltkjHybgdService.deletedLtkjHybgdByTjhAndTmh(hysqd.getTmh()); |
| | | } |
| | | if (ltkjHysqdService.save(hysqd)) { |
| | | List<LtkjHybgd> wsbg = testMapper.getWsxmLtkjHybgdByLisVi(s); |
| | | ltkjHybgdService.saveBatch(wsbg); |
| | | } |
| | | } |
| | | } |
| | | |
| | | String isWsByView = configService.selectConfigByKey("is_ws_by_view"); |
| | | if (StrUtil.isNotBlank(isWsByView) && isWsByView.equals("Y")){ |
| | | List<LtkjHysqd> sqd = testMapper.getWsHySqdByView(s); |
| | | if (sqd != null && !sqd.isEmpty()){ |
| | | for (LtkjHysqd hysqd : sqd) { |
| | | LtkjHysqd jybgid = ltkjHysqdService.getLtkjHysqdByTjhAndTmh(hysqd.getTjh(), hysqd.getTmh()); |
| | | if (null != jybgid) { |
| | | ltkjHysqdService.deletedLtkjHysqdByTjhAndTmh(hysqd.getTjh(), hysqd.getTmh()); |
| | | ltkjHybgdService.deletedLtkjHybgdByTjhAndTmh(hysqd.getTmh()); |
| | | } |
| | | if (ltkjHysqdService.save(hysqd)) { |
| | | List<LtkjHybgd> wsbg = testMapper.getWsHyBgdByView(hysqd.getTmh()); |
| | | ltkjHybgdService.saveBatch(wsbg); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | List<LtkjHysqd> hysqdList = testMapper.getCcXZxYyLtkjHysqdByLisVi(s,hospId); |
| | | if (null != hysqdList && !hysqdList.isEmpty()) { |
| | | for (LtkjHysqd hysqd : hysqdList) { |
| | | LtkjHysqd jybgid = ltkjHysqdService.getLtkjHysqdByTjhAndTmh(hysqd.getTjh(), hysqd.getTmh()); |
| | |
| | | } |
| | | if (ltkjHysqdService.save(hysqd)) { |
| | | List<LtkjHybgd> hybgdList = testMapper.getCcXZxYyLtkjHybgdByLisVi(hysqd.getTmh()); |
| | | List<LtkjHybgd> wsbg = testMapper.getWsxmLtkjHybgdByLisVi(s); |
| | | if(null !=wsbg && !wsbg.isEmpty())hybgdList.addAll(wsbg); |
| | | // List<LtkjHybgd> wsbg = testMapper.getWsxmLtkjHybgdByLisVi(s); |
| | | // if(null !=wsbg && !wsbg.isEmpty())hybgdList.addAll(wsbg); |
| | | ltkjHybgdService.saveBatch(hybgdList); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | private void extractedjiancha(String s) { |
| | | private void extractedjiancha(String s,String hospId) { |
| | | |
| | | try { |
| | | List<LtkjExamJcsqd> jcsqdList = testMapper.getCcXZxYyPacsLtkjExamJcsqd(s); |
| | | List<LtkjExamJcsqd> jcsqdList = testMapper.getCcXZxYyPacsLtkjExamJcsqd(s,hospId); |
| | | log.info("自动同步检查申请单数据:"+jcsqdList); |
| | | if (null != jcsqdList && !jcsqdList.isEmpty()) { |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | jcsqdService.deletedLtkjJcsqdByTjhAndTmh(s); |
| | | jcbgdService.deletedLtkjJcbgdByTjhAndTmh(s); |
| | | jcsqdService.saveBatch(jcsqdList); |
| | | List<LtkjExamJcbgd> jcbgdList = testMapper.getCcXZxYyPacsLtkjExamJcbgd(s); |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | List<LtkjExamJcbgd> jcbgdList = testMapper.getCcXZxYyPacsLtkjExamJcbgd(s,hospId); |
| | | // DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | log.info("自动同步检查报告单数据:"+jcbgdList); |
| | | if (null != jcbgdList && !jcbgdList.isEmpty()) jcbgdService.saveBatch(jcbgdList); |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | } |