com.dahuatech.icc.multiinone.utils.EventParamsUtils Maven / Gradle / Ivy
The newest version!
package com.dahuatech.icc.multiinone.utils;
import com.dahuatech.icc.multiinone.event.domain.*;
import com.dahuatech.icc.multiinone.event.vo.SimpleEventSubcribeRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class EventParamsUtils {
public static SimpleEventSubcribeRequest buildSimpleEventSubcribeRequest(BaseEventSubcribeInfo request){
SimpleEventSubcribeRequest simpleEventSubcribeRequest = new SimpleEventSubcribeRequest();
simpleEventSubcribeRequest.setOauthConfigBaseInfo(request.getOauthConfigBaseInfo());
simpleEventSubcribeRequest.setUri(request.getUri());
simpleEventSubcribeRequest.setHttps(request.isHttps());
simpleEventSubcribeRequest.setName(request.getName());
simpleEventSubcribeRequest.setReceiveIp(request.getReceiveIp());
simpleEventSubcribeRequest.setReceivePort(request.getReceivePort());
return simpleEventSubcribeRequest;
}
/**
* 简易封装事件订阅请求
* @param receiveIp
* @param receivePort
* @param uri
* @param isHttps
* @param config
* @return
*/
public static SubscribeVo simpleSubscribeVo(String receiveIp, String receivePort, String uri, boolean isHttps,String name, Map> config){
List monitorVos = new ArrayList();
MonitorVo monitorVo = new MonitorVo();
StringBuilder stringBuilder = new StringBuilder();
if(isHttps){
stringBuilder.append("https://");
}else{
stringBuilder.append("http://");
}
stringBuilder.append(receiveIp + ":" + receivePort + "/" + uri);
monitorVo.setMonitor(stringBuilder.toString());//第三方接收URL
List eventVos = new ArrayList();
for(Map.Entry> entry : config.entrySet()){
eventVos.add(buildEvent(entry.getKey(),entry.getValue(),null,null));
}
monitorVo.setEvents(eventVos);
monitorVos.add(monitorVo);
SubsystemVo subsystemVo = new SubsystemVo();
subsystemVo.setMagic(receiveIp + "_" + receivePort);
if(StringUtils.isEmpty(name)){
subsystemVo.setName(subsystemVo.getMagic());//默认与magic一样
}else{
subsystemVo.setName(name);//默认与magic一样
}
SubscribeParamVo subscribeParamVo = new SubscribeParamVo();
subscribeParamVo.setSubsystem(subsystemVo);
subscribeParamVo.setMonitors(monitorVos);
SubscribeVo subscribeVo = new SubscribeVo();
subscribeVo.setParam(subscribeParamVo);
return subscribeVo;
}
/**
* 参数设置可自行调整,默认是订阅报警+事件、本机+下级
* @param category
* @param types
* @param nodeCodes API文档-基础数据-设备管理-设备/通道分页查询或设备树
* @param orgs API文档-基础数据-组织管理-组织分页查询或设备树
* @return
*/
private static EventVo buildEvent(String category,List types,List nodeCodes,Listorgs){
EventVo eventVo = new EventVo();
eventVo.setAuthorities(buildAuthority(types,nodeCodes,orgs));//设为空是订阅所有
eventVo.setCategory(category);
return eventVo;
}
/**
* orgs与nodeCodes并集,即或的概念
* 只订阅orgs,nodeCodes需new 空数组;
* 只订阅nodeCodes,orgs需new 空数组;(二者是或的取值)
* @param types
* @param nodeCodes
* @param orgs
* @return
*/
private static List buildAuthority(List types,List nodeCodes,Listorgs){
List list = new ArrayList();
AuthorityVo authorityVo = new AuthorityVo();
authorityVo.setNodeCodes(nodeCodes);//调设备/通道分页查询、设备数获取列表
authorityVo.setOrgs(orgs);//调组织分页查询或组织树
authorityVo.setTypes(types);//指定订阅报警类型,业务类型、感知类型
list.add(authorityVo);
return list;
}
}