编解码器
南向子系统集成、终端设备接入的协议适配标准
标准数据格式
设备上报数据格式:
{ id:"设备ID", name:"设备名称", state:"设备状态", classify:"设备类型", collectTime:"时间", location:"位置详情", lon:"经度", lat:"维度", alt:"高度", properties:{ // 附加属性 xxx:'xx值' } }
告警上报数据格式:
{ id:"事件ID", name:"事件名称", deviceId:"设备ID", state:"事件状态", type:"事件类型", details:"事件详情", createTime:"时间", location:"位置详情", properties:{ // 附加属性 xxx:'xx值' } }
功能操作请求格式:
{ deviceId:"设备ID", func:"功能标识", req:{ // 请求参数 xxx:'xx值' } }
参考内容
设备状态
package cn.flyrise.pai.prot.common.enums;
import cn.flyrise.pai.prot.domain.vo.DefaultEnumVO;
import java.util.ArrayList;
import java.util.List;
/**
* 设备状态
* @author zhangq
* @date 2023-3-13
*/
public enum DeviceStatusType {
ONLINE(0, "正常"),
OFFLINE(1, "离线"),
HITCH(2, "故障"),
DISCARD(3, "废弃"),
NOT_ENABLED(-1, "未启用"),
;
DeviceStatusType(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
private Integer code;
private String desc;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public boolean match(Integer code) {
return this.code.equals(code);
}
public static String getDesc(Integer code) {
DeviceStatusType[] enums = values();
for (DeviceStatusType enum_data : enums) {
if (enum_data.match(code)) {
return enum_data.getDesc();
}
}
return "";
}
public static List<DefaultEnumVO> getCodeDesc() {
DeviceStatusType[] enums = values();
List list = new ArrayList();
for (DeviceStatusType enum_data : enums) {
DefaultEnumVO defaultJSON = new DefaultEnumVO();
defaultJSON.setId(String.valueOf(enum_data.getCode()));
defaultJSON.setName(enum_data.getDesc());
list.add(defaultJSON);
}
return list;
}
}
设备类型
package cn.flyrise.pai.prot.common.enums;
import cn.flyrise.pai.prot.domain.vo.DefaultEnumVO;
import java.util.ArrayList;
import java.util.List;
/**
* 标准设备类型
* @author zhangq
* @date 2023-3-13
*/
public enum DeviceType {
// 安防
DEVICE_CAMERA("CAMERA", "摄像头"),
DEVICE_ENCODER("DEVICE_ENCODER", "编码设备"),
DEVICE_SERVICE("DEVICE_SERVICE", "服务设备"),
DEVICE_ENTRANCE_GUARD("ENTRANCE_GUARD", "门禁"),
DEVICE_BARRIER_GATE("BARRIER_GATE", "道闸"),
// 能耗
DEVICE_ELECTRICITY("ELECTRICITY_METER", "电表"),
DEVICE_THREE_ELECTRICITY("THREE_ELECTRICITY", "三相电表"),
DEVICE_WATER("WATER_METER", "水表"),
DEVICE_GAS("GAS_METER", "燃气表"),
// 动环
DEVICE_WATER_IMMERSION("WATER_IMMERSION", "水浸报警器"),
DEVICE_WATER_GAGE("WATER_GAGE", "水压传感器"),
// 消防
DEVICE_SMOKE("SMOKE_SENSOR", "烟感器"),
DEVICE_FIRE_ENGINE("FIRE_ENGINE", "消防主机"),
DEVICE_ALARM_ENGINE("ALARM_ENGINE", "告警主机"),
// 传感器
DEVICE_TEMP("TEMP_SENSOR", "温度传感器"),
DEVICE_HUMIDITY("HUMIDITY_SENSOR", "湿度传感器"),
DEVICE_TEMP_HUMIDITY("TEMP_HUMIDITY_SENSOR", "温湿度传感器"),
DEVICE_LTH_SENSOR("LTH_SENSOR", "光照温湿度传感器"),
// 边缘计算、网关
DEVICE_GATEWAY("INTEL_GATEWAY", "智能网关"),
// 终端设备
DEVICE_ELECTRIC_RELAY("ELECTRIC_RELAY", "继电器"),
DEVICE_SWITCH("SWITCH", "控制面板"),
// BA
DEVICE_AIR_CONDITION("AIR_CONDITION", "空调"),
DEVICE_LIFT("DEVICE_LIFT", "电梯"),
DEVICE_LAMP("DEVICE_LAMP", "灯"),
DEVICE_WINDOW_OPENER("WINDOW_OPENER", "开窗器"),
// 信息发布
DEVICE_LED_SCREEN("LED_SCREEN", "LED屏"),
// 环境检测
DEVICE_WEATHER_STATION("WEATHER_STATION", "气象站监控仪"),
DEVICE_UNKNOWN("Z_DEVICE_UNKNOWN", "未知设备"),
;
DeviceType(String code, String desc) {
this.code = code;
this.desc = desc;
}
private String code;
private String desc;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public boolean match(String code) {
return this.code.equals(code);
}
public static String getDesc(String code) {
DeviceType[] enums = values();
for (DeviceType enum_data : enums) {
if (enum_data.match(code)) {
return enum_data.getDesc();
}
}
return "";
}
public static List<DefaultEnumVO> getCodeDesc() {
DeviceType[] enums = values();
List list = new ArrayList();
for (DeviceType enum_data : enums) {
DefaultEnumVO defaultJSON = new DefaultEnumVO();
defaultJSON.setId(String.valueOf(enum_data.getCode()));
defaultJSON.setName(enum_data.getDesc());
list.add(defaultJSON);
}
return list;
}
}
告警类型
package cn.flyrise.pai.prot.common.enums;
import cn.flyrise.pai.prot.domain.vo.DefaultEnumVO;
import java.util.ArrayList;
import java.util.List;
/**
* 告警事件类型
* @author zhangq
* @date 2023-3-13
*/
public enum EventType {
NORMAL("NORMAL", "正常"),
DEVICE_ALARM("DEVICE_ALARM", "设备告警"),
SERVICE_ALARM("SERVICE_ALARM", "服务告警"),
EXCEED_THRESHOLD("EXCEED_THRESHOLD", "阈值预警"),
FIRE_ALARM("FIRE_ALARM", "消防预警"),
SAFETY_WARN("SAFETY_WARN", "安防预警"),
TYPHOON_WARNING("TYPHOON_WARNING", "台风预警"),
OTHER_ALARM("OTHER_ALARM", "其他"),
;
EventType(String code, String desc) {
this.code = code;
this.desc = desc;
}
private String code;
private String desc;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public boolean match(Integer code) {
return this.code.equals(code);
}
public static String getDesc(Integer code) {
EventType[] enums = values();
for (EventType enum_data : enums) {
if (enum_data.match(code)) {
return enum_data.getDesc();
}
}
return "";
}
public static List<DefaultEnumVO> getCodeDesc() {
EventType[] enums = values();
List list = new ArrayList();
for (EventType enum_data : enums) {
DefaultEnumVO defaultJSON = new DefaultEnumVO();
defaultJSON.setId(String.valueOf(enum_data.getCode()));
defaultJSON.setName(enum_data.getDesc());
list.add(defaultJSON);
}
return list;
}
}
告警状态
package cn.flyrise.pai.prot.common.enums;
import cn.flyrise.pai.prot.domain.vo.DefaultEnumVO;
import java.util.ArrayList;
import java.util.List;
/**
* 告警事件状态
* @author zhangq
* @date 2023-3-13
*/
public enum EventStatusType {
PENDING(0, "待处理"),
PROCESSING(1, "处理中"),
PROCESSED(2, "已处理"),
IGNORED(3, "已忽略"),
MY_RESUME(4, "自恢复"),
;
EventStatusType(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
private Integer code;
private String desc;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public boolean match(Integer code) {
return this.code.equals(code);
}
public static String getDesc(Integer code) {
EventStatusType[] enums = values();
for (EventStatusType enum_data : enums) {
if (enum_data.match(code)) {
return enum_data.getDesc();
}
}
return "";
}
public static List<DefaultEnumVO> getCodeDesc() {
EventStatusType[] enums = values();
List list = new ArrayList();
for (EventStatusType enum_data : enums) {
DefaultEnumVO defaultJSON = new DefaultEnumVO();
defaultJSON.setId(String.valueOf(enum_data.getCode()));
defaultJSON.setName(enum_data.getDesc());
list.add(defaultJSON);
}
return list;
}
}
功能请求状态
package cn.flyrise.pai.prot.common.enums;
import cn.flyrise.pai.prot.domain.vo.DefaultEnumVO;
import java.util.ArrayList;
import java.util.List;
/**
* 功能请求状态
* @author zhangq
* @date 2023-3-13
*/
public enum FuncStatusType {
TO_BE_SENT(0, "待发送"),
TO_BE_SECCESS(1, "发送成功"),
TO_BE_ERROR(1, "发送失败"),
TO_BE_RETURNED(2, "完成"),
TO_BE_TIME_OUT(3, "超时"),
;
FuncStatusType(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
private Integer code;
private String desc;
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public boolean match(Integer code) {
return this.code.equals(code);
}
public static String getDesc(Integer code) {
FuncStatusType[] enums = values();
for (FuncStatusType enum_data : enums) {
if (enum_data.match(code)) {
return enum_data.getDesc();
}
}
return "";
}
public static List<DefaultEnumVO> getCodeDesc() {
FuncStatusType[] enums = values();
List list = new ArrayList();
for (FuncStatusType enum_data : enums) {
DefaultEnumVO defaultJSON = new DefaultEnumVO();
defaultJSON.setId(String.valueOf(enum_data.getCode()));
defaultJSON.setName(enum_data.getDesc());
list.add(defaultJSON);
}
return list;
}
}
默认功能方法
package cn.flyrise.pai.prot.common.enums;
import cn.flyrise.pai.prot.domain.vo.DefaultEnumVO;
import java.util.ArrayList;
import java.util.List;
/**
* 默认功能方法
* @author zhangq
* @date 2023-3-13
*/
public enum SubsystemFunc {
GET_DEVICE_LIST("getDeviceList", "获取设备列表"),
GET_DEVICE_INFO("getDeviceInfo", "获取设备信息"),
GET_EVENT_LIST("getEventList", "获取告警记录"),
PLATFORM_URL("platformUrl", "平台地址"),
VIDEO_STREAM_URL("videoStreamUrl", "视频流地址"),
INIT("init", "初始化"),
;
SubsystemFunc(String code, String desc) {
this.code = code;
this.desc = desc;
}
private String code;
private String desc;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public boolean match(String code) {
return this.code.equals(code);
}
public static String getDesc(String code) {
SubsystemFunc[] enums = values();
for (SubsystemFunc enum_data : enums) {
if (enum_data.match(code)) {
return enum_data.getDesc();
}
}
return "";
}
public static List<DefaultEnumVO> getCodeDesc() {
SubsystemFunc[] enums = values();
List list = new ArrayList();
for (SubsystemFunc enum_data : enums) {
DefaultEnumVO defaultJSON = new DefaultEnumVO();
defaultJSON.setId(String.valueOf(enum_data.getCode()));
defaultJSON.setName(enum_data.getDesc());
list.add(defaultJSON);
}
return list;
}
}
异常抛出类
package cn.flyrise.pai.prot.exception;
/**
* 业务异常基类
*/
public class BaseException extends RuntimeException {
/**
* 业务错误代码
*/
private String code;
protected BaseException() {
super();
}
protected BaseException(String code, String message) {
super(message);
this.code = code;
}
protected BaseException(String code, String message, Throwable throwable) {
super(message, throwable);
this.code = code;
}
public BaseException(BaseErrors baseErrors, Object... params) {
super(baseErrors.format(params));
this.code = baseErrors.getCode();
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
常见异常
package cn.flyrise.pai.prot.exception;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
/**
* 业务错误代码定义枚举类
*/
public enum BaseErrors {
//手动指定错误码
ERR_1001("not_supported", "不支持"),
ERR_1002("func_unrealized", "未实现"),
ERR_1003("param_deletion", "参数缺失"),
ERR_1004("param_null", "参数为空"),
ERR_1005("subsystem_service_err", "第三方服务连接异常"),
ERR_1006("authorization_err", "认证授权失败"),
//... 其他错误码的定义
;
/**
* 错误代码 1001-4999
*/
private String code;
/**
* 错误消息
*/
private String msg;
/**
* 错误消息国际化key
*/
private String key;
/**
* ERR_nnnn 的命名方式使用
*
* @param module 模块代码
* @param msg 内容
*/
BaseErrors(String module, String msg) {
this.msg = msg;
String name = this.name();
if (!name.contains("_")) {
throw new RuntimeException("命名不符合规范, 如:ERR_1001、 MSG_1001、 VIEW_5001");
}
String[] names = name.split("_");
if (!ReUtil.isMatch("^[a-zA-Z]+$", names[0]) || !NumberUtil.isInteger(names[1])) {
throw new RuntimeException("命名不符合规范, 如:ERR_1001、 MSG_1001、 VIEW_5001");
}
name = names[0];
this.code = names[1];
if ("ERR".equals(name)) {
name = "error";
} else if ("MSG".equals(name)) {
name = "message";
} else {
name = name.toLowerCase();
}
this.key = StrUtil.format("{}.{}.{}", name, module, this.code);
}
/**
* 自定义完整内容
*
* @param code 错误代码
* @param msg 内容
* @param key 配置文件Key
*/
BaseErrors(String code, String msg, String key) {
this.code = code;
this.msg = msg;
this.key = key;
}
public String getCode() {
return code;
}
public String getMsg() {
return msg;
}
public String getKey() {
return key;
}
/**
* 获取参数化的msg值
*/
public String format(Object... params) {
String msg = this.getMsg();
if (msg != null && msg.contains(StrUtil.EMPTY_JSON)) {
return StrUtil.format(msg, params);
}
return msg;
}
}
文档更新时间: 2023-10-25 10:07 作者:管理员