|  |  |  | 
|---|
|  |  |  | private IvrLibaTemplateTargetoptionMapper ivrLibaScriptTargetoptionMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IvrTaskVisitResultMapper ivrTaskVisitResultMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RedisCache redisCache; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | 
|---|
|  |  |  | //定义患者与单一任务关联表集合 | 
|---|
|  |  |  | List<PatTaskRelevance> patTaskRelevances = new ArrayList<>(); | 
|---|
|  |  |  | List<IvrTaskSingle> list = selectIvrTaskcallList(ivrTaskcall); | 
|---|
|  |  |  | if (CollectionUtils.isEmpty(list)) { | 
|---|
|  |  |  | new BaseException("该任务不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //将查出来的数据倒入IvrTaskcallVO中 | 
|---|
|  |  |  | IvrTaskSingleVO ivrTaskcallVO2 = DtoConversionUtils.sourceToTarget(list.get(0), IvrTaskSingleVO.class); | 
|---|
|  |  |  | String sendTimeSlot = list.get(0).getSendTimeSlot(); | 
|---|
|  |  |  | 
|---|
|  |  |  | IvrTask ivrTask = DtoConversionUtils.sourceToTarget(ivrTaskcallVO, IvrTask.class); | 
|---|
|  |  |  | Integer taskId = ivrTaskService.insertIvrTask(ivrTask); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ivrTaskcallVO.setTaskid(taskId.longValue()); | 
|---|
|  |  |  | ivrTaskcallVO.setTaskid(ivrTask.getTaskid().longValue()); | 
|---|
|  |  |  | //新增 | 
|---|
|  |  |  | if (CollectionUtils.isNotEmpty(ivrTaskcallVO.getPatTaskRelevances())) { | 
|---|
|  |  |  | for (PatTaskRelevance patTaskRelevance : ivrTaskcallVO.getPatTaskRelevances()) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public PhoneCallBackVO phoneCallBack(PhoneCallBackVO phoneCallBackVO) { | 
|---|
|  |  |  | log.info("phoneCallBackVO的入参:{},{},{},{},{},{},{}", phoneCallBackVO.getResultType(), phoneCallBackVO.getUuid(), phoneCallBackVO.getErrResult(), phoneCallBackVO.getTextResult(), phoneCallBackVO.getHangUpResult(), phoneCallBackVO.getEnumState(), phoneCallBackVO.getUint8()); | 
|---|
|  |  |  | public void phoneCallBack(PhoneCallBackVO phoneCallBackVO) { | 
|---|
|  |  |  | phoneCallBackVO.setTextResult(phoneCallBackVO.getTextResult().substring(0, phoneCallBackVO.getTextResult().length() - 1)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取数据 | 
|---|
|  |  |  | Boolean aBoolean = redisCache.hasKey(phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | if (!aBoolean) { | 
|---|
|  |  |  | new BaseException("该uuid不存在"); | 
|---|
|  |  |  | throw new BaseException("该uuid不存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer hangupValue = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "hangup"); | 
|---|
|  |  |  | PhoneUtils phoneUtils = new PhoneUtils(); | 
|---|
|  |  |  | if (hangupValue != null && hangupValue == 1) { | 
|---|
|  |  |  | log.info("电话要挂断了"); | 
|---|
|  |  |  | //hangupValue == 1  随访结束,直接可以挂电话 | 
|---|
|  |  |  | PhoneUtils phoneUtils = new PhoneUtils(); | 
|---|
|  |  |  | phoneUtils.hangup(phoneCallBackVO.getUuid(), null, null, null, null, null, null, null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | phoneUtils.hangup("", "", "", "", "", "", "", phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String cacheObject = redisCache.getCacheObject(phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | ObjectMapper objectMapper = new ObjectMapper(); | 
|---|
|  |  |  | Map<String, Object> map = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | map = objectMapper.readValue(cacheObject, Map.class); | 
|---|
|  |  |  | } catch (JsonProcessingException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String, Object> map = redisCache.getCacheObject(phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | IvrTaskSingle ivrTaskcall = (IvrTaskSingle) map.get("ivrTaskcall"); | 
|---|
|  |  |  | List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOs = (List<IvrLibaTemplateScriptVO>) map.get("ivrLibaTemplateScriptVO"); | 
|---|
|  |  |  | //将uuid更新到数据库中 | 
|---|
|  |  |  | 
|---|
|  |  |  | //获取模板信息 | 
|---|
|  |  |  | IvrLibaTemplateVO ivrLibaTemplateVO = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "ivrLibaTemplateVO"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //语音识别结果上报接口: 3 | 
|---|
|  |  |  | Integer noVoice = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "noVoice"); | 
|---|
|  |  |  | QuestionMessage returnQues = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "returnQues"); | 
|---|
|  |  |  | //将传回的结果放到回复对象中 | 
|---|
|  |  |  | returnQues.setContent(phoneCallBackVO.getTextResult()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //首先判断resultType | 
|---|
|  |  |  | if (phoneCallBackVO.getResultType() == 1) { | 
|---|
|  |  |  | //呼叫结果接口: 1 | 
|---|
|  |  |  | if (phoneCallBackVO.getUint8() == 1) { | 
|---|
|  |  |  | //呼叫失败,去redis中记录一下失败次数,进行再次呼叫 | 
|---|
|  |  |  | Integer integer = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "uint8"); | 
|---|
|  |  |  | if (integer != null) { | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "uint8", integer + 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | IvrLibaTemplateScriptVO nowQuestion = returnQues.getNowQuestion(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StringUtils.isEmpty(returnQues.getContent())) { | 
|---|
|  |  |  | //无回话 | 
|---|
|  |  |  | //判断noVoice是否已经到了最大值 | 
|---|
|  |  |  | if (noVoice == ivrLibaTemplateVO.getNoVoiceNum().intValue()) { | 
|---|
|  |  |  | //已经问了对应的遍数,就判断是否还有下一题 | 
|---|
|  |  |  | if (nowQuestion.getTargetid() == ivrLibaTemplateScriptVOs.size()) { | 
|---|
|  |  |  | //没有下一题了,就挂断电话,播放结束语 | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "uint8", 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //有下一题 | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | IvrLibaTemplateScriptVO nextQuestion = getNextQuestion(ivrLibaTemplateScriptVOs, nowQuestion); | 
|---|
|  |  |  | // 问题,  去调用“tts合成和播放”接口 | 
|---|
|  |  |  | phoneUtils.ttsPlayback(nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", noVoice + 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //调用ivrLibaTemplateScriptVO中的slienceText(静默话术) | 
|---|
|  |  |  | String slienceText = nowQuestion.getSlienceText(); | 
|---|
|  |  |  | //静默话术  + 问题,  去调用“tts合成和播放”接口 | 
|---|
|  |  |  | phoneUtils.ttsPlayback(slienceText + nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (integer != null && integer == ivrTaskcall.getRecallcount().intValue()) { | 
|---|
|  |  |  | log.info("无人接听:{},   {}", phoneCallBackVO.getErrResult(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | //连续打规定次,如果要没人接,那就结束 | 
|---|
|  |  |  | ivrTaskcall.setResult(phoneCallBackVO.getErrResult()); | 
|---|
|  |  |  | ivrTaskSingleMapper.updateIvrTaskcall(ivrTaskcall); | 
|---|
|  |  |  | redisCache.deleteObject(phoneCallBackVO.getUuid() + "uint8"); | 
|---|
|  |  |  | } else if (integer != null && integer < ivrTaskcall.getRecallcount().intValue()) { | 
|---|
|  |  |  | //进行重拨 | 
|---|
|  |  |  | PhoneUtils phoneUtils = new PhoneUtils(); | 
|---|
|  |  |  | phoneUtils.ob(phoneCallBackVO.getUuid(), null, ivrTaskcall.getPhone(), null, null, null, null, null, null, null, null); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //isppd用来记录是否匹配到 | 
|---|
|  |  |  | Boolean isppd = false; | 
|---|
|  |  |  | //有回话,对回答的问题,进行正则匹配(这里只针对选择题,其它题型不行) | 
|---|
|  |  |  | for (int j = 0; j < nowQuestion.getIvrLibaScriptTargetoptionList().size(); j++) { | 
|---|
|  |  |  | //包含 | 
|---|
|  |  |  | Matcher matcher = null; | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex())) { | 
|---|
|  |  |  | Pattern pattern = Pattern.compile(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()); | 
|---|
|  |  |  | matcher = pattern.matcher(phoneCallBackVO.getTextResult()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //不包含 | 
|---|
|  |  |  | Matcher matcher2 = null; | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2())) { | 
|---|
|  |  |  | Pattern pattern2 = Pattern.compile(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()); | 
|---|
|  |  |  | matcher2 = pattern2.matcher(phoneCallBackVO.getTextResult()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.info("phoneCallBack--Targetregex的值为:{}, phoneCallBack--Targetregex2的值为:{}", nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex(), nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()); | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() | 
|---|
|  |  |  | || StringUtils.isEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() | 
|---|
|  |  |  | || StringUtils.isEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) { | 
|---|
|  |  |  | //说明匹配正确了 | 
|---|
|  |  |  | //这里应该先判断类型,去再修改,设置IsUserOperation是单选题的改法 | 
|---|
|  |  |  | nowQuestion.getIvrLibaScriptTargetoptionList().get(j).setIsUserOperation(true); | 
|---|
|  |  |  | ivrLibaScriptTargetoptionMapper.updateIvrLibaTemplateTargetoption(nowQuestion.getIvrLibaScriptTargetoptionList().get(j)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //将静默置为0 | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", 0, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //将患者的回签写进表里 | 
|---|
|  |  |  | IvrTaskVisitResult ivrTaskVisitResult = DtoConversionUtils.sourceToTarget(ivrTaskcall, IvrTaskVisitResult.class); | 
|---|
|  |  |  | ivrTaskVisitResult.setId(null); | 
|---|
|  |  |  | ivrTaskVisitResult.setQuestion(nowQuestion.getQuestionText()); | 
|---|
|  |  |  | ivrTaskVisitResult.setPatientAnswer(phoneCallBackVO.getTextResult()); | 
|---|
|  |  |  | ivrTaskVisitResult.setCreateTime(new Date()); | 
|---|
|  |  |  | ivrTaskVisitResult.setOptionResult(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetvalue()); | 
|---|
|  |  |  | ivrTaskVisitResultMapper.insertIvrTaskVisitResult(ivrTaskVisitResult); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //将匹配到的标识改成true | 
|---|
|  |  |  | isppd = true; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取下一题 | 
|---|
|  |  |  | Integer nextQuestion = nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getNextQuestion(); | 
|---|
|  |  |  | for (IvrLibaTemplateScriptVO script : ivrLibaTemplateScriptVOs) { | 
|---|
|  |  |  | if (script.getTargetid() == nextQuestion) { | 
|---|
|  |  |  | QuestionMessage questionMessage = new QuestionMessage(); | 
|---|
|  |  |  | questionMessage.setNowQuestion(script); | 
|---|
|  |  |  | questionMessage.setQuestionList(ivrLibaTemplateScriptVOs); | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | phoneUtils.ttsPlayback(script.getQuestionText(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } else if (nextQuestion > ivrLibaTemplateScriptVOs.size()) { | 
|---|
|  |  |  | //没有下一题了,就结束了 | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Thread.sleep(3000); | 
|---|
|  |  |  | } catch (InterruptedException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | phoneUtils.hangup("", "", ivrLibaTemplateVO.getRevisitAfter(), "", "", "", "", phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //没有匹配上当前option | 
|---|
|  |  |  | //Targetregex2 为false,表示在Targetregex2中存在  语句中的关键字,这个option就不用再继续匹配了,直接匹配下一个option | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else if (phoneCallBackVO.getResultType() == 2) { | 
|---|
|  |  |  | //通话状态更新接口: 2 | 
|---|
|  |  |  | if (phoneCallBackVO.getEnumState() == 0) { | 
|---|
|  |  |  | // 0-振铃 | 
|---|
|  |  |  | Integer integer = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "enumState"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (integer != null && integer < ivrTaskcall.getRecallcount().intValue()) { | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "enumState", integer + 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | } else if (integer == null) { | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "enumState", 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | } else if (integer != null && integer == ivrTaskcall.getRecallcount().intValue()) { | 
|---|
|  |  |  | ivrTaskcall.setResult("无人接听"); | 
|---|
|  |  |  | ivrTaskSingleMapper.updateIvrTaskcall(ivrTaskcall); | 
|---|
|  |  |  | redisCache.deleteObject(phoneCallBackVO.getUuid() + "enumState"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else if (phoneCallBackVO.getEnumState() == 2) { | 
|---|
|  |  |  | //患者挂断电话 | 
|---|
|  |  |  | log.info("患者挂断电话:{}", phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | ivrTaskcall.setResult(phoneCallBackVO.getHangUpResult()); | 
|---|
|  |  |  | ivrTaskSingleMapper.updateIvrTaskcall(ivrTaskcall); | 
|---|
|  |  |  | redisCache.deleteObject(phoneCallBackVO.getUuid() + "enumState"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else if (phoneCallBackVO.getResultType() == 3) { | 
|---|
|  |  |  | //语音识别结果上报接口: 3 | 
|---|
|  |  |  | Integer noVoice = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "noVoice"); | 
|---|
|  |  |  | QuestionMessage returnQues = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "returnQues"); | 
|---|
|  |  |  | IvrLibaTemplateScriptVO nowQuestion = returnQues.getNowQuestion(); | 
|---|
|  |  |  | PhoneUtils phoneUtils = new PhoneUtils(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (StringUtils.isEmpty(phoneCallBackVO.getTextResult())) { | 
|---|
|  |  |  | //无回话 | 
|---|
|  |  |  | //判断noVoice是否已经到了最大值 | 
|---|
|  |  |  | if (noVoice == ivrLibaTemplateVO.getNoVoiceNum().intValue()) { | 
|---|
|  |  |  | //已经问了对应的遍数,就判断是否还有下一题 | 
|---|
|  |  |  | if (nowQuestion.getTargetid() == ivrLibaTemplateScriptVOs.size()) { | 
|---|
|  |  |  | //没有下一题了,就挂断电话,播放结束语 | 
|---|
|  |  |  | if (isppd != true) { | 
|---|
|  |  |  | //没有匹配到 | 
|---|
|  |  |  | Integer mateNum = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "mateNum"); | 
|---|
|  |  |  | if (mateNum == null) mateNum = 0; | 
|---|
|  |  |  | //无匹配次数去判断是否到最大询问次数,并且所有的选项都匹配完了 | 
|---|
|  |  |  | if (mateNum == ivrLibaTemplateVO.getMateNum().intValue()) { | 
|---|
|  |  |  | //如果下一题为空.则新的数据返回,并加上感谢语 | 
|---|
|  |  |  | if (nowQuestion.getTargetid() < ivrLibaTemplateScriptVOs.size()) { | 
|---|
|  |  |  | QuestionMessage questionMessage = new QuestionMessage(); | 
|---|
|  |  |  | IvrLibaTemplateScriptVO nextQuestion = getNextQuestion(ivrLibaTemplateScriptVOs, nowQuestion); | 
|---|
|  |  |  | questionMessage.setQuestionList(ivrLibaTemplateScriptVOs); | 
|---|
|  |  |  | questionMessage.setNowQuestion(nextQuestion); | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", 0, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | phoneUtils.ttsPlayback(nextQuestion.getQuestionText(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //就可以挂断电话了 | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //有下一题 | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | IvrLibaTemplateScriptVO nextQuestion = getNextQuestion(ivrLibaTemplateScriptVOs, nowQuestion); | 
|---|
|  |  |  | // 问题,  去调用“tts合成和播放”接口 | 
|---|
|  |  |  | phoneUtils.ttsPlayback(nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | Thread.sleep(3000); | 
|---|
|  |  |  | } catch (InterruptedException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | phoneUtils.hangup("", "", ivrLibaTemplateVO.getRevisitAfter(), "", "", "", "", phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", noVoice + 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //调用ivrLibaTemplateScriptVO中的slienceText(静默话术) | 
|---|
|  |  |  | String slienceText = nowQuestion.getSlienceText(); | 
|---|
|  |  |  | //静默话术  + 问题,  去调用“tts合成和播放”接口 | 
|---|
|  |  |  | phoneUtils.ttsPlayback(slienceText + nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | return new PhoneCallBackVO(); | 
|---|
|  |  |  | } else if (mateNum < ivrLibaTemplateVO.getMateNum().intValue()) { | 
|---|
|  |  |  | //没有问到规定次数 | 
|---|
|  |  |  | mateNum = mateNum + 1; | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", mateNum, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //有回话,对回答的问题,进行正则匹配(这里只针对选择题,其它题型不行) | 
|---|
|  |  |  | for (int j = 0; j < nowQuestion.getIvrLibaScriptTargetoptionList().size(); j++) { | 
|---|
|  |  |  | //包含 | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //选项匹配完成后,需要再去通过库再进行匹配一次 | 
|---|
|  |  |  | String extemplateID = ivrLibaTemplateVO.getSubmoduleID(); | 
|---|
|  |  |  | 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)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<IvrLibaExtemplatescript> ivrLibaExtemplatescripts = ivrLibaExtemplatescriptMapper.queryIvrLibaExtemplatescriptList(list1); | 
|---|
|  |  |  | for (IvrLibaExtemplatescript ivrLibaExtemplatescript : ivrLibaExtemplatescripts) { | 
|---|
|  |  |  | Matcher matcher = null; | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex())) { | 
|---|
|  |  |  | Pattern pattern = Pattern.compile(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()); | 
|---|
|  |  |  | matcher = pattern.matcher(phoneCallBackVO.getTextResult()); | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex())) { | 
|---|
|  |  |  | Pattern pattern = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex()); | 
|---|
|  |  |  | matcher = pattern.matcher(returnQues.getContent()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //不包含 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Matcher matcher2 = null; | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2())) { | 
|---|
|  |  |  | Pattern pattern2 = Pattern.compile(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()); | 
|---|
|  |  |  | matcher2 = pattern2.matcher(phoneCallBackVO.getTextResult()); | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2())) { | 
|---|
|  |  |  | Pattern pattern2 = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex2()); | 
|---|
|  |  |  | matcher2 = pattern2.matcher(returnQues.getContent()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.info("phoneCallBack--Targetregex的值为:{}, phoneCallBack--Targetregex2的值为:{}", nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex(), nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()); | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() && StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) { | 
|---|
|  |  |  | //说明匹配正确了 | 
|---|
|  |  |  | //这里应该先判断类型,去再修改,设置IsUserOperation是单选题的改法 | 
|---|
|  |  |  | nowQuestion.getIvrLibaScriptTargetoptionList().get(j).setIsUserOperation(true); | 
|---|
|  |  |  | ivrLibaScriptTargetoptionMapper.updateIvrLibaTemplateTargetoption(nowQuestion.getIvrLibaScriptTargetoptionList().get(j)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //将静默置为0 | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", 0, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //获取下一题 | 
|---|
|  |  |  | Integer nextQuestion = nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getNextQuestion(); | 
|---|
|  |  |  | for (IvrLibaTemplateScriptVO script : ivrLibaTemplateScriptVOs) { | 
|---|
|  |  |  | if (script.getTargetid() == nextQuestion) { | 
|---|
|  |  |  | QuestionMessage questionMessage = new QuestionMessage(); | 
|---|
|  |  |  | questionMessage.setNowQuestion(script); | 
|---|
|  |  |  | questionMessage.setQuestionList(ivrLibaTemplateScriptVOs); | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //没有匹配到 | 
|---|
|  |  |  | Integer mateNum = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "mateNum"); | 
|---|
|  |  |  | //无匹配次数去判断是否到最大询问次数,并且所有的选项都匹配完了 | 
|---|
|  |  |  | if (mateNum == ivrLibaTemplateVO.getMateNum().intValue() && j == nowQuestion.getIvrLibaScriptTargetoptionList().size() - 1) { | 
|---|
|  |  |  | //如果下一题为空.则新的数据返回,并加上感谢语 | 
|---|
|  |  |  | if (nowQuestion.getTargetid() < ivrLibaTemplateScriptVOs.size()) { | 
|---|
|  |  |  | QuestionMessage questionMessage = new QuestionMessage(); | 
|---|
|  |  |  | IvrLibaTemplateScriptVO nextQuestion = getNextQuestion(ivrLibaTemplateScriptVOs, nowQuestion); | 
|---|
|  |  |  | questionMessage.setQuestionList(ivrLibaTemplateScriptVOs); | 
|---|
|  |  |  | questionMessage.setNowQuestion(nextQuestion); | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", 0, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | //就可以挂断电话了 | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else if (mateNum < ivrLibaTemplateVO.getMateNum().intValue() && j == nowQuestion.getIvrLibaScriptTargetoptionList().size() - 1) { | 
|---|
|  |  |  | //没有问到规定次数 | 
|---|
|  |  |  | mateNum = mateNum + 1; | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", mateNum, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //选项匹配完成后,需要再去通过库再进行匹配一次 | 
|---|
|  |  |  | String extemplateID = ivrLibaTemplateVO.getSubmoduleID(); | 
|---|
|  |  |  | 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)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<IvrLibaExtemplatescript> ivrLibaExtemplatescripts = ivrLibaExtemplatescriptMapper.queryIvrLibaExtemplatescriptList(list1); | 
|---|
|  |  |  | for (IvrLibaExtemplatescript ivrLibaExtemplatescript : ivrLibaExtemplatescripts) { | 
|---|
|  |  |  | Matcher matcher = null; | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex())) { | 
|---|
|  |  |  | Pattern pattern = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex()); | 
|---|
|  |  |  | matcher = pattern.matcher(returnQues.getContent()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Matcher matcher2 = null; | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2())) { | 
|---|
|  |  |  | Pattern pattern2 = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex2()); | 
|---|
|  |  |  | matcher2 = pattern2.matcher(returnQues.getContent()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | log.info("++++++++++++++++++++++++++通用库是否为空:selfRegex : {} , selfRegex2 : {}", ivrLibaExtemplatescript.getSelfRegex(), ivrLibaExtemplatescript.getSelfRegex2()); | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex()) && matcher.matches() && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && matcher2.matches() || StringUtils.isEmpty(ivrLibaExtemplatescript.getSelfRegex()) && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && matcher2.matches() || StringUtils.isEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex()) && matcher.matches()) { | 
|---|
|  |  |  | QuestionMessage questionMessage = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "returnQues"); | 
|---|
|  |  |  | IvrLibaTemplateScriptVO ivrLibaTemplateScriptVO = returnQues.getNowQuestion(); | 
|---|
|  |  |  | ivrLibaTemplateScriptVO.setSubmoduleText(ivrLibaExtemplatescript.getSwitchText()); | 
|---|
|  |  |  | ivrLibaTemplateScriptVO.setSubmoduleVoice(ivrLibaExtemplatescript.getSwitchWav()); | 
|---|
|  |  |  | log.info("++++++++++++++++++++++++++通用库是否为空:selfRegex : {} , selfRegex2 : {}", ivrLibaExtemplatescript.getSelfRegex(), ivrLibaExtemplatescript.getSelfRegex2()); | 
|---|
|  |  |  | if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex()) && matcher.matches() && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && matcher2.matches() || StringUtils.isEmpty(ivrLibaExtemplatescript.getSelfRegex()) && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && matcher2.matches() || StringUtils.isEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex()) && matcher.matches()) { | 
|---|
|  |  |  | QuestionMessage questionMessage = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "returnQues"); | 
|---|
|  |  |  | IvrLibaTemplateScriptVO ivrLibaTemplateScriptVO = returnQues.getNowQuestion(); | 
|---|
|  |  |  | ivrLibaTemplateScriptVO.setSubmoduleText(ivrLibaExtemplatescript.getSwitchText()); | 
|---|
|  |  |  | ivrLibaTemplateScriptVO.setSubmoduleVoice(ivrLibaExtemplatescript.getSwitchWav()); | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | if (ivrLibaExtemplatescript.getIsEnd() == 1) { | 
|---|
|  |  |  | //将问题置空 | 
|---|
|  |  |  | IvrLibaTemplateScriptVO nowQuestion1 = questionMessage.getNowQuestion(); | 
|---|
|  |  |  | nowQuestion1.setQuestionText(null); | 
|---|
|  |  |  | nowQuestion1.setQuestionVoice(null); | 
|---|
|  |  |  | questionMessage.setNowQuestion(nowQuestion1); | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | if (ivrLibaExtemplatescript.getIsEnd() == 1) { | 
|---|
|  |  |  | //将问题置空 | 
|---|
|  |  |  | IvrLibaTemplateScriptVO nowQuestion1 = questionMessage.getNowQuestion(); | 
|---|
|  |  |  | nowQuestion1.setQuestionText(null); | 
|---|
|  |  |  | nowQuestion1.setQuestionVoice(null); | 
|---|
|  |  |  | questionMessage.setNowQuestion(nowQuestion1); | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "isOver", 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //调用“15、tts合成和播放, tts_playback”将结果传回 | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "isOver", 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | //调用“15、tts合成和播放, tts_playback”将结果传回 | 
|---|
|  |  |  | phoneUtils.ttsPlayback(nowQuestion.getQuestionText() + ivrLibaTemplateScriptVO.getSubmoduleText(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | phoneUtils.ttsPlayback(nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return phoneCallBackVO; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //下面的代码不能删除,上面的方法只是配合电话端联调用的, | 
|---|
|  |  |  | //    @Override | 
|---|
|  |  |  | //    public PhoneCallBackVO phoneCallBack(PhoneCallBackVO phoneCallBackVO) { | 
|---|
|  |  |  | //        log.error("phoneCallBackVO的入参:{},{},{},{},{},{},{}", phoneCallBackVO.getResultType(), phoneCallBackVO.getUuid(), phoneCallBackVO.getErrResult(), phoneCallBackVO.getTextResult(), phoneCallBackVO.getHangUpResult(), phoneCallBackVO.getEnumState(), phoneCallBackVO.getUint8()); | 
|---|
|  |  |  | //        //获取数据 | 
|---|
|  |  |  | //        Boolean aBoolean = redisCache.hasKey(phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | //        if (!aBoolean) { | 
|---|
|  |  |  | //            throw new BaseException("该uuid不存在"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        Integer hangupValue = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "hangup"); | 
|---|
|  |  |  | //        if (hangupValue != null && hangupValue == 1) { | 
|---|
|  |  |  | //            //hangupValue == 1  随访结束,直接可以挂电话 | 
|---|
|  |  |  | //            PhoneUtils phoneUtils = new PhoneUtils(); | 
|---|
|  |  |  | //            phoneUtils.hangup(phoneCallBackVO.getUuid(), null, null, null, null, null, null, null); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        Map<String, Object> map = redisCache.getCacheObject(phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | ////        ObjectMapper objectMapper = new ObjectMapper(); | 
|---|
|  |  |  | ////        Map<String, Object> map = null; | 
|---|
|  |  |  | ////        try { | 
|---|
|  |  |  | ////            map = objectMapper.readValue(cacheObject, Map.class); | 
|---|
|  |  |  | ////        } catch (JsonProcessingException e) { | 
|---|
|  |  |  | ////            e.printStackTrace(); | 
|---|
|  |  |  | ////        } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        IvrTaskSingle ivrTaskcall = (IvrTaskSingle) map.get("ivrTaskcall"); | 
|---|
|  |  |  | //        List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOs = (List<IvrLibaTemplateScriptVO>) map.get("ivrLibaTemplateScriptVO"); | 
|---|
|  |  |  | //        //将uuid更新到数据库中 | 
|---|
|  |  |  | //        ivrTaskcall.setSenduuid(phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | //        ivrTaskSingleMapper.updateIvrTaskcall(ivrTaskcall); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        //获取模板信息 | 
|---|
|  |  |  | //        IvrLibaTemplateVO ivrLibaTemplateVO = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "ivrLibaTemplateVO"); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        //首先判断resultType | 
|---|
|  |  |  | //        if (phoneCallBackVO.getResultType() == 1) { | 
|---|
|  |  |  | //            //呼叫结果接口: 1 | 
|---|
|  |  |  | //            if (phoneCallBackVO.getUint8() == 1) { | 
|---|
|  |  |  | //                //呼叫失败,去redis中记录一下失败次数,进行再次呼叫 | 
|---|
|  |  |  | //                Integer integer = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "uint8"); | 
|---|
|  |  |  | //                if (integer != null) { | 
|---|
|  |  |  | //                    redisCache.setCacheObject(phoneCallBackVO.getUuid() + "uint8", integer + 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                } else { | 
|---|
|  |  |  | //                    redisCache.setCacheObject(phoneCallBackVO.getUuid() + "uint8", 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                if (integer != null && integer == ivrTaskcall.getRecallcount().intValue()) { | 
|---|
|  |  |  | //                    log.info("无人接听:{},   {}", phoneCallBackVO.getErrResult(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | //                    //连续打规定次,如果要没人接,那就结束 | 
|---|
|  |  |  | //                    ivrTaskcall.setResult(phoneCallBackVO.getErrResult()); | 
|---|
|  |  |  | //                    ivrTaskSingleMapper.updateIvrTaskcall(ivrTaskcall); | 
|---|
|  |  |  | //                    redisCache.deleteObject(phoneCallBackVO.getUuid() + "uint8"); | 
|---|
|  |  |  | //                } else if (integer != null && integer < ivrTaskcall.getRecallcount().intValue()) { | 
|---|
|  |  |  | //                    //进行重拨 | 
|---|
|  |  |  | //                    PhoneUtils phoneUtils = new PhoneUtils(); | 
|---|
|  |  |  | //                    phoneUtils.ob(null, null, null, null, null, null, null, ivrTaskcall.getPhone(), phoneCallBackVO.getUuid(), true); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        } else if (phoneCallBackVO.getResultType() == 2) { | 
|---|
|  |  |  | //            //通话状态更新接口: 2 | 
|---|
|  |  |  | //            if (phoneCallBackVO.getEnumState() == 0) { | 
|---|
|  |  |  | //                // 0-振铃 | 
|---|
|  |  |  | //                Integer integer = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "enumState"); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                if (integer != null && integer < ivrTaskcall.getRecallcount().intValue()) { | 
|---|
|  |  |  | //                    redisCache.setCacheObject(phoneCallBackVO.getUuid() + "enumState", integer + 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                } else if (integer == null) { | 
|---|
|  |  |  | //                    redisCache.setCacheObject(phoneCallBackVO.getUuid() + "enumState", 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                } else if (integer != null && integer == ivrTaskcall.getRecallcount().intValue()) { | 
|---|
|  |  |  | //                    ivrTaskcall.setResult("无人接听"); | 
|---|
|  |  |  | //                    ivrTaskSingleMapper.updateIvrTaskcall(ivrTaskcall); | 
|---|
|  |  |  | //                    redisCache.deleteObject(phoneCallBackVO.getUuid() + "enumState"); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //            } else if (phoneCallBackVO.getEnumState() == 2) { | 
|---|
|  |  |  | //                //患者挂断电话 | 
|---|
|  |  |  | //                log.info("患者挂断电话:{}", phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | //                ivrTaskcall.setResult(phoneCallBackVO.getHangUpResult()); | 
|---|
|  |  |  | //                ivrTaskSingleMapper.updateIvrTaskcall(ivrTaskcall); | 
|---|
|  |  |  | //                redisCache.deleteObject(phoneCallBackVO.getUuid() + "enumState"); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //        } else if (phoneCallBackVO.getResultType() == 3) { | 
|---|
|  |  |  | //            //语音识别结果上报接口: 3 | 
|---|
|  |  |  | //            Integer noVoice = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "noVoice"); | 
|---|
|  |  |  | //            QuestionMessage returnQues = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "returnQues"); | 
|---|
|  |  |  | //            IvrLibaTemplateScriptVO nowQuestion = returnQues.getNowQuestion(); | 
|---|
|  |  |  | //            PhoneUtils phoneUtils = new PhoneUtils(); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            if (StringUtils.isEmpty(phoneCallBackVO.getTextResult())) { | 
|---|
|  |  |  | //                //无回话 | 
|---|
|  |  |  | //                //判断noVoice是否已经到了最大值 | 
|---|
|  |  |  | //                if (noVoice == ivrLibaTemplateVO.getNoVoiceNum().intValue()) { | 
|---|
|  |  |  | //                    //已经问了对应的遍数,就判断是否还有下一题 | 
|---|
|  |  |  | //                    if (nowQuestion.getTargetid() == ivrLibaTemplateScriptVOs.size()) { | 
|---|
|  |  |  | //                        //没有下一题了,就挂断电话,播放结束语 | 
|---|
|  |  |  | //                        redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                        phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | //                    } else { | 
|---|
|  |  |  | //                        //有下一题 | 
|---|
|  |  |  | //                        redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                        IvrLibaTemplateScriptVO nextQuestion = getNextQuestion(ivrLibaTemplateScriptVOs, nowQuestion); | 
|---|
|  |  |  | //                        // 问题,  去调用“tts合成和播放”接口 | 
|---|
|  |  |  | //                        phoneUtils.ttsPlayback(nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                } else { | 
|---|
|  |  |  | //                    redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", noVoice + 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                    //调用ivrLibaTemplateScriptVO中的slienceText(静默话术) | 
|---|
|  |  |  | //                    String slienceText = nowQuestion.getSlienceText(); | 
|---|
|  |  |  | //                    //静默话术  + 问题,  去调用“tts合成和播放”接口 | 
|---|
|  |  |  | //                    phoneUtils.ttsPlayback(slienceText + nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | //                    return new PhoneCallBackVO(); | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            } else { | 
|---|
|  |  |  | //                //有回话,对回答的问题,进行正则匹配(这里只针对选择题,其它题型不行) | 
|---|
|  |  |  | //                for (int j = 0; j < nowQuestion.getIvrLibaScriptTargetoptionList().size(); j++) { | 
|---|
|  |  |  | //                    //包含 | 
|---|
|  |  |  | //                    Matcher matcher = null; | 
|---|
|  |  |  | //                    if (StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex())) { | 
|---|
|  |  |  | //                        Pattern pattern = Pattern.compile(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()); | 
|---|
|  |  |  | //                        matcher = pattern.matcher(phoneCallBackVO.getTextResult()); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                    //不包含 | 
|---|
|  |  |  | //                    Matcher matcher2 = null; | 
|---|
|  |  |  | //                    if (StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2())) { | 
|---|
|  |  |  | //                        Pattern pattern2 = Pattern.compile(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()); | 
|---|
|  |  |  | //                        matcher2 = pattern2.matcher(phoneCallBackVO.getTextResult()); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                    log.info("phoneCallBack--Targetregex的值为:{}, phoneCallBack--Targetregex2的值为:{}", nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex(), nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()); | 
|---|
|  |  |  | //                    if (StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() && StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) { | 
|---|
|  |  |  | //                        //说明匹配正确了 | 
|---|
|  |  |  | //                        //这里应该先判断类型,去再修改,设置IsUserOperation是单选题的改法 | 
|---|
|  |  |  | //                        nowQuestion.getIvrLibaScriptTargetoptionList().get(j).setIsUserOperation(true); | 
|---|
|  |  |  | //                        ivrLibaScriptTargetoptionMapper.updateIvrLibaTemplateTargetoption(nowQuestion.getIvrLibaScriptTargetoptionList().get(j)); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                        //将静默置为0 | 
|---|
|  |  |  | //                        redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                        redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", 0, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                        //获取下一题 | 
|---|
|  |  |  | //                        Integer nextQuestion = nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getNextQuestion(); | 
|---|
|  |  |  | //                        for (IvrLibaTemplateScriptVO script : ivrLibaTemplateScriptVOs) { | 
|---|
|  |  |  | //                            if (script.getTargetid() == nextQuestion) { | 
|---|
|  |  |  | //                                QuestionMessage questionMessage = new QuestionMessage(); | 
|---|
|  |  |  | //                                questionMessage.setNowQuestion(script); | 
|---|
|  |  |  | //                                questionMessage.setQuestionList(ivrLibaTemplateScriptVOs); | 
|---|
|  |  |  | //                                redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                                break; | 
|---|
|  |  |  | //                            } | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  | //                        break; | 
|---|
|  |  |  | //                    } else { | 
|---|
|  |  |  | //                        //没有匹配到 | 
|---|
|  |  |  | //                        Integer mateNum = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "mateNum"); | 
|---|
|  |  |  | //                        //无匹配次数去判断是否到最大询问次数,并且所有的选项都匹配完了 | 
|---|
|  |  |  | //                        if (mateNum == ivrLibaTemplateVO.getMateNum().intValue() && j == nowQuestion.getIvrLibaScriptTargetoptionList().size() - 1) { | 
|---|
|  |  |  | //                            //如果下一题为空.则新的数据返回,并加上感谢语 | 
|---|
|  |  |  | //                            if (nowQuestion.getTargetid() < ivrLibaTemplateScriptVOs.size()) { | 
|---|
|  |  |  | //                                QuestionMessage questionMessage = new QuestionMessage(); | 
|---|
|  |  |  | //                                IvrLibaTemplateScriptVO nextQuestion = getNextQuestion(ivrLibaTemplateScriptVOs, nowQuestion); | 
|---|
|  |  |  | //                                questionMessage.setQuestionList(ivrLibaTemplateScriptVOs); | 
|---|
|  |  |  | //                                questionMessage.setNowQuestion(nextQuestion); | 
|---|
|  |  |  | //                                redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                                redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", 0, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                            } else { | 
|---|
|  |  |  | //                                //就可以挂断电话了 | 
|---|
|  |  |  | //                                redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                                phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid()); | 
|---|
|  |  |  | //                                break; | 
|---|
|  |  |  | //                            } | 
|---|
|  |  |  | //                        } else if (mateNum < ivrLibaTemplateVO.getMateNum().intValue() && j == nowQuestion.getIvrLibaScriptTargetoptionList().size() - 1) { | 
|---|
|  |  |  | //                            //没有问到规定次数 | 
|---|
|  |  |  | //                            mateNum = mateNum + 1; | 
|---|
|  |  |  | //                            redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", mateNum, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | //                //选项匹配完成后,需要再去通过库再进行匹配一次 | 
|---|
|  |  |  | //                String extemplateID = ivrLibaTemplateVO.getSubmoduleID(); | 
|---|
|  |  |  | //                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)); | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                    List<IvrLibaExtemplatescript> ivrLibaExtemplatescripts = ivrLibaExtemplatescriptMapper.queryIvrLibaExtemplatescriptList(list1); | 
|---|
|  |  |  | //                    for (IvrLibaExtemplatescript ivrLibaExtemplatescript : ivrLibaExtemplatescripts) { | 
|---|
|  |  |  | //                        Matcher matcher = null; | 
|---|
|  |  |  | //                        if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex())) { | 
|---|
|  |  |  | //                            Pattern pattern = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex()); | 
|---|
|  |  |  | //                            matcher = pattern.matcher(returnQues.getContent()); | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                        Matcher matcher2 = null; | 
|---|
|  |  |  | //                        if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2())) { | 
|---|
|  |  |  | //                            Pattern pattern2 = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex2()); | 
|---|
|  |  |  | //                            matcher2 = pattern2.matcher(returnQues.getContent()); | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  | //                        log.info("++++++++++++++++++++++++++通用库是否为空:selfRegex : {} , selfRegex2 : {}", ivrLibaExtemplatescript.getSelfRegex(), ivrLibaExtemplatescript.getSelfRegex2()); | 
|---|
|  |  |  | //                        if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex()) && matcher.matches() && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && matcher2.matches() || StringUtils.isEmpty(ivrLibaExtemplatescript.getSelfRegex()) && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && matcher2.matches() || StringUtils.isEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex()) && matcher.matches()) { | 
|---|
|  |  |  | //                            QuestionMessage questionMessage = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "returnQues"); | 
|---|
|  |  |  | //                            IvrLibaTemplateScriptVO ivrLibaTemplateScriptVO = returnQues.getNowQuestion(); | 
|---|
|  |  |  | //                            ivrLibaTemplateScriptVO.setSubmoduleText(ivrLibaExtemplatescript.getSwitchText()); | 
|---|
|  |  |  | //                            ivrLibaTemplateScriptVO.setSubmoduleVoice(ivrLibaExtemplatescript.getSwitchWav()); | 
|---|
|  |  |  | //                            redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                            if (ivrLibaExtemplatescript.getIsEnd() == 1) { | 
|---|
|  |  |  | //                                //将问题置空 | 
|---|
|  |  |  | //                                IvrLibaTemplateScriptVO nowQuestion1 = questionMessage.getNowQuestion(); | 
|---|
|  |  |  | //                                nowQuestion1.setQuestionText(null); | 
|---|
|  |  |  | //                                nowQuestion1.setQuestionVoice(null); | 
|---|
|  |  |  | //                                questionMessage.setNowQuestion(nowQuestion1); | 
|---|
|  |  |  | //                                redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                                redisCache.setCacheObject(phoneCallBackVO.getUuid() + "isOver", 1, 120, TimeUnit.MINUTES); | 
|---|
|  |  |  | //                            } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                            //调用“15、tts合成和播放, tts_playback”将结果传回 | 
|---|
|  |  |  | // | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //                        } | 
|---|
|  |  |  | //                        break; | 
|---|
|  |  |  | //                    } | 
|---|
|  |  |  | //                } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        return phoneCallBackVO; | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private IvrLibaTemplateScriptVO getNextQuestion(List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOList, IvrLibaTemplateScriptVO ivrLibaTemplateScriptVO) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (int j = 0; j < ivrLibaTemplateScriptVOList.size(); j++) { | 
|---|