From ce66fbac70998921bdd38bd05dd0661df2f3cffc Mon Sep 17 00:00:00 2001 From: leijx <1477272687@qq.com> Date: Thu, 24 Sep 2020 09:47:20 +0800 Subject: [PATCH] =?UTF-8?q?11=E3=80=81=E5=B0=86=E5=9B=BE=E7=89=87=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E6=94=B9=E6=88=90=E5=8F=AF=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=202=E3=80=81=E5=88=A0=E9=99=A4=E8=80=81=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=203=E3=80=81=E7=BB=99=E6=B8=85=E5=8D=95=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E9=A1=B5=E7=A0=81=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=8C=85?= =?UTF-8?q?=E6=8B=AC=E6=8A=A4=E7=90=86=E7=9A=84=EF=BC=8C=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E9=87=8D=E7=97=87=E7=9A=84=204=E3=80=81=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E6=8E=A5=E5=8F=A3=E4=B8=8B=E8=BD=BD=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E7=BB=9F=E4=B8=80=E5=8D=8F=E8=AE=AE=E4=B8=BA?= =?UTF-8?q?FTP=EF=BC=8C=E6=96=87=E4=BB=B6=E7=B1=BB=E5=9E=8B=E4=B8=BApdf,?= =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E5=AF=86=E7=A0=81=E9=83=BD=E4=B8=BAcommon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ann/controller/TestController.java | 134 ----------- .../com/ann/entity/constant/AliasName.java | 32 +-- .../com/ann/entity/filing/ArchiveDetail.java | 1 + .../com/ann/entity/filing/ArchiveDetail1.java | 63 ----- .../java/com/ann/entity/filing/Queue.java | 24 -- .../java/com/ann/job/SchedulerAllJob.java | 8 +- .../java/com/ann/job/config/QuartzConfig.java | 28 --- .../{QuartzConfig1.java => QuartzConfig.java} | 2 +- .../repository/ArchiveDetail1Repository.java | 27 --- .../repository/ArchiveDetailRepository.java | 46 ++-- .../InterfaceHisCacheRepository.java | 4 - .../com/ann/repository/QueueRepository.java | 11 - .../com/ann/service/ArchiveDetailService.java | 8 +- .../impl/ArchiveDetailServiceImpl.java | 35 +-- .../com/ann/service/impl/QueueService.java | 151 +++++------- src/main/java/com/ann/utils/DateUtils.java | 23 -- .../java/com/ann/utils/DownloadUtils.java | 6 +- src/main/java/com/ann/utils/FTPUtil.java | 1 - src/main/java/com/ann/utils/FileUtils.java | 61 ++--- src/main/java/com/ann/utils/FtpUtils.java | 36 --- src/main/java/com/ann/utils/JSchUtils.java | 67 ------ src/main/java/com/ann/utils/SFTPUtil.java | 224 ------------------ src/main/resources/application.yml | 5 +- 23 files changed, 136 insertions(+), 861 deletions(-) delete mode 100644 src/main/java/com/ann/controller/TestController.java delete mode 100644 src/main/java/com/ann/entity/filing/ArchiveDetail1.java delete mode 100644 src/main/java/com/ann/entity/filing/Queue.java delete mode 100644 src/main/java/com/ann/job/config/QuartzConfig.java rename src/main/java/com/ann/job/obsolete/{QuartzConfig1.java => QuartzConfig.java} (90%) delete mode 100644 src/main/java/com/ann/repository/ArchiveDetail1Repository.java delete mode 100644 src/main/java/com/ann/repository/QueueRepository.java delete mode 100644 src/main/java/com/ann/utils/DateUtils.java delete mode 100644 src/main/java/com/ann/utils/SFTPUtil.java diff --git a/src/main/java/com/ann/controller/TestController.java b/src/main/java/com/ann/controller/TestController.java deleted file mode 100644 index 3f4c267..0000000 --- a/src/main/java/com/ann/controller/TestController.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.ann.controller; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.serializer.SerializerFeature; -import com.ann.entity.filing.MessageSubordinate; -import com.ann.entity.filing.dto.MessageDto; -import com.ann.entity.filing.dto.PatientMainDto; -import com.ann.entity.interfaceEntity.MessageLog; -import com.ann.entity.other.QuartzBean; -import com.ann.repository.MessageSubordinateRepository; -import com.ann.service.ArchiveDetailService; -import com.ann.utils.*; -import jcifs.smb.SmbFileInputStream; -import org.apache.cxf.endpoint.Client; -import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; -import org.omg.SendingContext.RunTime; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestController; -import sun.net.ftp.FtpClient; - -import java.io.*; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * @Author: LeiJiaXin - * @Date: 2019/7/18 10:47 - */ -@Controller -@RequestMapping("/") -public class TestController { - - @Autowired - private ArchiveDetailService archiveDetailService; - - @Autowired - MessageSubordinateRepository messageSubordinateRepository; - - @RequestMapping("/demo") - public String aa() { - return "demo"; - } - - @RequestMapping("/haha") - public String createJob(QuartzBean quartzBean) { - - - JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); - Client client = dcf.createClient("http://localhost:8080/services/HomepageDictionary?wsdl"); - Object[] objects = new Object[0]; - // invoke("方法名",参数1,参数2,参数3....); - try { - objects = client.invoke("CheckData", "2b52c101-69d3-495c-94dc-1e3c47e61623"); - } catch (Exception e) { - e.printStackTrace(); - } - return objects[0].toString(); - } - - @RequestMapping("/xixi") - public String xixi() { - // 创建url地址 - /*String address = "ftp://PTVIEW:MedExTech@10.6.0.65:10021/ecgdata/ECG/2019-07-24/MECGCAS1907240069_1.jpg"; - address = address.substring(address.indexOf("/")+2,address.length()); - // 10.6.0.65:10021/ecgdata/ECG/2019-07-24/MECGCAS1907240069_1.jpg - String ftpAccount = address.substring(0,address.indexOf("@")); - String[] split = ftpAccount.split(":"); - - address = address.substring(address.indexOf("@")+1,address.length()); - - String url = address.substring(0,address.indexOf(":")); - Integer port = 0; - if(address.indexOf(":") != -1 && address.indexOf("/") != -1 ){ - port = Integer.parseInt(address.substring(address.indexOf(":")+1,address.indexOf("/"))); - } - String path = address.substring(address.indexOf("/"),address.length()); -*/ - String address = "ftp://10.6.0.75/000/000568558/2/000568558000_2_麻醉_麻醉单_1_1.pdf"; - //String address = "ftp://10.6.0.65:10021/ecgdata/ECG/2019-07-25/201907250940334102.pdf"; - String temp = address; - address = address.substring(address.indexOf("/") + 2, address.length()); - - String url = address.substring(0, address.indexOf("/")); - String path = address.substring(address.indexOf("/"), address.length()); - - try { - FtpClient ftpClient = FtpUtils.connectFTP(url, 21, "mdsd", "mdsd"); - // File pdfFile = FileUtils.createFile("pdfs","789","123456", "阿雷小猴子"); - //FtpUtils.downloadFtp(temp,ftpClient,pdfFile); - } catch (Exception e) { - e.printStackTrace(); - } - - - return "我是测试ftp的~~~~"; - } - -// @RequestMapping("/deleteDetail") -// public String deleteDetail() throws Exception{ -// archiveDetailService.delete(); -// return "成功"; -// } - - @ResponseBody - @RequestMapping("/test") - public String xixi1() { - archiveDetailService.test(); - return "哈哈哈哈"; - } - - @ResponseBody - @RequestMapping("/updatePatient") - public String cc1(){ - List haha = messageSubordinateRepository.findHaha(); - for (MessageSubordinate messageSubordinate: - haha) { - String contentJson = messageSubordinate.getContentJson(); - MessageLog messageLog = JSON.parseObject(contentJson, MessageLog.class); - if (messageLog != null) { - String outJson = messageLog.getOutJson(); - if (outJson != null) { - MessageDto messageDto = JSON.parseObject(outJson, MessageDto.class); - String patientMainStr = JSON.toJSONString(new PatientMainDto(messageDto.getInpNo(), messageDto.getVisitId()), SerializerFeature.WriteMapNullValue); - } - } - } - return haha.size()+""; - } - -} diff --git a/src/main/java/com/ann/entity/constant/AliasName.java b/src/main/java/com/ann/entity/constant/AliasName.java index 5367a77..1ffd51d 100644 --- a/src/main/java/com/ann/entity/constant/AliasName.java +++ b/src/main/java/com/ann/entity/constant/AliasName.java @@ -23,17 +23,17 @@ public class AliasName { // 心电图报告单 59 public static final String EKG_REPORT = "59"; - // 入院记录 - public static final String ADMISSION_RECORD = "9"; - - // 出院记录 - public static final String DISCHARGE_RECORD = "113"; - - // 转科记录 - public static final String TRANSFER_RECORD = "114"; +// // 入院记录 +// public static final String ADMISSION_RECORD = "9"; +// +// // 出院记录 +// public static final String DISCHARGE_RECORD = "113"; +// +// // 转科记录 +// public static final String TRANSFER_RECORD = "114"; // 取消入院 - public static final String CANCELLATION_DISCHARGE = "115"; +// public static final String CANCELLATION_DISCHARGE = "115"; // 手麻 public static final String HANDNUMBNESS_REPORT = "117"; @@ -42,7 +42,7 @@ public class AliasName { public static final String ICU_REPORT = "121"; // 检查申请单 - public static final String PARAMETER_EXAMAPPLY = "119"; +// public static final String PARAMETER_EXAMAPPLY = "119"; // 输血单 public static final String BLOODAPPLY_REPORT = "120"; @@ -51,16 +51,16 @@ public class AliasName { public static final String PETCT_REPORT = "60"; // V6护理记录单 - public static final String NURSING_RECORD_SHEET = "2"; +// public static final String NURSING_RECORD_SHEET = "2"; // 病案首页 - public static final String MEDICAL_RECORD_HOMEPAGE = "3"; +// public static final String MEDICAL_RECORD_HOMEPAGE = "3"; // 评估护理单 - public static final String ASSESSMENT_NURSING_LIST = "4"; +// public static final String ASSESSMENT_NURSING_LIST = "4"; // 体温单 - public static final String THERMOGRAM = "5"; +// public static final String THERMOGRAM = "5"; // 检验申请单 //public static final String PARAMETER_EXAMAPPLY = "118"; @@ -68,8 +68,8 @@ public class AliasName { // 检验报告 public static final String INSPECTION_REPORT = "10"; - // 扫描文件 - public static final String SCANNING_FILE = "30"; +// // 扫描文件 +// public static final String SCANNING_FILE = "30"; // 20200701 长期医嘱 public static final String PRN = "122"; diff --git a/src/main/java/com/ann/entity/filing/ArchiveDetail.java b/src/main/java/com/ann/entity/filing/ArchiveDetail.java index 2e36981..1a9253d 100644 --- a/src/main/java/com/ann/entity/filing/ArchiveDetail.java +++ b/src/main/java/com/ann/entity/filing/ArchiveDetail.java @@ -44,6 +44,7 @@ public class ArchiveDetail { private String sys; + private Integer pageNumber = 1; /** * 扩展字段: 用于进行更新状态、与报告进行匹配 * 2019-9-4 diff --git a/src/main/java/com/ann/entity/filing/ArchiveDetail1.java b/src/main/java/com/ann/entity/filing/ArchiveDetail1.java deleted file mode 100644 index 8eb659d..0000000 --- a/src/main/java/com/ann/entity/filing/ArchiveDetail1.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.ann.entity.filing; - -import lombok.Data; -import org.hibernate.annotations.GenericGenerator; - -import javax.persistence.*; -import java.util.Date; - -/** - * @Description 患者清单详情 是 ArchiveMaster患者清单 从属关系 - * @Date 2019/7/9 10:07 - * @Created by ljx - */ -@Data -@Entity -@Table(name = "archive_detail_20191202") -public class ArchiveDetail1 { - - @Id - @GenericGenerator(name = "system-uuid", strategy = "uuid2") - @GeneratedValue(generator = "system-uuid") - private String id; - - private String pdfPath; - - // -----------------------绑定关系 - @Column(name = "masterid") - private String masterID; - - @Column(name = "uploaddatetime") - private Date upLoadDateTime; - - @Column(name = "assortid") - private String assortID; - - private String source; - - @Column(name = "subassort") - private String subAssort; - - private String title; - - private String flag = "0"; - - private String sys; - - /** - * 扩展字段: 用于进行更新状态、与报告进行匹配 - * 2019-9-4 - */ - private String applyId; - - public ArchiveDetail1() { - } - - public ArchiveDetail1(String masterID, Date upLoadDateTime, String assortID, String source, String applyId) { - this.masterID = masterID; - this.upLoadDateTime = upLoadDateTime; - this.assortID = assortID; - this.source = source; - this.applyId = applyId; - } -} diff --git a/src/main/java/com/ann/entity/filing/Queue.java b/src/main/java/com/ann/entity/filing/Queue.java deleted file mode 100644 index 090afd5..0000000 --- a/src/main/java/com/ann/entity/filing/Queue.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.ann.entity.filing; - -import lombok.Data; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -/** - * 对列表 - * - * @Author: LeiJiaXin - * @Date: 2019/7/11 21:49 - */ -@Data -@Table -@Entity -public class Queue { - - @Id - private String id; - - private String time; -} diff --git a/src/main/java/com/ann/job/SchedulerAllJob.java b/src/main/java/com/ann/job/SchedulerAllJob.java index 1d8ed00..aae38a6 100644 --- a/src/main/java/com/ann/job/SchedulerAllJob.java +++ b/src/main/java/com/ann/job/SchedulerAllJob.java @@ -25,9 +25,9 @@ public class SchedulerAllJob { */ public void scheduleJobs() throws SchedulerException { Scheduler scheduler = schedulerFactoryBean.getScheduler(); -// scheduleJob1(scheduler); -// scheduleJob2(scheduler); -// scheduleJob3(scheduler); + scheduleJob1(scheduler); + scheduleJob2(scheduler); + scheduleJob3(scheduler); scheduleJob4(scheduler); } @@ -90,7 +90,7 @@ public class SchedulerAllJob { private void scheduleJob4(Scheduler scheduler) throws SchedulerException { JobDetail jobDetail = JobBuilder.newJob(ScheduledJob4.class).withIdentity("job4", "group1").build(); // 0 1-2 * * * ? - CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/15 * * * * ?"); + CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 */1 * * * ?"); // 每1分钟执行一次 CronTrigger cronTrigger = TriggerBuilder.newTrigger().withIdentity("job4", "group1").withSchedule(scheduleBuilder).build(); scheduler.scheduleJob(jobDetail, cronTrigger); diff --git a/src/main/java/com/ann/job/config/QuartzConfig.java b/src/main/java/com/ann/job/config/QuartzConfig.java deleted file mode 100644 index 4af1c58..0000000 --- a/src/main/java/com/ann/job/config/QuartzConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.ann.job.config; - -/** - * 定时任务 - * - * @Author: LeiJiaXin - * @Date: 2019/7/13 17:03 - */ -//@Configuration -public class QuartzConfig { - -// @Bean -// public JobDetail uploadTaskDetail() { -// // 创建工作 -// return JobBuilder.newJob(MyTask.class).withIdentity("MyTask").storeDurably().build(); -// } -// -// @Bean -// public Trigger uploadTaskTrigger() { -// //TODO 这里设定执行方式 -// CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("*/10 * * * * ?"); -// // 返回任务触发器 -// return TriggerBuilder.newTrigger().forJob(uploadTaskDetail()) -// .withIdentity("MyTask") -// .withSchedule(scheduleBuilder) -// .build(); -// } -} diff --git a/src/main/java/com/ann/job/obsolete/QuartzConfig1.java b/src/main/java/com/ann/job/obsolete/QuartzConfig.java similarity index 90% rename from src/main/java/com/ann/job/obsolete/QuartzConfig1.java rename to src/main/java/com/ann/job/obsolete/QuartzConfig.java index 6fba3dc..f0dfb9d 100644 --- a/src/main/java/com/ann/job/obsolete/QuartzConfig1.java +++ b/src/main/java/com/ann/job/obsolete/QuartzConfig.java @@ -12,7 +12,7 @@ import org.springframework.stereotype.Component; * @Date: 2019/7/13 17:03 */ @Component -public class QuartzConfig1 implements CommandLineRunner { +public class QuartzConfig implements CommandLineRunner { @Autowired public SchedulerAllJob scheduleJobs; diff --git a/src/main/java/com/ann/repository/ArchiveDetail1Repository.java b/src/main/java/com/ann/repository/ArchiveDetail1Repository.java deleted file mode 100644 index a725c24..0000000 --- a/src/main/java/com/ann/repository/ArchiveDetail1Repository.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.ann.repository; - -import com.ann.entity.filing.ArchiveDetail; -import com.ann.entity.filing.ArchiveDetail1; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.stereotype.Repository; - -import java.util.List; - -/** - * @Author: LeiJiaXin - * @Date: 2019/7/12 9:10 - */ -@Repository -public interface ArchiveDetail1Repository extends JpaRepository { - - // or Source = 'DoctorData' or AssortID = '117' or AssortID = '10' or AssortID = '60' or AssortID = '57' or AssortID = '52' or AssortID = '54' or AssortID = '59' - @Query(nativeQuery = true, value = "select * from archive_detail o where o.MasterID in (select id from archive_master m where m.dept_admission_to = '1040100'\n" + - "and m.admission_date_time < '2019-11-27 00:00:00.000' )") - public List findAllHaha(); - - @Query("select count (o) from ArchiveDetail o where o.masterID = ?1 and o.assortID = ?2 and o.source=?3 and (o.applyId = ?4 and o.applyId is not null) ") - Integer countByMasterIDAndAssortIDAndSourceAndApplyId(String masterId, String AssortID, String source, String applyId); - - public ArchiveDetail findByMasterIDAndAssortIDAndSourceAndApplyId(String masterId, String AssortID, String source, String applyId); -} diff --git a/src/main/java/com/ann/repository/ArchiveDetailRepository.java b/src/main/java/com/ann/repository/ArchiveDetailRepository.java index dde485d..c3159c0 100644 --- a/src/main/java/com/ann/repository/ArchiveDetailRepository.java +++ b/src/main/java/com/ann/repository/ArchiveDetailRepository.java @@ -14,9 +14,9 @@ import java.util.List; @Repository public interface ArchiveDetailRepository extends JpaRepository { - // or Source = 'DoctorData' or AssortID = '117' or AssortID = '10' or AssortID = '60' or AssortID = '57' or AssortID = '52' or AssortID = '54' or AssortID = '59' - @Query("select o from ArchiveDetail o ") - public List findAllHaha(); +// // or Source = 'DoctorData' or AssortID = '117' or AssortID = '10' or AssortID = '60' or AssortID = '57' or AssortID = '52' or AssortID = '54' or AssortID = '59' +// @Query("select o from ArchiveDetail o ") +// public List findAllHaha(); @Query("select count (o) from ArchiveDetail o where o.masterID = ?1 and o.assortID = ?2 and o.source=?3 and (o.applyId = ?4 and o.applyId is not null) and o.flag = 0") Integer countByMasterIDAndAssortIDAndSourceAndApplyId(String masterId, String AssortID, String source, String applyId); @@ -24,24 +24,24 @@ public interface ArchiveDetailRepository extends JpaRepository type, String masterId); - - @Query(value = "SELECT stuff(" + - " (SELECT ',' + CONVERT(VARCHAR,a.assort_name) " + - " FROM zd_assort a WHERE a.assort_id in ?1 " + - " and NOT EXISTS(SELECT id FROM archive_detail d WHERE a.assort_id = d.AssortID and d.MasterID = ?2 ) " + - " FOR XML PATH ('') " + - " ),1,1,'') ", nativeQuery = true) - String checkExamApply(String masterId); - - @Query(value = " select * from archive_detail o where o.MasterID in (select m.ID from archive_master m where " + - " m.dept_name in(select code from emr_dictionary where name like ?1 ) and m.admission_Date_Time <= ?2 ) " + - " order by masterid,AssortID ",nativeQuery = true) - public List findArchiveDetail(String deptName,String admissionDateTime); +// @Query(value = "SELECT stuff(" + +// " (SELECT ',' + CONVERT(VARCHAR,a.assort_name) " + +// " FROM zd_assort a WHERE a.assort_id in ?1 " + +// " and NOT EXISTS(SELECT id FROM archive_detail d WHERE a.assort_id = d.AssortID and d.MasterID = ?2 ) " + +// " FOR XML PATH ('') " + +// " ),1,1,'') ", nativeQuery = true) +// String getTypeNotExits(List type, String masterId); + +// @Query(value = "SELECT stuff(" + +// " (SELECT ',' + CONVERT(VARCHAR,a.assort_name) " + +// " FROM zd_assort a WHERE a.assort_id in ?1 " + +// " and NOT EXISTS(SELECT id FROM archive_detail d WHERE a.assort_id = d.AssortID and d.MasterID = ?2 ) " + +// " FOR XML PATH ('') " + +// " ),1,1,'') ", nativeQuery = true) +// String checkExamApply(String masterId); + +// @Query(value = " select * from archive_detail o where o.MasterID in (select m.ID from archive_master m where " + +// " m.dept_name in(select code from emr_dictionary where name like ?1 ) and m.admission_Date_Time <= ?2 ) " + +// " order by masterid,AssortID ",nativeQuery = true) +// public List findArchiveDetail(String deptName,String admissionDateTime); } diff --git a/src/main/java/com/ann/repository/InterfaceHisCacheRepository.java b/src/main/java/com/ann/repository/InterfaceHisCacheRepository.java index 3ca9941..2b5f86e 100644 --- a/src/main/java/com/ann/repository/InterfaceHisCacheRepository.java +++ b/src/main/java/com/ann/repository/InterfaceHisCacheRepository.java @@ -12,8 +12,4 @@ public interface InterfaceHisCacheRepository extends JpaRepository findAllByStateAndPdfPathIsNotNull(String state); -// @Transactional -// @Modifying -// @Query(value = "update InterfaceHisCache o set o.state = ?1 where o.id = ?2 and o.state = 0 and o.type = ?3 ") -// public Integer updateStateById(Integer state, String id, Integer type); } diff --git a/src/main/java/com/ann/repository/QueueRepository.java b/src/main/java/com/ann/repository/QueueRepository.java deleted file mode 100644 index 3f41def..0000000 --- a/src/main/java/com/ann/repository/QueueRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.ann.repository; - -import com.ann.entity.filing.Queue; -import org.springframework.data.jpa.repository.JpaRepository; - -/** - * @Author: LeiJiaXin - * @Date: 2019/7/11 21:59 - */ -public interface QueueRepository extends JpaRepository { -} diff --git a/src/main/java/com/ann/service/ArchiveDetailService.java b/src/main/java/com/ann/service/ArchiveDetailService.java index 9d92840..a0c36c6 100644 --- a/src/main/java/com/ann/service/ArchiveDetailService.java +++ b/src/main/java/com/ann/service/ArchiveDetailService.java @@ -1,5 +1,6 @@ package com.ann.service; + import com.ann.entity.filing.ArchiveDetail; import java.util.List; @@ -14,13 +15,10 @@ public interface ArchiveDetailService { public void delete(String id) throws Exception; - public ArchiveDetail isExit(String id, String type, String source, String applyId) throws Exception; - public String getTypeNotExits(List type, String masterId); - - public String checkExamApply(String masterId) throws Exception; +// public String getTypeNotExits(List type, String masterId); +// public String checkExamApply(String masterId) throws Exception; - public String test(); } diff --git a/src/main/java/com/ann/service/impl/ArchiveDetailServiceImpl.java b/src/main/java/com/ann/service/impl/ArchiveDetailServiceImpl.java index a8800b9..bda007f 100644 --- a/src/main/java/com/ann/service/impl/ArchiveDetailServiceImpl.java +++ b/src/main/java/com/ann/service/impl/ArchiveDetailServiceImpl.java @@ -1,8 +1,6 @@ package com.ann.service.impl; import com.ann.entity.filing.ArchiveDetail; -import com.ann.entity.filing.ArchiveDetail1; -import com.ann.repository.ArchiveDetail1Repository; import com.ann.repository.ArchiveDetailRepository; import com.ann.service.ArchiveDetailService; import com.ann.utils.FileUtils; @@ -22,8 +20,6 @@ public class ArchiveDetailServiceImpl implements ArchiveDetailService { @Autowired ArchiveDetailRepository archiveDetailRepository; - @Autowired - ArchiveDetail1Repository archiveDetail1Repository; @Override public void save(ArchiveDetail archiveDetail) throws Exception{ @@ -43,29 +39,14 @@ public class ArchiveDetailServiceImpl implements ArchiveDetailService { return null; } - @Override - public String getTypeNotExits(List type, String masterId) { - return archiveDetailRepository.getTypeNotExits(type, masterId); - } +// @Override +// public String getTypeNotExits(List type, String masterId) { +// return archiveDetailRepository.getTypeNotExits(type, masterId); +// } - @Override - public String checkExamApply(String masterId)throws Exception { - return archiveDetailRepository.checkExamApply(masterId); - } +// @Override +// public String checkExamApply(String masterId)throws Exception { +// return archiveDetailRepository.checkExamApply(masterId); +// } - @Override - public String test() { - List archiveDetails = archiveDetailRepository.findArchiveDetail("肾病内科","2020-04-06 00:00:00"); - // FileUtils.haha(archiveDetails); - System.out.println(archiveDetails.size()); - int i = 0; - for (ArchiveDetail a : archiveDetails) { - if (a.getPdfPath() != null) { - i = FileUtils.deleteImageFile1(new File(a.getPdfPath()), i); - } - } - System.out.println("一共有:" + archiveDetails.size()); - System.out.println("一共删除:" + i); - return null; - } } diff --git a/src/main/java/com/ann/service/impl/QueueService.java b/src/main/java/com/ann/service/impl/QueueService.java index 3e69b9c..aa60116 100644 --- a/src/main/java/com/ann/service/impl/QueueService.java +++ b/src/main/java/com/ann/service/impl/QueueService.java @@ -21,6 +21,7 @@ import java.io.File; import java.util.Date; import java.util.List; import java.util.Objects; +import java.util.regex.Pattern; /** * @Author: LeiJiaXin @@ -61,9 +62,10 @@ public class QueueService { messageSubordinate.setRemark("住院号:" + messageDto.getInpNo() + "pdf路径为空(可能出现下载问题)。。。"); } else { ArchiveMaster archiveMaster = archiveMasterService.findByInpNoAndVisitIdAndIsValid(messageDto.getInpNo(), messageDto.getVisitId()); + Date date = new Date(); if (archiveMaster != null) { - if(!Objects.equals(messageDto.getType(),AliasName.PATHOLOGY_REPORT)){ - if(archiveMaster.getArchiveState().equals("初审") || archiveMaster.getArchiveState().equals("已归档")){ + if (!Objects.equals(messageDto.getType(), AliasName.PATHOLOGY_REPORT)) { + if (archiveMaster.getArchiveState().equals("初审") || archiveMaster.getArchiveState().equals("已归档")) { messageSubordinate.setStatus(3); messageSubordinateService.save(messageSubordinate); continue; @@ -71,58 +73,68 @@ public class QueueService { } String address = messageDto.getReportAddress(); - Date date = new Date(); if (address != null && (!address.equals(""))) { // 如果是老数据 - if(Objects.equals(messageDto.getIsOld(),"0")){ - archiveDetail = new ArchiveDetail(archiveMaster.getId(), date, messageDto.getType(), messageDto.getSource(), messageDto.getApplyId(),messageDto.getDetailType(),1); + if (Objects.equals(messageDto.getIsOld(), "0")) { + archiveDetail = new ArchiveDetail(archiveMaster.getId(), date, messageDto.getType(), messageDto.getSource(), messageDto.getApplyId(), messageDto.getDetailType(), 1); archiveDetailService.save(archiveDetail); - }else{ + } else { // 查询库中是否存在 如果存在就更新 archiveDetail = archiveDetailService.isExit(archiveMaster.getId(), messageDto.getType(), messageDto.getSource(), messageDto.getApplyId()); if (archiveDetail == null) { archiveDetail = new ArchiveDetail(archiveMaster.getId(), date, messageDto.getType(), messageDto.getSource(), messageDto.getApplyId(), - messageDto.getDetailType(),1); + messageDto.getDetailType(), 1); archiveDetailService.save(archiveDetail); - }else{ + } else { //更新时间 archiveDetail.setUpLoadDateTime(date); } } String pdfPath = null; - String emrPath = ""; - - if(messageDto.getSource().equals(InterfaceName.NURSE_DATA)){ - //医生 护理单独做处理 - if(archiveMaster.getEmrNurseCmt() == null){ + String tempPath = ""; + Integer pageNum = 1; + if (messageDto.getSource().equals(InterfaceName.NURSE_DATA)) { + // 护理单独做处理 + if (archiveMaster.getEmrNurseCmt() == null) { archiveMaster.setEmrNurseCmt("提交"); archiveMasterService.save(archiveMaster); } - String a = ""; - if(messageDto.getApplyId().lastIndexOf("_") != -1){ - a = messageDto.getApplyId().substring(0, messageDto.getApplyId().indexOf(".pdf")); + + String tempPageNum = ""; + if (messageDto.getApplyId().lastIndexOf("_") != -1) { + //apply_id 000562390700_1_000562390700_0_1_JHR06.00.02_34_2.pdf + tempPageNum = messageDto.getApplyId().substring(0, messageDto.getApplyId().indexOf(".pdf")); }else{ - a = address.substring(0, address.lastIndexOf("_")); + // address ftp://10.6.0.155/2020-08-04/000562390700_1_000562390700_0_1_JHR06.00.02_34_2_0.pdf + tempPageNum = address.substring(0, address.lastIndexOf("_")); + } + tempPageNum = tempPageNum.substring(tempPageNum.lastIndexOf("_") + 1, tempPageNum.length() ); + if(isInteger(tempPageNum)){ + pageNum = Integer.valueOf(tempPageNum); } - emrPath = messageDto.getType() + "~" + (a.substring(a.lastIndexOf("_") + 1, a.length())) + "~"; - } else if(messageDto.getSource().equals(InterfaceName.DOCTOR_DATA)){ - //护士 护理单独做处理 - if(archiveMaster.getEmrDoctorCmt() == null){ + tempPath = messageDto.getType() + "~" + pageNum + "~"; + + } else if (messageDto.getSource().equals(InterfaceName.DOCTOR_DATA)) { + // 医生单独做处理 + if (archiveMaster.getEmrDoctorCmt() == null) { archiveMaster.setEmrDoctorCmt("提交"); archiveMasterService.save(archiveMaster); } - emrPath = messageDto.getType() + "~" + messageDto.getCaptionDateTime() + "~"; - }else{ + tempPath = messageDto.getType() + "~" + messageDto.getCaptionDateTime() + "~"; + } else { // 20200518 给重症系统的文件排序 - if(messageDto.getType().equals(AliasName.ICU_REPORT)){ + if (messageDto.getType().equals(AliasName.ICU_REPORT)) { + if(isInteger(messageDto.getCaptionDateTime())){ + pageNum = Integer.valueOf(messageDto.getCaptionDateTime()); + } //重症如果是pdf - emrPath = messageDto.getDetailType() + "~" + messageDto.getCaptionDateTime() + "~"; + tempPath = messageDto.getDetailType() + "~" + messageDto.getCaptionDateTime() + "~"; } } - File pdfFile = FileUtils.createFile("pdfs", messageDto.getInpNo(), messageDto.getVisitId(), archiveDetail.getId(), emrPath); + File pdfFile = FileUtils.createFile("pdfs", messageDto.getInpNo(), messageDto.getVisitId(), archiveDetail.getId(), tempPath); if (pdfFile != null) { if (address.endsWith(".pdf") || address.endsWith(".PDF")) { String path = DownloadUtils.downLoadPdfFile(pdfFile, address, messageDto.getType()); @@ -132,28 +144,28 @@ public class QueueService { } else { if (Objects.equals(messageDto.getType(), AliasName.ICU_REPORT)) { File file = pdfFile; - if(address.indexOf(".png") != -1){ + if (address.indexOf(".png") != -1) { file = FileUtils.createDir("images", messageDto.getInpNo(), messageDto.getVisitId()); } String fileNames = DownloadUtils.downloadImageFiles(address, file.getParent()); - if(fileNames != null){ - if(address.indexOf(".png") != -1) { + if (fileNames != null) { + if (address.indexOf(".png") != -1) { // 多个图片那么转成pdf pdfPath = PdfUtils.imageDirToPdf(fileNames, pdfFile); - } else{ - if(fileNames.indexOf(";") != -1){ - fileNames = fileNames.substring(0,fileNames.length()-1); + } else { + if (fileNames.indexOf(";") != -1) { + fileNames = fileNames.substring(0, fileNames.length() - 1); file.delete(); } - if(new File(fileNames).renameTo(file)){ + if (new File(fileNames).renameTo(file)) { pdfPath = file.getAbsolutePath(); } } } } else { // 一张图片转成pdf - File imageFile = FileUtils.createFile("images", messageDto.getInpNo(), messageDto.getVisitId(), archiveDetail.getId(), emrPath); + File imageFile = FileUtils.createFile("images", messageDto.getInpNo(), messageDto.getVisitId(), archiveDetail.getId(), tempPath); if (DownloadUtils.downloadImageFile(address, messageDto.getType(), imageFile)) { pdfPath = PdfUtils.imagesToPdf(imageFile, pdfFile); } @@ -163,6 +175,7 @@ public class QueueService { //存入pdf地址 if (pdfPath != null) { // 转成格式 + archiveDetail.setPageNumber(pageNum); archiveDetail.setPdfPath(pdfPath); archiveDetailService.save(archiveDetail); @@ -183,27 +196,9 @@ public class QueueService { } } } else { - // 判断是否是扫描文件 - if(messageDto.getType().equals(AliasName.SCANNING_FILE)){ - String outContent = this.handlePdfFile(messageDto, archiveMaster.getId()); - if(outContent == null){ - status = 1; - //更新messageLog的最后执行时间 - Date xmlCreateTime = messageLog.getXmlCreateTime(); - long beginTime = xmlCreateTime.getTime(); - long endTime = date.getTime(); - messageLog.setXmlExecutionTime(endTime - beginTime); - - messageService.save(messageLog); - }else{ - messageSubordinate.setRemark(outContent); - } - - }else{ - messageSubordinate.setRemark("地址为空。。。。"); - } + messageSubordinate.setRemark("地址为空。。。。"); } - } else { + } else{ messageSubordinate.setRemark("住院号为:" + messageDto.getInpNo() + "的ArchiveMaster为空。。。。"); } } @@ -241,45 +236,6 @@ public class QueueService { } } - public String handlePdfFile(MessageDto messageDto,String masterId) throws Exception { - try { - ScanningFile scanningFile = JSON.parseObject(messageDto.getObject().toString(), ScanningFile.class); - if (scanningFile == null) { - return "扫描文件解析实体错误。。。"; - } - - Object[] objects = WebServiceUtils.connect(scanningFile.getPath() + "\\" + scanningFile.getFileName()); - if (objects == null) { - return "扫描文件下载图片出错了。。。"; - } - - byte[] bytes = (byte[]) objects[0]; - String path = (scanningFile.getApplyId() != null ? scanningFile.getApplyId() : "") + "~" + (scanningFile.getNumber() != null ? scanningFile.getNumber() : ""); - // 给临时图片填充内容 - File imageTempFile = FileUtils.createFile("images", messageDto.getInpNo(), messageDto.getVisitId(), path); - File imageFile = FileUtils.getImageFileByByteArray(bytes, imageTempFile); - if (imageFile == null) { - return "扫描文件填充临时图片出错了。。。"; - } - - File pdfFile = FileUtils.createFile("pdfs", messageDto.getInpNo(), messageDto.getVisitId(), path); - String pdfPath = PdfUtils.imagesToPdf(imageFile, pdfFile); - //存入pdf地址 - if (pdfPath == null) { - return "扫描文件image转成pdf出错了。。。"; - } - - // 如果存在 那就更新 - ArchiveDetail archiveDetail = archiveDetailService.isExit(masterId, messageDto.getType(), messageDto.getSource(), messageDto.getApplyId() + "~" + (scanningFile.getNumber() != null ? scanningFile.getNumber() : "")); - if (archiveDetail == null) { - archiveDetail = new ArchiveDetail(masterId, new Date(), messageDto.getType(), messageDto.getSource(), messageDto.getApplyId() + "~" + (scanningFile.getNumber() != null ? scanningFile.getNumber() : ""), pdfPath); - archiveDetailService.save(archiveDetail); - } - } catch (Exception e) { - return e + ""; - } - return null; - } public void doSomethingByHIS() { try { @@ -302,10 +258,10 @@ public class QueueService { } // 查询库中是否存在 如果存在就更新 - archiveDetail = archiveDetailService.isExit(archiveMaster.getId(), interfaceHisCache.getType(), "HIS系统", ""); + archiveDetail = archiveDetailService.isExit(archiveMaster.getId(), type, "HIS系统", title); Date date = new Date(); if (archiveDetail == null) { - archiveDetail = new ArchiveDetail(archiveMaster.getId(), date, type, "HIS系统", "", + archiveDetail = new ArchiveDetail(archiveMaster.getId(), date, type, "HIS系统", title, title ,1); archiveDetailService.save(archiveDetail); }else{ @@ -359,4 +315,9 @@ public class QueueService { } } + + public boolean isInteger(String str) { + Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); + return pattern.matcher(str).matches(); + } } diff --git a/src/main/java/com/ann/utils/DateUtils.java b/src/main/java/com/ann/utils/DateUtils.java deleted file mode 100644 index 6b80444..0000000 --- a/src/main/java/com/ann/utils/DateUtils.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.ann.utils; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; - -/** - * @Description - * @Date 2019/6/24 10:51 - * @Created by ljx - */ -public class DateUtils { - - - // 生成指定格式的时间 - public static String getDateStr() { - //日期转换为字符串 - LocalDateTime now = LocalDateTime.now(); - DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyyMMddhhmmss"); - return now.format(format); - } - - -} diff --git a/src/main/java/com/ann/utils/DownloadUtils.java b/src/main/java/com/ann/utils/DownloadUtils.java index 9326d55..28808ba 100644 --- a/src/main/java/com/ann/utils/DownloadUtils.java +++ b/src/main/java/com/ann/utils/DownloadUtils.java @@ -227,9 +227,9 @@ public class DownloadUtils { userName = "his"; password = "his_docus"; }else if(Objects.equals(type, AliasName.OTHER_REPORT)) { - //其他报告 根据IP区分报告类型 考虑IP单独做配置 - userName = ""; - password = ""; + // 2020-8-18 后续接入的报告 统一走ftp、固定账号密码common/common + userName = "common"; + password = "common"; }else { // 电子病历 // ftp://10.6.0.155/2020-01-25/000593857900_1_000593857900_0_4_EMR06.02.04_3_5_0.pdf diff --git a/src/main/java/com/ann/utils/FTPUtil.java b/src/main/java/com/ann/utils/FTPUtil.java index 9d189fc..880be2f 100644 --- a/src/main/java/com/ann/utils/FTPUtil.java +++ b/src/main/java/com/ann/utils/FTPUtil.java @@ -149,7 +149,6 @@ public class FTPUtil { // 切换FTP目录 ftpClient.changeWorkingDirectory("/"); int dele = ftpClient.dele(path); - System.out.println(dele); logger.error("删除FTP文件为:{}",address); flag = true; } catch (Exception e) { diff --git a/src/main/java/com/ann/utils/FileUtils.java b/src/main/java/com/ann/utils/FileUtils.java index dc4dbb9..b11c019 100644 --- a/src/main/java/com/ann/utils/FileUtils.java +++ b/src/main/java/com/ann/utils/FileUtils.java @@ -27,43 +27,6 @@ public class FileUtils { // pdf地址 public static String pdfPath; - public static File createFile(String fileType, String inpNo, String visitId, String path) throws Exception { - File localFile = null; - try { - //生成图片地址 - // ---------------------------此处写死 年月需改善 - LocalDate date = LocalDate.now(); - String fileDirName = null; - if (Objects.equals(fileType, "images")) { - fileDirName = "Z:/images/" + date.getYear() + "/" + date.getMonthValue() + "/" + inpNo + "_" + visitId; - } else if (Objects.equals(fileType, "pdfs")) { - fileDirName = pdfPath + "/" + date.getYear() + "/" + date.getMonthValue() + "/" + inpNo + "_" + visitId; - } - - //判断是否有该文件夹 否则创建 - File fileDir = new File(fileDirName); - if (!fileDir.exists()) { - fileDir.mkdirs(); - } - - String fileName = null; - if (Objects.equals(fileType, "images")) { - fileName = fileDir + "/" + path + ".jpg"; - } else if (Objects.equals(fileType, "pdfs")) { - fileName = fileDir + "/" + path + ".pdf"; - } - - localFile = new File(fileName); - if (!localFile.exists()) { - localFile.createNewFile(); - } - } catch (IOException e) { - throw e; - } - return localFile; - - } - @Value("${file.pdfPath}") public void setPdfPath(String pdfPath) { FileUtils.pdfPath = pdfPath; @@ -73,15 +36,27 @@ public class FileUtils { return pdfPath; } - public static File createFile(String fileType, String inpNo, String visitId, String masterId, String emrPath) throws IOException { + // pdf地址 + public static String imagePath; + + @Value("${file.imagePath}") + public void setImagePath(String imagePath) { + FileUtils.imagePath = imagePath; + } + + public static String getImagePath() { + return imagePath; + } + + + public static File createFile(String fileType, String inpNo, String visitId, String detailId, String tempPath) throws IOException { File localFile = null; try { //生成图片地址 - // ---------------------------此处写死 年月需改善 LocalDate date = LocalDate.now(); String fileDirName = null; if (Objects.equals(fileType, "images")) { - fileDirName = "Z:/images/" + date.getYear() + "/" + date.getMonthValue() + "/" + inpNo + "_" + visitId; + fileDirName = imagePath+"/" + date.getYear() + "/" + date.getMonthValue() + "/" + inpNo + "_" + visitId; } else if (Objects.equals(fileType, "pdfs")) { fileDirName = pdfPath + "/" + date.getYear() + "/" + date.getMonthValue() + "/" + inpNo + "_" + visitId; } @@ -94,9 +69,9 @@ public class FileUtils { String fileName = null; if (Objects.equals(fileType, "images")) { - fileName = fileDir + "/" + emrPath + masterId + ".jpg"; + fileName = fileDir + "/" + tempPath + detailId + ".jpg"; } else if (Objects.equals(fileType, "pdfs")) { - fileName = fileDir + "/" + emrPath + masterId + ".pdf"; + fileName = fileDir + "/" + tempPath + detailId + ".pdf"; } localFile = new File(fileName); @@ -116,7 +91,7 @@ public class FileUtils { LocalDate date = LocalDate.now(); String fileDirName = null; if (Objects.equals(fileType, "images")) { - fileDirName = "Z:/images/" + date.getYear() + "/" + date.getMonthValue() + "/" + inpNo + "_" + visitId; + fileDirName = imagePath+"/" + date.getYear() + "/" + date.getMonthValue() + "/" + inpNo + "_" + visitId; } else if (Objects.equals(fileType, "pdfs")) { fileDirName = pdfPath + "/" + date.getYear() + "/" + date.getMonthValue() + "/" + inpNo + "_" + visitId; } diff --git a/src/main/java/com/ann/utils/FtpUtils.java b/src/main/java/com/ann/utils/FtpUtils.java index 1022263..46247c7 100644 --- a/src/main/java/com/ann/utils/FtpUtils.java +++ b/src/main/java/com/ann/utils/FtpUtils.java @@ -38,41 +38,5 @@ public class FtpUtils { return ftp; } - - /* public static boolean downloadFtp(String path, FtpClient ftp, File file) throws IOException, FtpProtocolException { - InputStream is = null; - FileOutputStream fos = null; - boolean result = false; - try { - - is = ftp.getFileStream(path); - // is - byte[] bytes = new byte[1024]; - int i; - fos = new FileOutputStream(file); - while((i = is.read(bytes)) != -1){ - fos.write(bytes, 0, i); - } - result = true; - } catch (Exception e) { - FileUtils.deleteImageFile(file); - logger.error("出错咯!错误信息:"+e); - throw e; - } finally { - try { - if(fos!=null) { - fos.close(); - } - if(is!=null){ - is.close(); - } - } catch (IOException e) { - FileUtils.deleteImageFile(file); - logger.error("出错咯!错误信息:"+e); - throw e; - } - } - return result; - }*/ } diff --git a/src/main/java/com/ann/utils/JSchUtils.java b/src/main/java/com/ann/utils/JSchUtils.java index 0a3b74a..139ccbd 100644 --- a/src/main/java/com/ann/utils/JSchUtils.java +++ b/src/main/java/com/ann/utils/JSchUtils.java @@ -70,60 +70,6 @@ public class JSchUtils { } } - /** - * 执行相关的命令, - * 但是部分情况不可用 - * - * @throws JSchException - */ - public static void execCmd(String command) throws JSchException { - BufferedReader reader = null; - - try { - if (command != null) { - channel = session.openChannel("exec"); - ((ChannelExec) channel).setCommand(command); - // ((ChannelExec) channel).setErrStream(System.err); - channel.connect(); - - InputStream in = channel.getInputStream(); - reader = new BufferedReader(new InputStreamReader(in)); - String buf = null; - while ((buf = reader.readLine()) != null) { - logger.info(buf); - } - } - } catch (IOException e) { - e.printStackTrace(); - } catch (JSchException e) { - e.printStackTrace(); - } finally { - try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - } - channel.disconnect(); - } - } - - /** - * 上传文件 - * - * @param directory 上传的目录 - * @param uploadFile 要上传的文件 - * @throws JSchException - * @throws SftpException - * @throws FileNotFoundException - */ - public static void upload(String directory, String uploadFile) throws Exception { - ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp"); - channelSftp.cd(directory); - File file = new File(uploadFile); - channelSftp.put(new FileInputStream(file), file.getName()); - logger.info("上传: " + uploadFile + "成功!"); - } - /** * 下载文件 * @@ -142,19 +88,6 @@ public class JSchUtils { } - /** - * 列出目录下的文件 - * - * @param directory 要列出的目录 - * @return - * @throws SftpException - * @throws JSchException - */ - @SuppressWarnings("rawtypes") - public Vector listFiles(String directory) throws Exception { - ChannelSftp channelSftp = (ChannelSftp) session.openChannel("sftp"); - return channelSftp.ls(directory); - } public static void main(String[] args) { try { diff --git a/src/main/java/com/ann/utils/SFTPUtil.java b/src/main/java/com/ann/utils/SFTPUtil.java deleted file mode 100644 index f7fb3d8..0000000 --- a/src/main/java/com/ann/utils/SFTPUtil.java +++ /dev/null @@ -1,224 +0,0 @@ -package com.ann.utils; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; -import java.util.Vector; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import com.jcraft.jsch.*; -import org.apache.commons.io.IOUtils; -import org.apache.commons.net.ftp.FTP; -import org.apache.commons.net.ftp.FTPClient; -import org.apache.commons.net.ftp.FTPFile; -import org.apache.commons.net.ftp.FTPReply; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @Author: LeiJiaXin - * @Date: 2019/9/2 11:19 - */ -public class SFTPUtil { - private transient Logger log = LoggerFactory.getLogger(this.getClass()); - - private ChannelSftp sftp; - - private Session session; - /** - * SFTP 登录用户名 - */ - private String username; - /** - * SFTP 登录密码 - */ - private String password; - /** - * 私钥 - */ - private String privateKey; - /** - * SFTP 服务器地址IP地址 - */ - private String host; - /** - * SFTP 端口 - */ - private int port; - - - /** - * 构造基于密码认证的sftp对象 - */ - public SFTPUtil(String username, String password, String host, int port) { - this.username = username; - this.password = password; - this.host = host; - this.port = port; - } - - /** - * 构造基于秘钥认证的sftp对象 - */ - public SFTPUtil(String username, String host, int port, String privateKey) { - this.username = username; - this.host = host; - this.port = port; - this.privateKey = privateKey; - } - - public SFTPUtil() { - } - - - /** - * 连接sftp服务器 - */ - public void login() { - try { - JSch jsch = new JSch(); - if (privateKey != null) { - jsch.addIdentity(privateKey);// 设置私钥 - } - - session = jsch.getSession(username, host, port); - - if (password != null) { - session.setPassword(password); - } - Properties config = new Properties(); - config.put("StrictHostKeyChecking", "no"); - - session.setConfig(config); - session.connect(); - - Channel channel = session.openChannel("sftp"); - channel.connect(); - - sftp = (ChannelSftp) channel; - } catch (JSchException e) { - e.printStackTrace(); - } - } - - /** - * 关闭连接 server - */ - public void logout() { - if (sftp != null) { - if (sftp.isConnected()) { - sftp.disconnect(); - } - } - if (session != null) { - if (session.isConnected()) { - session.disconnect(); - } - } - } - - - /** - * 将输入流的数据上传到sftp作为文件。文件完整路径=basePath+directory - * - * @param basePath 服务器的基础路径 - * @param directory 上传到该目录 - * @param sftpFileName sftp端文件名 - */ - public void upload(String basePath, String directory, String sftpFileName, InputStream input) throws SftpException { - try { - sftp.cd(basePath); - sftp.cd(directory); - } catch (SftpException e) { - //目录不存在,则创建文件夹 - String[] dirs = directory.split("/"); - String tempPath = basePath; - for (String dir : dirs) { - if (null == dir || "".equals(dir)) continue; - tempPath += "/" + dir; - try { - sftp.cd(tempPath); - } catch (SftpException ex) { - sftp.mkdir(tempPath); - sftp.cd(tempPath); - } - } - } - sftp.put(input, sftpFileName); //上传文件 - } - - - /** - * 下载文件。 - * - * @param directory 下载目录 - * @param downloadFile 下载的文件 - * @param saveFile 存在本地的路径 - */ - public void download(String directory, String downloadFile, File saveFile) throws SftpException, FileNotFoundException { - if (directory != null && !"".equals(directory)) { - sftp.cd(directory); - } - sftp.get(downloadFile, new FileOutputStream(saveFile)); - } - - /** - * 下载文件 - * - * @param directory 下载目录 - * @param downloadFile 下载的文件名 - * @return 字节数组 - */ - public byte[] download(String directory, String downloadFile) throws SftpException, IOException { - if (directory != null && !"".equals(directory)) { - sftp.cd(directory); - } - InputStream is = sftp.get(downloadFile); - - byte[] fileData = IOUtils.toByteArray(is); - - return fileData; - } - - - /** - * 删除文件 - * - * @param directory 要删除文件所在目录 - * @param deleteFile 要删除的文件 - */ - public void delete(String directory, String deleteFile) throws SftpException { - sftp.cd(directory); - sftp.rm(deleteFile); - } - - - /** - * 列出目录下的文件 - * - * @param directory 要列出的目录 - */ - public Vector listFiles(String directory) throws SftpException { - return sftp.ls(directory); - } - - //上传文件测试 - public static void main(String[] args) throws SftpException, IOException { - SFTPUtil sftp = new SFTPUtil("用户名", "密码", "ip地址", 22); - sftp.login(); - File file = new File("D:\\图片\\t0124dd095ceb042322.jpg"); - InputStream is = new FileInputStream(file); - - sftp.upload("基础路径", "文件路径", "test_sftp.jpg", is); - sftp.logout(); - } -} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index cc5fbc6..1613273 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,7 +11,7 @@ spring: # hibernate: # ddl-auto: update url: jdbc:sqlserver://10.6.1.127:1433;DatabaseName=DB_PrivilegeManagement_GYFY - # url: jdbc:sqlserver://120.27.212.36:1433;DatabaseName=emr_record + # url: jdbc:sqlserver://120.27.212.36:1433;DatabaseName=emr_record username: sa password: docus@702 driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver @@ -50,7 +50,8 @@ file: dischargeRecordPath: D:\\1\dischargeRecord.properties transferRecordPath: D:\\1\transferRecord.properties admissionRecordPath: D:\\1\admissionRecord.properties - pdfPath: D:/project_js + pdfPath: Z:/project_js + imagePath: Z:/images signContent: 0