| | |
| | | import com.smartor.mapper.IvrLibaExtemplatescriptMapper; |
| | | import com.smartor.service.IIvrLibaTemplateService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.socket.BinaryMessage; |
| | |
| | | if (socketMessage.getTemplateId() != null) { |
| | | //通过模板ID获取模板问题 |
| | | IvrLibaTemplateVO ivrLibaTemplateVO = new IvrLibaTemplateVO(); |
| | | ivrLibaTemplateVO.setID(socketMessage.getTemplateId()); |
| | | ivrLibaTemplateVO.setId(socketMessage.getTemplateId()); |
| | | IvrLibaTemplateVO ivrLibaTemplateVO1 = ivrLibaTemplateService.selectInfoByCondition(ivrLibaTemplateVO); |
| | | redisCache.setCacheObject(userId + "ivrLibaTemplateVO1", ivrLibaTemplateVO1, 120, TimeUnit.MINUTES); |
| | | //将查出来的问题,放到全局变量中去 |
| | | List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOList = ivrLibaTemplateVO1.getIvrLibaTemplateScriptVOList(); |
| | | //根据序号进行排序 |
| | | Collections.sort(ivrLibaTemplateScriptVOList, Comparator.comparing(IvrLibaTemplateScriptVO::getTargetid)); |
| | | Collections.sort(ivrLibaTemplateScriptVOList, Comparator.comparing(IvrLibaTemplateScriptVO::getSort)); |
| | | |
| | | //将查出来的数据放到redis中 |
| | | redisCache.setCacheObject(userId + "ivrLibaTemplateScriptVOList", ivrLibaTemplateScriptVOList, 120, TimeUnit.MINUTES); |
| | |
| | | redisCache.setCacheObject(userId + "isOver", 0, 120, TimeUnit.MINUTES); |
| | | |
| | | //用来返回当前需要问的问题信息 |
| | | QuestionMessage returnQues = new QuestionMessage(); |
| | | QuestionMessagePhone returnQues = new QuestionMessagePhone(); |
| | | |
| | | |
| | | for (IvrLibaTemplateScriptVO ivrLibaTemplateScriptVO : ivrLibaTemplateScriptVOList) { |
| | | if (ivrLibaTemplateScriptVO.getTargetid() == ivrLibaTemplateVO1.getFirstQuestionNum().intValue()) |
| | | if (ivrLibaTemplateScriptVO.getSort() == ivrLibaTemplateVO1.getFirstQuestionNum().intValue()) |
| | | //获取第一题的问题 |
| | | returnQues.setNowQuestion(ivrLibaTemplateScriptVO); |
| | | // returnQues.setCode(ivrLibaTemplateScriptVO.getTargetid() + 1); |
| | | // returnQues.setCode(ivrTaskTemplateScriptVO.getTargetid() + 1); |
| | | } |
| | | // returnQues.setKcb("你好,大傻狗,我们是某某某医院,现在需要做一次随访;"); |
| | | // 设置开场白 |
| | | returnQues.setKcb(ivrLibaTemplateVO1.getRevisitBefore()); |
| | | |
| | | //记录响应 |
| | |
| | | //获取socketMessage里的QuestionMessage,对答案进行处理然后,再问下一道 |
| | | Gson gson = new Gson(); |
| | | if (!StringUtils.isEmpty(socketMessage.getContent())) { |
| | | socketMessage.setQuestionMessage(gson.fromJson(socketMessage.getContent(), QuestionMessage.class)); |
| | | socketMessage.setQuestionMessage(gson.fromJson(socketMessage.getContent(), QuestionMessagePhone.class)); |
| | | } |
| | | |
| | | QuestionMessage questionMessage = socketMessage.getQuestionMessage(); |
| | | QuestionMessagePhone questionMessage = socketMessage.getQuestionMessage(); |
| | | List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOList = redisCache.getCacheObject(userId + "ivrLibaTemplateScriptVOList"); |
| | | //根据前端传回的条件,获取当前题目 |
| | | IvrLibaTemplateScriptVO ivrLibaTemplateScriptVO = questionMessage.getNowQuestion(); |
| | | if (ivrLibaTemplateScriptVO.getID() == null) { |
| | | QuestionMessage returnQues = redisCache.getCacheObject(userId + "returnQues"); |
| | | if (ivrLibaTemplateScriptVO.getId() == null) { |
| | | QuestionMessagePhone returnQues = redisCache.getCacheObject(userId + "returnQues"); |
| | | ivrLibaTemplateScriptVO = returnQues.getNowQuestion(); |
| | | } |
| | | //获取模板信息 |
| | | IvrLibaTemplateVO ivrLibaTemplateVO1 = redisCache.getCacheObject(userId + "ivrLibaTemplateVO1"); |
| | | |
| | | |
| | | if (StringUtils.isEmpty(questionMessage.getContent())) { |
| | | //调用ivrLibaTemplateScriptVO中的slienceText(静默话术) |
| | | //调用ivrTaskTemplateScriptVO中的slienceText(静默话术) |
| | | Integer noVoice = redisCache.getCacheObject(userId + "noVoice"); |
| | | //实际静默次数是否 等于 模板中配置的次数 |
| | | if (noVoice == ivrLibaTemplateVO1.getNoVoiceNum().intValue()) { |
| | |
| | | redisCache.setCacheObject(userId + "backQuset", backQuset, 120, TimeUnit.MINUTES); |
| | | |
| | | //如果几次都没响应,就下一题(需要先判断是否有下一题) |
| | | if (ivrLibaTemplateScriptVO.getTargetid() == ivrLibaTemplateScriptVOList.size()) { |
| | | if (ivrLibaTemplateScriptVO.getSort() == 0) { |
| | | //如果下一题没有了,就结束了 |
| | | QuestionMessage returnQues = new QuestionMessage(); |
| | | QuestionMessagePhone returnQues = new QuestionMessagePhone(); |
| | | // returnQues.setCode(null); |
| | | List<IvrLibaTemplateScriptVO> backQusetRedis = redisCache.getCacheObject(userId + "backQuset"); |
| | | returnQues.setContent(JSON.toJSONString(backQusetRedis)); |
| | | returnQues.setJsy("感谢您的耐心回答,再见"); |
| | | returnQues.setJsy(ivrLibaTemplateVO1.getRevisitAfter()); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | redisCache.setCacheObject(userId + "isOver", 1, 120, TimeUnit.MINUTES); |
| | | |
| | | } else { |
| | | //如果有下一题,就根据当前teagetID+1 获取下一题 |
| | | QuestionMessage returnQues = getNextQuestion(ivrLibaTemplateScriptVOList, ivrLibaTemplateScriptVO); |
| | | QuestionMessagePhone returnQues = getNextQuestion(ivrLibaTemplateScriptVOList, ivrLibaTemplateScriptVO); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | redisCache.setCacheObject(userId + "noVoice", 0, 120, TimeUnit.MINUTES); |
| | | } |
| | |
| | | |
| | | Integer noVoice2 = redisCache.getCacheObject(userId + "noVoice"); |
| | | noVoice2 = noVoice2 + 1; |
| | | |
| | | //给问题加上无匹配话术 |
| | | QuestionMessagePhone returnQues = redisCache.getCacheObject(userId + "returnQues"); |
| | | IvrLibaTemplateScriptVO nowQuestion = returnQues.getNowQuestion(); |
| | | boolean contains = nowQuestion.getScriptContent().contains(nowQuestion.getNoMatchText()); |
| | | if (!contains) { |
| | | String scriptContent = nowQuestion.getSlienceText() + "," + nowQuestion.getScriptContent(); |
| | | nowQuestion.setScriptContent(scriptContent); |
| | | } |
| | | returnQues.setNowQuestion(nowQuestion); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | redisCache.setCacheObject(userId + "noVoice", noVoice2, 120, TimeUnit.MINUTES); |
| | | } |
| | | } else { |
| | | //对回答的问题,进行正则匹配(这里只针对选择题,其它题型不行) |
| | | for (int j = 0; j < ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().size(); j++) { |
| | | //包含 |
| | | Matcher matcher = null; |
| | | if (StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex())) { |
| | | Pattern pattern = Pattern.compile(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()); |
| | | matcher = pattern.matcher(questionMessage.getContent()); |
| | | } |
| | | //不包含 |
| | | Matcher matcher2 = null; |
| | | if (StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2())) { |
| | | Pattern pattern2 = Pattern.compile(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()); |
| | | matcher2 = pattern2.matcher(questionMessage.getContent()); |
| | | } |
| | | log.info("==============================Targetregex的值为:{}, Targetregex2的值为:{}", ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex(), ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()); |
| | | |
| | | if (StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() && StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) { |
| | | //说明匹配正确了 |
| | | ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).setIsUserOperation(true); |
| | | List<IvrLibaTemplateScriptVO> backQuset = redisCache.getCacheObject(userId + "backQuset"); |
| | | //匹配完成后,将结果保存到新的数组 |
| | | backQuset.add(ivrLibaTemplateScriptVO); |
| | | redisCache.setCacheObject(userId + "backQuset", backQuset, 120, TimeUnit.MINUTES); |
| | | //将静默置为0 |
| | | redisCache.setCacheObject(userId + "noVoice", 0, 120, TimeUnit.MINUTES); |
| | | //获取下一题 |
| | | Integer nextQuestion = ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getNextQuestion(); |
| | | for (IvrLibaTemplateScriptVO script : ivrLibaTemplateScriptVOList) { |
| | | if (script.getTargetid() == nextQuestion) { |
| | | QuestionMessage returnQues = new QuestionMessage(); |
| | | returnQues.setNowQuestion(script); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | break; |
| | | } |
| | | } |
| | | break; |
| | | } else { |
| | | //没有匹配到 |
| | | Integer mateNum = redisCache.getCacheObject(userId + "mateNum"); |
| | | |
| | | //无匹配次数去判断是否到最大询问次数,并且所有的选项都匹配完了 |
| | | if (mateNum == ivrLibaTemplateVO1.getMateNum().intValue() && j == ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().size() - 1) { |
| | | //问了最大询问次数后,还是没有匹配上,将结果保存到新的数组 |
| | | List<IvrLibaTemplateScriptVO> backQuset = redisCache.getCacheObject(userId + "backQuset"); |
| | | backQuset.add(ivrLibaTemplateScriptVO); |
| | | redisCache.setCacheObject(userId + "backQuset", backQuset, 120, TimeUnit.MINUTES); |
| | | |
| | | //如果下一题为空.则新的数据返回,并加上感谢语 |
| | | if (ivrLibaTemplateScriptVO.getTargetid() < ivrLibaTemplateScriptVOList.size()) { |
| | | QuestionMessage returnQues = getNextQuestion(ivrLibaTemplateScriptVOList, ivrLibaTemplateScriptVO); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | redisCache.setCacheObject(userId + "mateNum", 0, 120, TimeUnit.MINUTES); |
| | | } else { |
| | | QuestionMessage returnQues2 = new QuestionMessage(); |
| | | // returnQues2.setCode(null); |
| | | List<IvrLibaTemplateScriptVO> backQusetRedis = redisCache.getCacheObject(userId + "backQuset"); |
| | | returnQues2.setQuestionList(backQusetRedis); |
| | | returnQues2.setJsy("感谢您的耐心回答,再见"); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues2, 120, TimeUnit.MINUTES); |
| | | redisCache.setCacheObject(userId + "isOver", 1, 120, TimeUnit.MINUTES); |
| | | break; |
| | | } |
| | | } else if (mateNum < ivrLibaTemplateVO1.getMateNum().intValue() && j == ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().size() - 1) { |
| | | //没有问到规定次数 |
| | | mateNum = mateNum + 1; |
| | | redisCache.setCacheObject(userId + "mateNum", mateNum, 120, TimeUnit.MINUTES); |
| | | } |
| | | } |
| | | } |
| | | //选项匹配完成后,需要再去通过库再进行匹配一次 |
| | | String extemplateID = ivrLibaTemplateVO1.getSubmoduleID(); |
| | | String[] split = extemplateID.split(","); |
| | | List<String> list = Arrays.asList(split); |
| | | List<Long> list1 = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(extemplateID)) { |
| | | if (org.apache.commons.lang3.StringUtils.isNotEmpty(extemplateID)) { |
| | | String[] split = extemplateID.split(","); |
| | | List<String> list = Arrays.asList(split); |
| | | List<Long> list1 = new ArrayList<>(); |
| | | for (String str : list) { |
| | | list1.add(Long.valueOf(str)); |
| | | } |
| | | List<IvrLibaExtemplatescript> ivrLibaExtemplatescripts = ivrLibaExtemplatescriptMapper.queryIvrLibaExtemplatescriptList(list1); |
| | | IvrLibaExtemplatescript les = null; |
| | | for (IvrLibaExtemplatescript ivrLibaExtemplatescript : ivrLibaExtemplatescripts) { |
| | | Matcher matcher = null; |
| | | if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex())) { |
| | | if (org.apache.commons.lang3.StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex())) { |
| | | Pattern pattern = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex()); |
| | | matcher = pattern.matcher(questionMessage.getContent()); |
| | | } |
| | | |
| | | Matcher matcher2 = null; |
| | | if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2())) { |
| | | if (org.apache.commons.lang3.StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2())) { |
| | | Pattern pattern2 = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex2()); |
| | | matcher2 = pattern2.matcher(questionMessage.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 returnQues = redisCache.getCacheObject(userId + "returnQues"); |
| | | IvrLibaTemplateScriptVO nowQuestion = returnQues.getNowQuestion(); |
| | | nowQuestion.setSubmoduleText(ivrLibaExtemplatescript.getSwitchText()); |
| | | nowQuestion.setSubmoduleVoice(ivrLibaExtemplatescript.getSwitchWav()); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | if (ivrLibaExtemplatescript.getIsEnd() == 1) { |
| | | //将问题置空 |
| | | IvrLibaTemplateScriptVO nowQuestion1 = returnQues.getNowQuestion(); |
| | | nowQuestion1.setQuestionText(null); |
| | | nowQuestion1.setQuestionVoice(null); |
| | | returnQues.setNowQuestion(nowQuestion1); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | |
| | | redisCache.setCacheObject(userId + "isOver", 1, 120, TimeUnit.MINUTES); |
| | | } |
| | | if (org.apache.commons.lang3.StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex()) && matcher.matches() && org.apache.commons.lang3.StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && matcher2.matches() || org.apache.commons.lang3.StringUtils.isEmpty(ivrLibaExtemplatescript.getSelfRegex()) && org.apache.commons.lang3.StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && matcher2.matches() || org.apache.commons.lang3.StringUtils.isEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && org.apache.commons.lang3.StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex()) && matcher.matches()) { |
| | | //将通用库匹配的,放到返回值中 |
| | | ivrLibaTemplateScriptVO.setCommonValue(ivrLibaExtemplatescript.getSwitchText()); |
| | | les = ivrLibaExtemplatescript; |
| | | } |
| | | break; |
| | | } |
| | | if (ObjectUtils.isNotEmpty(les)) { |
| | | //对匹配的结果处理一下(看看是不是需要挂机) |
| | | if (les.getIsEnd() != null && les.getIsEnd() == 1) { |
| | | //可以挂机了 |
| | | redisCache.deleteObject(userId + "ivrLibaTemplateScriptVOList"); |
| | | redisCache.deleteObject(userId + "backQuset"); |
| | | redisCache.deleteObject(userId + "noVoice"); |
| | | redisCache.deleteObject(userId + "returnQues"); |
| | | redisCache.deleteObject(userId + "isOver"); |
| | | redisCache.deleteObject(userId + "ivrLibaTemplateVO1"); |
| | | QuestionMessagePhone returnQues = new QuestionMessagePhone(); |
| | | List<IvrLibaTemplateScriptVO> backQuset = new ArrayList<>(); |
| | | IvrLibaTemplateScriptVO ls = new IvrLibaTemplateScriptVO(); |
| | | ls.setScriptContent(les.getSwitchText()); |
| | | backQuset.add(ls); |
| | | returnQues.setQuestionList(backQuset); |
| | | returnQues.setNowQuestion(ls); |
| | | session.sendMessage(new TextMessage(JSON.toJSONString(returnQues).getBytes(StandardCharsets.UTF_8))); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | //通过valueType判断是什么题型(值类型(1 选项 2 文本 3 数值)) |
| | | if (ivrLibaTemplateScriptVO.getValueType() == 2 || ivrLibaTemplateScriptVO.getValueType() == 3) { |
| | | ivrLibaTemplateScriptVO.setQuestionResult(questionMessage.getContent()); |
| | | |
| | | List<IvrLibaTemplateScriptVO> backQusetList = redisCache.getCacheObject(userId + "backQuset"); |
| | | //匹配完成后,将结果保存到新的数组 |
| | | backQusetList.add(ivrLibaTemplateScriptVO); |
| | | redisCache.setCacheObject(userId + "backQuset", backQusetList, 120, TimeUnit.MINUTES); |
| | | //将静默置为0 |
| | | redisCache.setCacheObject(userId + "noVoice", 0, 120, TimeUnit.MINUTES); |
| | | //获取下一题 |
| | | Long nextQuestion = Long.valueOf(ivrLibaTemplateScriptVO.getSort() + 1); |
| | | if (nextQuestion > ivrLibaTemplateScriptVOList.size()) { |
| | | //如果下一题没有了,就结束了 |
| | | QuestionMessagePhone returnQues = new QuestionMessagePhone(); |
| | | List<IvrLibaTemplateScriptVO> backQusetRedis = redisCache.getCacheObject(userId + "backQuset"); |
| | | returnQues.setContent(JSON.toJSONString(backQusetRedis)); |
| | | returnQues.setJsy(ivrLibaTemplateVO1.getRevisitAfter()); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | redisCache.setCacheObject(userId + "isOver", 1, 120, TimeUnit.MINUTES); |
| | | } else { |
| | | for (IvrLibaTemplateScriptVO script : ivrLibaTemplateScriptVOList) { |
| | | if (Long.valueOf(script.getSort()) == nextQuestion) { |
| | | QuestionMessagePhone returnQues = new QuestionMessagePhone(); |
| | | returnQues.setNowQuestion(script); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } else if (ivrLibaTemplateScriptVO.getValueType() == 1) { |
| | | |
| | | //对回答的问题,进行正则匹配(这里只针对选择题,其它题型不行)x |
| | | for (int j = 0; j < ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().size(); j++) { |
| | | //包含 |
| | | Matcher matcher = null; |
| | | if (StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex())) { |
| | | Pattern pattern = Pattern.compile(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()); |
| | | matcher = pattern.matcher(questionMessage.getContent()); |
| | | } |
| | | //不包含 |
| | | Matcher matcher2 = null; |
| | | if (StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2())) { |
| | | Pattern pattern2 = Pattern.compile(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()); |
| | | matcher2 = pattern2.matcher(questionMessage.getContent()); |
| | | } |
| | | log.info("==============================Targetregex的值为:{}, Targetregex2的值为:{}", ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex(), ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()); |
| | | |
| | | if (StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() || StringUtils.isEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) { |
| | | log.error("匹配正确了"); |
| | | //说明匹配正确了 |
| | | ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).setIsUserOperation(1); |
| | | List<IvrLibaTemplateScriptVO> backQuset = redisCache.getCacheObject(userId + "backQuset"); |
| | | //匹配完成后,将结果保存到新的数组 |
| | | backQuset.add(ivrLibaTemplateScriptVO); |
| | | redisCache.setCacheObject(userId + "backQuset", backQuset, 120, TimeUnit.MINUTES); |
| | | //将静默置为0 |
| | | redisCache.setCacheObject(userId + "noVoice", 0, 120, TimeUnit.MINUTES); |
| | | //获取下一题 |
| | | Integer nextQuestion = ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().get(j).getNextQuestion(); |
| | | if (nextQuestion > ivrLibaTemplateScriptVOList.size()) { |
| | | //如果下一题没有了,就结束了 |
| | | QuestionMessagePhone returnQues = new QuestionMessagePhone(); |
| | | List<IvrLibaTemplateScriptVO> backQusetRedis = redisCache.getCacheObject(userId + "backQuset"); |
| | | returnQues.setContent(JSON.toJSONString(backQusetRedis)); |
| | | returnQues.setJsy(ivrLibaTemplateVO1.getRevisitAfter()); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | redisCache.setCacheObject(userId + "isOver", 1, 120, TimeUnit.MINUTES); |
| | | } else { |
| | | for (IvrLibaTemplateScriptVO script : ivrLibaTemplateScriptVOList) { |
| | | if (script.getSort() == nextQuestion) { |
| | | QuestionMessagePhone returnQues = new QuestionMessagePhone(); |
| | | returnQues.setNowQuestion(script); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | } else { |
| | | log.error("无匹配"); |
| | | //没有匹配到 |
| | | Integer mateNum = redisCache.getCacheObject(userId + "mateNum"); |
| | | |
| | | //无匹配次数去判断是否到最大询问次数,并且所有的选项都匹配完了 |
| | | if (mateNum == ivrLibaTemplateVO1.getMateNum().intValue() && j == ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().size() - 1) { |
| | | //问了最大询问次数后,还是没有匹配上,将结果保存到新的数组 |
| | | List<IvrLibaTemplateScriptVO> backQuset = redisCache.getCacheObject(userId + "backQuset"); |
| | | backQuset.add(ivrLibaTemplateScriptVO); |
| | | redisCache.setCacheObject(userId + "backQuset", backQuset, 120, TimeUnit.MINUTES); |
| | | |
| | | //如果下一题为空.则新的数据返回,并加上感谢语 |
| | | if (ivrLibaTemplateScriptVO.getSort() == 0) { |
| | | QuestionMessagePhone returnQues = getNextQuestion(ivrLibaTemplateScriptVOList, ivrLibaTemplateScriptVO); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | redisCache.setCacheObject(userId + "mateNum", 0, 120, TimeUnit.MINUTES); |
| | | } else { |
| | | QuestionMessagePhone returnQues2 = new QuestionMessagePhone(); |
| | | // returnQues2.setCode(null); |
| | | List<IvrLibaTemplateScriptVO> backQusetRedis = redisCache.getCacheObject(userId + "backQuset"); |
| | | returnQues2.setQuestionList(backQusetRedis); |
| | | returnQues2.setJsy(ivrLibaTemplateVO1.getRevisitAfter()); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues2, 120, TimeUnit.MINUTES); |
| | | redisCache.setCacheObject(userId + "isOver", 1, 120, TimeUnit.MINUTES); |
| | | break; |
| | | } |
| | | } else if (mateNum < ivrLibaTemplateVO1.getMateNum().intValue() && j == ivrLibaTemplateScriptVO.getIvrLibaScriptTargetoptionList().size() - 1) { |
| | | //没有问到规定次数 |
| | | mateNum = mateNum + 1; |
| | | redisCache.setCacheObject(userId + "mateNum", mateNum, 120, TimeUnit.MINUTES); |
| | | //给问题加上无匹配话术 |
| | | QuestionMessagePhone returnQues = redisCache.getCacheObject(userId + "returnQues"); |
| | | IvrLibaTemplateScriptVO nowQuestion = returnQues.getNowQuestion(); |
| | | boolean contains = false; |
| | | if (StringUtils.isNotEmpty(nowQuestion.getNoMatchText())) |
| | | contains = nowQuestion.getScriptContent().contains(nowQuestion.getNoMatchText()); |
| | | if (!contains) { |
| | | String scriptContent = nowQuestion.getNoMatchText() + "," + nowQuestion.getScriptContent(); |
| | | nowQuestion.setScriptContent(scriptContent); |
| | | } |
| | | returnQues.setNowQuestion(nowQuestion); |
| | | redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // //选项匹配完成后,需要再去通过库再进行匹配一次 |
| | | // String extemplateID = ivrLibaTemplateVO1.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(questionMessage.getContent()); |
| | | // } |
| | | // |
| | | // Matcher matcher2 = null; |
| | | // if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2())) { |
| | | // Pattern pattern2 = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex2()); |
| | | // matcher2 = pattern2.matcher(questionMessage.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()) { |
| | | // QuestionMessagePhone returnQues = redisCache.getCacheObject(userId + "returnQues"); |
| | | // IvrLibaTemplateScriptVO nowQuestion = returnQues.getNowQuestion(); |
| | | // nowQuestion.setSubmoduleText(ivrLibaExtemplatescript.getSwitchText()); |
| | | // nowQuestion.setSubmoduleVoice(ivrLibaExtemplatescript.getSwitchWav()); |
| | | // redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | // if (ivrLibaExtemplatescript.getIsEnd() == 1) { |
| | | // //将问题置空 |
| | | // IvrLibaTemplateScriptVO nowQuestion1 = returnQues.getNowQuestion(); |
| | | // nowQuestion1.setScriptContent(null); |
| | | // nowQuestion1.setScriptVoice(null); |
| | | // returnQues.setNowQuestion(nowQuestion1); |
| | | // redisCache.setCacheObject(userId + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | // |
| | | // redisCache.setCacheObject(userId + "isOver", 1, 120, TimeUnit.MINUTES); |
| | | // } |
| | | // } |
| | | // break; |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | } |
| | | QuestionMessage returnQues = redisCache.getCacheObject(userId + "returnQues"); |
| | | QuestionMessagePhone returnQues = redisCache.getCacheObject(userId + "returnQues"); |
| | | List<IvrLibaTemplateScriptVO> backQusetRedis = redisCache.getCacheObject(userId + "backQuset"); |
| | | returnQues.setQuestionList(backQusetRedis); |
| | | session.sendMessage(new TextMessage(JSON.toJSONString(returnQues).getBytes(StandardCharsets.UTF_8))); |
| | |
| | | } |
| | | |
| | | //获取下一题(这个方法不适合选项中的nextQuestion) |
| | | private QuestionMessage getNextQuestion(List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOList, IvrLibaTemplateScriptVO ivrLibaTemplateScriptVO) { |
| | | QuestionMessage returnQues = new QuestionMessage(); |
| | | private QuestionMessagePhone getNextQuestion(List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOList, IvrLibaTemplateScriptVO ivrLibaTemplateScriptVO) { |
| | | QuestionMessagePhone returnQues = new QuestionMessagePhone(); |
| | | for (int j = 0; j < ivrLibaTemplateScriptVOList.size(); j++) { |
| | | if (ivrLibaTemplateScriptVOList.get(j).getTargetid() == ivrLibaTemplateScriptVO.getTargetid() + 1) { |
| | | if (ivrLibaTemplateScriptVOList.get(j).getSort() == ivrLibaTemplateScriptVO.getSort() + 1) { |
| | | // 对该条templateScriptVO进行处理 |
| | | returnQues.setNowQuestion(ivrLibaTemplateScriptVOList.get(j)); |
| | | } |