|  |  | 
 |  |  | package com.ruoyi.quartz.task; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson2.JSON; | 
 |  |  | import com.alibaba.fastjson2.JSONObject; | 
 |  |  | import com.fasterxml.jackson.core.JsonParser; | 
 |  |  | import com.fasterxml.jackson.databind.JsonNode; | 
 |  |  | import com.fasterxml.jackson.databind.ObjectMapper; | 
 |  |  | import com.google.common.reflect.TypeToken; | 
 |  |  | import com.google.gson.Gson; | 
 |  |  | import com.google.gson.JsonArray; | 
 |  |  | import com.google.gson.JsonObject; | 
 |  |  | import com.ruoyi.common.core.redis.RedisCache; | 
 |  |  | import com.ruoyi.common.enums.MsgLSEnum; | 
 |  |  | import com.ruoyi.common.enums.ServiceFromEnum; | 
 |  |  | import com.ruoyi.common.utils.DtoConversionUtils; | 
 |  |  | import com.ruoyi.common.enums.VisitSendStateEnum; | 
 |  |  | import com.ruoyi.common.enums.WxGZHEnum; | 
 |  |  | import com.ruoyi.common.utils.HttpUtil; | 
 |  |  | import com.ruoyi.common.utils.OkHttpExample; | 
 |  |  | import com.ruoyi.common.utils.RSAPublicKeyExample; | 
 |  |  | import com.ruoyi.common.utils.StringUtils; | 
 |  |  | import com.ruoyi.common.utils.http.HttpUtils; | 
 |  |  | import com.smartor.common.SendService; | 
 |  |  | import com.ruoyi.quartz.service.ICollectHISService; | 
 |  |  | import com.smartor.common.LSHospTokenUtil; | 
 |  |  | import com.smartor.domain.*; | 
 |  |  | import com.smartor.mapper.HeLibraryMapper; | 
 |  |  | import com.smartor.mapper.ServiceSubtaskMapper; | 
 |  |  | import com.smartor.mapper.ServiceTaskMapper; | 
 |  |  | import com.smartor.mapper.SysUserImportMapper; | 
 |  |  | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.beans.factory.annotation.Value; | 
 |  |  | import org.springframework.stereotype.Component; | 
 |  |  | import org.springframework.transaction.PlatformTransactionManager; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  |  | 
 |  |  | import java.io.File; | 
 |  |  | import java.io.FileWriter; | 
 |  |  | import java.io.IOException; | 
 |  |  | import java.io.UnsupportedEncodingException; | 
 |  |  | import java.lang.reflect.Type; | 
 |  |  | import java.net.URLEncoder; | 
 |  |  | import java.nio.charset.StandardCharsets; | 
 |  |  | import java.nio.file.Files; | 
 |  |  | import java.nio.file.Paths; | 
 |  |  | import java.text.ParseException; | 
 |  |  | import java.text.SimpleDateFormat; | 
 |  |  | import java.security.MessageDigest; | 
 |  |  | import java.time.LocalDate; | 
 |  |  | import java.time.LocalDateTime; | 
 |  |  | import java.time.LocalTime; | 
 |  |  | import java.time.ZoneId; | 
 |  |  | import java.time.format.DateTimeFormatter; | 
 |  |  | import java.util.*; | 
 |  |  | import java.util.stream.Collectors; | 
 |  |  |  | 
 |  |  | import static cn.hutool.core.convert.Convert.toHex; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 定时任务调度测试 | 
 |  |  | 
 |  |  |     private IPatMedInhospService iPatMedInhospService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private IPatMedOuthospService iPatMedOuthospService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private IPatMedOperationService iPatMedOperationService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private IServiceSubtaskService iServiceSubtaskService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private IServicePatientTempService iServicePatientTempService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private PlatformTransactionManager transactionManager; | 
 |  |  |     private IHNGatherPatArchiveService ihnGatherPatArchiveService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private SysUserImportMapper sysUserImportMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private HeLibraryMapper heLibraryMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private ICollectHISService ichService; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Value("${localIP}") | 
 |  |  |     private String localIP; | 
 |  |  | 
 |  |  |     @Value("${pub_key}") | 
 |  |  |     private String pub_key; | 
 |  |  |  | 
 |  |  |     @Value("${thirdWXUrl}") | 
 |  |  |     private String thirdWXUrl; | 
 |  |  |  | 
 |  |  |     @Value("${req_path}") | 
 |  |  |     private String req_path; | 
 |  |  |  | 
 |  |  |     @Value("${visitHosp}") | 
 |  |  |     private Integer visitHosp; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private ServiceTaskMapper serviceTaskMapper; | 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     IPatArchiveService patArchiveService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     IPatMedInhospService patMedInhospService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     IPatMedOuthospService patMedOuthospService; | 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     IIvrTaskTemplateService iIvrTaskTemplateService; | 
 |  |  |  | 
 |  |  |     @Value("${hosp_info_url}") | 
 |  |  |     private String hospInfoUrl; | 
 |  |  |     @Autowired | 
 |  |  |     IXHGatherPatArchiveService ixhGatherPatArchiveService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     ICollectHISService icollectHis; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Value("${appid}") | 
 |  |  |     private String appid; | 
 |  |  |  | 
 |  |  |     @Value("${server.port}") | 
 |  |  |     private String port; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Value("${spring.profiles.active}") | 
 |  |  |     private String active; | 
 |  |  |  | 
 |  |  |     public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) { | 
 |  |  |         System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i)); | 
 |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 处理his数据 | 
 |  |  |      * 处理HIS数据采集 | 
 |  |  |      * 定时任务:采集患者信息、出院、门诊数据 | 
 |  |  |      */ | 
 |  |  |     public void dealHisData() { | 
 |  |  |         //将患者信息、出院、门诊数据全部采集 | 
 |  |  |         // 获取当前日期和时间 | 
 |  |  |         LocalDateTime endTime = LocalDateTime.now(); | 
 |  |  |         endTime = endTime.with(LocalTime.MIN); | 
 |  |  | //        String dateStr = "2024/11/30 00:00:00"; | 
 |  |  | //        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); | 
 |  |  | //        LocalDateTime endTime = LocalDateTime.parse(dateStr, formatter); | 
 |  |  |         // 获取前一天的日期和时间 | 
 |  |  |         LocalDateTime startTime = endTime.minusDays(1); | 
 |  |  |         startTime = startTime.with(LocalTime.MIN); | 
 |  |  |         getInHospInfo("0", startTime, endTime); | 
 |  |  |         getInHospInfo("1", startTime, endTime); | 
 |  |  |         log.info("【dealHisData】开始执行HIS数据采集任务"); | 
 |  |  |         // 获取昨天0点到今天0点的时间范围 | 
 |  |  |         LocalDateTime todayZero = LocalDateTime.now().with(LocalTime.MIN); | 
 |  |  |         LocalDateTime yesterdayZero = todayZero.minusDays(1); | 
 |  |  |         log.info("【dealHisData】采集时间范围:{} ~ {}", yesterdayZero, todayZero); | 
 |  |  |  | 
 |  |  |         //调用dealOupHospInfo数据处理方法,处理完后,将“出院表的check_flag=1” | 
 |  |  |         //获取当前日期 (精确到天)往前推相应天数(在指定的基础模板中找对应的天数), | 
 |  |  |         //循环患者信息,根据患者"出院诊断ICD值”获取到相当的模板(获取取相应的天数); | 
 |  |  |         //根据查询出来的模板,去固定任务(固定任务,已经将模板也固定了)去匹配模板 | 
 |  |  |         //根据匹配出来的模板和任务与患者信息,将数据插入到子任务表中 | 
 |  |  |         if (active.trim().equals("xh")) { | 
 |  |  |             try { | 
 |  |  |                 // 采集入院数据 | 
 |  |  |                 log.info("【dealHisData】新华开始采集入院数据"); | 
 |  |  |                 ixhGatherPatArchiveService.getInHospDataGather("0", yesterdayZero, todayZero); | 
 |  |  |                 log.info("【dealHisData】新华入院数据采集完成"); | 
 |  |  |  | 
 |  |  |                 // 采集出院数据 | 
 |  |  |                 log.info("【dealHisData】新华开始采集出院数据"); | 
 |  |  |                 ixhGatherPatArchiveService.getInHospDataGather("1", yesterdayZero, todayZero); | 
 |  |  |                 log.info("【dealHisData】新华出院数据采集完成"); | 
 |  |  |  | 
 |  |  |             } catch (Exception e) { | 
 |  |  |                 log.error("【dealHisData】新华数据采集异常", e); | 
 |  |  |             } | 
 |  |  |         } else if (active.trim().equals("hn")) { | 
 |  |  |             try { | 
 |  |  |                 // 河南数据采集 | 
 |  |  |                 HnDataGatherVO hnDataGatherVO = new HnDataGatherVO(); | 
 |  |  |                 log.info("【dealHisData】河南开始采集数据"); | 
 |  |  |                 ihnGatherPatArchiveService.hnDataGather(hnDataGatherVO); | 
 |  |  |                 log.info("【dealHisData】河南结束采集数据"); | 
 |  |  |             } catch (Exception e) { | 
 |  |  |                 log.error("【dealHisData】河南数据采集异常", e); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 这个只是新华临时使用,平时用不到 | 
 |  |  |      */ | 
 |  |  |     public void dealHisData2() { | 
 |  |  |         //将患者信息、出院、门诊数据全部采集 | 
 |  |  |         //将患者信息、出入院数据全部采集 | 
 |  |  |         // 指定的开始日期 | 
 |  |  |         LocalDate endDate = LocalDate.of(2024, 9, 1); | 
 |  |  |         LocalDate endDate = LocalDate.of(2025, 3, 3); | 
 |  |  |         // 当前日期 | 
 |  |  |         LocalDate currentDate = LocalDate.now(); | 
 |  |  |         // 定义日期格式 | 
 |  |  | 
 |  |  |         // 从开始日期到当前日期逐天打印 | 
 |  |  |         for (LocalDate date = endDate; !date.isAfter(currentDate); date = date.plusDays(1)) { | 
 |  |  |             System.out.println(date.format(formatter)); | 
 |  |  |             getInHospInfo("0", date.minusDays(1).atStartOfDay(), date.atStartOfDay()); | 
 |  |  |             getInHospInfo("1", date.minusDays(1).atStartOfDay(), date.atStartOfDay()); | 
 |  |  |             ixhGatherPatArchiveService.getInHospDataGather("0", date.minusDays(1).atStartOfDay(), date.atStartOfDay()); | 
 |  |  |             ixhGatherPatArchiveService.getInHospDataGather("1", date.minusDays(1).atStartOfDay(), date.atStartOfDay()); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |     } | 
 |  |  | 
 |  |  |      * 处理患者信息,进入子任务表 | 
 |  |  |      */ | 
 |  |  |     public void dealOutHospInfo() { | 
 |  |  |         iPatMedInhospService.dealOutHospInfo(); | 
 |  |  |         if (port.equals("8095")) { | 
 |  |  |             //出院表 | 
 |  |  |             iPatMedInhospService.dealOutHospInfo(); | 
 |  |  |             //门诊表 | 
 |  |  |             if (visitHosp != 1) { | 
 |  |  |                 iPatMedOuthospService.dealOutpatientInfo(); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 处理手术信息,进入子任务表 | 
 |  |  |      */ | 
 |  |  |     public void dealOperationInfo() { | 
 |  |  |         if (port.equals("8095")) iPatMedOperationService.dealOperationInfo(); | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 处理患者信息,进入子任务表(微信小程序) | 
 |  |  |      */ | 
 |  |  |     public void dealOutHospInfoXHC() { | 
 |  |  |         PatMedInhosp patMedInhosp = new PatMedInhosp(); | 
 |  |  |         //获取未处理的数据 | 
 |  |  |         List<ServicePatientTemp> servicePatientTemps = iServicePatientTempService.selectServicePatientTempList(new ServicePatientTemp()); | 
 |  |  |  | 
 |  |  |         if (port.equals("8095")) { | 
 |  |  |             PatMedInhosp patMedInhosp = new PatMedInhosp(); | 
 |  |  |             //获取未处理的数据 | 
 |  |  |             List<ServicePatientTemp> servicePatientTemps = iServicePatientTempService.selectServicePatientTempList(new ServicePatientTemp()); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 长期任务执行(电话) | 
 |  |  |      * 长期任务执行 | 
 |  |  |      */ | 
 |  |  |     public void longTaskSend() { | 
 |  |  |         //获取任务信息 | 
 |  |  | 
 |  |  |         st.setDelFlag("0"); | 
 |  |  |         st.setLongTask(1); | 
 |  |  |         List<ServiceTask> serviceTasks = serviceTaskMapper.selectServiceTaskList(st); | 
 |  |  |         log.error("serviceTasks进来了吗?{}", serviceTasks); | 
 |  |  |         log.info("【longTaskSend】获取到{}个长期任务", serviceTasks.size()); | 
 |  |  |         for (ServiceTask serviceTask : serviceTasks) { | 
 |  |  |             CommonTaskcallMQ commonTaskcallMQ = new CommonTaskcallMQ(); | 
 |  |  |             commonTaskcallMQ.setTaskid(serviceTask.getTaskid()); | 
 |  |  | 
 |  |  |      * @return | 
 |  |  |      */ | 
 |  |  |     public boolean isDateToday(Date date) { | 
 |  |  |         //如果给的日期小于当前日期,也直接发送 | 
 |  |  |         LocalDateTime localDateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); | 
 |  |  |         if (localDateTime.isBefore(LocalDateTime.now())) { | 
 |  |  |             return true; | 
 |  |  |         if (date == null) { | 
 |  |  |             return false; | 
 |  |  |         } | 
 |  |  |         // 获取当前日期 | 
 |  |  |         Calendar calendarNow = Calendar.getInstance(); | 
 |  |  |         int todayYear = calendarNow.get(Calendar.YEAR); | 
 |  |  |         int todayMonth = calendarNow.get(Calendar.MONTH); | 
 |  |  |         int todayDay = calendarNow.get(Calendar.DAY_OF_MONTH); | 
 |  |  |  | 
 |  |  |         // 创建一个 Calendar 实例用于检查的日期 | 
 |  |  |         Calendar calendarToCheck = Calendar.getInstance(); | 
 |  |  |         calendarToCheck.setTime(date); | 
 |  |  |  | 
 |  |  |         // 比较年、月和日 | 
 |  |  |         return (calendarToCheck.get(Calendar.YEAR) == todayYear && calendarToCheck.get(Calendar.MONTH) == todayMonth && calendarToCheck.get(Calendar.DAY_OF_MONTH) == todayDay); | 
 |  |  |         // 将 Date 转为 LocalDate | 
 |  |  |         LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); | 
 |  |  |         // 获取今天的 LocalDate | 
 |  |  |         LocalDate today = LocalDate.now(); | 
 |  |  |         // 如果日期早于或等于今天,返回 true | 
 |  |  |         return !localDate.isAfter(today); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void sfHandlle(CommonTaskcallMQ commonTaskcallMQ, String ip) { | 
 |  |  |         log.error("sfHandlle进来了吗?{}", commonTaskcallMQ); | 
 |  |  |         log.info("【sfHandlle】开始处理任务,任务ID:{}", commonTaskcallMQ.getTaskid()); | 
 |  |  |         //判断一下commonTaskcallMQ中的stopstate是否与ivr_task中的一致,不一致,则说明是暂停了 | 
 |  |  |         ServiceTask ivrTask1 = serviceTaskMapper.selectServiceTaskByTaskid(commonTaskcallMQ.getTaskid()); | 
 |  |  |  | 
 |  |  |         if (StringUtils.isNotEmpty(commonTaskcallMQ.getPreachform())) { | 
 |  |  |             //如何任务发送方式不为空 | 
 |  |  |             String[] split = commonTaskcallMQ.getPreachform().split(","); | 
 |  |  |             log.error("split进来了吗?{}", split); | 
 |  |  |             log.info("【sfHandlle】任务发送方式:{}", Arrays.toString(split)); | 
 |  |  |             for (String serviceFrom : split) { | 
 |  |  |                 String descByCode = ServiceFromEnum.getDescByCode(Integer.valueOf(serviceFrom)); | 
 |  |  |                 //通过任务ID拿到患者信息 | 
 |  |  |                 ServiceSubtaskVO ivrTaskcall = new ServiceSubtaskVO(); | 
 |  |  |                 ivrTaskcall.setTaskid(commonTaskcallMQ.getTaskid()); | 
 |  |  |                 ivrTaskcall.setSendstate(2L); | 
 |  |  |                 List<ServiceSubtask> selectServiceSubtaskList = iServiceSubtaskService.selectServiceSubtaskList(ivrTaskcall); | 
 |  |  |                 List<ServiceSubtask> subtaskList = iServiceSubtaskService.selectServiceSubtaskList(ivrTaskcall); | 
 |  |  |                 //丽水有的医院还没法做长期任务随访 | 
 |  |  |                 List<ServiceSubtask> subtaskList2 = new ArrayList<>(); | 
 |  |  |                 if (visitHosp == 2) { | 
 |  |  |                     try { | 
 |  |  |                         for (ServiceSubtask serviceSubtask : subtaskList) { | 
 |  |  |                             Boolean b = VisitSendStateEnum.getDescByCode(serviceSubtask.getOrgid()); | 
 |  |  |  | 
 |  |  |                             if (b) subtaskList2.add(serviceSubtask); | 
 |  |  |                         } | 
 |  |  |                     } catch (Exception e) { | 
 |  |  |                         log.error("-------长期任务异常为:", e); | 
 |  |  |                         continue; | 
 |  |  |                     } | 
 |  |  | //                    for (ServiceSubtask serviceSubtask : subtaskList) { | 
 |  |  | //                        Boolean b = VisitSendStateEnum.getDescByCode(serviceSubtask.getOrgid()); | 
 |  |  | // | 
 |  |  | //                        if (b) subtaskList2.add(serviceSubtask); | 
 |  |  | //                    } | 
 |  |  |                     subtaskList = subtaskList2; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 // 按照 endtime 离当前时间最近的排序 | 
 |  |  |                 List<ServiceSubtask> selectServiceSubtaskList = subtaskList.stream().sorted(Comparator.comparing(subtask -> Math.abs(subtask.getEndtime().getTime() - new Date().getTime()))).collect(Collectors.toList()); | 
 |  |  |  | 
 |  |  |                 if (descByCode.equals("电话")) { | 
 |  |  |                     String value = ""; | 
 |  |  |                     List<String> list = new ArrayList<>(); | 
 |  |  |                     for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { | 
 |  |  |                         ServiceTask ivrTask = serviceTaskMapper.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); | 
 |  |  |                         if (ivrTask.getSendState() != null && ivrTask.getSendState() == 3 || ivrTask.getSendState() != null && ivrTask.getSendState() == 4) { | 
 |  |  |                             //如何任务被“暂停”或“终止” | 
 |  |  |                             //如何任务被"暂停"或"终止" | 
 |  |  |                             break; | 
 |  |  |                         } | 
 |  |  |                         if (org.apache.commons.lang3.StringUtils.isEmpty(serviceSubtask.getPhone())) { | 
 |  |  |                             serviceSubtask.setRemark("手机号为空"); | 
 |  |  |                             serviceSubtask.setSendstate(4L); | 
 |  |  |                             serviceSubtask.setResult("error"); | 
 |  |  | //                            serviceSubtask.setFinishtime(new Date()); | 
 |  |  |                             serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); | 
 |  |  |                             continue; | 
 |  |  |                         } | 
 |  |  |                         boolean dateToday = isDateToday(serviceSubtask.getLongSendTime()); | 
 |  |  |                         //说明是立即发送(先把消息放到cache-0中,   displayNo不知道怎么配置) | 
 |  |  | 
 |  |  |                     } | 
 |  |  |                     //将要执行的放到缓存中 | 
 |  |  |                     if (list.size() > 0) { | 
 |  |  |                         redisCache.setCacheListLeft("cache-0", list); | 
 |  |  | //                        redisCache.setCacheListLeft("cache-0", list); | 
 |  |  |                         redisCache.setCacheListLeftAndDistinct("cache-0", list); | 
 |  |  |                         log.info("【sfHandlle】电话任务已加入队列,数量:{}", list.size()); | 
 |  |  |                     } | 
 |  |  |                 } else if (descByCode.equals("多媒体")) { | 
 |  |  |                     //多媒体 | 
 |  |  | 
 |  |  |                     //纸质 | 
 |  |  |                 } else if (descByCode.equals("微信小程序")) { | 
 |  |  |                     //微信小程序 | 
 |  |  |                     for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { | 
 |  |  |                         log.error("微信小程序期任务发送---------进来了吗?{}", serviceSubtask); | 
 |  |  |                     log.info("【sfHandlle】处理微信小程序任务,任务信息:{}", ivrTask1); | 
 |  |  |                     if (ObjectUtils.isNotEmpty(ivrTask1) && ivrTask1.getPatCycle() == 1) { | 
 |  |  |                         //说明该任务的患者是循环执行的 | 
 |  |  |                         ServiceSubtaskVO serviceSubtaskVO = new ServiceSubtaskVO(); | 
 |  |  |                         serviceSubtaskVO.setTaskid(ivrTask1.getTaskid()); | 
 |  |  |                         List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO); | 
 |  |  |                         //这里需要根据身份证去重 | 
 |  |  |                         List<ServiceSubtask> serviceSubtaskListFilter = new ArrayList<>(); | 
 |  |  |                         aa: | 
 |  |  |                         for (ServiceSubtask serviceSubtask : serviceSubtaskList) { | 
 |  |  |                             for (ServiceSubtask ss : serviceSubtaskListFilter) { | 
 |  |  |                                 if (ss.getSfzh().equals(serviceSubtask.getSfzh())) { | 
 |  |  |                                     continue aa; | 
 |  |  |                                 } | 
 |  |  |                             } | 
 |  |  |                             serviceSubtaskListFilter.add(serviceSubtask); | 
 |  |  |                         } | 
 |  |  |                         for (ServiceSubtask serviceSubtask : serviceSubtaskListFilter) { | 
 |  |  |                             //将子任务ID删除 、sendstate改成3 | 
 |  |  |                             serviceSubtask.setSendstate(3L); | 
 |  |  |                             serviceSubtask.setId(null); | 
 |  |  |                             serviceSubtask.setFinishtime(null); | 
 |  |  |                             serviceSubtask.setCreateTime(new Date()); | 
 |  |  |                             serviceSubtask.setUpdateTime(new Date()); | 
 |  |  |                             //处理重复新增问题,先查一下今天是不是有新增过,新增过就不新增了 | 
 |  |  |                             ServiceSubtaskVO ssvo = new ServiceSubtaskVO(); | 
 |  |  |                             LocalDate today = LocalDate.now(); | 
 |  |  |                             LocalTime startOfDay = LocalTime.of(0, 0, 0); | 
 |  |  |                             LocalTime endOfDay = LocalTime.of(23, 59, 59); | 
 |  |  |                             Date startOfDayDate = Date.from(today.atTime(startOfDay).atZone(ZoneId.systemDefault()).toInstant()); | 
 |  |  |                             Date endOfDayDate = Date.from(today.atTime(endOfDay).atZone(ZoneId.systemDefault()).toInstant()); | 
 |  |  |                             ssvo.setCreateStartTime(startOfDayDate); | 
 |  |  |                             ssvo.setCreateEndTime(endOfDayDate); | 
 |  |  |                             ssvo.setCreateBy(serviceSubtask.getCreateBy()); | 
 |  |  |                             ssvo.setSendname(serviceSubtask.getSendname()); | 
 |  |  |                             ssvo.setSfzh(serviceSubtask.getSfzh()); | 
 |  |  |                             List<ServiceSubtask> serviceSubtaskListByCreateTime = serviceSubtaskMapper.selectServiceSubtaskListByCreateTime(ssvo); | 
 |  |  |                             if (CollectionUtils.isEmpty(serviceSubtaskListByCreateTime)) | 
 |  |  |                                 serviceSubtaskMapper.insertServiceSubtask(serviceSubtask); | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } else if (descByCode.equals("短信")) { | 
 |  |  |                     RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); | 
 |  |  |                     String taskId = rsaPublicKeyExample.encryptedData(ivrTask1.getTaskid().toString(), pub_key); | 
 |  |  |                     for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { | 
 |  |  |                         log.error("短信长期任务发送---------进来了吗?{}", serviceSubtask); | 
 |  |  |                         log.info("【sfHandlle】处理短信长期任务,患者ID:{}", serviceSubtask.getPatid()); | 
 |  |  |                         boolean dateToday = isDateToday(serviceSubtask.getLongSendTime()); | 
 |  |  |                         if (dateToday) { | 
 |  |  |                             try { | 
 |  |  | 
 |  |  |                                     serviceSubtask.setResult("error"); | 
 |  |  |                                     serviceSubtask.setRemark(patArchive.getNotrequiredreason()); | 
 |  |  |                                     serviceSubtask.setSendstate(4L); | 
 |  |  |                                     serviceSubtask.setFinishtime(new Date()); | 
 |  |  |                                     iServiceSubtaskService.insertServiceSubtask(serviceSubtask); | 
 |  |  |                                     continue; | 
 |  |  |                                 } | 
 |  |  |                                 String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key); | 
 |  |  |                                 String subId = rsaPublicKeyExample.encryptedData(serviceSubtask.getId().toString(), pub_key); | 
 |  |  |                                 SendMagParam sendMagParam = new SendMagParam(); | 
 |  |  |                                 sendMagParam.setType("4"); | 
 |  |  |                                 ServiceOutPath serviceOutPath = new ServiceOutPath(); | 
 |  |  |                                 serviceOutPath.setParam1(taskId); | 
 |  |  |                                 serviceOutPath.setParam2(patid); | 
 |  |  |                                 serviceOutPath.setParam3(ivrTask1.getTaskName()); | 
 |  |  |                                 serviceOutPath.setParam6(subId); | 
 |  |  |                                 serviceOutPath.setCreateTime(new Date()); | 
 |  |  |                                 iServiceOutPathService.insertServiceOutPath(serviceOutPath); | 
 |  |  |                                 String format = String.format("%03X", serviceOutPath.getId()); | 
 |  |  |                                 serviceOutPath.setRadix(format); | 
 |  |  |                                 serviceOutPath.setUpdateTime(new Date()); | 
 |  |  |                                 iServiceOutPathService.updateServiceOutPath(serviceOutPath); | 
 |  |  |                                 sendMagParam.setPhone(serviceSubtask.getPhone()); | 
 |  |  |                                 sendMagParam.setUrl(ip + ":" + req_path + "/wt?p=" + format); | 
 |  |  |                                 sendMagParam.setContent("【新华医院】您好,邀请您填写出院调查表,请点击" + sendMagParam.getUrl() + "填写。感谢您配合!"); | 
 |  |  |                                 Map<String, String> req = new HashMap<>(); | 
 |  |  |                                 req.put("phone", sendMagParam.getPhone()); | 
 |  |  |                                 req.put("content", sendMagParam.getContent()); | 
 |  |  |                                 String isSuccess = HttpUtil.postJsonRequest(xhsmsPath, new Gson().toJson(req)); | 
 |  |  |                                 //先判断一下发的是不是宣教 | 
 |  |  |                                 if (!"3".equals(serviceSubtask.getType())) { | 
 |  |  |                                     sendMagParam.setPhone(serviceSubtask.getPhone()); | 
 |  |  |                                     sendMagParam.setUrl(ip + ":" + req_path + "/wt?p=" + format); | 
 |  |  |                                     sendMagParam.setContent("【新华医院】您好,邀请您填写出院调查表,请点击" + sendMagParam.getUrl() + "填写。感谢您配合!"); | 
 |  |  |                                 } else { | 
 |  |  |                                     HeLibrary heLibrary = heLibraryMapper.selectHeLibraryById(serviceSubtask.getLibtemplateid()); | 
 |  |  |                                     if ("2".equals(heLibrary.getHetype())) { | 
 |  |  |                                         sendMagParam.setPhone(serviceSubtask.getPhone()); | 
 |  |  |                                         sendMagParam.setContent(heLibrary.getPreachcontent()); | 
 |  |  |                                     } | 
 |  |  |                                 } | 
 |  |  |                                 String isSuccess = null; | 
 |  |  |                                 if (visitHosp == 1) { | 
 |  |  |                                     Map<String, String> req = new HashMap<>(); | 
 |  |  |                                     req.put("phone", sendMagParam.getPhone()); | 
 |  |  |                                     req.put("content", sendMagParam.getContent()); | 
 |  |  |                                     isSuccess = HttpUtil.postJsonRequest(xhsmsPath, new Gson().toJson(req)); | 
 |  |  |                                 } else if (visitHosp == 2) { | 
 |  |  |                                     //丽水的短信发送方式 | 
 |  |  |                                     Map<String, String> map = MsgLSEnum.getAddressByCode(serviceSubtask.getOrgid()); | 
 |  |  |                                     String token = LSHospTokenUtil.getToken(serviceSubtask.getOrgid()); | 
 |  |  |                                     if (ObjectUtils.isNotEmpty(map) && StringUtils.isEmpty(map.get("address"))) { | 
 |  |  |                                         ServiceSubtask ss = new ServiceSubtask(); | 
 |  |  |                                         ss.setResult("error"); | 
 |  |  |                                         ss.setRemark("短信发送失败,该机构没有配置短信地址"); | 
 |  |  |                                         ss.setSendstate(5L); | 
 |  |  |                                         ss.setId(serviceSubtask.getId()); | 
 |  |  | //                                        ss.setFinishtime(new Date()); | 
 |  |  |                                         serviceSubtaskMapper.updateServiceSubtask(ss); | 
 |  |  |                                         continue; | 
 |  |  |                                     } | 
 |  |  |                                     log.info("【sfHandlle】丽水短信发送,地址:{},参数:{},机构ID:{}", map.get("address"), sendMagParam, serviceSubtask.getOrgid()); | 
 |  |  |                                     String dxCode = getDXCode(map.get("address"), sendMagParam.getPhone(), sendMagParam.getContent(), map.get("sendPersonId"), map.get("sendPersonName"), MsgLSEnum.getHeaderByCode(serviceSubtask.getOrgid()), token); | 
 |  |  |                                     log.info("【sfHandlle】丽水短信发送结果:{}", dxCode); | 
 |  |  |                                     ObjectMapper objectMapper = new ObjectMapper(); | 
 |  |  |                                     Map<String, Object> textParam = objectMapper.readValue(dxCode, Map.class); | 
 |  |  |                                     String code = textParam.get("Code").toString(); | 
 |  |  |                                     if (code.equals("0")) { | 
 |  |  |                                         isSuccess = "true"; | 
 |  |  |                                     } | 
 |  |  |                                 } | 
 |  |  |                                 //任务发送记录 | 
 |  |  |                                 ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); | 
 |  |  |                                 serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); | 
 |  |  | 
 |  |  |                                 iServiceSubtaskService.updateServiceSubtask(serviceSubtask); | 
 |  |  |                             } catch (Exception e) { | 
 |  |  |                                 String guid = UUID.randomUUID().toString(); | 
 |  |  |                                 log.error("长期任务,短信发送失败原因:{},{}", e.getMessage(), guid); | 
 |  |  |                                 log.error("【sfHandlle】长期任务短信发送失败,原因:{},GUID:{}", e.getMessage(), guid); | 
 |  |  |                                 serviceSubtask.setResult("error"); | 
 |  |  |                                 serviceSubtask.setRemark("系统错误"); | 
 |  |  |                                 serviceSubtask.setSendstate(5L); | 
 |  |  |                                 serviceSubtask.setFinishtime(new Date()); | 
 |  |  |                                 serviceSubtask.setGuid(guid); | 
 |  |  |                                 iServiceSubtaskService.updateServiceSubtask(serviceSubtask); | 
 |  |  |                             } | 
 |  |  |                         } | 
 |  |  |                     } | 
 |  |  |                 } else if (descByCode.equals("公众号")) { | 
 |  |  |                     log.error("公众号进来了吗?{}", descByCode); | 
 |  |  |                     log.info("【sfHandlle】处理公众号任务,任务信息:{}", ivrTask1); | 
 |  |  |                     //公众号 | 
 |  |  |                     RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); | 
 |  |  |                     String taskId = rsaPublicKeyExample.encryptedData(ivrTask1.getTaskid().toString(), pub_key); | 
 |  |  |                     for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { | 
 |  |  |                         log.error("serviceSubtask---------进来了吗?{}", serviceSubtask); | 
 |  |  |                         boolean dateToday = isDateToday(serviceSubtask.getLongSendTime()); | 
 |  |  |                         if (dateToday) { | 
 |  |  |                             try { | 
 |  |  | 
 |  |  |                                     serviceSubtask.setResult("error"); | 
 |  |  |                                     serviceSubtask.setRemark(patArchive.getNotrequiredreason()); | 
 |  |  |                                     serviceSubtask.setSendstate(4L); | 
 |  |  |                                     serviceSubtask.setFinishtime(new Date()); | 
 |  |  |                                     iServiceSubtaskService.insertServiceSubtask(serviceSubtask); | 
 |  |  |                                     continue; | 
 |  |  |                                 } | 
 |  |  |                                 String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key); | 
 |  |  |                                 String url = null; | 
 |  |  |                                 url = ip + ":" + req_path + "/outsideChainwt?param1=" + taskId + "¶m2=" + patid + "¶m3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "¶m5=false"; | 
 |  |  |                                 String wxCode = getWXCode(serviceSubtask.getSfzh(), url, serviceSubtask.getTaskName(), serviceSubtask.getTaskDesc(), "无"); | 
 |  |  |                                 Map<String, Object> map = JSONObject.parseObject(wxCode, Map.class); | 
 |  |  |  | 
 |  |  |                                 //获取微信公众号请求信息根据机构ID | 
 |  |  |                                 List<String> wxqqxx = WxGZHEnum.getDescByCode(patArchive.getOrgid()); | 
 |  |  |                                 if (CollectionUtils.isEmpty(wxqqxx) || wxqqxx.size() < 4) { | 
 |  |  |                                     ServiceSubtask ss = new ServiceSubtask(); | 
 |  |  |                                     ss.setResult("error"); | 
 |  |  |                                     ss.setRemark("该机构的公众号配置信息不全,无法通过公众号发送"); | 
 |  |  |                                     ss.setSendstate(5L); | 
 |  |  |                                     ss.setId(serviceSubtask.getId()); | 
 |  |  |                                     serviceSubtaskMapper.updateServiceSubtask(ss); | 
 |  |  |                                     continue; | 
 |  |  |                                 } | 
 |  |  |  | 
 |  |  |                                 if (StringUtils.isEmpty(patArchive.getPatidHis())) { | 
 |  |  |                                     ServiceSubtask ss = new ServiceSubtask(); | 
 |  |  |                                     ss.setResult("error"); | 
 |  |  |                                     ss.setRemark("公众号发送失败,his系统的患者id为空"); | 
 |  |  |                                     ss.setSendstate(5L); | 
 |  |  |                                     ss.setId(serviceSubtask.getId()); | 
 |  |  |                                     serviceSubtaskMapper.updateServiceSubtask(ss); | 
 |  |  |                                     continue; | 
 |  |  |                                 } | 
 |  |  |                                 String wxCode = getWXCode(serviceSubtask.getSfzh(), url, serviceSubtask.getTaskName(), serviceSubtask.getTaskDesc(), patArchive.getTelcode(), serviceSubtask.getSendname(), patArchive.getPatidHis(), wxqqxx); | 
 |  |  |  | 
 |  |  |                                 Map<String, Object> map = JSONObject.parseObject(wxCode, Map.class); | 
 |  |  |                                 //任务发送记录 | 
 |  |  |                                 ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); | 
 |  |  |                                 serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); | 
 |  |  | 
 |  |  |                                 if ((Boolean) map.get("succ") == true) { | 
 |  |  |                                     serviceSubtask.setResult("success"); | 
 |  |  |                                 } else { | 
 |  |  |                                     log.error("【sfHandlle】公众号发送失败,患者信息:{},错误信息:{}", serviceSubtask, map.get("msg")); | 
 |  |  |                                     serviceSubtask.setResult("error"); | 
 |  |  |                                     serviceSubtask.setSendstate(5L); | 
 |  |  |                                     serviceSubtask.setRemark(map.get("msg").toString()); | 
 |  |  | 
 |  |  |                                 iServiceSubtaskService.updateServiceSubtask(serviceSubtask); | 
 |  |  |                             } catch (Exception e) { | 
 |  |  |                                 String guid = UUID.randomUUID().toString(); | 
 |  |  |                                 log.error("长期任务,公众号发送失败原因:{},{}", e.getMessage(), guid); | 
 |  |  |                                 log.error("【sfHandlle】长期任务公众号发送失败,原因:{},GUID:{}", e.getMessage(), guid); | 
 |  |  |                                 serviceSubtask.setResult("error"); | 
 |  |  |                                 serviceSubtask.setRemark("系统错误"); | 
 |  |  |                                 serviceSubtask.setSendstate(5L); | 
 |  |  |                                 serviceSubtask.setFinishtime(new Date()); | 
 |  |  |                                 serviceSubtask.setGuid(guid); | 
 |  |  |                                 iServiceSubtaskService.updateServiceSubtask(serviceSubtask); | 
 |  |  |                             } | 
 |  |  | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 获出院患者信息 | 
 |  |  |      * cry    出入院: 0 入院   1 出院 | 
 |  |  |      */ | 
 |  |  |     @Transactional | 
 |  |  |     public void getInHospInfo(String cry, LocalDateTime startTime, LocalDateTime endTime) { | 
 |  |  |         // 定义日期时间格式 | 
 |  |  |         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"); | 
 |  |  |         Map<String, String> req = new HashMap<>(); | 
 |  |  |         if (cry.equals("1")) { | 
 |  |  |             req.put("cashStartDate", startTime.format(formatter)); | 
 |  |  |             req.put("cashEndDate", endTime.format(formatter)); | 
 |  |  |             req.put("currStatus", "4"); | 
 |  |  |         } else if (cry.equals("0")) { | 
 |  |  |             req.put("admissStartDate", startTime.format(formatter)); | 
 |  |  |             req.put("admissEndDate", endTime.format(formatter)); | 
 |  |  |             req.put("currStatus", "2"); | 
 |  |  |         } | 
 |  |  |         Map<String, String> header = new HashMap<>(); | 
 |  |  |         header.put("x-hcsb-serviceno", "IS002347"); | 
 |  |  |         header.put("x-hcsb-version", "2.0"); | 
 |  |  |         header.put("x-hcsb-sourcesyscode", "14"); | 
 |  |  |         header.put("x-hcsb-token", "ArGE2JnHtxG/Zx5nrnGY4eOfMUJGGJokAJHigG1BrCY="); | 
 |  |  |         header.put("x-hcsb-msgdate", startTime.format(formatter)); | 
 |  |  |         String result = HttpUtils.sendPostByHeader(hospInfoUrl, new Gson().toJson(req), header); | 
 |  |  |         //数据解析 | 
 |  |  |         Gson gson = new Gson(); | 
 |  |  |         JsonObject jsonObject = gson.fromJson(result, JsonObject.class); | 
 |  |  |         JsonArray resultArray = jsonObject.getAsJsonObject("data").getAsJsonArray("result"); | 
 |  |  |         Type resultType = new TypeToken<List<ThiedInhospInfo>>() { | 
 |  |  |         }.getType(); | 
 |  |  |         List<ThiedInhospInfo> thiedInhospInfoList = gson.fromJson(resultArray, resultType); | 
 |  |  |  | 
 |  |  |         // 创建一个新文件 | 
 |  |  |         String filename = null; | 
 |  |  |         if (cry.equals("0")) filename = "入院信息" + System.currentTimeMillis(); | 
 |  |  |         if (cry.equals("1")) filename = "出院信息" + System.currentTimeMillis(); | 
 |  |  |         File file = new File("D:\\public\\华卓集成平台数据\\" + filename); | 
 |  |  |         if (!file.exists()) { | 
 |  |  |             // 如果文件不存在,则创建新文件 | 
 |  |  |             try { | 
 |  |  |                 if (file.createNewFile()) { | 
 |  |  |                     System.out.println("成功创建了新文件!"); | 
 |  |  |                 } else { | 
 |  |  |                     System.out.println("失败!文件无法创建!"); | 
 |  |  |                 } | 
 |  |  |             } catch (IOException e) { | 
 |  |  |                 e.printStackTrace(); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         // 将数据写入到文件中 | 
 |  |  |         try { | 
 |  |  |             FileWriter writer = new FileWriter(file); | 
 |  |  |             writer.write(result); | 
 |  |  |         } catch (IOException e) { | 
 |  |  |             e.printStackTrace(); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (CollectionUtils.isNotEmpty(thiedInhospInfoList)) { | 
 |  |  |             for (ThiedInhospInfo thiedInhospInfo : thiedInhospInfoList) { | 
 |  |  |                 //通过身份证号查询该患者在患者表是否存在 | 
 |  |  |                 PatArchive patArchive = new PatArchive(); | 
 |  |  |                 List<PatArchive> patArchives = null; | 
 |  |  |                 patArchive.setIdcardno(thiedInhospInfo.getPatiIdCardNo().trim()); | 
 |  |  |                 if (StringUtils.isNotEmpty(thiedInhospInfo.getPatiIdCardNo().trim())) { | 
 |  |  |                     patArchives = patArchiveService.selectPatArchiveList(patArchive); | 
 |  |  |                 } else { | 
 |  |  |                     //患者信息为空,直接 下一个 | 
 |  |  |                     continue; | 
 |  |  |                 } | 
 |  |  |                 if (CollectionUtils.isEmpty(patArchives) || patArchives.size() == 0) { | 
 |  |  |                     patArchive.setPatientno(thiedInhospInfo.getPatiMediaNo()); | 
 |  |  |                     patArchive.setSourcefrom(2); | 
 |  |  |                     patArchive.setPattype("2"); | 
 |  |  |                     if (StringUtils.isNotEmpty(thiedInhospInfo.getOutWayId()) && thiedInhospInfo.getOutWayId().equals("4")) { | 
 |  |  |                         //如果为4就是死亡 | 
 |  |  |                         patArchive.setNotrequiredFlag("1"); | 
 |  |  |                         patArchive.setNotrequiredreason(thiedInhospInfo.getOutWayName()); | 
 |  |  |                     } | 
 |  |  |                     if (cry.equals("1") && StringUtils.isEmpty(thiedInhospInfo.getOutWayId())) { | 
 |  |  |                         //如果为4就是死亡 | 
 |  |  |                         patArchive.setNotrequiredFlag("1"); | 
 |  |  |                         patArchive.setNotrequiredreason("出院方式为空"); | 
 |  |  |                     } | 
 |  |  |                     patArchive.setSex(thiedInhospInfo.getPatiRecordGender().equals("男") ? 1L : 2L); | 
 |  |  |                     patArchive.setNation(thiedInhospInfo.getPatiNation()); | 
 |  |  |                     patArchive.setNativePlace(thiedInhospInfo.getPatiNationality()); | 
 |  |  |                     patArchive.setPlaceOfResidence(thiedInhospInfo.getPatiHomeAddr()); | 
 |  |  |                     try { | 
 |  |  |                         if (StringUtils.isNotEmpty(thiedInhospInfo.getPatiBirthday())) | 
 |  |  |                             patArchive.setBirthdate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(thiedInhospInfo.getPatiBirthday())); | 
 |  |  |                     } catch (ParseException e) { | 
 |  |  |                         e.printStackTrace(); | 
 |  |  |                     } | 
 |  |  |                     if (thiedInhospInfo.getTreateAge() != null) { | 
 |  |  |                         patArchive.setAge(Long.valueOf(thiedInhospInfo.getTreateAge())); | 
 |  |  |                     } else { | 
 |  |  |                         patArchive.setAge(null); | 
 |  |  |                     } | 
 |  |  |                     patArchive.setAgeUnit(thiedInhospInfo.getTreatAgeunit()); | 
 |  |  |                     patArchive.setTelcode(thiedInhospInfo.getCompanyTelNum()); | 
 |  |  |                     patArchive.setRelativetelcode(thiedInhospInfo.getContactPersonPhone()); | 
 |  |  |                     patArchive.setDelFlag("0"); | 
 |  |  |                     patArchive.setCreateTime(new Date()); | 
 |  |  |                     patArchive.setUpdateTime(new Date()); | 
 |  |  |                     patArchive.setName(thiedInhospInfo.getPatiRecordName()); | 
 |  |  |                     patArchiveService.insertPatArchive(patArchive); | 
 |  |  |                 } else { | 
 |  |  |                     patArchive = patArchives.get(0); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 log.error("入参的patArchive:{}", patArchive); | 
 |  |  |                 PatMedInhosp patMedInhosp = new PatMedInhosp(); | 
 |  |  |                 patMedInhosp.setPatid(patArchive.getId()); | 
 |  |  |                 patMedInhosp.setPatno(patArchive.getPatientno()); | 
 |  |  |                 patMedInhosp.setPatname(patArchive.getName()); | 
 |  |  |                 patMedInhosp.setNurseId(thiedInhospInfo.getNurseId()); | 
 |  |  |                 patMedInhosp.setNurseName(thiedInhospInfo.getNurseName()); | 
 |  |  |                 patMedInhosp.setSerialnum(thiedInhospInfo.getInpatientId()); | 
 |  |  |                 if (cry.equals("0")) { | 
 |  |  |                     patMedInhosp.setInhospstate("0"); | 
 |  |  |                 } else if (cry.equals("1")) { | 
 |  |  |                     patMedInhosp.setInhospstate("1"); | 
 |  |  |                 } | 
 |  |  |                 patMedInhosp.setHospitalcode(thiedInhospInfo.getAreaId()); | 
 |  |  |                 patMedInhosp.setIcd10code(thiedInhospInfo.getDiagIcd10()); | 
 |  |  |                 patMedInhosp.setDiagname(thiedInhospInfo.getDiagName()); | 
 |  |  |                 try { | 
 |  |  |                     if (StringUtils.isNotEmpty(thiedInhospInfo.getAdmissDate())) | 
 |  |  |                         patMedInhosp.setStarttime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(thiedInhospInfo.getAdmissDate())); | 
 |  |  |                 } catch (ParseException e) { | 
 |  |  |                     e.printStackTrace(); | 
 |  |  |                 } | 
 |  |  |                 try { | 
 |  |  |                     if (StringUtils.isNotEmpty(thiedInhospInfo.getOutDate())) | 
 |  |  |                         patMedInhosp.setEndtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(thiedInhospInfo.getOutDate())); | 
 |  |  |                 } catch (ParseException e) { | 
 |  |  |                     e.printStackTrace(); | 
 |  |  |                 } | 
 |  |  |                 patMedInhosp.setDeptcode(thiedInhospInfo.getAdmissDeptId()); | 
 |  |  |                 patMedInhosp.setDeptid(thiedInhospInfo.getAdmissDeptId()); | 
 |  |  |                 patMedInhosp.setDeptname(thiedInhospInfo.getAdmissDeptName()); | 
 |  |  |                 patMedInhosp.setBedNo(thiedInhospInfo.getAdmissBedNo()); | 
 |  |  |                 patMedInhosp.setDelFlag("0"); | 
 |  |  | //                patMedInhosp.setLeaveldeptcode(thiedInhospInfo.getCurrDeptCode()); | 
 |  |  |                 patMedInhosp.setLeaveldeptcode(thiedInhospInfo.getCurrDeptId()); | 
 |  |  |                 patMedInhosp.setLeaveldeptname(thiedInhospInfo.getCurrDeptName()); | 
 |  |  |                 patMedInhosp.setLeavediagname(thiedInhospInfo.getDiagName()); | 
 |  |  |                 patMedInhosp.setLeaveicd10code(thiedInhospInfo.getDiagIcd10()); | 
 |  |  |                 patMedInhosp.setDrname(thiedInhospInfo.getDoctName()); | 
 |  |  |                 patMedInhosp.setDrcode(thiedInhospInfo.getDoctId()); | 
 |  |  |                 patMedInhosp.setOutWayId(thiedInhospInfo.getOutWayId()); | 
 |  |  |                 patMedInhosp.setOutWayName(thiedInhospInfo.getOutWayName()); | 
 |  |  |                 if (cry.equals("0")) { | 
 |  |  |                     patMedInhosp.setSchemestatus(1L); | 
 |  |  |                 } else if (cry.equals("1")) { | 
 |  |  |                     patMedInhosp.setSchemestatus(2L); | 
 |  |  |                 } | 
 |  |  |                 patMedInhosp.setLeavehospitaldistrictid(thiedInhospInfo.getCurrWardCode()); | 
 |  |  |                 patMedInhosp.setLeavehospitaldistrictcode(thiedInhospInfo.getCurrWardId()); | 
 |  |  |                 patMedInhosp.setLeavehospitaldistrictname(thiedInhospInfo.getCurrWardName()); | 
 |  |  |                 patMedInhosp.setLeaveldeptid(thiedInhospInfo.getCurrDeptCode()); | 
 |  |  |                 //如果是出院,先通过患者编号和流水号去查一下,患者是否存在,如果存在,则进行修改 | 
 |  |  |                 PatMedInhosp inhosp = new PatMedInhosp(); | 
 |  |  |                 inhosp.setPatno(patArchive.getPatientno()); | 
 |  |  |                 inhosp.setSerialnum(patMedInhosp.getSerialnum()); | 
 |  |  |                 List<PatMedInhosp> patMedInhosps = patMedInhospService.selectPatMedInhospList(inhosp); | 
 |  |  |                 log.error("是否需要更新:{}", patMedInhosps.size()); | 
 |  |  |                 if (CollectionUtils.isNotEmpty(patMedInhosps)) { | 
 |  |  |                     patMedInhosp.setInhospid(patMedInhosps.get(0).getInhospid()); | 
 |  |  |                     log.error("------患者出入院修改信息:{}", patMedInhosp); | 
 |  |  |                     patMedInhospService.updatePatMedInhosp(patMedInhosp); | 
 |  |  |                 } else { | 
 |  |  |                     log.error("----患者出入院新增信息:{}", patMedInhosp); | 
 |  |  |                     patMedInhospService.insertPatMedInhosp(patMedInhosp); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     private String getKey() { | 
 |  |  |         Map<String, String> map = new HashMap<>(); | 
 |  |  | 
 |  |  |         return key; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private String getWXCode(String idcard, String url, String taskName, String taskDesc, String submitprompt) { | 
 |  |  |     private String getDXCode(String address, String ShouJiHM, String FaSongNR, String FaSongRID, String FaSongRXM, Map<String, Object> headerMap, String token) { | 
 |  |  |         Map<String, Object> map = new LinkedHashMap<>(); | 
 |  |  |  | 
 |  |  |         Map<String, Object> YeWuXX = new LinkedHashMap<>(); | 
 |  |  |         Map<String, Object> DuanXinXX = new LinkedHashMap<>(); | 
 |  |  |         DuanXinXX.put("ShouJiHM", ShouJiHM); | 
 |  |  |         DuanXinXX.put("FaSongNR", FaSongNR); | 
 |  |  |         DuanXinXX.put("FaSongRID", FaSongRID); | 
 |  |  |         DuanXinXX.put("FaSongRXM", FaSongRXM); | 
 |  |  |         YeWuXX.put("DuanXinXX", DuanXinXX); | 
 |  |  |  | 
 |  |  |         map.put("XiaoXiTou", headerMap); | 
 |  |  |         map.put("YeWuXX", YeWuXX); | 
 |  |  |  | 
 |  |  |         String body = new Gson().toJson(map); | 
 |  |  |  | 
 |  |  | //        String result = HttpUtils.sendPost(address, body); | 
 |  |  |         String result = null; | 
 |  |  |         try { | 
 |  |  |             result = OkHttpExample.sendPostRequest(address, body, token); | 
 |  |  |         } catch (IOException e) { | 
 |  |  |             e.printStackTrace(); | 
 |  |  |         } | 
 |  |  |         log.info("【getDXCode】短信发送结果:{}", result); | 
 |  |  |  | 
 |  |  |         JSONObject jsonObject = JSONObject.parseObject(result); | 
 |  |  |         String code = (String) jsonObject.toString(); | 
 |  |  |         return code; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     private String getWXCode(String idcard, String url, String taskName, String taskDesc, String phone, String setPatientname, String setPatientid, List<String> wxqqxx) { | 
 |  |  |         XinHuaWXReq xinHuaWXReq = new XinHuaWXReq(); | 
 |  |  |         xinHuaWXReq.setIdcard(idcard); | 
 |  |  |         xinHuaWXReq.setUrl(url); | 
 |  |  |         xinHuaWXReq.setKeyword1("浙中医大二院出院随访"); | 
 |  |  |         xinHuaWXReq.setKeyword2(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); | 
 |  |  |         xinHuaWXReq.setKeyword3(taskName); | 
 |  |  |         xinHuaWXReq.setKeyword4("疾病康复注意事项"); | 
 |  |  |         xinHuaWXReq.setPatientid(setPatientid); | 
 |  |  |         xinHuaWXReq.setPatientname(setPatientname); | 
 |  |  |         xinHuaWXReq.setMobile(phone); | 
 |  |  |         xinHuaWXReq.setMedcardno(null); | 
 |  |  |         xinHuaWXReq.setTitlename(taskName); | 
 |  |  |         xinHuaWXReq.setContent(taskDesc); | 
 |  |  |         xinHuaWXReq.setAppid(wxqqxx.get(1)); | 
 |  |  |         log.info("【getWXCode】微信公众号请求参数:{}", xinHuaWXReq); | 
 |  |  |         String body = new Gson().toJson(xinHuaWXReq); | 
 |  |  |         String encode = encode(wxqqxx.get(2).concat(body)); | 
 |  |  |         Map<String, String> headerMap = new HashMap<>(); | 
 |  |  |         headerMap.put("sign", encode); | 
 |  |  |         String result = HttpUtils.sendPostByHeader(wxqqxx.get(3), body, headerMap); | 
 |  |  |  | 
 |  |  |         String result = HttpUtils.sendPost(thirdWXUrl, new Gson().toJson(xinHuaWXReq)); | 
 |  |  |         JSONObject jsonObject = JSONObject.parseObject(result); | 
 |  |  |         log.error("jsonObject的数据为:{}", jsonObject.toString()); | 
 |  |  | //        String code = (String) jsonObject.get("code"); | 
 |  |  |         return jsonObject.toString(); | 
 |  |  |         String code = (String) jsonObject.toString(); | 
 |  |  |         return code; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | //    public static void main(String[] args) { | 
 |  |  | //        LocalDateTime originalDateTime = LocalDateTime.now(); | 
 |  |  | //        LocalDateTime startOfDay = originalDateTime.with(LocalTime.MIN); | 
 |  |  | //        System.out.println("Original DateTime: " + originalDateTime); | 
 |  |  | //        System.out.println("Start of Day: " + startOfDay); | 
 |  |  | //    } | 
 |  |  |  | 
 |  |  |     public String encode(String arg) { | 
 |  |  |         if (arg == null) { | 
 |  |  |             arg = ""; | 
 |  |  |         } | 
 |  |  |         MessageDigest md5 = null; | 
 |  |  |         try { | 
 |  |  |             md5 = MessageDigest.getInstance("MD5"); | 
 |  |  |             md5.update(arg.getBytes("UTF-8")); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             e.printStackTrace(); | 
 |  |  |         } | 
 |  |  |         return toHex(md5.digest()); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void collectHIS() { | 
 |  |  |         try { | 
 |  |  |             // HIS数据采集 | 
 |  |  |             log.info("【dealHisData】HIS开始采集数据"); | 
 |  |  |             ichService.sync(); | 
 |  |  |             log.info("【dealHisData】HIS结束采集数据"); | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             log.error("【dealHisData】HIS数据采集异常", e); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  | } |