liusheng
2024-05-07 29d027349c605bda0b7944301cd82a25ec9c1d7a
smartor/src/main/java/com/smartor/service/impl/IvrTaskSingleServiceImpl.java
@@ -49,6 +49,9 @@
    private IvrLibaTemplateTargetoptionMapper ivrLibaScriptTargetoptionMapper;
    @Autowired
    private IvrTaskVisitResultMapper ivrTaskVisitResultMapper;
    @Autowired
    private RedisCache redisCache;
    @Autowired
@@ -326,7 +329,8 @@
    }
    @Override
    public void phoneCallBack(PhoneCallBackVO phoneCallBackVO) {phoneCallBackVO.setTextResult(phoneCallBackVO.getTextResult().substring(0, phoneCallBackVO.getTextResult().length() - 1));
    public void phoneCallBack(PhoneCallBackVO phoneCallBackVO) {
        phoneCallBackVO.setTextResult(phoneCallBackVO.getTextResult().substring(0, phoneCallBackVO.getTextResult().length() - 1));
        //获取数据
        Boolean aBoolean = redisCache.hasKey(phoneCallBackVO.getUuid());
@@ -338,8 +342,7 @@
        if (hangupValue != null && hangupValue == 1) {
            log.info("电话要挂断了");
            //hangupValue == 1  随访结束,直接可以挂电话
            phoneUtils.hangup(null, null, null, null, null, null, null, phoneCallBackVO.getUuid());
            log.info("电话挂断----------------------------");
            phoneUtils.hangup("", "", "", "", "", "", "", phoneCallBackVO.getUuid());
            return;
        }
@@ -388,6 +391,8 @@
            }
        } else {
            //isppd用来记录是否匹配到
            Boolean isppd = false;
            //有回话,对回答的问题,进行正则匹配(这里只针对选择题,其它题型不行)
            for (int j = 0; j < nowQuestion.getIvrLibaScriptTargetoptionList().size(); j++) {
                //包含
@@ -403,7 +408,9 @@
                    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()) {
                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);
@@ -412,6 +419,19 @@
                    //将静默置为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) {
@@ -426,40 +446,55 @@
                            //没有下一题了,就结束了
                            redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES);
                            phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid());
                            phoneUtils.hangup(null, null, null, null, null, null, null, phoneCallBackVO.getUuid());
                            try {
                                Thread.sleep(3000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            phoneUtils.hangup("", "", ivrLibaTemplateVO.getRevisitAfter(), "", "", "", "", phoneCallBackVO.getUuid());
                            return;
                        }
                    }
                    return;
                } else {
                    //没有匹配到
                    Integer mateNum = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "mateNum");
                    if (mateNum == null) mateNum = 0;
                    //无匹配次数去判断是否到最大询问次数,并且所有的选项都匹配完了
                    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);
                            phoneUtils.ttsPlayback(nextQuestion.getQuestionText(), phoneCallBackVO.getUuid());
                            return;
                        } else {
                            //就可以挂断电话了
                            redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES);
                            phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid());
                            phoneUtils.hangup(null, null, null, null, null, null, null, phoneCallBackVO.getUuid());
                            return;
                        }
                    } else if (mateNum < ivrLibaTemplateVO.getMateNum().intValue() && j == nowQuestion.getIvrLibaScriptTargetoptionList().size() - 1) {
                        //没有问到规定次数
                        mateNum = mateNum + 1;
                        redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", mateNum, 120, TimeUnit.MINUTES);
                    //没有匹配上当前option
                    //Targetregex2 为false,表示在Targetregex2中存在  语句中的关键字,这个option就不用再继续匹配了,直接匹配下一个option
                    continue;
                }
            }
            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());
                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        phoneUtils.hangup("", "", ivrLibaTemplateVO.getRevisitAfter(), "", "", "", "", phoneCallBackVO.getUuid());
                        return;
                    }
                } else if (mateNum < ivrLibaTemplateVO.getMateNum().intValue()) {
                    //没有问到规定次数
                    mateNum = mateNum + 1;
                    redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", mateNum, 120, TimeUnit.MINUTES);
                }
            }
            //选项匹配完成后,需要再去通过库再进行匹配一次