liusheng
2024-11-29 fd6dca0c559c08129b7e0abdf67093b1a728ffd3
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -369,6 +369,7 @@
                    //将任务信息新增到随访服务表中
                    serviceSubtask.setSendname(patTaskRelevance.getName());
                    serviceSubtask.setAge(patTaskRelevance.getAge());
                    serviceSubtask.setLibtemplateid(Long.valueOf(serviceTask.getLibtemplateid()));
                    serviceSubtask.setSfzh(patTaskRelevance.getIdcardno());
                    serviceSubtask.setPhone(patTaskRelevance.getTelcode());
                    serviceSubtask.setAddr(patTaskRelevance.getAddr());
@@ -533,7 +534,7 @@
                    // 问题,  去调用“tts合成和播放”接口
                    String date = simpleDateFormat1.format(new Date());
                    log.info("去调用tts合成和播放接口: {},uuid为:{}", date, phoneCallBackVO.getUuid());
                    phoneUtils.ttsPlayback(nowQuestion.getScriptContent(), phoneCallBackVO.getUuid());
                    phoneUtils.ttsPlayback(nowQuestion.getIvrtext(), phoneCallBackVO.getUuid());
                }
            } else {
                redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", noVoice + 1, 120, TimeUnit.MINUTES);
@@ -542,7 +543,7 @@
                //静默话术  + 问题,  去调用“tts合成和播放”接口
                String date = simpleDateFormat1.format(new Date());
                log.info("静默话术  + 问题,去调用tts合成和播放接口: {},uuid为:{}", date, phoneCallBackVO.getUuid());
                phoneUtils.ttsPlayback(slienceText + nowQuestion.getScriptContent(), phoneCallBackVO.getUuid());
                phoneUtils.ttsPlayback(slienceText + nowQuestion.getIvrtext(), phoneCallBackVO.getUuid());
                return;
            }
@@ -563,7 +564,7 @@
                    Pattern pattern2 = Pattern.compile(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2());
                    matcher2 = pattern2.matcher(phoneCallBackVO.getTextResult());
                }
                log.error("PCB--getQuestionText问题为:{},UUID:{}", nowQuestion.getScriptContent(), phoneCallBackVO.getUuid());
                log.error("PCB--getQuestionText问题为:{},UUID:{}", nowQuestion.getIvrtext(), phoneCallBackVO.getUuid());
                if (StringUtils.isNotEmpty(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() || StringUtils.isEmpty(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) {
                    //说明匹配正确了
                    //这里应该先判断类型,去再修改,设置IsUserOperation是单选题的改法
@@ -577,7 +578,7 @@
                    //将患者的回签写进表里
                    IvrTaskVisitResult serviceTaskVisitResult = DtoConversionUtils.sourceToTarget(serviceSubtask, IvrTaskVisitResult.class);
                    serviceTaskVisitResult.setId(null);
                    serviceTaskVisitResult.setQuestion(nowQuestion.getScriptContent());
                    serviceTaskVisitResult.setQuestion(nowQuestion.getIvrtext());
                    serviceTaskVisitResult.setPatientAnswer(phoneCallBackVO.getTextResult());
                    serviceTaskVisitResult.setCreateTime(new Date());
                    serviceTaskVisitResult.setOptionResult(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetvalue());
@@ -594,7 +595,7 @@
                            questionMessage.setNowQuestion(script);
                            questionMessage.setQuestionList(IvrTaskTemplateScriptVOs);
                            redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES);
                            phoneUtils.ttsPlayback(script.getScriptContent(), phoneCallBackVO.getUuid());
                            phoneUtils.ttsPlayback(script.getIvrtext(), phoneCallBackVO.getUuid());
                            return;
                        } else if (nextQuestion > IvrTaskTemplateScriptVOs.size()) {
                            //没有下一题了,就结束了
@@ -639,7 +640,7 @@
                        redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", 0, 120, TimeUnit.MINUTES);
                        String date = simpleDateFormat1.format(new Date());
                        log.info("如果下一题为空.则新的数据返回,并加上感谢语: {},uuid为:{}", date, phoneCallBackVO.getUuid());
                        phoneUtils.ttsPlayback(nextQuestion.getScriptContent(), phoneCallBackVO.getUuid());
                        phoneUtils.ttsPlayback(nextQuestion.getIvrtext(), phoneCallBackVO.getUuid());
                        return;
                    } else {
                        //就可以挂断电话了
@@ -707,13 +708,13 @@
                        //调用“15、tts合成和播放, tts_playback”将结果传回
                        String date = simpleDateFormat1.format(new Date());
                        log.info("调用“15、tts合成和播放------: {},uuid为:{}", date, phoneCallBackVO.getUuid());
                        phoneUtils.ttsPlayback(nowQuestion.getScriptContent() + ivrTaskTemplateScriptVO.getSubmoduleText(), phoneCallBackVO.getUuid());
                        phoneUtils.ttsPlayback(nowQuestion.getIvrtext() + ivrTaskTemplateScriptVO.getSubmoduleText(), phoneCallBackVO.getUuid());
                    }
                    break;
                }
                String date = simpleDateFormat1.format(new Date());
                log.info("最后的信息回复-: {},uuid为:{}", date, phoneCallBackVO.getUuid());
                phoneUtils.ttsPlayback(nowQuestion.getScriptContent(), phoneCallBackVO.getUuid());
                phoneUtils.ttsPlayback(nowQuestion.getIvrtext(), phoneCallBackVO.getUuid());
            }
        }
    }
@@ -749,6 +750,9 @@
                req.put("caller", phoneCallReqYQVO.getPhone());
                HttpUtil.postJsonRequest(hangup, new Gson().toJson(req));
                redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- hangup", "1", 2, TimeUnit.MINUTES);
                //先把默认的recordAccept-hungup删除,再更新
                redisCache.deleteObject(phoneCallReqYQVO.getTaskid() + "recordAccept-hungup");
                redisCache.setCacheObject(phoneCallReqYQVO.getTaskid() + "recordAccept-hungup", "1", 10, TimeUnit.MINUTES);
                //这个时候就需要走补偿机制了,先暂定走短信
                getSmsCompensate(Long.valueOf(phoneCallReqYQVO.getTaskid()));
                return new PhoneCallBackYQVO();
@@ -781,7 +785,6 @@
                    HttpUtil.postJsonRequest(hangup, new Gson().toJson(req));
                    //删除结束语的患存
                    redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "- jsy");
                    redisCache.setCacheObject(phoneCallReqYQVO.getTaskid() + "recordAccept-hungup", "2", 10, TimeUnit.MINUTES);
                } else {
                    redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop", true, 120, TimeUnit.MINUTES);
                    log.error("-------PlayEventCallbackPlaystop的值为:{}", true);
@@ -827,7 +830,7 @@
                //小与的话,就继续问患者
                phoneCallBackYQVO.setType("text");
                phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                String scriptContent = ivrTaskTemplateScriptVO.getScriptContent();
                String scriptContent = ivrTaskTemplateScriptVO.getIvrtext();
                log.error("SilentCallback的问题内容scriptContent:{}", scriptContent);
                phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent));
                //将静默次数加1
@@ -870,7 +873,9 @@
            }
            return phoneCallBackYQVO;
        } else if ("AsrCallback".equals(phoneCallReqYQVO.getOperate()) && phoneCallReqYQVO.getEnd_time() != null && phoneCallReqYQVO.getEnd_time() != -1) {
            //做一个标识,用来在通话详情接口里,判断是否有人接电话(value=2,表示有人接)
            redisCache.deleteObject(phoneCallReqYQVO.getTaskid() + "recordAccept-hungup");
            redisCache.setCacheObject(phoneCallReqYQVO.getTaskid() + "recordAccept-hungup", "2", 10, TimeUnit.MINUTES);
            // 先对通话进行通用库匹配一次
            String extemplateID = ivrTaskTemplate.getSubmoduleID();
            if (StringUtils.isNotEmpty(extemplateID)) {
@@ -1042,7 +1047,7 @@
                                if (script.getSort() == nextQuestion.intValue()) {
                                    phoneCallBackYQVO.setType("text");
                                    phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                                    String scriptContent = script.getScriptContent();
                                    String scriptContent = script.getIvrtext();
                                    log.error("下一题问题:{}", scriptContent);
                                    phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + getObject(serviceSubtask, scriptContent));
                                    //将该患者的Redis中的题目ID,进行修改
@@ -1147,7 +1152,7 @@
                                if (script.getSort() == ivrTaskTemplateScriptVO.getNextScriptno().intValue()) {
                                    phoneCallBackYQVO.setType("text");
                                    phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                                    String scriptContent = script.getScriptContent();
                                    String scriptContent = script.getIvrtext();
                                    phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + getObject(serviceSubtask, scriptContent));
                                    //将该患者的Redis中的题目ID,进行修改
                                    redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim(), script.getId().toString(), 120, TimeUnit.MINUTES);
@@ -1169,7 +1174,7 @@
                            redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid(), count + 1, 120, TimeUnit.MINUTES);
                        phoneCallBackYQVO.setType("text");
                        phoneCallBackYQVO.setValue(ivrTaskTemplateScriptVO.getNoMatchText() + getObject(serviceSubtask, ivrTaskTemplateScriptVO.getScriptContent()));
                        phoneCallBackYQVO.setValue(ivrTaskTemplateScriptVO.getNoMatchText() + getObject(serviceSubtask, ivrTaskTemplateScriptVO.getIvrtext()));
                    }
                }
@@ -1199,7 +1204,7 @@
                        if (ivrTaskTemplateScriptVO.getNextScriptno().intValue() == ivrTaskTemplateScript1.getSort()) {
                            phoneCallBackYQVO.setType("text");
                            phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                            String scriptContent = ivrTaskTemplateScript1.getScriptContent();
                            String scriptContent = ivrTaskTemplateScript1.getIvrtext();
                            phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + getObject(serviceSubtask, scriptContent));
                            redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid());
                            redisCache.setCacheObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone(), ivrTaskTemplateScript1.getId().toString());
@@ -1367,7 +1372,7 @@
        //根据,获取子任务的ID
        String[] split = subIds.split(",,");
        for (int i = 0; i < split.length; i++) {
            if (cacheName.equals("cache-0") && i < 5 || !cacheName.equals("cache-0") && i < 1) {
            if (cacheName.equals("cache-0") && i < split.length || !cacheName.equals("cache-0") && i < 1) {
                PullTaskVO pullTaskVO = new PullTaskVO();
                String subId = split[i].trim().replace(",", "");
                ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(Long.valueOf(subId));
@@ -1389,7 +1394,7 @@
                //如果ivrTaskTemplateScript为空,也就没有往下执行的必要了
                if (ObjectUtils.isEmpty(ivrTaskTemplateScript)) return null;
                //获取通配符匹配过后的问题
                String scrContent = getObject(serviceSubtask, ivrTaskTemplateScript.getScriptContent());
                String scrContent = getObject(serviceSubtask, ivrTaskTemplateScript.getIvrtext());
                String kcb = serviceTask.getKcb() + "," + scrContent;
//                String kcb = ivrTaskTemplate.getRevisitBefore();
@@ -1700,21 +1705,40 @@
    @Override
    public Integer recordAccept(PhoneCallRecordVO phoneCallRecordVO) {
        Object cacheObject = redisCache.getCacheObject("recordAccept-hungup");
        if (ObjectUtils.isNotEmpty(cacheObject) && String.valueOf(cacheObject).equals("2")) {
        Object cacheObject = redisCache.getCacheObject(phoneCallRecordVO.getTaskid() + "recordAccept-hungup");
        if (phoneCallRecordVO.getHangup_cause().equals("NO_USER_RESPONSE") || ObjectUtils.isNotEmpty(cacheObject) && String.valueOf(cacheObject).equals("1")) {
            //无人接听
            getSmsCompensate(Long.valueOf(phoneCallRecordVO.getTaskid()));
            redisCache.deleteObject(phoneCallRecordVO.getTaskid() + "recordAccept-hungup");
        } else if (ObjectUtils.isNotEmpty(cacheObject) && String.valueOf(cacheObject).equals("2")) {
//        if (phoneCallRecordVO.getAnswered() != null && phoneCallRecordVO.getAnswered() == true) {
            log.error("有人接电话了,并且完了");
            //说明有人接了
            int startIndex = phoneCallRecordVO.getRecord_path().indexOf("voice") + "voice".length() + 1;  // 加1是跳过/符号
            int endIndex = phoneCallRecordVO.getRecord_path().lastIndexOf("/");
            String result = phoneCallRecordVO.getRecord_path().substring(startIndex, endIndex);
            ServiceSubtask serviceSubtask = new ServiceSubtask();
            serviceSubtask.setRemark("电话拨打已完成");
            serviceSubtask.setSendstate(6L);
            serviceSubtask.setId(Long.valueOf(phoneCallRecordVO.getTaskid()));
            serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
            //下载文件
            ftpService.downloadFolder("/" + LocalDate.now().toString(), profile + "/upload/vadio/voice/" + LocalDate.now().toString());
        } else if (phoneCallRecordVO.getHangup_cause().equals("NO_USER_RESPONSE") || ObjectUtils.isNotEmpty(cacheObject) && !String.valueOf(cacheObject).equals("2")) {
            //无人接听
            getSmsCompensate(Long.valueOf(phoneCallRecordVO.getTaskid()));
            redisCache.deleteObject(phoneCallRecordVO.getTaskid() + "recordAccept-hungup");
        } else {
            //患者拒绝随访
            ServiceSubtask serviceSubtask = new ServiceSubtask();
            serviceSubtask.setRemark("电话接通成功,患者拒绝随访");
            serviceSubtask.setId(Long.valueOf(phoneCallRecordVO.getTaskid()));
            serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
            int startIndex = phoneCallRecordVO.getRecord_path().indexOf("voice") + "voice".length() + 1;  // 加1是跳过/符号
            int endIndex = phoneCallRecordVO.getRecord_path().lastIndexOf("/");
            String result = phoneCallRecordVO.getRecord_path().substring(startIndex, endIndex);
            //下载文件
            ftpService.downloadFolder("/" + LocalDate.now().toString(), profile + "/upload/vadio/voice/" + LocalDate.now().toString());
            redisCache.deleteObject(phoneCallRecordVO.getTaskid() + "recordAccept-hungup");
        }
        redisCache.deleteObject("recordAccept-hungup");
        return 1;
    }
@@ -1784,7 +1808,7 @@
        serviceSubtaskDetail.setSentEnd(1L);
        serviceSubtaskDetail.setTemplateid(ivrTaskTemplate.getId().toString());
        serviceSubtaskDetail.setTemplatequestionnum(ivrTaskTemplateScriptVO.getId());
        serviceSubtaskDetail.setQuestiontext(ivrTaskTemplateScriptVO.getScriptContent());
        serviceSubtaskDetail.setQuestiontext(ivrTaskTemplateScriptVO.getIvrtext());
        serviceSubtaskDetail.setQuestionvoice(phoneCallReqYQVO.getRecordpath());
        serviceSubtaskDetail.setCategoryname(ivrTaskTemplateScriptVO.getScriptType());
        serviceSubtaskDetail.setTargetoptions(ivrTaskTemplateScriptVO.getTargetOptions());
@@ -1829,8 +1853,7 @@
        map.put("content", sendMagParam.getContent());
        String result = HttpUtil.postJsonRequest(xhsmsPath, new Gson().toJson(map));
        redisCache.setCacheObject(subTaskId + "recordAccept-hungup", "1", 10, TimeUnit.MINUTES);
        if (StringUtils.isNotEmpty(serviceSubtask.getRemark()))
            serviceSubtask.setRemark("电话发送拒接,短信补偿发送成功");
        if (StringUtils.isNotEmpty(serviceSubtask.getRemark())) serviceSubtask.setRemark("电话发送拒接,短信补偿发送成功");
        else serviceSubtask.setRemark("短信补偿发送成功");
        serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
    }