From 500130efe30180fe635ba4482e097e848d37c7e3 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期二, 28 五月 2024 09:42:39 +0800
Subject: [PATCH] 代码提交

---
 ruoyi-admin/src/main/java/com/ruoyi/web/component/RabbitMqReceiver.java |  185 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 131 insertions(+), 54 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 fa8a7ec..61396f7 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,24 +2,29 @@
 
 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.enums.ServiceFromEnum;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.web.task.PhoneTask;
-import com.smartor.config.RabbitMqConfig;
-import com.smartor.domain.IvrLibaTemplateVO;
-import com.smartor.domain.IvrTaskSingle;
-import com.smartor.domain.IvrTaskcallMQ;
+import com.smartor.common.SendService;
+import com.smartor.config.PhoneUtils;
+import com.smartor.config.RabbitMqCallPhoneConfig;
+import com.smartor.config.RobotPhoneUtils;
+import com.smartor.domain.*;
+import com.smartor.mapper.IvrTaskMapper;
 import com.smartor.mapper.IvrTaskSingleMapper;
-import com.smartor.service.IIvrLibaTemplateService;
+import com.smartor.service.IIvrTaskTemplateService;
 import lombok.extern.slf4j.Slf4j;
 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.beans.factory.annotation.Value;
 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;
@@ -30,19 +35,44 @@
 @Component//鐩戝惉姝ら槦鍒�
 public class RabbitMqReceiver {
 
-    private static IIvrLibaTemplateService ivrLibaTemplateService;
+    @Value("${phonePath}")
+    private String phonePath;
+
+    private static IIvrTaskTemplateService ivrTaskTemplateService;
 
     private static IvrTaskSingleMapper ivrTaskcallMapper;
 
+    private static IvrTaskMapper ivrTaskMapper;
+
+    private static SendService sendService;
+
     private static RedisCache redisCache;
+
+    private static RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig;
+
+    private static RobotPhoneUtils robotPhoneUtils;
 
     // 鍒涘缓鍥哄畾澶у皬鐨勭嚎绋嬫睜
     private static final ExecutorService executorService = Executors.newFixedThreadPool(10);
 
+    @Autowired
+    public void setIIvrTaskTemplateService(IIvrTaskTemplateService ivrTaskTemplateService) {
+        RabbitMqReceiver.ivrTaskTemplateService = ivrTaskTemplateService;
+    }
 
     @Autowired
-    public void setIIvrLibaTemplateService(IIvrLibaTemplateService ivrLibaTemplateService) {
-        RabbitMqReceiver.ivrLibaTemplateService = ivrLibaTemplateService;
+    public void setRobotPhoneUtilsService(RobotPhoneUtils robotPhoneUtils) {
+        RabbitMqReceiver.robotPhoneUtils = robotPhoneUtils;
+    }
+
+    @Autowired
+    public void setSendService(SendService sendService) {
+        RabbitMqReceiver.sendService = sendService;
+    }
+
+    @Autowired
+    public void setRabbitMqCallPhoneConfig(RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig) {
+        RabbitMqReceiver.rabbitMqCallPhoneConfig = rabbitMqCallPhoneConfig;
     }
 
     @Autowired
@@ -51,74 +81,121 @@
     }
 
     @Autowired
+    public void setIvrTaskMapper(IvrTaskMapper ivrTaskMapper) {
+        RabbitMqReceiver.ivrTaskMapper = ivrTaskMapper;
+    }
+
+    @Autowired
     public void setRedisCache(RedisCache redisCache) {
         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 = "task_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();
             }
-            //閫氳繃妯℃澘ID鑾峰彇妯℃澘闂
-            IvrLibaTemplateVO ivrLibaTemplateVO = new IvrLibaTemplateVO();
-            ivrLibaTemplateVO.setID(Long.valueOf(ivrTaskcallMQ.getTemplateid()));
-            IvrLibaTemplateVO ivrLibaTemplateVO1 = ivrLibaTemplateService.selectInfoByCondition(ivrLibaTemplateVO);
-
-            //閫氳繃浠诲姟ID鎷垮埌鎮h�呬俊鎭�
-            IvrTaskSingle ivrTaskcall = new IvrTaskSingle();
-            ivrTaskcall.setTaskid(ivrTaskcallMQ.getTaskid());
-            List<IvrTaskSingle> ivrTaskcalls = ivrTaskcallMapper.selectIvrTaskcallList(ivrTaskcall);
-
-            for (IvrTaskSingle ivrTaskcall1 : ivrTaskcalls) {
-                //閫氳繃澶氱嚎绋嬬殑鏂瑰紡鍘绘墦鐢佃瘽
-                executorService.submit(new PhoneTask(ivrTaskcall1, ivrLibaTemplateVO1, redisCache, channel, message));
+            //鍒ゆ柇涓�涓媔vrTaskcallMQ涓殑stopstate鏄惁涓巌vr_task涓殑涓�鑷达紝涓嶄竴鑷达紝鍒欒鏄庢槸鏆傚仠浜�
+            IvrTask ivrTask1 = ivrTaskMapper.selectIvrTaskByTaskid(ivrTaskcallMQ.getTaskid());
+            if (ivrTask1.getStopState() != ivrTaskcallMQ.getStopState()) {
+                //灏嗘秷鎭粠闃熷垪涓墧闄�
+                channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+                return;
             }
-            //閫氱煡 MQ 娑堟伅宸茶鎺ユ敹,鍙互ACK(浠庨槦鍒椾腑鍒犻櫎)浜�   锛堣繖涓渶瑕佹牴鎹笟鍔″啀鍘诲鐞咥CK锛�
-            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
 
-            log.info("=============Do Something==============");
+            if (StringUtils.isNotEmpty(ivrTaskcallMQ.getServicefrom())) {
+                //濡備綍浠诲姟鍙戦�佹柟寮忎笉涓虹┖
+                String[] split = ivrTaskcallMQ.getServicefrom().split(",");
+                for (String serviceFrom : split) {
+                    String descByCode = ServiceFromEnum.getDescByCode(Integer.valueOf(serviceFrom));
+                    //杩欓噷鍙互鑰冭檻鐢ㄧ瓥鐣ユā寮忎紭鍖栦竴涓嬶紝涓嶇劧澶毦鐪嬩簡
+                    if (descByCode.equals("鐢佃瘽")) {
+                        //閫氳繃妯℃澘ID鑾峰彇妯℃澘闂
+                        IvrTaskTemplateVO ivrTaskTemplateVO = new IvrTaskTemplateVO();
+                        ivrTaskTemplateVO.setID(Long.valueOf(ivrTaskcallMQ.getTemplateid()));
+                        IvrTaskTemplateVO ivrTaskTemplateVO1 = ivrTaskTemplateService.selectInfoByCondition(ivrTaskTemplateVO);
+
+                        //閫氳繃浠诲姟ID鎷垮埌鎮h�呬俊鎭�
+                        IvrTaskSingle ivrTaskcall = new IvrTaskSingle();
+                        ivrTaskcall.setTaskid(ivrTaskcallMQ.getTaskid());
+                        List<IvrTaskSingle> ivrTaskcalls = ivrTaskcallMapper.selectIvrTaskcallList(ivrTaskcall);
+
+                        for (IvrTaskSingle ivrTaskcall1 : ivrTaskcalls) {
+                            IvrTask ivrTask = ivrTaskMapper.selectIvrTaskByTaskid(ivrTaskcall1.getTaskid());
+                            if (StringUtils.isNotEmpty(ivrTask.getSendState()) && ivrTask.getSendState().equals(3) || StringUtils.isNotEmpty(ivrTask.getSendState()) && ivrTask.getSendState().equals(4)) {
+                                //濡備綍浠诲姟琚�滄殏鍋溾�濇垨鈥滅粓姝⑩��
+                                break;
+                            }
+                            //閫氳繃澶氱嚎绋嬬殑鏂瑰紡鍘绘墦鐢佃瘽
+                            executorService.submit(new PhoneTask(ivrTaskcall1, ivrTaskTemplateVO1, redisCache, rabbitMqCallPhoneConfig, message, sendService, phonePath, robotPhoneUtils));
+                        }
+                    } else if (descByCode.equals("鍏紬鍙�")) {
+
+                    }
+                    //閫氱煡 MQ 娑堟伅宸茶鎺ユ敹,鍙互ACK(浠庨槦鍒椾腑鍒犻櫎)浜�   锛堣繖涓渶瑕佹牴鎹笟鍔″啀鍘诲鐞咥CK锛�
+                    channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+                }
+            }
         } 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);
         }
     }
 
+
     @Bean
     public SimpleRabbitListenerContainerFactory jsonContainerFactory(ConnectionFactory connectionFactory) {
         SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();

--
Gitblit v1.9.3