From 312f26c49124f355e9f78c6ddd69f71895aa73fc Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期一, 26 五月 2025 13:47:43 +0800 Subject: [PATCH] 修改公交公司的事件订阅功能 --- ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/Artemis.java | 70 ++++++++++++++--------------------- 1 files changed, 28 insertions(+), 42 deletions(-) diff --git a/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/Artemis.java b/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/Artemis.java index b9fd822..d8614a1 100644 --- a/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/Artemis.java +++ b/ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/Artemis.java @@ -8,6 +8,7 @@ import com.ruoyi.dataInterchange.util.haikang.model.EventSubscriptionByEventTypesRequest; import com.ruoyi.dataInterchange.util.haikang.model.EventSubscriptionViewRequest; import com.ruoyi.dataInterchange.util.haikang.model.EventUnSubscriptionByEventTypesRequest; +import com.ruoyi.dataInterchange.util.haikang.model.GetTopicInfoRequest; import lombok.extern.slf4j.Slf4j; import javax.servlet.ServletContextEvent; @@ -24,8 +25,7 @@ * @Date 2025/5/20 16:17 */ @Slf4j -@WebListener -public class Artemis implements ServletContextListener { +public class Artemis { /** * STEP2:设置OpenAPI接口的上下文 @@ -52,46 +52,32 @@ String result =ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json"); return result; } + + + //按事件类型获取事件订阅信息 + public static String getTopicInfo(GetTopicInfoRequest getTopicInfoRequest)throws Exception { + String getTopicInfoDataApi = ARTEMIS_PATH +"/api/common/v1/event/getTopicInfo"; + Map<String,String> path = new HashMap<String,String>(2){ + { + put("https://",getTopicInfoDataApi); + } + }; + String body=JSON.toJSONString(getTopicInfoRequest); + String result =ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json"); + return result; + } + - @Override - public void contextInitialized(ServletContextEvent sce) { + public static void run() { try { //先查询是否订阅事件 - EventSubscriptionViewRequest eventSubscriptionViewRequest = new EventSubscriptionViewRequest(); - eventSubscriptionViewRequest.setSubWay(1); - String eventSubscriptionView = Artemis.eventSubscriptionView(eventSubscriptionViewRequest); + GetTopicInfoRequest getTopicInfoRequest = new GetTopicInfoRequest(); + getTopicInfoRequest.setEventTypes(new ArrayList<Long>(){{ + add(5201154049L); + add(5201301505L); + }}); + String eventSubscriptionView = Artemis.getTopicInfo(getTopicInfoRequest); JSONObject jsonObject = JSON.parseObject(eventSubscriptionView); - String code = jsonObject.getString("code"); - if("200".equals(code)){ - JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("detail"); - List<String> list = new ArrayList<>(); - for (int i = 0; i < jsonArray.size(); i++) { - JSONArray eventTypes = jsonArray.getJSONObject(i).getJSONArray("eventTypes"); - eventTypes.forEach(eventType -> { - list.add(eventType.toString()); - }); - } - //告警事件类型 - if(!list.contains("5201154049")){ - //订阅事件 - EventSubscriptionByEventTypesRequest eventSubscriptionByEventTypesRequest = new EventSubscriptionByEventTypesRequest(); - eventSubscriptionByEventTypesRequest.setSubWay(1); - eventSubscriptionByEventTypesRequest.setEventDest("http://221.182.45.100:1000/dataInterchange/warnMsgAdptInfo/alarmNotice"); - eventSubscriptionByEventTypesRequest.setEventTypes(new ArrayList<String>(){{ - add("5201154049"); - }}); - String subscription = Artemis.eventSubscriptionByEventTypes(eventSubscriptionByEventTypesRequest); - jsonObject = JSON.parseObject(subscription); - code = jsonObject.getString("code"); - if(!"200".equals(code)){ - log.error("告警事件订阅失败"); - }else { - log.info("告警事件订阅成功"); - } - } - }else{ - log.error("查询事件订阅信息失败"); - } }catch (Exception e){ e.printStackTrace(); } @@ -122,9 +108,9 @@ String result = ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json"); return result; } - - @Override - public void contextDestroyed(ServletContextEvent sce) { - + + + public static void main(String[] args) { + Artemis.run(); } } -- Gitblit v1.7.1