liusheng
2024-04-15 fdf1b9c1e4489a0c2615fa596268b2f71fad7b4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
package com.smartor.service.impl;
 
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.smartor.config.PhoneUtils;
import com.smartor.config.PhoneUtils;
import com.smartor.config.RabbitMqConfig;
import com.smartor.domain.*;
import com.smartor.mapper.IvrLibaExtemplatescriptMapper;
import com.smartor.mapper.IvrLibaTemplateTargetoptionMapper;
import com.smartor.mapper.IvrTaskcallMapper;
import com.smartor.service.IIvrTaskcallService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
/**
 * 单一任务(随访)Service业务层处理
 *
 * @author ruoyi
 * @date 2024-02-02
 */
@Slf4j
@Service
public class IvrTaskcallServiceImpl implements IIvrTaskcallService {
    @Autowired
    private IvrTaskcallMapper ivrTaskcallMapper;
 
    @Autowired
    private IvrLibaTemplateTargetoptionMapper ivrLibaScriptTargetoptionMapper;
 
    @Autowired
    private RedisCache redisCache;
 
    @Autowired
    private IvrLibaExtemplatescriptMapper ivrLibaExtemplatescriptMapper;
 
    @Autowired
    private RabbitTemplate rabbitTemplate;
 
 
    /**
     * 查询单一任务(随访)
     *
     * @param id 单一任务(随访)主键
     * @return 单一任务(随访)
     */
    @Override
    public IvrTaskcall selectIvrTaskcallById(Long id) {
        return ivrTaskcallMapper.selectIvrTaskcallById(id);
    }
 
    /**
     * 查询单一任务(随访)列表
     *
     * @param ivrTaskcall 单一任务(随访)
     * @return 单一任务(随访)
     */
    @Override
    public List<IvrTaskcall> selectIvrTaskcallList(IvrTaskcall ivrTaskcall) {
        return ivrTaskcallMapper.selectIvrTaskcallList(ivrTaskcall);
    }
 
    /**
     * 新增单一任务(随访)
     *
     * @param ivrTaskcall 单一任务(随访)
     * @return 结果
     */
    @Override
    public int insertIvrTaskcall(IvrTaskcall ivrTaskcall) {
        ivrTaskcall.setCreateTime(DateUtils.getNowDate());
        return ivrTaskcallMapper.insertIvrTaskcall(ivrTaskcall);
    }
 
    /**
     * 修改单一任务(随访)
     *
     * @param ivrTaskcall 单一任务(随访)
     * @return 结果
     */
    @Override
    public int updateIvrTaskcall(IvrTaskcall ivrTaskcall) {
        ivrTaskcall.setUpdateTime(DateUtils.getNowDate());
        return ivrTaskcallMapper.updateIvrTaskcall(ivrTaskcall);
    }
 
    /**
     * 批量删除单一任务(随访)
     *
     * @param ids 需要删除的单一任务(随访)主键
     * @return 结果
     */
    @Override
    public int deleteIvrTaskcallByIds(Long[] ids) {
        Integer i = 0;
        for (Long id : ids) {
            i = ivrTaskcallMapper.deleteIvrTaskcallById(id);
        }
        return i;
    }
 
    /**
     * 单一任务
     *
     * @param ivrTaskcallVO 单一任务
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insertOrUpdateTask(IvrTaskcallVO ivrTaskcallVO) {
        if (ObjectUtils.isEmpty(ivrTaskcallVO)) {
            log.info("任务入参为空,请检查入参");
            throw new BaseException("任务入参为空,请检查入参");
        }
        Integer integer = 0;
        if (ivrTaskcallVO.getIsoperation() != null && ivrTaskcallVO.getIsoperation() == 1) {
            //新增
            if (CollectionUtils.isNotEmpty(ivrTaskcallVO.getPatTaskRelevances())) {
                for (PatTaskRelevance patTaskRelevance : ivrTaskcallVO.getPatTaskRelevances()) {
                    //将任务信息新增到宣教任务表中
                    IvrTaskcall ivrTaskcall = DtoConversionUtils.sourceToTarget(ivrTaskcallVO, IvrTaskcall.class);
                    ivrTaskcall.setSendname(patTaskRelevance.getName());
                    ivrTaskcall.setAge(patTaskRelevance.getAge());
                    ivrTaskcall.setSfzh(patTaskRelevance.getSfzh());
                    ivrTaskcall.setPhone(patTaskRelevance.getPhone());
                    ivrTaskcall.setAddr(patTaskRelevance.getAddr());
                    ivrTaskcall.setCreateTime(DateUtils.getNowDate());
                    ivrTaskcall.setTextParam(new Gson().toJson(ivrTaskcallVO.getTextParam()));
                    if (CollectionUtils.isNotEmpty(ivrTaskcallVO.getSendTimeslot())) {
                        ivrTaskcall.setSendTimeSlot(ivrTaskcallVO.getSendTimeslot().toString());
                    }
                    ivrTaskcallMapper.insertIvrTaskcall(ivrTaskcall);
                    integer = ivrTaskcall.getId().intValue();
                }
            }
 
        } else if (ivrTaskcallVO.getIsoperation() != null && ivrTaskcallVO.getIsoperation() == 2) {
            if (CollectionUtils.isNotEmpty(ivrTaskcallVO.getPatTaskRelevances())) {
                for (PatTaskRelevance patTaskRelevance : ivrTaskcallVO.getPatTaskRelevances()) {
                    IvrTaskcall ivrTaskcall = DtoConversionUtils.sourceToTarget(ivrTaskcallVO, IvrTaskcall.class);
                    ivrTaskcall.setSendname(patTaskRelevance.getName());
                    ivrTaskcall.setAge(patTaskRelevance.getAge());
                    ivrTaskcall.setSfzh(patTaskRelevance.getSfzh());
                    ivrTaskcall.setPhone(patTaskRelevance.getPhone());
                    ivrTaskcall.setAddr(patTaskRelevance.getAddr());
                    ivrTaskcall.setCreateTime(DateUtils.getNowDate());
                    if (CollectionUtils.isNotEmpty(ivrTaskcallVO.getSendTimeslot())) {
                        ivrTaskcall.setSendTimeSlot(ivrTaskcallVO.getSendTimeslot().toString());
                    }
                    ivrTaskcall.setTextParam(new Gson().toJson(ivrTaskcallVO.getTextParam()));
                    ivrTaskcallMapper.updateIvrTaskcall(ivrTaskcall);
                    integer = ivrTaskcall.getId().intValue();
                }
            }
 
        } else if (ivrTaskcallVO.getIsoperation() != null && ivrTaskcallVO.getIsoperation() == 3) {
            ivrTaskcallMapper.deleteIvrTaskcallById(ivrTaskcallVO.getId());
 
            integer = ivrTaskcallVO.getId().intValue();
        }
        return integer;
    }
 
    /**
     * 任务发送
     *
     * @return
     */
    @Override
    public int heTaskSend(IvrTaskcallVO ivrTaskcallVO) {
        //判断任务是否是立即发送
        if (ivrTaskcallVO.getSendType().equals("2") && ivrTaskcallVO.getSendstate() == 1) {
            IvrTaskcallMQ ivrTaskcallMQ = new IvrTaskcallMQ();
            ivrTaskcallMQ.setTaskid(ivrTaskcallVO.getTaskid());
            ivrTaskcallMQ.setSendType("1");
            ivrTaskcallMQ.setTemplateid(ivrTaskcallVO.getTemplateid());
 
            //立即发送
            rabbitTemplate.convertAndSend(RabbitMqConfig.phone_exchange, RabbitMqConfig.routing_key, new Gson().toJson(ivrTaskcallMQ), message -> {
                //注意这里时间可以使long,而且是设置header
                message.getMessageProperties().setHeader("x-delay", 0);
                return message;
            });
        } else if (ivrTaskcallVO.getSendType().equals("2") && ivrTaskcallVO.getSendstate() == 1) {
            //时间段发送
            if (CollectionUtils.isNotEmpty(ivrTaskcallVO.getSendTimeslot())) {
                for (TaskSendTimeVO taskSendTimeVO : ivrTaskcallVO.getSendTimeslot()) {
                    List<TaskSendTimeVO> list = new ArrayList<>();
                    list.add(taskSendTimeVO);
 
                    //获取开始发送时间
                    String begantime = taskSendTimeVO.getBegantime();
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    //记录目前到发送时间的毫秒值 (发送时间的毫秒值 - 当前时间的毫秒值)
                    Long milliseconds = 1000L;
                    try {
                        Date date = sdf.parse(begantime);
                        milliseconds = date.getTime() - System.currentTimeMillis();
                        System.out.println("日期毫秒数:" + milliseconds);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    IvrTaskcallMQ ivrTaskcallMQ = new IvrTaskcallMQ();
                    ivrTaskcallMQ.setTaskid(ivrTaskcallVO.getTaskid());
                    ivrTaskcallMQ.setSendType("2");
                    ivrTaskcallMQ.setTemplateid(ivrTaskcallVO.getTemplateid());
                    ivrTaskcallMQ.setSendTimeslot(list);
 
                    Long finalMilliseconds = milliseconds;
                    rabbitTemplate.convertAndSend(RabbitMqConfig.phone_exchange, RabbitMqConfig.routing_key, new Gson().toJson(ivrTaskcallMQ), message -> {
                        //注意这里时间可以使long,而且是设置header
                        message.getMessageProperties().setHeader("x-delay", finalMilliseconds);
                        return message;
                    });
                }
            }
        }
 
        return 0;
    }
 
    @Override
    public PhoneCallBackVO phoneCallBack(PhoneCallBackVO phoneCallBackVO) {
        log.info("phoneCallBackVO的入参:{},{},{},{},{},{},{}", phoneCallBackVO.getResultType(), phoneCallBackVO.getUuid(), phoneCallBackVO.getErrResult(), phoneCallBackVO.getTextResult(), phoneCallBackVO.getHangUpResult(), phoneCallBackVO.getEnumState(), phoneCallBackVO.getUint8());
        //获取数据
        Boolean aBoolean = redisCache.hasKey(phoneCallBackVO.getUuid());
        if (!aBoolean) {
            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);
 
        }
 
        String cacheObject = 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();
        }
 
        IvrTaskcall ivrTaskcall = (IvrTaskcall) map.get("ivrTaskcall");
        List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOs = (List<IvrLibaTemplateScriptVO>) map.get("ivrLibaTemplateScriptVO");
        //将uuid更新到数据库中
        ivrTaskcall.setSenduuid(phoneCallBackVO.getUuid());
        ivrTaskcallMapper.updateIvrTaskcall(ivrTaskcall);
 
        //获取模板信息
        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 == ivrTaskcall.getRecallcount().intValue()) {
                    log.info("无人接听:{},   {}", phoneCallBackVO.getErrResult(), phoneCallBackVO.getUuid());
                    //连续打规定次,如果要没人接,那就结束
                    ivrTaskcall.setResult(phoneCallBackVO.getErrResult());
                    ivrTaskcallMapper.updateIvrTaskcall(ivrTaskcall);
                    redisCache.deleteObject(phoneCallBackVO.getUuid() + "uint8");
                } else if (integer != null && integer < ivrTaskcall.getRecallcount().intValue()) {
                    //进行重拨
                    PhoneUtils phoneUtils = new PhoneUtils();
                    phoneUtils.ob(phoneCallBackVO.getUuid(), null, ivrTaskcall.getPhone(), null, null, null, null, null, null, null, null);
                }
            }
 
        } else if (phoneCallBackVO.getResultType() == 2) {
            //通话状态更新接口: 2
            if (phoneCallBackVO.getEnumState() == 0) {
                // 0-振铃
                Integer integer = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "enumState");
 
                if (integer != null && integer < ivrTaskcall.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 == ivrTaskcall.getRecallcount().intValue()) {
                    ivrTaskcall.setResult("无人接听");
                    ivrTaskcallMapper.updateIvrTaskcall(ivrTaskcall);
                    redisCache.deleteObject(phoneCallBackVO.getUuid() + "enumState");
                }
            } else if (phoneCallBackVO.getEnumState() == 2) {
                //患者挂断电话
                log.info("患者挂断电话:{}", phoneCallBackVO.getUuid());
                ivrTaskcall.setResult(phoneCallBackVO.getHangUpResult());
                ivrTaskcallMapper.updateIvrTaskcall(ivrTaskcall);
                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;
    }
 
    private IvrLibaTemplateScriptVO getNextQuestion(List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOList, IvrLibaTemplateScriptVO ivrLibaTemplateScriptVO) {
 
        for (int j = 0; j < ivrLibaTemplateScriptVOList.size(); j++) {
            if (ivrLibaTemplateScriptVOList.get(j).getTargetid() == ivrLibaTemplateScriptVO.getTargetid() + 1) {
                // 对该条templateScriptVO进行处理
                return ivrLibaTemplateScriptVOList.get(j);
            }
        }
        return null;
    }
 
}