| | |
| | | package com.ruoyi.web.task; |
| | | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.rabbitmq.client.Channel; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.DtoConversionUtils; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.smartor.common.SendService; |
| | | import com.smartor.config.PhoneUtils; |
| | | import com.smartor.domain.IvrLibaTemplateScriptVO; |
| | | import com.smartor.domain.IvrLibaTemplateVO; |
| | | import com.smartor.domain.IvrTaskcall; |
| | | import com.smartor.domain.QuestionMessage; |
| | | import com.smartor.domain.*; |
| | | import org.springframework.amqp.core.Message; |
| | | import org.springframework.data.convert.Jsr310Converters; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | public class PhoneTask implements Runnable { |
| | | private IvrTaskcall ivrTaskcall; |
| | | private IvrTaskSingle ivrTaskSingle; |
| | | private List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVO; |
| | | private RedisCache redisCache; |
| | | private IvrLibaTemplateVO ivrLibaTemplateVO; |
| | | private Channel channel; |
| | | private Message message; |
| | | private SendService sendService; |
| | | |
| | | public PhoneTask(IvrTaskcall ivrTaskcall, IvrLibaTemplateVO ivrLibaTemplateVO, RedisCache redisCache) { |
| | | this.ivrTaskcall = ivrTaskcall; |
| | | this.ivrLibaTemplateScriptVO = ivrLibaTemplateVO.getIvrLibaTemplateScriptVOList(); |
| | | this.ivrLibaTemplateVO = ivrLibaTemplateVO; |
| | | |
| | | public PhoneTask(IvrTaskSingle ivrTaskSingle, IvrLibaTemplateVO ivrLibaTemplateVO, RedisCache redisCache, Channel channel, Message message, SendService sendService) { |
| | | this.ivrTaskSingle = DtoConversionUtils.sourceToTarget(ivrTaskSingle, IvrTaskSingle.class); |
| | | this.ivrLibaTemplateScriptVO = DtoConversionUtils.sourceToTarget(ivrLibaTemplateVO.getIvrLibaTemplateScriptVOList(), IvrLibaTemplateScriptVO.class); |
| | | this.ivrLibaTemplateVO = DtoConversionUtils.sourceToTarget(ivrLibaTemplateVO, IvrLibaTemplateVO.class); |
| | | this.redisCache = redisCache; |
| | | this.channel = channel; |
| | | this.message = message; |
| | | this.sendService = sendService; |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | //获取电话组,查看哪些电话可以使用 |
| | | PhoneUtils phoneUtils = new PhoneUtils(); |
| | | String uuid = IdUtils.randomUUID(); |
| | | Map<String, Object> objectMap = new HashMap<>(); |
| | | objectMap.put("ivrTaskcall", ivrTaskcall); |
| | | objectMap.put("ivrLibaTemplateScriptVO", ivrLibaTemplateScriptVO); |
| | | //将数据放到redis中,方便在回调方法里获取 |
| | | redisCache.setCacheObject(uuid, objectMap, 120, TimeUnit.MINUTES); |
| | | synchronized (PhoneTask.class) { |
| | | try { |
| | | //获取电话组,查看哪些电话可以使用 |
| | | PhoneUtils phoneUtils = new PhoneUtils(); |
| | | final String uuid = IdUtils.randomUUID(); |
| | | //获取所有的“通配符”键值对 |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | Map<String, Map<String, String>> ivrTaskSingleMmap = objectMapper.readValue(ivrTaskSingle.getTextParam(), Map.class); |
| | | List<Map<String, String>> mapList = new ArrayList<>(); |
| | | if (!Objects.isNull(ivrTaskSingleMmap)) { |
| | | for (Map<String, String> map : ivrTaskSingleMmap.values()) { |
| | | mapList.add(map); |
| | | } |
| | | //将模板问题话术里的通配符替换 |
| | | for (IvrLibaTemplateScriptVO ivrLibaTemplateScriptVO : ivrLibaTemplateScriptVO) { |
| | | for (Map<String, String> map : mapList) { |
| | | for (String key : map.keySet()) { |
| | | ivrLibaTemplateScriptVO.setQuestionText(ivrLibaTemplateScriptVO.getQuestionText().replace(key, map.get(key))); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | Map<String, Object> objectMap = new HashMap<>(); |
| | | objectMap.put("ivrTaskSingle", ivrTaskSingle); |
| | | objectMap.put("ivrLibaTemplateScriptVO", ivrLibaTemplateScriptVO); |
| | | //将数据放到redis中,方便在回调方法里获取 |
| | | redisCache.setCacheObject(uuid, objectMap, 120, TimeUnit.MINUTES); |
| | | |
| | | //记录首次问题 |
| | | QuestionMessage returnQues = new QuestionMessage(); |
| | | returnQues.setKcb(ivrLibaTemplateVO.getRevisitBefore()); |
| | | for (IvrLibaTemplateScriptVO ivrLibaTemplateScriptVO : ivrLibaTemplateScriptVO) { |
| | | if (ivrLibaTemplateScriptVO.getTargetid() == ivrLibaTemplateVO.getFirstQuestionNum().intValue()) { |
| | | returnQues.setNowQuestion(ivrLibaTemplateScriptVO); |
| | | //记录首次问题 |
| | | QuestionMessage returnQues = new QuestionMessage(); |
| | | returnQues.setKcb(ivrLibaTemplateVO.getRevisitBefore()); |
| | | for (IvrLibaTemplateScriptVO ivrLibaTemplateScriptVO : ivrLibaTemplateScriptVO) { |
| | | if (ivrLibaTemplateScriptVO.getTargetid() == ivrLibaTemplateVO.getFirstQuestionNum().intValue()) { |
| | | returnQues.setNowQuestion(ivrLibaTemplateScriptVO); |
| | | } |
| | | } |
| | | returnQues.setQuestionList(ivrLibaTemplateScriptVO); |
| | | //将问题,和模板信息放到redis中 |
| | | redisCache.setCacheObject(uuid + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | redisCache.setCacheObject(uuid + "ivrLibaTemplateVO", ivrLibaTemplateVO, 120, TimeUnit.MINUTES); |
| | | |
| | | System.out.println("----------------uuID为 :" + uuid + " " + ivrTaskSingle.getSendname() + " " + returnQues.getNowQuestion().getQuestionText() + " " + ivrTaskSingle.getPhone()); |
| | | |
| | | //调用机器人电话,开始电话(需要将回调方法传入,这个等”电话方“告诉怎么传,现在先空着,还有第一句问题话术) |
| | | String ob = phoneUtils.ob("", "", "", "", "", "", "", ivrTaskSingle.getPhone(), uuid, true); |
| | | System.out.println("OB的值为:" + ob); |
| | | //通了之后,立马去调开场白 |
| | | System.out.println("问题的值为:" + returnQues.getNowQuestion().getQuestionText() + " " + uuid); |
| | | phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitBefore() + returnQues.getNowQuestion().getQuestionText(), uuid); |
| | | |
| | | // //通知 MQ 消息已被接收,可以ACK(从队列中删除)了 (这个需要根据业务再去处理ACK) |
| | | // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | returnQues.setQuestionList(ivrLibaTemplateScriptVO); |
| | | //将问题,和模板信息放到redis中 |
| | | redisCache.setCacheObject(uuid + "returnQues", returnQues, 120, TimeUnit.MINUTES); |
| | | redisCache.setCacheObject(uuid + "ivrLibaTemplateVO", ivrLibaTemplateVO, 120, TimeUnit.MINUTES); |
| | | |
| | | //调用机器人电话,开始电话(需要将回调方法传入,这个等”电话方“告诉怎么传,现在先空着,还有第一句问题话术) |
| | | phoneUtils.ob(uuid, null, ivrTaskcall.getPhone(), null, null, null, null, null, null, null, null); |
| | | |
| | | |
| | | } |
| | | } |