From bedd0a1cef215538df64470df6b8d4a022189136 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期三, 28 八月 2024 14:05:16 +0800
Subject: [PATCH] 代码提交
---
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java | 825 ++++++++++++++++++++++++++++++++++------------------------
1 files changed, 476 insertions(+), 349 deletions(-)
diff --git a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
index 4e8f587..2d4efa9 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -12,6 +12,8 @@
import com.smartor.config.PhoneUtils;
import com.smartor.domain.*;
import com.smartor.mapper.*;
+import com.smartor.service.IIvrTaskTemplateScriptService;
+import com.smartor.service.IIvrTaskTemplateService;
import com.smartor.service.IServiceSubtaskService;
import com.smartor.service.IServiceTaskService;
import lombok.extern.slf4j.Slf4j;
@@ -24,10 +26,15 @@
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
+import java.time.LocalTime;
+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;
/**
* 鍗曚竴浠诲姟锛堥殢璁匡級Service涓氬姟灞傚鐞�
@@ -42,7 +49,7 @@
private ServiceSubtaskMapper serviceSubtaskMapper;
@Autowired
- private ServiceSubtaskDetailMapper ivrTaskcalldetailMapper;
+ private ServiceSubtaskDetailMapper serviceSubtaskDetailMapper;
@Autowired
private IServiceTaskService serviceTaskService;
@@ -58,6 +65,11 @@
@Autowired
private IvrLibaExtemplatescriptMapper ivrLibaExtemplatescriptMapper;
+
+ @Autowired
+ private IIvrTaskTemplateService ivrTaskTemplateService;
+ @Autowired
+ private IIvrTaskTemplateScriptService iIvrTaskTemplateScriptService;
@Value("${pri_key}")
private String pri_key;
@@ -219,7 +231,8 @@
if (ObjectUtils.isNotEmpty(serviceTaskVO.getSendTimeslot()))
serviceTask.setSendTimeSlot(JSON.toJSONString(serviceTaskVO.getSendTimeslot()));
if (serviceTask.getSendState() == null) serviceTask.setSendState(1);
- serviceTask.setTemplateid(serviceTaskVO.getLibtemplateid());
+ serviceTask.setLibtemplateid(serviceTaskVO.getLibtemplateid().toString());
+ serviceTask.setTemplateid(serviceTaskVO.getTemplateid());
serviceTaskService.insertServiceTask(serviceTask);
//灏嗕换鍔′俊鎭斁鍒版湇鍔¤〃涓�
@@ -233,11 +246,6 @@
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.setCreateTime(DateUtils.getNowDate());
- serviceSubtask.setSendstate(1L);
serviceSubtask.setType(serviceTaskVO.getHospType());
serviceSubtask.setHospType(patTaskRelevance.getHospType());
serviceSubtask.setOpenid(patTaskRelevance.getOpenid());
@@ -255,15 +263,10 @@
serviceTask.setStopState(serviceTask1.getStopState() + 1);
serviceTask.setTemplateid(serviceTaskVO.getLibtemplateid());
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());
@@ -292,7 +295,6 @@
@Override
public void phoneCallBack(PhoneCallBackVO phoneCallBackVO) {
-
phoneCallBackVO.setTextResult(phoneCallBackVO.getTextResult().substring(0, phoneCallBackVO.getTextResult().length() - 1));
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
@@ -335,15 +337,10 @@
if (noVoice == ivrTaskTemplateVO.getNoVoiceNum().intValue()) {
//宸茬粡闂簡瀵瑰簲鐨勯亶鏁帮紝灏卞垽鏂槸鍚﹁繕鏈変笅涓�棰�
if (nowQuestion.getTargetid() == IvrTaskTemplateScriptVOs.size()) {
- //娌℃湁涓嬩竴棰樹簡锛屽氨鎸傛柇鐢佃瘽锛屾挱鏀剧粨鏉熻
- redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES);
phoneUtils.ttsPlayback(ivrTaskTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid());
return;
} else {
//鏈変笅涓�棰�
- redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES);
- IvrTaskTemplateScriptVO nextQuestion = getNextQuestion(IvrTaskTemplateScriptVOs, nowQuestion);
- // 闂锛� 鍘昏皟鐢ㄢ�渢ts鍚堟垚鍜屾挱鏀锯�濇帴鍙�
String date = simpleDateFormat1.format(new Date());
log.info("鍘昏皟鐢╰ts鍚堟垚鍜屾挱鏀炬帴鍙�: {},uuid涓猴細{}", date, phoneCallBackVO.getUuid());
phoneUtils.ttsPlayback(nowQuestion.getScriptContent(), phoneCallBackVO.getUuid());
@@ -376,60 +373,6 @@
Pattern pattern2 = Pattern.compile(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2());
matcher2 = pattern2.matcher(phoneCallBackVO.getTextResult());
}
- log.error("PCB--getQuestionText闂涓猴細{},UUID锛歿}", nowQuestion.getScriptContent(), phoneCallBackVO.getUuid());
- if (StringUtils.isNotEmpty(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() || StringUtils.isEmpty(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) {
- //璇存槑鍖归厤姝g‘浜�
- //杩欓噷搴旇鍏堝垽鏂被鍨嬶紝鍘诲啀淇敼锛岃缃甀sUserOperation鏄崟閫夐鐨勬敼娉�
- nowQuestion.getIvrTaskScriptTargetoptionList().get(j).setIsUserOperation(true);
- serviceTaskScriptTargetoptionMapper.updateIvrTaskTemplateTargetoption(nowQuestion.getIvrTaskScriptTargetoptionList().get(j));
-
- //灏嗛潤榛樼疆涓�0
- redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES);
- redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", 0, 120, TimeUnit.MINUTES);
-
- //灏嗘偅鑰呯殑鍥炵鍐欒繘琛ㄩ噷
- IvrTaskVisitResult serviceTaskVisitResult = DtoConversionUtils.sourceToTarget(serviceSubtask, IvrTaskVisitResult.class);
- serviceTaskVisitResult.setId(null);
- serviceTaskVisitResult.setQuestion(nowQuestion.getScriptContent());
- serviceTaskVisitResult.setPatientAnswer(phoneCallBackVO.getTextResult());
- serviceTaskVisitResult.setCreateTime(new Date());
- serviceTaskVisitResult.setOptionResult(nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getTargetvalue());
- serviceTaskVisitResultMapper.insertIvrTaskVisitResult(serviceTaskVisitResult);
-
- //灏嗗尮閰嶅埌鐨勬爣璇嗘敼鎴恡rue
- isppd = true;
-
- //鑾峰彇涓嬩竴棰�
- Long nextQuestion = nowQuestion.getIvrTaskScriptTargetoptionList().get(j).getNextQuestion();
- for (IvrTaskTemplateScriptVO script : IvrTaskTemplateScriptVOs) {
- if (script.getTargetid() == nextQuestion) {
- QuestionMessage questionMessage = new QuestionMessage();
- questionMessage.setNowQuestion(script);
- questionMessage.setQuestionList(IvrTaskTemplateScriptVOs);
- redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES);
- phoneUtils.ttsPlayback(script.getScriptContent(), phoneCallBackVO.getUuid());
- return;
- } else if (nextQuestion > IvrTaskTemplateScriptVOs.size()) {
- //娌℃湁涓嬩竴棰樹簡锛屽氨缁撴潫浜�
- String date = simpleDateFormat1.format(new Date());
- log.error("娌℃湁涓嬩竴棰樹簡锛屽氨缁撴潫浜�: {},uuid涓猴細{}", date, phoneCallBackVO.getUuid());
- redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES);
- phoneUtils.ttsPlayback(ivrTaskTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid());
- try {
- Thread.sleep(3000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- phoneUtils.hangup("", "", ivrTaskTemplateVO.getRevisitAfter(), "", "", "", "", phoneCallBackVO.getUuid());
- return;
- }
- }
- return;
- } else {
- //娌℃湁鍖归厤涓婂綋鍓峯ption
- //Targetregex2 涓篺alse锛岃〃绀哄湪Targetregex2涓瓨鍦� 璇彞涓殑鍏抽敭瀛楋紝杩欎釜option灏变笉鐢ㄥ啀缁х画鍖归厤浜嗭紝鐩存帴鍖归厤涓嬩竴涓猳ption
- continue;
- }
}
if (isppd != true) {
@@ -444,8 +387,6 @@
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());
@@ -454,7 +395,6 @@
//灏卞彲浠ユ寕鏂數璇濅簡
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);
@@ -481,39 +421,16 @@
}
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());
+ pattern.matcher(returnQues.getContent());
}
- Matcher matcher2 = null;
if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2())) {
Pattern pattern2 = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex2());
- matcher2 = pattern2.matcher(returnQues.getContent());
+ 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銆乼ts鍚堟垚鍜屾挱鏀撅紝 tts_playback鈥濆皢缁撴灉浼犲洖
- String date = simpleDateFormat1.format(new Date());
- log.info("璋冪敤鈥�15銆乼ts鍚堟垚鍜屾挱鏀�------: {},uuid涓猴細{}", date, phoneCallBackVO.getUuid());
- phoneUtils.ttsPlayback(nowQuestion.getScriptContent() + ivrTaskTemplateScriptVO.getSubmoduleText(), phoneCallBackVO.getUuid());
- }
break;
}
String date = simpleDateFormat1.format(new Date());
@@ -523,261 +440,432 @@
}
}
- //涓嬮潰鐨勪唬鐮佷笉鑳藉垹闄わ紝涓婇潰鐨勬柟娉曞彧鏄厤鍚堢數璇濈鑱旇皟鐢ㄧ殑锛�
-// @Override
-// public PhoneCallBackVO phoneCallBack(PhoneCallBackVO phoneCallBackVO) {
-// log.error("phoneCallBackVO鐨勫叆鍙傦細{},{},{},{},{},{},{}", phoneCallBackVO.getResultType(), phoneCallBackVO.getUuid(), phoneCallBackVO.getErrResult(), phoneCallBackVO.getTextResult(), phoneCallBackVO.getHangUpResult(), phoneCallBackVO.getEnumState(), phoneCallBackVO.getUint8());
-// //鑾峰彇鏁版嵁
-// Boolean aBoolean = redisCache.hasKey(phoneCallBackVO.getUuid());
-// if (!aBoolean) {
-// throw new BaseException("璇uid涓嶅瓨鍦�");
-// }
-// Integer hangupValue = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "hangup");
-// if (hangupValue != null && hangupValue == 1) {
-// //hangupValue == 1 闅忚缁撴潫锛岀洿鎺ュ彲浠ユ寕鐢佃瘽
-// PhoneUtils phoneUtils = new PhoneUtils();
-// phoneUtils.hangup(phoneCallBackVO.getUuid(), null, null, null, null, null, null, null);
+ /**
+ * 鐢佃瘽ASR閫氳瘽鍥炶皟(闆ㄧ划)
+ *
+ * @param phoneCallReqYQVO
+ */
+ @Override
+ public PhoneCallBackYQVO phoneCallBackYQ(PhoneCallReqYQVO phoneCallReqYQVO) {
+ PhoneCallBackYQVO phoneCallBackYQVO = new PhoneCallBackYQVO();
+ //channel_create 閫氶亾鍒涘缓鐨勬椂鍊欙紝鍙互鎵ц涓�浜涘叾瀹冩搷浣滐紝璀鍙戜釜鐭俊涔嬬被鐨�; 鎴戜滑鐨勪笟鍔″彲浠ヤ笉鐢ㄧ PlayEventCallback 杩欎釜鏄挱鏀捐闊崇殑,鏆傛椂鐢ㄤ笉鍒� End_time()= -1鎴杗ull琛ㄧず褰撳墠鐨刟srtext涓嶆槸涓�鍙ュ畬鏁寸殑璇�
+ if (phoneCallReqYQVO.getOperate().equals("channel_create") || phoneCallReqYQVO.getOperate().equals("PlayEventCallback") || phoneCallReqYQVO.getEnd_time() == null || phoneCallReqYQVO.getEnd_time() == -1) {
+ return phoneCallBackYQVO;
+ }
+ //閫氳繃瀛愪换鍔D鑾峰彇鍒版ā鏉夸俊鎭�
+ ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(Long.valueOf(phoneCallReqYQVO.getTaskid()));
+ IvrTaskTemplate ivrTaskTemplate = ivrTaskTemplateService.selectIvrTaskTemplateByID(serviceSubtask.getTemplateid());
+ //鑾峰彇妯℃澘闂
+ IvrTaskTemplateScript ivrTaskTemplateScript = new IvrTaskTemplateScript();
+ ivrTaskTemplateScript.setTemplateID(serviceSubtask.getTemplateid());
+ List<IvrTaskTemplateScript> ivrTaskTemplateScripts = iIvrTaskTemplateScriptService.selectIvrTaskTemplateScriptList(ivrTaskTemplateScript);
+ //鑾峰彇闂ID 鍜� 搴忓彿
+ String scriptId = redisCache.getCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim());
+ log.error("scriptId鏄灏戯細{}", scriptId);
+ //褰撳墠棰樼殑淇℃伅
+ IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO = iIvrTaskTemplateScriptService.getTaskTempScriptInfoByid(Long.valueOf(scriptId));
+ //鍒ゆ柇UUID鏄惁瀛樺湪
+ Boolean aBoolean = redisCache.hasKey(phoneCallReqYQVO.getUuid());
+ if (!aBoolean) {
+ //缁欓潤榛樿缃竴涓粯璁ゆ鏁板湪redis涓�
+ redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES);
+ }
+
+ if ("SilentCallback".equals(phoneCallReqYQVO.getOperate())) {
+ //濡傛灉鏄潤榛樺洖璋�
+ Integer num = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "noVoice");
+ //鍒ゆ柇闈欓粯鍥炶皟娆℃暟鏄惁灏忎笌妯℃澘瑙勫畾鐨勬鏁�
+ if (num < ivrTaskTemplate.getNoVoiceNum()) {
+ //灏忎笌鐨勮瘽,灏辩户缁棶鎮h��
+ phoneCallBackYQVO.setType("text");
+ phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
+ String scriptContent = ivrTaskTemplateScriptVO.getScriptContent();
+ phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent));
+ //灏嗛潤榛樻鏁板姞1
+ Integer noVoiceNum = redisCache.getCacheObject(phoneCallReqYQVO.getUuid() + "noVoice");
+ redisCache.setCacheObject(phoneCallReqYQVO.getUuid() + "noVoice", noVoiceNum + 1, 120, TimeUnit.MINUTES);
+ } else {
+ log.error("闈欓粯娆℃暟杈惧埌,鎸傛帀鐢佃瘽锛歿}", num);
+ //澶т笌绛変簬鐨勮瘽,鐩存帴鎸傛柇
+ phoneCallBackYQVO.setType("hangup");
+ phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
+ phoneCallBackYQVO.setValue(ivrTaskTemplate.getRevisitAfter());
+ //灏嗙粨鏋滃啓鍒癲etail涓�
+ ServiceSubTaskDetailReq serviceSubTaskDetailReq = new ServiceSubTaskDetailReq();
+ List<ServiceSubtaskDetail> serviceSubtaskDetailList = new ArrayList<>();
+ serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate));
+ serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList);
+ saveQuestionAnswerPhone(serviceSubTaskDetailReq);
+ redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
+ }
+ return phoneCallBackYQVO;
+ } else if ("AsrCallback".equals(phoneCallReqYQVO.getOperate())) {
+ //濡傛灉鏄枃鏈洖璋�
+ //鏍规嵁闂ID鑾峰彇璇ラ棶棰樼殑绫诲瀷
+ if (ivrTaskTemplateScriptVO.getScriptType().equals("1")) {
+ //鏄�夋嫨棰�
+ for (int j = 0; j < ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().size(); j++) {
+ log.error("phoneCallReqYQVO.getAsrtext()鐨勫�间负锛歿}", phoneCallReqYQVO.getAsrtext());
+ if (StringUtils.isEmpty(phoneCallReqYQVO.getAsrtext())) {
+ continue;
+ }
+ //鍖呭惈
+ Matcher matcher = null;
+ if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex())) {
+ Pattern pattern = Pattern.compile(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex());
+ matcher = pattern.matcher(phoneCallReqYQVO.getAsrtext());
+ }
+ //涓嶅寘鍚�
+ Matcher matcher2 = null;
+ if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2())) {
+ Pattern pattern2 = Pattern.compile(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2());
+ matcher2 = pattern2.matcher(phoneCallReqYQVO.getAsrtext());
+ }
+ if (StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) {
+ //璇存槑鍖归厤姝g‘浜�
+ //杩欓噷搴旇鍏堝垽鏂被鍨嬶紝鍘诲啀淇敼锛岃缃甀sUserOperation鏄崟閫夐鐨勬敼娉�
+ ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).setIsUserOperation(1);
+ serviceTaskScriptTargetoptionMapper.updateIvrTaskTemplateTargetoption(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j));
+
+ //灏嗘偅鑰呯殑鍥炵鍐欒繘service_subtask_detail涓�
+ ServiceSubTaskDetailReq serviceSubTaskDetailReq = new ServiceSubTaskDetailReq();
+ List<ServiceSubtaskDetail> serviceSubtaskDetailList = new ArrayList<>();
+ ivrTaskTemplateScriptVO.setQuestionResult(ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getOptiondesc());
+ serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate));
+ serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList);
+ saveQuestionAnswerPhone(serviceSubTaskDetailReq);
//
-// }
-//
-// Map<String, Object> map = redisCache.getCacheObject(phoneCallBackVO.getUuid());
-//// ObjectMapper objectMapper = new ObjectMapper();
-//// Map<String, Object> map = null;
-//// try {
-//// map = objectMapper.readValue(cacheObject, Map.class);
-//// } catch (JsonProcessingException e) {
-//// e.printStackTrace();
-//// }
-//
-// ServiceSubtask ServiceSubtask = (ServiceSubtask) map.get("ServiceSubtask");
-// List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOs = (List<IvrLibaTemplateScriptVO>) map.get("ivrLibaTemplateScriptVO");
-// //灏唘uid鏇存柊鍒版暟鎹簱涓�
-// ServiceSubtask.setSenduuid(phoneCallBackVO.getUuid());
-// ServiceSubtaskMapper.updateServiceSubtask(ServiceSubtask);
-//
-// //鑾峰彇妯℃澘淇℃伅
-// IvrLibaTemplateVO ivrLibaTemplateVO = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "ivrLibaTemplateVO");
-//
-//
-// //棣栧厛鍒ゆ柇resultType
-// if (phoneCallBackVO.getResultType() == 1) {
-// //鍛煎彨缁撴灉鎺ュ彛: 1
-// if (phoneCallBackVO.getUint8() == 1) {
-// //鍛煎彨澶辫触锛屽幓redis涓褰曚竴涓嬪け璐ユ鏁帮紝杩涜鍐嶆鍛煎彨
-// Integer integer = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "uint8");
-// if (integer != null) {
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "uint8", integer + 1, 120, TimeUnit.MINUTES);
-// } else {
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "uint8", 1, 120, TimeUnit.MINUTES);
-// }
-//
-// if (integer != null && integer == ServiceSubtask.getRecallcount().intValue()) {
-// log.info("鏃犱汉鎺ュ惉锛歿}, {}", phoneCallBackVO.getErrResult(), phoneCallBackVO.getUuid());
-// //杩炵画鎵撹瀹氭锛屽鏋滆娌′汉鎺ワ紝閭e氨缁撴潫
-// ServiceSubtask.setResult(phoneCallBackVO.getErrResult());
-// ServiceSubtaskMapper.updateServiceSubtask(ServiceSubtask);
-// redisCache.deleteObject(phoneCallBackVO.getUuid() + "uint8");
-// } else if (integer != null && integer < ServiceSubtask.getRecallcount().intValue()) {
-// //杩涜閲嶆嫧
-// PhoneUtils phoneUtils = new PhoneUtils();
-// phoneUtils.ob(null, null, null, null, null, null, null, ServiceSubtask.getPhone(), phoneCallBackVO.getUuid(), true);
-// }
-// }
-//
-// } else if (phoneCallBackVO.getResultType() == 2) {
-// //閫氳瘽鐘舵�佹洿鏂版帴鍙�: 2
-// if (phoneCallBackVO.getEnumState() == 0) {
-// // 0-鎸搩
-// Integer integer = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "enumState");
-//
-// if (integer != null && integer < ServiceSubtask.getRecallcount().intValue()) {
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "enumState", integer + 1, 120, TimeUnit.MINUTES);
-// } else if (integer == null) {
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "enumState", 1, 120, TimeUnit.MINUTES);
-// } else if (integer != null && integer == ServiceSubtask.getRecallcount().intValue()) {
-// ServiceSubtask.setResult("鏃犱汉鎺ュ惉");
-// ServiceSubtaskMapper.updateServiceSubtask(ServiceSubtask);
-// redisCache.deleteObject(phoneCallBackVO.getUuid() + "enumState");
-// }
-// } else if (phoneCallBackVO.getEnumState() == 2) {
-// //鎮h�呮寕鏂數璇�
-// log.info("鎮h�呮寕鏂數璇濓細{}", phoneCallBackVO.getUuid());
-// ServiceSubtask.setResult(phoneCallBackVO.getHangUpResult());
-// ServiceSubtaskMapper.updateServiceSubtask(ServiceSubtask);
-// redisCache.deleteObject(phoneCallBackVO.getUuid() + "enumState");
-// }
-//
-//
-// } else if (phoneCallBackVO.getResultType() == 3) {
-// //璇煶璇嗗埆缁撴灉涓婃姤鎺ュ彛: 3
-// Integer noVoice = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "noVoice");
-// QuestionMessage returnQues = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "returnQues");
-// IvrLibaTemplateScriptVO nowQuestion = returnQues.getNowQuestion();
-// PhoneUtils phoneUtils = new PhoneUtils();
-//
-// if (StringUtils.isEmpty(phoneCallBackVO.getTextResult())) {
-// //鏃犲洖璇�
-// //鍒ゆ柇noVoice鏄惁宸茬粡鍒颁簡鏈�澶у��
-// if (noVoice == ivrLibaTemplateVO.getNoVoiceNum().intValue()) {
-// //宸茬粡闂簡瀵瑰簲鐨勯亶鏁帮紝灏卞垽鏂槸鍚﹁繕鏈変笅涓�棰�
-// if (nowQuestion.getTargetid() == ivrLibaTemplateScriptVOs.size()) {
-// //娌℃湁涓嬩竴棰樹簡锛屽氨鎸傛柇鐢佃瘽锛屾挱鏀剧粨鏉熻
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES);
-// phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid());
-// } else {
-// //鏈変笅涓�棰�
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES);
-// IvrLibaTemplateScriptVO nextQuestion = getNextQuestion(ivrLibaTemplateScriptVOs, nowQuestion);
-// // 闂锛� 鍘昏皟鐢ㄢ�渢ts鍚堟垚鍜屾挱鏀锯�濇帴鍙�
-// phoneUtils.ttsPlayback(nowQuestion.getQuestionText(), phoneCallBackVO.getUuid());
-// }
-// } else {
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", noVoice + 1, 120, TimeUnit.MINUTES);
-// //璋冪敤ivrLibaTemplateScriptVO涓殑slienceText(闈欓粯璇濇湳)
-// String slienceText = nowQuestion.getSlienceText();
-// //闈欓粯璇濇湳 + 闂锛� 鍘昏皟鐢ㄢ�渢ts鍚堟垚鍜屾挱鏀锯�濇帴鍙�
-// phoneUtils.ttsPlayback(slienceText + nowQuestion.getQuestionText(), phoneCallBackVO.getUuid());
-// return new PhoneCallBackVO();
-// }
-//
-// } else {
-// //鏈夊洖璇濓紝瀵瑰洖绛旂殑闂,杩涜姝e垯鍖归厤锛堣繖閲屽彧閽堝閫夋嫨棰橈紝鍏跺畠棰樺瀷涓嶈锛�
-// for (int j = 0; j < nowQuestion.getIvrLibaScriptTargetoptionList().size(); j++) {
-// //鍖呭惈
-// Matcher matcher = null;
-// if (StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex())) {
-// Pattern pattern = Pattern.compile(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex());
-// matcher = pattern.matcher(phoneCallBackVO.getTextResult());
-// }
-// //涓嶅寘鍚�
-// Matcher matcher2 = null;
-// if (StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2())) {
-// Pattern pattern2 = Pattern.compile(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2());
-// matcher2 = pattern2.matcher(phoneCallBackVO.getTextResult());
-// }
-// log.info("phoneCallBack--Targetregex鐨勫�间负锛歿}, phoneCallBack--Targetregex2鐨勫�间负锛歿}", nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex(), nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2());
-// if (StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches() && StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() || StringUtils.isEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.matches()) {
-// //璇存槑鍖归厤姝g‘浜�
-// //杩欓噷搴旇鍏堝垽鏂被鍨嬶紝鍘诲啀淇敼锛岃缃甀sUserOperation鏄崟閫夐鐨勬敼娉�
-// nowQuestion.getIvrLibaScriptTargetoptionList().get(j).setIsUserOperation(true);
-// ivrLibaScriptTargetoptionMapper.updateIvrLibaTemplateTargetoption(nowQuestion.getIvrLibaScriptTargetoptionList().get(j));
-//
-//
-// //灏嗛潤榛樼疆涓�0
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES);
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", 0, 120, TimeUnit.MINUTES);
// //鑾峰彇涓嬩竴棰�
-// Integer nextQuestion = nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getNextQuestion();
-// for (IvrLibaTemplateScriptVO script : ivrLibaTemplateScriptVOs) {
-// if (script.getTargetid() == nextQuestion) {
-// QuestionMessage questionMessage = new QuestionMessage();
-// questionMessage.setNowQuestion(script);
-// questionMessage.setQuestionList(ivrLibaTemplateScriptVOs);
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES);
-// break;
-// }
-// }
-// break;
-// } else {
-// //娌℃湁鍖归厤鍒�
-// Integer mateNum = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "mateNum");
-// //鏃犲尮閰嶆鏁板幓鍒ゆ柇鏄惁鍒版渶澶ц闂鏁帮紝骞朵笖鎵�鏈夌殑閫夐」閮藉尮閰嶅畬浜�
-// if (mateNum == ivrLibaTemplateVO.getMateNum().intValue() && j == nowQuestion.getIvrLibaScriptTargetoptionList().size() - 1) {
-// //濡傛灉涓嬩竴棰樹负绌�.鍒欐柊鐨勬暟鎹繑鍥�,骞跺姞涓婃劅璋㈣
-// if (nowQuestion.getTargetid() < ivrLibaTemplateScriptVOs.size()) {
-// QuestionMessage questionMessage = new QuestionMessage();
-// IvrLibaTemplateScriptVO nextQuestion = getNextQuestion(ivrLibaTemplateScriptVOs, nowQuestion);
-// questionMessage.setQuestionList(ivrLibaTemplateScriptVOs);
-// questionMessage.setNowQuestion(nextQuestion);
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES);
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", 0, 120, TimeUnit.MINUTES);
-// } else {
-// //灏卞彲浠ユ寕鏂數璇濅簡
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES);
-// phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid());
-// break;
-// }
-// } else if (mateNum < ivrLibaTemplateVO.getMateNum().intValue() && j == nowQuestion.getIvrLibaScriptTargetoptionList().size() - 1) {
-// //娌℃湁闂埌瑙勫畾娆℃暟
-// mateNum = mateNum + 1;
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", mateNum, 120, TimeUnit.MINUTES);
-// }
-// }
-//
-// }
-// //閫夐」鍖归厤瀹屾垚鍚庯紝闇�瑕佸啀鍘婚�氳繃搴撳啀杩涜鍖归厤涓�娆�
-// String extemplateID = ivrLibaTemplateVO.getSubmoduleID();
-// String[] split = extemplateID.split(",");
-// List<String> list = Arrays.asList(split);
-// List<Long> list1 = new ArrayList<>();
-// if (StringUtils.isNotEmpty(extemplateID)) {
-// for (String str : list) {
-// list1.add(Long.valueOf(str));
-// }
-// List<IvrLibaExtemplatescript> ivrLibaExtemplatescripts = ivrLibaExtemplatescriptMapper.queryIvrLibaExtemplatescriptList(list1);
-// for (IvrLibaExtemplatescript ivrLibaExtemplatescript : ivrLibaExtemplatescripts) {
-// Matcher matcher = null;
-// if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex())) {
-// Pattern pattern = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex());
-// matcher = pattern.matcher(returnQues.getContent());
-// }
-//
-// Matcher matcher2 = null;
-// if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2())) {
-// Pattern pattern2 = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex2());
-// matcher2 = pattern2.matcher(returnQues.getContent());
-// }
-// log.info("++++++++++++++++++++++++++閫氱敤搴撴槸鍚︿负绌猴細selfRegex : {} , selfRegex2 : {}", ivrLibaExtemplatescript.getSelfRegex(), ivrLibaExtemplatescript.getSelfRegex2());
-// if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex()) && matcher.matches() && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && matcher2.matches() || StringUtils.isEmpty(ivrLibaExtemplatescript.getSelfRegex()) && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && matcher2.matches() || StringUtils.isEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex()) && matcher.matches()) {
-// QuestionMessage questionMessage = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "returnQues");
-// IvrLibaTemplateScriptVO ivrLibaTemplateScriptVO = returnQues.getNowQuestion();
-// ivrLibaTemplateScriptVO.setSubmoduleText(ivrLibaExtemplatescript.getSwitchText());
-// ivrLibaTemplateScriptVO.setSubmoduleVoice(ivrLibaExtemplatescript.getSwitchWav());
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES);
-// if (ivrLibaExtemplatescript.getIsEnd() == 1) {
-// //灏嗛棶棰樼疆绌�
-// IvrLibaTemplateScriptVO nowQuestion1 = questionMessage.getNowQuestion();
-// nowQuestion1.setQuestionText(null);
-// nowQuestion1.setQuestionVoice(null);
-// questionMessage.setNowQuestion(nowQuestion1);
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "returnQues", questionMessage, 120, TimeUnit.MINUTES);
-//
-// redisCache.setCacheObject(phoneCallBackVO.getUuid() + "isOver", 1, 120, TimeUnit.MINUTES);
-// }
-//
-// //璋冪敤鈥�15銆乼ts鍚堟垚鍜屾挱鏀撅紝 tts_playback鈥濆皢缁撴灉浼犲洖
-//
-//
-// }
-// break;
-// }
-// }
-//
-// }
-// }
-// return phoneCallBackVO;
-// }
+ if (ivrTaskTemplateScriptVO.getBranchFlag().equals("1") || ivrTaskTemplateScriptVO.getBranchFlag().equals("0") && ivrTaskTemplateScriptVO.getNextScriptno() != 0) {
+ Long nextQuestion = null;
+ if (ivrTaskTemplateScriptVO.getBranchFlag().equals("1")) {
+ nextQuestion = ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().get(j).getNextQuestion();
+ } else {
+ nextQuestion = ivrTaskTemplateScriptVO.getNextScriptno();
+ }
+
+
+ for (IvrTaskTemplateScript script : ivrTaskTemplateScripts) {
+ if (script.getSort() == nextQuestion.intValue()) {
+ phoneCallBackYQVO.setType("text");
+ phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
+ String scriptContent = script.getScriptContent();
+ phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent));
+ //灏嗚鎮h�呯殑Redis涓殑棰樼洰ID锛岃繘琛屼慨鏀�
+ redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim(), script.getId().toString(), 120, TimeUnit.MINUTES);
+ //鍒犻櫎鏃犲搷搴�
+ redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid());
+ }
+ }
+ } else if (ivrTaskTemplateScriptVO.getBranchFlag().equals("0")) {
+ if (ivrTaskTemplateScriptVO.getNextScriptno() == 0 || ivrTaskTemplateScriptVO.getNextScriptno() == null) {
+ phoneCallBackYQVO.setType("hangup");
+ phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
+ //璁剧疆缁撴潫璇�
+ phoneCallBackYQVO.setValue(ivrTaskTemplate.getRevisitAfter());
+ Long id = serviceSubtask.getId();
+ Map<String, String> map = delRedisValue(null, id.toString());
+ redisCache.setCacheObject(map.get("cacheName"), map.get("val"));
+ redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
+ redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid());
+// return phoneCallBackYQVO;
+ }
+ }
+ } else {
+ continue;
+ }
+ }
+ //閮芥病鏈夊尮閰嶅埌
+ if (StringUtils.isEmpty(phoneCallBackYQVO.getValue())) {
+ Integer count = redisCache.getCacheObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid());
+ if (count != null && count >= ivrTaskTemplate.getMateNum()) {
+ //濡傛灉count宸茬粡澶т簬鎴栫瓑浜庢病鏈夊尮閰嶆鏁�
+ if (ivrTaskTemplateScriptVO.getBranchFlag().equals("0") && ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getBranchFlag().equals("0") && ivrTaskTemplateScriptVO.getNextScriptno() == 0 || ivrTaskTemplateScriptVO.getBranchFlag().equals("1") && ivrTaskTemplateScriptVO.getNextScriptno() == null || ivrTaskTemplateScriptVO.getBranchFlag().equals("1") && ivrTaskTemplateScriptVO.getNextScriptno() == 0) {
+ //濡傛灉鏄渶鍚庝竴閬撻锛屾垨鑰呮病鏈変笅涓�棰樹簡锛屽氨鐩存帴鎸傛満
+ phoneCallBackYQVO.setType("hangup");
+ phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
+ if (StringUtils.isNotEmpty(phoneCallBackYQVO.getValue()))
+ phoneCallBackYQVO.setValue(phoneCallBackYQVO.getValue() + ivrTaskTemplate.getRevisitAfter());
+ else phoneCallBackYQVO.setValue(ivrTaskTemplate.getRevisitAfter());
+ //鍘籸edis涓紝鎶婅瀛愪换鍔D鍒犻櫎
+ Long id = serviceSubtask.getId();
+ Map<String, String> map = delRedisValue(null, id.toString());
+ redisCache.setCacheObject(map.get("cacheName"), map.get("val"));
+ redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
+// return phoneCallBackYQVO;
+ } else {
+ //鏍规嵁ivrTaskTemplateScriptVO.getNextScriptno()鑾峰彇涓嬩竴棰樿繘琛屾彁闂�
+ for (IvrTaskTemplateScript script : ivrTaskTemplateScripts) {
+ if (script.getSort() == ivrTaskTemplateScriptVO.getNextScriptno().intValue()) {
+ phoneCallBackYQVO.setType("text");
+ phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
+ String scriptContent = script.getScriptContent();
+ phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent));
+ //灏嗚鎮h�呯殑Redis涓殑棰樼洰ID锛岃繘琛屼慨鏀�
+ redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "-" + phoneCallReqYQVO.getPhone().trim(), script.getId().toString(), 120, TimeUnit.MINUTES);
+ }
+ }
+ }
+ } else {
+ if (count == null)
+ redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid(), 1, 120, TimeUnit.MINUTES);
+ else
+ redisCache.setCacheObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid(), count + 1, 120, TimeUnit.MINUTES);
+
+ phoneCallBackYQVO.setType("text");
+ phoneCallBackYQVO.setValue(ivrTaskTemplateScriptVO.getNoMatchText() + getObject(serviceSubtask, ivrTaskTemplateScriptVO.getScriptContent()));
+ }
+ }
+
+ } else {
+ //涓嶆槸閫夋嫨棰�,鐩存帴璁板綍绛旀锛屽皢缁撴灉鍐欏埌detail涓�
+ ServiceSubTaskDetailReq serviceSubTaskDetailReq = new ServiceSubTaskDetailReq();
+ List<ServiceSubtaskDetail> serviceSubtaskDetailList = new ArrayList<>();
+ serviceSubtaskDetailList.add(getServiceSubtaskDetail(phoneCallReqYQVO, ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate));
+ serviceSubTaskDetailReq.setServiceSubtaskDetailList(serviceSubtaskDetailList);
+ saveQuestionAnswerPhone(serviceSubTaskDetailReq);
+
+ //濡傛灉閫夐」鍒嗘敮涓�1鐨勮瘽锛屽垯闇�瑕佹牴鎹棶棰樹笂鐨刵extScriptno杩涜璺宠浆
+ //闂瓟棰樻病鏈夎烦杞�
+ if (ivrTaskTemplateScriptVO.getNextScriptno() != null || ivrTaskTemplateScriptVO.getNextScriptno() != 0) {
+ for (IvrTaskTemplateScript ivrTaskTemplateScript1 : ivrTaskTemplateScripts) {
+ if (ivrTaskTemplateScriptVO.getNextScriptno().intValue() == ivrTaskTemplateScript1.getSort()) {
+ phoneCallBackYQVO.setType("text");
+ phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
+ String scriptContent = ivrTaskTemplateScript1.getScriptContent();
+ phoneCallBackYQVO.setValue(getObject(serviceSubtask, scriptContent));
+ redisCache.deleteObject(phoneCallReqYQVO.getTaskid().trim() + "&&" + "mate" + "&&" + phoneCallReqYQVO.getUuid());
+ }
+ }
+ } else if (ivrTaskTemplateScriptVO.getNextScriptno() == null) {
+ //娌℃湁涓嬩竴棰樹簡锛屽氨缁撴潫浜�
+ phoneCallBackYQVO.setType("hangup");
+ phoneCallBackYQVO.setSilent_interval(ivrTaskTemplate.getSilencetime().intValue());
+ phoneCallBackYQVO.setValue(ivrTaskTemplate.getRevisitAfter());
+ //鍘籸edis涓紝鎶婅瀛愪换鍔D鍒犻櫎
+ Long id = serviceSubtask.getId();
+ redisCache.deleteObject(serviceSubtask.getId() + "-" + serviceSubtask.getPhone());
+ log.error("鐢佃瘽鎸傛柇4");
+ }
+
+ //閫夐」鍖归厤瀹屾垚鍚庯紝闇�瑕佸啀鍘婚�氳繃搴撳啀杩涜鍖归厤涓�娆�
+ String extemplateID = ivrTaskTemplate.getSubmoduleID();
+ String[] split = extemplateID.split(",");
+ List<String> list = Arrays.asList(split);
+ List<Long> list1 = new ArrayList<>();
+ if (StringUtils.isNotEmpty(extemplateID)) {
+ for (String str : list) {
+ list1.add(Long.valueOf(str));
+ }
+ List<IvrLibaExtemplatescript> ivrLibaExtemplatescripts = ivrLibaExtemplatescriptMapper.queryIvrLibaExtemplatescriptList(list1);
+ for (IvrLibaExtemplatescript ivrLibaExtemplatescript : ivrLibaExtemplatescripts) {
+ Matcher matcher = null;
+ if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex())) {
+ Pattern pattern = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex());
+ matcher = pattern.matcher(phoneCallReqYQVO.getAsrtext());
+ }
+
+ Matcher matcher2 = null;
+ if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2())) {
+ Pattern pattern2 = Pattern.compile(ivrLibaExtemplatescript.getSelfRegex2());
+ matcher2 = pattern2.matcher(phoneCallReqYQVO.getAsrtext());
+ }
+ if (StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex()) && matcher.matches() && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && matcher2.matches() || StringUtils.isEmpty(ivrLibaExtemplatescript.getSelfRegex()) && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && matcher2.matches() || StringUtils.isEmpty(ivrLibaExtemplatescript.getSelfRegex2()) && StringUtils.isNotEmpty(ivrLibaExtemplatescript.getSelfRegex()) && matcher.matches()) {
+ //灏嗛�氱敤搴撳尮閰嶇殑锛屾斁鍒拌繑鍥炲�间腑
+ phoneCallBackYQVO.setValue(phoneCallBackYQVO.getValue() + ivrLibaExtemplatescript.getSwitchText());
+ }
+ break;
+ }
+ }
+
+ }
+
+ }
+ return phoneCallBackYQVO;
+ }
+
+ private String getObject(ServiceSubtask serviceSubtask, String scriptContent) {
+ Map<String, Map<String, String>> param = getParam(serviceSubtask.getTaskid());
+ for (Map<String, String> map : param.values()) {
+ for (String key : map.keySet()) {
+ scriptContent = scriptContent.replace(key, StringUtils.isNotEmpty(map.get(key)) ? map.get(key) : "");
+ }
+ }
+ scriptContent.replace("${name}", StringUtils.isNotEmpty(serviceSubtask.getName()) ? serviceSubtask.getName() : "");
+ scriptContent.replace("${dzz}", StringUtils.isNotEmpty(serviceSubtask.getPlaceOfResidence()) ? serviceSubtask.getPlaceOfResidence() : "");
+ scriptContent.replace("${phone}", StringUtils.isNotEmpty(serviceSubtask.getTelcode()) ? serviceSubtask.getTelcode() : "");
+
+ return scriptContent;
+ }
+
+
+ /**
+ * 鑾峰彇浠诲姟閲岀殑閫氶厤绗�
+ *
+ * @param taskId
+ * @return
+ */
+ private Map<String, Map<String, String>> getParam(Long taskId) {
+ ServiceTask serviceTask = serviceTaskService.selectServiceTaskByTaskid(taskId);
+ ObjectMapper objectMapper = new ObjectMapper();
+ Map<String, Map<String, String>> serviceTaskMap = null;
+ try {
+ serviceTaskMap = objectMapper.readValue(serviceTask.getTextParam(), Map.class);
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ }
+ return serviceTaskMap;
+ }
+
+ private Map<String, String> delRedisValue(String cache, String id) {
+ id = "," + id + ",";
+ String val = "";
+ String cacheName = "";
+ Map<String, String> map = new HashMap<>();
+
+ if (StringUtils.isNotEmpty(cache)) {
+ val = redisCache.getCacheObject(cache);
+ if (!StringUtils.isEmpty(val)) {
+ if (val.contains(id)) {
+ val = val.replaceAll(id, "");
+ }
+ }
+ map.put("val", val);
+ map.put("cacheName", cache);
+ return map;
+ }
+
+ for (int i = 0; i < 6; i++) {
+ val = redisCache.getCacheObject("cache-0" + i);
+ if (!StringUtils.isEmpty(val)) {
+ if (val.contains(id)) {
+ val = val.replaceAll(id, "");
+ map.put("val", val);
+ map.put("cacheName", "cache-0" + i);
+ }
+ }
+ }
+ return map;
+ }
+
+
+ /**
+ * 闆ㄧ划浠诲姟鎷夊彇
+ *
+ * @return
+ */
+ @Override
+ public List<PullTaskVO> taskPull() {
+ //pullTaskVOList鐢ㄤ簬鏁版嵁杩斿洖
+ List<PullTaskVO> pullTaskVOList = new ArrayList<>();
+ String value0 = redisCache.getCacheObject("cache-0");
+ // cache-0涓虹珛鍗冲彂璧风殑,鍏跺畠鐨勫厛鎺ㄨ繜
+ if (!StringUtils.isEmpty(value0)) {
+ pullTaskVOList = getPullTaskList(value0, "cache-0");
+ //灏哻ache-0鐨勬暟鎹紝杞Щ涓嶅鍔瞔ache-00涓�
+ String cache00 = redisCache.getCacheObject("cache-0");
+ if (!StringUtils.isEmpty(cache00)) redisCache.setCacheObject("cache-0", cache00 + "," + value0);
+ else redisCache.setCacheObject("cache-0", value0);
+ redisCache.deleteObject("cache-0");
+ } else {
+ for (int i = 1; i < 6; i++) {
+ //鍙栧嚭浠巆ache-1 鍒� cache-5鐨勭涓�涓瓙浠诲姟淇℃伅
+ String value = redisCache.getCacheObject("cache-" + i);
+ if (StringUtils.isEmpty(value)) continue;
+ List<PullTaskVO> pullTaskVOList2 = getPullTaskList(value, "cache-" + i);
+ if (CollectionUtils.isNotEmpty(pullTaskVOList2) && pullTaskVOList2.size() > 0) {
+ pullTaskVOList.addAll(pullTaskVOList2);
+ }
+ redisCache.deleteObject("cache-" + i);
+ }
+ }
+
+ return pullTaskVOList;
+ }
+
+
+ private List<PullTaskVO> getPullTaskList(String subIds, String cacheName) {
+ //pullTaskVOList鐢ㄤ簬鏁版嵁杩斿洖
+ List<PullTaskVO> pullTaskVOList = new ArrayList<>();
+ //newValue0鐢ㄤ簬淇濆瓨娌℃湁澶勭悊鐨勫瓙 浠诲姟
+ String newValue0 = "";
+ //鏍规嵁,鑾峰彇瀛愪换鍔$殑ID
+ String[] split = subIds.split(",,");
+ for (int i = 0; i < split.length; i++) {
+ if (cacheName.equals("cache-0") && i < 5 || !cacheName.equals("cache-0") && i < 1) {
+ PullTaskVO pullTaskVO = new PullTaskVO();
+ String subId = split[i].trim().replace(",", "");
+
+ ServiceSubtask serviceSubtask = serviceSubtaskMapper.selectServiceSubtaskById(Long.valueOf(subId));
+ IvrTaskTemplate ivrTaskTemplate = ivrTaskTemplateService.selectIvrTaskTemplateByID(serviceSubtask.getTemplateid());
+ //閫氳繃浠诲姟妯℃澘涓殑"绗竴娆¢棶棰樼紪鍙�"鑾峰彇绗竴涓棶棰�;
+ IvrTaskTemplateScript ivrTaskTemplateScript = null;
+ IvrTaskTemplateScript ivrTaskTemplateScript1 = new IvrTaskTemplateScript();
+ ivrTaskTemplateScript1.setTemplateID(ivrTaskTemplate.getId());
+ List<IvrTaskTemplateScript> ivrTaskTemplateScripts = iIvrTaskTemplateScriptService.selectIvrTaskTemplateScriptList(ivrTaskTemplateScript1);
+ aa:
+ for (IvrTaskTemplateScript ivrTaskTemplateScript2 : ivrTaskTemplateScripts) {
+ if (ivrTaskTemplate.getFirstQuestionNum() == Long.valueOf(ivrTaskTemplateScript2.getSort())) {
+ ivrTaskTemplateScript = ivrTaskTemplateScript2;
+ break aa;
+ }
+ }
+ //濡傛灉ivrTaskTemplateScript涓虹┖锛屼篃灏辨病鏈夊線涓嬫墽琛岀殑蹇呰浜�
+ if (ObjectUtils.isEmpty(ivrTaskTemplateScript)) return null;
+ //鑾峰彇閫氶厤绗﹀尮閰嶈繃鍚庣殑闂
+ String scrContent = getObject(serviceSubtask, ivrTaskTemplateScript.getScriptContent());
+ String kcb = ivrTaskTemplate.getRevisitBefore() + "," + scrContent;
+
+ //灏佽杩斿洖鏁版嵁
+ //taskId = 瀛愪换鍔D + 闂ID +闂搴忓彿
+ pullTaskVO.setTaskid(subId);
+ pullTaskVO.setAppkey("ZurNHpaQLq6P55YS");
+ pullTaskVO.setSections(LocalTime.now().format(DateTimeFormatter.ofPattern("hh:mm")) + "-" + LocalTime.now().plusMinutes(1).format(DateTimeFormatter.ofPattern("hh:mm")));
+ pullTaskVO.setPhones(serviceSubtask.getPhone());
+ pullTaskVO.setPrologue(kcb);
+ pullTaskVO.setDisplayNo("85129866");
+ pullTaskVOList.add(pullTaskVO);
+ redisCache.setCacheObject(subId.trim() + "-" + serviceSubtask.getPhone().trim(), ivrTaskTemplateScript.getId().toString());
+ } else {
+ if (StringUtils.isEmpty(newValue0)) {
+ newValue0 = "," + split[i].trim() + ",";
+ } else {
+ newValue0 = newValue0 + "," + split[i].trim() + ",";
+ }
+ redisCache.setCacheObject(cacheName, newValue0);
+ }
+ }
+
+ return pullTaskVOList;
+ }
@Override
public Integer saveQuestionAnswerPhone(ServiceSubTaskDetailReq serviceSubTaskDetailReq) {
- 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();
- ivrTaskSingle.setTaskid(tid);
- ivrTaskSingle.setPatid(pid);
- List<ServiceSubtask> selectServiceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(ivrTaskSingle);
- if (CollectionUtils.isEmpty(selectServiceSubtaskList) || selectServiceSubtaskList.size() == 0) {
- log.error("鎶ラ敊浜嗭紝selectServiceSubtaskList鏁版嵁涓虹┖浜嗭細{}", ivrTaskSingle);
- return 0;
- }
int i = 0;
- //闅忚
- for (ServiceSubtaskDetail serviceSubtaskDetail : serviceSubTaskDetailReq.getServiceSubtaskDetailList()) {
- serviceSubtaskDetail.setSubId(selectServiceSubtaskList.get(0).getId());
- serviceSubtaskDetail.setId(UUID.randomUUID().toString());
- serviceSubtaskDetail.setCreateTime(new Date());
- i = ivrTaskcalldetailMapper.insertServiceSubtaskDetail(serviceSubtaskDetail);
+ if (StringUtils.isNotEmpty(serviceSubTaskDetailReq.getParam1())) {
+ 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();
+ ivrTaskSingle.setTaskid(tid);
+ ivrTaskSingle.setPatid(pid);
+ List<ServiceSubtask> selectServiceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(ivrTaskSingle);
+ if (CollectionUtils.isEmpty(selectServiceSubtaskList) || selectServiceSubtaskList.size() == 0) {
+ log.error("鎶ラ敊浜嗭紝selectServiceSubtaskList鏁版嵁涓虹┖浜嗭細{}", ivrTaskSingle);
+ return 0;
+ }
+ //闅忚
+ for (ServiceSubtaskDetail serviceSubtaskDetail : serviceSubTaskDetailReq.getServiceSubtaskDetailList()) {
+ serviceSubtaskDetail.setSubId(selectServiceSubtaskList.get(0).getId());
+ serviceSubtaskDetail.setId(UUID.randomUUID().toString());
+ serviceSubtaskDetail.setCreateTime(new Date());
+ i = serviceSubtaskDetailMapper.insertServiceSubtaskDetail(serviceSubtaskDetail);
+ }
+ } else {
+ for (ServiceSubtaskDetail serviceSubtaskDetail : serviceSubTaskDetailReq.getServiceSubtaskDetailList()) {
+ serviceSubtaskDetail.setCreateTime(new Date());
+ i = serviceSubtaskDetailMapper.insertServiceSubtaskDetail(serviceSubtaskDetail);
+ }
}
return i;
}
@@ -793,4 +881,43 @@
return null;
}
+
+ private ServiceSubtaskDetail getServiceSubtaskDetail(PhoneCallReqYQVO phoneCallReqYQVO, IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO, ServiceSubtask serviceSubtask, IvrTaskTemplate ivrTaskTemplate) {
+ ServiceSubtaskDetail serviceSubtaskDetail = new ServiceSubtaskDetail();
+ serviceSubtaskDetail.setSubId(Long.valueOf(phoneCallReqYQVO.getTaskid()));
+ serviceSubtaskDetail.setUuid(phoneCallReqYQVO.getUuid());
+ serviceSubtaskDetail.setPhone(phoneCallReqYQVO.getPhone());
+ serviceSubtaskDetail.setOperate(serviceSubtask.getCreateBy());
+ serviceSubtaskDetail.setDisplayno(phoneCallReqYQVO.getPhone());
+ serviceSubtaskDetail.setAssigntime(System.currentTimeMillis());
+ serviceSubtaskDetail.setStarttime(System.currentTimeMillis());
+ serviceSubtaskDetail.setAnswertime(System.currentTimeMillis());
+ serviceSubtaskDetail.setAsrtext("鏃犲簲绛�");
+ if (StringUtils.isNotEmpty(phoneCallReqYQVO.getAsrtext()))
+ serviceSubtaskDetail.setAsrtext(phoneCallReqYQVO.getAsrtext());
+ serviceSubtaskDetail.setBeginTime(System.currentTimeMillis());
+ serviceSubtaskDetail.setEndTime(System.currentTimeMillis());
+ serviceSubtaskDetail.setSentEnd(1L);
+ serviceSubtaskDetail.setTemplateid(ivrTaskTemplate.getId().toString());
+ serviceSubtaskDetail.setTemplatequestionnum(ivrTaskTemplateScriptVO.getId());
+ serviceSubtaskDetail.setQuestiontext(ivrTaskTemplateScriptVO.getScriptContent());
+ serviceSubtaskDetail.setCategoryname(ivrTaskTemplateScriptVO.getScriptType());
+ serviceSubtaskDetail.setTargetoptions(ivrTaskTemplateScriptVO.getTargetOptions());
+
+ int i = 1;
+ for (IvrTaskTemplateTargetoption ivrTaskTemplateTargetoption : ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList()) {
+ if (ivrTaskTemplateTargetoption.getIsUserOperation() == 1) {
+ serviceSubtaskDetail.setMatchedtext(ivrTaskTemplateTargetoption.getTargetvalue());
+ }
+ serviceSubtaskDetail.setTargetvalue(StringUtils.isEmpty(serviceSubtaskDetail.getTargetvalue()) ? i + ivrTaskTemplateTargetoption.getTargetvalue() : serviceSubtaskDetail.getTargetvalue() + " " + (i + 1) + ivrTaskTemplateTargetoption.getTargetvalue());
+ }
+
+ serviceSubtaskDetail.setAddtime(new Date());
+ serviceSubtaskDetail.setIsupload(0L);
+ serviceSubtaskDetail.setUploadTime(new Date());
+ serviceSubtaskDetail.setDelFlag("0");
+ serviceSubtaskDetail.setValueType(ivrTaskTemplateScriptVO.getScriptType());
+ return serviceSubtaskDetail;
+ }
+
}
--
Gitblit v1.9.3