diff --git a/src/main/java/com/ann/repository/InterfaceHisCacheDtoRepository.java b/src/main/java/com/ann/repository/InterfaceHisCacheDtoRepository.java index 44293bc..93eb3e5 100644 --- a/src/main/java/com/ann/repository/InterfaceHisCacheDtoRepository.java +++ b/src/main/java/com/ann/repository/InterfaceHisCacheDtoRepository.java @@ -8,7 +8,7 @@ import org.springframework.data.jpa.repository.Query; import java.util.List; public interface InterfaceHisCacheDtoRepository extends JpaRepository { - @Query(value = "select id,inp_no,visit_id,pdf_path,type from Interface_His_Cache where state = 0 and pdf_path is not null",nativeQuery = true) + @Query(value = "select top 10 id,inp_no,visit_id,pdf_path,type from Interface_His_Cache where state = 0 and pdf_path is not null",nativeQuery = true) public List findAllByStateAndPdfPathIsNotNullDto(); } diff --git a/src/main/java/com/ann/service/impl/QueueService.java b/src/main/java/com/ann/service/impl/QueueService.java index 4a00681..c14f64d 100644 --- a/src/main/java/com/ann/service/impl/QueueService.java +++ b/src/main/java/com/ann/service/impl/QueueService.java @@ -19,6 +19,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import java.io.File; import java.util.Date; @@ -382,83 +383,96 @@ public class QueueService { public void doSomethingByHIS() { try { - //循环开始处理 所有未处理的 - List interfaceHisCaches = interfaceHisCacheService.findInterfaceHisCacheByState(); - for (InterfaceHisCacheDto interfaceHisCacheDto: interfaceHisCaches) { - InterfaceHisCache interfaceHisCache = new InterfaceHisCache(); - BeanUtils.copyProperties(interfaceHisCacheDto,interfaceHisCache); - String type = null,remark = null,title = null,pdfPath = null,state = "2"; - ArchiveDetail archiveDetail = null; - try{ - ArchiveMaster archiveMaster = archiveMasterService.findByInpNoAndVisitIdAndIsValid(interfaceHisCache.getInpNo(), interfaceHisCache.getVisitId()); - if(archiveMaster != null){ - if(interfaceHisCache.getType() != null){ - //给type 属性赋值 - if(Objects.equals(interfaceHisCache.getType(),"0")){ - type = AliasName.SOS; - title = "临时医嘱"; - }else if(Objects.equals(interfaceHisCache.getType(),"1")){ - type = AliasName.PRN; - title = "长期医嘱"; - } + while (true) { + //循环开始处理 所有未处理的 + List interfaceHisCaches = interfaceHisCacheService.findInterfaceHisCacheByState(); + if(CollectionUtils.isEmpty(interfaceHisCaches)){ + break; + } + doSomethingByHISMethod(interfaceHisCaches); + } + }catch (Exception e){ + logger.error("出错咯!错误信息为{},以及错误行数为:{}" ,e,e.getStackTrace()[0]); + } - // 查询库中是否存在 如果存在就更新 - archiveDetail = archiveDetailService.isExit(archiveMaster.getId(), type, "HIS系统", title); - Date date = new Date(); - if (archiveDetail == null) { - archiveDetail = new ArchiveDetail(archiveMaster.getId(), date, type, "HIS系统", title, - title ,1); - archiveDetailService.save(archiveDetail); - }else{ - //更新时间 - archiveDetail.setUpLoadDateTime(date); - } + } - //开始下载 - File pdfFile = FileUtils.createFile("pdfs", interfaceHisCache.getInpNo(), interfaceHisCache.getVisitId(), archiveDetail.getId(), ""); - if (pdfFile != null) { - if (interfaceHisCache.getPdfPath().endsWith(".pdf") || interfaceHisCache.getPdfPath().endsWith(".PDF")) { - pdfPath = DownloadUtils.downLoadPdfFile(pdfFile, interfaceHisCache.getPdfPath(), type); - if (pdfPath != null) { - // 转成格式 - archiveDetail.setPdfPath(pdfPath); - archiveDetailService.save(archiveDetail); - //删除FTP文件 - if(FTPUtil.deleteFile(interfaceHisCache.getPdfPath())){ - // 成功 - state = "1"; - } - }else { - remark = "下载失败"; + private void doSomethingByHISMethod(List interfaceHisCaches){ + for (InterfaceHisCacheDto interfaceHisCacheDto: interfaceHisCaches) { + InterfaceHisCache interfaceHisCache = new InterfaceHisCache(); + BeanUtils.copyProperties(interfaceHisCacheDto,interfaceHisCache); + String type = null,remark = null,title = null,pdfPath = null,state = "2"; + ArchiveDetail archiveDetail = null; + try{ + ArchiveMaster archiveMaster = archiveMasterService.findByInpNoAndVisitIdAndIsValid(interfaceHisCache.getInpNo(), interfaceHisCache.getVisitId()); + if(archiveMaster != null){ + if(interfaceHisCache.getType() != null){ + //给type 属性赋值 + if(Objects.equals(interfaceHisCache.getType(),"0")){ + type = AliasName.SOS; + title = "临时医嘱"; + }else if(Objects.equals(interfaceHisCache.getType(),"1")){ + type = AliasName.PRN; + title = "长期医嘱"; + } + + // 查询库中是否存在 如果存在就更新 + archiveDetail = archiveDetailService.isExit(archiveMaster.getId(), type, "HIS系统", title); + Date date = new Date(); + if (archiveDetail == null) { + archiveDetail = new ArchiveDetail(archiveMaster.getId(), date, type, "HIS系统", title, + title ,1); + archiveDetailService.save(archiveDetail); + }else{ + //更新时间 + archiveDetail.setUpLoadDateTime(date); + } + + //开始下载 + File pdfFile = FileUtils.createFile("pdfs", interfaceHisCache.getInpNo(), interfaceHisCache.getVisitId(), archiveDetail.getId(), ""); + if (pdfFile != null) { + if (interfaceHisCache.getPdfPath().endsWith(".pdf") || interfaceHisCache.getPdfPath().endsWith(".PDF")) { + pdfPath = DownloadUtils.downLoadPdfFile(pdfFile, interfaceHisCache.getPdfPath(), type); + if (pdfPath != null) { + // 转成格式 + archiveDetail.setPdfPath(pdfPath); + archiveDetailService.save(archiveDetail); + //删除FTP文件 + if(FTPUtil.deleteFile(interfaceHisCache.getPdfPath())){ + // 成功 + state = "1"; } + }else { + remark = "下载失败"; } - }else{ - remark = "文件创建失败"; } }else{ - remark = "类型为空"; + remark = "文件创建失败"; } }else{ - remark = "没有入院信息"; + remark = "类型为空"; } - }catch (Exception e){ - remark = e.getMessage(); + }else{ + remark = "没有入院信息"; } + }catch (Exception e){ + remark = e.getMessage(); + } - if(remark != null){ - // 报错删掉患者报告详情信息 - if (archiveDetail != null) { + if(remark != null){ + // 报错删掉患者报告详情信息 + if (archiveDetail != null) { + try { archiveDetailService.delete(archiveDetail.getId()); + } catch (Exception e) { + e.printStackTrace(); } } - //赋值 - interfaceHisCache.setValue(state,remark,new Date()); - interfaceHisCacheService.save(interfaceHisCache); } - }catch (Exception e){ - logger.error("出错咯!错误信息为{},以及错误行数为:{}" ,e,e.getStackTrace()[0]); + //赋值 + interfaceHisCache.setValue(state,remark,new Date()); + interfaceHisCacheService.save(interfaceHisCache); } - } public boolean isInteger(String str) {