| | |
| | | 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.ltkj.common.enums.DataSourceType; |
| | | import com.ltkj.db.DataSourceConfig; |
| | |
| | | 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.ZonedDateTime; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | |
| | | @Slf4j |
| | |
| | | @Autowired |
| | | private DataSourceConfig dataSourceConfig; |
| | | |
| | | private final ReentrantLock reentrantLock = new ReentrantLock(); |
| | | private final Map<String, ReentrantLock> lockMap = new ConcurrentHashMap<>(); |
| | | |
| | | // 用来跟踪已调度任务的用户ID集合,避免重复添加任务 |
| | | private final Set<String> scheduledTasks = new HashSet<>(); |
| | |
| | | |
| | | // 创建定时任务的方法,用户ID不存在任务时才会添加 |
| | | public void createTask(DictHosp dictHosp) { |
| | | log.info("进入创建任务方法 ->{}",dictHosp.getCode()); |
| | | log.info("已有任务集合 ->{}", scheduledTasks); |
| | | // 如果任务已经存在,则不重复添加 |
| | | if (scheduledTasks.contains(dictHosp.getCode())) { |
| | | return; |
| | |
| | | }, Instant.now().plus(15, ChronoUnit.MINUTES)); |
| | | } |
| | | |
| | | private ReentrantLock getLock(String id) { |
| | | return lockMap.computeIfAbsent(id, k -> new ReentrantLock()); |
| | | } |
| | | |
| | | // 执行日志同步任务的方法 |
| | | public void executeTask(DictHosp dictHosp) { |
| | | // 获取锁,确保同一时间只有一个任务执行 |
| | | log.info("{}执行结果同步", dictHosp.getCode()); |
| | | dataSourceConfig.addDataSource(dictHosp.getDbname()); |
| | | DataSourceContextHolder.setDataSourceKey(dictHosp.getDbname()); |
| | | String dsqkssj = configService.selectConfigByKey("dsqkssj"); |
| | | String dsqjssj = configService.selectConfigByKey("dsqjssj"); |
| | | boolean panduandangqianshijian = panduandangqianshijian(dsqkssj, dsqjssj); |
| | | |
| | | log.info("{}执行结果同步加锁前",JSONUtil.toJsonStr(dictHosp)); |
| | | ReentrantLock reentrantLock = getLock(dictHosp.getCode()); |
| | | boolean lock = reentrantLock.tryLock(); |
| | | try { |
| | | log.info("{}执行结果同步加锁后",JSONUtil.toJsonStr(dictHosp)); |
| | | log.info("{}执行结果同步", dictHosp.getCode()); |
| | | dataSourceConfig.addDataSource(dictHosp.getDbname()); |
| | | DataSourceContextHolder.setDataSourceKey(dictHosp.getDbname()); |
| | | String dsqkssj = configService.selectConfigByKey("dsqkssj"); |
| | | String dsqjssj = configService.selectConfigByKey("dsqjssj"); |
| | | boolean panduandangqianshijian = panduandangqianshijian(dsqkssj, dsqjssj); |
| | | if (!panduandangqianshijian) { |
| | | if (lock) { |
| | | log.info("任务开始执行时间 -> {}", dateTimeFormat.format(new Date())); |
| | |
| | | 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<>(); |
| | |
| | | List<LtkjExamJcsqd> list = jcsqdService.getLtkjJcsqdByTjh(s); |
| | | if(null !=list && !list.isEmpty()){ |
| | | for (LtkjExamJcsqd jcsqd : list) { |
| | | if(jcsqd.getJgbx().contains("。")){ |
| | | String[] split = jcsqd.getJgzt().split("。"); |
| | | if(StringUtil.isNotBlank(jcsqd.getJgzt())){ |
| | | String[] split = jcsqd.getJgzt().replaceAll("\n", "").split("。|;|;"); |
| | | for (String jg : split) { |
| | | if(StringUtil.isNotBlank(jg) && !jg.contains("未见异常") |
| | | && !jg.contains("未见明显异常") && !jg.contains("未见占位") |
| | | && !jg.contains("未见明显")&& !jg.contains("正常")&& !jg.contains("双侧椎间孔无狭窄")){ |
| | | && !jg.contains("未见明显异常") && !jg.contains("未见占位") && !jg.contains("未见") |
| | | && !jg.contains("未见明显")&& !jg.contains("正常")&& !jg.contains("双侧椎间孔无狭窄")&& !jg.contains("无殊")){ |
| | | TjJcycxm jcycxm=new TjJcycxm(); |
| | | jcycxm.setTjh(s); |
| | | jcycxm.setYqid(dictHosp.getCode()); |
| | |
| | | log.error("定时器执行报错"); |
| | | log.error(String.valueOf(e),e.getMessage()); |
| | | } finally { |
| | | if (reentrantLock.isLocked()) { |
| | | scheduledTasks.remove(dictHosp.getCode()); |
| | | reentrantLock.unlock(); |
| | | } |
| | | DataSourceContextHolder.setDataSourceKey(DataSourceType.MASTER.name()); |
| | | DataSourceContextHolder.clear(); |
| | | |
| | | reentrantLock.unlock(); |
| | | scheduledTasks.remove(dictHosp.getCode()); |
| | | // DataSourceContextHolder.setDataSourceKey(DataSourceType.MASTER.name()); |
| | | // DataSourceContextHolder.clear(); |
| | | log.info("任务{}已释放锁",dictHosp.getCode()); |
| | | } |
| | | } |
| | | |
| | |
| | | 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); |
| | | if (null != jcsqdList && !jcsqdList.isEmpty()) { |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | jcsqdService.deletedLtkjJcsqdByTjhAndTmh(s); |
| | | jcbgdService.deletedLtkjJcbgdByTjhAndTmh(s); |
| | | jcsqdService.saveBatch(jcsqdList); |
| | | List<LtkjExamJcbgd> jcbgdList = testMapper.getCcXZxYyPacsLtkjExamJcbgd(s); |
| | | List<LtkjExamJcbgd> jcbgdList = testMapper.getCcXZxYyPacsLtkjExamJcbgd(s,hospId); |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |
| | | if (null != jcbgdList && !jcbgdList.isEmpty()) jcbgdService.saveBatch(jcbgdList); |
| | | DynamicDataSourceContextHolder.clearDataSourceType(); |