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 | 86 ++++++++++++++++++++++++++++++------------- 1 files changed, 60 insertions(+), 26 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 db62ae9..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 @@ -4,15 +4,17 @@ 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.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; @@ -20,6 +22,7 @@ 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; @@ -32,8 +35,10 @@ @Component//鐩戝惉姝ら槦鍒� public class RabbitMqReceiver { + @Value("${phonePath}") + private String phonePath; - private static IIvrLibaTemplateService ivrLibaTemplateService; + private static IIvrTaskTemplateService ivrTaskTemplateService; private static IvrTaskSingleMapper ivrTaskcallMapper; @@ -45,13 +50,19 @@ 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 @@ -80,11 +91,12 @@ } /** - * 鐢佃瘽闅忚 + * 浠诲姟闅忚 * concurrency = "50" 骞跺彂鏁颁负50 */ - @RabbitListener(queues = "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; @@ -98,32 +110,53 @@ } 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)); + //鍒ゆ柇涓�涓媔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); + + 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()); channel.basicReject(message.getMessageProperties().getDeliveryTag(), true); } + } /** @@ -162,6 +195,7 @@ } } + @Bean public SimpleRabbitListenerContainerFactory jsonContainerFactory(ConnectionFactory connectionFactory) { SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); -- Gitblit v1.9.3