| | |
| | | package com.ruoyi.web.component; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.google.gson.Gson; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.enums.ServiceFromEnum; |
| | | 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.ruoyi.web.task.PhoneTask; |
| | | import com.smartor.common.SendService; |
| | | import com.smartor.config.RobotPhoneUtils; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.mapper.ServiceSubtaskMapper; |
| | | import com.smartor.mapper.ServiceTaskMapper; |
| | | import com.smartor.mapper.SvyTaskMapper; |
| | | import com.smartor.mapper.SvyTaskSingleMapper; |
| | | 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.data.redis.connection.Message; |
| | |
| | | import org.springframework.data.redis.listener.RedisMessageListenerContainer; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.math.BigInteger; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | |
| | | private String thirdWXUrl; |
| | | |
| | | @Autowired |
| | | private IIvrTaskTemplateService ivrTaskTemplateService; |
| | | private IServiceOutPathService iServiceOutPathService; |
| | | |
| | | @Autowired |
| | | private ServiceSubtaskMapper ivrTaskcallMapper; |
| | |
| | | @Autowired |
| | | IBaseSmsaccountService baseSmsaccountService; |
| | | |
| | | @Value("${xhsmsPath}") |
| | | private String xhsmsPath; |
| | | |
| | | // 创建固定大小的线程池 |
| | | private static final ExecutorService executorService = Executors.newFixedThreadPool(10); |
| | | |
| | |
| | | } else { |
| | | commonTaskcallMQ = mapper.readValue(content, CommonTaskcallMQ.class); |
| | | } |
| | | if (commonTaskcallMQ.getTaskType() == 1) { |
| | | //随访 |
| | | sfHandle(commonTaskcallMQ, ip); |
| | | } else if (commonTaskcallMQ.getTaskType() == 2) { |
| | | //问卷 |
| | | wjHandle(commonTaskcallMQ, ip); |
| | | } else if (commonTaskcallMQ.getTaskType() == 3) { |
| | | //宣教 |
| | | xjHandle(commonTaskcallMQ, ip); |
| | | } |
| | | if (commonTaskcallMQ != null) tsakHandle(commonTaskcallMQ, ip, commonTaskcallMQ.getTaskType()); |
| | | |
| | | //处理完成,移除redis |
| | | redisCache.deleteObject(message.toString()); |
| | | //将状态改成完成 |
| | | ServiceTask serviceTask = new ServiceTask(); |
| | | serviceTask.setTaskid(Long.valueOf(commonTaskcallMQ.getTaskid())); |
| | | serviceTask.setSendState(5); |
| | | serviceTask.setSendState(5L); |
| | | serviceTask.setFail(1L); |
| | | svyTaskMapper.updateServiceTask(serviceTask); |
| | | |
| | | } catch (Exception e) { |
| | | Integer integer = redisCache.getCacheObject(commonTaskcallMQ.getTaskid().toString()); |
| | | if (integer != null && integer == 2) { |
| | | if (integer != null && integer == 3) { |
| | | redisCache.deleteObject(message.toString()); |
| | | ServiceTask serviceTask = new ServiceTask(); |
| | | serviceTask.setTaskid(Long.valueOf(commonTaskcallMQ.getTaskid().toString())); |
| | | serviceTask.setFail(0L); |
| | | svyTaskMapper.updateServiceTask(serviceTask); |
| | | //将消息从队列中删除 |
| | | } else if (integer == null) { |
| | | redisCache.setCacheObject(commonTaskcallMQ.getTaskid().toString(), 1, 120, TimeUnit.MINUTES); |
| | | } else { |
| | | redisCache.setCacheObject(commonTaskcallMQ.getTaskid().toString(), integer + 1, 120, TimeUnit.MINUTES); |
| | | } |
| | | |
| | | log.error("============消费失败,尝试消息补发再次消费!============== {}", e.getMessage()); |
| | | redisCache.setCacheObject(message.toString(), message.toString(), 60, TimeUnit.SECONDS); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 随访任务处理 |
| | | * 任务处理 |
| | | * |
| | | * @param commonTaskcallMQ |
| | | */ |
| | | public void sfHandle(CommonTaskcallMQ commonTaskcallMQ, String ip) { |
| | | log.error("进随访了吗?{}", commonTaskcallMQ); |
| | | public void tsakHandle(CommonTaskcallMQ commonTaskcallMQ, String ip, Integer type) { |
| | | log.error("进任务了吗?{}", commonTaskcallMQ); |
| | | //判断一下commonTaskcallMQ中的stopstate是否与ivr_task中的一致,不一致,则说明是暂停了 |
| | | ServiceTask ivrTask1 = ivrTaskMapper.selectServiceTaskByTaskid(commonTaskcallMQ.getTaskid()); |
| | | if (ivrTask1.getStopState() != commonTaskcallMQ.getStopState()) { |
| | |
| | | if (StringUtils.isNotEmpty(commonTaskcallMQ.getPreachform())) { |
| | | //如何任务发送方式不为空 |
| | | String[] split = commonTaskcallMQ.getPreachform().split(","); |
| | | System.out.println("split的值为:" + split); |
| | | log.error("split的值为:{}", split); |
| | | |
| | | //定义一个集合,用与存没有执行的子任务ID |
| | | List<Long> subIds = new ArrayList<>(); |
| | | //临时存没有执行的子任务ID |
| | | List<Long> lssubIds = new ArrayList<>(); |
| | | //是否将全部患者者发送完 |
| | | Boolean isSend = false; |
| | | |
| | | aa: |
| | | for (String serviceFrom : split) { |
| | | String descByCode = ServiceFromEnum.getDescByCode(Integer.valueOf(serviceFrom)); |
| | | //这里可以考虑用策略模式优化一下,不然太难看了 |
| | | |
| | | // //通过模板ID获取模板问题 |
| | | // IvrTaskTemplateVO ivrTaskTemplateVO = new IvrTaskTemplateVO(); |
| | | // ivrTaskTemplateVO.setId(Long.valueOf(commonTaskcallMQ.getTemplateid())); |
| | | // IvrTaskTemplateVO ivrTaskTemplateVO1 = ivrTaskTemplateService.selectInfoByCondition(ivrTaskTemplateVO); |
| | | if (isSend == true) { |
| | | break aa; |
| | | } |
| | | |
| | | //通过任务ID拿到患者信息 |
| | | ServiceSubtaskVO ivrTaskcall = new ServiceSubtaskVO(); |
| | | ivrTaskcall.setTaskid(commonTaskcallMQ.getTaskid()); |
| | | ivrTaskcall.setSendstate(1L); |
| | | List<ServiceSubtask> selectServiceSubtaskList = ivrTaskcallMapper.selectServiceSubtaskList(ivrTaskcall); |
| | | if (descByCode.equals("电话")) { |
| | | for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { |
| | | ServiceTask ivrTask = ivrTaskMapper.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 = ivrTaskcallMapper.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 = ivrTaskcallMapper.selectServiceSubtaskList(serviceSubtask1); |
| | | for (ServiceSubtask serviceSubtask2 : selectServiceSubtaskList1) { |
| | | if (StringUtils.isEmpty(value)) { |
| | | value = "," + serviceSubtask2.getId().toString() + ","; |
| | | } else { |
| | | value = value + "," + serviceSubtask2.getId().toString() + ","; |
| | | } |
| | | } |
| | | redisCache.setCacheObject(key, value); |
| | | //先判断一下,subIds是否为空,如果不为空,只执行subIds里的患者 |
| | | if (CollectionUtils.isNotEmpty(subIds)) { |
| | | boolean contains = subIds.contains(serviceSubtask.getId()); |
| | | //如果contains不为true,说明当前的患者已经发送成功,直接循环下一个人就行 |
| | | if (!contains) continue; |
| | | } |
| | | |
| | | //任务发送记录(这个代码应该写在phoneTask中,先写在这,后面再改) |
| | | try { |
| | | ServiceTask ivrTask = ivrTaskMapper.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()); |
| | | log.error("缓存中serviceSubtask1的值为:{}", serviceSubtask1); |
| | | List<ServiceSubtask> selectServiceSubtaskList1 = ivrTaskcallMapper.selectServiceSubtaskList(serviceSubtask1); |
| | | for (ServiceSubtask serviceSubtask2 : selectServiceSubtaskList1) { |
| | | if (StringUtils.isEmpty(value)) { |
| | | value = "," + serviceSubtask2.getId().toString() + ","; |
| | | } else { |
| | | if (!value.contains("," + serviceSubtask2.getId().toString())) |
| | | value = value + "," + serviceSubtask2.getId().toString() + ","; |
| | | } |
| | | } |
| | | log.error("缓存中cache-0的值为:{}", value); |
| | | redisCache.setCacheObject("cache-0", value); |
| | | } else { |
| | | //非立即发送 |
| | | String value = redisCache.getCacheObject(key); |
| | | ServiceSubtaskVO serviceSubtask1 = new ServiceSubtaskVO(); |
| | | serviceSubtask1.setTaskid(commonTaskcallMQ.getTaskid()); |
| | | List<ServiceSubtask> selectServiceSubtaskList1 = ivrTaskcallMapper.selectServiceSubtaskList(serviceSubtask1); |
| | | for (ServiceSubtask serviceSubtask2 : selectServiceSubtaskList1) { |
| | | if (StringUtils.isEmpty(value)) { |
| | | value = "," + serviceSubtask2.getId().toString() + ","; |
| | | } else { |
| | | value = value + "," + serviceSubtask2.getId().toString() + ","; |
| | | } |
| | | } |
| | | redisCache.setCacheObject(key, value); |
| | | } |
| | | } catch (Exception exception) { |
| | | ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); |
| | | serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); |
| | | serviceSubtaskRecord.setSubtaskId(serviceSubtask.getId()); |
| | | serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); |
| | | serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); |
| | | serviceSubtaskRecord.setPreachform("3"); |
| | | serviceSubtaskRecord.setResult("fail"); |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | serviceSubtaskRecord.setRemark("电话发送失败"); |
| | | log.error("电话发送失败:{}", exception.getMessage()); |
| | | lssubIds.add(serviceSubtask.getId()); |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(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.setUuid(UUID.randomUUID().toString()); |
| | | serviceSubtaskRecord.setSubtaskId(serviceSubtask.getId()); |
| | | serviceSubtaskRecord.setUuid(uuid); |
| | | serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); |
| | | serviceSubtaskRecord.setPreachform("3"); |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | serviceSubtaskRecord.setRemark("电话发送成功"); |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); |
| | | |
| | | // //通过多线程的方式去打电话 |
| | | // executorService.submit(new PhoneTask(serviceSubtask, ivrTaskTemplateVO1, redisCache, sendService, phonePath, robotPhoneUtils)); |
| | | } |
| | | if (CollectionUtils.isEmpty(lssubIds)) { |
| | | //如果“临时子任务”为空,说明全发送完了 |
| | | isSend = true; |
| | | } |
| | | //将子任务ID清空,将“临时子任务”数据 放到 “子任务” 中 |
| | | subIds.clear(); |
| | | subIds.addAll(lssubIds); |
| | | lssubIds.clear(); |
| | | } else if (descByCode.equals("多媒体")) { |
| | | //多媒体 |
| | | return; |
| | | continue; |
| | | } else if (descByCode.equals("纸质")) { |
| | | //纸质 |
| | | return; |
| | | continue; |
| | | } 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.setUrl(ip + ":" + req_path + "/followvisit/particty?param1=" + taskId + "¶m2=" + patid + "¶m5=false"); |
| | | Boolean aBoolean = sendService.sendMsg(sendMagParam); |
| | | //先判断一下,subIds是否为空,如果不为空,只执行subIds里的患者 |
| | | if (CollectionUtils.isNotEmpty(subIds)) { |
| | | boolean contains = subIds.contains(serviceSubtask.getId()); |
| | | //如果contains不为true,说明当前的患者已经发送成功,直接循环下一个人就行 |
| | | if (!contains) continue; |
| | | } |
| | | |
| | | try { |
| | | String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key); |
| | | SendMagParam sendMagParam = new SendMagParam(); |
| | | sendMagParam.setType("4"); |
| | | if (type == 1) { |
| | | //随访 |
| | | ServiceOutPath serviceOutPath = new ServiceOutPath(); |
| | | serviceOutPath.setParam1(taskId); |
| | | serviceOutPath.setParam2(patid); |
| | | serviceOutPath.setCreateTime(new Date()); |
| | | iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | // sendMagParam.setUrl(ip + ":" + req_path + "/followvisit/particty?param1=" + taskId + "¶m2=" + patid + "¶m5=false"); |
| | | //转成16进制 |
| | | String format = String.format("%03X", serviceOutPath.getId()); |
| | | serviceOutPath.setRadix(format); |
| | | serviceOutPath.setUpdateTime(new Date()); |
| | | iServiceOutPathService.updateServiceOutPath(serviceOutPath); |
| | | sendMagParam.setPhone(serviceSubtask.getPhone()); |
| | | sendMagParam.setUrl(ip + ":" + req_path + "/sf?p=" + format); |
| | | sendMagParam.setContent("【新华医院】您好,邀请您填写出院随访调查表,请点击" + sendMagParam.getUrl() + "填写。感谢您配合!"); |
| | | } else if (type == 2) { |
| | | //问券(问题) |
| | | ServiceOutPath serviceOutPath = new ServiceOutPath(); |
| | | serviceOutPath.setParam1(taskId); |
| | | serviceOutPath.setParam2(patid); |
| | | // serviceOutPath.setParam3(URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString())); |
| | | serviceOutPath.setParam3(ivrTask1.getTaskName()); |
| | | serviceOutPath.setCreateTime(new Date()); |
| | | iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | String format = String.format("%03X", serviceOutPath.getId()); |
| | | serviceOutPath.setRadix(format); |
| | | serviceOutPath.setUpdateTime(new Date()); |
| | | iServiceOutPathService.updateServiceOutPath(serviceOutPath); |
| | | // sendMagParam.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() + "填写。感谢您配合!"); |
| | | } else if (type == 3) { |
| | | //宣教 |
| | | ServiceOutPath serviceOutPath = new ServiceOutPath(); |
| | | serviceOutPath.setParam1(taskId); |
| | | serviceOutPath.setParam2(patid); |
| | | // serviceOutPath.setParam3(URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString())); |
| | | serviceOutPath.setParam3(ivrTask1.getTaskName()); |
| | | serviceOutPath.setCreateTime(new Date()); |
| | | iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | String format = String.format("%03X", serviceOutPath.getId()); |
| | | serviceOutPath.setRadix(format); |
| | | serviceOutPath.setUpdateTime(new Date()); |
| | | iServiceOutPathService.updateServiceOutPath(serviceOutPath); |
| | | // sendMagParam.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() + "查看。感谢您配合!"); |
| | | } |
| | | //短信还需要模板 |
| | | 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)); |
| | | if (s.equals("true")) { |
| | | ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); |
| | | serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); |
| | | serviceSubtaskRecord.setSubtaskId(serviceSubtask.getId()); |
| | | serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); |
| | | serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); |
| | | serviceSubtaskRecord.setPreachform("4"); |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | serviceSubtaskRecord.setRemark("短信发送成功"); |
| | | lssubIds.add(serviceSubtask.getId()); |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); |
| | | continue; |
| | | } |
| | | } catch (Exception e) { |
| | | ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); |
| | | serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); |
| | | serviceSubtaskRecord.setSubtaskId(serviceSubtask.getId()); |
| | | serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); |
| | | serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); |
| | | serviceSubtaskRecord.setPreachform("4"); |
| | | serviceSubtaskRecord.setResult("fail"); |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | serviceSubtaskRecord.setRemark("短信发送失败"); |
| | | log.error("短信发送失败:{}", e.getMessage()); |
| | | lssubIds.add(serviceSubtask.getId()); |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(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.setUuid(UUID.randomUUID().toString()); |
| | | serviceSubtaskRecord.setSubtaskId(serviceSubtask.getId()); |
| | | serviceSubtaskRecord.setUuid(uuid); |
| | | serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); |
| | | serviceSubtaskRecord.setPreachform("4"); |
| | | serviceSubtaskRecord.setPreachform("5"); |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | serviceSubtaskRecord.setResult(aBoolean == true ? "成功" : "失败"); |
| | | serviceSubtaskRecord.setResult("success"); |
| | | serviceSubtaskRecord.setRemark("短信发送成功"); |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); |
| | | } |
| | | if (CollectionUtils.isEmpty(lssubIds)) { |
| | | //如果“临时子任务”为空,说明全发送完了 |
| | | isSend = true; |
| | | } |
| | | //将子任务ID清空,将“临时子任务”数据 放到 “子任务” 中 |
| | | subIds.clear(); |
| | | subIds.addAll(lssubIds); |
| | | lssubIds.clear(); |
| | | } else if (descByCode.equals("公众号")) { |
| | | //公众号 |
| | | 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("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); |
| | | 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); |
| | | String url = null; |
| | | |
| | | String url = ip + ":" + req_path + "/outsideChain?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName() + "¶m5=false"; |
| | | String wxCode = getWXCode(serviceSubtask.getIdcardno(), url); |
| | | //// 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"; |
| | | //// } |
| | | // if (type == 1) { |
| | | // //随访 |
| | | // ServiceOutPath serviceOutPath = new ServiceOutPath(); |
| | | // serviceOutPath.setParam1(taskId); |
| | | // serviceOutPath.setParam2(patid); |
| | | // serviceOutPath.setCreateTime(new Date()); |
| | | // iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | // String format = String.format("%03X", serviceOutPath.getId()); |
| | | // serviceOutPath.setRadix(format); |
| | | // serviceOutPath.setUpdateTime(new Date()); |
| | | // iServiceOutPathService.updateServiceOutPath(serviceOutPath); |
| | | //// sendMagParam.setUrl(ip + ":" + req_path + "/followvisit/particty?param1=" + taskId + "¶m2=" + patid + "¶m5=false"); |
| | | // url = ip + ":" + req_path + "/sf?p=" + format; |
| | | // } else if (type == 2) { |
| | | // //问券 |
| | | // ServiceOutPath serviceOutPath = new ServiceOutPath(); |
| | | // serviceOutPath.setParam1(taskId); |
| | | // serviceOutPath.setParam2(patid); |
| | | //// serviceOutPath.setParam3(URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString())); |
| | | // serviceOutPath.setParam3(ivrTask1.getTaskName()); |
| | | // serviceOutPath.setCreateTime(new Date()); |
| | | // iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | // String format = String.format("%03X", serviceOutPath.getId()); |
| | | // serviceOutPath.setRadix(format); |
| | | // serviceOutPath.setUpdateTime(new Date()); |
| | | // iServiceOutPathService.updateServiceOutPath(serviceOutPath); |
| | | //// sendMagParam.setUrl(ip + ":" + req_path + "/outsideChainwt?param1=" + taskId + "¶m2=" + patid + "¶m3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "¶m5=false"); |
| | | // url = ip + ":" + req_path + "/wt?p=" + format; |
| | | // } else if (type == 3) { |
| | | // //宣教 |
| | | // ServiceOutPath serviceOutPath = new ServiceOutPath(); |
| | | // serviceOutPath.setParam1(taskId); |
| | | // serviceOutPath.setParam2(patid); |
| | | //// serviceOutPath.setParam3(URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString())); |
| | | // serviceOutPath.setParam3(ivrTask1.getTaskName()); |
| | | // serviceOutPath.setCreateTime(new Date()); |
| | | // iServiceOutPathService.insertServiceOutPath(serviceOutPath); |
| | | // String format = String.format("%03X", serviceOutPath.getId()); |
| | | // serviceOutPath.setRadix(format); |
| | | // serviceOutPath.setUpdateTime(new Date()); |
| | | // iServiceOutPathService.updateServiceOutPath(serviceOutPath); |
| | | // url = ip + ":" + req_path + "/xj?p=" + format; |
| | | // } |
| | | // |
| | | // String wxCode = getWXCode(serviceSubtask.getSfzh(), url, serviceSubtask.getTaskName(), serviceSubtask.getTaskDesc(), "无"); |
| | | // Map<String, Object> map = JSONObject.parseObject(wxCode, Map.class); |
| | | // if (!map.isEmpty()) { |
| | | serviceSubtask.setResult("success"); |
| | | serviceSubtask.setSendstate(3L); |
| | | if (aBoolean == false) { |
| | | ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); |
| | | serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); |
| | | serviceSubtaskRecord.setSubtaskId(serviceSubtask.getId()); |
| | | serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); |
| | | serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); |
| | | serviceSubtaskRecord.setPreachform("5"); |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | serviceSubtaskRecord.setRemark(map.get("msg").toString()); |
| | | lssubIds.add(serviceSubtask.getId()); |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); |
| | | continue; |
| | | } |
| | | // } |
| | | } catch (Exception e) { |
| | | ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); |
| | | serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); |
| | | serviceSubtaskRecord.setSubtaskId(serviceSubtask.getId()); |
| | | serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); |
| | | serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); |
| | | serviceSubtaskRecord.setPreachform("5"); |
| | | serviceSubtaskRecord.setResult("fail"); |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | serviceSubtaskRecord.setRemark("公众号发送失败"); |
| | | log.error("公众号发送失败:{}", e.getMessage()); |
| | | lssubIds.add(serviceSubtask.getId()); |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(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.setUuid(UUID.randomUUID().toString()); |
| | | serviceSubtaskRecord.setUuid(uuid); |
| | | serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); |
| | | serviceSubtaskRecord.setPreachform("4"); |
| | | serviceSubtaskRecord.setPreachform("5"); |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | serviceSubtaskRecord.setResult("成功"); |
| | | if (wxCode.equals("0")) serviceSubtaskRecord.setResult("失败"); |
| | | serviceSubtaskRecord.setResult("success"); |
| | | serviceSubtaskRecord.setRemark("公众号发送成功"); |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); |
| | | } |
| | | if (CollectionUtils.isEmpty(lssubIds)) { |
| | | //如果“临时子任务”为空,说明全发送完了 |
| | | isSend = true; |
| | | } |
| | | //将子任务ID清空,将“临时子任务”数据 放到 “子任务” 中 |
| | | subIds.clear(); |
| | | subIds.addAll(lssubIds); |
| | | lssubIds.clear(); |
| | | } |
| | | //通知 MQ 消息已被接收,可以ACK(从队列中删除)了 (这个需要根据业务再去处理ACK) |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 宣教任务处理 |
| | | * |
| | | * @param commonTaskcallMQ |
| | | */ |
| | | private void xjHandle(CommonTaskcallMQ commonTaskcallMQ, String ip) { |
| | | log.error("进宣教了吗?{}", commonTaskcallMQ); |
| | | //判断一下commonTaskcallMQ中的stopstate是否与ivr_task中的一致,不一致,则说明是暂停了 |
| | | ServiceTask ivrTask1 = ivrTaskMapper.selectServiceTaskByTaskid(commonTaskcallMQ.getTaskid()); |
| | | if (ivrTask1.getStopState() != commonTaskcallMQ.getStopState()) { |
| | | //将消息从队列中剔除 |
| | | return; |
| | | } |
| | | |
| | | if (StringUtils.isNotEmpty(commonTaskcallMQ.getPreachform())) { |
| | | //如何任务发送方式不为空 |
| | | String[] split = commonTaskcallMQ.getPreachform().split(","); |
| | | System.out.println("split的值为:" + split); |
| | | for (String serviceFrom : split) { |
| | | String descByCode = ServiceFromEnum.getDescByCode(Integer.valueOf(serviceFrom)); |
| | | //这里可以考虑用策略模式优化一下,不然太难看了 |
| | | |
| | | //通过模板ID获取模板问题 |
| | | IvrTaskTemplateVO ivrTaskTemplateVO1 = null; |
| | | if (commonTaskcallMQ.getTaskType().equals("1")) { |
| | | IvrTaskTemplateVO ivrTaskTemplateVO = new IvrTaskTemplateVO(); |
| | | ivrTaskTemplateVO.setId(Long.valueOf(commonTaskcallMQ.getTemplateid())); |
| | | ivrTaskTemplateVO1 = ivrTaskTemplateService.selectInfoByCondition(ivrTaskTemplateVO); |
| | | if (CollectionUtils.isNotEmpty(subIds)) { |
| | | //如果全部的发送方式都发完了,还有是未发送的,需要去subTask表中,记录一下,发送失败 |
| | | for (Long id : subIds) { |
| | | ServiceSubtask serviceSubtask = new ServiceSubtask(); |
| | | serviceSubtask.setResult("error"); |
| | | serviceSubtask.setRemark("发送失败"); |
| | | serviceSubtask.setSendstate(5L); |
| | | serviceSubtask.setId(id); |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | } |
| | | //通过任务ID拿到患者信息 |
| | | ServiceSubtaskVO ivrTaskcall = new ServiceSubtaskVO(); |
| | | ivrTaskcall.setTaskid(commonTaskcallMQ.getTaskid()); |
| | | List<ServiceSubtask> ivrTaskcalls = ivrTaskcallMapper.selectServiceSubtaskList(ivrTaskcall); |
| | | if (descByCode.equals("电话")) { |
| | | for (ServiceSubtask ivrTaskcall1 : ivrTaskcalls) { |
| | | ServiceTask ivrTask = ivrTaskMapper.selectServiceTaskByTaskid(ivrTaskcall1.getTaskid()); |
| | | if (ivrTask.getSendState() != null && ivrTask.getSendState() == 3 || ivrTask.getSendState() != null && ivrTask.getSendState() == 4) { |
| | | //如何任务被“暂停”或“终止” |
| | | break; |
| | | } |
| | | |
| | | //任务发送记录(这个代码应该写在phoneTask中,先写在这,后面再改) |
| | | ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); |
| | | serviceSubtaskRecord.setTaskid(ivrTaskcall1.getTaskid().toString()); |
| | | serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); |
| | | serviceSubtaskRecord.setTasktype(ivrTaskcall1.getType()); |
| | | serviceSubtaskRecord.setPreachform("3"); |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); |
| | | |
| | | //通过多线程的方式去打电话 |
| | | executorService.submit(new PhoneTask(ivrTaskcall1, 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 ivrTaskSingle : ivrTaskcalls) { |
| | | String patid = rsaPublicKeyExample.encryptedData(ivrTaskSingle.getPatid().toString(), pub_key); |
| | | SendMagParam sendMagParam = new SendMagParam(); |
| | | sendMagParam.setType("4"); |
| | | sendMagParam.setUrl(ip + ":" + req_path + "/followvisit/particty?param1=" + taskId + "¶m2=" + patid + "¶m5=false"); |
| | | Boolean aBoolean = sendService.sendMsg(sendMagParam); |
| | | |
| | | //任务发送记录 |
| | | ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); |
| | | serviceSubtaskRecord.setTaskid(ivrTaskSingle.getTaskid().toString()); |
| | | serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); |
| | | serviceSubtaskRecord.setTasktype(ivrTaskSingle.getType()); |
| | | serviceSubtaskRecord.setPreachform("4"); |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | serviceSubtaskRecord.setResult(aBoolean == true ? "成功" : "失败"); |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); |
| | | } |
| | | } else if (descByCode.equals("公众号")) { |
| | | //公众号 |
| | | RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); |
| | | String taskId = rsaPublicKeyExample.encryptedData(ivrTask1.getTaskid().toString(), pub_key); |
| | | for (ServiceSubtask ivrTaskSingle : ivrTaskcalls) { |
| | | String patid = rsaPublicKeyExample.encryptedData(ivrTaskSingle.getPatid().toString(), pub_key); |
| | | // SendMagParam sendMagParam = new SendMagParam(); |
| | | // sendMagParam.setType("5"); |
| | | // sendMagParam.setUrl(ip + ":" + req_path + "/outsideChainxj?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName() + "¶m5=false"); |
| | | // log.info("链接完整路径:{}", req_path + "/outsideChainxj?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(ivrTaskSingle.getOpenid()); |
| | | //新华医院有自己的公众号发送接口,我们的先不用(先保留,其它项目可以用) |
| | | // Boolean aBoolean = sendService.sendMsg(sendMagParam); |
| | | // log.error("是否发送成功:{}", aBoolean); |
| | | |
| | | String url = ip + ":" + req_path + "/outsideChainxj?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName() + "¶m5=false"; |
| | | String wxCode = getWXCode(ivrTaskSingle.getIdcardno(), url); |
| | | //任务发送记录 |
| | | ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); |
| | | serviceSubtaskRecord.setTaskid(ivrTaskSingle.getTaskid().toString()); |
| | | serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); |
| | | serviceSubtaskRecord.setTasktype(ivrTaskSingle.getType()); |
| | | serviceSubtaskRecord.setPreachform("4"); |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | serviceSubtaskRecord.setResult("成功"); |
| | | if (!wxCode.equals("0")) { |
| | | serviceSubtaskRecord.setResult("失败"); |
| | | } |
| | | |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); |
| | | } |
| | | } |
| | | //通知 MQ 消息已被接收,可以ACK(从队列中删除)了 (这个需要根据业务再去处理ACK) |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 问卷任务处理 |
| | | * |
| | | * @param commonTaskcallMQ |
| | | */ |
| | | private void wjHandle(CommonTaskcallMQ commonTaskcallMQ, String ip) { |
| | | log.error("进问卷了吗?{}", commonTaskcallMQ); |
| | | //判断一下commonTaskcallMQ中的stopstate是否与ivr_task中的一致,不一致,则说明是暂停了 |
| | | ServiceTask svyTask = svyTaskMapper.selectServiceTaskByTaskid(commonTaskcallMQ.getTaskid()); |
| | | log.error("svyTask.getStopState()的值为:{} , commonTaskcallMQ.getStopState()的值为:{}", svyTask.getStopState(), commonTaskcallMQ.getStopState()); |
| | | |
| | | if (svyTask.getStopState() != commonTaskcallMQ.getStopState()) { |
| | | //将消息从队列中剔除 |
| | | return; |
| | | } |
| | | |
| | | if (StringUtils.isNotEmpty(commonTaskcallMQ.getPreachform())) { |
| | | //如何任务发送方式不为空 |
| | | String[] split = commonTaskcallMQ.getPreachform().split(","); |
| | | System.out.println("split的值为:" + split); |
| | | for (String serviceFrom : split) { |
| | | String descByCode = ServiceFromEnum.getDescByCode(Integer.valueOf(serviceFrom)); |
| | | //这里可以考虑用策略模式优化一下,不然太难看了 |
| | | |
| | | //通过模板ID获取模板问题 |
| | | SvyTaskTemplateVO svyTaskTemplateVO = new SvyTaskTemplateVO(); |
| | | svyTaskTemplateVO.setId(Long.valueOf(commonTaskcallMQ.getTemplateid())); |
| | | SvyTaskTemplateVO svyTaskTemplateVO1 = iSvyTaskTemplateService.selectInfoByCondition(svyTaskTemplateVO); |
| | | |
| | | //通过任务ID拿到患者信息 |
| | | ServiceSubtaskVO serviceSubtaskVO = new ServiceSubtaskVO(); |
| | | serviceSubtaskVO.setTaskid(commonTaskcallMQ.getTaskid()); |
| | | List<ServiceSubtask> selectServiceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO); |
| | | log.error("selectServiceSubtaskList数据是多少?{}", selectServiceSubtaskList.size()); |
| | | if (descByCode.equals("电话")) { |
| | | for (ServiceSubtask svyTaskSingle1 : selectServiceSubtaskList) { |
| | | ServiceTask svyTask1 = svyTaskMapper.selectServiceTaskByTaskid(svyTaskSingle1.getTaskid()); |
| | | if (svyTask1.getSendState() != null && svyTask1.getSendState().equals("3") || svyTask1.getSendState() != null && svyTask1.getSendState().equals("4")) { |
| | | //如何任务被“暂停”或“终止” |
| | | break; |
| | | } |
| | | |
| | | //任务发送记录(这个代码应该写在phoneTask中,先写在这,后面再改) |
| | | ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); |
| | | serviceSubtaskRecord.setTaskid(svyTaskSingle1.getTaskid().toString()); |
| | | serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); |
| | | serviceSubtaskRecord.setTasktype(svyTaskSingle1.getType()); |
| | | serviceSubtaskRecord.setPreachform("3"); |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); |
| | | //通过多线程的方式去打电话 |
| | | // executorService.submit(new PhoneTask(ivrTaskcall1, ivrTaskTemplateVO1, redisCache, sendService, phonePath, robotPhoneUtils)); |
| | | } |
| | | } else if (descByCode.equals("多媒体")) { |
| | | //多媒体 |
| | | } else if (descByCode.equals("纸质")) { |
| | | //纸质 |
| | | } else if (descByCode.equals("短信")) { |
| | | //短信 |
| | | } else if (descByCode.equals("公众号")) { |
| | | log.error("进问卷公众号了吗?{}", descByCode); |
| | | //公众号 |
| | | RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); |
| | | String taskId = rsaPublicKeyExample.encryptedData(svyTask.getTaskid().toString(), pub_key); |
| | | for (ServiceSubtask svyTaskSingle1 : selectServiceSubtaskList) { |
| | | String patid = rsaPublicKeyExample.encryptedData(svyTaskSingle1.getPatid().toString(), pub_key); |
| | | String url = ip + ":" + req_path + "/outsideChainwt?param1=" + taskId + "¶m2=" + patid + "¶m3=" + svyTask.getTaskName() + "¶m5=false"; |
| | | //这个是我们自己的微信公众号发送方式, |
| | | SendMagParam sendMagParam = new SendMagParam(); |
| | | sendMagParam.setType("5"); |
| | | sendMagParam.setUrl(url); |
| | | log.info("链接完整路径:{}", req_path + "/outsideChainwt?param1=" + taskId + "¶m2=" + patid + "¶m3=" + svyTask.getTaskName() + "¶m5=false"); |
| | | //这个模板ID先写死,后面做成可选 |
| | | sendMagParam.setTmpCode("oG3pJHPVWpE81DmZsua_2tKwgJ97r0qz37z56ns7NB4"); |
| | | Map map = new HashMap(); |
| | | map.put("first", svyTask.getTaskName()); |
| | | sendMagParam.setContent(JSON.toJSONString(map)); |
| | | sendMagParam.setOpenid(svyTaskSingle1.getOpenid()); |
| | | Boolean aBoolean = sendService.sendMsg(sendMagParam); |
| | | log.error("发送成功了吗?{}", aBoolean); |
| | | // String wxCode = getWXCode(svyTaskSingle1.getIdcardno(), url); |
| | | |
| | | //任务发送记录 |
| | | ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); |
| | | serviceSubtaskRecord.setTaskid(svyTaskSingle1.getTaskid().toString()); |
| | | serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); |
| | | serviceSubtaskRecord.setTasktype(svyTaskSingle1.getType()); |
| | | serviceSubtaskRecord.setPreachform("4"); |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | serviceSubtaskRecord.setResult("成功"); |
| | | // if (!wxCode.equals("0")) { |
| | | // serviceSubtaskRecord.setResult("失败"); |
| | | // } |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); |
| | | } |
| | | } |
| | | //通知 MQ 消息已被接收,可以ACK(从队列中删除)了 (这个需要根据业务再去处理ACK) |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | // /** |
| | | // * 机器人第一句话语音 |
| | |
| | | return key; |
| | | } |
| | | |
| | | private String getWXCode(String idcard, String url) { |
| | | 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(null); |
| | | xinHuaWXReq.setKeyword2(null); |
| | | xinHuaWXReq.setKeyword3(null); |
| | | xinHuaWXReq.setKeyword4(null); |
| | | 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"); |
| | | String code = (String) jsonObject.toString(); |
| | | return code; |
| | | } |
| | | |