liusheng
2024-10-17 723d38375c45d24737bfef6f33a9686254abf99b
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,21 @@
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.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 +76,12 @@
    @Value("${pri_key}")
    private String pri_key;
    @Value("${ASRCallBackPath}")
    private String ASRCallBackPath;
    @Value("${hangup}")
    private String hangup;
    /**
     * 查询单一任务(随访)
@@ -89,23 +97,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) {
        //定义患者与单一任务关联表集合
        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 +150,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 +175,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 +202,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 +284,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 +325,25 @@
                    //将任务信息新增到随访服务表中
                    serviceSubtask.setSendname(patTaskRelevance.getName());
                    serviceSubtask.setAge(patTaskRelevance.getAge());
                    serviceSubtask.setSfzh(patTaskRelevance.getSfzh());
                    serviceSubtask.setSfzh(patTaskRelevance.getIdcardno());
                    serviceSubtask.setPhone(patTaskRelevance.getPhone());
                    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 +355,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.getPhone());
                    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 +400,10 @@
                }
            }
        }
        return integer;
        Map<String, Integer> map = new HashMap<>();
        map.put("subTaskId", integer);
        map.put("taskId", serviceTask.getTaskid().intValue());
        return map;
    }
@@ -337,10 +451,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);
                    // 问题,  去调用“tts合成和播放”接口
                    String date = simpleDateFormat1.format(new Date());
                    log.info("去调用tts合成和播放接口: {},uuid为:{}", date, phoneCallBackVO.getUuid());
                    phoneUtils.ttsPlayback(nowQuestion.getScriptContent(), phoneCallBackVO.getUuid());
@@ -373,6 +492,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()) {
                    //说明匹配正确了
                    //这里应该先判断类型,去再修改,设置IsUserOperation是单选题的改法
                    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);
                    //将匹配到的标识改成true
                    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 {
                    //没有匹配上当前option
                    //Targetregex2 为false,表示在Targetregex2中存在  语句中的关键字,这个option就不用再继续匹配了,直接匹配下一个option
                    continue;
                }
            }
            if (isppd != true) {
@@ -387,6 +560,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 +570,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 +597,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());
                    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、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());
                    }
                    break;
                }
                String date = simpleDateFormat1.format(new Date());
@@ -447,11 +645,45 @@
     */
    @Override
    public PhoneCallBackYQVO phoneCallBackYQ(PhoneCallReqYQVO phoneCallReqYQVO) {
        //定义一个分数的变量
        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或null表示当前的asrtext不是一句完整的话
        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));
                    //删除结束语的患存
                    redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "- jsy");
                } else {
                    redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop", true, 120, TimeUnit.MINUTES);
                    log.error("-------PlayEventCallbackPlaystop的值为:{}", true);
                }
            }
            return phoneCallBackYQVO;
        }
        //获取放音是否结束
        boolean isPlayEventOver = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop");
        if (!isPlayEventOver) {
            return phoneCallBackYQVO;
        }
        //通过子任务ID获取到模板信息
        ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(Long.valueOf(phoneCallReqYQVO.getTaskid()));
        IvrTaskTemplate ivrTaskTemplate = ivrTaskTemplateService.selectIvrTaskTemplateByID(serviceSubtask.getTemplateid());
@@ -469,6 +701,8 @@
        if (!aBoolean) {
            //给静默设置一个默认次数在redis中
            redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES);
            //如果不存在,就把当前的UUID做为key,放到对象中去
            redisCache.setCacheObject(phoneCallReqYQVO.getUuid(), phoneCallReqYQVO, 120, TimeUnit.MINUTES);
        }
        if ("SilentCallback".equals(phoneCallReqYQVO.getOperate())) {
@@ -480,14 +714,16 @@
                phoneCallBackYQVO.setType("text");
                phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                String scriptContent = ivrTaskTemplateScriptVO.getScriptContent();
                log.error("SilentCallback的问题内容scriptContent:{}", 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);
                //大与等于的话,直接挂断
                phoneCallBackYQVO.setType("hangup");
                phoneCallBackYQVO.setType("text");
                phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                phoneCallBackYQVO.setValue(ivrTaskTemplate.getRevisitAfter());
                //将结果写到detail中
@@ -496,10 +732,39 @@
                serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate));
                serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList);
                saveQuestionAnswerPhone(serviceSubTaskDetailReq);
                //去redis中,把该子任务ID删除
                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());
                redisCache.setCacheObject(map.get("cacheName"), map.get("val"));
                redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
                redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE");
                redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop");
                //在redis中保存一下结束语,在调用挂电话的方法时删除
                redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", ivrTaskTemplate.getRevisitAfter(), 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) {
            //播报第一题
            Integer integer = redisCache.getCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim() + "-firstSort");
//            if(integer==0){
//                //integer==0,表示开场白刚播报完,需要停顿一下,等患者说话
//                redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim() + "-firstSort", 1, 120, TimeUnit.MINUTES);
//                return phoneCallBackYQVO;
//            }
            if (ivrTaskTemplateScriptVO.getSort() == 1 && integer == 1) {
                phoneCallBackYQVO.setType("text");
                phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                String scriptContent = ivrTaskTemplateScriptVO.getScriptContent();
                phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent));
                redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim() + "-firstSort", 2, 120, TimeUnit.MINUTES);
                return phoneCallBackYQVO;
            }
            //如果是文本回调
            //根据问题ID获取该问题的类型
            if (ivrTaskTemplateScriptVO.getScriptType().equals("1")) {
@@ -534,22 +799,33 @@
                        serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate));
                        serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList);
                        saveQuestionAnswerPhone(serviceSubTaskDetailReq);
//
                        //将当前前的播报状态删除,给下一题让位
                        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);
                            }
                            for (IvrTaskTemplateScript script : ivrTaskTemplateScripts) {
                                if (script.getSort() == nextQuestion.intValue()) {
                                    phoneCallBackYQVO.setType("text");
                                    phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                                    String scriptContent = script.getScriptContent();
                                    log.error("下一题问题:{}", scriptContent);
                                    phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent));
                                    //将该患者的Redis中的题目ID,进行修改
                                    redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim(), script.getId().toString(), 120, TimeUnit.MINUTES);
@@ -558,9 +834,14 @@
                                }
                            }
                        } else if (ivrTaskTemplateScriptVO.getBranchFlag().equals("0")) {
                            if (ivrTaskTemplateScriptVO.getNextScriptno() == 0 || ivrTaskTemplateScriptVO.getNextScriptno() == null) {
                                phoneCallBackYQVO.setType("hangup");
                            if (ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getNextScriptno() == 0) {
                                phoneCallBackYQVO.setType("text");
                                phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                                //更新一下分数
                                double score = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE");
                                serviceSubtask.setScore(BigDecimal.valueOf(score));
                                serviceSubtask.setFinishtime(new Date());
                                serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
                                //设置结束语
                                phoneCallBackYQVO.setValue(ivrTaskTemplate.getRevisitAfter());
                                Long id = serviceSubtask.getId();
@@ -568,6 +849,10 @@
                                redisCache.setCacheObject(map.get("cacheName"), map.get("val"));
                                redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
                                redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid());
                                redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "SCORE");
                                redisCache.deleteObject(phoneCallReqYQVO.getUuid() + "PlayEventCallbackPlaystop");
                                //在redis中保存一下结束语,在调用挂电话的方法时删除
                                redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", ivrTaskTemplate.getRevisitAfter(), 120, TimeUnit.MINUTES);
//                                return phoneCallBackYQVO;
                            }
                        }
@@ -582,16 +867,26 @@
                        //如果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");
                            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());
                            //更新一下分数
                            double score = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE");
                            serviceSubtask.setScore(BigDecimal.valueOf(score));
                            serviceSubtask.setFinishtime(new Date());
                            serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
                            //在redis中保存一下结束语,在调用挂电话的方法时删除
                            redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", ivrTaskTemplate.getRevisitAfter(), 120, TimeUnit.MINUTES);
                            //去redis中,把该子任务ID删除
                            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()获取下一题进行提问
@@ -603,6 +898,12 @@
                                    phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent));
                                    //将该患者的Redis中的题目ID,进行修改
                                    redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim(), script.getId().toString(), 120, TimeUnit.MINUTES);
                                    //更新一下分数
                                    double score = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE");
                                    score = BigDecimal.valueOf(score).add(script.getScore()).doubleValue();
                                    redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score);
                                }
                            }
                        }
@@ -624,10 +925,11 @@
                serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate));
                serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList);
                saveQuestionAnswerPhone(serviceSubTaskDetailReq);
//                String xh = idSort.split("-")[1];
                //如果选项分支为1的话,则需要根据问题上的nextScriptno进行跳转
                //问答题没有跳转
                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");
@@ -635,25 +937,44 @@
                            String scriptContent = ivrTaskTemplateScript1.getScriptContent();
                            phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent));
                            redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid());
                            redisCache.setCacheObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone(), ivrTaskTemplateScript1.getId().toString());
                            //更新一下分数
                            double score = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE");
                            score = BigDecimal.valueOf(score).add(ivrTaskTemplateScriptVO.getScore()).doubleValue();
                            redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "SCORE", score);
//                            return phoneCallBackYQVO;
                        }
                    }
                } else if (ivrTaskTemplateScriptVO.getNextScriptno() == null) {
                } else if (ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getNextScriptno() == 0) {
                    //没有下一题了,就结束了
                    phoneCallBackYQVO.setType("hangup");
                    phoneCallBackYQVO.setType("text");
                    phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
                    phoneCallBackYQVO.setValue(ivrTaskTemplate.getRevisitAfter());
                    //更新一下分数
                    double score = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "SCORE");
                    serviceSubtask.setScore(BigDecimal.valueOf(score));
                    serviceSubtask.setFinishtime(new Date());
                    serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
                    //去redis中,把该子任务ID删除
                    Long id = serviceSubtask.getId();
                    Map<String, String> map = delRedisValue(null, id.toString());
                    redisCache.setCacheObject(map.get("cacheName"), map.get("val"));
                    //在redis中保存一下结束语,在调用挂电话的方法时删除
                    redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "- jsy", ivrTaskTemplate.getRevisitAfter(), 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)) {
                    String[] split = extemplateID.split(",");
                    List<String> list = Arrays.asList(split);
                    List<Long> list1 = new ArrayList<>();
                    for (String str : list) {
                        list1.add(Long.valueOf(str));
                    }
@@ -677,12 +998,11 @@
                        break;
                    }
                }
            }
        }
        return phoneCallBackYQVO;
    }
    private String getObject(ServiceSubtask serviceSubtask, String scriptContent) {
        Map<String, Map<String, String>> param = getParam(serviceSubtask.getTaskid());
@@ -763,9 +1083,11 @@
        if (!StringUtils.isEmpty(value0)) {
            pullTaskVOList = getPullTaskList(value0, "cache-0");
            //将cache-0的数据,转移不对劲cache-00中
            String cache00 = redisCache.getCacheObject("cache-0");
            if (!StringUtils.isEmpty(cache00)) redisCache.setCacheObject("cache-0", cache00 + "," + value0);
            else redisCache.setCacheObject("cache-0", value0);
            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 +1098,19 @@
                if (CollectionUtils.isNotEmpty(pullTaskVOList2) && pullTaskVOList2.size() > 0) {
                    pullTaskVOList.addAll(pullTaskVOList2);
                }
                //将cache-i的数据,转移不对劲cache-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;
    }
@@ -813,8 +1144,9 @@
                //如果ivrTaskTemplateScript为空,也就没有往下执行的必要了
                if (ObjectUtils.isEmpty(ivrTaskTemplateScript)) return null;
                //获取通配符匹配过后的问题
                String scrContent = getObject(serviceSubtask, ivrTaskTemplateScript.getScriptContent());
                String kcb = ivrTaskTemplate.getRevisitBefore() + "," + scrContent;
//                String scrContent = getObject(serviceSubtask, ivrTaskTemplateScript.getScriptContent());
//                String kcb = ivrTaskTemplate.getRevisitBefore() + "," + scrContent;
                String kcb = ivrTaskTemplate.getRevisitBefore();
                //封装返回数据
                //taskId = 子任务ID + 问题ID +问题序号
@@ -826,6 +1158,7 @@
                pullTaskVO.setDisplayNo("85129866");
                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 +1172,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("该uuid不存在");
//        }
//        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");
//        //将uuid更新到数据库中
//        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());
//                    //连续打规定次,如果要没人接,那就结束
//                    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) {
//                //患者挂断电话
//                log.info("患者挂断电话:{}", 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);
//                        // 问题,  去调用“tts合成和播放”接口
//                        phoneUtils.ttsPlayback(nowQuestion.getQuestionText(), phoneCallBackVO.getUuid());
//                    }
//                } else {
//                    redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", noVoice + 1, 120, TimeUnit.MINUTES);
//                    //调用ivrLibaTemplateScriptVO中的slienceText(静默话术)
//                    String slienceText = nowQuestion.getSlienceText();
//                    //静默话术  + 问题,  去调用“tts合成和播放”接口
//                    phoneUtils.ttsPlayback(slienceText + nowQuestion.getQuestionText(), phoneCallBackVO.getUuid());
//                    return new PhoneCallBackVO();
//                }
//
//            } else {
//                //有回话,对回答的问题,进行正则匹配(这里只针对选择题,其它题型不行)
//                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()) {
//                        //说明匹配正确了
//                        //这里应该先判断类型,去再修改,设置IsUserOperation是单选题的改法
//                        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、tts合成和播放, tts_playback”将结果传回
//
//
//                        }
//                        break;
//                    }
//                }
//
//            }
//        }
//        return phoneCallBackVO;
//    }
    @Override
    public Integer saveQuestionAnswerPhone(ServiceSubTaskDetailReq serviceSubTaskDetailReq) {
        int i = 0;
@@ -846,7 +1415,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 +1439,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++) {