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 | 176 ++++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 115 insertions(+), 61 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 4208bc2..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,22 +2,26 @@
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.DateUtils;
+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.IvrTaskcall;
-import com.smartor.domain.IvrTaskcallMQ;
-import com.smartor.mapper.IvrTaskcallMapper;
+import com.smartor.common.SendService;
+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;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
-import org.springframework.amqp.rabbit.annotation.RabbitHandler;
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 java.io.IOException;
import java.util.List;
@@ -28,11 +32,18 @@
@Component//鐩戝惉姝ら槦鍒�
public class RabbitMqReceiver {
+
private static IIvrLibaTemplateService ivrLibaTemplateService;
- private static IvrTaskcallMapper ivrTaskcallMapper;
+ private static IvrTaskSingleMapper ivrTaskcallMapper;
+
+ private static IvrTaskMapper ivrTaskMapper;
+
+ private static SendService sendService;
private static RedisCache redisCache;
+
+ private static RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig;
// 鍒涘缓鍥哄畾澶у皬鐨勭嚎绋嬫睜
private static final ExecutorService executorService = Executors.newFixedThreadPool(10);
@@ -44,8 +55,23 @@
}
@Autowired
- public void setIvrTaskcallMapper(IvrTaskcallMapper ivrTaskcallMapper) {
+ public void setSendService(SendService sendService) {
+ RabbitMqReceiver.sendService = sendService;
+ }
+
+ @Autowired
+ public void setRabbitMqCallPhoneConfig(RabbitMqCallPhoneConfig rabbitMqCallPhoneConfig) {
+ RabbitMqReceiver.rabbitMqCallPhoneConfig = rabbitMqCallPhoneConfig;
+ }
+
+ @Autowired
+ public void setIvrTaskcallMapper(IvrTaskSingleMapper ivrTaskcallMapper) {
RabbitMqReceiver.ivrTaskcallMapper = ivrTaskcallMapper;
+ }
+
+ @Autowired
+ public void setIvrTaskMapper(IvrTaskMapper ivrTaskMapper) {
+ RabbitMqReceiver.ivrTaskMapper = ivrTaskMapper;
}
@Autowired
@@ -53,66 +79,94 @@
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 {
-// System.out.println(content);
-// IvrTaskcallMQ ivrTaskcallMQ = null;
-// ObjectMapper mapper = new ObjectMapper();
-// try {
-// 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�呬俊鎭�
-// IvrTaskcall ivrTaskcall = new IvrTaskcall();
-// ivrTaskcall.setTaskid(ivrTaskcallMQ.getTaskid());
-// List<IvrTaskcall> ivrTaskcalls = ivrTaskcallMapper.selectIvrTaskcallList(ivrTaskcall);
-//
-// for (IvrTaskcall ivrTaskcall1 : ivrTaskcalls) {
-// //閫氳繃澶氱嚎绋嬬殑鏂瑰紡鍘绘墦鐢佃瘽
-// executorService.submit(new PhoneTask(ivrTaskcall1, ivrLibaTemplateVO1, redisCache));
-// }
- //閫氱煡 MQ 娑堟伅宸茶鎺ユ敹,鍙互ACK(浠庨槦鍒椾腑鍒犻櫎)浜� 锛堣繖涓渶瑕佹牴鎹笟鍔″啀鍘诲鐞咥CK锛�
- channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
try {
- log.info("=============Do Something==============");
+ IvrTaskcallMQ ivrTaskcallMQ = null;
+
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ 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) {
+ 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, ivrLibaTemplateVO1, redisCache, rabbitMqCallPhoneConfig, message, sendService));
+ }
+ //閫氱煡 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();
+ factory.setConnectionFactory(connectionFactory);
+ factory.setMessageConverter(new Jackson2JsonMessageConverter());
+ return factory;
+ }
}
--
Gitblit v1.9.3