ruoyi-admin/src/main/java/com/ruoyi/web/component/RabbitMqReceiver.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/IvrLibaTemplateController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ruoyi-admin/src/main/java/com/ruoyi/web/task/PhoneTask.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
ruoyi-common/src/main/java/com/ruoyi/common/utils/HttpUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
smartor/src/main/java/com/smartor/config/RabbitMqCallPhoneConfig.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
smartor/src/main/java/com/smartor/config/RabbitMqConfig.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
smartor/src/main/java/com/smartor/domain/IvrTaskcallPhoneMQ.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
smartor/src/main/java/com/smartor/domain/TestVo.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
smartor/src/main/java/com/smartor/service/impl/IvrTaskSingleServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
ruoyi-admin/src/main/java/com/ruoyi/web/component/RabbitMqReceiver.java
@@ -2,16 +2,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.rabbitmq.client.Channel; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.web.task.PhoneTask; import com.ruoyi.web.task.PhoneTask2; import com.smartor.common.SendService; import com.smartor.config.RabbitMqConfig; import com.smartor.domain.IvrLibaTemplateVO; import com.smartor.domain.IvrTask; import com.smartor.domain.IvrTaskSingle; import com.smartor.domain.IvrTaskcallMQ; import com.smartor.config.PhoneUtils; import com.smartor.config.RabbitMqCallPhoneConfig; import com.smartor.domain.*; import com.smartor.mapper.IvrTaskMapper; import com.smartor.mapper.IvrTaskSingleMapper; import com.smartor.service.IIvrLibaTemplateService; @@ -19,12 +17,11 @@ import org.springframework.amqp.core.Message; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; import com.rabbitmq.client.Channel; import org.springframework.amqp.rabbit.connection.ConnectionFactory; import java.io.IOException; import java.util.List; @@ -35,6 +32,7 @@ @Component//ç嬿¤éå public class RabbitMqReceiver { private static IIvrLibaTemplateService ivrLibaTemplateService; private static IvrTaskSingleMapper ivrTaskcallMapper; @@ -44,6 +42,8 @@ private static SendService sendService; private static RedisCache redisCache; private static RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig; // å建åºå®å¤§å°ççº¿ç¨æ± private static final ExecutorService executorService = Executors.newFixedThreadPool(10); @@ -57,6 +57,11 @@ @Autowired public void setSendService(SendService sendService) { RabbitMqReceiver.sendService = sendService; } @Autowired public void setRabbitMqCallPhoneConfig(RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig) { RabbitMqReceiver.rabbitMqCallPhoneConfig = rabbitMqCallPhoneConfig; } @Autowired @@ -74,37 +79,22 @@ RabbitMqReceiver.redisCache = redisCache; } // @RabbitListener(queues = RabbitMqConfig.delay_queue) // public void consultReceiveDealy(String content, Message message, Channel channel) throws IOException { // log.info("----------------æ¥æ¶å»¶è¿éåæ¶æ¯--------------------"); // //éç¥ MQ æ¶æ¯å·²è¢«æ¥æ¶,å¯ä»¥ACK(ä»éåä¸å é¤)äº // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); // try { // log.info("=============Do Something=============="); // } catch (Exception e) { // log.error("============æ¶è´¹å¤±è´¥,å°è¯æ¶æ¯è¡¥å忬¡æ¶è´¹!=============="); // log.error(e.getMessage()); // /** // * basicRecoveræ¹æ³æ¯è¿è¡è¡¥åæä½ï¼ // * å ¶ä¸çåæ°å¦æä¸ºtrueæ¯ææ¶æ¯éåå°queue使¯æå¯è½è¢«å ¶å®çconsumer(é群)æ¥æ¶å°ï¼ // * 设置为falseæ¯åªè¡¥åç»å½åçconsumer // */ // channel.basicRecover(false); // } // } /** * çµè¯é访 * concurrency = "50" å¹¶åæ°ä¸º50 */ @RabbitListener(queues = RabbitMqConfig.phone_queue, concurrency = "50") @RabbitListener(queues = "phone_queue", concurrency = "50") public void phoneVisit(String content, Message message, Channel channel) throws IOException { try { IvrTaskcallMQ ivrTaskcallMQ = null; ObjectMapper mapper = new ObjectMapper(); try { ivrTaskcallMQ = mapper.readValue("{" + content + "}", IvrTaskcallMQ.class); if (!content.contains("{")) { ivrTaskcallMQ = mapper.readValue("{" + content + "}", IvrTaskcallMQ.class); } else { ivrTaskcallMQ = mapper.readValue(content, IvrTaskcallMQ.class); } } catch (JsonProcessingException e) { e.printStackTrace(); } @@ -125,22 +115,50 @@ break; } // //éè¿å¤çº¿ç¨çæ¹å¼å»æçµè¯ // executorService.submit(new PhoneTask(ivrTaskcall1, ivrLibaTemplateVO1, redisCache, channel, message, sendService)); new PhoneTask2().runPhone(ivrTaskcall1, ivrLibaTemplateVO1, redisCache, channel, message, sendService); executorService.submit(new PhoneTask(ivrTaskcall1, ivrLibaTemplateVO1, redisCache, rabbitMqCallPhoneConfig, message, sendService)); } //éç¥ MQ æ¶æ¯å·²è¢«æ¥æ¶,å¯ä»¥ACK(ä»éåä¸å é¤)äº ï¼è¿ä¸ªéè¦æ ¹æ®ä¸å¡åå»å¤çACKï¼ channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); log.info("=============Do Something=============="); } catch (Exception e) { log.error("============æ¶è´¹å¤±è´¥,å°è¯æ¶æ¯è¡¥å忬¡æ¶è´¹!=============="); log.error(e.getMessage()); /** * basicRecoveræ¹æ³æ¯è¿è¡è¡¥åæä½ï¼ * å ¶ä¸çåæ°å¦æä¸ºtrueæ¯ææ¶æ¯éåå°queue使¯æå¯è½è¢«å ¶å®çconsumer(é群)æ¥æ¶å°ï¼ * 设置为falseæ¯åªè¡¥åç»å½åçconsumer */ channel.basicRecover(false); channel.basicReject(message.getMessageProperties().getDeliveryTag(), true); } } /** * æºå¨äººç¬¬ä¸å¥è¯è¯é³ * concurrency = "50" å¹¶åæ°ä¸º50 */ @RabbitListener(queues = "ob_queue", concurrency = "50") public void obVisit(String content, Message message, Channel channel) throws IOException { try { IvrTaskcallPhoneMQ ivrTaskcallMQ = null; ObjectMapper mapper = new ObjectMapper(); ivrTaskcallMQ = mapper.readValue(content, IvrTaskcallPhoneMQ.class); //夿æ£è æ¯å¦å·²ç»æ¥çµè¯ String str = redisCache.getCacheObject(ivrTaskcallMQ.getUuid() + "state_id"); System.out.println("-----------------" + str); if (StringUtils.isNotEmpty(str) && str.equals("0")) { //æ£è å·²ç»æ¥å¬äºçµè¯ new PhoneUtils().ttsPlayback(ivrTaskcallMQ.getScript(), ivrTaskcallMQ.getUuid()); } else if (StringUtils.isNotEmpty(str) && str.equals("-10")) { //è¿ä¸ªè¯´æ,å·²ç»æäºæå®éæ°è¿æ¯æ²¡æäººæ¥ï¼å¯ä»¥å°æ¶æ¯ä»éåä¸ç§»é¤äº channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); return; } else { //è¿è¡éåå°¾é¨ï¼è¿è¡ä¸ä¸æ¬¡æ ¡éª // channel.basicRecover(false); channel.basicReject(message.getMessageProperties().getDeliveryTag(), true); System.out.println("++++++++++++++++++++++" + str); return; } //éç¥ MQ æ¶æ¯å·²è¢«æ¥æ¶,å¯ä»¥ACK(ä»éåä¸å é¤)äº ï¼è¿ä¸ªéè¦æ ¹æ®ä¸å¡åå»å¤çACKï¼ channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); } catch (Exception e) { log.error("============æ¶è´¹å¤±è´¥,å°è¯æ¶æ¯è¡¥å忬¡æ¶è´¹!=============="); log.error(e.getMessage()); channel.basicReject(message.getMessageProperties().getDeliveryTag(), true); } } ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/IvrLibaTemplateController.java
@@ -1,7 +1,6 @@ package com.ruoyi.web.controller.smartor; import com.alibaba.fastjson2.JSON; import com.google.gson.Gson; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; @@ -10,7 +9,7 @@ import com.ruoyi.common.exception.base.BaseException; import com.ruoyi.common.utils.poi.ExcelUtil; import com.smartor.config.PhoneUtils; import com.smartor.config.RabbitMqConfig; import com.smartor.config.RabbitMqCallPhoneConfig; import com.smartor.domain.IvrLibaTemplate; import com.smartor.domain.IvrLibaTemplateVO; import com.smartor.domain.Test1Vo; @@ -19,19 +18,12 @@ import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.springframework.amqp.AmqpException; import org.springframework.amqp.core.Message; import org.springframework.amqp.core.MessageBuilder; import org.springframework.amqp.core.MessagePostProcessor; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.util.HashMap; import java.util.List; import java.util.Map; /** * é访模æ¿åºController @@ -47,11 +39,14 @@ @Autowired private IIvrLibaTemplateService ivrLibaTemplateService; @Autowired private RabbitTemplate rabbitTemplate; // @Autowired // private RabbitTemplate rabbitTemplate; @Autowired private PhoneUtils phoneUtils; @Autowired private RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig; /** * æ¥è¯¢æ¨¡æ¿åºå表 @@ -152,30 +147,19 @@ @PostMapping("/queryRabbitmq") public AjaxResult queryRabbitmq(@RequestBody Test1Vo test1Vo) { // rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_NAME, "phone.001", "æµè¯æ°æ®001"); // rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_NAME, "phone.002", "æµè¯æ°æ®002"); // rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_NAME, "phone.003", "æµè¯æ°æ®003"); // rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_NAME, routintKey, message, new MessagePostProcessor() { // @Override // public Message postProcessMessage(Message message) throws AmqpException { //// message.getMessageProperties().setDelay(times); // message.getMessageProperties().getHeaders().put("x-delay", times); ////message.getMessageProperties().setExpiration(); // return message; // } // }); log.info("-------------å¯å¨å¨è¯¢åºçè¶ æ¶æéå»¶è¿éå-------------"); String data = JSON.toJSONString(test1Vo.getTestVo()); String substring = data.substring(1, data.length() - 1); rabbitMqCallPhoneConfig.sendMessage("phone_exchange", "phone.123", substring, test1Vo.getTimes()); this.rabbitTemplate.convertAndSend(RabbitMqConfig.phone_exchange, RabbitMqConfig.routing_key, substring, message -> { //注æè¿éæ¶é´å¯ä»¥ä½¿longï¼è䏿¯è®¾ç½®header message.getMessageProperties().setHeader("x-delay", test1Vo.getTimes()); return message; }); log.info("-------------å»¶è¿éå{}msåæ§è¡.-------------", test1Vo.getTimes()); return success(); } @GetMapping("/tts") public AjaxResult tts(@RequestParam("fileText") String fileText, @RequestParam("uuid") String uuid) { new PhoneUtils().ttsPlayback(fileText, uuid); return success(); } } ruoyi-admin/src/main/java/com/ruoyi/web/task/PhoneTask.java
@@ -1,15 +1,16 @@ package com.ruoyi.web.task; import com.alibaba.fastjson2.JSON; 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.config.RabbitMqCallPhoneConfig; import com.smartor.domain.*; import org.springframework.amqp.core.Message; import org.springframework.data.convert.Jsr310Converters; import org.springframework.amqp.rabbit.core.RabbitTemplate; import java.util.*; import java.util.concurrent.TimeUnit; @@ -19,79 +20,95 @@ private List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVO; private RedisCache redisCache; private IvrLibaTemplateVO ivrLibaTemplateVO; private Channel channel; private RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig; private Message message; private SendService sendService; public PhoneTask(IvrTaskSingle ivrTaskSingle, IvrLibaTemplateVO ivrLibaTemplateVO, RedisCache redisCache, Channel channel, Message message, SendService sendService) { public PhoneTask(IvrTaskSingle ivrTaskSingle, IvrLibaTemplateVO ivrLibaTemplateVO, RedisCache redisCache, RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig, 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.rabbitMqCallPhoneConfig = rabbitMqCallPhoneConfig; this.message = message; this.sendService = sendService; } @Override public void run() { 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))); } 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); } } 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(); } } 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); } } 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()); //å å°è¯æ¯æ¾å°ob_queueéåä¸ IvrTaskcallPhoneMQ ivrTaskcallPhoneMQ = new IvrTaskcallPhoneMQ(); ivrTaskcallPhoneMQ.setScript(ivrLibaTemplateVO.getRevisitBefore() + returnQues.getNowQuestion().getQuestionText()); ivrTaskcallPhoneMQ.setType("1"); ivrTaskcallPhoneMQ.setUuid(uuid); String data = JSON.toJSONString(ivrTaskcallPhoneMQ); rabbitMqCallPhoneConfig.sendMessage("phone_exchange", "phone.ob1", data, 0L); //è°ç¨æºå¨äººçµè¯ï¼å¼å§çµè¯ String ob = phoneUtils.ob("", "", "", "", "", "", "", ivrTaskSingle.getPhone(), uuid, true); System.out.println("----------------uuID为 ï¼" + uuid + " " + ivrTaskSingle.getSendname() + " " + returnQues.getNowQuestion().getQuestionText() + " " + ivrTaskSingle.getPhone() + "----------å·²ç»æ¨æ"); Map<String, String> obMap = objectMapper.readValue(ob, Map.class); Thread.sleep(1000); redisCache.setCacheObject(uuid + "state_id", "0", 10, TimeUnit.MINUTES); //è¿éå æ³¨éï¼state_id,çµè¯é£è¾¹ï¼åªè½è¿å6ï¼ä¸è½è¿å0ï¼è¿éè¦çµè¯é£è¾¹è¿è¡ä¿®æ¹ï¼é£è¾¹ä¿®æ¹ä¹åï¼ä¸é¢ä¸¤è¡å¯å é¤ï¼å°ä¸é¢çè§£å¼æ³¨é // if (obMap.get("state_id").equals("0")) { // // 说ææéäº // redisCache.setCacheObject(uuid + "state_id", "0", 10, TimeUnit.MINUTES); // } else { // while (true) { // Thread.sleep(2000); // redisCache.setCacheObject(uuid + "state_id", "0", 10, TimeUnit.MINUTES); // } // } System.out.println("OBçå¼ä¸ºï¼" + ob); } catch (Exception e) { e.printStackTrace(); } } } ruoyi-common/src/main/java/com/ruoyi/common/utils/HttpUtil.java
@@ -77,9 +77,9 @@ // 设å®åæ°ï¼å®¢æ·ç«¯çæ»è¿æ¥æ° manager.getParams().setMaxTotalConnections(400); // è®¾ç½®è¿æ¥è¶ æ¶æ¶é´,åä½ï¼æ¯«ç§ manager.getParams().setConnectionTimeout(8000); manager.getParams().setConnectionTimeout(30000); // 设置请æ±è¯»åè¶ æ¶æ¶é´ï¼åä½ï¼æ¯«ç§ manager.getParams().setSoTimeout(8000); manager.getParams().setSoTimeout(30000); // 设置ä»è¿æ¥æ± ä¸è·å龿¥æ¶é´ï¼ åä½ï¼æ¯«ç§ manager.getParams().setParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, 8000); // 使ç¨è¿æ¥æ± ææ¯å建HttpClient对象 smartor/src/main/java/com/smartor/config/RabbitMqCallPhoneConfig.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,113 @@ package com.smartor.config; import org.springframework.amqp.core.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.Map; @Component public class RabbitMqCallPhoneConfig { @Autowired private AmqpAdmin amqpAdmin; @Autowired private AmqpTemplate rabbitTemplate; /** * åå»ºäº¤æ¢æº * * @param exchangeName äº¤æ¢æºåç§° */ public void createExchange(String exchangeName) { Map<String, Object> args = new HashMap<>(); args.put("x-delayed-type", "topic"); CustomExchange exchange = new CustomExchange(exchangeName, "x-delayed-message", true, false, args); amqpAdmin.declareExchange(exchange); } /** * å建éå * * @param queueName éååç§° */ public void createQueue(String queueName) { Queue queue = new Queue(queueName, true, false, false); amqpAdmin.declareQueue(queue); } /** * äº¤æ¢æºç»å® * * @param changeName äº¤æ¢æºåç§° * @param routingKey è·¯ç±key * @param queueName éååç§° */ public void bindExchange(String changeName, String routingKey, String queueName) { Binding binding = new Binding(queueName, Binding.DestinationType.QUEUE, changeName, routingKey, null); amqpAdmin.declareBinding(binding); } /** * åéä¿¡æ¯å°äº¤æ¢æº * * @param changeName äº¤æ¢æºåç§° * @param routingKey è·¯ç±key * @param data æ¶æ¯ */ public void sendMessage(String changeName, String routingKey, String data, Long times) { this.rabbitTemplate.convertAndSend(changeName, routingKey, data, message -> { //注æè¿éæ¶é´å¯ä»¥ä½¿longï¼è䏿¯è®¾ç½®header message.getMessageProperties().setHeader("x-delay", times); return message; }); // rabbitTemplate.convertAndSend(changeName, routingKey, message); } /** * å é¤äº¤æ¢æº * * @param changeName äº¤æ¢æºåç§° */ public void deleteExchange(String changeName) { amqpAdmin.deleteExchange(changeName); } /** * å é¤éå * * @param queueName éååç§° */ public void deleteQueue(String queueName) { amqpAdmin.deleteQueue(queueName); } /** * å建MQ * * @param exchangName * @param queueName * @param routingKey * @return */ public Boolean createRabbitMq(String exchangName, String queueName, String routingKey) { this.createExchange(exchangName); this.createQueue(queueName); this.bindExchange(exchangName, routingKey, queueName); return true; } /** * å å°éè¦å建çéå建好 */ @Bean public void createMq() { createRabbitMq("phone_exchange", "ob_queue", "phone.ob1"); createRabbitMq("phone_exchange", "phone_queue", "phone.123"); } } smartor/src/main/java/com/smartor/config/RabbitMqConfig.java
@@ -1,91 +1,57 @@ package com.smartor.config; import org.springframework.amqp.core.*; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.util.HashMap; import java.util.Map; @Configuration public class RabbitMqConfig { // public static final String EXCHANGE_NAME = "phone_topic_exchange2"; // public static final String QUEUE_NAME = "phone_queue"; // // /** // * topicäº¤æ¢æº,å¹¶æä¹ å // */ // @Bean(EXCHANGE_NAME) // public Exchange phoneExchange() { // Map<String, Object> arguments = new HashMap<>(); // //æå®éä¿¡æ¹å¼ä¸ºtopic // arguments.put("x-delayed-type", "topic"); // //使ç¨CustomExchangeç±»å建ï¼ç±»åè¦æå®ä¸ºâx-delayed-messageâç±»å // Exchange exchange = new CustomExchange(EXCHANGE_NAME, "x-delayed-message", true, false, arguments); // return exchange; //package com.smartor.config; // //// //// return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build(); // } //import org.springframework.amqp.core.*; //import org.springframework.beans.factory.annotation.Qualifier; //import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Configuration; // //import java.util.HashMap; //import java.util.Map; // ////@Configuration //public class RabbitMqConfig { // ////å®ä¹å»¶è¿éå // public static final String phone_queue = "phone_queue"; // //å®ä¹å»¶è¿äº¤æ¢æº // public static final String phone_exchange = "phone_exchange"; // //å®ä¹è·¯ç±é® // public static final String routing_key = "phone.123"; // // // /** // * éå // */ // @Bean(QUEUE_NAME) // public Queue phoneQueue() { // return QueueBuilder.durable(QUEUE_NAME).build(); // } // // /** // * äº¤æ¢æºä¸éåçç»å® // * å®ä¹å»¶è¿éå // * // * @return // */ // @Bean // public Binding bindQueueExchange(@Qualifier(QUEUE_NAME) Queue phoneQueue, @Qualifier(EXCHANGE_NAME) Exchange phoneExchange) { // return BindingBuilder.bind(phoneQueue).to(phoneExchange).with(" phone.#").noargs(); // public Queue delayQueue() { // return new Queue(phone_queue, true); // } //å®ä¹å»¶è¿éå public static final String phone_queue = "phone_queue"; //å®ä¹å»¶è¿äº¤æ¢æº public static final String phone_exchange = "phone_exchange"; //å®ä¹è·¯ç±é® public static final String routing_key = "phone.123"; /** * å®ä¹å»¶è¿éå * * @return */ @Bean public Queue delayQueue() { return new Queue(phone_queue, true); } /** * å»¶æ¶éåäº¤æ¢æº * äº¤æ¢æºç±»åï¼CustomExchange * * @return */ @Bean public CustomExchange delayExchange() { Map<String, Object> args = new HashMap<>(); args.put("x-delayed-type", "topic"); return new CustomExchange(phone_exchange, "x-delayed-message", true, false, args); } /** * 为延è¿éåç»å®äº¤æ¢æº * * @param queue * @param exchange * @return */ @Bean public Binding delayBinding(Queue queue, CustomExchange exchange) { return BindingBuilder.bind(queue).to(exchange).with(routing_key).noargs(); } } // // /** // * å»¶æ¶éåäº¤æ¢æº // * äº¤æ¢æºç±»åï¼CustomExchange // * // * @return // */ // @Bean // public CustomExchange delayExchange() { // Map<String, Object> args = new HashMap<>(); // args.put("x-delayed-type", "topic"); // return new CustomExchange(phone_exchange, "x-delayed-message", true, false, args); // } // // /** // * 为延è¿éåç»å®äº¤æ¢æº // * // * @param queue // * @param exchange // * @return // */ // @Bean // public Binding delayBinding(Queue queue, CustomExchange exchange) { // return BindingBuilder.bind(queue).to(exchange).with(routing_key).noargs(); // } // //} smartor/src/main/java/com/smartor/domain/IvrTaskcallPhoneMQ.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,33 @@ package com.smartor.domain; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.List; /** * MQä»»å¡ * * @author ruoyi * @date 2024-02-02 */ @Data public class IvrTaskcallPhoneMQ extends BaseEntity { private static final long serialVersionUID = 1L; /** * ç±»å: 1 çµè¯ 2å ¶å® */ @ApiModelProperty(value = "ç±»å: 1 çµè¯ 2å ¶å®") private String type; @ApiModelProperty(value = "é®é¢") private String script; @ApiModelProperty(value = "é®é¢") private String uuid; } smartor/src/main/java/com/smartor/domain/TestVo.java
@@ -28,5 +28,7 @@ @ApiModelProperty(value = "åéç±»å: 1 æ¶é´æ®µ 2 å³å»åé") private String sendType; private String type; } smartor/src/main/java/com/smartor/service/impl/IvrTaskSingleServiceImpl.java
@@ -4,15 +4,12 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; 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.config.RabbitMqCallPhoneConfig; import com.smartor.domain.*; import com.smartor.mapper.*; import com.smartor.service.IIvrTaskService; @@ -21,7 +18,6 @@ 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; @@ -63,7 +59,7 @@ private IvrLibaExtemplatescriptMapper ivrLibaExtemplatescriptMapper; @Autowired private RabbitTemplate rabbitTemplate; private RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig; /** @@ -280,11 +276,8 @@ 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; }); rabbitMqCallPhoneConfig.sendMessage("phone_exchange", "phone.123", ivrTaskcallMQJson, 0L); } else if (ivrTaskcallVO.getSendType().equals("1")) { //æ¶é´æ®µåé if (CollectionUtils.isNotEmpty(ivrTaskcallVO.getSendTimeslot())) { @@ -314,11 +307,7 @@ 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(); @@ -333,168 +322,127 @@ @Override public void phoneCallBack(PhoneCallBackVO phoneCallBackVO) { synchronized (new IvrTaskSingleServiceImpl()) { 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()); if (!aBoolean) { throw new BaseException("该uuidä¸åå¨"); } Integer hangupValue = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "hangup"); PhoneUtils phoneUtils = new PhoneUtils(); if (hangupValue != null && hangupValue == 1) { 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()); if (!aBoolean) { throw new BaseException("该uuidä¸åå¨"); } Integer hangupValue = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "hangup"); PhoneUtils phoneUtils = new PhoneUtils(); if (hangupValue != null && hangupValue == 1) { 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("ivrTaskSingle"); List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOs = (List<IvrLibaTemplateScriptVO>) map.get("ivrLibaTemplateScriptVO"); //å°uuidæ´æ°å°æ°æ®åºä¸ ivrTaskcall.setSenduuid(phoneCallBackVO.getUuid()); ivrTaskSingleMapper.updateIvrTaskcall(ivrTaskcall); //è·å模æ¿ä¿¡æ¯ IvrLibaTemplateVO ivrLibaTemplateVO = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "ivrLibaTemplateVO"); //è¯é³è¯å«ç»æä¸æ¥æ¥å£: 3 Integer noVoice = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "noVoice"); QuestionMessage returnQues = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "returnQues"); //å°ä¼ åçç»ææ¾å°åå¤å¯¹è±¡ä¸ returnQues.setContent(phoneCallBackVO.getTextResult()); IvrLibaTemplateScriptVO nowQuestion = returnQues.getNowQuestion(); if (StringUtils.isEmpty(returnQues.getContent())) { //æ åè¯ //夿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()); return; } else { //æä¸ä¸é¢ 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 { redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", noVoice + 1, 120, TimeUnit.MINUTES); //è°ç¨ivrLibaTemplateScriptVOä¸çslienceText(éé»è¯æ¯) String slienceText = nowQuestion.getSlienceText(); //éé»è¯æ¯ + é®é¢ï¼ å»è°ç¨âttsåæåææ¾âæ¥å£ String date = simpleDateFormat1.format(new Date()); log.info("çµè¯è¦ææäº: {}", date); //hangupValue == 1 éè®¿ç»æï¼ç´æ¥å¯ä»¥æçµè¯ phoneUtils.hangup("", "", "", "", "", "", "", phoneCallBackVO.getUuid()); log.info("éé»è¯æ¯ + é®é¢,å»è°ç¨ttsåæåææ¾æ¥å£: {},uuid为ï¼{}", date, phoneCallBackVO.getUuid()); phoneUtils.ttsPlayback(slienceText + nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); return; } Map<String, Object> map = redisCache.getCacheObject(phoneCallBackVO.getUuid()); IvrTaskSingle ivrTaskcall = (IvrTaskSingle) map.get("ivrTaskSingle"); List<IvrLibaTemplateScriptVO> ivrLibaTemplateScriptVOs = (List<IvrLibaTemplateScriptVO>) map.get("ivrLibaTemplateScriptVO"); //å°uuidæ´æ°å°æ°æ®åºä¸ ivrTaskcall.setSenduuid(phoneCallBackVO.getUuid()); ivrTaskSingleMapper.updateIvrTaskcall(ivrTaskcall); //è·å模æ¿ä¿¡æ¯ IvrLibaTemplateVO ivrLibaTemplateVO = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "ivrLibaTemplateVO"); //è¯é³è¯å«ç»æä¸æ¥æ¥å£: 3 Integer noVoice = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "noVoice"); QuestionMessage returnQues = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "returnQues"); //å°ä¼ åçç»ææ¾å°åå¤å¯¹è±¡ä¸ returnQues.setContent(phoneCallBackVO.getTextResult()); IvrLibaTemplateScriptVO nowQuestion = returnQues.getNowQuestion(); if (StringUtils.isEmpty(returnQues.getContent())) { //æ åè¯ //夿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()); return; } else { //æä¸ä¸é¢ 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 { redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", noVoice + 1, 120, TimeUnit.MINUTES); //è°ç¨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; } else { //isppdç¨æ¥è®°å½æ¯å¦å¹é å° Boolean isppd = false; //æåè¯ï¼å¯¹åççé®é¢,è¿è¡æ£åå¹é ï¼è¿éåªé坹鿩é¢ï¼å ¶å®é¢åä¸è¡ï¼ 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()); } } else { //isppdç¨æ¥è®°å½æ¯å¦å¹é å° Boolean isppd = false; //æåè¯ï¼å¯¹åççé®é¢,è¿è¡æ£åå¹é ï¼è¿éåªé坹鿩é¢ï¼å ¶å®é¢åä¸è¡ï¼ 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.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); 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); //å°æ£è çåç¾åè¿è¡¨é IvrTaskVisitResult ivrTaskVisitResult = DtoConversionUtils.sourceToTarget(ivrTaskcall, IvrTaskVisitResult.class); ivrTaskVisitResult.setId(null); ivrTaskVisitResult.setQuestion(nowQuestion.getQuestionText()); ivrTaskVisitResult.setPatientAnswer(phoneCallBackVO.getTextResult()); ivrTaskVisitResult.setCreateTime(new Date()); ivrTaskVisitResult.setOptionResult(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetvalue()); ivrTaskVisitResultMapper.insertIvrTaskVisitResult(ivrTaskVisitResult); //å°å¹é å°çæ è¯æ¹ætrue isppd = true; //è·åä¸ä¸é¢ 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); phoneUtils.ttsPlayback(script.getQuestionText(), phoneCallBackVO.getUuid()); 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 { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } phoneUtils.hangup("", "", ivrLibaTemplateVO.getRevisitAfter(), "", "", "", "", phoneCallBackVO.getUuid()); return; } } return; } else { //没æå¹é ä¸å½åoption //Targetregex2 为falseï¼è¡¨ç¤ºå¨Targetregex2ä¸åå¨ è¯å¥ä¸çå ³é®åï¼è¿ä¸ªoptionå°±ä¸ç¨åç»§ç»å¹é äºï¼ç´æ¥å¹é ä¸ä¸ä¸ªoption continue; } //ä¸å å« 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.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); ivrLibaScriptTargetoptionMapper.updateIvrLibaTemplateTargetoption(nowQuestion.getIvrLibaScriptTargetoptionList().get(j)); if (isppd != true) { //没æå¹é å° Integer mateNum = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "mateNum"); if (mateNum == null) mateNum = 0; //æ å¹é 次æ°å»å¤ææ¯å¦å°æå¤§è¯¢é®æ¬¡æ°ï¼å¹¶ä¸ææçé项é½å¹é å®äº if (mateNum == ivrLibaTemplateVO.getMateNum().intValue()) { //妿ä¸ä¸é¢ä¸ºç©º.åæ°çæ°æ®è¿å,å¹¶å ä¸æè°¢è¯ if (nowQuestion.getTargetid() < ivrLibaTemplateScriptVOs.size()) { //å°éé»ç½®ä¸º0 redisCache.setCacheObject(phoneCallBackVO.getUuid() + "noVoice", 0, 120, TimeUnit.MINUTES); redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", 0, 120, TimeUnit.MINUTES); //å°æ£è çåç¾åè¿è¡¨é IvrTaskVisitResult ivrTaskVisitResult = DtoConversionUtils.sourceToTarget(ivrTaskcall, IvrTaskVisitResult.class); ivrTaskVisitResult.setId(null); ivrTaskVisitResult.setQuestion(nowQuestion.getQuestionText()); ivrTaskVisitResult.setPatientAnswer(phoneCallBackVO.getTextResult()); ivrTaskVisitResult.setCreateTime(new Date()); ivrTaskVisitResult.setOptionResult(nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getTargetvalue()); ivrTaskVisitResultMapper.insertIvrTaskVisitResult(ivrTaskVisitResult); //å°å¹é å°çæ è¯æ¹ætrue isppd = true; //è·åä¸ä¸é¢ Integer nextQuestion = nowQuestion.getIvrLibaScriptTargetoptionList().get(j).getNextQuestion(); for (IvrLibaTemplateScriptVO script : ivrLibaTemplateScriptVOs) { if (script.getTargetid() == nextQuestion) { QuestionMessage questionMessage = new QuestionMessage(); IvrLibaTemplateScriptVO nextQuestion = getNextQuestion(ivrLibaTemplateScriptVOs, nowQuestion); questionMessage.setNowQuestion(script); questionMessage.setQuestionList(ivrLibaTemplateScriptVOs); 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()); phoneUtils.ttsPlayback(script.getQuestionText(), phoneCallBackVO.getUuid()); return; } else { //å°±å¯ä»¥ææçµè¯äº } else if (nextQuestion > ivrLibaTemplateScriptVOs.size()) { //没æä¸ä¸é¢äºï¼å°±ç»æäº String date = simpleDateFormat1.format(new Date()); log.info("å°±å¯ä»¥ææçµè¯äº------: {},uuid为ï¼{}", date, phoneCallBackVO.getUuid()); log.error("没æä¸ä¸é¢äºï¼å°±ç»æäº: {},uuid为ï¼{}", date, phoneCallBackVO.getUuid()); redisCache.setCacheObject(phoneCallBackVO.getUuid() + "hangup", 1, 120, TimeUnit.MINUTES); phoneUtils.ttsPlayback(ivrLibaTemplateVO.getRevisitAfter(), phoneCallBackVO.getUuid()); try { @@ -505,62 +453,102 @@ phoneUtils.hangup("", "", ivrLibaTemplateVO.getRevisitAfter(), "", "", "", "", phoneCallBackVO.getUuid()); return; } } else if (mateNum < ivrLibaTemplateVO.getMateNum().intValue()) { //没æé®å°è§å®æ¬¡æ° mateNum = mateNum + 1; redisCache.setCacheObject(phoneCallBackVO.getUuid() + "mateNum", mateNum, 120, TimeUnit.MINUTES); } return; } else { //没æå¹é ä¸å½åoption //Targetregex2 为falseï¼è¡¨ç¤ºå¨Targetregex2ä¸åå¨ è¯å¥ä¸çå ³é®åï¼è¿ä¸ªoptionå°±ä¸ç¨åç»§ç»å¹é äºï¼ç´æ¥å¹é ä¸ä¸ä¸ªoption continue; } //é项å¹é 宿åï¼éè¦åå»éè¿åºåè¿è¡å¹é 䏿¬¡ 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()); if (isppd != true) { //没æå¹é å° Integer mateNum = redisCache.getCacheObject(phoneCallBackVO.getUuid() + "mateNum"); if (mateNum == null) mateNum = 0; //æ å¹é 次æ°å»å¤ææ¯å¦å°æå¤§è¯¢é®æ¬¡æ°ï¼å¹¶ä¸ææçé项é½å¹é å®äº if (mateNum == ivrLibaTemplateVO.getMateNum().intValue()) { //妿ä¸ä¸é¢ä¸ºç©º.åæ°çæ°æ®è¿å,å¹¶å ä¸æè°¢è¯ 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); 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 { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } 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()); phoneUtils.hangup("", "", ivrLibaTemplateVO.getRevisitAfter(), "", "", "", "", phoneCallBackVO.getUuid()); return; } } else if (mateNum < ivrLibaTemplateVO.getMateNum().intValue()) { //没æé®å°è§å®æ¬¡æ° 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); 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âå°ç»æä¼ å String date = simpleDateFormat1.format(new Date()); log.info("è°ç¨â15ãttsåæåææ¾------: {},uuid为ï¼{}", date, phoneCallBackVO.getUuid()); phoneUtils.ttsPlayback(nowQuestion.getQuestionText() + ivrLibaTemplateScriptVO.getSubmoduleText(), phoneCallBackVO.getUuid()); redisCache.setCacheObject(phoneCallBackVO.getUuid() + "isOver", 1, 120, TimeUnit.MINUTES); } break; //è°ç¨â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()); } String date = simpleDateFormat1.format(new Date()); log.info("æåçä¿¡æ¯åå¤-: {},uuid为ï¼{}", date, phoneCallBackVO.getUuid()); phoneUtils.ttsPlayback(nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); break; } String date = simpleDateFormat1.format(new Date()); log.info("æåçä¿¡æ¯åå¤-: {},uuid为ï¼{}", date, phoneCallBackVO.getUuid()); phoneUtils.ttsPlayback(nowQuestion.getQuestionText(), phoneCallBackVO.getUuid()); } } }