From bedd0a1cef215538df64470df6b8d4a022189136 Mon Sep 17 00:00:00 2001 From: liusheng <337615773@qq.com> Date: 星期三, 28 八月 2024 14:05:16 +0800 Subject: [PATCH] 代码提交 --- ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java | 206 +++++++++++++++++++++++++++++++-------------------- 1 files changed, 126 insertions(+), 80 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java b/ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java index d5e72b6..f2fedf4 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/component/RedisMqReceiver.java @@ -14,9 +14,7 @@ import com.smartor.mapper.ServiceTaskMapper; import com.smartor.mapper.SvyTaskMapper; import com.smartor.mapper.SvyTaskSingleMapper; -import com.smartor.service.IIvrTaskTemplateService; -import com.smartor.service.IServiceSubtaskRecordService; -import com.smartor.service.ISvyTaskTemplateService; +import com.smartor.service.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -40,20 +38,29 @@ @Value("${pub_key}") private String pub_key; + @Value("${localIP}") + private String localIP; + @Value("${req_path}") private String req_path; - private static IIvrTaskTemplateService ivrTaskTemplateService; + @Autowired + private IIvrTaskTemplateService ivrTaskTemplateService; - private static ServiceSubtaskMapper ivrTaskcallMapper; + @Autowired + private ServiceSubtaskMapper ivrTaskcallMapper; - private static ServiceTaskMapper ivrTaskMapper; + @Autowired + private ServiceTaskMapper ivrTaskMapper; - private static SendService sendService; + @Autowired + private SendService sendService; - private static RedisCache redisCache; + @Autowired + private RedisCache redisCache; - private static RobotPhoneUtils robotPhoneUtils; + @Autowired + private RobotPhoneUtils robotPhoneUtils; @Autowired private SvyTaskMapper svyTaskMapper; @@ -67,6 +74,9 @@ @Autowired private IServiceSubtaskRecordService serviceSubtaskRecordService; + @Autowired + IBaseSmsaccountService baseSmsaccountService; + // 鍒涘缓鍥哄畾澶у皬鐨勭嚎绋嬫睜 private static final ExecutorService executorService = Executors.newFixedThreadPool(10); @@ -74,40 +84,11 @@ super(listenerContainer); } - - @Autowired - public void setIIvrTaskTemplateService(IIvrTaskTemplateService ivrTaskTemplateService) { - RedisMqReceiver.ivrTaskTemplateService = ivrTaskTemplateService; - } - - @Autowired - public void setRobotPhoneUtilsService(RobotPhoneUtils robotPhoneUtils) { - RedisMqReceiver.robotPhoneUtils = robotPhoneUtils; - } - - @Autowired - public void setSendService(SendService sendService) { - RedisMqReceiver.sendService = sendService; - } - - @Autowired - public void setIvrTaskcallMapper(ServiceSubtaskMapper ivrTaskcallMapper) { - RedisMqReceiver.ivrTaskcallMapper = ivrTaskcallMapper; - } - - @Autowired - public void setIvrTaskMapper(ServiceTaskMapper ivrTaskMapper) { - RedisMqReceiver.ivrTaskMapper = ivrTaskMapper; - } - - @Autowired - public void setRedisCache(RedisCache redisCache) { - RedisMqReceiver.redisCache = redisCache; - } - @Override public void onMessage(Message message, byte[] pattern) { log.info("鐩戝惉Redis key杩囨湡锛宬ey锛歿}锛宑hannel锛歿}", message.toString(), new String(pattern)); + String ip = localIP; + log.error("鏈満鐨勭綉缁淚P涓�:{}", ip); String content = message.toString(); //鍒ゆ柇鏄笉鏄换鍔′俊鎭紝濡傛灉涓嶆槸锛岀洿鎺ヨ繑鍥烇紝涓嶉渶瑕佹墽琛� if (!content.contains("taskid")) { @@ -125,14 +106,16 @@ if (commonTaskcallMQ.getTaskType() == 1) { //闅忚 - sfHandle((commonTaskcallMQ)); + sfHandle(commonTaskcallMQ, ip); } else if (commonTaskcallMQ.getTaskType() == 2) { //闂嵎 - wjHandle(commonTaskcallMQ); + wjHandle(commonTaskcallMQ, ip); } else if (commonTaskcallMQ.getTaskType() == 3) { //瀹f暀 + xjHandle(commonTaskcallMQ, ip); } - + //澶勭悊瀹屾垚锛岀Щ闄edis + redisCache.deleteObject(message.toString()); } catch (Exception e) { Integer integer = redisCache.getCacheObject(commonTaskcallMQ.getTaskid().toString()); @@ -147,7 +130,6 @@ log.error("============娑堣垂澶辫触,灏濊瘯娑堟伅琛ュ彂鍐嶆娑堣垂!============== {}", e.getMessage()); redisCache.setCacheObject(message.toString(), message.toString(), 60, TimeUnit.SECONDS); } - } /** @@ -155,7 +137,7 @@ * * @param commonTaskcallMQ */ - private void sfHandle(CommonTaskcallMQ commonTaskcallMQ) { + public void sfHandle(CommonTaskcallMQ commonTaskcallMQ, String ip) { //鍒ゆ柇涓�涓媍ommonTaskcallMQ涓殑stopstate鏄惁涓巌vr_task涓殑涓�鑷达紝涓嶄竴鑷达紝鍒欒鏄庢槸鏆傚仠浜� ServiceTask ivrTask1 = ivrTaskMapper.selectServiceTaskByTaskid(commonTaskcallMQ.getTaskid()); if (ivrTask1.getStopState() != commonTaskcallMQ.getStopState()) { @@ -171,39 +153,72 @@ String descByCode = ServiceFromEnum.getDescByCode(Integer.valueOf(serviceFrom)); //杩欓噷鍙互鑰冭檻鐢ㄧ瓥鐣ユā寮忎紭鍖栦竴涓嬶紝涓嶇劧澶毦鐪嬩簡 - //閫氳繃妯℃澘ID鑾峰彇妯℃澘闂 - IvrTaskTemplateVO ivrTaskTemplateVO = new IvrTaskTemplateVO(); - ivrTaskTemplateVO.setID(Long.valueOf(commonTaskcallMQ.getTemplateid())); - IvrTaskTemplateVO ivrTaskTemplateVO1 = ivrTaskTemplateService.selectInfoByCondition(ivrTaskTemplateVO); +// //閫氳繃妯℃澘ID鑾峰彇妯℃澘闂 +// IvrTaskTemplateVO ivrTaskTemplateVO = new IvrTaskTemplateVO(); +// ivrTaskTemplateVO.setId(Long.valueOf(commonTaskcallMQ.getTemplateid())); +// IvrTaskTemplateVO ivrTaskTemplateVO1 = ivrTaskTemplateService.selectInfoByCondition(ivrTaskTemplateVO); //閫氳繃浠诲姟ID鎷垮埌鎮h�呬俊鎭� ServiceSubtask ivrTaskcall = new ServiceSubtask(); ivrTaskcall.setTaskid(commonTaskcallMQ.getTaskid()); - List<ServiceSubtask> ivrTaskcalls = ivrTaskcallMapper.selectServiceSubtaskList(ivrTaskcall); + List<ServiceSubtask> selectServiceSubtaskList = ivrTaskcallMapper.selectServiceSubtaskList(ivrTaskcall); if (descByCode.equals("鐢佃瘽")) { - for (ServiceSubtask ivrTaskcall1 : ivrTaskcalls) { - ServiceTask ivrTask = ivrTaskMapper.selectServiceTaskByTaskid(ivrTaskcall1.getTaskid()); + for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { + ServiceTask ivrTask = ivrTaskMapper.selectServiceTaskByTaskid(serviceSubtask.getTaskid()); if (ivrTask.getSendState() != null && ivrTask.getSendState() == 3 || ivrTask.getSendState() != null && ivrTask.getSendState() == 4) { //濡備綍浠诲姟琚�滄殏鍋溾�濇垨鈥滅粓姝⑩�� break; } + //鑾峰彇鍒皏alue鍊兼渶灏戠殑key + String key = getKey(); + if (commonTaskcallMQ.getSendType().equals("2")) { + //璇存槑鏄珛鍗冲彂閫� + String value = redisCache.getCacheObject("cache-0"); + ServiceSubtask serviceSubtask1 = new ServiceSubtask(); + serviceSubtask1.setTaskid(commonTaskcallMQ.getTaskid()); + List<ServiceSubtask> selectServiceSubtaskList1 = ivrTaskcallMapper.selectServiceSubtaskList(serviceSubtask1); + for (ServiceSubtask serviceSubtask2 : selectServiceSubtaskList1) { + if (StringUtils.isEmpty(value)) { + value = "," + serviceSubtask2.getId().toString() + ","; + } else { + value = value + "," + serviceSubtask2.getId().toString() + ","; + } + } + redisCache.setCacheObject("cache-0", value); + } else { + //闈炵珛鍗冲彂閫� + String value = redisCache.getCacheObject(key); + ServiceSubtask serviceSubtask1 = new ServiceSubtask(); + serviceSubtask1.setTaskid(commonTaskcallMQ.getTaskid()); + List<ServiceSubtask> selectServiceSubtaskList1 = ivrTaskcallMapper.selectServiceSubtaskList(serviceSubtask1); + for (ServiceSubtask serviceSubtask2 : selectServiceSubtaskList1) { + if (StringUtils.isEmpty(value)) { + value = "," + serviceSubtask2.getId().toString() + ","; + } else { + value = value + "," + serviceSubtask2.getId().toString() + ","; + } + } + redisCache.setCacheObject(key, value); + } //浠诲姟鍙戦�佽褰曪紙杩欎釜浠g爜搴旇鍐欏湪phoneTask涓紝鍏堝啓鍦ㄨ繖锛屽悗闈㈠啀鏀癸級 ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); - serviceSubtaskRecord.setTaskid(ivrTaskcall1.getTaskid().toString()); + serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); - serviceSubtaskRecord.setTasktype(ivrTaskcall1.getType()); + serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); serviceSubtaskRecord.setPreachform("3"); serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); serviceSubtaskRecordService.insertServiceSubtaskRecord(serviceSubtaskRecord); - //閫氳繃澶氱嚎绋嬬殑鏂瑰紡鍘绘墦鐢佃瘽 - executorService.submit(new PhoneTask(ivrTaskcall1, ivrTaskTemplateVO1, redisCache, sendService, phonePath, robotPhoneUtils)); +// //閫氳繃澶氱嚎绋嬬殑鏂瑰紡鍘绘墦鐢佃瘽 +// executorService.submit(new PhoneTask(serviceSubtask, ivrTaskTemplateVO1, redisCache, sendService, phonePath, robotPhoneUtils)); } } else if (descByCode.equals("澶氬獟浣�")) { //澶氬獟浣� + return; } else if (descByCode.equals("绾歌川")) { //绾歌川 + return; } else if (descByCode.equals("鐭俊")) { //鐭俊 // http://localhost:8099/followvisit/particty?param1=3¶m2=348 @@ -211,19 +226,19 @@ RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); String taskId = rsaPublicKeyExample.encryptedData(ivrTask1.getTaskid().toString(), pub_key); - - for (ServiceSubtask ivrTaskSingle : ivrTaskcalls) { - String patid = rsaPublicKeyExample.encryptedData(ivrTaskSingle.getPatid().toString(), pub_key); + for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { + String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key); SendMagParam sendMagParam = new SendMagParam(); sendMagParam.setType("4"); - sendMagParam.setUrl(req_path + "/followvisit/particty?param1=" + taskId + "¶m2=" + patid); + sendMagParam.setUrl(ip + ":" + req_path + "/followvisit/particty?param1=" + taskId + "¶m2=" + patid + "¶m5=false"); Boolean aBoolean = sendService.sendMsg(sendMagParam); + //浠诲姟鍙戦�佽褰� ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); - serviceSubtaskRecord.setTaskid(ivrTaskSingle.getTaskid().toString()); + serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); - serviceSubtaskRecord.setTasktype(ivrTaskSingle.getType()); + serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); serviceSubtaskRecord.setPreachform("4"); serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); serviceSubtaskRecord.setResult(aBoolean == true ? "鎴愬姛" : "澶辫触"); @@ -233,24 +248,25 @@ //鍏紬鍙� RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample(); String taskId = rsaPublicKeyExample.encryptedData(ivrTask1.getTaskid().toString(), pub_key); - for (ServiceSubtask ivrTaskSingle : ivrTaskcalls) { - String patid = rsaPublicKeyExample.encryptedData(ivrTaskSingle.getPatid().toString(), pub_key); + for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) { + String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key); SendMagParam sendMagParam = new SendMagParam(); sendMagParam.setType("5"); - sendMagParam.setUrl(req_path + "/outsideChain?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName()); - log.info("閾炬帴瀹屾暣璺緞锛歿}", req_path + "/outsideChain?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName()); + sendMagParam.setUrl(ip + ":" + req_path + "/outsideChain?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName() + "¶m5=false"); + log.info("閾炬帴瀹屾暣璺緞锛歿}", ip + ":" + req_path + "/outsideChain?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName() + "¶m5=false"); //杩欎釜妯℃澘ID鍏堝啓姝伙紝鍚庨潰鍋氭垚鍙�� sendMagParam.setTmpCode("oG3pJHPVWpE81DmZsua_2tKwgJ97r0qz37z56ns7NB4"); Map map = new HashMap(); map.put("first", ivrTask1.getTaskName()); sendMagParam.setContent(JSON.toJSONString(map)); + sendMagParam.setOpenid(serviceSubtask.getOpenid()); Boolean aBoolean = sendService.sendMsg(sendMagParam); //浠诲姟鍙戦�佽褰� ServiceSubtaskRecord serviceSubtaskRecord = new ServiceSubtaskRecord(); - serviceSubtaskRecord.setTaskid(ivrTaskSingle.getTaskid().toString()); + serviceSubtaskRecord.setTaskid(serviceSubtask.getTaskid().toString()); serviceSubtaskRecord.setUuid(UUID.randomUUID().toString()); - serviceSubtaskRecord.setTasktype(ivrTaskSingle.getType()); + serviceSubtaskRecord.setTasktype(serviceSubtask.getType()); serviceSubtaskRecord.setPreachform("4"); serviceSubtaskRecord.setStartTime(System.currentTimeMillis()); serviceSubtaskRecord.setResult(aBoolean == true ? "鎴愬姛" : "澶辫触"); @@ -267,7 +283,7 @@ * * @param commonTaskcallMQ */ - private void xjHandle(CommonTaskcallMQ commonTaskcallMQ) { + private void xjHandle(CommonTaskcallMQ commonTaskcallMQ, String ip) { //鍒ゆ柇涓�涓媍ommonTaskcallMQ涓殑stopstate鏄惁涓巌vr_task涓殑涓�鑷达紝涓嶄竴鑷达紝鍒欒鏄庢槸鏆傚仠浜� ServiceTask ivrTask1 = ivrTaskMapper.selectServiceTaskByTaskid(commonTaskcallMQ.getTaskid()); if (ivrTask1.getStopState() != commonTaskcallMQ.getStopState()) { @@ -284,10 +300,12 @@ //杩欓噷鍙互鑰冭檻鐢ㄧ瓥鐣ユā寮忎紭鍖栦竴涓嬶紝涓嶇劧澶毦鐪嬩簡 //閫氳繃妯℃澘ID鑾峰彇妯℃澘闂 - IvrTaskTemplateVO ivrTaskTemplateVO = new IvrTaskTemplateVO(); - ivrTaskTemplateVO.setID(Long.valueOf(commonTaskcallMQ.getTemplateid())); - IvrTaskTemplateVO ivrTaskTemplateVO1 = ivrTaskTemplateService.selectInfoByCondition(ivrTaskTemplateVO); - + IvrTaskTemplateVO ivrTaskTemplateVO1 = null; + if (commonTaskcallMQ.getTaskType().equals("1")) { + IvrTaskTemplateVO ivrTaskTemplateVO = new IvrTaskTemplateVO(); + ivrTaskTemplateVO.setId(Long.valueOf(commonTaskcallMQ.getTemplateid())); + ivrTaskTemplateVO1 = ivrTaskTemplateService.selectInfoByCondition(ivrTaskTemplateVO); + } //閫氳繃浠诲姟ID鎷垮埌鎮h�呬俊鎭� ServiceSubtask ivrTaskcall = new ServiceSubtask(); ivrTaskcall.setTaskid(commonTaskcallMQ.getTaskid()); @@ -328,7 +346,7 @@ String patid = rsaPublicKeyExample.encryptedData(ivrTaskSingle.getPatid().toString(), pub_key); SendMagParam sendMagParam = new SendMagParam(); sendMagParam.setType("4"); - sendMagParam.setUrl(req_path + "/followvisit/particty?param1=" + taskId + "¶m2=" + patid); + sendMagParam.setUrl(ip + ":" + req_path + "/followvisit/particty?param1=" + taskId + "¶m2=" + patid + "¶m5=false"); Boolean aBoolean = sendService.sendMsg(sendMagParam); //浠诲姟鍙戦�佽褰� @@ -349,13 +367,14 @@ String patid = rsaPublicKeyExample.encryptedData(ivrTaskSingle.getPatid().toString(), pub_key); SendMagParam sendMagParam = new SendMagParam(); sendMagParam.setType("5"); - sendMagParam.setUrl(req_path + "/outsideChain?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName()); - log.info("閾炬帴瀹屾暣璺緞锛歿}", req_path + "/outsideChain?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName()); + sendMagParam.setUrl(ip + ":" + req_path + "/outsideChainxj?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName() + "¶m5=false"); + log.info("閾炬帴瀹屾暣璺緞锛歿}", req_path + "/outsideChainxj?param1=" + taskId + "¶m2=" + patid + "¶m3=" + ivrTask1.getTaskName() + "¶m5=false"); //杩欎釜妯℃澘ID鍏堝啓姝伙紝鍚庨潰鍋氭垚鍙�� sendMagParam.setTmpCode("oG3pJHPVWpE81DmZsua_2tKwgJ97r0qz37z56ns7NB4"); Map map = new HashMap(); map.put("first", ivrTask1.getTaskName()); sendMagParam.setContent(JSON.toJSONString(map)); + sendMagParam.setOpenid(ivrTaskSingle.getOpenid()); Boolean aBoolean = sendService.sendMsg(sendMagParam); //浠诲姟鍙戦�佽褰� @@ -379,7 +398,7 @@ * * @param commonTaskcallMQ */ - private void wjHandle(CommonTaskcallMQ commonTaskcallMQ) { + private void wjHandle(CommonTaskcallMQ commonTaskcallMQ, String ip) { //鍒ゆ柇涓�涓媍ommonTaskcallMQ涓殑stopstate鏄惁涓巌vr_task涓殑涓�鑷达紝涓嶄竴鑷达紝鍒欒鏄庢槸鏆傚仠浜� SvyTask svyTask = svyTaskMapper.selectSvyTaskByTaskid(commonTaskcallMQ.getTaskid()); if (svyTask.getStopState() != commonTaskcallMQ.getStopState()) { @@ -437,8 +456,8 @@ String patid = rsaPublicKeyExample.encryptedData(svyTaskSingle1.getPatid().toString(), pub_key); SendMagParam sendMagParam = new SendMagParam(); sendMagParam.setType("5"); - sendMagParam.setUrl(req_path + "/outsideChain?param1=" + taskId + "¶m2=" + patid + "¶m3=" + svyTask.getTaskName()); - log.info("閾炬帴瀹屾暣璺緞锛歿}", req_path + "/outsideChain?param1=" + taskId + "¶m2=" + patid + "¶m3=" + svyTask.getTaskName()); + sendMagParam.setUrl(ip + ":" + req_path + "//outsideChainwt?param1=" + taskId + "¶m2=" + patid + "¶m3=" + svyTask.getTaskName() + "¶m5=false"); + log.info("閾炬帴瀹屾暣璺緞锛歿}", req_path + "//outsideChainwt?param1=" + taskId + "¶m2=" + patid + "¶m3=" + svyTask.getTaskName() + "¶m5=false"); //杩欎釜妯℃澘ID鍏堝啓姝伙紝鍚庨潰鍋氭垚鍙�� sendMagParam.setTmpCode("oG3pJHPVWpE81DmZsua_2tKwgJ97r0qz37z56ns7NB4"); Map map = new HashMap(); @@ -463,7 +482,7 @@ } -// /** + // /** // * 鏈哄櫒浜虹涓�鍙ヨ瘽璇煶 // * concurrency = "50" 骞跺彂鏁颁负50 // */ @@ -498,5 +517,32 @@ // channel.basicReject(message.getMessageProperties().getDeliveryTag(), true); // } // } + private String getKey() { + Map<String, String> map = new HashMap<>(); + for (int i = 0; i < 6; i++) { + Boolean aBoolean = redisCache.hasKey("cache-" + i); + if (!aBoolean) { + redisCache.setCacheObject("cache-" + i, ""); + map.put("cache-" + i, ""); + } else { + map.put("cache-" + i, redisCache.getCacheObject("cache-" + i)); + } + } + + String key = null; + String value = ""; + for (Map.Entry<String, String> entry : map.entrySet()) { + if (StringUtils.isEmpty(value)) { + value = entry.getValue(); + key = entry.getKey(); + } else { + if (entry.getValue().split(",").length < value.split(",").length) { + value = entry.getValue(); + key = entry.getKey(); + } + } + } + return key; + } } -- Gitblit v1.9.3