陈昶聿
昨天 21c27eaa5280713b0ec39423bbe6e3d7541f1da7
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -32,6 +32,7 @@
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.ibatis.annotations.Param;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
@@ -39,8 +40,10 @@
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
@@ -655,9 +658,16 @@
        ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(serviceSubtaskTemplateVO.getSubId());
        if (serviceSubtask == null || serviceSubtask.getSendstate() != 2L)
            throw new BaseException("该任务已发送给患者,不能再进行修改模板");
        serviceSubtaskTemplateVO.getSvyTaskTemplateVO().setIntroduce("该问卷是替换后的问题,替换前的问题是:" + serviceSubtask.getTemplateid());
        Integer taskTempid = svyTaskTemplateService.saveOrUpdateTemplate(serviceSubtaskTemplateVO.getSvyTaskTemplateVO());
        if (taskTempid == null) return false;
        //每次都新建一个也可以,但新建之后要把之前的删除
        if (serviceSubtask.getType().equals("2")) {
            svyTaskTemplateService.deleteSvyTaskTemplateBySvyid(serviceSubtask.getTemplateid());
        } else if (serviceSubtask.getType().equals("1"))
            ivrTaskTemplateService.deleteIvrTaskTemplateByID(serviceSubtask.getTemplateid());
        String tempName = svyTaskTemplateService.selectSvyTaskTemplateBySvyid(Long.valueOf(taskTempid)).getSvyname();
        serviceSubtask.setTemplateid(taskTempid.longValue());
@@ -1724,42 +1734,43 @@
            if (ivrTaskTemplateScriptVO.getScriptType().equals("1")) {
                //用来标记,是否有匹配上的
                Integer flag = 0;
//                //2-AI识别
//                SysConfig configVoiceMatchType = new SysConfig();
//                configVoiceMatchType.setOrgid(phoneCallReqYQVO.getOrgid());
//                configVoiceMatchType.setConfigKey("sys.voice.match.type");
//                SysConfig matchType = sysConfigMapper.selectConfig(configVoiceMatchType);
//
//            if (ObjectUtils.isNotEmpty(matchType) && StringUtils.isNotEmpty(matchType.getConfigValue())
//                    && matchType.getConfigValue().equals("2")) {
//                PhoneCallBackYQVO aiMatchResult = AiMatch(phoneCallReqYQVO, phoneCallBackYQVO,
//                        ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate,
//                        ivrTaskTemplateScripts, scriptId, flag);
//                if(aiMatchResult != null){
//                    return aiMatchResult;
//                }
//            } else {
                //是选择题
                for (int j = 0; j < ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().size(); j++) {
                    log.error("phoneCallReqYQVO.getAsrtext()的值为:{}", phoneCallReqYQVO.getAsrtext());
                    if (StringUtils.isEmpty(phoneCallReqYQVO.getAsrtext())) {
                        continue;
                    }
                    //2-AI识别
                    SysConfig configVoiceMatchType = new SysConfig();
                    configVoiceMatchType.setOrgid(phoneCallReqYQVO.getOrgid());
                    configVoiceMatchType.setConfigKey("sys.voice.match.type");
                    SysConfig matchType = sysConfigMapper.selectConfig(configVoiceMatchType);
                    boolean matchedFlag = false;
                    if(ObjectUtils.isNotEmpty(matchType) && StringUtils.isNotEmpty(matchType.getConfigValue()) && matchType.getConfigValue().equals("2")){
                        int checkFlag = DeepSeekApi.matchQuestionAnswer(ivrTaskTemplateScriptVO.getScriptContent(),
                                phoneCallReqYQVO.getAsrtext(),
                                ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetvalue());
                        if(checkFlag == 1){
                            matchedFlag = true;
                        }
                    }else {
                        //包含
                        Matcher matcher = null;
                        if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex())) {
                            Pattern pattern = Pattern.compile(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex());
                            matcher = pattern.matcher(phoneCallReqYQVO.getAsrtext());
                        }
                        //不包含
                        Matcher matcher2 = null;
                        if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2())) {
                            Pattern pattern2 = Pattern.compile(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2());
                            matcher2 = pattern2.matcher(phoneCallReqYQVO.getAsrtext());
                        }
                    //包含
                    Matcher matcher = null;
                    if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex())) {
                        Pattern pattern = Pattern.compile(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex());
                        matcher = pattern.matcher(phoneCallReqYQVO.getAsrtext());
                    }
                    //不包含
                    Matcher matcher2 = null;
                    if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2())) {
                        Pattern pattern2 = Pattern.compile(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2());
                        matcher2 = pattern2.matcher(phoneCallReqYQVO.getAsrtext());
                    }
                        if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) {
                            matchedFlag = true;
                        }
                    if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) {
                        matchedFlag = true;
                    }
                    //说明匹配正确了
                    if(matchedFlag){
@@ -1979,6 +1990,7 @@
                        continue;
                    }
                }
//            }
                //都没有匹配到
                if (StringUtils.isEmpty(phoneCallBackYQVO.getValue())) {
                    log.info("都没有匹配到-------------------------");
@@ -4862,7 +4874,7 @@
                ServiceTaskdept serviceTaskdept = new ServiceTaskdept();
                if (ObjectUtils.isNotEmpty(serviceTaskVo.getDeptcode())) {
                    serviceTaskdept.setDeptType("1");
                    serviceTaskdept.setDeptCode(serviceTask.getDeptcode());
                    serviceTaskdept.setDeptCode(serviceTaskVo.getDeptcode());
                }
                if (ObjectUtils.isNotEmpty(serviceTaskVo.getLeavehospitaldistrictcode())) {
                    serviceTaskdept.setDeptType("2");
@@ -4875,10 +4887,10 @@
                if (!CollectionUtils.isEmpty(serviceTaskdepts)) {
                    PatArchive patArchive = new PatArchive();
                    patArchive.setId(-1L);
                    patArchive.setId(999999999L);
                    patArchive.setName("虚拟患者");
                    //封装serviceSubtask
                    ServiceSubtask serviceSubtask = boxedServiceSubtask(serviceTask, patArchive);
                    ServiceSubtask serviceSubtask = boxedServiceSubtask(serviceTask, serviceTaskdepts.get(0), patArchive);
                    int i = serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
                    //根据生成外链
                    if (ObjectUtils.isNotEmpty(serviceSubtask.getTaskid()) && ObjectUtils.isNotEmpty(serviceSubtask.getPatid()) && ObjectUtils.isNotEmpty(serviceSubtask.getId())) {
@@ -4912,7 +4924,7 @@
        return content;
    }
    public ServiceSubtask boxedServiceSubtask(ServiceTask serviceTask, PatArchive patArchive) {
    public ServiceSubtask boxedServiceSubtask(ServiceTask serviceTask, ServiceTaskdept serviceTaskdept, PatArchive patArchive) {
        ServiceSubtask serviceSubtask = DtoConversionUtils.sourceToTarget(serviceTask, ServiceSubtask.class);
        serviceSubtask.setTaskid(serviceTask.getTaskid());
        if (StringUtils.isNotEmpty(serviceTask.getLibtemplateid()))
@@ -4921,10 +4933,13 @@
//        serviceSubtask.setNurseName(patMedInhosp1.getNurseName());
//        serviceSubtask.setDrcode(patMedInhosp1.getDrcode());
//        serviceSubtask.setDrname(patMedInhosp1.getDrname());
        serviceSubtask.setDeptcode(serviceTask.getDeptcode());
        serviceSubtask.setDeptname(serviceTask.getDeptname());
        serviceSubtask.setLeavehospitaldistrictcode(serviceTask.getLeavehospitaldistrictcode());
        serviceSubtask.setLeavehospitaldistrictname(serviceTask.getLeavehospitaldistrictname());
        if(StringUtils.isNotEmpty(serviceTaskdept.getDeptType()) && serviceTaskdept.getDeptType().equals("1")){
            serviceSubtask.setDeptcode(serviceTaskdept.getDeptCode());
            serviceSubtask.setDeptname(serviceTaskdept.getDeptName());
        }else {
            serviceSubtask.setLeavehospitaldistrictcode(serviceTaskdept.getDeptCode());
            serviceSubtask.setLeavehospitaldistrictname(serviceTaskdept.getDeptName());
        }
        serviceSubtask.setTemplateid(serviceTask.getTemplateid());
        serviceSubtask.setTemplatename(serviceTask.getTemplatename());
        serviceSubtask.setPatid(patArchive.getId());
@@ -4953,4 +4968,274 @@
        serviceSubtask.setVisitTime(newDate);
        return serviceSubtask;
    }
    /**
     * Ai 匹配选项
     * @param questionText
     * @param voiceText
     * @param options
     * @return
     */
    public String matchOptionIndex(String questionText, String voiceText, List<IvrTaskTemplateTargetoption> options) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("userQuestion",questionText);
        jsonObject.put("userAnswer",voiceText);
        jsonObject.put("options", options);
        String jsonString = jsonObject.toJSONString();
        String result = null;
        try {
            result = OkHttpExample.post("http://localhost:8099/matchOptionIndex", jsonString);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return result;
    }
    public PhoneCallBackYQVO AiMatch(PhoneCallReqYQVO phoneCallReqYQVO, PhoneCallBackYQVO phoneCallBackYQVO,
                        IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO, ServiceSubtask serviceSubtask, IvrTaskTemplate ivrTaskTemplate,
                        List<IvrTaskTemplateScript> ivrTaskTemplateScripts, String scriptId, Integer flag){
        PhoneCallBackYQVO back = null;
        String result = "0";
        List<IvrTaskTemplateTargetoption> options = ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList();
        String voiceText = phoneCallReqYQVO.getAsrtext();
        String questionText = StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrtext()) ? ivrTaskTemplateScriptVO.getIvrtext() : ivrTaskTemplateScriptVO.getScriptContent();
        result = matchOptionIndex(questionText, voiceText, options);
        Integer matched = Integer.valueOf(result);
        IvrTaskTemplateTargetoption chosenOption = options.get(matched);
        //说明匹配正确了
        if(matched != null && matched != 0){
            //这里应该先判断类型,去再修改,设置IsUserOperation是单选题的改法
            log.info("匹配正确了吗--------------");
            chosenOption.setIsUserOperation(1);
            serviceTaskScriptTargetoptionMapper.updateIvrTaskTemplateTargetoption(chosenOption);
            //将患者的回签写进service_subtask_detail中
            ServiceSubTaskDetailReq serviceSubTaskDetailReq = new ServiceSubTaskDetailReq();
            List<ServiceSubtaskDetail> serviceSubtaskDetailList = new ArrayList<>();
            ivrTaskTemplateScriptVO.setQuestionResult(chosenOption.getOptiondesc());
            ServiceSubtaskDetail serviceSubtaskDetail = getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate);
            //修改一下语音路径(改成前端可以访问的,存到数据库中)
            if (StringUtils.isNotEmpty(serviceSubtaskDetail.getQuestionvoice())) {
                String questionvoice = serviceSubtaskDetail.getQuestionvoice();
                String[] split = questionvoice.split("\\\\");
                if (split.length > 0) {
                    String lastPart = split[split.length - 1];
                    serviceSubtaskDetail.setQuestionvoice(voicePathPrefix + lastPart);
                }
            }
            serviceSubtaskDetailList.add(serviceSubtaskDetail);
            serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList);
            serviceSubTaskDetailReq.setGuid(phoneCallReqYQVO.getGuid());
            serviceSubTaskDetailReq.setOrgid(phoneCallReqYQVO.getOrgid());
            saveQuestionAnswerPhone(serviceSubTaskDetailReq);
            //判断一下当前的问题是不是满意度问题,并且dutyDeptCode是否有值,并且选项是不是异常选项,如果全符合,则往满意度问题异常表新增
            if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getDutyDeptCode()) && 1 == chosenOption.getIsabnormal()) {
                ServiceSubtaskDetailTrace subtaskDetailTrace = new ServiceSubtaskDetailTrace();
                //用taskid、subid和scriptid去获取detailid
                ServiceSubtaskDetail ssd = new ServiceSubtaskDetail();
                ssd.setSubId(serviceSubtask.getId());
                ssd.setTaskid(serviceSubtask.getTaskid());
                ssd.setScriptid(StringUtils.isNotEmpty(scriptId) ? Long.valueOf(scriptId) : null);
                List<ServiceSubtaskDetail> serviceSubtaskDetails = serviceSubtaskDetailMapper.selectServiceSubtaskDetailList(ssd);
                subtaskDetailTrace.setDetailId(CollectionUtils.isNotEmpty(serviceSubtaskDetails) ? serviceSubtaskDetails.get(0).getId() : null);
                subtaskDetailTrace.setSubId(serviceSubtask.getId());
                subtaskDetailTrace.setTaskid(serviceSubtask.getTaskid());
                subtaskDetailTrace.setTemplateid(ivrTaskTemplateScriptVO.getId());
                subtaskDetailTrace.setTemplatequestionnum(ivrTaskTemplateScriptVO.getScriptno());
                subtaskDetailTrace.setSwitchid(chosenOption.getId());
                subtaskDetailTrace.setQuestiontext(ivrTaskTemplateScriptVO.getScriptContent());
                subtaskDetailTrace.setQuestionvoice(null);
                subtaskDetailTrace.setCategoryname(ivrTaskTemplateScriptVO.getScriptAssortname());
                subtaskDetailTrace.setCategoryid(ivrTaskTemplateScriptVO.getScriptAssortid());
                //获取所有选项
                String optionDescStr = Optional.ofNullable(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList()).filter(list -> !list.isEmpty()).map(list -> list.stream().map(IvrTaskTemplateTargetoption::getOptiondesc).filter(Objects::nonNull).collect(Collectors.joining("&"))).orElse("");
                subtaskDetailTrace.setTargetid(chosenOption.getId());
                subtaskDetailTrace.setTargetvalue(optionDescStr);
                subtaskDetailTrace.setMatchedtext(chosenOption.getOptiondesc());
                subtaskDetailTrace.setValueType(serviceSubtaskDetails.get(0).getValueType());
                subtaskDetailTrace.setTemplateType(1);
                SvyLibScriptCategory svyLibScriptCategory = svyLibScriptCategoryMapper.selectSvyLibScriptCategoryById(ivrTaskTemplateScriptVO.getScriptAssortid());
                subtaskDetailTrace.setType(svyLibScriptCategory.getType());
                subtaskDetailTrace.setScriptid(ivrTaskTemplateScriptVO.getId());
                subtaskDetailTrace.setAsrtext(phoneCallReqYQVO.getAsrtext());
                subtaskDetailTrace.setRecordpath(phoneCallReqYQVO.getRecordpath());
                subtaskDetailTrace.setPatid(serviceSubtask.getPatid());
                JSONObject patdescJson = new JSONObject();
                patdescJson.put("sendname", serviceSubtask.getSendname());
                patdescJson.put("phone", serviceSubtask.getPhone());
                patdescJson.put("age", serviceSubtask.getAge());
                patdescJson.put("sex", serviceSubtask.getSex() != null ? serviceSubtask.getSex() == 1 ? "男" : "女" : null);
                subtaskDetailTrace.setPatdesc(patdescJson.toJSONString());
                subtaskDetailTrace.setTodeptcode(ivrTaskTemplateScriptVO.getDutyDeptCode());
                subtaskDetailTrace.setTodeptname(ivrTaskTemplateScriptVO.getDutyDeptName());
                subtaskDetailTrace.setOrgid(serviceSubtask.getOrgid());
                subtaskDetailTrace.setHandleFlag("0");
                subtaskDetailTrace.setGuid(phoneCallReqYQVO.getGuid());
                subtaskDetailTrace.setCreateTime(new Date());
                subtaskDetailTrace.setUpdateTime(new Date());
                subtaskDetailTrace.setOrgid(phoneCallReqYQVO.getOrgid());
                traceService.insertServiceSubtaskDetailTtrace(subtaskDetailTrace);
            }
            //判断一下,这个选项结果是不是还有继续问下去的必要,例如选项结果是别人不想继续回答问题,就要结束掉
            if (chosenOption.getIsEnd() == 1) {
                redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
                redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE");
                redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop");
                redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "noVoice");
                //在redis中保存一下结束语,在调用挂电话的方法时删除
                ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
                redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES);
                phoneCallBackYQVO.setType("text");
                phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask.getJsy());
                //记录状态
                setFailPreachForm(serviceSubtask, "3", "电话拨打已完成", "9");
                return phoneCallBackYQVO;
            }
            flag = 1;
            //将当前前的播报状态删除,给下一题让位
            redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop");
//                        //获取下一题
            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 = chosenOption.getNextQuestion();
                    //更新分数
                    double score = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE");
                    score = BigDecimal.valueOf(score).add(chosenOption.getScore()).doubleValue();
                    redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score);
                } else {
                    nextQuestion = ivrTaskTemplateScriptVO.getNextScriptno();
                    //更新分数
                    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(chosenOption.getScore()).doubleValue();
                    redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score, 120, TimeUnit.MINUTES);
                }
                if (nextQuestion == null || nextQuestion == 0L) {
                    //如果下一题为空,或者为0,则挂机
                    ServiceSubtask ss = new ServiceSubtask();
                    ss.setId(serviceSubtask.getId());
                    ss.setSendstate(6L);
                    ss.setRemark("电话拨打已完成");
                    serviceSubtaskMapper.updateServiceSubtask(ss);
                    //记录状态
                    setFailPreachForm(serviceSubtask, "3", "电话拨打已完成", "9");
                    redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
                    redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE");
                    redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop");
                    redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "noVoice");
                    //在redis中保存一下结束语,在调用挂电话的方法时删除
                    ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
                    redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES);
                    phoneCallBackYQVO.setType("text");
                    phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask.getJsy());
                    //将结果写进detail表
                    ServiceSubTaskDetailReq ssdReq = new ServiceSubTaskDetailReq();
                    List<ServiceSubtaskDetail> serviceSubtaskDetailList2 = new ArrayList<>();
                    serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate));
                    serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList2);
                    ssdReq.setGuid(phoneCallReqYQVO.getGuid());
                    ssdReq.setOrgid(phoneCallReqYQVO.getOrgid());
                    saveQuestionAnswerPhone(ssdReq);
                    return phoneCallBackYQVO;
                }
                for (IvrTaskTemplateScript script : ivrTaskTemplateScripts) {
                    if (script.getSort() == nextQuestion.intValue()) {
                        phoneCallBackYQVO.setType("text");
                        phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                        String scriptContent = StringUtils.isNotEmpty(script.getIvrtext()) ? script.getIvrtext() : script.getScriptContent();
                        log.error("下一题问题:{}", scriptContent);
                        log.error("下一题的子任务是:{}", serviceSubtask);
                        phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + getObject(serviceSubtask, scriptContent));
                        //将该患者的Redis中的题目ID,进行修改
                        redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim(), script.getId().toString(), 120, TimeUnit.MINUTES);
                        //删除无响应
                        redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid());
                    }
                }
            } else if (ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getNextScriptno() == 0) {
                ServiceTask serviceTask1 = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
                phoneCallBackYQVO.setType("text");
                phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                //更新一下分数
                double score = 0.0;
                Object scoreObj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE");
                if (ObjectUtils.isNotEmpty(scoreObj)) score = (double) scoreObj;
                serviceSubtask.setScore(BigDecimal.valueOf(score));
                serviceSubtask.setFinishtime(new Date());
                serviceSubtask.setSendstate(6L);
                serviceSubtask.setRemark("电话拨打已完成");
                serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
                //记录状态
                setFailPreachForm(serviceSubtask, "3", "电话拨打已完成", "9");
                //设置结束语
                phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask1.getJsy());
                Long id = serviceSubtask.getId();
                Map<String, String> map = delRedisValue(null, id.toString());
                log.error("map的值为:{}", map);
                if (ObjectUtils.isNotEmpty(map))
                    redisCache.setCacheObject(map.get("cacheName"), map.get("val"));
                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中保存一下结束语,在调用挂电话的方法时删除
                ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
                redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES);
//                                return phoneCallBackYQVO;
            }
        } else {
            log.info("没有匹配上----------------------------");
            //flag=0,说明没 匹配上,也要把患者说的话记录下来
            if (matched == ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().size() - 1 && flag == 0) {
                ServiceSubTaskDetailReq serviceSubTaskDetailReq = new ServiceSubTaskDetailReq();
                List<ServiceSubtaskDetail> serviceSubtaskDetailList = new ArrayList<>();
                ServiceSubtaskDetail serviceSubtaskDetail = getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate);
                //修改一下语音路径(改成前端可以访问的,存到数据库中)
                if (StringUtils.isNotEmpty(serviceSubtaskDetail.getQuestionvoice())) {
                    String questionvoice = serviceSubtaskDetail.getQuestionvoice();
                    String[] split = questionvoice.split("\\\\");
                    if (split.length > 0) {
                        String lastPart = split[split.length - 1];
                        serviceSubtaskDetail.setQuestionvoice(voicePathPrefix + lastPart);
                    }
                }
                serviceSubtaskDetailList.add(serviceSubtaskDetail);
                //如果没有 匹配上,这个必须为null
                serviceSubtaskDetailList.get(0).setMatchedtext("");
                serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList);
                serviceSubTaskDetailReq.setGuid(phoneCallReqYQVO.getGuid());
                serviceSubTaskDetailReq.setOrgid(phoneCallReqYQVO.getOrgid());
                saveQuestionAnswerPhone(serviceSubTaskDetailReq);
            }
        }
        return back;
    }
    @Test
    public void TestMatch(){
        String questionText = "您好,请问您是患者本人还是家属?\n";
        String voiceText = "我自己";
        Long scriptid = 31231L;
        List<IvrTaskTemplateTargetoption> options = new ArrayList<>();
        IvrTaskTemplateTargetoption ivrTaskTemplateTargetoption1 = new IvrTaskTemplateTargetoption();
        ivrTaskTemplateTargetoption1.setTargetvalue("本人");
        options.add(ivrTaskTemplateTargetoption1);
        IvrTaskTemplateTargetoption ivrTaskTemplateTargetoption2 = new IvrTaskTemplateTargetoption();
        ivrTaskTemplateTargetoption2.setTargetvalue("家属");
        options.add(ivrTaskTemplateTargetoption2);
        IvrTaskTemplateTargetoption ivrTaskTemplateTargetoption3 = new IvrTaskTemplateTargetoption();
        ivrTaskTemplateTargetoption3.setTargetvalue("其他");
        options.add(ivrTaskTemplateTargetoption3);
        matchOptionIndex(questionText,voiceText,options);
    }
}