| | |
| | | |
| | | 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 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.*; |
| | | |
| | |
| | | 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("---------------------------"); |
| | | //数据解析 |
| | |
| | | List<ServiceTask> serviceTasks = serviceTaskMapper.selectServiceTaskList(st); |
| | | log.error("serviceTasks进来了吗?{}", serviceTasks); |
| | | for (ServiceTask serviceTask : serviceTasks) { |
| | | |
| | | //通过taskId,获取未执行的子任务信息 |
| | | ServiceSubtaskVO serviceSubtask = new ServiceSubtaskVO(); |
| | | serviceSubtask.setTaskid(serviceTask.getTaskid()); |
| | | serviceSubtask.setSendstate(2L); |
| | | List<ServiceSubtask> selectServiceSubtaskList = iServiceSubtaskService.selectServiceSubtaskList(serviceSubtask); |
| | | log.error("selectServiceSubtaskList进来了吗?{}", selectServiceSubtaskList); |
| | | if (CollectionUtils.isNotEmpty(selectServiceSubtaskList)) { |
| | | for (ServiceSubtask serviceSubtask1 : selectServiceSubtaskList) { |
| | | //如果患者的发送日期是今天,则进行发送 |
| | | try { |
| | | boolean dateToday = isDateToday(serviceSubtask1.getLongSendTime()); |
| | | if (dateToday) { |
| | | //先判断患者是不是还要发送 |
| | | PatArchive patArchive = patArchiveService.selectPatArchiveByPatid(serviceSubtask1.getPatid()); |
| | | if (!Objects.isNull(patArchive) && patArchive.getNotrequiredFlag() == "1") { |
| | | //不需要发送 |
| | | serviceSubtask1.setResult("error"); |
| | | serviceSubtask1.setRemark(patArchive.getNotrequiredreason()); |
| | | serviceSubtask1.setSendstate(4L); |
| | | serviceSubtask1.setFinishtime(new Date()); |
| | | iServiceSubtaskService.insertServiceSubtask(serviceSubtask1); |
| | | continue; |
| | | } |
| | | |
| | | log.error("dateToday进来了吗?{}", dateToday); |
| | | CommonTaskcallMQ commonTaskcallMQ = new CommonTaskcallMQ(); |
| | | commonTaskcallMQ.setTaskid(serviceTask.getTaskid()); |
| | | commonTaskcallMQ.setPreachform(serviceSubtask1.getServiceform()); |
| | | commonTaskcallMQ.setSendType("2"); |
| | | Map<String, Object> map = sfHandlle(commonTaskcallMQ, localIP); |
| | | //发送完成后,修改状态 |
| | | serviceSubtask1.setSendstate(3L); |
| | | if ((Boolean) map.get("succ") == false) { |
| | | serviceSubtask1.setResult("success"); |
| | | } else { |
| | | serviceSubtask1.setResult("error"); |
| | | serviceSubtask1.setRemark(map.get("msg").toString()); |
| | | } |
| | | iServiceSubtaskService.updateServiceSubtask(serviceSubtask1); |
| | | } |
| | | } catch (Exception e) { |
| | | String guid = UUID.randomUUID().toString(); |
| | | log.error("长期任务,发送失败原因:{},{}", e.getMessage(), guid); |
| | | serviceSubtask1.setResult("error"); |
| | | serviceSubtask1.setRemark("系统错误"); |
| | | serviceSubtask1.setSendstate(5L); |
| | | serviceSubtask1.setFinishtime(new Date()); |
| | | serviceSubtask1.setGuid(guid); |
| | | iServiceSubtaskService.insertServiceSubtask(serviceSubtask1); |
| | | } |
| | | } |
| | | } |
| | | |
| | | CommonTaskcallMQ commonTaskcallMQ = new CommonTaskcallMQ(); |
| | | commonTaskcallMQ.setTaskid(serviceTask.getTaskid()); |
| | | commonTaskcallMQ.setPreachform(serviceTask.getPreachform()); |
| | | commonTaskcallMQ.setSendType("2"); |
| | | sfHandlle(commonTaskcallMQ, localIP); |
| | | } |
| | | } |
| | | |
| | |
| | | * @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); |
| | |
| | | return (calendarToCheck.get(Calendar.YEAR) == todayYear && calendarToCheck.get(Calendar.MONTH) == todayMonth && calendarToCheck.get(Calendar.DAY_OF_MONTH) == todayDay); |
| | | } |
| | | |
| | | public Map<String, Object> sfHandlle(CommonTaskcallMQ commonTaskcallMQ, String ip) { |
| | | public void sfHandlle(CommonTaskcallMQ commonTaskcallMQ, String ip) { |
| | | log.error("sfHandlle进来了吗?{}", commonTaskcallMQ); |
| | | //判断一下commonTaskcallMQ中的stopstate是否与ivr_task中的一致,不一致,则说明是暂停了 |
| | | ServiceTask ivrTask1 = serviceTaskMapper.selectServiceTaskByTaskid(commonTaskcallMQ.getTaskid()); |
| | |
| | | //通过任务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) { |
| | |
| | | } |
| | | } else if (descByCode.equals("多媒体")) { |
| | | //多媒体 |
| | | return null; |
| | | } else if (descByCode.equals("纸质")) { |
| | | //纸质 |
| | | return null; |
| | | } else if (descByCode.equals("短信")) { |
| | | //短信 |
| | | // http://localhost:8099/followvisit/particty?param1=3¶m2=348 |
| | |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | serviceSubtaskRecord.setResult(aBoolean == true ? "成功" : "失败"); |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); |
| | | return null; |
| | | |
| | | } |
| | | } else if (descByCode.equals("公众号")) { |
| | | log.error("公众号进来了吗?{}", descByCode); |
| | |
| | | String taskId = rsaPublicKeyExample.encryptedData(ivrTask1.getTaskid().toString(), pub_key); |
| | | for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { |
| | | log.error("serviceSubtask---------进来了吗?{}", serviceSubtask); |
| | | String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key); |
| | | String url = null; |
| | | try { |
| | | url = ip + ":" + req_path + "/outsideChainwt?param1=" + taskId + "¶m2=" + patid + "¶m3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "¶m5=false"; |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | String wxCode = getWXCode(serviceSubtask.getSfzh(), url, serviceSubtask.getTaskName(), serviceSubtask.getTaskDesc(), "无"); |
| | | Map<String, Object> map = JSONObject.parseObject(wxCode, Map.class); |
| | | 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); |
| | | return map; |
| | | //任务发送记录 |
| | | 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) |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | @Transactional |
| | | public void getInHospInfo(String cry, LocalDateTime startTime, LocalDateTime endTime) { |
| | | // 获取当前日期和时间 |
| | | LocalDateTime currentDateTime = LocalDateTime.now(); |
| | | // 获取前一天的日期和时间 |
| | | LocalDateTime previousDateTime = currentDateTime.minusDays(1); |
| | | // 定义日期时间格式 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.S"); |
| | | Map<String, String> req = new HashMap<>(); |
| | |
| | | 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", currentDateTime.format(formatter)); |
| | | header.put("x-hcsb-msgdate", startTime.format(formatter)); |
| | | String result = HttpUtils.sendPostByHeader(hospInfoUrl, new Gson().toJson(req), header); |
| | | //数据解析 |
| | | Gson gson = new Gson(); |
| | |
| | | patArchive.setPatientno(thiedInhospInfo.getPatiMediaNo()); |
| | | patArchive.setSourcefrom(2); |
| | | patArchive.setPattype("2"); |
| | | if (thiedInhospInfo.getOutWayId().equals("4")) { |
| | | 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()); |
| | |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | patArchive.setAge(Long.valueOf(thiedInhospInfo.getTreateAge())); |
| | | 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()); |
| | |
| | | } else { |
| | | patArchive = patArchives.get(0); |
| | | } |
| | | |
| | | log.error("入参的patArchive:{}", patArchive); |
| | | PatMedInhosp patMedInhosp = new PatMedInhosp(); |
| | | patMedInhosp.setPatid(patArchive.getId()); |
| | |
| | | patMedInhosp.setLeavehospitaldistrictcode(thiedInhospInfo.getCurrWardId()); |
| | | patMedInhosp.setLeavehospitaldistrictname(thiedInhospInfo.getCurrWardName()); |
| | | patMedInhosp.setLeaveldeptid(thiedInhospInfo.getCurrDeptCode()); |
| | | patMedInhospService.insertPatMedInhosp(patMedInhosp); |
| | | //如果是出院,先通过患者编号和流水号去查一下,患者是否存在,如果存在,则进行修改 |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | } |
| | |
| | | |
| | | String result = HttpUtils.sendPost(thirdWXUrl, new Gson().toJson(xinHuaWXReq)); |
| | | JSONObject jsonObject = JSONObject.parseObject(result); |
| | | String code = (String) jsonObject.get("code"); |
| | | return code; |
| | | // String code = (String) jsonObject.get("code"); |
| | | return jsonObject.toString(); |
| | | } |
| | | } |