| | |
| | | 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.config.RabbitMqCallPhoneConfig; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.mapper.*; |
| | | import com.smartor.service.IIvrTaskService; |
| | |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | 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; |
| | |
| | | private IvrLibaTemplateTargetoptionMapper ivrLibaScriptTargetoptionMapper; |
| | | |
| | | @Autowired |
| | | private IvrLibaTemplateScriptMapper ivrLibaTemplateScriptMapper; |
| | | |
| | | @Autowired |
| | | private IvrTaskVisitResultMapper ivrTaskVisitResultMapper; |
| | | |
| | | @Autowired |
| | |
| | | private IvrLibaExtemplatescriptMapper ivrLibaExtemplatescriptMapper; |
| | | |
| | | @Autowired |
| | | private RabbitTemplate rabbitTemplate; |
| | | |
| | | |
| | | @Autowired |
| | | private PatMedOuthospMapper patMedOuthospMapper; |
| | | |
| | | @Autowired |
| | | private PatMedInhospMapper patMedInhospMapper; |
| | | private RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig; |
| | | |
| | | |
| | | /** |
| | |
| | | patTaskRelevance.setPhone(ivrTaskcall1.getPhone()); |
| | | patTaskRelevance.setAddr(ivrTaskcall1.getAddr()); |
| | | patTaskRelevance.setDeptName(ivrTaskcall1.getDeptname()); |
| | | patTaskRelevance.setBedNo(ivrTaskcall1.getBadNo()); |
| | | patTaskRelevance.setBedNo(ivrTaskcall1.getBedNo()); |
| | | patTaskRelevance.setDiagname(ivrTaskcall1.getDiagname()); |
| | | patTaskRelevances.add(patTaskRelevance); |
| | | } |
| | |
| | | if (ivrTaskcallVO.getIsoperation() != null && ivrTaskcallVO.getIsoperation() == 1) { |
| | | //往任务表中,新增任务 |
| | | IvrTask ivrTask = DtoConversionUtils.sourceToTarget(ivrTaskcallVO, IvrTask.class); |
| | | Integer taskId = ivrTaskService.insertIvrTask(ivrTask); |
| | | ivrTaskService.insertIvrTask(ivrTask); |
| | | |
| | | ivrTaskcallVO.setTaskid(ivrTask.getTaskid().longValue()); |
| | | //新增 |
| | |
| | | ivrTaskcall.setPhone(patTaskRelevance.getPhone()); |
| | | ivrTaskcall.setAddr(patTaskRelevance.getAddr()); |
| | | ivrTaskcall.setCreateTime(DateUtils.getNowDate()); |
| | | ivrTaskcall.setTextParam(new Gson().toJson(ivrTaskcallVO.getTextParam())); |
| | | ivrTaskcall.setTextParam(new Gson().toJson(patTaskRelevance.getTextParam())); |
| | | if (CollectionUtils.isNotEmpty(ivrTaskcallVO.getSendTimeslot())) { |
| | | ivrTaskcall.setSendTimeSlot(ivrTaskcallVO.getSendTimeslot().toString()); |
| | | } |
| | |
| | | @Override |
| | | public int heTaskSend(IvrTaskSingleVO ivrTaskcallVO) { |
| | | //判断任务是否是立即发送 |
| | | if (ivrTaskcallVO.getSendType().equals("2") && ivrTaskcallVO.getSendstate() == 1) { |
| | | if (ivrTaskcallVO.getSendType().equals("2")) { |
| | | IvrTaskcallMQ ivrTaskcallMQ = new IvrTaskcallMQ(); |
| | | ivrTaskcallMQ.setTaskid(ivrTaskcallVO.getTaskid()); |
| | | ivrTaskcallMQ.setSendType("1"); |
| | |
| | | String ivrTaskcallMQJson = JSON.toJSONString(ivrTaskcallMQ); |
| | | ivrTaskcallMQJson = ivrTaskcallMQJson.substring(1, ivrTaskcallMQJson.length() - 1); |
| | | //立即发送 |
| | | rabbitTemplate.convertAndSend(RabbitMqConfig.phone_exchange, RabbitMqConfig.routing_key, ivrTaskcallMQJson, message -> { |
| | | //注意这里时间可以使long,而且是设置header |
| | | message.getMessageProperties().setHeader("x-delay", 0); |
| | | return message; |
| | | }); |
| | | } else if (ivrTaskcallVO.getSendType().equals("1") && ivrTaskcallVO.getSendstate() == 1) { |
| | | rabbitMqCallPhoneConfig.sendMessage("phone_exchange", "phone.123", ivrTaskcallMQJson, 0L); |
| | | |
| | | } else if (ivrTaskcallVO.getSendType().equals("1")) { |
| | | //时间段发送 |
| | | if (CollectionUtils.isNotEmpty(ivrTaskcallVO.getSendTimeslot())) { |
| | | for (TaskSendTimeVO taskSendTimeVO : ivrTaskcallVO.getSendTimeslot()) { |
| | |
| | | Long finalMilliseconds = milliseconds; |
| | | String ivrTaskcallMQJson = JSON.toJSONString(ivrTaskcallMQ); |
| | | ivrTaskcallMQJson = ivrTaskcallMQJson.substring(1, ivrTaskcallMQJson.length() - 1); |
| | | rabbitTemplate.convertAndSend(RabbitMqConfig.phone_exchange, RabbitMqConfig.routing_key, ivrTaskcallMQJson, message -> { |
| | | //注意这里时间可以使long,而且是设置header |
| | | message.getMessageProperties().setHeader("x-delay", finalMilliseconds); |
| | | return message; |
| | | }); |
| | | rabbitMqCallPhoneConfig.sendMessage("phone_exchange", "phone.123", ivrTaskcallMQJson, 0L); |
| | | } |
| | | //将任务状态修改成执行中 |
| | | IvrTask ivrTask = new IvrTask(); |
| | | ivrTask.setTaskid(ivrTaskcallVO.getTaskid()); |
| | | ivrTask.setSendState("2"); |
| | | ivrTaskService.updateIvrTask(ivrTask); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | @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"); |
| | | |
| | | //获取数据 |
| | | Boolean aBoolean = redisCache.hasKey(phoneCallBackVO.getUuid()); |
| | |
| | | Integer hangupValue = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "hangup"); |
| | | PhoneUtils phoneUtils = new PhoneUtils(); |
| | | if (hangupValue != null && hangupValue == 1) { |
| | | log.info("电话要挂断了"); |
| | | String date = simpleDateFormat1.format(new Date()); |
| | | log.info("电话要挂断了: {}", date); |
| | | //hangupValue == 1 随访结束,直接可以挂电话 |
| | | phoneUtils.hangup("", "", "", "", "", "", "", phoneCallBackVO.getUuid()); |
| | | return; |
| | | } |
| | | |
| | | Map<String, Object> map = redisCache.getCacheObject(phoneCallBackVO.getUuid()); |
| | | IvrTaskSingle ivrTaskcall = (IvrTaskSingle) map.get("ivrTaskcall"); |
| | | IvrTaskSingle ivrTaskcall = (IvrTaskSingle) map.get("ivrTaskSingle"); |
| | | List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOs = (List<IvrLibaTemplateScriptVO>) map.get("ivrLibaTemplateScriptVO"); |
| | | //将uuid更新到数据库中 |
| | | ivrTaskcall.setSenduuid(phoneCallBackVO.getUuid()); |
| | |
| | | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES); |
| | | IvrLibaTemplateScriptVO nextQuestion = getNextQuestion(ivrLibaTemplateScriptVOs, nowQuestion); |
| | | // 问题, 去调用“tts合成和播放”接口 |
| | | String date = simpleDateFormat1.format(new Date()); |
| | | log.info("去调用tts合成和播放接口: {},uuid为:{}", date, phoneCallBackVO.getUuid()); |
| | | phoneUtils.ttsPlayback(nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); |
| | | } |
| | | } else { |
| | |
| | | //调用ivrLibaTemplateScriptVO中的slienceText(静默话术) |
| | | String slienceText = nowQuestion.getSlienceText(); |
| | | //静默话术 + 问题, 去调用“tts合成和播放”接口 |
| | | String date = simpleDateFormat1.format(new Date()); |
| | | log.info("静默话术 + 问题,去调用tts合成和播放接口: {},uuid为:{}", date, phoneCallBackVO.getUuid()); |
| | | phoneUtils.ttsPlayback(slienceText + nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); |
| | | return; |
| | | } |
| | |
| | | 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).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.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()) { |
| | | log.error("PCB--getQuestionText问题为:{},UUID:{}", nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); |
| | | if (StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex2()) && matcher2.matches() && StringUtils.isNotEmpty(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetregex()) && matcher.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); |
| | |
| | | return; |
| | | } else if (nextQuestion > ivrLibaTemplateScriptVOs.size()) { |
| | | //没有下一题了,就结束了 |
| | | String date = simpleDateFormat1.format(new Date()); |
| | | log.error("没有下一题了,就结束了: {},uuid为:{}", date, phoneCallBackVO.getUuid()); |
| | | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES); |
| | | phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid()); |
| | | try { |
| | |
| | | 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.getQuestionText(), phoneCallBackVO.getUuid()); |
| | | return; |
| | | } else { |
| | | //就可以挂断电话了 |
| | | String date = simpleDateFormat1.format(new Date()); |
| | | log.info("就可以挂断电话了------: {},uuid为:{}", date, phoneCallBackVO.getUuid()); |
| | | redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES); |
| | | phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid()); |
| | | try { |
| | |
| | | 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.getQuestionText() + ivrLibaTemplateScriptVO.getSubmoduleText(), phoneCallBackVO.getUuid()); |
| | | } |
| | | break; |
| | | } |
| | | String date = simpleDateFormat1.format(new Date()); |
| | | log.info("最后的信息回复-: {},uuid为:{}", date, phoneCallBackVO.getUuid()); |
| | | phoneUtils.ttsPlayback(nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); |
| | | } |
| | | } |