| package com.ruoyi.quartz.task; | 
|   | 
| import com.alibaba.fastjson2.JSON; | 
| import com.alibaba.fastjson2.JSONObject; | 
| 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.ServiceFromEnum; | 
| import com.ruoyi.common.utils.DtoConversionUtils; | 
| 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.smartor.domain.*; | 
| import com.smartor.mapper.ServiceTaskMapper; | 
| import com.smartor.service.*; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.apache.commons.collections4.CollectionUtils; | 
| 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.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.time.LocalDate; | 
| import java.time.LocalDateTime; | 
| import java.time.ZoneId; | 
| import java.time.format.DateTimeFormatter; | 
| import java.util.*; | 
|   | 
| /** | 
|  * 定时任务调度测试 | 
|  * | 
|  * @author ruoyi | 
|  */ | 
| @Slf4j | 
| @Component("ryTask") | 
| public class RyTask { | 
|     @Autowired | 
|     private IServiceThirdDataService iServiceThirdDataService; | 
|   | 
|     @Autowired | 
|     private IServiceSubtaskAnswerService serviceSubtaskAnswerService; | 
|   | 
|     @Autowired | 
|     private IPatMedInhospService iPatMedInhospService; | 
|   | 
|     @Autowired | 
|     private IServiceSubtaskService iServiceSubtaskService; | 
|   | 
|     @Autowired | 
|     private PlatformTransactionManager transactionManager; | 
|   | 
|     @Value("${localIP}") | 
|     private String localIP; | 
|   | 
|     @Value("${pub_key}") | 
|     private String pub_key; | 
|   | 
|     @Value("${thirdWXUrl}") | 
|     private String thirdWXUrl; | 
|   | 
|     @Value("${req_path}") | 
|     private String req_path; | 
|   | 
|     @Autowired | 
|     private ServiceTaskMapper serviceTaskMapper; | 
|   | 
|     @Autowired | 
|     private SendService sendService; | 
|   | 
|     @Autowired | 
|     private RedisCache redisCache; | 
|   | 
|     @Autowired | 
|     private IServiceSubtaskRecordService serviceSubtaskRecordService; | 
|   | 
|     @Autowired | 
|     IBaseSmsaccountService baseSmsaccountService; | 
|   | 
|     @Autowired | 
|     IPatArchiveService patArchiveService; | 
|   | 
|     @Autowired | 
|     IPatMedInhospService patMedInhospService; | 
|   | 
|     @Autowired | 
|     IPatMedOuthospService patMedOuthospService; | 
|   | 
|     @Autowired | 
|     ISvyTaskTemplateService svyTaskTemplateService; | 
|   | 
|     @Value("${hosp_info_url}") | 
|     private String hospInfoUrl; | 
|   | 
|     public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) { | 
|         System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i)); | 
|     } | 
|   | 
|     public void ryParams(String params) { | 
|         System.out.println("执行有参方法:" + params); | 
|     } | 
|   | 
|     public void ryNoParams() { | 
|         System.out.println("执行无参方法"); | 
|     } | 
|   | 
|     public void importData() { | 
| //        String filePath = "path/to/your/file.txt"; // 替换为你的文件路径 | 
| // | 
| //        try { | 
| //            // 读取文件内容 | 
| //            String jsonContent = new String(Files.readAllBytes(Paths.get(filePath))); | 
| // | 
| //            // 创建ObjectMapper对象 | 
| //            ObjectMapper objectMapper = new ObjectMapper(); | 
| // | 
| //            // 解析JSON为JsonNode | 
| //            JsonNode rootNode = objectMapper.readTree(jsonContent); | 
| //            // 获取resultList | 
| //            JsonNode resultListNode = rootNode.path("results").path("resultList"); | 
| //            // 遍历resultList中的每个对象 | 
| //            for (JsonNode item : resultListNode) { | 
| //                String userName = item.path("staffNum").asText(); | 
| //                String idCard = item.path("idCard").asText(); | 
| //                String personnelStampNum = item.path("defaultWardId").asText(); | 
| //                String personnelStampNum = item.path("defaultWardName").asText(); | 
| //                String deptName = item.path("defaultDeptName").asText(); | 
| //                String deptCode = item.path("defaultDeptId").asText(); | 
| //                String phonenumber = item.path("telphone").asText(); | 
| //                String nickName = item.path("staffName").asText(); | 
| //                String sex = item.path("staffSex").asText(); | 
| // | 
| //            } | 
| // | 
| //        } catch (IOException e) { | 
| //            e.printStackTrace(); | 
| //        } | 
|   | 
|     } | 
|   | 
|     public void analysisData() { | 
|         System.out.println("---------------------------"); | 
|         //数据解析 | 
|         ServiceThirdData serviceThirdData = new ServiceThirdData(); | 
|         serviceThirdData.setDataType("ADT^A03"); | 
|         serviceThirdData.setIsDeal(0); | 
|         serviceThirdData.setCreateTime(new Date()); | 
|         iServiceThirdDataService.queryList(serviceThirdData); | 
|   | 
|     } | 
|   | 
|     /** | 
|      * 定时处理外链的数据 | 
|      */ | 
|     public void runServiceSubTaskAnswer() { | 
|         serviceSubtaskAnswerService.saveQuestionAnswer(null); | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 处理his数据 | 
|      */ | 
|     public void dealHisData() { | 
|         //将患者信息、出院、门诊数据全部采集 | 
|         // 获取当前日期和时间 | 
|         LocalDateTime endTime = LocalDateTime.now(); | 
|         // 获取前一天的日期和时间 | 
|         LocalDateTime startTime = endTime.minusDays(1); | 
|         getInHospInfo("0", startTime, endTime); | 
|         getInHospInfo("1", startTime, endTime); | 
|   | 
|         //调用dealOupHospInfo数据处理方法,处理完后,将“出院表的check_flag=1” | 
|         //获取当前日期 (精确到天)往前推相应天数(在指定的基础模板中找对应的天数), | 
|         //循环患者信息,根据患者"出院诊断ICD值”获取到相当的模板(获取取相应的天数); | 
|         //根据查询出来的模板,去固定任务(固定任务,已经将模板也固定了)去匹配模板 | 
|         //根据匹配出来的模板和任务与患者信息,将数据插入到子任务表中 | 
|     } | 
|   | 
|     public void dealHisData2() { | 
|         //将患者信息、出院、门诊数据全部采集 | 
|         // 指定的开始日期 | 
|         LocalDate endDate = LocalDate.of(2024, 9, 1); | 
|         // 当前日期 | 
|         LocalDate currentDate = LocalDate.now(); | 
|         // 定义日期格式 | 
|         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd "); | 
|   | 
|         // 从开始日期到当前日期逐天打印 | 
|         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()); | 
|         } | 
|   | 
|     } | 
|   | 
|     /** | 
|      * 处理患者信息,进入子任务表 | 
|      */ | 
|     public void dealOutHospInfo() { | 
|         iPatMedInhospService.dealOutHospInfo(); | 
|     } | 
|   | 
|     /** | 
|      * 长期任务执行 | 
|      */ | 
|     public void longTaskSend() { | 
|         //获取任务信息 | 
|         ServiceTask st = new ServiceTask(); | 
|         st.setDelFlag("0"); | 
|         st.setLongTask(1); | 
|         List<ServiceTask> serviceTasks = serviceTaskMapper.selectServiceTaskList(st); | 
|         log.error("serviceTasks进来了吗?{}", serviceTasks); | 
|         for (ServiceTask serviceTask : serviceTasks) { | 
|             CommonTaskcallMQ commonTaskcallMQ = new CommonTaskcallMQ(); | 
|             commonTaskcallMQ.setTaskid(serviceTask.getTaskid()); | 
|             commonTaskcallMQ.setPreachform(serviceTask.getPreachform()); | 
|             commonTaskcallMQ.setSendType("2"); | 
|             sfHandlle(commonTaskcallMQ, localIP); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 判断日期是否是今天 | 
|      * | 
|      * @param date | 
|      * @return | 
|      */ | 
|     public boolean isDateToday(Date date) { | 
|         //如果给的日期小于当前日期,也直接发送 | 
|         LocalDateTime localDateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); | 
|         if (localDateTime.isBefore(LocalDateTime.now())) { | 
|             return true; | 
|         } | 
|         // 获取当前日期 | 
|         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); | 
|     } | 
|   | 
|     public void sfHandlle(CommonTaskcallMQ commonTaskcallMQ, String ip) { | 
|         log.error("sfHandlle进来了吗?{}", commonTaskcallMQ); | 
|         //判断一下commonTaskcallMQ中的stopstate是否与ivr_task中的一致,不一致,则说明是暂停了 | 
|         ServiceTask ivrTask1 = serviceTaskMapper.selectServiceTaskByTaskid(commonTaskcallMQ.getTaskid()); | 
|   | 
|         if (StringUtils.isNotEmpty(commonTaskcallMQ.getPreachform())) { | 
|             //如何任务发送方式不为空 | 
|             String[] split = commonTaskcallMQ.getPreachform().split(","); | 
|             log.error("split进来了吗?{}", 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); | 
|                 if (descByCode.equals("电话")) { | 
|                     for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { | 
|                         ServiceTask ivrTask = serviceTaskMapper.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); | 
|                         if (ivrTask.getSendState() != null && ivrTask.getSendState() == 3 || ivrTask.getSendState() != null && ivrTask.getSendState() == 4) { | 
|                             //如何任务被“暂停”或“终止” | 
|                             break; | 
|                         } | 
|                         //获取到value值最少的key | 
|                         String key = getKey(); | 
|                         if (commonTaskcallMQ.getSendType().equals("2")) { | 
|                             //说明是立即发送 | 
|                             String value = redisCache.getCacheObject("cache-0"); | 
|                             ServiceSubtaskVO serviceSubtask1 = new ServiceSubtaskVO(); | 
|                             serviceSubtask1.setTaskid(commonTaskcallMQ.getTaskid()); | 
|                             List<ServiceSubtask> selectServiceSubtaskList1 = iServiceSubtaskService.selectServiceSubtaskList(serviceSubtask1); | 
|                             for (ServiceSubtask serviceSubtask2 : selectServiceSubtaskList1) { | 
|                                 if (StringUtils.isEmpty(value)) { | 
|                                     value = "," + serviceSubtask2.getId().toString() + ","; | 
|                                 } else { | 
|                                     value = value + "," + serviceSubtask2.getId().toString() + ","; | 
|                                 } | 
|                             } | 
|                             redisCache.setCacheObject("cache-0", value); | 
|                         } else { | 
|                             //非立即发送 | 
|                             String value = redisCache.getCacheObject(key); | 
|                             ServiceSubtaskVO serviceSubtask1 = new ServiceSubtaskVO(); | 
|                             serviceSubtask1.setTaskid(commonTaskcallMQ.getTaskid()); | 
|                             List<ServiceSubtask> selectServiceSubtaskList1 = iServiceSubtaskService.selectServiceSubtaskList(serviceSubtask1); | 
|                             for (ServiceSubtask serviceSubtask2 : selectServiceSubtaskList1) { | 
|                                 if (StringUtils.isEmpty(value)) { | 
|                                     value = "," + serviceSubtask2.getId().toString() + ","; | 
|                                 } else { | 
|                                     value = value + "," + serviceSubtask2.getId().toString() + ","; | 
|                                 } | 
|                             } | 
|                             redisCache.setCacheObject(key, value); | 
|                         } | 
|   | 
|                         //任务发送记录(这个代码应该写在phoneTask中,先写在这,后面再改) | 
|                         ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); | 
|                         serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); | 
|                         serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); | 
|                         serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); | 
|                         serviceSubtaskRecord.setPreachform("3"); | 
|                         serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); | 
|                         serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); | 
|   | 
| //                        //通过多线程的方式去打电话 | 
| //                        executorService.submit(new PhoneTask(serviceSubtask, ivrTaskTemplateVO1, redisCache, sendService, phonePath, robotPhoneUtils)); | 
|                     } | 
|                 } else if (descByCode.equals("多媒体")) { | 
|                     //多媒体 | 
|                 } else if (descByCode.equals("纸质")) { | 
|                     //纸质 | 
|                 } else if (descByCode.equals("短信")) { | 
|                     //短信 | 
| //                        http://localhost:8099/followvisit/particty?param1=3¶m2=348 | 
|                     //对url中两个参数加密 | 
|                     RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); | 
|                     String taskId = rsaPublicKeyExample.encryptedData(ivrTask1.getTaskid().toString(), pub_key); | 
|   | 
|                     for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { | 
|                         String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key); | 
|                         SendMagParam sendMagParam = new SendMagParam(); | 
|                         sendMagParam.setType("4"); | 
|                         sendMagParam.setPhone(serviceSubtask.getPhone()); | 
|                         sendMagParam.setUrl(ip + ":" + req_path + "/followvisit/particty?param1=" + taskId + "¶m2=" + patid + "¶m5=false"); | 
|                         Boolean aBoolean = sendService.sendMsg(sendMagParam); | 
|   | 
|                         //任务发送记录 | 
|                         ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); | 
|                         serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); | 
|                         serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); | 
|                         serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); | 
|                         serviceSubtaskRecord.setPreachform("4"); | 
|                         serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); | 
|                         serviceSubtaskRecord.setResult(aBoolean == true ? "成功" : "失败"); | 
|                         serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); | 
|   | 
|                     } | 
|                 } else if (descByCode.equals("公众号")) { | 
|                     log.error("公众号进来了吗?{}", descByCode); | 
|                     //公众号 | 
|                     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 { | 
|                                 //先判断患者是不是还要发送 | 
|                                 PatArchive patArchive = patArchiveService.selectPatArchiveByPatid(serviceSubtask.getPatid()); | 
|                                 if (!Objects.isNull(patArchive) && patArchive.getNotrequiredFlag() == "1") { | 
|                                     //不需要发送 | 
|                                     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); | 
|   | 
|                                 //任务发送记录 | 
|                                 ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); | 
|                                 serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); | 
|                                 serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); | 
|                                 serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); | 
|                                 serviceSubtaskRecord.setPreachform("4"); | 
|                                 serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); | 
|                                 serviceSubtaskRecord.setResult("success"); | 
|                                 if (!map.isEmpty() && (Boolean) map.get("succ") == false) | 
|                                     serviceSubtaskRecord.setResult("error"); | 
|                                 serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); | 
|   | 
|                                 //发送完成后,修改状态 | 
|                                 serviceSubtask.setSendstate(3L); | 
|                                 if ((Boolean) map.get("succ") == true) { | 
|                                     serviceSubtask.setResult("success"); | 
|                                 } else { | 
|                                     serviceSubtask.setResult("error"); | 
|                                     serviceSubtask.setRemark(map.get("msg").toString()); | 
|                                 } | 
|                                 iServiceSubtaskService.updateServiceSubtask(serviceSubtask); | 
|                             } catch (Exception e) { | 
|                                 String guid = UUID.randomUUID().toString(); | 
|                                 log.error("长期任务,发送失败原因:{},{}", e.getMessage(), guid); | 
|                                 serviceSubtask.setResult("error"); | 
|                                 serviceSubtask.setRemark("系统错误"); | 
|                                 serviceSubtask.setSendstate(5L); | 
|                                 serviceSubtask.setFinishtime(new Date()); | 
|                                 serviceSubtask.setGuid(guid); | 
|                                 iServiceSubtaskService.updateServiceSubtask(serviceSubtask); | 
|                             } | 
|                         } | 
|                     } | 
|                 } | 
|                 //通知 MQ 消息已被接收,可以ACK(从队列中删除)了   (这个需要根据业务再去处理ACK) | 
|             } | 
|         } | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 获出院患者信息 | 
|      * 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("startTime", startTime.format(formatter)); | 
|             req.put("endTime", 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); | 
|         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.setInhospno(patArchive.getPatientno()); | 
|                 inhosp.setSerialnum(patMedInhosp.getSerialnum()); | 
|                 List<PatMedInhosp> patMedInhosps = patMedInhospService.selectPatMedInhospList(inhosp); | 
|                 if (CollectionUtils.isNotEmpty(patMedInhosps)) { | 
|                     patMedInhospService.updatePatMedInhosp(patMedInhosp); | 
|                 } else { | 
|                     patMedInhospService.insertPatMedInhosp(patMedInhosp); | 
|                 } | 
|   | 
|             } | 
|         } | 
|     } | 
|   | 
|   | 
|     private String getKey() { | 
|         Map<String, String> map = new HashMap<>(); | 
|         for (int i = 0; i < 6; i++) { | 
|             Boolean aBoolean = redisCache.hasKey("cache-" + i); | 
|             if (!aBoolean) { | 
|                 redisCache.setCacheObject("cache-" + i, ""); | 
|                 map.put("cache-" + i, ""); | 
|             } else { | 
|                 map.put("cache-" + i, redisCache.getCacheObject("cache-" + i)); | 
|             } | 
|         } | 
|   | 
|         String key = null; | 
|         String value = ""; | 
|         for (Map.Entry<String, String> entry : map.entrySet()) { | 
|             if (StringUtils.isEmpty(value)) { | 
|                 value = entry.getValue(); | 
|                 key = entry.getKey(); | 
|             } else { | 
|                 if (entry.getValue().split(",").length < value.split(",").length) { | 
|                     value = entry.getValue(); | 
|                     key = entry.getKey(); | 
|                 } | 
|             } | 
|         } | 
|         return key; | 
|     } | 
|   | 
|     private String getWXCode(String idcard, String url, String taskName, String taskDesc, String submitprompt) { | 
|         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("疾病康复注意事项"); | 
|   | 
|         String result = HttpUtils.sendPost(thirdWXUrl, new Gson().toJson(xinHuaWXReq)); | 
|         JSONObject jsonObject = JSONObject.parseObject(result); | 
| //        String code = (String) jsonObject.get("code"); | 
|         return jsonObject.toString(); | 
|     } | 
| } |