diff --git a/dataConfig/RequestParams.xml b/dataConfig/RequestParams.xml index 20aaaed..f99acf7 100644 --- a/dataConfig/RequestParams.xml +++ b/dataConfig/RequestParams.xml @@ -30,7 +30,7 @@ - 1123 + 20211213 20211222 diff --git a/dataConfig/homeQualitySet.json b/dataConfig/homeQualitySet.json index abb59b1..7d0384e 100644 --- a/dataConfig/homeQualitySet.json +++ b/dataConfig/homeQualitySet.json @@ -1,6 +1,10 @@ { //唯一键目录结构数组,最高层为前面,最后一层为数据采集层,根节点不填 "directory":["Msg","ReportInfo"], + //配置pacs补偿采集间隔天数 + "intervalDay":3, + //pacs补偿采集开关 1:开启 0:关闭 + "intervalDayOpen":1, //患者主索引号 "indexFlag":"就诊号", //采集流水号 @@ -9,6 +13,8 @@ "filetitle":"文书名", //下载地址 "downurl":"WEB_ADDRESS", + //时间格式 + "dateFormat": "yyyy-MM-dd HH:mm:ss", //分类id "assortid":"15E7FE7803F545CB81390BC88E725240", //过滤报告单,多个用逗号隔开 @@ -50,9 +56,9 @@ //oracle时间配置 "collectTimeName":"ARCHIVE_DATE_TIME", //批量按需采集开始时间 - "collectStartDate": "2021-01-01", + "collectStartDate": "2022-09-20", //批量按需采集结束时间 - "collectEndDate": "2022-04-01", + "collectEndDate": "2022-09-20", //批量按需采集开关 1:开启 0:关闭 "collectOpen": "1", //校验完整性方式 1:根据af_collect_task完成情况 2:梅州根据信息科提供任务视图 diff --git a/src/main/java/com/docus/bgts/DemoApplication.java b/src/main/java/com/docus/bgts/DemoApplication.java index d5059f8..db8525b 100644 --- a/src/main/java/com/docus/bgts/DemoApplication.java +++ b/src/main/java/com/docus/bgts/DemoApplication.java @@ -3,7 +3,10 @@ package com.docus.bgts; import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; @EnableScheduling @SpringBootApplication(exclude = {MybatisPlusAutoConfiguration.class}) @@ -13,5 +16,11 @@ public class DemoApplication { System.setProperty("javax.xml.parsers.DocumentBuilderFactory","com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); SpringApplication.run(DemoApplication.class, args); } + @Bean + public TaskScheduler taskScheduler() { + ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); + taskScheduler.setPoolSize(3); + return taskScheduler; + } } diff --git a/src/main/java/com/docus/bgts/config/LocalBusFactory.java b/src/main/java/com/docus/bgts/config/LocalBusFactory.java new file mode 100644 index 0000000..9713787 --- /dev/null +++ b/src/main/java/com/docus/bgts/config/LocalBusFactory.java @@ -0,0 +1,25 @@ +package com.docus.bgts.config; + +import org.apache.cxf.Bus; +import org.apache.cxf.BusFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; +import java.util.WeakHashMap; + + +public class LocalBusFactory extends BusFactory { + private static Logger logger = LoggerFactory.getLogger(LocalBusFactory.class); + + @Override + public Bus createBus() { + return null; + } + + public static void printTHREAD_BUSSES(){ + logger.info("THREAD_BUSSES SIZE {}",THREAD_BUSSES.size()); + } + + +} diff --git a/src/main/java/com/docus/bgts/config/MyScheduling.java b/src/main/java/com/docus/bgts/config/MyScheduling.java index ffd383b..ceede10 100644 --- a/src/main/java/com/docus/bgts/config/MyScheduling.java +++ b/src/main/java/com/docus/bgts/config/MyScheduling.java @@ -1,6 +1,8 @@ package com.docus.bgts.config; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.docus.bgts.entity.TableJsonRead; import com.docus.bgts.enums.Codes; @@ -8,17 +10,26 @@ import com.docus.bgts.facade.IBgtsService; import com.docus.bgts.service.CheckIntegrityService; import com.docus.bgts.utils.FileUtils; import com.docus.bgts.utils.HttpUtils; +import io.swagger.models.auth.In; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import javax.annotation.Resource; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; @Component public class MyScheduling { @@ -26,9 +37,9 @@ public class MyScheduling { private String beatUrl; public static String syncFlag; - private final String tempfilePrefix="dataConfig\\temp"; - private final String tempDataFileName="collectTimeTemp"; - private final String lastTimeStr="lastTime"; + private final String tempfilePrefix = "dataConfig\\temp"; + private final String tempDataFileName = "collectTimeTemp"; + private final String lastTimeStr = "lastTime"; // static { // syncFlag=FileUtils.getJsonByName("syncFlag").toString(); @@ -42,8 +53,11 @@ public class MyScheduling { private Logger logger = LogManager.getLogger(MyScheduling.class); + @Autowired + private ThreadPoolExecutor threadPoolExecutor; + //5分钟执行一次心跳 - @Scheduled(fixedRate = 1000 * 60 * 5) + @Scheduled(fixedRate = 1000 * 5) public void beat() { Map params = new HashMap<>(); params.put("code", String.valueOf(FileUtils.getJsonByName("collectorid"))); @@ -56,7 +70,6 @@ public class MyScheduling { } - /** * 手麻/重症采集器 * 10分钟执行一次 @@ -70,22 +83,122 @@ public class MyScheduling { // bgtsService.timerCollect(); // } +// // 时间 +// private static List date = new ArrayList<>(); +// // 上次任务执行时间 +// private static int currentIndex = 0; + + // public static void main(String[] args) throws Exception{ +// MyScheduling myScheduling = new MyScheduling(); +// +// for (int i = 0; i <=50;i++){ +// myScheduling.collectByExamNo(); +// TimeUnit.MILLISECONDS.sleep(500); +// } +// +//// System.out.println(date); +//// System.out.println(currentIndex); +// } +// private static void initDate() throws Exception { +// String configStart = String.valueOf(FileUtils.getJsonByName("collectStartDate")); +// String configEnd = String.valueOf(FileUtils.getJsonByName("collectEndDate")); +// if (StrUtil.isBlank(configStart) || StrUtil.isBlank(configEnd)) { +// throw new RuntimeException("check homeQualitySet.json collectStartDate AND collectEndDate confg!"); +// } +// DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd"); +// LocalDate localDate = LocalDate.parse(configStart, dtf); +// LocalDate end = LocalDate.parse(configEnd); +// while (!localDate.isAfter(end)) { +// date.add(localDate.toString()); +// localDate = localDate.plusDays(1); +// } +// } + + + /** * 批量按需采集 * 10分钟执行一次 */ - @Scheduled(fixedRate = 1000 * 60 *10 ) - public void collectByExamNo(){ - String collectOpen = String.valueOf(FileUtils.getJsonByName("collectOpen")); - if (collectOpen.equals("1")){ - logger.info("按需采集开始----------"); - String collectStartDate = String.valueOf(FileUtils.getJsonByName("collectStartDate")); - String collectEndDate = String.valueOf(FileUtils.getJsonByName("collectEndDate")); +// +// @Scheduled(fixedDelay = 1000 * 60 * 10) +// public void collectByExamNo() { +// String collectOpen = String.valueOf(FileUtils.getJsonByName("collectOpen")); +// if (collectOpen.equals("1")) { +// logger.info("按需采集任务执行----"); +//// if (CollUtil.isEmpty(date)) { +//// try { +//// initDate(); +//// } catch (Exception e) { +//// logger.error(e.getMessage()); +//// return; +//// } +//// } +//// if (currentIndex >= date.size()) { +//// currentIndex = 0; +//// } +//// logger.info("index:{},Thread {}", currentIndex, Thread.currentThread().getName()); +//// String collectStartDate = date.get(currentIndex); +//// String collectEndDate = collectStartDate + "\t23:59:59"; +// String collectStartDate = String.valueOf(FileUtils.getJsonByName("collectStartDate"))+ "\t00:00:00"; +// String collectEndDate = String.valueOf(FileUtils.getJsonByName("collectEndDate"))+ "\t23:59:59"; +// logger.info("按需采集开始----------开始时间---" + collectStartDate + "------结束时间---" + collectEndDate); +// String collectorid = String.valueOf(FileUtils.getJsonByName("collectorid")); +// CountDownLatch countDownLatch = new CountDownLatch(1); +// threadPoolExecutor.execute(() -> { +// bgtsService.collectByDate(collectStartDate, collectEndDate, collectorid); +// countDownLatch.countDown(); +// }); +// try { +// countDownLatch.await(); +// } catch (Exception e) { +// logger.error("JUC countDownLatch error {}", e.getMessage()); +// } +// logger.info("{},采集结束----", collectStartDate); +// currentIndex++; +// System.gc(); +// } +// +// } + + @Scheduled(cron ="0 0 0 * * ?") + public void collect(){ + String intervalDayOpen = String.valueOf(FileUtils.getJsonByName("intervalDayOpen")); + if (intervalDayOpen.equals("1")){ String collectorid = String.valueOf(FileUtils.getJsonByName("collectorid")); - bgtsService.collectByDate(collectStartDate,collectEndDate,collectorid); + int day = Integer.parseInt(String.valueOf(FileUtils.getJsonByName("intervalDay"))); + logger.info("0点采集前"+day+"天出院数据"); + Map dateCollectionTime = getDateCollectionTime(new Date(), day); + logger.info("采集"+dateCollectionTime.get("startDate")+"至-------"+dateCollectionTime.get("endDate")+"数据"); + bgtsService.collectByDate(dateCollectionTime.get("startDate"),dateCollectionTime.get("endDate"),collectorid); } } + + /** + * 获取前x天开始与结束时间 + * + * @param date + * @return + */ + + public static Map getDateCollectionTime(Date date, int day) { + Date dBefore; + Calendar calendar = Calendar.getInstance(); //得到日历 + calendar.setTime(date);//把当前时间赋给日历 + calendar.add(Calendar.DAY_OF_MONTH, -day); //设置为前day天 + dBefore = calendar.getTime(); //得到前一天的时间 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //设置时间格式 + String defaultStartDate = sdf.format(dBefore); //格式化前一天 + defaultStartDate = defaultStartDate + " 00:00:00"; + String defaultEndDate = defaultStartDate.substring(0, 10) + " 23:59:59"; + Map map = new HashMap<>(); + map.put("startDate", defaultStartDate); + map.put("endDate", defaultEndDate); + return map; + } + + /** * 完整性校验 */ diff --git a/src/main/java/com/docus/bgts/config/ThreadPoolConfig.java b/src/main/java/com/docus/bgts/config/ThreadPoolConfig.java new file mode 100644 index 0000000..eba09d5 --- /dev/null +++ b/src/main/java/com/docus/bgts/config/ThreadPoolConfig.java @@ -0,0 +1,32 @@ +package com.docus.bgts.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.concurrent.*; + +@Configuration +public class ThreadPoolConfig { + + @Bean + public ThreadPoolExecutor threadPoolExecutor() { + return new ThreadPoolExecutor( + Runtime.getRuntime().availableProcessors(), + (int) (Runtime.getRuntime().availableProcessors() / (1 - 0.9)), + 60, + TimeUnit.SECONDS, + new LinkedBlockingQueue<>(Runtime.getRuntime().availableProcessors()), + Executors.defaultThreadFactory(), + new ThreadPoolExecutor.CallerRunsPolicy() + ); + + } + + @Bean + public ScheduledThreadPoolExecutor scheduledThreadPoolExecutor() { + return new ScheduledThreadPoolExecutor( + Runtime.getRuntime().availableProcessors(), + Executors.defaultThreadFactory(), + new ThreadPoolExecutor.CallerRunsPolicy()); + } +} diff --git a/src/main/java/com/docus/bgts/controller/BgtsController.java b/src/main/java/com/docus/bgts/controller/BgtsController.java index 5566988..2bd1e7c 100644 --- a/src/main/java/com/docus/bgts/controller/BgtsController.java +++ b/src/main/java/com/docus/bgts/controller/BgtsController.java @@ -78,6 +78,82 @@ public class BgtsController { } return CommonResult.failed(e.getMessage()); } + catch (Exception e) { + e.printStackTrace(); + }catch (Throwable t){ + t.printStackTrace(); + logger.error("throwable,{}", t.getMessage()); + } + return CommonResult.success("ok"); + } + + @ApiOperation("Pacs采集接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "empId",value = "患者主索引号",required = true,dataTypeClass = String.class), + @ApiImplicitParam(name = "collectSubId",value = "af_interface_collect_sub表id",required = true), + @ApiImplicitParam(name = "admissDate",value = "入院时间",required = true), + @ApiImplicitParam(name = "disDate",value = "出院时间",required = true), + @ApiImplicitParam(name = "times",value = "住院次数",required = true) + }) + @GetMapping("/collectPacs") + public CommonResult collect(@RequestParam("collectSubId") String collectSubId, + @RequestParam("empId") String empId, + @RequestParam("admissDate") String admissDate, + @RequestParam("disDate") String disDate, + @RequestParam("times") String times){ + try { + logger.info("采集接口接收到参数:\nempId--"+empId+"\ncollectSubId--"+collectSubId); + bgtsService.collectPacs(empId,admissDate,disDate,times); + logger.info("采集完成"); + afCollectTaskService.updateInterfaceCollect(collectSubId, 1); + logger.info("------------采集结束-----------"); + } catch (RuntimeException e) { + e.printStackTrace(); + try { + afCollectTaskService.updateInterfaceCollect(collectSubId, 0); + }catch (Exception e1) { + logger.info(e1.getMessage()); + return CommonResult.failed(e1.getMessage()); + } + return CommonResult.failed(e.getMessage()); + } + catch (Exception e) { + e.printStackTrace(); + } + return CommonResult.success("ok"); + } + + + @ApiOperation("动态心电采集接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "empId",value = "患者主索引号",required = true,dataTypeClass = String.class), + @ApiImplicitParam(name = "collectSubId",value = "af_interface_collect_sub表id",required = true), + @ApiImplicitParam(name = "admissDate",value = "入院时间",required = true), + @ApiImplicitParam(name = "disDate",value = "出院时间",required = true), + @ApiImplicitParam(name = "times",value = "住院次数",required = true) + }) + @GetMapping("/collectEcg") + public CommonResult collectEcg(@RequestParam("collectSubId") String collectSubId, + @RequestParam("empId") String empId, + @RequestParam("admissDate") String admissDate, + @RequestParam("disDate") String disDate, + @RequestParam("times") String times){ + try { + logger.info("采集接口接收到参数:\nempId--"+empId+"\ncollectSubId--"+collectSubId); + bgtsService.collectEcg(empId,admissDate,disDate,times); + logger.info("采集完成"); + afCollectTaskService.updateInterfaceCollect(collectSubId, 1); + logger.info("------------采集结束-----------"); + } catch (RuntimeException e) { + e.printStackTrace(); + try { + afCollectTaskService.updateInterfaceCollect(collectSubId, 0); + }catch (Exception e1) { + logger.info(e1.getMessage()); + return CommonResult.failed(e1.getMessage()); + } + return CommonResult.failed(e.getMessage()); + } catch (Exception e) { e.printStackTrace(); } @@ -125,5 +201,23 @@ public class BgtsController { return CommonResult.success("ok"); } + /** + * pacs按需采集 + */ + @ApiOperation("pacs按需采集接口") + @GetMapping("/collectByPacs") + public CommonResult collectByPacs(){ + try{ + bgtsService.collectPacss(); + }catch (Exception e){ + e.printStackTrace(); + return CommonResult.failed(e.getMessage()); + } + return CommonResult.success("ok"); + } + + + + } diff --git a/src/main/java/com/docus/bgts/entity/ReportDownPatientDto.java b/src/main/java/com/docus/bgts/entity/ReportDownPatientDto.java index 8509d86..0d0f4c0 100644 --- a/src/main/java/com/docus/bgts/entity/ReportDownPatientDto.java +++ b/src/main/java/com/docus/bgts/entity/ReportDownPatientDto.java @@ -7,4 +7,8 @@ import lombok.Data; public class ReportDownPatientDto { @ApiModelProperty(value = "记帐号") private String jzh; + @ApiModelProperty(value = "住院号") + private String inPatientNo; + @ApiModelProperty(value = "住院次数") + private String visitId; } diff --git a/src/main/java/com/docus/bgts/facade/IAfCollectTaskService.java b/src/main/java/com/docus/bgts/facade/IAfCollectTaskService.java index 258e369..93ddf7f 100644 --- a/src/main/java/com/docus/bgts/facade/IAfCollectTaskService.java +++ b/src/main/java/com/docus/bgts/facade/IAfCollectTaskService.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.docus.bgts.entity.AfCollectTask; import com.docus.bgts.entity.ReportDownDto; import org.apache.ibatis.annotations.Param; +import org.springframework.web.bind.annotation.RequestParam; import java.util.List; import java.util.Map; @@ -25,6 +26,14 @@ public interface IAfCollectTaskService extends IService { void insert(ReportDownDto reportDownDto); + String getJzhByInpatientNo(String inPatientNo,String visitId); + /** + * 查询数据库是否存在该jzh患者 + */ + String getJzhByJzh(String jzh); + + void insertServer(ReportDownDto reportDownDto); + void updateInterfaceCollect(String collectSubId, int state); /** @@ -33,7 +42,7 @@ public interface IAfCollectTaskService extends IService { * @param endDate 结束日期 * @return */ - List getjzhByDate(String startDate,String endDate); + List getjzhByDate(String startDate,String endDate,int size,int current); /** * 通过记帐号获取唯一报告单号 @@ -56,6 +65,12 @@ public interface IAfCollectTaskService extends IService { */ List getJzhByPatientId(List patientIds); + /** + * 通过住院号和住院次数获取patient_id + */ + + String getPatientIdByInpatientNo(String inPatientNo,String visitId); + /** * 根据jzh集合查询文件采集任务情况 * @param jzhs diff --git a/src/main/java/com/docus/bgts/facade/IBgtsService.java b/src/main/java/com/docus/bgts/facade/IBgtsService.java index e8343b7..dae734c 100644 --- a/src/main/java/com/docus/bgts/facade/IBgtsService.java +++ b/src/main/java/com/docus/bgts/facade/IBgtsService.java @@ -6,6 +6,11 @@ public interface IBgtsService { */ void collect(String empId) throws Exception; + void collectPacs(String empId,String admissDate,String disDate,String times) throws Exception; + + void collectEcg(String empId,String admissDate,String disDate,String times) throws Exception; + + void collectPacss(); /** * 按需采集 * @param emamNo diff --git a/src/main/java/com/docus/bgts/mapper/dbmysql/AfCollectAddMapper.java b/src/main/java/com/docus/bgts/mapper/dbmysql/AfCollectAddMapper.java index b65cc76..94a99ed 100644 --- a/src/main/java/com/docus/bgts/mapper/dbmysql/AfCollectAddMapper.java +++ b/src/main/java/com/docus/bgts/mapper/dbmysql/AfCollectAddMapper.java @@ -24,6 +24,12 @@ public interface AfCollectAddMapper extends BaseMapper { */ List listJzh(@Param("pageNumber") int pageNumber,@Param("pageSize") Integer pageSize); + /** + * 根据jzh查询出入院时间 + * @param jzh + * @return + */ + Map selectDate(@Param("jzh") String jzh); /** * 数据完整性校验 * @param mzSyncs diff --git a/src/main/java/com/docus/bgts/mapper/dbmysql/AfCollectTaskMapper.java b/src/main/java/com/docus/bgts/mapper/dbmysql/AfCollectTaskMapper.java index ab0c11e..990b407 100644 --- a/src/main/java/com/docus/bgts/mapper/dbmysql/AfCollectTaskMapper.java +++ b/src/main/java/com/docus/bgts/mapper/dbmysql/AfCollectTaskMapper.java @@ -5,8 +5,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.docus.bgts.entity.AfCollectTask; import com.docus.bgts.entity.JzhListSync; import org.apache.ibatis.annotations.Param; +import org.springframework.web.bind.annotation.RequestParam; import java.util.List; +import java.util.Map; /** *

@@ -24,14 +26,18 @@ public interface AfCollectTaskMapper extends BaseMapper { */ String getpatientIdByEmpId(@Param("jzh") String empId); + String getPatientIdByInpatientNo(@Param("inPatientNo") String inPatientNo,@Param("visitId") String visitId); + String getJzhByInpatientNo(@Param("inPatientNo") String inPatientNo,@Param("visitId") String visitId); + + String getJzhByJzh(@Param("jzh") String jzh); /** * 通过出院日期获取患者jzh * @param startDate 开始日期 * @param endDate 结束日期 * @return */ - List getjzhByDate(@Param("startDate") String startDate,@Param("endDate") String endDate); + List getjzhByDate(@Param("startDate") String startDate, @Param("endDate") String endDate, @RequestParam("size") int size, @RequestParam("current") int current); /** * 通过记帐号与采集器编号获取唯一报告单号 diff --git a/src/main/java/com/docus/bgts/service/AfCollectTaskServiceImpl.java b/src/main/java/com/docus/bgts/service/AfCollectTaskServiceImpl.java index 3f5c85d..36d1784 100644 --- a/src/main/java/com/docus/bgts/service/AfCollectTaskServiceImpl.java +++ b/src/main/java/com/docus/bgts/service/AfCollectTaskServiceImpl.java @@ -51,8 +51,76 @@ public class AfCollectTaskServiceImpl extends ServiceImpl scanfiles = reportDownDto.getScanfiles(); + for (ReportDownScanFileDto scanfile : scanfiles) { + // 判断任务是否已存在 + afCollectTask = afCollectTaskMapper.selectOne(new QueryWrapper().eq("C1", scanfile.getSerialnum()).eq("sysflag", reportDownDto.getCollectorid())); + if (afCollectTask == null) { + //不存在 新增 + afCollectTask = new AfCollectTask(); + afCollectTask.setPatientId(patientId); + afCollectTask.setSysflag(reportDownDto.getCollectorid()); + afCollectTask.setState("0"); + afCollectTask.setSyncTime(date); + afCollectTask.setC1(scanfile.getSerialnum()); + afCollectTask.setC2(scanfile.getFiletitle()); + afCollectTask.setC3(reportDownDto.getPatient().getJzh()); + save = afCollectTaskMapper.insert(afCollectTask); + if (save <= 0) { + throw new RuntimeException("插入病案任务表数据出错"); + } else { + log.warn("插入病案成功"); + } + + } else { + //存在就修改 + afCollectTask.setPatientId(patientId); + afCollectTask.setSysflag(reportDownDto.getCollectorid()); + afCollectTask.setState("0"); + afCollectTask.setSyncTime(date); + afCollectTask.setC1(scanfile.getSerialnum()); + afCollectTask.setC2(scanfile.getFiletitle()); + save = afCollectTaskMapper.updateById(afCollectTask); + log.warn("修改病案成功"); + } + scanfile.setTaskid(afCollectTask.getId()); + } + reportDownDto.setScanfiles(scanfiles); + } catch (Exception e) { + log.error(reportDownDto.getPatient().getJzh() + "插入任务表出错! " + e.getMessage()); + } + } + } + + @Override + public String getJzhByInpatientNo(String inPatientNo, String visitId) { + return afCollectTaskMapper.getJzhByInpatientNo(inPatientNo,visitId); + } + + @Override + public String getJzhByJzh(String jzh) { + return afCollectTaskMapper.getJzhByJzh(jzh); + } + + @Override + public void insertServer(ReportDownDto reportDownDto) { + synchronized (this) { + String patientId; AfCollectTask afCollectTask; - String patientId = getpatientIdByEmpId(reportDownDto.getPatient().getJzh()); + if (StringUtils.isBlank(reportDownDto.getPatient().getJzh())) { + patientId = getPatientIdByInpatientNo(reportDownDto.getPatient().getInPatientNo(), reportDownDto.getPatient().getVisitId()); + } else { + patientId = getpatientIdByEmpId(reportDownDto.getPatient().getJzh()); + } if (StringUtils.isBlank(patientId)) { throw new RuntimeException("操作的病案信息不存在"); } @@ -75,7 +143,7 @@ public class AfCollectTaskServiceImpl extends ServiceImpl getjzhByDate(String startDate, String endDate) { - List patientIds = afCollectTaskMapper.getjzhByDate(startDate, endDate); + public List getjzhByDate(String startDate, String endDate,int size,int current) { + List patientIds = afCollectTaskMapper.getjzhByDate(startDate, endDate,size,current); return patientIds; } @@ -174,6 +243,11 @@ public class AfCollectTaskServiceImpl extends ServiceImpl exams = new ArrayList<>(); + //通过empId获取报告单号集合 + if (collectorid.equals("14")){ + exams = getExamNoNj(empId); + }else { + exams = getExamNo(empId); + } + + + //获取插入表数据 + ReportDownDto reportDownDto = getUrlCreateReportDto(exams, empId); + //插入文件af_collect_task表数据 + afCollectTaskService.insert(reportDownDto); + //通过报告单号集合采集 + collectExams(exams, empId, reportDownDto); + } + + + + @Override + public void collectPacs(String empId, String admissDate, String disDate, String times) throws Exception { + SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd"); + Date ad = sim.parse(admissDate); + Date di = sim.parse(disDate); + String admiss = sim.format(ad); + String dis = sim.format(di); + //通过empId获取报告单号集合 + List exams = getExamNo(empId, admiss, dis); + String jzh = afCollectTaskService.getJzhByInpatientNo(empId,times); + if (null == jzh) { + logger.info("通过住院号与住院次数未匹配到患者"); + return; + } + //获取插入表数据 + ReportDownDto reportDownDto = getUrlCreateReportDto(exams, jzh); + //插入文件af_collect_task表数据 + afCollectTaskService.insert(reportDownDto); + //通过报告单号集合采集 + collectExams(exams, empId, reportDownDto); + } + + @Override + public void collectEcg(String empId, String admissDate, String disDate, String times) throws Exception { + Map smCollectionTime = getSmCollectionTimeEcg(admissDate, disDate); //通过empId获取报告单号集合 - List exams = getExamNo(empId); + List exams = getExamNoEcg(empId, smCollectionTime.get("admissDate"), smCollectionTime.get("disDate")); + String jzh = afCollectTaskService.getpatientIdByEmpId(empId); + if (null == jzh) { + logger.info(empId+" 通过jzh未匹配到患者"); + return; + } //获取插入表数据 ReportDownDto reportDownDto = getUrlCreateReportDto(exams, empId); //插入文件af_collect_task表数据 @@ -73,6 +133,7 @@ public class BgtsServiceImpl implements IBgtsService { collectExams(exams, empId, reportDownDto); } + @Override public void collectByExamNo(String emamNo, String empId) throws Exception { String[] strings = new String[2]; @@ -112,99 +173,6 @@ public class BgtsServiceImpl implements IBgtsService { * @param startDate * @param endDate */ - private void collectByDates(String startDate, String endDate) { - //页码 - int current; - //每页10条数据 - int size; - String collectorid = String.valueOf(FileUtils.getJsonByName("collectorid")); - String assortid = String.valueOf(FileUtils.getJsonByName("assortid")); - int filesource = Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filesource"))); - int filestoragetype = Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filestoragetype"))); - Map headMap = new HashMap<>(); - headMap.put("Content-Type", "application/json"); - SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0); - String indexFlag = String.valueOf(FileUtils.getJsonByName("indexFlag")); - String serialnum = String.valueOf(FileUtils.getJsonByName("serialnum")); - String filetitle = String.valueOf(FileUtils.getJsonByName("filetitle")); - String downurl = String.valueOf(FileUtils.getJsonByName("downurl")); - List fieldArr = new ArrayList<>(); - fieldArr.add(indexFlag); - fieldArr.add(serialnum); - if (StringUtils.isNotBlank(filetitle)) { - fieldArr.add(filetitle); - } - fieldArr.add(downurl); - String namespace = String.valueOf(FileUtils.getJsonByName("namespace")); - String tableName = String.valueOf(FileUtils.getJsonByName("tableName")); - String collectTimeName = String.valueOf(FileUtils.getJsonByName("collectTimeName")); - List maps; - //2.获取第一页10条数据开始采集 - for (current = 1; ; current++) { - size = 10 * current; - maps = vDocumentPdfMapper.listCollectPage(size - 10, size, startDate, endDate, namespace, tableName, fieldArr, collectTimeName); - logger.info("处理采集数据:" + maps); - if (null == maps || maps.size() <= 0) { - break; - } - maps: - for (Map map : maps) { - //获取过滤报告单 - String[] filterReports = String.valueOf(FileUtils.getJsonByName("filterReport")).split(","); - if (filterReports.length > 0) { - for (String filterReport : filterReports) { - //需要过滤的报告单存在则不采集 - if (String.valueOf(map.get(filetitle)).equals(filterReport)) { - continue maps; - } - } - } - ReportDownDto reportDownDto = new ReportDownDto(); - reportDownDto.setCollectorid(collectorid); - reportDownDto.setAssortid(assortid); - ReportDownPatientDto reportDownPatientDto = new ReportDownPatientDto(); - reportDownPatientDto.setJzh(String.valueOf(map.get(indexFlag))); - reportDownDto.setPatient(reportDownPatientDto); - - List reportDownScanFileDtos = new ArrayList<>(); - ReportDownScanFileDto reportDownScanFileDto = new ReportDownScanFileDto(); - reportDownScanFileDto.setDownurl(String.valueOf(map.get(downurl))); - reportDownScanFileDto.setFilestoragetype(filestoragetype); - reportDownScanFileDto.setFilesource(filesource); - reportDownScanFileDto.setFiletitle(map.get(filetitle) == null ? "重症" + (System.currentTimeMillis()) : String.valueOf(map.get(filetitle))); - reportDownScanFileDto.setSerialnum(StringUtils.isNotBlank(String.valueOf(map.get(serialnum))) ? String.valueOf(map.get(serialnum)) : String.valueOf(idWorker.nextId())); - reportDownScanFileDtos.add(reportDownScanFileDto); - reportDownDto.setScanfiles(reportDownScanFileDtos); - String post; - try { - afCollectTaskService.insert(reportDownDto); - //String uploadConnector = String.valueOf(FileUtils.getJsonByName("uploadConnector")); - //调用下载接口 - post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), headMap, JSON.parseObject(JSON.toJSONString(reportDownDto), Map.class)); - Map resMap = JSON.parseObject(post, Map.class); - logger.info(reportDownDto); - if (String.valueOf(resMap.get("code")).equals("500")) { - throw new RuntimeException(String.valueOf(resMap.get("msg"))); - } - } catch (Exception e) { - //打印错误日志 - logger.info("采集出错:" + reportDownDto); - logger.info(e); - String stackTrace = ExceptionUtils.getStackTrace(e); - logger.info("错误信息----------" + stackTrace); - addMrReportErrorLog(reportDownDto); - e.printStackTrace(); - } - } - } - } - - /** - * 根据时间到采集任务 重症 - * - * @param startDate - * @param endDate - */ // private void collectByDates(String startDate, String endDate) { // //页码 // int current; @@ -219,33 +187,42 @@ public class BgtsServiceImpl implements IBgtsService { // SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0); // String indexFlag = String.valueOf(FileUtils.getJsonByName("indexFlag")); // String serialnum = String.valueOf(FileUtils.getJsonByName("serialnum")); -// //String filetitle = String.valueOf(FileUtils.getJsonByName("filetitle")); +// String filetitle = String.valueOf(FileUtils.getJsonByName("filetitle")); // String downurl = String.valueOf(FileUtils.getJsonByName("downurl")); -// List fieldArr=new ArrayList<>(); +// List fieldArr = new ArrayList<>(); // fieldArr.add(indexFlag); // fieldArr.add(serialnum); -//// if(StringUtils.isNotBlank(filetitle)){ -//// fieldArr.add(filetitle); -//// } +// if (StringUtils.isNotBlank(filetitle)) { +// fieldArr.add(filetitle); +// } // fieldArr.add(downurl); // String namespace = String.valueOf(FileUtils.getJsonByName("namespace")); // String tableName = String.valueOf(FileUtils.getJsonByName("tableName")); // String collectTimeName = String.valueOf(FileUtils.getJsonByName("collectTimeName")); // List maps; // //2.获取第一页10条数据开始采集 -// logger.info("开始时间-----"+startDate+"结束时间-----"+"\n"+endDate); // for (current = 1; ; current++) { // size = 10 * current; -// maps = vDocumentPdfMapper.listCollectPage(size-10, size, startDate, endDate, namespace, tableName, fieldArr, collectTimeName); -// logger.info("处理采集数据:"+maps); +// maps = vDocumentPdfMapper.listCollectPage(size - 10, size, startDate, endDate, namespace, tableName, fieldArr, collectTimeName); +// logger.info("处理采集数据:" + maps); // if (null == maps || maps.size() <= 0) { // break; // } -// maps.stream().forEach(map -> { +// maps: +// for (Map map : maps) { +// //获取过滤报告单 +// String[] filterReports = String.valueOf(FileUtils.getJsonByName("filterReport")).split(","); +// if (filterReports.length > 0) { +// for (String filterReport : filterReports) { +// //需要过滤的报告单存在则不采集 +// if (String.valueOf(map.get(filetitle)).equals(filterReport)) { +// continue maps; +// } +// } +// } // ReportDownDto reportDownDto = new ReportDownDto(); // reportDownDto.setCollectorid(collectorid); // reportDownDto.setAssortid(assortid); -// // ReportDownPatientDto reportDownPatientDto = new ReportDownPatientDto(); // reportDownPatientDto.setJzh(String.valueOf(map.get(indexFlag))); // reportDownDto.setPatient(reportDownPatientDto); @@ -255,15 +232,15 @@ public class BgtsServiceImpl implements IBgtsService { // reportDownScanFileDto.setDownurl(String.valueOf(map.get(downurl))); // reportDownScanFileDto.setFilestoragetype(filestoragetype); // reportDownScanFileDto.setFilesource(filesource); -// //reportDownScanFileDto.setFiletitle(map.get(filetitle)==null?"重症"+(System.currentTimeMillis()):String.valueOf(map.get(filetitle))); -// reportDownScanFileDto.setFiletitle(StringUtils.isNotBlank(String.valueOf(map.get(serialnum)))?String.valueOf(map.get(serialnum)):String.valueOf(idWorker.nextId())); -// reportDownScanFileDto.setSerialnum(StringUtils.isNotBlank(String.valueOf(map.get(serialnum)))?String.valueOf(map.get(serialnum)):String.valueOf(idWorker.nextId())); +// reportDownScanFileDto.setFiletitle(map.get(filetitle) == null ? "重症" + (System.currentTimeMillis()) : String.valueOf(map.get(filetitle))); +// reportDownScanFileDto.setSerialnum(StringUtils.isNotBlank(String.valueOf(map.get(serialnum))) ? String.valueOf(map.get(serialnum)) : String.valueOf(idWorker.nextId())); // reportDownScanFileDtos.add(reportDownScanFileDto); // reportDownDto.setScanfiles(reportDownScanFileDtos); // String post; // try { // afCollectTaskService.insert(reportDownDto); // //String uploadConnector = String.valueOf(FileUtils.getJsonByName("uploadConnector")); +// //调用下载接口 // post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), headMap, JSON.parseObject(JSON.toJSONString(reportDownDto), Map.class)); // Map resMap = JSON.parseObject(post, Map.class); // logger.info(reportDownDto); @@ -272,16 +249,181 @@ public class BgtsServiceImpl implements IBgtsService { // } // } catch (Exception e) { // //打印错误日志 -// logger.info("采集出错:"+reportDownDto); +// logger.info("采集出错:" + reportDownDto); // logger.info(e); // String stackTrace = ExceptionUtils.getStackTrace(e); -// logger.info("错误信息----------"+stackTrace); +// logger.info("错误信息----------" + stackTrace); // addMrReportErrorLog(reportDownDto); // e.printStackTrace(); // } -// }); +// } // } // } + // 时间 + private static List date = new ArrayList<>(); + // 上次任务执行时间 + private static int currentIndex = 0; + + private static void initDate() throws Exception { + String configStart = String.valueOf(FileUtils.getJsonByName("collectStartDate")); + String configEnd = String.valueOf(FileUtils.getJsonByName("collectEndDate")); + if (StrUtil.isBlank(configStart) || StrUtil.isBlank(configEnd)) { + throw new RuntimeException("check homeQualitySet.json collectStartDate AND collectEndDate confg!"); + } + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate localDate = LocalDate.parse(configStart, dtf); + LocalDate end = LocalDate.parse(configEnd); + while (!localDate.isAfter(end)) { + date.add(localDate.toString()); + localDate = localDate.plusDays(1); + } + } + + + public void collectPacss(){ + logger.info("按需采集任务执行----"); +// if (CollUtil.isEmpty(date)) { +// try { +// initDate(); +// } catch (Exception e) { +// logger.error(e.getMessage()); +// return; +// } +// } +// if (currentIndex >= date.size()) { +// currentIndex = 0; +// } + logger.info("index:{},Thread {}", currentIndex, Thread.currentThread().getName()); +// String collectStartDate = date.get(currentIndex); +// String collectEndDate = collectStartDate + "\t23:59:59"; + String collectStartDate = String.valueOf(FileUtils.getJsonByName("collectStartDate"))+"\t00:00:00"; + String collectEndDate = String.valueOf(FileUtils.getJsonByName("collectEndDate"))+"\t23:59:59"; + String collectorid = String.valueOf(FileUtils.getJsonByName("collectorid")); + CountDownLatch countDownLatch = new CountDownLatch(1); + threadPoolExecutor.execute(() -> { + try { + collectByDate(collectStartDate, collectEndDate, collectorid); + }catch (Exception e) { + logger.info("按需采集出错{}",e.getMessage()); + } + countDownLatch.countDown(); + }); + try { + countDownLatch.await(); + } catch (Exception e) { + logger.error("JUC countDownLatch error {}", e.getMessage()); + } + logger.info("{},采集结束----", collectStartDate); + // currentIndex++; + System.gc(); + + } + + + + /** + * 根据时间到采集任务 重症 + * + * @param startDate + * @param endDate + */ + private void collectByDates(String startDate, String endDate) { + //页码 + int current; + //每页10条数据 + int size; + String collectorid = String.valueOf(FileUtils.getJsonByName("collectorid")); + String assortid = String.valueOf(FileUtils.getJsonByName("assortid")); + int filesource = Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filesource"))); + int filestoragetype = Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filestoragetype"))); + Map headMap = new HashMap<>(); + headMap.put("Content-Type", "application/json"); + SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0); + String indexFlag = String.valueOf(FileUtils.getJsonByName("indexFlag")); + String serialnum = String.valueOf(FileUtils.getJsonByName("serialnum")); + //String filetitle = String.valueOf(FileUtils.getJsonByName("filetitle")); + String downurl = String.valueOf(FileUtils.getJsonByName("downurl")); + String inPatientNo = String.valueOf(FileUtils.getJsonByName("inPatientNo")); + String visitId = String.valueOf(FileUtils.getJsonByName("visitId")); + String inJzh = String.valueOf(FileUtils.getJsonByName("jzh")); + + List fieldArr = new ArrayList<>(); + fieldArr.add(indexFlag); + fieldArr.add(serialnum); + fieldArr.add(inPatientNo); + fieldArr.add(visitId); + fieldArr.add(inJzh); +// if(StringUtils.isNotBlank(filetitle)){ +// fieldArr.add(filetitle); +// } + fieldArr.add(downurl); + String namespace = String.valueOf(FileUtils.getJsonByName("namespace")); + String tableName = String.valueOf(FileUtils.getJsonByName("tableName")); + String collectTimeName = String.valueOf(FileUtils.getJsonByName("collectTimeName")); + List maps; + //2.获取第一页10条数据开始采集 + logger.info("开始时间-----" + startDate + "结束时间-----" + "\n" + endDate); + for (current = 1; ; current++) { + size = 10 * current; + maps = vDocumentPdfMapper.listCollectPage(size - 10, size, startDate, endDate, namespace, tableName, fieldArr, collectTimeName); + logger.info("处理采集数据:" + maps); + if (null == maps || maps.size() <= 0) { + break; + } + maps.stream().forEach(map -> { + ReportDownDto reportDownDto = new ReportDownDto(); + reportDownDto.setCollectorid(collectorid); + reportDownDto.setAssortid(assortid); + ReportDownPatientDto reportDownPatientDto = new ReportDownPatientDto(); + if (collectorid.equals("15")){ + reportDownPatientDto.setJzh(String.valueOf(map.get(inJzh))); + }else { + reportDownPatientDto.setInPatientNo(String.valueOf(map.get(inPatientNo))); + reportDownPatientDto.setVisitId(String.valueOf(map.get(visitId))); + } + reportDownDto.setPatient(reportDownPatientDto); + // reportDownPatientDto.setJzh(String.valueOf(map.get(indexFlag))); + List reportDownScanFileDtos = new ArrayList<>(); + ReportDownScanFileDto reportDownScanFileDto = new ReportDownScanFileDto(); + reportDownScanFileDto.setDownurl(String.valueOf(map.get(downurl))); + reportDownScanFileDto.setFilestoragetype(filestoragetype); + reportDownScanFileDto.setFilesource(filesource); + //reportDownScanFileDto.setFiletitle(map.get(filetitle)==null?"重症"+(System.currentTimeMillis()):String.valueOf(map.get(filetitle))); + reportDownScanFileDto.setFiletitle(StringUtils.isNotBlank(String.valueOf(map.get(serialnum))) ? String.valueOf(map.get(serialnum)) : String.valueOf(idWorker.nextId())); + reportDownScanFileDto.setSerialnum(StringUtils.isNotBlank(String.valueOf(map.get(serialnum))) ? String.valueOf(map.get(serialnum)) : String.valueOf(idWorker.nextId())); + reportDownScanFileDtos.add(reportDownScanFileDto); + reportDownDto.setScanfiles(reportDownScanFileDtos); + String post; + try { + afCollectTaskService.insertServer(reportDownDto); + //String uploadConnector = String.valueOf(FileUtils.getJsonByName("uploadConnector")); + String jzh = afCollectTaskService.getJzhByJzh(reportDownDto.getPatient().getJzh()); + if (null != jzh && !("").equals(jzh)) { + reportDownPatientDto.setJzh(jzh); + reportDownDto.setPatient(reportDownPatientDto); + post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), headMap, JSON.parseObject(JSON.toJSONString(reportDownDto), Map.class)); + Map resMap = JSON.parseObject(post, Map.class); + logger.info(reportDownDto.getPatient().getJzh()+" 调用下载参数:--\n"+JSON.parseObject(JSON.toJSONString(reportDownDto))); + if (String.valueOf(resMap.get("code")).equals("500")) { + logger.info(reportDownDto.getPatient().getJzh()+" 下载失败!"); + throw new RuntimeException(String.valueOf(resMap.get("msg"))); + }else { + logger.info(reportDownDto.getPatient().getJzh()+" 下载成功!"); + } + } + + } catch (Exception e) { + //打印错误日志 + logger.info(reportDownDto.getPatient().getJzh()+" 采集出错:" + reportDownDto +e.getMessage()); + // String stackTrace = ExceptionUtils.getStackTrace(e); + // logger.info("错误信息----------"+stackTrace); + addMrReportErrorLog(reportDownDto); + e.printStackTrace(); + } + }); + } + } + @Override public void timerCollect() { logger.info("------采集器开始采集---------"); @@ -289,8 +431,8 @@ public class BgtsServiceImpl implements IBgtsService { //1.获取上次采集时间 Date time; if (collectorid.equals("5")) { - time = afCollectAddMapper.getTimeByAdd(5); - }else { + time = afCollectAddMapper.getTimeByAdd(5); + } else { time = afCollectAddMapper.getTimeByAdd(15); } SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -340,8 +482,9 @@ public class BgtsServiceImpl implements IBgtsService { headMap.put("Content-Type", "application/json"); String post = HttpUtils.post(String.valueOf(FileUtils.getJsonByName(Codes.UPLOAD.getMessage())), headMap, JSON.parseObject(JSON.toJSONString(reportDownDto), Map.class)); Map resMap = JSON.parseObject(post, Map.class); - System.out.println(resMap); + logger.info(empId+": 调用下载Map参数{}",JSON.toJSONString(reportDownDto)); if (String.valueOf(resMap.get("code")).equals("500")) { + logger.info(empId+"调用下载服务错误: "+(resMap.get("msg"))); throw new RuntimeException(String.valueOf(resMap.get("msg"))); } } @@ -367,15 +510,29 @@ public class BgtsServiceImpl implements IBgtsService { int filesource = Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filesource"))); int filestoragetype = Integer.parseInt(String.valueOf(FileUtils.getJsonByName("filestoragetype"))); for (String[] exam : exams) { - reportDownScanFileDto = getScanByExam(exam); - reportDownScanFileDto.setFilesource(filesource); - reportDownScanFileDto.setFilestoragetype(filestoragetype); - reportDownScanFileDtos.add(reportDownScanFileDto); + try { + reportDownScanFileDto = getScanByExam(exam); + reportDownScanFileDto.setFilesource(filesource); + reportDownScanFileDto.setFilestoragetype(filestoragetype); + //过滤pacs中病理报告 + if (collectorid.equals("3")) { + if (!reportDownScanFileDto.getDownurl().contains("病理") + && !reportDownScanFileDto.getDownurl().contains("胃肠镜") + && !reportDownScanFileDto.getDownurl().contains("心电")) { + reportDownScanFileDtos.add(reportDownScanFileDto); + } + }else { + reportDownScanFileDtos.add(reportDownScanFileDto); + } + }catch (Exception e){ + logger.error(exam[0]+"调用明细错误信息-----"+e.getMessage()); + } } reportDownDto.setScanfiles(reportDownScanFileDtos); return reportDownDto; } + /** * 创建ReportDownScanFileDto对象 通过报告单号 * @@ -383,20 +540,26 @@ public class BgtsServiceImpl implements IBgtsService { * @return */ private ReportDownScanFileDto getScanByExam(String[] exam) throws Exception { + String collectorid = String.valueOf(FileUtils.getJsonByName("collectorid")); ReportDownScanFileDto reportDownScanFileDto = new ReportDownScanFileDto(); - reportDownScanFileDto.setSerialnum(exam[0]); + reportDownScanFileDto.setSerialnum(exam[0]); reportDownScanFileDto.setFiletitle(exam[1]); XmlUtils reqXmlUtils = new XmlUtils(FileUtils.getXmlDetailsPath()); Element esbEntry = reqXmlUtils.getMsgElement(); esbEntry.element("EXAM_NO").setText(exam[0]); - String resXml = invokeWs(reqXmlUtils.getDocument().asXML()); + String resXml; logger.info("明细入参------------" + reqXmlUtils.getDocument().asXML()); + if (collectorid.equals("14")) { + resXml = invokeWsNj(reqXmlUtils.getDocument().asXML()); + } else { + resXml = invokeWs(reqXmlUtils.getDocument().asXML()); + } //解析XML XmlUtils xmlUtils = new XmlUtils(new ByteArrayInputStream(resXml.getBytes("UTF-8"))); String success = xmlUtils.isSuccess(); if (!success.equals("ok")) { logger.info("发送错误:" + success); - throw new RuntimeException(success); + throw new RuntimeException("发送错误:" + success); } List dis = (List) FileUtils.getJsonByName("bgtsDetailRespon"); //数据所在节点 @@ -405,6 +568,8 @@ public class BgtsServiceImpl implements IBgtsService { return reportDownScanFileDto; } + + /** * 通过empId获取报告单号集合 * @@ -413,10 +578,223 @@ public class BgtsServiceImpl implements IBgtsService { */ private List getExamNo(String empId) throws Exception { List exams = new ArrayList<>(); + XmlUtils reqXmlUtils = new XmlUtils(FileUtils.getXmlPath()); + Element reqElement = reqXmlUtils.getMsgElement(); + Map map = afCollectAddMapper.selectDate(empId); + reqElement.element("INHOSP_NO").setText(empId); + reqElement.element("BEGIN_DATE").setText(new SimpleDateFormat(FileUtils.getJsonByName("dateFormat").toString()).format(map.get("admiss_date"))); + reqElement.element("END_DATE").setText(new SimpleDateFormat(FileUtils.getJsonByName("dateFormat").toString()).format(map.get("dis_date"))); + logger.info("-------根据患者主索引号查询多个报告单号,地址:" + wsUrl + ",方法:" + wsLocalMethod + "---------"); + String xml = reqXmlUtils.getDocument().asXML(); + logger.info("---------------------------"); + logger.info(xml); + logger.info("----------------------------"); + String resXml = invokeWs(xml); + logger.info("---------返回值-------------"); + logger.info(resXml); + logger.info("-----------------------------"); + //解析XML + XmlUtils xmlUtils = new XmlUtils(new ByteArrayInputStream(resXml.getBytes("UTF-8"))); + String success = xmlUtils.isSuccess(); + if (!success.equals("ok")) { + logger.info("发送错误:" + success); + throw new RuntimeException(success); + } + + List dis = (List) FileUtils.getJsonByName("bgtsRespon"); + //数据所在节点 + Element element = xmlUtils.getElement(dis); + List examInfos = element.elements("ExamInfo"); + Element examNo; + String[] key; + for (Element examInfo : examInfos) { + key = new String[2]; + examNo = examInfo.element(String.valueOf(FileUtils.getJsonByName("examNo"))); + if (examNo != null) { + key[0] = examNo.getText(); + } + Element examItemInfo = examInfo.element("ExamItemInfo"); + if (examItemInfo != null) { + key[1] = examItemInfo.element(String.valueOf(FileUtils.getJsonByName("examItemName"))).getText(); + } + exams.add(key); + } + return exams; + } + /** + * 通过empId获取报告单号集合 + * + * @param empId + * @return + */ + private List getExamNoNj(String empId) throws Exception { + List exams = new ArrayList<>(); XmlUtils reqXmlUtils = new XmlUtils(FileUtils.getXmlPath()); Element reqElement = reqXmlUtils.getMsgElement(); + Map map = afCollectAddMapper.selectDate(empId); reqElement.element("INHOSP_NO").setText(empId); + reqElement.element("BEGIN_DATE").setText(new SimpleDateFormat(FileUtils.getJsonByName("dateFormat").toString()).format(map.get("admiss_date"))); + reqElement.element("END_DATE").setText(new SimpleDateFormat(FileUtils.getJsonByName("dateFormat").toString()).format(map.get("dis_date"))); + logger.info("-------根据患者主索引号查询多个报告单号,地址:" + wsUrl + ",方法:" + wsLocalMethod + "---------"); + String xml = reqXmlUtils.getDocument().asXML(); + logger.info("---------------------------"); + logger.info(xml); + logger.info("----------------------------"); + String resXml = invokeWs(xml); + logger.info("---------返回值-------------"); + logger.info(resXml); + logger.info("-----------------------------"); + //解析XML + XmlUtils xmlUtils = new XmlUtils(new ByteArrayInputStream(resXml.getBytes("UTF-8"))); + String success = xmlUtils.isSuccess(); + if (!success.equals("ok")) { + logger.info("发送错误:" + success); + throw new RuntimeException(success); + } + String examNo; + String[] key; + String examName; + + List dis = (List) FileUtils.getJsonByName("bgtsRespon"); + //数据所在节点 + Element element = xmlUtils.getElement(dis); + List elements = element.elements("Msg"); + for (int i = 0; i < elements.size(); i++) { + List examInfo = elements.get(i).elements("ExamInfo"); + for (int j = 0; j < examInfo.size(); j++) { + examNo = examInfo.get(j).element(String.valueOf(FileUtils.getJsonByName("examNo"))).getText(); + key = new String[2]; + if (examNo != null) { + key[0] = examNo; + } + Element examItemInfo = examInfo.get(j).element("ExamItemInfo"); + if (examItemInfo != null) { + key[1] = examItemInfo.element(String.valueOf(FileUtils.getJsonByName("examItemName"))).getText(); + } + exams.add(key); + logger.info("报告单号---{}",examNo); + + } + } + return exams; + } + + + public static Map getSmCollectionTime(String admissDate, String disDate) { + Date dBefore; + Calendar calendar = Calendar.getInstance(); //得到日历 + Map map = new HashMap<>(); + try { + calendar.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(admissDate));//把当前时间赋给日历 + + calendar.add(Calendar.HOUR, -6); //设置为前6小时 + dBefore = calendar.getTime(); //得到前一天的时间 + Calendar calendar1 = Calendar.getInstance(); //得到日历 + calendar1.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(disDate));//把当前时间赋给日历 + + calendar1.add(Calendar.HOUR, 6); //设置为后6小时 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置时间格式 + String defaultStartDate = sdf.format(dBefore); //格式化前6小时 + String defaultEndDate = sdf.format(calendar1.getTime()); //格式化前6小时 + map.put("admissDate", defaultStartDate); + map.put("disDate", defaultEndDate); + + } catch (ParseException e) { + e.printStackTrace(); + } + return map; + } + + public static Map getSmCollectionTimeEcg(String admissDate, String disDate) { + Date dBefore; + Calendar calendar = Calendar.getInstance(); //得到日历 + Map map = new HashMap<>(); + try { + calendar.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(admissDate));//把当前时间赋给日历 + + calendar.add(Calendar.HOUR, -6); //设置为前6小时 + dBefore = calendar.getTime(); //得到前一天的时间 + Calendar calendar1 = Calendar.getInstance(); //得到日历 + calendar1.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(disDate));//把当前时间赋给日历 + + calendar1.add(Calendar.HOUR, 30); //设置为后30小时 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置时间格式 + String defaultStartDate = sdf.format(dBefore); //格式化前6小时 + String defaultEndDate = sdf.format(calendar1.getTime()); //格式化前6小时 + map.put("admissDate", defaultStartDate); + map.put("disDate", defaultEndDate); + + } catch (ParseException e) { + e.printStackTrace(); + } + return map; + } + + + /** + * 通过empId获取报告单号集合 pacs + * + * @param empId + * @return + */ + private List getExamNo(String empId, String admissDate, String disDate) throws Exception { + List exams = new ArrayList<>(); + // Map Time = getSmCollectionTime(admissDate, disDate); + XmlUtils reqXmlUtils = new XmlUtils(FileUtils.getXmlPath()); + Element reqElement = reqXmlUtils.getMsgElement(); + reqElement.element("INHOSP_INDEX_NO").setText(empId); + reqElement.element("BEGIN_DATE").setText(String.valueOf(admissDate)); + reqElement.element("END_DATE").setText(String.valueOf(disDate)); + logger.info("-------根据患者主索引号查询多个报告单号,地址:" + wsUrl + ",方法:" + wsLocalMethod + "---------"); + String xml = reqXmlUtils.getDocument().asXML(); + logger.info("---------------------------"); + logger.info(xml); + logger.info("----------------------------"); + String resXml = invokeWs(xml); + logger.info("---------返回值-------------"); + logger.info(resXml); + logger.info("-----------------------------"); + //解析XML + XmlUtils xmlUtils = new XmlUtils(new ByteArrayInputStream(resXml.getBytes("UTF-8"))); + String success = xmlUtils.isSuccess(); + if (!success.equals("ok")) { + logger.info("发送错误:" + success); + throw new RuntimeException(success); + } + List dis = (List) FileUtils.getJsonByName("bgtsRespon"); + //数据所在节点 + Element element = xmlUtils.getElement(dis); + List examInfos = element.elements("ExamInfo"); + Element examNo; + String[] key; + for (Element examInfo : examInfos) { + key = new String[2]; + examNo = examInfo.element(String.valueOf(FileUtils.getJsonByName("examNo"))); + List examItemInfo = examInfo.elements("ExamItemInfo"); + for (Element element1 : examItemInfo) { + if (examNo != null) { + key[0] = examNo.getText(); + } + key[1] = element1.element(String.valueOf(FileUtils.getJsonByName("examItemName"))).getText(); + } + exams.add(key); + } + return exams; + } + /** + * 通过empId获取报告单号集合 动态心电 + * + * @param empId + * @return + */ + private List getExamNoEcg(String empId, String admissDate, String disDate) throws Exception { + List exams = new ArrayList<>(); + XmlUtils reqXmlUtils = new XmlUtils(FileUtils.getXmlPath()); + Element reqElement = reqXmlUtils.getMsgElement(); + reqElement.element("INHOSP_NO").setText(empId); + reqElement.element("BEGIN_DATE").setText(String.valueOf(admissDate)); + reqElement.element("END_DATE").setText(String.valueOf(disDate)); logger.info("-------根据患者主索引号查询多个报告单号,地址:" + wsUrl + ",方法:" + wsLocalMethod + "---------"); String xml = reqXmlUtils.getDocument().asXML(); logger.info("---------------------------"); @@ -463,49 +841,65 @@ public class BgtsServiceImpl implements IBgtsService { * @param collectorId 采集器编号 */ public void collectByDate(String startDate, String endDate, String collectorId) { - //通过日期查询patientId集合 - List patientIds = afCollectTaskService.getjzhByDate(startDate, endDate); - //通过patientId集合与采集器编号查询报告单号 - //List c1s = afCollectTaskService.getC1ByPatientId(patientIds, collectorId); - //通过唯一报告单号查询patient_id - //List patientIdByC1 = afCollectTaskService.getPatientIdByC1(c1s); - //通过patientId集合查询jzh - //List jzhs = afCollectTaskService.getJzhByPatientId(patientIds); - //int i = -1; - //循环jzh与报告单号c1调用按需采集 -// for (String c1 : c1s) { -// try { -// if (i patientIds; + for (startrow = 0; ; startrow += 10) { + patientIds = afCollectTaskService.getjzhByDate(startDate, endDate, startrow, endrow); + + if (null == patientIds || patientIds.size() <= 0) { + logger.info("未查询到按需采集患者!"); + break; } -// for (String jzh : jzhs) { -// if (jzh!=null) { -// logger.info("按需采集------患者"+jzh); -// collect(jzh); -// } -// } - } catch (Exception e) { - e.printStackTrace(); + for (Map patientId : patientIds) { + if (patientId != null) { + try { + logger.info("按需采集------患者" + patientId.get("inpatient_no")); + logger.info("处理按需采集第" + startrow + "条数据----"); + if (collectorId.equals("3")) { + collectPacs(String.valueOf(patientId.get("inpatient_no")), String.valueOf(patientId.get("admiss_date")) + , String.valueOf(patientId.get("dis_date")), String.valueOf(patientId.get("admiss_times"))); + } else if (collectorId.equals("4") || collectorId.equals("23")) { + collectEcg(String.valueOf(patientId.get("jzh")), String.valueOf(patientId.get("admiss_date")) + , String.valueOf(patientId.get("dis_date")), String.valueOf(patientId.get("admiss_times"))); + } else { + collect(String.valueOf(patientId.get("jzh"))); + } + + } catch (Exception e) { + logger.error("按需采集-患者inpatient_no:{},collectPacs() Error:{}", patientId.get("inpatient_no"), e.getMessage()); + } + } + } + patientIds.clear(); + } + }catch (Exception e){ + logger.error(e.getMessage()); + }catch (Throwable t) { + t.printStackTrace(); + logger.error("throwable,{}", t.getMessage()); } + } + + private static JaxWsDynamicClientFactory wsDynamicClientFactory = JaxWsDynamicClientFactory.newInstance(); + private static volatile Client client = null; + private Client getClient() { + if (client == null) { + synchronized (this.getClass()) { + client = wsDynamicClientFactory.createClient(wsUrl); + } + } + return client; } + + /** * 调用web service * @@ -515,12 +909,58 @@ public class BgtsServiceImpl implements IBgtsService { */ public String invokeWs(String xml) throws Exception { logger.info("-----\n客户端调用服务端:" + wsUrl + "方法:" + wsLocalMethod + "\n------------"); - JAXDynamicClientFactory dcf = JAXDynamicClientFactory.newInstance(); - Client client = dcf.createClient(wsUrl); +// JAXDynamicClientFactory dcf = JAXDynamicClientFactory.newInstance(); +// Client client = dcf.createClient(wsUrl); +// LocalBusFactory.printTHREAD_BUSSES(); +// JaxWsDynamicClientFactory wsDynamicClientFactory = JaxWsDynamicClientFactory.newInstance(); +// logger.info("JaxWsDynamicClientFactory object created!"); +// Client client = wsDynamicClientFactory.createClient(wsUrl); + Client client = this.getClient(); + + HTTPConduit conduit = (HTTPConduit) client.getConduit(); + HTTPClientPolicy policy = new HTTPClientPolicy(); + policy.setConnectionTimeout(10000); + policy.setReceiveTimeout(10000); + conduit.setClient(policy); + logger.info("Client started!"); Object[] objects = client.invoke(wsLocalMethod, xml); + logger.info("Client invoke after!"); + String str = objects[0].toString(); +// client.destroy(); + logger.info("----------结果---------\n{}", str); +// logger.info(str); + return str; + } + + /** + * 调用web service + * + * @param xml + * @return + * @throws Exception + */ + public String invokeWsNj(String xml) throws Exception { + logger.info("-----\n客户端调用服务端:" + wsUrl + "方法:" + wsLocalMethodNj + "\n------------"); +// JAXDynamicClientFactory dcf = JAXDynamicClientFactory.newInstance(); +// Client client = dcf.createClient(wsUrl); +// LocalBusFactory.printTHREAD_BUSSES(); +// JaxWsDynamicClientFactory wsDynamicClientFactory = JaxWsDynamicClientFactory.newInstance(); +// logger.info("JaxWsDynamicClientFactory object created!"); +// Client client = wsDynamicClientFactory.createClient(wsUrl); + Client client = this.getClient(); + + HTTPConduit conduit = (HTTPConduit) client.getConduit(); + HTTPClientPolicy policy = new HTTPClientPolicy(); + policy.setConnectionTimeout(10000); + policy.setReceiveTimeout(10000); + conduit.setClient(policy); + logger.info("Client started!"); + Object[] objects = client.invoke(wsLocalMethodNj, xml); + logger.info("Client invoke after!"); String str = objects[0].toString(); - logger.info("----------结果---------"); - logger.info(str); +// client.destroy(); + logger.info("----------结果---------\n{}", str); +// logger.info(str); return str; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index f4b45a1..858785e 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -18,6 +18,7 @@ beat: ws: url: http://192.168.1.115:8010/ws_server/weather?wsdl localMethod: OperationA + LocalMethodNj: 111 spring: datasource: @@ -25,7 +26,7 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver username: docus password: docus702 - url: jdbc:mysql://db.docus.cn:3306/docus_archivefile?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true&allowMultiQueries=true + url: jdbc:mysql://localhost:3306/docus_archivefile?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true&allowMultiQueries=true oracle-docus: driver-class-name: oracle.jdbc.driver.OracleDriver # url: jdbc:oracle:thin:@localhost:1521:ORCL diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 8d89969..0b28482 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -21,8 +21,8 @@ log/demo.%d.%i.log - - 15 + + 30 10MB diff --git a/src/main/resources/mapper/dbmysql/AfCollectAddMapper.xml b/src/main/resources/mapper/dbmysql/AfCollectAddMapper.xml index ad1f222..bf495ea 100644 --- a/src/main/resources/mapper/dbmysql/AfCollectAddMapper.xml +++ b/src/main/resources/mapper/dbmysql/AfCollectAddMapper.xml @@ -15,6 +15,12 @@ limit ${pageNumber},${pageSize} + + - + select inpatient_no,admiss_date,dis_date,admiss_times,jzh from docus_medicalrecord.t_basic where dis_date between #{startDate} and #{endDate} + order by dis_date + limit #{size},#{current} + + +