From f243bb8af00a2464d16536d42150a4107f87b4ae Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期日, 12 五月 2024 21:32:57 +0800
Subject: [PATCH] 代码提交

---
 ruoyi-admin/src/main/java/com/ruoyi/web/component/RabbitMqReceiver.java |   96 ++++++++++++++++++++++++++++-------------------
 1 files changed, 57 insertions(+), 39 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/component/RabbitMqReceiver.java b/ruoyi-admin/src/main/java/com/ruoyi/web/component/RabbitMqReceiver.java
index 13df8de..db62ae9 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/component/RabbitMqReceiver.java
+++ b/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浣嗘槸鏈夊彲鑳借鍏跺畠鐨刢onsumer(闆嗙兢)鎺ユ敹鍒帮紝
-//             * 璁剧疆涓篺alse鏄彧琛ュ彂缁欏綋鍓嶇殑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(浠庨槦鍒椾腑鍒犻櫎)浜�   锛堣繖涓渶瑕佹牴鎹笟鍔″啀鍘诲鐞咥CK锛�
             channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
-
-            log.info("=============Do Something==============");
         } catch (Exception e) {
             log.error("============娑堣垂澶辫触,灏濊瘯娑堟伅琛ュ彂鍐嶆娑堣垂!==============");
             log.error(e.getMessage());
-            /**
-             * basicRecover鏂规硶鏄繘琛岃ˉ鍙戞搷浣滐紝
-             * 鍏朵腑鐨勫弬鏁板鏋滀负true鏄妸娑堟伅閫�鍥炲埌queue浣嗘槸鏈夊彲鑳借鍏跺畠鐨刢onsumer(闆嗙兢)鎺ユ敹鍒帮紝
-             * 璁剧疆涓篺alse鏄彧琛ュ彂缁欏綋鍓嶇殑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);
+            //鍒ゆ柇鎮h�呮槸鍚﹀凡缁忔帴鐢佃瘽
+            String str = redisCache.getCacheObject(ivrTaskcallMQ.getUuid() + "state_id");
+            System.out.println("-----------------" + str);
+            if (StringUtils.isNotEmpty(str) && str.equals("0")) {
+                //鎮h�呭凡缁忔帴鍚簡鐢佃瘽
+                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(浠庨槦鍒椾腑鍒犻櫎)浜�   锛堣繖涓渶瑕佹牴鎹笟鍔″啀鍘诲鐞咥CK锛�
+            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+        } catch (Exception e) {
+            log.error("============娑堣垂澶辫触,灏濊瘯娑堟伅琛ュ彂鍐嶆娑堣垂!==============");
+            log.error(e.getMessage());
+            channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
         }
     }
 

--
Gitblit v1.9.3