昨天 | Pu Zhibing | ![]() |
昨天 | Pu Zhibing | ![]() |
ruoyi-service/ruoyi-dataInterchange/lib/artemis-http-client-1.1.13.RELEASE.jarBinary files differ
ruoyi-service/ruoyi-dataInterchange/pom.xml
@@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>com.ruoyi</groupId> @@ -118,6 +118,12 @@ <groupId>com.ruoyi</groupId> <artifactId>ruoyi-api-dataInterchange</artifactId> </dependency> <dependency> <groupId>com.hikvision.ga</groupId> <artifactId>artemis-http-client</artifactId> <version>1.1.13.RELEASE</version> <systemPath>${project.basedir}/lib/artemis-http-client-1.1.13.RELEASE.jar</systemPath> </dependency> </dependencies> <build> @@ -137,6 +143,13 @@ </plugins> <resources> <resource> <directory>lib</directory> <targetPath>/BOOT-INF/lib/</targetPath> <includes> <include>**/*.jar</include> </includes> </resource> <resource> <directory>src/main/resources</directory> </resource> <resource> @@ -148,5 +161,4 @@ </resource> </resources> </build> </project> ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/controller/UPWarnMsgAdptInfoController.java
@@ -1,5 +1,6 @@ package com.ruoyi.dataInterchange.controller; import com.alibaba.fastjson2.JSON; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.utils.bean.BeanUtils; import com.ruoyi.dataInterchange.api.vo.UPWarnMsgAdptInfoVo; @@ -7,10 +8,9 @@ import com.ruoyi.dataInterchange.dao.UPWarnMsgUrgeTodoAckDao; import com.ruoyi.dataInterchange.model.UPWarnMsgAdptInfo; import com.ruoyi.dataInterchange.model.UPWarnMsgUrgeTodoAck; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.ruoyi.dataInterchange.util.haikang.model.SubscriptionEvent; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.ArrayList; @@ -23,6 +23,7 @@ * @author zhibing.pu * @Date 2025/4/2 10:08 */ @Slf4j @RestController @RequestMapping("/warnMsgAdptInfo") public class UPWarnMsgAdptInfoController { @@ -89,4 +90,16 @@ } return R.ok(); } /** * 海康威视报警信息推送 * @return */ @ResponseBody @PostMapping("/alarmNotice") public void alarmNotice(@RequestBody SubscriptionEvent event) { log.error("收到危海康的事件回调"); log.error(JSON.toJSONString(event)); } } ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/Artemis.java
New file @@ -0,0 +1,130 @@ package com.ruoyi.dataInterchange.util.haikang; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hikvision.artemis.sdk.ArtemisHttpUtil; import com.hikvision.artemis.sdk.config.ArtemisConfig; 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 lombok.extern.slf4j.Slf4j; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import javax.servlet.annotation.WebListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 事件订阅工具类 * @author zhibing.pu * @Date 2025/5/20 16:17 */ @Slf4j @WebListener public class Artemis implements ServletContextListener { /** * STEP2:设置OpenAPI接口的上下文 */ private static final String ARTEMIS_PATH = "/artemis"; /** * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数. * * ip:port : 平台门户/nginx的IP和端口(必须使用https协议,https端口默认为443) * appKey : 请填入appKey * appSecret : 请填入appSecret */ private static ArtemisConfig artemisConfig = new ArtemisConfig("112.18.106.230:443", "27273246", "vjvZA7X4hHUc0SbONht9"); //按事件类型取消订阅 public static String eventUnSubscriptionByEventTypes(EventUnSubscriptionByEventTypesRequest eventUnSubscriptionByEventTypesRequest) throws Exception { String eventUnSubscriptionByEventTypesDataApi = ARTEMIS_PATH +"/api/eventService/v1/eventUnSubscriptionByEventTypes"; Map<String,String> path = new HashMap<String,String>(2){ { put("https://",eventUnSubscriptionByEventTypesDataApi); } }; String body= JSON.toJSONString(eventUnSubscriptionByEventTypesRequest); String result =ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json"); return result; } @Override public void contextInitialized(ServletContextEvent sce) { try { //先查询是否订阅事件 EventSubscriptionViewRequest eventSubscriptionViewRequest = new EventSubscriptionViewRequest(); eventSubscriptionViewRequest.setSubWay(1); String eventSubscriptionView = Artemis.eventSubscriptionView(eventSubscriptionViewRequest); 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(); } } //查询事件订阅信息 public static String eventSubscriptionView(EventSubscriptionViewRequest eventSubscriptionViewRequest) throws Exception { String eventSubscriptionViewDataApi = ARTEMIS_PATH +"/api/eventService/v1/eventSubscriptionView"; Map<String,String> path = new HashMap<String,String>(2){ { put("https://",eventSubscriptionViewDataApi); } }; String body=JSON.toJSONString(eventSubscriptionViewRequest); String result =ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json"); return result; } //按事件类型订阅事件 public static String eventSubscriptionByEventTypes(EventSubscriptionByEventTypesRequest eventSubscriptionByEventTypesRequest) throws Exception { String eventSubscriptionByEventTypesDataApi = ARTEMIS_PATH +"/api/eventService/v1/eventSubscriptionByEventTypes"; Map<String,String> path = new HashMap<String,String>(2){ { put("https://",eventSubscriptionByEventTypesDataApi); } }; String body=JSON.toJSONString(eventSubscriptionByEventTypesRequest); String result = ArtemisHttpUtil.doPostStringArtemis(artemisConfig,path,body,null,null,"application/json"); return result; } @Override public void contextDestroyed(ServletContextEvent sce) { } } ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/EventSubscriptionByEventTypesRequest.java
New file @@ -0,0 +1,51 @@ package com.ruoyi.dataInterchange.util.haikang.model; import java.util.ArrayList; public class EventSubscriptionByEventTypesRequest { private ArrayList<String> eventTypes; private Integer subWay; private String eventDest; private Integer subType; private ArrayList<Integer> eventLvl; public ArrayList<String> getEventTypes() { return eventTypes; } public void setEventTypes(ArrayList<String> eventTypes) { this.eventTypes = eventTypes; } public Integer getSubWay() { return subWay; } public void setSubWay(Integer subWay) { this.subWay = subWay; } public String getEventDest() { return eventDest; } public void setEventDest(String eventDest) { this.eventDest = eventDest; } public Integer getSubType() { return subType; } public void setSubType(Integer subType) { this.subType = subType; } public ArrayList<Integer> getEventLvl() { return eventLvl; } public void setEventLvl(ArrayList<Integer> eventLvl) { this.eventLvl = eventLvl; } } ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/EventSubscriptionViewRequest.java
New file @@ -0,0 +1,13 @@ package com.ruoyi.dataInterchange.util.haikang.model; public class EventSubscriptionViewRequest { private Integer subWay; public Integer getSubWay() { return subWay; } public void setSubWay(Integer subWay) { this.subWay = subWay; } } ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/EventUnSubscriptionByEventTypesRequest.java
New file @@ -0,0 +1,24 @@ package com.ruoyi.dataInterchange.util.haikang.model; import java.util.ArrayList; public class EventUnSubscriptionByEventTypesRequest { private ArrayList<Integer> eventTypes; private ArrayList<String> clientIds; public ArrayList<Integer> getEventTypes() { return eventTypes; } public void setEventTypes(ArrayList<Integer> eventTypes) { this.eventTypes = eventTypes; } public ArrayList<String> getClientIds() { return clientIds; } public void setClientIds(ArrayList<String> clientIds) { this.clientIds = clientIds; } } ruoyi-service/ruoyi-dataInterchange/src/main/java/com/ruoyi/dataInterchange/util/haikang/model/SubscriptionEvent.java
New file @@ -0,0 +1,77 @@ package com.ruoyi.dataInterchange.util.haikang.model; import lombok.Data; /** * 订阅事件统一格式 * @author zhibing.pu * @Date 2025/5/21 14:08 */ @Data public class SubscriptionEvent { /** * 方法名 */ private String method; /** * 事件参数信息 */ private String params; /** * 事件从接收者发出的时间 */ private String sendTime; /** * 事件类别,如视频事件、门禁事件 */ private String ability; /** * 事件信息 */ private String events; /** * 事件Id,标识事件的一次发生,同一 * 事件发送多次需要ID相同 */ private String eventId; /** * 事件源编号,物理设备是资源编号 */ private String srcIndex; /** * 事件源类型 */ private String srcType; /** * 事件源名称,utf8 */ private String srcName; /** * 事件类型 */ private String eventType; /** * 事件状态, 0-瞬时 1-开始 2-停止 3-事件脉冲 4-事件联动结果更新 */ private Integer status; /** * 事件等级:0-未配置, 非0-配置登记的事件,注意,此处事件等级是指在事件联动中配置的等级 */ private Integer eventLvl; /** * 脉冲超时时间,一个持续性的事件,上报的间隔 */ private Integer timeout; /** * 事件发生时间 */ private String happenTime; /** * 事件发生的事件源父设备,无-空字符串 */ private String srcParentIdex; /** * 事件其它扩展信息 */ private String data; }