From 37b79cfd8e5ecdc6f9f09750583f998183c338fb Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期四, 07 十一月 2024 10:55:27 +0800
Subject: [PATCH] 代码提交

---
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java |  889 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 788 insertions(+), 101 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
index 2d4efa9..c1286ec 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -1,14 +1,14 @@
 package com.smartor.service.impl;
 
+import afu.org.checkerframework.checker.oigj.qual.O;
 import com.alibaba.fastjson2.JSON;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.gson.Gson;
 import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.exception.base.BaseException;
-import com.ruoyi.common.utils.DateUtils;
-import com.ruoyi.common.utils.DtoConversionUtils;
-import com.ruoyi.common.utils.RSAPublicKeyExample;
+import com.ruoyi.common.utils.*;
+import com.ruoyi.common.utils.http.HttpUtils;
 import com.smartor.config.PhoneUtils;
 import com.smartor.domain.*;
 import com.smartor.mapper.*;
@@ -22,19 +22,22 @@
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
+import java.sql.Time;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
 import java.time.LocalTime;
+import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-
-import static cn.hutool.poi.excel.sax.AttributeName.r;
-import static cn.hutool.poi.excel.sax.AttributeName.s;
+import java.util.stream.Collectors;
 
 /**
  * 鍗曚竴浠诲姟锛堥殢璁匡級Service涓氬姟灞傚鐞�
@@ -74,6 +77,12 @@
     @Value("${pri_key}")
     private String pri_key;
 
+    @Value("${ASRCallBackPath}")
+    private String ASRCallBackPath;
+
+    @Value("${hangup}")
+    private String hangup;
+
 
     /**
      * 鏌ヨ鍗曚竴浠诲姟锛堥殢璁匡級
@@ -89,23 +98,27 @@
     /**
      * 鏌ヨ鍗曚竴浠诲姟锛堥殢璁匡級鍒楄〃
      *
-     * @param ServiceSubtask 鍗曚竴浠诲姟锛堥殢璁匡級
+     * @param serviceSubtaskVO 鍗曚竴浠诲姟锛堥殢璁匡級
      * @return 鍗曚竴浠诲姟锛堥殢璁匡級
      */
     @Override
-    public List<ServiceSubtask> selectServiceSubtaskList(ServiceSubtask ServiceSubtask) {
-        return serviceSubtaskMapper.selectServiceSubtaskList(ServiceSubtask);
+    public List<ServiceSubtask> selectServiceSubtaskList(ServiceSubtaskVO serviceSubtaskVO) {
+        return serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO);
     }
 
     @Override
-    public ServiceTaskVO queryTaskByCondition(ServiceSubtask ServiceSubtask) {
+    public ServiceTaskVO queryTaskByCondition(ServiceSubtask serviceSubtask) {
         //瀹氫箟鎮h�呬笌鍗曚竴浠诲姟鍏宠仈琛ㄩ泦鍚�
         List<PatTaskRelevance> patTaskRelevances = new ArrayList<>();
-        List<ServiceSubtask> list = selectServiceSubtaskList(ServiceSubtask);
+        ServiceSubtaskVO serviceSubtaskVO = DtoConversionUtils.sourceToTarget(serviceSubtask, ServiceSubtaskVO.class);
+        List<ServiceSubtask> list = selectServiceSubtaskList(serviceSubtaskVO);
+
+        ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
         if (CollectionUtils.isEmpty(list) || list.size() == 0) {
-            return new ServiceTaskVO();
+            return DtoConversionUtils.sourceToTarget(serviceTask, ServiceTaskVO.class);
         }
-        ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(ServiceSubtask.getTaskid());
+
+
         //灏嗘煡鍑烘潵鐨勬暟鎹�掑叆ServiceSubtaskVO涓�
         ServiceTaskVO serviceTaskVO = DtoConversionUtils.sourceToTarget(serviceTask, ServiceTaskVO.class);
         serviceTaskVO.setShowDate(serviceTask.getShowDate());
@@ -138,12 +151,23 @@
                 //鑾峰彇鍒版偅鑰呬俊鎭紝骞舵斁鍏ュ埌闆嗗悎涓�
                 patTaskRelevance.setName(serviceSubtask1.getSendname());
                 patTaskRelevance.setAge(serviceSubtask1.getAge());
+                patTaskRelevance.setFinishtime(serviceSubtask1.getFinishtime());
                 patTaskRelevance.setSfzh(serviceSubtask1.getSfzh());
                 patTaskRelevance.setPhone(serviceSubtask1.getPhone());
                 patTaskRelevance.setAddr(serviceSubtask1.getAddr());
                 patTaskRelevance.setDiagname(serviceSubtask1.getDiagname());
                 patTaskRelevance.setPatid(serviceSubtask1.getPatid());
                 patTaskRelevance.setSendStatus(serviceSubtask1.getSendstate());
+                patTaskRelevance.setDeptCode(serviceSubtask1.getDeptcode());
+                patTaskRelevance.setDeptName(serviceSubtask1.getDeptname());
+                patTaskRelevance.setLeavehospitaldistrictcode(serviceSubtask1.getLeavehospitaldistrictcode());
+                patTaskRelevance.setLeavehospitaldistrictname(serviceSubtask1.getLeavehospitaldistrictname());
+                patTaskRelevance.setInhosptime(serviceSubtask1.getInhosptime());
+                patTaskRelevance.setDrname(serviceSubtask1.getDrname());
+                patTaskRelevance.setDrcode(serviceSubtask1.getDrcode());
+                patTaskRelevance.setEndtime(serviceSubtask1.getEndtime());
+                patTaskRelevance.setNurseId(serviceSubtask1.getNurseId());
+                patTaskRelevance.setNurseName(serviceSubtask1.getNurseName());
                 patTaskRelevances.add(patTaskRelevance);
             }
             if (serviceSubtask1.getHospType().equals("2")) {
@@ -152,12 +176,24 @@
                 patTaskRelevance.setAge(serviceSubtask1.getAge());
                 patTaskRelevance.setSfzh(serviceSubtask1.getSfzh());
                 patTaskRelevance.setPhone(serviceSubtask1.getPhone());
+                patTaskRelevance.setFinishtime(serviceSubtask1.getFinishtime());
                 patTaskRelevance.setAddr(serviceSubtask1.getAddr());
                 patTaskRelevance.setDeptName(serviceSubtask1.getDeptname());
+                patTaskRelevance.setDeptCode(serviceSubtask1.getDeptcode());
                 patTaskRelevance.setBedNo(serviceSubtask1.getBedNo());
                 patTaskRelevance.setDiagname(serviceSubtask1.getDiagname());
                 patTaskRelevance.setPatid(serviceSubtask1.getPatid());
                 patTaskRelevance.setSendStatus(serviceSubtask1.getSendstate());
+                patTaskRelevance.setLeavehospitaldistrictcode(serviceSubtask1.getLeavehospitaldistrictcode());
+                patTaskRelevance.setLeavehospitaldistrictname(serviceSubtask1.getLeavehospitaldistrictname());
+                patTaskRelevance.setInhosptime(serviceSubtask1.getInhosptime());
+                patTaskRelevance.setStarttime(serviceSubtask1.getStarttime());
+                patTaskRelevance.setDrname(serviceSubtask1.getDrname());
+                patTaskRelevance.setDrcode(serviceSubtask1.getDrcode());
+                patTaskRelevance.setEndtime(serviceSubtask1.getEndtime());
+                patTaskRelevance.setStarttime(serviceSubtask1.getStarttime());
+                patTaskRelevance.setNurseId(serviceSubtask1.getNurseId());
+                patTaskRelevance.setNurseName(serviceSubtask1.getNurseName());
                 patTaskRelevances.add(patTaskRelevance);
             }
         }
@@ -167,10 +203,41 @@
     }
 
     @Override
-    public List<ServiceSubtask> patItem(ServiceSubtask serviceSubtask) {
+    public List<ServiceSubtask> patItem(ServiceSubtaskVO serviceSubtaskVO) {
+        List<ServiceSubtask> selectServiceSubtaskList = this.selectServiceSubtaskList(serviceSubtaskVO);
+        //鏍规嵁鍑洪櫌 鏃堕棿鍊掑簭
+//        List<ServiceSubtask> sortedServiceSubtaskList = selectServiceSubtaskList.stream().sorted(Comparator.comparing(ServiceSubtask::getEndtime).reversed()).collect(Collectors.toList());
+        return selectServiceSubtaskList;
+    }
 
+    @Override
+    public Map<String, Object> patItemCount(ServiceSubtaskVO serviceSubtaskVO) {
+        serviceSubtaskVO.setPageSize(99999999);
+        serviceSubtaskVO.setPageNum(1);
+        List<ServiceSubtask> selectServiceSubtaskList = this.selectServiceSubtaskList(serviceSubtaskVO);
+        Map<String, Object> map = new HashMap<>();
+        Integer wzx = 0;
+        Integer ysf = 0;
+        Integer yc = 0;
+        Integer fssb = 0;
+        Integer yfs = 0;
+        Integer blq = 0;
+        for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) {
+            if (serviceSubtask.getSendstate() == 4L) wzx = wzx + 1;
+            else if (serviceSubtask.getSendstate() != 4L) ysf = ysf + 1;
+            if (serviceSubtask.getSendstate() == 5L) fssb = fssb + 1;
+            if (serviceSubtask.getSendstate() == 3L) yfs = yfs + 1;
+            if (serviceSubtask.getSendstate() == 1L) blq = blq + 1;
+            if (serviceSubtask.getExcep().equals("1")) yc = yc + 1;
+        }
+        map.put("wzx", wzx);
+        map.put("ysf", ysf);
+        map.put("yc", yc);
+        map.put("fssb", fssb);
+        map.put("yfs", yfs);
+        map.put("blq", blq);
 
-        return this.selectServiceSubtaskList(serviceSubtask);
+        return map;
     }
 
     /**
@@ -218,22 +285,36 @@
      */
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public int insertOrUpdateTask(ServiceTaskVO serviceTaskVO) {
+    public Map<String, Integer> insertOrUpdateTask(ServiceTaskVO serviceTaskVO) {
         if (ObjectUtils.isEmpty(serviceTaskVO)) {
             log.info("浠诲姟鍏ュ弬涓虹┖锛岃妫�鏌ュ叆鍙�");
             throw new BaseException("浠诲姟鍏ュ弬涓虹┖锛岃妫�鏌ュ叆鍙�");
         }
-        Integer integer = 1;
+        Integer integer = null;
         ServiceTask serviceTask = DtoConversionUtils.sourceToTarget(serviceTaskVO, ServiceTask.class);
         serviceTask.setTextParam(JSON.toJSONString(serviceTaskVO.getTextParam()));
         if (serviceTaskVO.getIsoperation() != null && serviceTaskVO.getIsoperation() == 1) {
             //寰�浠诲姟琛ㄤ腑锛屾柊澧炰换鍔�
             if (ObjectUtils.isNotEmpty(serviceTaskVO.getSendTimeslot()))
                 serviceTask.setSendTimeSlot(JSON.toJSONString(serviceTaskVO.getSendTimeslot()));
-            if (serviceTask.getSendState() == null) serviceTask.setSendState(1);
-            serviceTask.setLibtemplateid(serviceTaskVO.getLibtemplateid().toString());
+            if (serviceTask.getSendState() == null) {
+                serviceTask.setSendState(1L);
+                serviceTaskVO.setSendState(1L);
+            }
+            if (StringUtils.isNotEmpty(serviceTaskVO.getLibtemplateid())) {
+                serviceTask.setLibtemplateid(serviceTaskVO.getLibtemplateid());
+            }
             serviceTask.setTemplateid(serviceTaskVO.getTemplateid());
+
+            serviceTask.setLeaveldeptcodes(serviceTaskVO.getLeaveldeptcodes());
+            serviceTask.setLeavehospitaldistrictcode(serviceTask.getLeavehospitaldistrictcode());
             serviceTaskService.insertServiceTask(serviceTask);
+            if (serviceTaskVO.getLongTask() != null && serviceTaskVO.getLongTask() == 1) {
+                Map<String, Integer> map = new HashMap<>();
+                map.put("subTaskId", null);
+                map.put("taskId", serviceTask.getTaskid().intValue());
+                return map;
+            }
 
             //灏嗕换鍔′俊鎭斁鍒版湇鍔¤〃涓�
             ServiceSubtask serviceSubtask = DtoConversionUtils.sourceToTarget(serviceTaskVO, ServiceSubtask.class);
@@ -245,10 +326,25 @@
                     //灏嗕换鍔′俊鎭柊澧炲埌闅忚鏈嶅姟琛ㄤ腑
                     serviceSubtask.setSendname(patTaskRelevance.getName());
                     serviceSubtask.setAge(patTaskRelevance.getAge());
-                    serviceSubtask.setSfzh(patTaskRelevance.getSfzh());
+                    serviceSubtask.setSfzh(patTaskRelevance.getIdcardno());
+                    serviceSubtask.setPhone(patTaskRelevance.getTelcode());
+                    serviceSubtask.setAddr(patTaskRelevance.getAddr());
+                    serviceSubtask.setPatid(patTaskRelevance.getPatid());
+                    serviceSubtask.setCreateTime(DateUtils.getNowDate());
+                    serviceSubtask.setSendstate(1L);
+                    serviceSubtask.setDeptcode(patTaskRelevance.getDeptCode());
+                    serviceSubtask.setDeptname(patTaskRelevance.getDeptName());
+                    serviceSubtask.setLeavehospitaldistrictcode(patTaskRelevance.getLeavehospitaldistrictcode());
+                    serviceSubtask.setLeavehospitaldistrictname(patTaskRelevance.getLeavehospitaldistrictname());
                     serviceSubtask.setType(serviceTaskVO.getHospType());
                     serviceSubtask.setHospType(patTaskRelevance.getHospType());
                     serviceSubtask.setOpenid(patTaskRelevance.getOpenid());
+                    serviceSubtask.setDrname(patTaskRelevance.getDrname());
+                    serviceSubtask.setDrcode(patTaskRelevance.getDrcode());
+                    serviceSubtask.setInhosptime(patTaskRelevance.getInhosptime());
+                    serviceSubtask.setEndtime(patTaskRelevance.getEndtime());
+                    serviceSubtask.setNurseId(patTaskRelevance.getNurseId());
+                    serviceSubtask.setNurseName(patTaskRelevance.getNurseName());
                     serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
                     integer = serviceSubtask.getId().intValue();
                 }
@@ -260,19 +356,35 @@
                 serviceTask.setSendTimeSlot(JSON.toJSONString(serviceTaskVO.getSendTimeslot()));
             //淇敼鎿嶄綔锛岄渶瑕佸皢stopState鐘舵��+1
             ServiceTask serviceTask1 = serviceTaskService.selectServiceTaskByTaskid(serviceTask.getTaskid());
-            serviceTask.setStopState(serviceTask1.getStopState() + 1);
-            serviceTask.setTemplateid(serviceTaskVO.getLibtemplateid());
+            long l = serviceTask1.getStopState() + 1;
+            serviceTask.setStopState(l);
+            if (serviceTaskVO.getLibtemplateid() != null)
+                serviceTask.setLibtemplateid(serviceTaskVO.getLibtemplateid().toString());
+            serviceTask.setTemplateid(serviceTaskVO.getTemplateid());
             serviceTaskService.updateServiceTask(serviceTask);
             if (CollectionUtils.isNotEmpty(serviceTaskVO.getPatTaskRelevances())) {
                 for (PatTaskRelevance patTaskRelevance : serviceTaskVO.getPatTaskRelevances()) {
                     ServiceSubtask serviceSubtask = DtoConversionUtils.sourceToTarget(serviceTaskVO, ServiceSubtask.class);
                     serviceSubtask.setSendname(patTaskRelevance.getName());
+                    serviceSubtask.setAge(patTaskRelevance.getAge());
+                    serviceSubtask.setSfzh(patTaskRelevance.getSfzh());
+                    serviceSubtask.setPhone(patTaskRelevance.getTelcode());
                     serviceSubtask.setAddr(patTaskRelevance.getAddr());
                     serviceSubtask.setPatid(patTaskRelevance.getPatid());
                     serviceSubtask.setOpenid(patTaskRelevance.getOpenid());
+                    serviceSubtask.setDeptcode(patTaskRelevance.getDeptCode());
+                    serviceSubtask.setLeavehospitaldistrictname(patTaskRelevance.getLeavehospitaldistrictname());
+                    serviceSubtask.setLeavehospitaldistrictcode(patTaskRelevance.getLeavehospitaldistrictcode());
+                    serviceSubtask.setDeptname(patTaskRelevance.getDeptName());
                     serviceSubtask.setType(serviceTaskVO.getHospType());
                     serviceSubtask.setCreateTime(DateUtils.getNowDate());
+                    serviceSubtask.setDrname(patTaskRelevance.getDrname());
+                    serviceSubtask.setDrcode(patTaskRelevance.getDrcode());
+                    serviceSubtask.setInhosptime(patTaskRelevance.getInhosptime());
                     serviceSubtask.setHospType(patTaskRelevance.getHospType());
+                    serviceSubtask.setEndtime(patTaskRelevance.getEndtime());
+                    serviceSubtask.setNurseId(patTaskRelevance.getNurseId());
+                    serviceSubtask.setNurseName(patTaskRelevance.getNurseName());
                     serviceSubtask.setTextParam(new Gson().toJson(serviceTaskVO.getTextParam()));
                     if (patTaskRelevance.getIsoperation() != null) {
                         if (patTaskRelevance.getIsoperation() == 2)
@@ -289,7 +401,10 @@
                 }
             }
         }
-        return integer;
+        Map<String, Integer> map = new HashMap<>();
+        map.put("subTaskId", integer);
+        map.put("taskId", serviceTask.getTaskid().intValue());
+        return map;
     }
 
 
@@ -337,10 +452,15 @@
             if (noVoice == ivrTaskTemplateVO.getNoVoiceNum().intValue()) {
                 //宸茬粡闂簡瀵瑰簲鐨勯亶鏁帮紝灏卞垽鏂槸鍚﹁繕鏈変笅涓�棰�
                 if (nowQuestion.getTargetid() == IvrTaskTemplateScriptVOs.size()) {
+                    //娌℃湁涓嬩竴棰樹簡锛屽氨鎸傛柇鐢佃瘽锛屾挱鏀剧粨鏉熻
+                    redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES);
                     phoneUtils.ttsPlayback(ivrTaskTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid());
                     return;
                 } else {
                     //鏈変笅涓�棰�
+                    redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES);
+                    IvrTaskTemplateScriptVO nextQuestion = getNextQuestion(IvrTaskTemplateScriptVOs, nowQuestion);
+                    // 闂锛�  鍘昏皟鐢ㄢ�渢ts鍚堟垚鍜屾挱鏀锯�濇帴鍙�
                     String date = simpleDateFormat1.format(new Date());
                     log.info("鍘昏皟鐢╰ts鍚堟垚鍜屾挱鏀炬帴鍙�: {},uuid涓猴細{}", date, phoneCallBackVO.getUuid());
                     phoneUtils.ttsPlayback(nowQuestion.getScriptContent(), phoneCallBackVO.getUuid());
@@ -373,6 +493,60 @@
                     Pattern pattern2 = Pattern.compile(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2());
                     matcher2 = pattern2.matcher(phoneCallBackVO.getTextResult());
                 }
+                log.error("PCB--getQuestionText闂涓猴細{},UUID锛歿}", nowQuestion.getScriptContent(), 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()) {
+                    //璇存槑鍖归厤姝g‘浜�
+                    //杩欓噷搴旇鍏堝垽鏂被鍨嬶紝鍘诲啀淇敼锛岃缃甀sUserOperation鏄崟閫夐鐨勬敼娉�
+                    nowQuestion.getIvrTaskScriptTargetoptionList().get(j).setIsUserOperation(1);
+                    serviceTaskScriptTargetoptionMapper.updateIvrTaskTemplateTargetoption(nowQuestion.getIvrTaskScriptTargetoptionList().get(j));
+
+                    //灏嗛潤榛樼疆涓�0
+                    redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES);
+                    redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", 0, 120, TimeUnit.MINUTES);
+
+                    //灏嗘偅鑰呯殑鍥炵鍐欒繘琛ㄩ噷
+                    IvrTaskVisitResult serviceTaskVisitResult = DtoConversionUtils.sourceToTarget(serviceSubtask, IvrTaskVisitResult.class);
+                    serviceTaskVisitResult.setId(null);
+                    serviceTaskVisitResult.setQuestion(nowQuestion.getScriptContent());
+                    serviceTaskVisitResult.setPatientAnswer(phoneCallBackVO.getTextResult());
+                    serviceTaskVisitResult.setCreateTime(new Date());
+                    serviceTaskVisitResult.setOptionResult(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetvalue());
+                    serviceTaskVisitResultMapper.insertIvrTaskVisitResult(serviceTaskVisitResult);
+
+                    //灏嗗尮閰嶅埌鐨勬爣璇嗘敼鎴恡rue
+                    isppd = true;
+
+                    //鑾峰彇涓嬩竴棰�
+                    Long nextQuestion = nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getNextQuestion();
+                    for (IvrTaskTemplateScriptVO script : IvrTaskTemplateScriptVOs) {
+                        if (script.getTargetid() == nextQuestion) {
+                            QuestionMessage questionMessage = new QuestionMessage();
+                            questionMessage.setNowQuestion(script);
+                            questionMessage.setQuestionList(IvrTaskTemplateScriptVOs);
+                            redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES);
+                            phoneUtils.ttsPlayback(script.getScriptContent(), phoneCallBackVO.getUuid());
+                            return;
+                        } else if (nextQuestion > IvrTaskTemplateScriptVOs.size()) {
+                            //娌℃湁涓嬩竴棰樹簡锛屽氨缁撴潫浜�
+                            String date = simpleDateFormat1.format(new Date());
+                            log.error("娌℃湁涓嬩竴棰樹簡锛屽氨缁撴潫浜�: {},uuid涓猴細{}", date, phoneCallBackVO.getUuid());
+                            redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES);
+                            phoneUtils.ttsPlayback(ivrTaskTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid());
+                            try {
+                                Thread.sleep(3000);
+                            } catch (InterruptedException e) {
+                                e.printStackTrace();
+                            }
+                            phoneUtils.hangup("", "", ivrTaskTemplateVO.getRevisitAfter(), "", "", "", "", phoneCallBackVO.getUuid());
+                            return;
+                        }
+                    }
+                    return;
+                } else {
+                    //娌℃湁鍖归厤涓婂綋鍓峯ption
+                    //Targetregex2 涓篺alse锛岃〃绀哄湪Targetregex2涓瓨鍦�  璇彞涓殑鍏抽敭瀛楋紝杩欎釜option灏变笉鐢ㄥ啀缁х画鍖归厤浜嗭紝鐩存帴鍖归厤涓嬩竴涓猳ption
+                    continue;
+                }
             }
 
             if (isppd != true) {
@@ -387,6 +561,8 @@
                         IvrTaskTemplateScriptVO nextQuestion = getNextQuestion(IvrTaskTemplateScriptVOs, nowQuestion);
                         questionMessage.setQuestionList(IvrTaskTemplateScriptVOs);
                         questionMessage.setNowQuestion(nextQuestion);
+                        redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES);
+                        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());
@@ -395,6 +571,7 @@
                         //灏卞彲浠ユ寕鏂數璇濅簡
                         String date = simpleDateFormat1.format(new Date());
                         log.info("灏卞彲浠ユ寕鏂數璇濅簡------: {},uuid涓猴細{}", date, phoneCallBackVO.getUuid());
+                        redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES);
                         phoneUtils.ttsPlayback(ivrTaskTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid());
                         try {
                             Thread.sleep(3000);
@@ -421,16 +598,38 @@
                 }
                 List<IvrLibaExtemplatescript> ivrLibaExtemplatescripts = ivrLibaExtemplatescriptMapper.queryIvrLibaExtemplatescriptList(list1);
                 for (IvrLibaExtemplatescript ivrLibaExtemplatescript : ivrLibaExtemplatescripts) {
+                    Matcher matcher = null;
                     if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex())) {
                         Pattern pattern = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex());
-                        pattern.matcher(returnQues.getContent());
+                        matcher = pattern.matcher(returnQues.getContent());
                     }
 
+                    Matcher matcher2 = null;
                     if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2())) {
                         Pattern pattern2 = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex2());
-                        pattern2.matcher(returnQues.getContent());
+                        matcher2 = pattern2.matcher(returnQues.getContent());
                     }
-                    log.info("++++++++++++++++++++++++++閫氱敤搴撴槸鍚︿负绌猴細selfRegex : {} , selfRegex2 : {}", ivrLibaExtemplatescript.getSelfRegex(), ivrLibaExtemplatescript.getSelfRegex2());
+                    log.error("++++++++++++++++++++++++++閫氱敤搴撴槸鍚︿负绌猴細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");
+                        IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO = returnQues.getNowQuestion();
+                        ivrTaskTemplateScriptVO.setSubmoduleText(ivrLibaExtemplatescript.getSwitchText());
+                        ivrTaskTemplateScriptVO.setSubmoduleVoice(ivrLibaExtemplatescript.getSwitchWav());
+                        redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES);
+                        if (ivrLibaExtemplatescript.getIsEnd() == 1) {
+                            //灏嗛棶棰樼疆绌�
+                            IvrTaskTemplateScriptVO nowQuestion1 = questionMessage.getNowQuestion();
+                            nowQuestion1.setScriptContent(null);
+                            nowQuestion1.setScriptVoice(null);
+                            questionMessage.setNowQuestion(nowQuestion1);
+                            redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES);
+                            redisCache.setCacheObject(phoneCallBackVO.getUuid() + "isOver", 1, 120, TimeUnit.MINUTES);
+                        }
+                        //璋冪敤鈥�15銆乼ts鍚堟垚鍜屾挱鏀撅紝 tts_playback鈥濆皢缁撴灉浼犲洖
+                        String date = simpleDateFormat1.format(new Date());
+                        log.info("璋冪敤鈥�15銆乼ts鍚堟垚鍜屾挱鏀�------: {},uuid涓猴細{}", date, phoneCallBackVO.getUuid());
+                        phoneUtils.ttsPlayback(nowQuestion.getScriptContent() + ivrTaskTemplateScriptVO.getSubmoduleText(), phoneCallBackVO.getUuid());
+                    }
                     break;
                 }
                 String date = simpleDateFormat1.format(new Date());
@@ -447,11 +646,70 @@
      */
     @Override
     public PhoneCallBackYQVO phoneCallBackYQ(PhoneCallReqYQVO phoneCallReqYQVO) {
+        //鍒ゆ柇鏄惁鎸傛満
+        String hangupState = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "- hangup");
+        if (StringUtils.isNotEmpty(hangupState) && hangup.equals("1")) {
+            return new PhoneCallBackYQVO();
+        }
+        if ("AsrCallback".equals(phoneCallReqYQVO.getOperate()) && phoneCallReqYQVO.getEnd_time() != null && phoneCallReqYQVO.getEnd_time() != -1) {
+            //澶勭悊鎸傛柇
+            if (phoneCallReqYQVO.getAsrtext().contains("鎷ㄥ彨鐨勭敤鎴锋蹇�")) {
+                ServiceSubtask serviceSubtask2 = new ServiceSubtask();
+                serviceSubtask2.setRemark("鐢佃瘽鍙戦�佹垚鍔燂紙鎮h�呮寕鏂級");
+                serviceSubtask2.setSenduuid(phoneCallReqYQVO.getUuid());
+                serviceSubtask2.setId(Long.valueOf(phoneCallReqYQVO.getTaskid()));
+                serviceSubtaskMapper.updateServiceSubtask(serviceSubtask2);
+                Map<String, String> req = new HashMap<>();
+                req.put("uuid", phoneCallReqYQVO.getUuid());
+                req.put("caller", phoneCallReqYQVO.getPhone());
+                HttpUtil.postJsonRequest(hangup, new Gson().toJson(req));
+                redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- hangup", "1", 2, TimeUnit.MINUTES);
+                return new PhoneCallBackYQVO();
+            }
+        }
+        //瀹氫箟涓�涓垎鏁扮殑鍙橀噺
+        Boolean aBoolean1 = redisCache.hasKey(phoneCallReqYQVO.getUuid() + "SCORE");
+        if (!aBoolean1) redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", 0.0, 120, TimeUnit.MINUTES);
         PhoneCallBackYQVO phoneCallBackYQVO = new PhoneCallBackYQVO();
         //channel_create 閫氶亾鍒涘缓鐨勬椂鍊欙紝鍙互鎵ц涓�浜涘叾瀹冩搷浣滐紝璀鍙戜釜鐭俊涔嬬被鐨�;  鎴戜滑鐨勪笟鍔″彲浠ヤ笉鐢ㄧ    PlayEventCallback 杩欎釜鏄挱鏀捐闊崇殑,鏆傛椂鐢ㄤ笉鍒�     End_time()= -1鎴杗ull琛ㄧず褰撳墠鐨刟srtext涓嶆槸涓�鍙ュ畬鏁寸殑璇�
-        if (phoneCallReqYQVO.getOperate().equals("channel_create") || phoneCallReqYQVO.getOperate().equals("PlayEventCallback") || phoneCallReqYQVO.getEnd_time() == null || phoneCallReqYQVO.getEnd_time() == -1) {
+        if (phoneCallReqYQVO.getOperate().equals("channel_create")) {
             return phoneCallBackYQVO;
         }
+        //PlayEventCallback 杩欎釜鏄挱鏀捐闊崇殑    playstart锛氭斁闊冲紑濮嬶紙闂鎾姤寮�濮嬶級    playstop锛� 鏀鹃煶缁撴潫锛堥棶棰樻挱鎶ョ粨鏉燂級
+        if (phoneCallReqYQVO.getOperate().equals("PlayEventCallback")) {
+            String cacheJSY = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "- jsy");
+            if (phoneCallReqYQVO.getOperate().equals("PlayEventCallback") && phoneCallReqYQVO.getPlaystop() == false) {
+                //鍒ゆ柇redis涓槸鍚︽湁缁撴潫璇�
+                if (StringUtils.isEmpty(cacheJSY)) {
+                    redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop", false, 120, TimeUnit.MINUTES);
+                    log.error("PlayEventCallbackPlaystop鐨勫�间负-------锛歿}", false);
+                }
+            } else {
+                //濡傛灉缁撴潫璇笉涓虹┖锛屽垯瑕佹寕鐢佃瘽浜�
+                if (StringUtils.isNotEmpty(cacheJSY)) {
+                    Map<String, String> req = new HashMap<>();
+                    req.put("uuid", phoneCallReqYQVO.getUuid());
+                    req.put("caller", phoneCallReqYQVO.getPhone());
+//                    HttpUtils.sendPost(hangup, new Gson().toJson(req));
+                    HttpUtil.postJsonRequest(hangup, new Gson().toJson(req));
+                    //鍒犻櫎缁撴潫璇殑鎮e瓨
+                    redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "- jsy");
+                } else {
+                    redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop", true, 120, TimeUnit.MINUTES);
+                    log.error("-------PlayEventCallbackPlaystop鐨勫�间负锛歿}", true);
+                }
+            }
+            return phoneCallBackYQVO;
+        }
+        //鑾峰彇鏀鹃煶鏄惁缁撴潫
+        Object isPlayEventOverObj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop");
+        if (ObjectUtils.isNotEmpty(isPlayEventOverObj)) {
+            Boolean isPlayEventOver = (Boolean) isPlayEventOverObj;
+            if (!isPlayEventOver) {
+                return phoneCallBackYQVO;
+            }
+        }
+
         //閫氳繃瀛愪换鍔D鑾峰彇鍒版ā鏉夸俊鎭�
         ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(Long.valueOf(phoneCallReqYQVO.getTaskid()));
         IvrTaskTemplate ivrTaskTemplate = ivrTaskTemplateService.selectIvrTaskTemplateByID(serviceSubtask.getTemplateid());
@@ -469,6 +727,8 @@
         if (!aBoolean) {
             //缁欓潤榛樿缃竴涓粯璁ゆ鏁板湪redis涓�
             redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES);
+            //濡傛灉涓嶅瓨鍦紝灏辨妸褰撳墠鐨刄UID鍋氫负key锛屾斁鍒板璞′腑鍘�
+            redisCache.setCacheObject(phoneCallReqYQVO.getUuid(), phoneCallReqYQVO, 120, TimeUnit.MINUTES);
         }
 
         if ("SilentCallback".equals(phoneCallReqYQVO.getOperate())) {
@@ -480,29 +740,105 @@
                 phoneCallBackYQVO.setType("text");
                 phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                 String scriptContent = ivrTaskTemplateScriptVO.getScriptContent();
+                log.error("SilentCallback鐨勯棶棰樺唴瀹箂criptContent锛歿}", scriptContent);
                 phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent));
                 //灏嗛潤榛樻鏁板姞1
                 Integer noVoiceNum = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "noVoice");
                 redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "noVoice", noVoiceNum + 1, 120, TimeUnit.MINUTES);
+                return phoneCallBackYQVO;
             } else {
                 log.error("闈欓粯娆℃暟杈惧埌,鎸傛帀鐢佃瘽锛歿}", num);
+                ServiceTask serviceTask1 = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
                 //澶т笌绛変簬鐨勮瘽,鐩存帴鎸傛柇
-                phoneCallBackYQVO.setType("hangup");
+                phoneCallBackYQVO.setType("text");
                 phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
-                phoneCallBackYQVO.setValue(ivrTaskTemplate.getRevisitAfter());
+                phoneCallBackYQVO.setValue(serviceTask1.getJsy());
                 //灏嗙粨鏋滃啓鍒癲etail涓�
                 ServiceSubTaskDetailReq serviceSubTaskDetailReq = new ServiceSubTaskDetailReq();
                 List<ServiceSubtaskDetail> serviceSubtaskDetailList = new ArrayList<>();
                 serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate));
                 serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList);
                 saveQuestionAnswerPhone(serviceSubTaskDetailReq);
+                //鍘籸edis涓紝鎶婅瀛愪换鍔D鍒犻櫎
+                Long id = serviceSubtask.getId();
+                //鍏堟洿鏂颁竴涓嬪垎鏁�
+                double score = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE");
+                serviceSubtask.setScore(BigDecimal.valueOf(score));
+                serviceSubtask.setFinishtime(new Date());
+                serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
+                Map<String, String> map = delRedisValue(null, id.toString());
+                if (ObjectUtils.isNotEmpty(map)) redisCache.setCacheObject(map.get("cacheName"), map.get("val"));
                 redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
+                redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE");
+                redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop");
+                //鍦╮edis涓繚瀛樹竴涓嬬粨鏉熻锛屽湪璋冪敤鎸傜數璇濈殑鏂规硶鏃跺垹闄�
+                ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
+                redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES);
             }
             return phoneCallBackYQVO;
-        } else if ("AsrCallback".equals(phoneCallReqYQVO.getOperate())) {
+        } else if ("AsrCallback".equals(phoneCallReqYQVO.getOperate()) && phoneCallReqYQVO.getEnd_time() != null && phoneCallReqYQVO.getEnd_time() != -1) {
+
+            // 鍏堝閫氳瘽杩涜閫氱敤搴撳尮閰嶄竴娆�
+            String extemplateID = ivrTaskTemplate.getSubmoduleID();
+            if (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())) {
+                        Pattern pattern = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex());
+                        matcher = pattern.matcher(phoneCallReqYQVO.getAsrtext());
+                    }
+
+                    Matcher matcher2 = null;
+                    if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2())) {
+                        Pattern pattern2 = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex2());
+                        matcher2 = pattern2.matcher(phoneCallReqYQVO.getAsrtext());
+                    }
+                    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()) {
+                        //灏嗛�氱敤搴撳尮閰嶇殑锛屾斁鍒拌繑鍥炲�间腑
+//                        phoneCallBackYQVO.setValue(phoneCallBackYQVO.getValue() + ivrLibaExtemplatescript.getSwitchText());
+                        phoneCallBackYQVO.setCommonValue(ivrLibaExtemplatescript.getSwitchText());
+                        les = ivrLibaExtemplatescript;
+                    }
+                    break;
+                }
+                if (ObjectUtils.isNotEmpty(les)) {
+                    //瀵瑰尮閰嶇殑缁撴灉澶勭悊涓�涓�(鐪嬬湅鏄笉鏄渶瑕佹寕鏈�)
+                    if (les.getIsEnd() != null && les.getIsEnd() == 1) {
+                        //鍙互鎸傛満浜�
+                        redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
+                        redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE");
+                        redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop");
+                        redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "noVoice");
+                        //鍦╮edis涓繚瀛樹竴涓嬬粨鏉熻锛屽湪璋冪敤鎸傜數璇濈殑鏂规硶鏃跺垹闄�
+                        ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
+                        redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES);
+                        phoneCallBackYQVO.setType("text");
+                        phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + les.getSwitchText());
+                        //灏嗙粨鏋滃啓杩沝etail琛�
+                        ServiceSubTaskDetailReq serviceSubTaskDetailReq = new ServiceSubTaskDetailReq();
+                        List<ServiceSubtaskDetail> serviceSubtaskDetailList = new ArrayList<>();
+                        ivrTaskTemplateScriptVO.setExtemplateText(les.getSwitchText());
+                        serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate));
+                        serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList);
+                        saveQuestionAnswerPhone(serviceSubTaskDetailReq);
+                        return phoneCallBackYQVO;
+                    }
+                }
+            }
+
             //濡傛灉鏄枃鏈洖璋�
             //鏍规嵁闂ID鑾峰彇璇ラ棶棰樼殑绫诲瀷
             if (ivrTaskTemplateScriptVO.getScriptType().equals("1")) {
+                //鐢ㄦ潵鏍囪锛屾槸鍚︽湁鍖归厤涓婄殑
+                Integer flag = 0;
                 //鏄�夋嫨棰�
                 for (int j = 0; j < ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().size(); j++) {
                     log.error("phoneCallReqYQVO.getAsrtext()鐨勫�间负锛歿}", phoneCallReqYQVO.getAsrtext());
@@ -534,64 +870,128 @@
                         serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate));
                         serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList);
                         saveQuestionAnswerPhone(serviceSubTaskDetailReq);
-//
+                        //鍒ゆ柇涓�涓嬶紝杩欎釜閫夐」缁撴灉鏄笉鏄繕鏈夌户缁棶涓嬪幓鐨勫繀瑕侊紝渚嬪閫夐」缁撴灉鏄埆浜轰笉鎯崇户缁洖绛旈棶棰橈紝灏辫缁撴潫鎺�
+                        if (ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getIsEnd() == 1) {
+                            redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
+                            redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE");
+                            redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop");
+                            redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "noVoice");
+                            //鍦╮edis涓繚瀛樹竴涓嬬粨鏉熻锛屽湪璋冪敤鎸傜數璇濈殑鏂规硶鏃跺垹闄�
+                            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());
+                            return phoneCallBackYQVO;
+                        }
+
+                        flag = 1;
+                        //灏嗗綋鍓嶅墠鐨勬挱鎶ョ姸鎬佸垹闄わ紝缁欎笅涓�棰樿浣�
+                        redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop");
 //                        //鑾峰彇涓嬩竴棰�
-                        if (ivrTaskTemplateScriptVO.getBranchFlag().equals("1") || ivrTaskTemplateScriptVO.getBranchFlag().equals("0") && ivrTaskTemplateScriptVO.getNextScriptno() != 0) {
+                        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 = ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getNextQuestion();
+                                //鏇存柊鍒嗘暟
+                                double score = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE");
+                                score = BigDecimal.valueOf(score).add(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).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(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getScore()).doubleValue();
+                                redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score, 120, TimeUnit.MINUTES);
                             }
-
 
                             for (IvrTaskTemplateScript script : ivrTaskTemplateScripts) {
                                 if (script.getSort() == nextQuestion.intValue()) {
                                     phoneCallBackYQVO.setType("text");
                                     phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                                     String scriptContent = script.getScriptContent();
-                                    phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent));
+                                    log.error("涓嬩竴棰橀棶棰橈細{}", scriptContent);
+                                    phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + getObject(serviceSubtask, scriptContent));
                                     //灏嗚鎮h�呯殑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.getBranchFlag().equals("0")) {
-                            if (ivrTaskTemplateScriptVO.getNextScriptno() == 0 || ivrTaskTemplateScriptVO.getNextScriptno() == null) {
-                                phoneCallBackYQVO.setType("hangup");
-                                phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
-                                //璁剧疆缁撴潫璇�
-                                phoneCallBackYQVO.setValue(ivrTaskTemplate.getRevisitAfter());
-                                Long id = serviceSubtask.getId();
-                                Map<String, String> map = delRedisValue(null, id.toString());
+                        } 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());
+                            serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
+                            //璁剧疆缁撴潫璇�
+                            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(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
+                            redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid());
+                            redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE");
+                            redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop");
+                            //鍦╮edis涓繚瀛樹竴涓嬬粨鏉熻锛屽湪璋冪敤鎸傜數璇濈殑鏂规硶鏃跺垹闄�
+                            ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
+                            redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES);
 //                                return phoneCallBackYQVO;
-                            }
+
                         }
                     } else {
-                        continue;
+                        //flag=0,璇存槑娌� 鍖归厤涓婏紝涔熻鎶婃偅鑰呰鐨勮瘽璁板綍涓嬫潵
+                        if (j == ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().size() - 1 && flag == 0) {
+                            ServiceSubTaskDetailReq serviceSubTaskDetailReq = new ServiceSubTaskDetailReq();
+                            List<ServiceSubtaskDetail> serviceSubtaskDetailList = new ArrayList<>();
+                            serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate));
+                            serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList);
+                            saveQuestionAnswerPhone(serviceSubTaskDetailReq);
+                            continue;
+                        }
                     }
                 }
                 //閮芥病鏈夊尮閰嶅埌
                 if (StringUtils.isEmpty(phoneCallBackYQVO.getValue())) {
-                    Integer count = redisCache.getCacheObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid());
+                    Integer count = null;
+                    Object countObj = redisCache.getCacheObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid());
+                    if (ObjectUtils.isNotEmpty(countObj)) count = (Integer) countObj;
                     if (count != null && count >= ivrTaskTemplate.getMateNum()) {
                         //濡傛灉count宸茬粡澶т簬鎴栫瓑浜庢病鏈夊尮閰嶆鏁�
                         if (ivrTaskTemplateScriptVO.getBranchFlag().equals("0") && ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getBranchFlag().equals("0") && ivrTaskTemplateScriptVO.getNextScriptno() == 0 || ivrTaskTemplateScriptVO.getBranchFlag().equals("1") && ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getBranchFlag().equals("1") && ivrTaskTemplateScriptVO.getNextScriptno() == 0) {
                             //濡傛灉鏄渶鍚庝竴閬撻锛屾垨鑰呮病鏈変笅涓�棰樹簡锛屽氨鐩存帴鎸傛満
-                            phoneCallBackYQVO.setType("hangup");
+                            ServiceTask serviceTask1 = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
+                            phoneCallBackYQVO.setType("text");
                             phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                             if (StringUtils.isNotEmpty(phoneCallBackYQVO.getValue()))
-                                phoneCallBackYQVO.setValue(phoneCallBackYQVO.getValue() + ivrTaskTemplate.getRevisitAfter());
-                            else phoneCallBackYQVO.setValue(ivrTaskTemplate.getRevisitAfter());
+                                phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + phoneCallBackYQVO.getValue() + serviceTask1.getJsy());
+                            else phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask1.getJsy());
+
+                            //鏇存柊涓�涓嬪垎鏁�
+                            Double score = null;
+                            Object scoreObj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE");
+                            if (ObjectUtils.isNotEmpty(scoreObj)) score = (Double) scoreObj;
+                            serviceSubtask.setScore(BigDecimal.valueOf(score));
+                            serviceSubtask.setFinishtime(new Date());
+                            serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
+
+                            //鍦╮edis涓繚瀛樹竴涓嬬粨鏉熻锛屽湪璋冪敤鎸傜數璇濈殑鏂规硶鏃跺垹闄�
+                            ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
+                            redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask.getJsy(), 120, TimeUnit.MINUTES);
                             //鍘籸edis涓紝鎶婅瀛愪换鍔D鍒犻櫎
                             Long id = serviceSubtask.getId();
                             Map<String, String> map = delRedisValue(null, id.toString());
                             redisCache.setCacheObject(map.get("cacheName"), map.get("val"));
                             redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
+                            redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE");
 //                            return phoneCallBackYQVO;
                         } else {
                             //鏍规嵁ivrTaskTemplateScriptVO.getNextScriptno()鑾峰彇涓嬩竴棰樿繘琛屾彁闂�
@@ -600,9 +1000,17 @@
                                     phoneCallBackYQVO.setType("text");
                                     phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                                     String scriptContent = script.getScriptContent();
-                                    phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent));
+                                    phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + getObject(serviceSubtask, scriptContent));
                                     //灏嗚鎮h�呯殑Redis涓殑棰樼洰ID锛岃繘琛屼慨鏀�
                                     redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim(), script.getId().toString(), 120, TimeUnit.MINUTES);
+
+                                    //鏇存柊涓�涓嬪垎鏁�
+                                    Double score = null;
+                                    Object scoreObj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE");
+                                    if (ObjectUtils.isNotEmpty(scoreObj)) score = (Double) scoreObj;
+                                    score = BigDecimal.valueOf(score).add(script.getScore()).doubleValue();
+
+                                    redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score, 120, TimeUnit.MINUTES);
                                 }
                             }
                         }
@@ -624,65 +1032,59 @@
                 serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate));
                 serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList);
                 saveQuestionAnswerPhone(serviceSubTaskDetailReq);
+                //    String xh = idSort.split("-")[1];
 
                 //濡傛灉閫夐」鍒嗘敮涓�1鐨勮瘽锛屽垯闇�瑕佹牴鎹棶棰樹笂鐨刵extScriptno杩涜璺宠浆
                 //闂瓟棰樻病鏈夎烦杞�
-                if (ivrTaskTemplateScriptVO.getNextScriptno() != null || ivrTaskTemplateScriptVO.getNextScriptno() != 0) {
+                if (ivrTaskTemplateScriptVO.getNextScriptno() != null && ivrTaskTemplateScriptVO.getNextScriptno() != 0) {
                     for (IvrTaskTemplateScript ivrTaskTemplateScript1 : ivrTaskTemplateScripts) {
                         if (ivrTaskTemplateScriptVO.getNextScriptno().intValue() == ivrTaskTemplateScript1.getSort()) {
                             phoneCallBackYQVO.setType("text");
                             phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                             String scriptContent = ivrTaskTemplateScript1.getScriptContent();
-                            phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent));
+                            phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + getObject(serviceSubtask, scriptContent));
                             redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid());
+                            redisCache.setCacheObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone(), ivrTaskTemplateScript1.getId().toString());
+
+                            //鏇存柊涓�涓嬪垎鏁�
+                            Double score = null;
+                            Object scoreObj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE");
+                            if (ObjectUtils.isNotEmpty(scoreObj)) score = (Double) scoreObj;
+                            score = BigDecimal.valueOf(score).add(ivrTaskTemplateScriptVO.getScore()).doubleValue();
+                            redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score, 120, TimeUnit.MINUTES);
+
                         }
                     }
-                } else if (ivrTaskTemplateScriptVO.getNextScriptno() == null) {
+                } else if (ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getNextScriptno() == 0) {
                     //娌℃湁涓嬩竴棰樹簡锛屽氨缁撴潫浜�
-                    phoneCallBackYQVO.setType("hangup");
+                    ServiceTask serviceTask1 = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
+                    phoneCallBackYQVO.setType("text");
                     phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
-                    phoneCallBackYQVO.setValue(ivrTaskTemplate.getRevisitAfter());
+                    phoneCallBackYQVO.setValue(phoneCallBackYQVO.getCommonValue() + serviceTask1.getJsy());
+
+                    //鏇存柊涓�涓嬪垎鏁�
+                    Double score = null;
+                    Object scoreObj = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE");
+                    if (ObjectUtils.isNotEmpty(scoreObj)) score = (Double) scoreObj;
+                    serviceSubtask.setScore(BigDecimal.valueOf(score));
+                    serviceSubtask.setFinishtime(new Date());
+                    serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
+
                     //鍘籸edis涓紝鎶婅瀛愪换鍔D鍒犻櫎
                     Long id = serviceSubtask.getId();
+                    Map<String, String> map = delRedisValue(null, id.toString());
+                    redisCache.setCacheObject(map.get("cacheName"), map.get("val"));
+                    //鍦╮edis涓繚瀛樹竴涓嬬粨鏉熻锛屽湪璋冪敤鎸傜數璇濈殑鏂规硶鏃跺垹闄�
+                    redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", serviceTask1.getJsy(), 120, TimeUnit.MINUTES);
                     redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
-                    log.error("鐢佃瘽鎸傛柇4");
+                    redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE");
                 }
-
-                //閫夐」鍖归厤瀹屾垚鍚庯紝闇�瑕佸啀鍘婚�氳繃搴撳啀杩涜鍖归厤涓�娆�
-                String extemplateID = ivrTaskTemplate.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(phoneCallReqYQVO.getAsrtext());
-                        }
-
-                        Matcher matcher2 = null;
-                        if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2())) {
-                            Pattern pattern2 = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex2());
-                            matcher2 = pattern2.matcher(phoneCallReqYQVO.getAsrtext());
-                        }
-                        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()) {
-                            //灏嗛�氱敤搴撳尮閰嶇殑锛屾斁鍒拌繑鍥炲�间腑
-                            phoneCallBackYQVO.setValue(phoneCallBackYQVO.getValue() + ivrLibaExtemplatescript.getSwitchText());
-                        }
-                        break;
-                    }
-                }
-
             }
-
         }
+        log.error("phoneCallBackYQVO鐨勮繑鍥炲�兼槸锛歿}", phoneCallBackYQVO);
         return phoneCallBackYQVO;
     }
+
 
     private String getObject(ServiceSubtask serviceSubtask, String scriptContent) {
         Map<String, Map<String, String>> param = getParam(serviceSubtask.getTaskid());
@@ -691,9 +1093,9 @@
                 scriptContent = scriptContent.replace(key, StringUtils.isNotEmpty(map.get(key)) ? map.get(key) : "");
             }
         }
-        scriptContent.replace("${name}", StringUtils.isNotEmpty(serviceSubtask.getName()) ? serviceSubtask.getName() : "");
-        scriptContent.replace("${dzz}", StringUtils.isNotEmpty(serviceSubtask.getPlaceOfResidence()) ? serviceSubtask.getPlaceOfResidence() : "");
-        scriptContent.replace("${phone}", StringUtils.isNotEmpty(serviceSubtask.getTelcode()) ? serviceSubtask.getTelcode() : "");
+        scriptContent = scriptContent.replace("${name}", StringUtils.isNotEmpty(serviceSubtask.getSendname()) ? serviceSubtask.getSendname() : "");
+        scriptContent = scriptContent.replace("${dzz}", StringUtils.isNotEmpty(serviceSubtask.getAddr()) ? serviceSubtask.getAddr() : "");
+        scriptContent = scriptContent.replace("${phone}", StringUtils.isNotEmpty(serviceSubtask.getTelcode()) ? serviceSubtask.getTelcode() : "");
 
         return scriptContent;
     }
@@ -762,10 +1164,12 @@
         //  cache-0涓虹珛鍗冲彂璧风殑,鍏跺畠鐨勫厛鎺ㄨ繜
         if (!StringUtils.isEmpty(value0)) {
             pullTaskVOList = getPullTaskList(value0, "cache-0");
-            //灏哻ache-0鐨勬暟鎹紝杞Щ涓嶅鍔瞔ache-00涓�
-            String cache00 = redisCache.getCacheObject("cache-0");
-            if (!StringUtils.isEmpty(cache00)) redisCache.setCacheObject("cache-0", cache00 + "," + value0);
-            else redisCache.setCacheObject("cache-0", value0);
+            //灏哻ache-0鐨勬暟鎹紝杞Щ鍒癱ache-00涓�
+            redisCache.deleteObject("cache-00");
+            String cache00 = redisCache.getCacheObject("cache-00");
+            if (!StringUtils.isEmpty(cache00))
+                redisCache.setCacheObject("cache-00", cache00 + "," + value0, 120, TimeUnit.MINUTES);
+            else redisCache.setCacheObject("cache-00", value0, 120, TimeUnit.MINUTES);
             redisCache.deleteObject("cache-0");
         } else {
             for (int i = 1; i < 6; i++) {
@@ -776,10 +1180,19 @@
                 if (CollectionUtils.isNotEmpty(pullTaskVOList2) && pullTaskVOList2.size() > 0) {
                     pullTaskVOList.addAll(pullTaskVOList2);
                 }
+                //灏哻ache-i鐨勬暟鎹紝杞Щ涓嶅鍔瞔ache-0i涓�
+                String cache0i = redisCache.getCacheObject("cache-0" + i);
+                if (!StringUtils.isEmpty(cache0i)) redisCache.setCacheObject("cache-0" + i, cache0i + "," + value);
+                else redisCache.setCacheObject("cache-0" + i, value);
                 redisCache.deleteObject("cache-" + i);
             }
         }
-
+        if (CollectionUtils.isNotEmpty(pullTaskVOList)) {
+            //缁欏洖璋冨弬鏁拌祴鍊�
+            for (PullTaskVO pullTaskVO : pullTaskVOList) {
+                pullTaskVO.setAsrcallback(ASRCallBackPath);
+            }
+        }
         return pullTaskVOList;
     }
 
@@ -797,7 +1210,9 @@
                 String subId = split[i].trim().replace(",", "");
 
                 ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(Long.valueOf(subId));
+                ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
                 IvrTaskTemplate ivrTaskTemplate = ivrTaskTemplateService.selectIvrTaskTemplateByID(serviceSubtask.getTemplateid());
+                if (ObjectUtils.isEmpty(ivrTaskTemplate)) continue;
                 //閫氳繃浠诲姟妯℃澘涓殑"绗竴娆¢棶棰樼紪鍙�"鑾峰彇绗竴涓棶棰�;
                 IvrTaskTemplateScript ivrTaskTemplateScript = null;
                 IvrTaskTemplateScript ivrTaskTemplateScript1 = new IvrTaskTemplateScript();
@@ -814,7 +1229,8 @@
                 if (ObjectUtils.isEmpty(ivrTaskTemplateScript)) return null;
                 //鑾峰彇閫氶厤绗﹀尮閰嶈繃鍚庣殑闂
                 String scrContent = getObject(serviceSubtask, ivrTaskTemplateScript.getScriptContent());
-                String kcb = ivrTaskTemplate.getRevisitBefore() + "," + scrContent;
+                String kcb = serviceTask.getKcb() + "," + scrContent;
+//                String kcb = ivrTaskTemplate.getRevisitBefore();
 
                 //灏佽杩斿洖鏁版嵁
                 //taskId = 瀛愪换鍔D + 闂ID +闂搴忓彿
@@ -823,9 +1239,11 @@
                 pullTaskVO.setSections(LocalTime.now().format(DateTimeFormatter.ofPattern("hh:mm")) + "-" + LocalTime.now().plusMinutes(1).format(DateTimeFormatter.ofPattern("hh:mm")));
                 pullTaskVO.setPhones(serviceSubtask.getPhone());
                 pullTaskVO.setPrologue(kcb);
-                pullTaskVO.setDisplayNo("85129866");
+                if (cacheName.equals("cache-0")) pullTaskVO.setDisplayNo("2");
+                else pullTaskVO.setDisplayNo("2");
                 pullTaskVOList.add(pullTaskVO);
                 redisCache.setCacheObject(subId.trim() + "-" + serviceSubtask.getPhone().trim(), ivrTaskTemplateScript.getId().toString());
+//                redisCache.setCacheObject(subId.trim() + "-" + serviceSubtask.getPhone().trim() + "-firstSort", 1, 120, TimeUnit.MINUTES);
             } else {
                 if (StringUtils.isEmpty(newValue0)) {
                     newValue0 = "," + split[i].trim() + ",";
@@ -839,6 +1257,242 @@
         return pullTaskVOList;
     }
 
+
+    //涓嬮潰鐨勪唬鐮佷笉鑳藉垹闄わ紝涓婇潰鐨勬柟娉曞彧鏄厤鍚堢數璇濈鑱旇皟鐢ㄧ殑锛�
+//    @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("璇uid涓嶅瓨鍦�");
+//        }
+//        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();
+////        }
+//
+//        ServiceSubtask ServiceSubtask = (ServiceSubtask) map.get("ServiceSubtask");
+//        List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOs = (List<IvrLibaTemplateScriptVO>) map.get("ivrLibaTemplateScriptVO");
+//        //灏唘uid鏇存柊鍒版暟鎹簱涓�
+//        ServiceSubtask.setSenduuid(phoneCallBackVO.getUuid());
+//        ServiceSubtaskMapper.updateServiceSubtask(ServiceSubtask);
+//
+//        //鑾峰彇妯℃澘淇℃伅
+//        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 == ServiceSubtask.getRecallcount().intValue()) {
+//                    log.info("鏃犱汉鎺ュ惉锛歿},   {}", phoneCallBackVO.getErrResult(), phoneCallBackVO.getUuid());
+//                    //杩炵画鎵撹瀹氭锛屽鏋滆娌′汉鎺ワ紝閭e氨缁撴潫
+//                    ServiceSubtask.setResult(phoneCallBackVO.getErrResult());
+//                    ServiceSubtaskMapper.updateServiceSubtask(ServiceSubtask);
+//                    redisCache.deleteObject(phoneCallBackVO.getUuid() + "uint8");
+//                } else if (integer != null && integer < ServiceSubtask.getRecallcount().intValue()) {
+//                    //杩涜閲嶆嫧
+//                    PhoneUtils phoneUtils = new PhoneUtils();
+//                    phoneUtils.ob(null, null, null, null, null, null, null, ServiceSubtask.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 < ServiceSubtask.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 == ServiceSubtask.getRecallcount().intValue()) {
+//                    ServiceSubtask.setResult("鏃犱汉鎺ュ惉");
+//                    ServiceSubtaskMapper.updateServiceSubtask(ServiceSubtask);
+//                    redisCache.deleteObject(phoneCallBackVO.getUuid() + "enumState");
+//                }
+//            } else if (phoneCallBackVO.getEnumState() == 2) {
+//                //鎮h�呮寕鏂數璇�
+//                log.info("鎮h�呮寕鏂數璇濓細{}", phoneCallBackVO.getUuid());
+//                ServiceSubtask.setResult(phoneCallBackVO.getHangUpResult());
+//                ServiceSubtaskMapper.updateServiceSubtask(ServiceSubtask);
+//                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);
+//                        // 闂锛�  鍘昏皟鐢ㄢ�渢ts鍚堟垚鍜屾挱鏀锯�濇帴鍙�
+//                        phoneUtils.ttsPlayback(nowQuestion.getQuestionText(), phoneCallBackVO.getUuid());
+//                    }
+//                } else {
+//                    redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", noVoice + 1, 120, TimeUnit.MINUTES);
+//                    //璋冪敤ivrLibaTemplateScriptVO涓殑slienceText(闈欓粯璇濇湳)
+//                    String slienceText = nowQuestion.getSlienceText();
+//                    //闈欓粯璇濇湳  + 闂锛�  鍘昏皟鐢ㄢ�渢ts鍚堟垚鍜屾挱鏀锯�濇帴鍙�
+//                    phoneUtils.ttsPlayback(slienceText + nowQuestion.getQuestionText(), phoneCallBackVO.getUuid());
+//                    return new PhoneCallBackVO();
+//                }
+//
+//            } else {
+//                //鏈夊洖璇濓紝瀵瑰洖绛旂殑闂,杩涜姝e垯鍖归厤锛堣繖閲屽彧閽堝閫夋嫨棰橈紝鍏跺畠棰樺瀷涓嶈锛�
+//                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()) {
+//                        //璇存槑鍖归厤姝g‘浜�
+//                        //杩欓噷搴旇鍏堝垽鏂被鍨嬶紝鍘诲啀淇敼锛岃缃甀sUserOperation鏄崟閫夐鐨勬敼娉�
+//                        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銆乼ts鍚堟垚鍜屾挱鏀撅紝 tts_playback鈥濆皢缁撴灉浼犲洖
+//
+//
+//                        }
+//                        break;
+//                    }
+//                }
+//
+//            }
+//        }
+//        return phoneCallBackVO;
+//    }
+
     @Override
     public Integer saveQuestionAnswerPhone(ServiceSubTaskDetailReq serviceSubTaskDetailReq) {
         int i = 0;
@@ -846,7 +1500,7 @@
             RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample();
             Long tid = Long.valueOf(rsaPublicKeyExample.decryptedData(serviceSubTaskDetailReq.getParam1(), pri_key));
             Long pid = Long.valueOf(rsaPublicKeyExample.decryptedData(serviceSubTaskDetailReq.getParam2(), pri_key));
-            ServiceSubtask ivrTaskSingle = new ServiceSubtask();
+            ServiceSubtaskVO ivrTaskSingle = new ServiceSubtaskVO();
             ivrTaskSingle.setTaskid(tid);
             ivrTaskSingle.setPatid(pid);
             List<ServiceSubtask> selectServiceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(ivrTaskSingle);
@@ -870,6 +1524,38 @@
         return i;
     }
 
+    @Override
+    public List<ServiceSubtaskCount> getSfFzInfoEveryMonth(ServiceSubtaskCountReq serviceSubtaskCountReq) {
+        if (serviceSubtaskCountReq.getUserId() == null) {
+            Long userId = SecurityUtils.getUserId();
+            serviceSubtaskCountReq.setUserId(userId);
+        }
+        if (serviceSubtaskCountReq.getStartTime() == null) {
+            LocalDate of = LocalDate.of(LocalDate.now().getYear(), 1, 1);
+            serviceSubtaskCountReq.setStartTime(Date.from(of.atStartOfDay(ZoneId.systemDefault()).toInstant()));
+        }
+        if (serviceSubtaskCountReq.getEndTime() == null) {
+            serviceSubtaskCountReq.setEndTime(new Date());
+        }
+        List<ServiceSubtaskCount> sfFzInfoEveryMonth = serviceSubtaskMapper.getSfFzInfoEveryMonth(serviceSubtaskCountReq);
+        List<ServiceSubtaskCount> result = sfFzInfoEveryMonth.stream().collect(Collectors.groupingBy(ServiceSubtaskCount::getMonth, Collectors.groupingBy(ServiceSubtaskCount::getServiceType, Collectors.summingLong(ServiceSubtaskCount::getCount)))).entrySet().stream().flatMap(monthEntry -> monthEntry.getValue().entrySet().stream().map(typeEntry -> new ServiceSubtaskCount(monthEntry.getKey(), typeEntry.getKey(), typeEntry.getValue()))).collect(Collectors.toList());
+
+        List<ServiceSubtaskCount> result2 = new ArrayList<>();
+        //鏍规嵁鏈嶅姟绫诲瀷杩涜绛涢��
+        if (CollectionUtils.isNotEmpty(serviceSubtaskCountReq.getServiceType())) {
+            for (ServiceSubtaskCount serviceSubtaskCount : result) {
+                for (Long type : serviceSubtaskCountReq.getServiceType()) {
+                    if (type == serviceSubtaskCount.getServiceType()) {
+                        result2.add(serviceSubtaskCount);
+                    }
+                }
+            }
+        } else {
+            result2 = result;
+        }
+        return result2;
+    }
+
     private IvrTaskTemplateScriptVO getNextQuestion(List<IvrTaskTemplateScriptVO> IvrTaskTemplateScriptVOList, IvrTaskTemplateScriptVO IvrTaskTemplateScriptVO) {
 
         for (int j = 0; j < IvrTaskTemplateScriptVOList.size(); j++) {
@@ -880,7 +1566,6 @@
         }
         return null;
     }
-
 
     private ServiceSubtaskDetail getServiceSubtaskDetail(PhoneCallReqYQVO phoneCallReqYQVO, IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO, ServiceSubtask serviceSubtask, IvrTaskTemplate ivrTaskTemplate) {
         ServiceSubtaskDetail serviceSubtaskDetail = new ServiceSubtaskDetail();
@@ -901,8 +1586,10 @@
         serviceSubtaskDetail.setTemplateid(ivrTaskTemplate.getId().toString());
         serviceSubtaskDetail.setTemplatequestionnum(ivrTaskTemplateScriptVO.getId());
         serviceSubtaskDetail.setQuestiontext(ivrTaskTemplateScriptVO.getScriptContent());
+        serviceSubtaskDetail.setQuestionvoice(phoneCallReqYQVO.getRecordpath());
         serviceSubtaskDetail.setCategoryname(ivrTaskTemplateScriptVO.getScriptType());
         serviceSubtaskDetail.setTargetoptions(ivrTaskTemplateScriptVO.getTargetOptions());
+        serviceSubtaskDetail.setExtemplateText(ivrTaskTemplateScriptVO.getExtemplateText());
 
         int i = 1;
         for (IvrTaskTemplateTargetoption ivrTaskTemplateTargetoption : ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList()) {

--
Gitblit v1.9.3