| | |
| | | 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.io.UnsupportedEncodingException; |
| | | import java.math.BigInteger; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.time.LocalDateTime; |
| | |
| | | private String thirdWXUrl; |
| | | |
| | | @Autowired |
| | | private IIvrTaskTemplateService ivrTaskTemplateService; |
| | | @Autowired |
| | | private ISvyTaskTemplateService svyTaskTemplateService; |
| | | private IServiceOutPathService iServiceOutPathService; |
| | | |
| | | @Autowired |
| | | private ServiceSubtaskMapper ivrTaskcallMapper; |
| | |
| | | |
| | | @Autowired |
| | | IBaseSmsaccountService baseSmsaccountService; |
| | | |
| | | @Value("${xhsmsPath}") |
| | | private String xhsmsPath; |
| | | |
| | | // 创建固定大小的线程池 |
| | | private static final ExecutorService executorService = Executors.newFixedThreadPool(10); |
| | |
| | | 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()); |
| | | 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() + ","; |
| | | } |
| | | } |
| | | 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(6L); |
| | | 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("多媒体")) { |
| | | //多媒体 |
| | | continue; |
| | |
| | | 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) { |
| | | //先判断一下,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) { |
| | | sendMagParam.setUrl(ip + ":" + req_path + "/followvisit/particty?param1=" + taskId + "¶m2=" + patid + "¶m5=false"); |
| | | } else if (type == 1) { |
| | | sendMagParam.setUrl(ip + ":" + req_path + "/outsideChainwt?param1=" + taskId + "¶m2=" + patid + "¶m3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "¶m5=false"); |
| | | //随访 |
| | | 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) { |
| | | sendMagParam.setUrl(ip + ":" + req_path + "/outsideChainxj?param1=" + taskId + "¶m2=" + patid + "¶m3=" + URLEncoder.encode(ivrTask1.getTaskName(), StandardCharsets.UTF_8.toString()) + "¶m5=false"); |
| | | //宣教 |
| | | 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() + "查看。感谢您配合!"); |
| | | } |
| | | Boolean aBoolean = sendService.sendMsg(sendMagParam); |
| | | |
| | | //任务发送记录 |
| | | //短信还需要模板 |
| | | 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.setResult(aBoolean == true ? "success" : "error"); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | serviceSubtaskRecord.setRemark("短信发送失败"); |
| | | log.error("短信发送失败:{}", e.getMessage()); |
| | | lssubIds.add(serviceSubtask.getId()); |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); |
| | | } catch (UnsupportedEncodingException e) { |
| | | String guid = UUID.randomUUID().toString(); |
| | | log.error("短信任务,发送失败原因:{},{}", e.getMessage(), guid); |
| | | serviceSubtask.setResult("error"); |
| | | serviceSubtask.setRemark("系统错误(任务)"); |
| | | serviceSubtask.setGuid(guid); |
| | | serviceSubtask.setSendstate(4L); |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | serviceSubtaskMapper.insertServiceSubtask(serviceSubtask); |
| | | 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)) { |
| | | //如果“临时子任务”为空,说明全发送完了 |
| | | 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); |
| | | String url = null; |
| | | try { |
| | | 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"; |
| | | } |
| | | 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 wxCode = getWXCode(serviceSubtask.getSfzh(), url, serviceSubtask.getTaskName(), serviceSubtask.getTaskDesc(), "无"); |
| | | Map<String, Object> map = JSONObject.parseObject(wxCode, Map.class); |
| | | if (!map.isEmpty()) { |
| | | //// 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 ((Boolean) map.get("succ") == false) { |
| | | serviceSubtask.setResult("error"); |
| | | serviceSubtask.setRemark(map.get("msg").toString()); |
| | | serviceSubtask.setSendstate(5L); |
| | | 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.setResult("success"); |
| | | if ((Boolean) map.get("succ") == false) { |
| | | serviceSubtaskRecord.setResult("error"); |
| | | } |
| | | serviceSubtaskMapper.insertServiceSubtask(serviceSubtask); |
| | | serviceSubtaskRecord.setRemark("公众号发送失败"); |
| | | log.error("公众号发送失败:{}", e.getMessage()); |
| | | lssubIds.add(serviceSubtask.getId()); |
| | | serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); |
| | | } catch (Exception e) { |
| | | String guid = UUID.randomUUID().toString(); |
| | | log.error("公众号任务,发送失败原因:{},{}", e.getMessage(), guid); |
| | | serviceSubtask.setResult("error"); |
| | | serviceSubtask.setRemark("系统错误(任务)"); |
| | | serviceSubtask.setGuid(guid); |
| | | serviceSubtask.setSendstate(5L); |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | serviceSubtaskMapper.insertServiceSubtask(serviceSubtask); |
| | | 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); |
| | | serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); |
| | | serviceSubtaskRecord.setPreachform("5"); |
| | | serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); |
| | | 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) |
| | | } |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | // /** |