| | |
| | | import com.google.gson.Gson; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.DtoConversionUtils; |
| | | import com.ruoyi.common.utils.RSAPublicKeyExample; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.*; |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import com.smartor.config.PhoneUtils; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.mapper.*; |
| | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | |
| | | @Value("${pri_key}") |
| | | private String pri_key; |
| | | |
| | | @Value("${ASRCallBackPath}") |
| | | private String ASRCallBackPath; |
| | | |
| | | @Value("${hangup}") |
| | | private String hangup; |
| | | |
| | | |
| | | /** |
| | |
| | | public List<ServiceSubtask> patItem(ServiceSubtaskVO serviceSubtaskVO) { |
| | | List<ServiceSubtask> selectServiceSubtaskList = this.selectServiceSubtaskList(serviceSubtaskVO); |
| | | //根据出院 时间倒序 |
| | | List<ServiceSubtask> sortedServiceSubtaskList = selectServiceSubtaskList.stream().sorted(Comparator.comparing(ServiceSubtask::getEndtime).reversed()).collect(Collectors.toList()); |
| | | return sortedServiceSubtaskList; |
| | | // List<ServiceSubtask> sortedServiceSubtaskList = selectServiceSubtaskList.stream().sorted(Comparator.comparing(ServiceSubtask::getEndtime).reversed()).collect(Collectors.toList()); |
| | | return selectServiceSubtaskList; |
| | | } |
| | | |
| | | @Override |
| | |
| | | public PhoneCallBackYQVO phoneCallBackYQ(PhoneCallReqYQVO phoneCallReqYQVO) { |
| | | //定义一个分数的变量 |
| | | Boolean aBoolean1 = redisCache.hasKey(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | if (!aBoolean1) redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", 0); |
| | | if (!aBoolean1) redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", 0.0, 120, TimeUnit.MINUTES); |
| | | PhoneCallBackYQVO phoneCallBackYQVO = new PhoneCallBackYQVO(); |
| | | //channel_create 通道创建的时候,可以执行一些其它操作,譬如发个短信之类的; 我们的业务可以不用管 PlayEventCallback 这个是播放语音的,暂时用不到 End_time()= -1或null表示当前的asrtext不是一句完整的话 |
| | | if (phoneCallReqYQVO.getOperate().equals("channel_create") || phoneCallReqYQVO.getOperate().equals("PlayEventCallback") || phoneCallReqYQVO.getEnd_time() == null || phoneCallReqYQVO.getEnd_time() == -1) { |
| | | if (phoneCallReqYQVO.getOperate().equals("channel_create")) { |
| | | return phoneCallBackYQVO; |
| | | } |
| | | //PlayEventCallback 这个是播放语音的 playstart:放音开始(问题播报开始) playstop: 放音结束(问题播报结束) |
| | | if (phoneCallReqYQVO.getOperate().equals("PlayEventCallback")) { |
| | | String cacheJSY = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "- jsy"); |
| | | if (phoneCallReqYQVO.getOperate().equals("PlayEventCallback") && phoneCallReqYQVO.getPlaystop() == false) { |
| | | //判断redis中是否有结束语 |
| | | if (StringUtils.isEmpty(cacheJSY)) { |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop", false, 120, TimeUnit.MINUTES); |
| | | log.error("PlayEventCallbackPlaystop的值为-------:{}", false); |
| | | } |
| | | } else { |
| | | //如果结束语不为空,则要挂电话了 |
| | | if (StringUtils.isNotEmpty(cacheJSY)) { |
| | | Map<String, String> req = new HashMap<>(); |
| | | req.put("uuid", phoneCallReqYQVO.getUuid()); |
| | | req.put("caller", phoneCallReqYQVO.getPhone()); |
| | | HttpUtils.sendPost(hangup, new Gson().toJson(req)); |
| | | //删除结束语的患存 |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "- jsy"); |
| | | } else { |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop", true, 120, TimeUnit.MINUTES); |
| | | log.error("-------PlayEventCallbackPlaystop的值为:{}", true); |
| | | } |
| | | } |
| | | return phoneCallBackYQVO; |
| | | } |
| | | //获取放音是否结束 |
| | | boolean isPlayEventOver = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop"); |
| | | if (!isPlayEventOver) { |
| | | return phoneCallBackYQVO; |
| | | } |
| | | |
| | | //通过子任务ID获取到模板信息 |
| | | ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(Long.valueOf(phoneCallReqYQVO.getTaskid())); |
| | | IvrTaskTemplate ivrTaskTemplate = ivrTaskTemplateService.selectIvrTaskTemplateByID(serviceSubtask.getTemplateid()); |
| | |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | String scriptContent = ivrTaskTemplateScriptVO.getScriptContent(); |
| | | log.error("SilentCallback的问题内容scriptContent:{}", scriptContent); |
| | | phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent)); |
| | | //将静默次数加1 |
| | | Integer noVoiceNum = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "noVoice"); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "noVoice", noVoiceNum + 1, 120, TimeUnit.MINUTES); |
| | | return phoneCallBackYQVO; |
| | | } else { |
| | | log.error("静默次数达到,挂掉电话:{}", num); |
| | | //大与等于的话,直接挂断 |
| | | phoneCallBackYQVO.setType("hangup"); |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | phoneCallBackYQVO.setValue(ivrTaskTemplate.getRevisitAfter()); |
| | | //将结果写到detail中 |
| | |
| | | redisCache.setCacheObject(map.get("cacheName"), map.get("val")); |
| | | redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop"); |
| | | //在redis中保存一下结束语,在调用挂电话的方法时删除 |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", ivrTaskTemplate.getRevisitAfter(), 120, TimeUnit.MINUTES); |
| | | } |
| | | return phoneCallBackYQVO; |
| | | } else if ("AsrCallback".equals(phoneCallReqYQVO.getOperate())) { |
| | | } else if ("AsrCallback".equals(phoneCallReqYQVO.getOperate()) && phoneCallReqYQVO.getEnd_time() != null && phoneCallReqYQVO.getEnd_time() != -1) { |
| | | //播报第一题 |
| | | Integer integer = redisCache.getCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim() + "-firstSort"); |
| | | // if(integer==0){ |
| | | // //integer==0,表示开场白刚播报完,需要停顿一下,等患者说话 |
| | | // redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim() + "-firstSort", 1, 120, TimeUnit.MINUTES); |
| | | // return phoneCallBackYQVO; |
| | | // } |
| | | if (ivrTaskTemplateScriptVO.getSort() == 1 && integer == 1) { |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | String scriptContent = ivrTaskTemplateScriptVO.getScriptContent(); |
| | | phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent)); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim() + "-firstSort", 2, 120, TimeUnit.MINUTES); |
| | | return phoneCallBackYQVO; |
| | | } |
| | | |
| | | //如果是文本回调 |
| | | //根据问题ID获取该问题的类型 |
| | | if (ivrTaskTemplateScriptVO.getScriptType().equals("1")) { |
| | |
| | | serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate)); |
| | | serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList); |
| | | saveQuestionAnswerPhone(serviceSubTaskDetailReq); |
| | | // |
| | | //将当前前的播报状态删除,给下一题让位 |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop"); |
| | | // //获取下一题 |
| | | if (ivrTaskTemplateScriptVO.getBranchFlag().equals("1") || ivrTaskTemplateScriptVO.getBranchFlag().equals("0") && ivrTaskTemplateScriptVO.getNextScriptno() != 0) { |
| | | log.error("获取下一题的信息:{}", ivrTaskTemplateScriptVO); |
| | | if (ivrTaskTemplateScriptVO.getBranchFlag().equals("1") || ivrTaskTemplateScriptVO.getBranchFlag().equals("0") && ivrTaskTemplateScriptVO.getNextScriptno() != null && ivrTaskTemplateScriptVO.getNextScriptno() != 0) { |
| | | Long nextQuestion = null; |
| | | if (ivrTaskTemplateScriptVO.getBranchFlag().equals("1")) { |
| | | nextQuestion = ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getNextQuestion(); |
| | |
| | | } else { |
| | | nextQuestion = ivrTaskTemplateScriptVO.getNextScriptno(); |
| | | //更新分数 |
| | | double score = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | Object obj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | Double score = (obj == null ? new Double(0.00) : new Double(((Double) obj).doubleValue())); |
| | | score = BigDecimal.valueOf(score).add(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getScore()).doubleValue(); |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score); |
| | | } |
| | |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | String scriptContent = script.getScriptContent(); |
| | | log.error("下一题问题:{}", scriptContent); |
| | | phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent)); |
| | | //将该患者的Redis中的题目ID,进行修改 |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim(), script.getId().toString(), 120, TimeUnit.MINUTES); |
| | |
| | | } |
| | | } |
| | | } else if (ivrTaskTemplateScriptVO.getBranchFlag().equals("0")) { |
| | | if (ivrTaskTemplateScriptVO.getNextScriptno() == 0 || ivrTaskTemplateScriptVO.getNextScriptno() == null) { |
| | | phoneCallBackYQVO.setType("hangup"); |
| | | if (ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getNextScriptno() == 0) { |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | //更新一下分数 |
| | | double score = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | |
| | | redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop"); |
| | | //在redis中保存一下结束语,在调用挂电话的方法时删除 |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", ivrTaskTemplate.getRevisitAfter(), 120, TimeUnit.MINUTES); |
| | | // return phoneCallBackYQVO; |
| | | } |
| | | } |
| | |
| | | //如果count已经大于或等于没有匹配次数 |
| | | if (ivrTaskTemplateScriptVO.getBranchFlag().equals("0") && ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getBranchFlag().equals("0") && ivrTaskTemplateScriptVO.getNextScriptno() == 0 || ivrTaskTemplateScriptVO.getBranchFlag().equals("1") && ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getBranchFlag().equals("1") && ivrTaskTemplateScriptVO.getNextScriptno() == 0) { |
| | | //如果是最后一道题,或者没有下一题了,就直接挂机 |
| | | phoneCallBackYQVO.setType("hangup"); |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | if (StringUtils.isNotEmpty(phoneCallBackYQVO.getValue())) |
| | | phoneCallBackYQVO.setValue(phoneCallBackYQVO.getValue() + ivrTaskTemplate.getRevisitAfter()); |
| | |
| | | serviceSubtask.setFinishtime(new Date()); |
| | | serviceSubtaskMapper.updateServiceSubtask(serviceSubtask); |
| | | |
| | | //在redis中保存一下结束语,在调用挂电话的方法时删除 |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", ivrTaskTemplate.getRevisitAfter(), 120, TimeUnit.MINUTES); |
| | | //去redis中,把该子任务ID删除 |
| | | Long id = serviceSubtask.getId(); |
| | | Map<String, String> map = delRedisValue(null, id.toString()); |
| | |
| | | |
| | | //如果选项分支为1的话,则需要根据问题上的nextScriptno进行跳转 |
| | | //问答题没有跳转 |
| | | if (ivrTaskTemplateScriptVO.getNextScriptno() != null || ivrTaskTemplateScriptVO.getNextScriptno() != 0) { |
| | | if (ivrTaskTemplateScriptVO.getNextScriptno() != null && ivrTaskTemplateScriptVO.getNextScriptno() != 0) { |
| | | for (IvrTaskTemplateScript ivrTaskTemplateScript1 : ivrTaskTemplateScripts) { |
| | | if (ivrTaskTemplateScriptVO.getNextScriptno().intValue() == ivrTaskTemplateScript1.getSort()) { |
| | | phoneCallBackYQVO.setType("text"); |
| | |
| | | // return phoneCallBackYQVO; |
| | | } |
| | | } |
| | | } else if (ivrTaskTemplateScriptVO.getNextScriptno() == null) { |
| | | } else if (ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getNextScriptno() == 0) { |
| | | //没有下一题了,就结束了 |
| | | phoneCallBackYQVO.setType("hangup"); |
| | | phoneCallBackYQVO.setType("text"); |
| | | phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue()); |
| | | phoneCallBackYQVO.setValue(ivrTaskTemplate.getRevisitAfter()); |
| | | |
| | |
| | | Long id = serviceSubtask.getId(); |
| | | Map<String, String> map = delRedisValue(null, id.toString()); |
| | | redisCache.setCacheObject(map.get("cacheName"), map.get("val")); |
| | | //在redis中保存一下结束语,在调用挂电话的方法时删除 |
| | | redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", ivrTaskTemplate.getRevisitAfter(), 120, TimeUnit.MINUTES); |
| | | redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone()); |
| | | redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE"); |
| | | } |
| | | |
| | | //选项匹配完成后,需要再去通过库再进行匹配一次 |
| | | String extemplateID = ivrTaskTemplate.getSubmoduleID(); |
| | | if (StringUtils.isNotEmpty(extemplateID)) { |
| | | String[] split = extemplateID.split(","); |
| | | List<String> list = Arrays.asList(split); |
| | | List<Long> list1 = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(extemplateID)) { |
| | | for (String str : list) { |
| | | list1.add(Long.valueOf(str)); |
| | | } |
| | |
| | | } |
| | | return phoneCallBackYQVO; |
| | | } |
| | | |
| | | |
| | | private String getObject(ServiceSubtask serviceSubtask, String scriptContent) { |
| | | Map<String, Map<String, String>> param = getParam(serviceSubtask.getTaskid()); |
| | |
| | | if (!StringUtils.isEmpty(value0)) { |
| | | pullTaskVOList = getPullTaskList(value0, "cache-0"); |
| | | //将cache-0的数据,转移不对劲cache-00中 |
| | | redisCache.deleteObject("cache-00"); |
| | | String cache00 = redisCache.getCacheObject("cache-00"); |
| | | if (!StringUtils.isEmpty(cache00)) redisCache.setCacheObject("cache-00", cache00 + "," + value0); |
| | | else redisCache.setCacheObject("cache-00", value0); |
| | | if (!StringUtils.isEmpty(cache00)) |
| | | redisCache.setCacheObject("cache-00", cache00 + "," + value0, 120, TimeUnit.MINUTES); |
| | | else redisCache.setCacheObject("cache-00", value0, 120, TimeUnit.MINUTES); |
| | | redisCache.deleteObject("cache-0"); |
| | | } else { |
| | | for (int i = 1; i < 6; i++) { |
| | |
| | | redisCache.deleteObject("cache-" + i); |
| | | } |
| | | } |
| | | |
| | | if (CollectionUtils.isNotEmpty(pullTaskVOList)) { |
| | | //给回调参数赋值 |
| | | for (PullTaskVO pullTaskVO : pullTaskVOList) { |
| | | pullTaskVO.setAsrcallback(ASRCallBackPath); |
| | | } |
| | | } |
| | | return pullTaskVOList; |
| | | } |
| | | |
| | |
| | | //如果ivrTaskTemplateScript为空,也就没有往下执行的必要了 |
| | | if (ObjectUtils.isEmpty(ivrTaskTemplateScript)) return null; |
| | | //获取通配符匹配过后的问题 |
| | | String scrContent = getObject(serviceSubtask, ivrTaskTemplateScript.getScriptContent()); |
| | | String kcb = ivrTaskTemplate.getRevisitBefore() + "," + scrContent; |
| | | // String scrContent = getObject(serviceSubtask, ivrTaskTemplateScript.getScriptContent()); |
| | | // String kcb = ivrTaskTemplate.getRevisitBefore() + "," + scrContent; |
| | | String kcb = ivrTaskTemplate.getRevisitBefore(); |
| | | |
| | | //封装返回数据 |
| | | //taskId = 子任务ID + 问题ID +问题序号 |
| | |
| | | pullTaskVO.setDisplayNo("85129866"); |
| | | pullTaskVOList.add(pullTaskVO); |
| | | redisCache.setCacheObject(subId.trim() + "-" + serviceSubtask.getPhone().trim(), ivrTaskTemplateScript.getId().toString()); |
| | | redisCache.setCacheObject(subId.trim() + "-" + serviceSubtask.getPhone().trim() + "-firstSort", 1, 120, TimeUnit.MINUTES); |
| | | } else { |
| | | if (StringUtils.isEmpty(newValue0)) { |
| | | newValue0 = "," + split[i].trim() + ","; |