| | |
| | | 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.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.WxGZHEnum; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.HttpUtil; |
| | | 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.ServiceSubtaskMapper; |
| | | import com.smartor.mapper.ServiceTaskMapper; |
| | |
| | | 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.security.MessageDigest; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | |
| | | 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 |
| | |
| | | @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; |
| | |
| | | |
| | | @Value("${hosp_info_url}") |
| | | private String hospInfoUrl; |
| | | |
| | | @Value("${appid}") |
| | | private String appid; |
| | | |
| | | @Value("${server.port}") |
| | | private String port; |
| | | |
| | | 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 dealHisData2() { |
| | | //将患者信息、出院、门诊数据全部采集 |
| | | // 指定的开始日期 |
| | | LocalDate endDate = LocalDate.of(2024, 9, 1); |
| | | LocalDate endDate = LocalDate.of(2025, 3, 3); |
| | | // 当前日期 |
| | | LocalDate currentDate = LocalDate.now(); |
| | | // 定义日期格式 |
| | |
| | | * 处理患者信息,进入子任务表 |
| | | */ |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | ServiceSubtaskVO ivrTaskcall = new ServiceSubtaskVO(); |
| | | ivrTaskcall.setTaskid(commonTaskcallMQ.getTaskid()); |
| | | ivrTaskcall.setSendstate(2L); |
| | | List<ServiceSubtask> selectServiceSubtaskList = iServiceSubtaskService.selectServiceSubtaskList(ivrTaskcall); |
| | | List<ServiceSubtask> subtaskList = iServiceSubtaskService.selectServiceSubtaskList(ivrTaskcall); |
| | | |
| | | // 按照 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<>(); |
| | |
| | | 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不知道怎么配置) |
| | |
| | | } |
| | | } |
| | | //将要执行的放到缓存中 |
| | | redisCache.setCacheList("cache-0", list); |
| | | |
| | | if (list.size() > 0) { |
| | | // redisCache.setCacheListLeft("cache-0", list); |
| | | redisCache.setCacheListLeftAndDistinct("cache-0", list); |
| | | } |
| | | } else if (descByCode.equals("多媒体")) { |
| | | //多媒体 |
| | | } else if (descByCode.equals("纸质")) { |
| | | //纸质 |
| | | } else if (descByCode.equals("微信小程序")) { |
| | | //微信小程序 |
| | | for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { |
| | | log.error("微信小程序期任务发送---------进来了吗?{}", serviceSubtask); |
| | | log.error("ivrTask1的值为:{}", 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(); |
| | |
| | | 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()); |
| | |
| | | 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)); |
| | | 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) { |
| | | //丽水的短信发送方式 |
| | | String address = MsgLSEnum.getAddressByCode(serviceSubtask.getOrgid()); |
| | | if (StringUtils.isEmpty(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.error("---------丽水短信发送入参address:{}, sendMagParam:{}, orgid:{}-------", address,sendMagParam,serviceSubtask.getOrgid()); |
| | | String dxCode = getDXCode(address, sendMagParam.getPhone(), sendMagParam.getContent(), "", "", MsgLSEnum.getHeaderByCode(serviceSubtask.getOrgid())); |
| | | log.error("---------丽水短信发送结果:{}-------", 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()); |
| | |
| | | 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); |
| | | // String wxCode = getWXCode(serviceSubtask.getSfzh(), url, serviceSubtask.getTaskName(), serviceSubtask.getTaskDesc(), "无"); |
| | | |
| | | //获取微信公众号请求信息根据机构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()); |
| | | ss.setFinishtime(new Date()); |
| | | 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()); |
| | | ss.setFinishtime(new Date()); |
| | | 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()); |
| | |
| | | String filename = null; |
| | | if (cry.equals("0")) filename = "入院信息" + System.currentTimeMillis(); |
| | | if (cry.equals("1")) filename = "出院信息" + System.currentTimeMillis(); |
| | | File file = new File("D:\\public\\华卓集成平台数据\\" + filename); |
| | | File file = new File("D:\\public\\HIS数据采集\\" + filename); |
| | | if (!file.exists()) { |
| | | // 如果文件不存在,则创建新文件 |
| | | try { |
| | |
| | | patArchive.setSex(thiedInhospInfo.getPatiRecordGender().equals("男") ? 1L : 2L); |
| | | patArchive.setNation(thiedInhospInfo.getPatiNation()); |
| | | patArchive.setNativePlace(thiedInhospInfo.getPatiNationality()); |
| | | patArchive.setPlaceOfResidence(thiedInhospInfo.getPatiHomeAddr()); |
| | | patArchive.setPlaceOfResidence(StringUtils.isNotEmpty(thiedInhospInfo.getPatiHomeAddr()) ? thiedInhospInfo.getPatiHomeAddr().replace("null", "") : ""); |
| | | try { |
| | | if (StringUtils.isNotEmpty(thiedInhospInfo.getPatiBirthday())) |
| | | patArchive.setBirthdate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(thiedInhospInfo.getPatiBirthday())); |
| | | patArchive.setBirthdate(new SimpleDateFormat("yyyy-MM-dd").parse(thiedInhospInfo.getPatiBirthday())); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | patMedInhosp.setNurseId(thiedInhospInfo.getNurseId()); |
| | | patMedInhosp.setNurseName(thiedInhospInfo.getNurseName()); |
| | | patMedInhosp.setSerialnum(thiedInhospInfo.getInpatientId()); |
| | | patMedInhosp.setFuflag("1"); |
| | | if (cry.equals("0")) { |
| | | patMedInhosp.setInhospstate("0"); |
| | | } else if (cry.equals("1")) { |
| | |
| | | patMedInhosp.setLeavehospitaldistrictcode(thiedInhospInfo.getCurrWardId()); |
| | | patMedInhosp.setLeavehospitaldistrictname(thiedInhospInfo.getCurrWardName()); |
| | | patMedInhosp.setLeaveldeptid(thiedInhospInfo.getCurrDeptCode()); |
| | | patMedInhosp.setOrgid("1"); |
| | | //如果是出院,先通过患者编号和流水号去查一下,患者是否存在,如果存在,则进行修改 |
| | | PatMedInhosp inhosp = new PatMedInhosp(); |
| | | inhosp.setPatno(patArchive.getPatientno()); |
| | |
| | | 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) { |
| | | 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("DuanXinXX", DuanXinXX); |
| | | |
| | | String body = new Gson().toJson(map); |
| | | |
| | | String result = HttpUtils.sendPost(address, body); |
| | | log.error("--------result的值为:{}-----", 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.error("----getWXCode---xinHuaWXReq的出参为:{}", 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()); |
| | | } |
| | | } |