|  |  | 
 |  |  | package com.ruoyi.web.component; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson.JSON; | 
 |  |  | import com.alibaba.fastjson2.JSONObject; | 
 |  |  | import com.fasterxml.jackson.databind.ObjectMapper; | 
 |  |  | import com.google.gson.Gson; | 
 |  |  | import com.google.gson.GsonBuilder; | 
 |  |  | import com.ruoyi.common.core.redis.RedisCache; | 
 |  |  | import com.ruoyi.common.enums.MsgLSEnum; | 
 |  |  | import com.ruoyi.common.enums.ServiceFromEnum; | 
 |  |  | import com.ruoyi.common.enums.WxGZHEnum; | 
 |  |  | import com.ruoyi.common.exception.base.BaseException; | 
 |  |  | 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.smartor.config.RobotPhoneUtils; | 
 |  |  | import com.smartor.common.LSHospTokenUtil; | 
 |  |  | import com.smartor.domain.*; | 
 |  |  | import com.smartor.mapper.HeLibraryMapper; | 
 |  |  | import com.smartor.mapper.PatArchiveMapper; | 
 |  |  | import com.smartor.mapper.ServiceSubtaskMapper; | 
 |  |  | import com.smartor.mapper.ServiceTaskMapper; | 
 |  |  | import com.smartor.service.IBaseSmsaccountService; | 
 |  |  | import com.smartor.service.IServiceOutPathService; | 
 |  |  | import com.smartor.service.IServiceSubtaskRecordService; | 
 |  |  | import com.smartor.service.ISvyTaskTemplateService; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.apache.commons.collections4.CollectionUtils; | 
 |  |  | import org.apache.commons.lang3.ObjectUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.beans.factory.annotation.Value; | 
 |  |  | import org.springframework.data.redis.connection.Message; | 
 |  |  | 
 |  |  | import org.springframework.data.redis.listener.RedisMessageListenerContainer; | 
 |  |  | import org.springframework.stereotype.Component; | 
 |  |  |  | 
 |  |  | import java.net.URLEncoder; | 
 |  |  | import java.time.LocalDateTime; | 
 |  |  | import java.time.format.DateTimeFormatter; | 
 |  |  | import java.io.IOException; | 
 |  |  | import java.security.MessageDigest; | 
 |  |  | import java.util.*; | 
 |  |  | import java.util.concurrent.ExecutorService; | 
 |  |  | import java.util.concurrent.Executors; | 
 |  |  | import java.util.concurrent.TimeUnit; | 
 |  |  |  | 
 |  |  | import static cn.hutool.core.convert.Convert.toHex; | 
 |  |  |  | 
 |  |  | @Slf4j | 
 |  |  | @Component//监听此队列 | 
 |  |  | 
 |  |  |     @Value("${req_path}") | 
 |  |  |     private String req_path; | 
 |  |  |  | 
 |  |  |     @Value("${thirdWXUrl}") | 
 |  |  |     private String thirdWXUrl; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private IServiceOutPathService iServiceOutPathService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private ServiceSubtaskMapper ivrTaskcallMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private HeLibraryMapper heLibraryMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private ServiceTaskMapper ivrTaskMapper; | 
 |  |  | 
 |  |  |     private RedisCache redisCache; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private RobotPhoneUtils robotPhoneUtils; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private ServiceTaskMapper svyTaskMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private ServiceSubtaskMapper serviceSubtaskMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private ISvyTaskTemplateService iSvyTaskTemplateService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private IServiceSubtaskRecordService serviceSubtaskRecordService; | 
 |  |  | 
 |  |  |     @Value("${xhsmsPath}") | 
 |  |  |     private String xhsmsPath; | 
 |  |  |  | 
 |  |  |     @Value("${appid}") | 
 |  |  |     private String appid; | 
 |  |  |     @Value("${visitHosp}") | 
 |  |  |     private Integer visitHosp; | 
 |  |  |  | 
 |  |  |     @Value("${server.port}") | 
 |  |  |     private String port; | 
 |  |  |  | 
 |  |  |     // 创建固定大小的线程池 | 
 |  |  |     private static final ExecutorService executorService = Executors.newFixedThreadPool(10); | 
 |  |  | 
 |  |  |     public void onMessage(Message message, byte[] pattern) { | 
 |  |  |         log.info("监听Redis key过期,key:{},channel:{}", message.toString(), new String(pattern)); | 
 |  |  |         String ip = localIP; | 
 |  |  |         log.error("本机的网络IP为:{}", ip); | 
 |  |  |         log.info("本机的网络IP为:{}", ip); | 
 |  |  |         String content = message.toString(); | 
 |  |  |         //判断是不是任务信息,如果不是,直接返回,不需要执行 | 
 |  |  |         if (!content.contains("taskid")) { | 
 |  |  |         if (!content.contains("taskid") || !port.equals("8095")) { | 
 |  |  |             log.error("不是任务信息"); | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  | 
 |  |  |      * @param commonTaskcallMQ | 
 |  |  |      */ | 
 |  |  |     public void tsakHandle(CommonTaskcallMQ commonTaskcallMQ, String ip, Integer type) { | 
 |  |  |         log.error("进任务了吗?{}", commonTaskcallMQ); | 
 |  |  |         log.info("进任务了吗?{}", commonTaskcallMQ); | 
 |  |  |         //判断一下commonTaskcallMQ中的stopstate是否与ivr_task中的一致,不一致,则说明是暂停了 | 
 |  |  |         ServiceTask ivrTask1 = ivrTaskMapper.selectServiceTaskByTaskid(commonTaskcallMQ.getTaskid()); | 
 |  |  |  | 
 |  |  | 
 |  |  |         if (StringUtils.isNotEmpty(commonTaskcallMQ.getPreachform())) { | 
 |  |  |             //如何任务发送方式不为空 | 
 |  |  |             String[] split = commonTaskcallMQ.getPreachform().split(","); | 
 |  |  |             log.error("split的值为:{}", split); | 
 |  |  |             log.info("split的值为:{}", split); | 
 |  |  |  | 
 |  |  |             //定义一个集合,用与存没有执行的子任务ID | 
 |  |  |             List<Long> subIds = new ArrayList<>(); | 
 |  |  | 
 |  |  |                                 //说明是立即发送 | 
 |  |  |                                 ServiceSubtaskVO serviceSubtask1 = new ServiceSubtaskVO(); | 
 |  |  |                                 serviceSubtask1.setTaskid(commonTaskcallMQ.getTaskid()); | 
 |  |  |                                 log.error("缓存中serviceSubtask1的值为:{}", serviceSubtask1); | 
 |  |  |                                 log.info("缓存中serviceSubtask1的值为:{}", serviceSubtask1); | 
 |  |  |                                 List<String> list = new ArrayList<>(); | 
 |  |  |                                 List<ServiceSubtask> selectServiceSubtaskList1 = ivrTaskcallMapper.selectServiceSubtaskList(serviceSubtask1); | 
 |  |  |                                 for (ServiceSubtask serviceSubtask2 : selectServiceSubtaskList1) { | 
 |  |  |                                     list.add(serviceSubtask2.getId().toString()); | 
 |  |  |                                 } | 
 |  |  |                                 log.error("缓存中cache-0的值为:{}", list); | 
 |  |  |                                 log.info("缓存中cache-0的值为:{}", list); | 
 |  |  | //                                redisCache.setCacheListLeft("cache-0", list); | 
 |  |  |                                 redisCache.setCacheListLeftAndDistinct("cache-0", list); | 
 |  |  |                             } else { | 
 |  |  | 
 |  |  |                                 iServiceOutPathService.updateServiceOutPath(serviceOutPath); | 
 |  |  |                                 sendMagParam.setPhone(serviceSubtask.getPhone()); | 
 |  |  |                                 sendMagParam.setUrl(ip + ":" + req_path + "/sf?p=" + format); | 
 |  |  |                                 sendMagParam.setContent("【新华医院】您好,邀请您填写出院随访调查表,请点击" + sendMagParam.getUrl() + "填写。感谢您配合!"); | 
 |  |  |                                 if (visitHosp == 2) { | 
 |  |  |                                     sendMagParam.setContent("您好,邀请您填写出院宣教调查表,请点击" + sendMagParam.getUrl() + "查看。感谢您配合!"); | 
 |  |  |                                 } else if (visitHosp == 1) { | 
 |  |  |                                     sendMagParam.setContent("【新华医院】您好,邀请您填写出院随访调查表,请点击" + sendMagParam.getUrl() + "填写。感谢您配合!"); | 
 |  |  |                                 } | 
 |  |  |  | 
 |  |  |                             } else if (type == 2) { | 
 |  |  |                                 //问券(问题) | 
 |  |  |                                 ServiceOutPath serviceOutPath = new ServiceOutPath(); | 
 |  |  | 
 |  |  | //                                sendMagParam.setUrl(ip + ":" + req_path + "/outsideChainwt?param1=" + taskId + "¶m2=" + patid + "¶m3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "¶m5=false"); | 
 |  |  |                                 sendMagParam.setPhone(serviceSubtask.getPhone()); | 
 |  |  |                                 sendMagParam.setUrl(ip + ":" + req_path + "/wt?p=" + format); | 
 |  |  |                                 sendMagParam.setContent("【新华医院】您好,邀请您填写出院调查表,请点击" + sendMagParam.getUrl() + "填写。感谢您配合!"); | 
 |  |  |                                 if (serviceSubtask.getOrgid().equals("47255004333112711A1001")) { | 
 |  |  |                                     sendMagParam.setContent("【景宁畲族自治县人民医院】您好,邀请您填写出院宣教调查表,请点击" + sendMagParam.getUrl() + "查看。感谢您配合!"); | 
 |  |  |                                 } else if (serviceSubtask.getOrgid().equals("47255004333112711A1001")) { | 
 |  |  |                                     sendMagParam.setContent("【丽水中医院】您好,邀请您填写出院宣教调查表,请点击" + sendMagParam.getUrl() + "查看。感谢您配合!"); | 
 |  |  |                                 } else | 
 |  |  |                                     sendMagParam.setContent("【新华医院】您好,邀请您填写出院调查表,请点击" + sendMagParam.getUrl() + "填写。感谢您配合!"); | 
 |  |  |                             } else if (type == 3) { | 
 |  |  |                                 //宣教 | 
 |  |  |                                 ServiceOutPath serviceOutPath = new ServiceOutPath(); | 
 |  |  |                                 serviceOutPath.setParam1(taskId); | 
 |  |  |                                 serviceOutPath.setParam2(patid); | 
 |  |  |                                 serviceOutPath.setParam6(subId); | 
 |  |  | //                                serviceOutPath.setParam3(URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString())); | 
 |  |  |                                 serviceOutPath.setParam3(ivrTask1.getTaskName()); | 
 |  |  |                                 serviceOutPath.setCreateTime(new Date()); | 
 |  |  |                                 iServiceOutPathService.insertServiceOutPath(serviceOutPath); | 
 |  |  | 
 |  |  |                                 serviceOutPath.setRadix(format); | 
 |  |  |                                 serviceOutPath.setUpdateTime(new Date()); | 
 |  |  |                                 iServiceOutPathService.updateServiceOutPath(serviceOutPath); | 
 |  |  | //                                sendMagParam.setUrl(ip + ":" + req_path + "/outsideChainxj?param1=" + taskId + "¶m2=" + patid + "¶m3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "¶m5=false"); | 
 |  |  |                                 sendMagParam.setPhone(serviceSubtask.getPhone()); | 
 |  |  |                                 sendMagParam.setUrl(ip + ":" + req_path + "/xj?p=" + format); | 
 |  |  |                                 sendMagParam.setContent("【新华医院】您好,邀请您填写出院宣教调查表,请点击" + sendMagParam.getUrl() + "查看。感谢您配合!"); | 
 |  |  |                                 //需要通过模板ID去判断要发的内容是宣教还是通知 | 
 |  |  |                                 HeLibrary heLibrary = heLibraryMapper.selectHeLibraryById(serviceSubtask.getLibtemplateid()); | 
 |  |  |                                 if (heLibrary.getHetype().equals("1")) { | 
 |  |  |                                     sendMagParam.setPhone(serviceSubtask.getPhone()); | 
 |  |  |                                     sendMagParam.setUrl(ip + ":" + req_path + "/xj?p=" + format); | 
 |  |  |                                     if (serviceSubtask.getOrgid().equals("47255004333112711A1001")) { | 
 |  |  |                                         sendMagParam.setContent("【景宁畲族自治县人民医院】您好,邀请您填写出院宣教调查表,请点击" + sendMagParam.getUrl() + "查看。感谢您配合!"); | 
 |  |  |                                     } else if (serviceSubtask.getOrgid().equals("47255004333112711A1001")) { | 
 |  |  |                                         sendMagParam.setContent("【丽水中医院】您好,邀请您填写出院宣教调查表,请点击" + sendMagParam.getUrl() + "查看。感谢您配合!"); | 
 |  |  |                                     } else | 
 |  |  |                                         sendMagParam.setContent("【新华医院】您好,邀请您填写出院宣教调查表,请点击" + sendMagParam.getUrl() + "查看。感谢您配合!"); | 
 |  |  |                                 } else { | 
 |  |  |                                     //通知 | 
 |  |  |                                     sendMagParam.setPhone(serviceSubtask.getPhone()); | 
 |  |  |                                     sendMagParam.setContent(heLibrary.getPreachcontent()); | 
 |  |  |                                 } | 
 |  |  |                             } | 
 |  |  |                             //短信还需要模板 | 
 |  |  |                             Map<String, String> req = new HashMap<>(); | 
 |  |  |                             req.put("phone", sendMagParam.getPhone()); | 
 |  |  |                             req.put("content", sendMagParam.getContent()); | 
 |  |  |                             String s = HttpUtil.postJsonRequest(xhsmsPath, new Gson().toJson(req)); | 
 |  |  |                             String s = null; | 
 |  |  |                             if (visitHosp == 1) { | 
 |  |  |                                 //新华的短信发送方式 | 
 |  |  |                                 Map<String, String> req = new HashMap<>(); | 
 |  |  |                                 req.put("phone", sendMagParam.getPhone()); | 
 |  |  |                                 req.put("content", sendMagParam.getContent()); | 
 |  |  |                                 s = 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()); | 
 |  |  |                                 log.info("-----------token的值为:{}", token); | 
 |  |  |                                 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("---------mq丽水短信发送入参address:{},  sendMagParam:{},  orgid:{}-------", 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("---------丽水短信发送结果:{}-------", dxCode); | 
 |  |  |                                 ObjectMapper objectMapper = new ObjectMapper(); | 
 |  |  |                                 Map<String, Object> textParam = objectMapper.readValue(dxCode, Map.class); | 
 |  |  |                                 String code = textParam.get("Code").toString(); | 
 |  |  |                                 if (code.equals("0")) { | 
 |  |  |                                     s = "true"; | 
 |  |  |                                 } else { | 
 |  |  |                                     throw new BaseException(null); | 
 |  |  |                                 } | 
 |  |  |                             } | 
 |  |  |                             if (s.equals("true")) { | 
 |  |  |                                 //在子任务表里记录一下 | 
 |  |  |                                 String uuid = UUID.randomUUID().toString(); | 
 |  |  |                                 serviceSubtask.setResult("success"); | 
 |  |  |                                 serviceSubtask.setRemark("短信发送成功"); | 
 |  |  |                                 serviceSubtask.setGuid(uuid); | 
 |  |  |                                 serviceSubtask.setSendstate(3L); | 
 |  |  |                                 serviceSubtask.setFinishtime(new Date()); | 
 |  |  |                                 serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); | 
 |  |  |  | 
 |  |  |                                 //任务发送记录 | 
 |  |  |                                 ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); | 
 |  |  |                                 serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); | 
 |  |  |                                 serviceSubtaskRecord.setSubtaskId(serviceSubtask.getId()); | 
 |  |  |                                 serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); | 
 |  |  |                                 serviceSubtaskRecord.setUuid(uuid); | 
 |  |  |                                 serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); | 
 |  |  |                                 serviceSubtaskRecord.setPreachform("4"); | 
 |  |  |                                 serviceSubtaskRecord.setPreachform("5"); | 
 |  |  |                                 serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); | 
 |  |  |                                 serviceSubtaskRecord.setResult("success"); | 
 |  |  |                                 serviceSubtaskRecord.setRemark("短信发送成功"); | 
 |  |  |                                 lssubIds.add(serviceSubtask.getId()); | 
 |  |  |                                 serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); | 
 |  |  |                                 continue; | 
 |  |  |                                 log.error("serviceSubtaskRecord保存成功了吗?:{}", serviceSubtaskRecord); | 
 |  |  |                             } | 
 |  |  |                         } catch (Exception e) { | 
 |  |  |                             ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); | 
 |  |  | 
 |  |  |                             continue; | 
 |  |  |                         } | 
 |  |  |  | 
 |  |  |                         //在子任务表里记录一下 | 
 |  |  |                         String uuid = UUID.randomUUID().toString(); | 
 |  |  |                         serviceSubtask.setResult("success"); | 
 |  |  |                         serviceSubtask.setRemark("短信发送成功"); | 
 |  |  |                         serviceSubtask.setGuid(uuid); | 
 |  |  |                         serviceSubtask.setSendstate(3L); | 
 |  |  |                         serviceSubtask.setFinishtime(new Date()); | 
 |  |  |                         serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); | 
 |  |  |  | 
 |  |  |                         //任务发送记录 | 
 |  |  |                         ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); | 
 |  |  |                         serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); | 
 |  |  |                         serviceSubtaskRecord.setSubtaskId(serviceSubtask.getId()); | 
 |  |  |                         serviceSubtaskRecord.setUuid(uuid); | 
 |  |  |                         serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); | 
 |  |  |                         serviceSubtaskRecord.setPreachform("5"); | 
 |  |  |                         serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); | 
 |  |  |                         serviceSubtaskRecord.setResult("success"); | 
 |  |  |                         serviceSubtaskRecord.setRemark("短信发送成功"); | 
 |  |  |                         serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); | 
 |  |  |                     } | 
 |  |  |                     if (CollectionUtils.isEmpty(lssubIds)) { | 
 |  |  |                         //如果“临时子任务”为空,说明全发送完了 | 
 |  |  | 
 |  |  |                         try { | 
 |  |  |                             SendMagParam sendMagParam = new SendMagParam(); | 
 |  |  |                             sendMagParam.setType("5"); | 
 |  |  | //                            sendMagParam.setUrl(ip + ":" + req_path + "/outsideChain?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName() + "¶m5=false"); | 
 |  |  | //                            log.info("链接完整路径:{}", ip + ":" + req_path + "/outsideChain?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName() + "¶m5=false"); | 
 |  |  | //                            //这个模板ID先写死,后面做成可选 | 
 |  |  | //                            sendMagParam.setTmpCode("oG3pJHPVWpE81DmZsua_2tKwgJ97r0qz37z56ns7NB4"); | 
 |  |  | //                            Map map = new HashMap(); | 
 |  |  | //                            map.put("first", ivrTask1.getTaskName()); | 
 |  |  | //                            sendMagParam.setContent(JSON.toJSONString(map)); | 
 |  |  | //                            sendMagParam.setOpenid(serviceSubtask.getOpenid()); | 
 |  |  | //                            Boolean aBoolean = sendService.sendMsg(sendMagParam); | 
 |  |  | // | 
 |  |  |  | 
 |  |  | //                            if (type == 1) { | 
 |  |  | //                                url = ip + ":" + req_path + "/outsideChain?param1=" + taskId + "¶m2=" + patid + "¶m3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "¶m5=false"; | 
 |  |  | //                            } else if (type == 2) { | 
 |  |  | //                                url = ip + ":" + req_path + "/outsideChainwt?param1=" + taskId + "¶m2=" + patid + "¶m3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "¶m5=false"; | 
 |  |  | //                            } else if (type == 3) { | 
 |  |  | //                                url = ip + ":" + req_path + "/outsideChainxj?param1=" + taskId + "¶m2=" + patid + "¶m3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "¶m5=false"; | 
 |  |  | //                            } | 
 |  |  |                             String url = null; | 
 |  |  |                             Boolean aBoolean = false; | 
 |  |  |                             if (type == 1) { | 
 |  |  | 
 |  |  |                                 url = ip + ":" + req_path + "/xj?p=" + format; | 
 |  |  |                             } | 
 |  |  |                             PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(serviceSubtask.getPatid()); | 
 |  |  |                             String wxCode = getWXCode(serviceSubtask.getSfzh(), url, serviceSubtask.getTaskName(), serviceSubtask.getTaskDesc(), null, patArchive.getName(), patArchive.getPatientno()); | 
 |  |  |                             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; | 
 |  |  |                             } | 
 |  |  |  | 
 |  |  |                             //获取微信公众号请求信息根据机构ID | 
 |  |  |                             log.error("获取微信公众号请求信息根据机构ID:{}", patArchive.getOrgid()); | 
 |  |  |                             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; | 
 |  |  |                             } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                             String wxCode = getWXCode(serviceSubtask.getSfzh(), url, serviceSubtask.getTaskName(), serviceSubtask.getTaskName(), patArchive.getTelcode(), patArchive.getName(), patArchive.getPatidHis(), wxqqxx); | 
 |  |  |                             log.error("wxCode的值为:{}", wxCode); | 
 |  |  |                             Map<String, Object> map = JSONObject.parseObject(wxCode, Map.class); | 
 |  |  |                             log.error("map的值为:{}", map); | 
 |  |  |                             if (!map.isEmpty()) { | 
 |  |  |                                 serviceSubtask.setResult("success"); | 
 |  |  |                                 serviceSubtask.setSendstate(3L); | 
 |  |  |                                 log.error("aBoolean的值为:{}", aBoolean); | 
 |  |  |                                 if (map.get("succ").toString().equals("true")) { | 
 |  |  |                                     aBoolean = true; | 
 |  |  |                                 } | 
 |  |  |                                 if (aBoolean == false) { | 
 |  |  |                                     ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); | 
 |  |  |                                     serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); | 
 |  |  | 
 |  |  |                                     serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); | 
 |  |  |                                     serviceSubtaskRecord.setPreachform("5"); | 
 |  |  |                                     serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); | 
 |  |  |                                     serviceSubtaskRecord.setRemark(map.get("msg").toString()); | 
 |  |  |                                     serviceSubtaskRecord.setRemark(ObjectUtils.isNotEmpty(map.get("msg")) ? map.get("msg").toString() : null); | 
 |  |  |                                     lssubIds.add(serviceSubtask.getId()); | 
 |  |  |                                     serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); | 
 |  |  |                                     continue; | 
 |  |  | 
 |  |  |                     serviceSubtask.setRemark("发送失败"); | 
 |  |  |                     serviceSubtask.setSendstate(5L); | 
 |  |  |                     serviceSubtask.setId(id); | 
 |  |  |                     serviceSubtask.setFinishtime(new Date()); | 
 |  |  | //                    serviceSubtask.setFinishtime(new Date()); | 
 |  |  |                     serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  | 
 |  |  |         return key; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private String getWXCode(String idcard, String url, String taskName, String taskDesc, String Medcardno, String setPatientname, String setPatientid) { | 
 |  |  |     private String getWXCode(String idcard, String url, String taskName, String taskDesc, String phone, String patientname, String setPatientid, List<String> wxqqxx) { | 
 |  |  |         XinHuaWXReq xinHuaWXReq = new XinHuaWXReq(); | 
 |  |  |         xinHuaWXReq.setIdcard(idcard); | 
 |  |  |         xinHuaWXReq.setUrl(url); | 
 |  |  |         xinHuaWXReq.setPatientid(setPatientid); | 
 |  |  |         xinHuaWXReq.setPatientname(setPatientname); | 
 |  |  |         xinHuaWXReq.setMobile(taskName); | 
 |  |  |         xinHuaWXReq.setMedcardno(Medcardno); | 
 |  |  |         xinHuaWXReq.setPatientname(patientname); | 
 |  |  |         xinHuaWXReq.setMobile(phone); | 
 |  |  |         xinHuaWXReq.setMedcardno(null); | 
 |  |  |         xinHuaWXReq.setTitlename(taskName); | 
 |  |  |         xinHuaWXReq.setContent(taskDesc); | 
 |  |  |         xinHuaWXReq.setAppid(appid); | 
 |  |  |         log.error("-----微信公众号的出差为----:{}", xinHuaWXReq); | 
 |  |  |         String result = HttpUtils.sendPost(thirdWXUrl, new Gson().toJson(xinHuaWXReq)); | 
 |  |  |         xinHuaWXReq.setAppid(wxqqxx.get(1)); | 
 |  |  |         log.error("-----微信公众号的出参为----:{}", xinHuaWXReq); | 
 |  |  | //         new Gson().toJson(xinHuaWXReq); | 
 |  |  |         GsonBuilder gb = new GsonBuilder(); | 
 |  |  |         gb.disableHtmlEscaping(); | 
 |  |  |         String body = gb.create().toJson(xinHuaWXReq); | 
 |  |  |  | 
 |  |  |         log.error("encode的入参为wxqqxx :{},   body:{}", wxqqxx.get(2), body); | 
 |  |  |         String encode = encode(wxqqxx.get(2).concat(body)); | 
 |  |  |         log.error("--------encode的值为:{}-----", encode); | 
 |  |  |         Map<String, String> headerMap = new HashMap<>(); | 
 |  |  |         headerMap.put("sign", encode); | 
 |  |  |         String result = HttpUtils.sendPostByHeader(wxqqxx.get(3), body, headerMap); | 
 |  |  |         log.error("--------result的值为:{}-----", result); | 
 |  |  |  | 
 |  |  |         JSONObject jsonObject = JSONObject.parseObject(result); | 
 |  |  |         String code = (String) jsonObject.toString(); | 
 |  |  |         return code; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     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.error("--------result的值为:{}-----", result); | 
 |  |  |  | 
 |  |  |         JSONObject jsonObject = JSONObject.parseObject(result); | 
 |  |  |         String code = (String) jsonObject.toString(); | 
 |  |  |         return code; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     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()); | 
 |  |  |     } | 
 |  |  | } |