setExtraInfo(String key, Object value) {
35 | extraInfo.put(key, value);
36 | return extraInfo;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/gnss-common/src/main/java/com/gnss/common/exception/ApplicationException.java:
--------------------------------------------------------------------------------
1 | package com.gnss.common.exception;
2 |
3 | /**
4 | * Description: 应用异常
5 | * Company: www.gps-pro.cn
6 | *
7 | * @author huangguangbin
8 | * @version 1.0.1
9 | * @date 2017/9/15
10 | */
11 | public class ApplicationException extends RuntimeException {
12 |
13 | public ApplicationException() {
14 | }
15 |
16 | public ApplicationException(String message) {
17 | super(message);
18 | }
19 |
20 | public ApplicationException(Throwable cause) {
21 | super(cause);
22 | }
23 |
24 | public ApplicationException(String message, Throwable cause) {
25 | super(message, cause);
26 | }
27 |
28 | protected ApplicationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
29 | super(message, cause, enableSuppression, writableStackTrace);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/gnss-common/src/main/java/com/gnss/common/annotations/MessageService.java:
--------------------------------------------------------------------------------
1 | package com.gnss.common.annotations;
2 |
3 | import com.gnss.common.constants.CommonConstants;
4 | import org.springframework.stereotype.Component;
5 |
6 | import java.lang.annotation.Documented;
7 | import java.lang.annotation.ElementType;
8 | import java.lang.annotation.Retention;
9 | import java.lang.annotation.RetentionPolicy;
10 | import java.lang.annotation.Target;
11 |
12 | @Target(ElementType.TYPE)
13 | @Retention(RetentionPolicy.RUNTIME)
14 | @Documented
15 | @Component
16 | public @interface MessageService {
17 |
18 | /**
19 | * 消息ID
20 | *
21 | * @return 返回消息ID
22 | */
23 | int messageId() default CommonConstants.DEFAULT_MESSAGE_ID;
24 |
25 | /**
26 | * 字符串类型的消息ID
27 | *
28 | * @return 返回字符串类型的消息ID
29 | */
30 | String strMessageId() default "";
31 |
32 | /**
33 | * 消息类型描述
34 | *
35 | * @return 返回消息类型描述
36 | */
37 | String desc() default "不支持消息";
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/gnss-common/src/main/java/com/gnss/common/constants/CommandSendResultEnum.java:
--------------------------------------------------------------------------------
1 | package com.gnss.common.constants;
2 |
3 | import lombok.Getter;
4 |
5 | /**
6 | * Description: 指令发送结果
7 | * Company: www.gps-pro.cn
8 | *
9 | * @author huangguangbin
10 | * @version 1.0.1
11 | * @date 2018/2/3
12 | */
13 | @Getter
14 | public enum CommandSendResultEnum {
15 | /**
16 | * 成功
17 | */
18 | SUCCESS(0, "成功"),
19 |
20 | /**
21 | * 失败
22 | */
23 | FAILED(1, "失败"),
24 |
25 | /**
26 | * 终端不在线
27 | */
28 | TERMINAL_OFFLINE(2, "终端不在线"),
29 |
30 | /**
31 | * 指令超时
32 | */
33 | TIMEOUT(3, "指令超时"),
34 |
35 | /**
36 | * 指令不支持
37 | */
38 | NOT_SUPPORT(4, "指令不支持"),
39 |
40 | /**
41 | * 内部服务错误
42 | */
43 | INTERNAL_SERVER_ERROR(5, "内部服务错误");
44 |
45 | private Integer code;
46 |
47 | private String desc;
48 |
49 | CommandSendResultEnum(Integer code, String desc) {
50 | this.code = code;
51 | this.desc = desc;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/gnss-common/src/main/java/com/gnss/common/security/AuthTokenDetails.java:
--------------------------------------------------------------------------------
1 | package com.gnss.common.security;
2 |
3 | import com.gnss.common.constants.RoleTypeEnum;
4 | import lombok.Getter;
5 | import lombok.Setter;
6 | import lombok.ToString;
7 |
8 | import java.util.Date;
9 |
10 | /**
11 | * Description: JWT详情
12 | * Company: www.gps-pro.cn
13 | *
14 | * @author huangguangbin
15 | * @version 1.0.1
16 | * @date 2017/6/19
17 | */
18 | @Getter
19 | @Setter
20 | @ToString
21 | public class AuthTokenDetails {
22 | /**
23 | * APP ID
24 | */
25 | private String appId;
26 | /**
27 | * 用户ID
28 | */
29 | private Long userId;
30 | /**
31 | * 组织ID
32 | */
33 | private Long organizationId;
34 | /**
35 | * 角色ID
36 | */
37 | private Long roleId;
38 | /**
39 | * 角色类型
40 | */
41 | private RoleTypeEnum roleType;
42 | /**
43 | * 过期时间
44 | */
45 | private Date expirationDate;
46 | /**
47 | * 语言环境
48 | */
49 | private String language;
50 | }
51 |
--------------------------------------------------------------------------------
/gnss-common/src/main/java/com/gnss/common/constants/CommonConstants.java:
--------------------------------------------------------------------------------
1 | package com.gnss.common.constants;
2 |
3 | import java.time.ZoneId;
4 |
5 | /**
6 | * Description: 公共常量
7 | * Company: www.gps-pro.cn
8 | *
9 | * @author huangguangbin
10 | * @version 1.0.1
11 | * @date 2018/2/3
12 | */
13 | public class CommonConstants {
14 |
15 | private CommonConstants() {
16 | }
17 |
18 | /**
19 | * 中国时区
20 | */
21 | public static final ZoneId ZONE_GMT8 = ZoneId.of("GMT+8");
22 |
23 | public static final int YES = 1;
24 |
25 | public static final int NO = 0;
26 |
27 | /**
28 | * 默认消息ID
29 | */
30 | public static final int DEFAULT_MESSAGE_ID = -999;
31 |
32 | /**
33 | * 不支持的整型指令ID
34 | */
35 | public static final int UNSUPPORT_MESSAGE_ID = -1;
36 |
37 | /**
38 | * 不支持的字符串指令ID
39 | */
40 | public static final String UNSUPPORTED_STR_MESSAGE_ID = "unsupported";
41 |
42 | /**
43 | * 默认编码
44 | */
45 | public static final String DEFAULT_CHARSET_NAME = "GBK";
46 | }
47 |
--------------------------------------------------------------------------------
/gnss-common/src/main/java/com/gnss/common/proto/LocationProtoDTO.java:
--------------------------------------------------------------------------------
1 | package com.gnss.common.proto;
2 |
3 | import com.baidu.bjf.remoting.protobuf.FieldType;
4 | import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;
5 | import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
6 | import lombok.Getter;
7 | import lombok.Setter;
8 | import lombok.ToString;
9 |
10 | import java.io.Serializable;
11 |
12 | /**
13 | * Description: 位置传输对象protobuf定义
14 | * Company: www.gps-pro.cn
15 | *
16 | * @author huangguangbin
17 | * @version 1.0.1
18 | * @date 2018/4/15
19 | */
20 | @Getter
21 | @Setter
22 | @ToString
23 | @ProtobufClass
24 | public class LocationProtoDTO implements Serializable {
25 |
26 | /**
27 | * 节点名称
28 | */
29 | @Protobuf(fieldType = FieldType.STRING, order = 1, required = true)
30 | private String nodeName;
31 |
32 | /**
33 | * 位置信息
34 | */
35 | @Protobuf(fieldType = FieldType.OBJECT, order = 2, required = true)
36 | private LocationProto locationProto;
37 |
38 | /**
39 | * 终端信息
40 | */
41 | @Protobuf(fieldType = FieldType.OBJECT, order = 3)
42 | private TerminalProto terminalProto;
43 | }
44 |
--------------------------------------------------------------------------------
/gnss-common/src/main/java/com/gnss/common/proto/RpcProto.java:
--------------------------------------------------------------------------------
1 | package com.gnss.common.proto;
2 |
3 | import com.baidu.bjf.remoting.protobuf.FieldType;
4 | import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;
5 | import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
6 | import com.gnss.common.constants.RpcEnum;
7 | import lombok.Data;
8 |
9 | import java.io.Serializable;
10 |
11 | /**
12 | * Description: RPC protobuf定义
13 | * Company: www.gps-pro.cn
14 | *
15 | * @author huangguangbin
16 | * @version 1.0.1
17 | * @date 2018/2/3
18 | */
19 | @Data
20 | @ProtobufClass
21 | public class RpcProto implements Serializable {
22 |
23 | /**
24 | * RPC类型
25 | */
26 | @Protobuf(fieldType = FieldType.ENUM, order = 1, required = true)
27 | private RpcEnum rpcType;
28 |
29 | /**
30 | * 内容
31 | */
32 | @Protobuf(fieldType = FieldType.STRING, order = 2)
33 | private String content;
34 |
35 | public RpcProto() {
36 | }
37 |
38 | public RpcProto(RpcEnum rpcType) {
39 | this.rpcType = rpcType;
40 | }
41 |
42 | public RpcProto(RpcEnum rpcType, String content) {
43 | this.rpcType = rpcType;
44 | this.content = content;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/gnss-common/src/main/java/com/gnss/common/proto/TerminalProto.java:
--------------------------------------------------------------------------------
1 | package com.gnss.common.proto;
2 |
3 | import com.baidu.bjf.remoting.protobuf.FieldType;
4 | import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;
5 | import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
6 | import lombok.Getter;
7 | import lombok.Setter;
8 | import lombok.ToString;
9 |
10 | import java.io.Serializable;
11 |
12 | /**
13 | * Description: 终端protobuf定义
14 | * Company: www.gps-pro.cn
15 | *
16 | * @author huangguangbin
17 | * @version 1.0.1
18 | * @date 2017/9/15
19 | */
20 | @Getter
21 | @Setter
22 | @ToString
23 | @ProtobufClass
24 | public class TerminalProto implements Serializable {
25 |
26 | /**
27 | * 节点名称
28 | */
29 | @Protobuf(fieldType = FieldType.STRING, order = 1, required = true)
30 | private String nodeName;
31 |
32 | /**
33 | * 终端ID
34 | */
35 | @Protobuf(fieldType = FieldType.INT64, order = 2, required = true)
36 | private long terminalId;
37 |
38 | /**
39 | * 终端手机号
40 | */
41 | @Protobuf(fieldType = FieldType.STRING, order = 3)
42 | private String terminalSimCode;
43 |
44 | /**
45 | * 终端号码
46 | */
47 | @Protobuf(fieldType = FieldType.STRING, order = 4)
48 | private String terminalNum;
49 |
50 | /**
51 | * 车牌号码
52 | */
53 | @Protobuf(fieldType = FieldType.STRING, order = 5)
54 | private String vehicleNum;
55 | }
56 |
--------------------------------------------------------------------------------
/gnss-mqutil/src/main/java/com/gnss/mqutil/constants/MqConstants.java:
--------------------------------------------------------------------------------
1 | package com.gnss.mqutil.constants;
2 |
3 | /**
4 | * Description: MQ常量
5 | * Company: www.gps-pro.cn
6 | *
7 | * @author huangguangbin
8 | * @version 1.0.1
9 | * @date 2018/9/14
10 | */
11 | public class MqConstants {
12 | private MqConstants() {
13 | }
14 |
15 | public static final String STATUS_EXCHANGE = "status.exchange";
16 |
17 | public static final String STATUS_ROUTING_KEY = "#.status";
18 |
19 | public static final String LOCATION_EXCHANGE = "location.exchange";
20 |
21 | public static final String LOCATION_ROUTING_KEY = "#.location";
22 |
23 | public static final String ALARM_EXCHANGE = "alarm.exchange";
24 |
25 | public static final String ALARM_ROUTING_KEY = "#.alarm";
26 |
27 | public static final String MEDIA_FILE_EXCHANGE = "media.file.exchange";
28 |
29 | public static final String MEDIA_FILE_ROUTING_KEY = "#.media.file";
30 |
31 | public static final String UP_COMMAND_EXCHANGE = "up.command.exchange";
32 |
33 | public static final String UP_COMMAND_ROUTING_KEY = "#.up.command";
34 |
35 | public static final String DOWN_COMMAND_EXCHANGE = "down.command.exchange";
36 |
37 | public static final String DOWN_COMMAND_ROUTING_KEY = "#.down.command";
38 |
39 | public static final String RPC_EXCHANGE = "rpc.exchange";
40 |
41 | public static final String RPC_ROUTING_KEY = "gnss.rpc";
42 | }
--------------------------------------------------------------------------------
/gnss-common/src/main/java/com/gnss/common/proto/AlarmProtoDTO.java:
--------------------------------------------------------------------------------
1 | package com.gnss.common.proto;
2 |
3 | import com.baidu.bjf.remoting.protobuf.FieldType;
4 | import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;
5 | import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
6 | import com.gnss.common.constants.AlarmActionEnum;
7 | import lombok.Getter;
8 | import lombok.Setter;
9 | import lombok.ToString;
10 |
11 | import java.io.Serializable;
12 | import java.util.List;
13 |
14 | /**
15 | * Description: 报警传输对象protobuf定义
16 | * Company: www.gps-pro.cn
17 | *
18 | * @author huangguangbin
19 | * @version 1.0.1
20 | * @date 2018/4/15
21 | */
22 | @Getter
23 | @Setter
24 | @ToString
25 | @ProtobufClass
26 | public class AlarmProtoDTO implements Serializable {
27 |
28 | /**
29 | * 报警动作
30 | */
31 | @Protobuf(fieldType = FieldType.ENUM, order = 1, required = true)
32 | private AlarmActionEnum alarmAction;
33 |
34 | /**
35 | * 节点名称
36 | */
37 | @Protobuf(fieldType = FieldType.STRING, order = 2, required = true)
38 | private String nodeName;
39 |
40 | /**
41 | * 位置信息
42 | */
43 | @Protobuf(fieldType = FieldType.OBJECT, order = 3, required = true)
44 | private LocationProto locationProto;
45 |
46 | /**
47 | * 终端信息
48 | */
49 | @Protobuf(fieldType = FieldType.OBJECT, order = 4, required = true)
50 | private TerminalProto terminalProto;
51 |
52 | /**
53 | * 报警位
54 | */
55 | @Protobuf(fieldType = FieldType.INT32, order = 5, required = true)
56 | private List alarmBits;
57 | }
58 |
--------------------------------------------------------------------------------
/gnss-common/src/main/java/com/gnss/common/dto/SuperiorConfigDTO.java:
--------------------------------------------------------------------------------
1 | package com.gnss.common.dto;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * Description: JT809上级平台配置DTO
7 | * Company: www.gps-pro.cn
8 | *
9 | * @author huangguangbin
10 | * @version 1.0.1
11 | * @date 2018/2/3
12 | */
13 | @Data
14 | public class SuperiorConfigDTO {
15 |
16 | /**
17 | * 上级平台名称
18 | */
19 | private String name;
20 |
21 | /**
22 | * 是否启用
23 | */
24 | private String isEnable;
25 |
26 | /**
27 | * 上级平台IP
28 | */
29 | private String superiorIp;
30 |
31 | /**
32 | * 上级平台端口
33 | */
34 | private Integer superiorPort;
35 |
36 | /**
37 | * 本地IP
38 | */
39 | private String localIp;
40 |
41 | /**
42 | * 本地端口
43 | */
44 | private Integer localPort;
45 |
46 | /**
47 | * 接入码
48 | */
49 | private Integer centerId;
50 |
51 | /**
52 | * 用户名
53 | */
54 | private Integer userId;
55 |
56 | /**
57 | * 密码
58 | */
59 | private String password;
60 |
61 | /**
62 | * 是否加密
63 | */
64 | private String isCrypto;
65 |
66 | /**
67 | * 加密密钥
68 | */
69 | private Integer cryptoKey;
70 |
71 | /**
72 | * 加密元素M1
73 | */
74 | private Integer m1;
75 |
76 | /**
77 | * 加密元素IA1
78 | */
79 | private Integer ia1;
80 |
81 | /**
82 | * 加密元素IC1
83 | */
84 | private Integer ic1;
85 |
86 | /**
87 | * 平台编码
88 | */
89 | private String platformId;
90 |
91 | /**
92 | * 版本标识
93 | */
94 | private byte[] versionArr;
95 | }
96 |
--------------------------------------------------------------------------------
/gnss-common/src/main/java/com/gnss/common/service/BaseMessageService.java:
--------------------------------------------------------------------------------
1 | package com.gnss.common.service;
2 |
3 | import com.gnss.common.exception.ApplicationException;
4 | import com.gnss.common.model.BaseMessage;
5 | import com.gnss.common.proto.TerminalProto;
6 | import com.gnss.common.utils.SessionUtil;
7 | import io.netty.buffer.ByteBuf;
8 | import io.netty.channel.ChannelHandlerContext;
9 | import lombok.Getter;
10 | import lombok.Setter;
11 |
12 | /**
13 | * Description: 消息处理器
14 | * Company: www.gps-pro.cn
15 | *
16 | * @author huangguangbin
17 | * @version 1.0.1
18 | * @date 2017/9/15
19 | */
20 | @Getter
21 | @Setter
22 | public abstract class BaseMessageService {
23 |
24 | private int messageId;
25 |
26 | private String strMessageId;
27 |
28 | private String desc;
29 |
30 | /**
31 | * 获取终端信息
32 | *
33 | * @param ctx ChannelHandlerContext
34 | * @return 终端信息
35 | */
36 | public TerminalProto getTerminalInfo(ChannelHandlerContext ctx) {
37 | return SessionUtil.getTerminalInfo(ctx.channel());
38 | }
39 |
40 | /**
41 | * 检查消息体长度
42 | *
43 | * @param msg 消息
44 | * @param msgBodyLen 消息体长度
45 | * @throws ApplicationException 应用异常
46 | */
47 | public void checkMessageBodyLen(T msg, int msgBodyLen) throws ApplicationException {
48 | byte[] msgBody = msg.getMsgBodyArr();
49 | if (msgBody.length < msgBodyLen) {
50 | throw new ApplicationException("消息体长度不对,不能小于" + msgBodyLen);
51 | }
52 | }
53 |
54 | /**
55 | * 处理消息
56 | *
57 | * @param ctx ChannelHandlerContext
58 | * @param msg 消息
59 | * @param msgBodyBuf 消息体
60 | * @return 返回结果
61 | * @throws Exception 异常
62 | */
63 | public abstract Object process(ChannelHandlerContext ctx, T msg, ByteBuf msgBodyBuf) throws Exception;
64 | }
65 |
--------------------------------------------------------------------------------
/gnss-common/src/main/java/com/gnss/common/proto/MediaFileProtoDTO.java:
--------------------------------------------------------------------------------
1 | package com.gnss.common.proto;
2 |
3 | import com.baidu.bjf.remoting.protobuf.FieldType;
4 | import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;
5 | import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
6 | import lombok.Getter;
7 | import lombok.Setter;
8 | import lombok.ToString;
9 |
10 | import java.io.Serializable;
11 |
12 | /**
13 | * Description: 多媒体文件传输对象protobuf定义
14 | * Company: www.gps-pro.cn
15 | *
16 | * @author huangguangbin
17 | * @version 1.0.1
18 | * @date 2018/4/13
19 | */
20 | @Getter
21 | @Setter
22 | @ToString(exclude = {"mediaData"})
23 | @ProtobufClass
24 | public class MediaFileProtoDTO implements Serializable {
25 | /**
26 | * 多媒体ID
27 | */
28 | @Protobuf(fieldType = FieldType.INT64, order = 1)
29 | private Long mediaId;
30 |
31 | /**
32 | * 多媒体类型
33 | */
34 | @Protobuf(fieldType = FieldType.INT32, order = 2)
35 | private Integer mediaType;
36 |
37 | /**
38 | * 多媒体格式编码
39 | */
40 | @Protobuf(fieldType = FieldType.INT32, order = 3)
41 | private Integer mediaFormatCode;
42 |
43 | /**
44 | * 事件项编码
45 | */
46 | @Protobuf(fieldType = FieldType.INT32, order = 4)
47 | private Integer eventItemCode;
48 |
49 | /**
50 | * 通道ID
51 | */
52 | @Protobuf(fieldType = FieldType.INT32, order = 5)
53 | private Integer channelId;
54 |
55 | /**
56 | * 位置信息
57 | */
58 | @Protobuf(fieldType = FieldType.OBJECT, order = 6)
59 | private LocationProto location;
60 |
61 | /**
62 | * 多媒体数据
63 | */
64 | @Protobuf(fieldType = FieldType.BYTES, order = 7, required = true)
65 | private byte[] mediaData;
66 |
67 | /**
68 | * 终端信息
69 | */
70 | @Protobuf(fieldType = FieldType.OBJECT, order = 8, required = true)
71 | private TerminalProto terminalInfo;
72 | }
73 |
--------------------------------------------------------------------------------
/gnss-common/src/main/java/com/gnss/common/session/Session.java:
--------------------------------------------------------------------------------
1 | package com.gnss.common.session;
2 |
3 | import com.gnss.common.proto.TerminalProto;
4 | import lombok.Getter;
5 | import lombok.Setter;
6 | import org.apache.commons.lang3.tuple.MutablePair;
7 |
8 | /**
9 | * Description: 通信会话
10 | * Company: www.gps-pro.cn
11 | *
12 | * @author huangguangbin
13 | * @version 1.0.1
14 | * @date 2018/11/1
15 | */
16 | public class Session {
17 |
18 | /**
19 | * 消息流水号最小值
20 | */
21 | public static final int DEFAULT_MIN_MSG_FLOW_ID = 0x0001;
22 |
23 | /**
24 | * 消息流水号最大值
25 | */
26 | public static final int DEFAULT_MAX_MSG_FLOW_ID = 0x7FFF;
27 |
28 | /**
29 | * 终端信息
30 | */
31 | @Getter
32 | @Setter
33 | private TerminalProto terminalInfo;
34 |
35 | /**
36 | * 手机号数组
37 | */
38 | @Getter
39 | @Setter
40 | private byte[] phoneNumArr;
41 |
42 | /**
43 | * 消息流水号范围
44 | */
45 | private final MutablePair msgFlowIdRange;
46 |
47 | /**
48 | * 当前消息流水号
49 | */
50 | private int currentMsgFlowId;
51 |
52 | public Session(TerminalProto terminalInfo) {
53 | this.msgFlowIdRange = MutablePair.of(DEFAULT_MIN_MSG_FLOW_ID, DEFAULT_MAX_MSG_FLOW_ID);
54 | this.terminalInfo = terminalInfo;
55 | }
56 |
57 | public Session(Integer minMsgFlowId, Integer maxMsgFlowId, TerminalProto terminalInfo) {
58 | this.msgFlowIdRange = MutablePair.of(minMsgFlowId, maxMsgFlowId);
59 | this.terminalInfo = terminalInfo;
60 | }
61 |
62 | /**
63 | * 获取消息流水号,并设置下个消息流水号
64 | *
65 | * @return 返回消息流水号
66 | */
67 | public int getNextMsgFlowId() {
68 | int msgFlowId = currentMsgFlowId;
69 | int minMsgFlowId = msgFlowIdRange.getLeft();
70 | int maxMsgFlowId = msgFlowIdRange.getRight();
71 | currentMsgFlowId = currentMsgFlowId >= maxMsgFlowId ? minMsgFlowId : currentMsgFlowId + 1;
72 | return msgFlowId;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/gnss-common/src/main/java/com/gnss/common/proto/CommandProto.java:
--------------------------------------------------------------------------------
1 | package com.gnss.common.proto;
2 |
3 | import com.baidu.bjf.remoting.protobuf.FieldType;
4 | import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;
5 | import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
6 | import com.gnss.common.constants.CommandRequestTypeEnum;
7 | import com.gnss.common.constants.CommandSendResultEnum;
8 | import lombok.Data;
9 |
10 | import java.io.Serializable;
11 |
12 | /**
13 | * Description: 指令MQ传输信息, 用于应用程序间上行下行指令传输
14 | * Company: www.gps-pro.cn
15 | *
16 | * @author huangguangbin
17 | * @version 1.0.1
18 | * @date 2018/2/3
19 | */
20 | @Data
21 | @ProtobufClass
22 | public class CommandProto implements Serializable {
23 |
24 | /**
25 | * 指令操作日志ID
26 | */
27 | @Protobuf(fieldType = FieldType.INT64, order = 1, required = true)
28 | private long commandOperationLogId;
29 |
30 | /**
31 | * 终端ID
32 | */
33 | @Protobuf(fieldType = FieldType.INT64, order = 2, required = true)
34 | private long terminalId;
35 |
36 | /**
37 | * 指令请求方式
38 | */
39 | @Protobuf(fieldType = FieldType.ENUM, order = 3, required = true)
40 | private CommandRequestTypeEnum requestType;
41 |
42 | /**
43 | * 下行指令ID
44 | */
45 | @Protobuf(fieldType = FieldType.STRING, order = 4, required = true)
46 | private String downCommandId;
47 |
48 | /**
49 | * 参数
50 | */
51 | @Protobuf(fieldType = FieldType.STRING, order = 5)
52 | private String params;
53 |
54 | /**
55 | * 指令发送结果
56 | */
57 | @Protobuf(fieldType = FieldType.ENUM, order = 6)
58 | private CommandSendResultEnum sendResult;
59 |
60 | /**
61 | * 响应指令ID
62 | */
63 | @Protobuf(fieldType = FieldType.STRING, order = 7)
64 | private String respCommandId;
65 |
66 | /**
67 | * 发送方节点
68 | */
69 | @Protobuf(fieldType = FieldType.STRING, order = 8, required = true)
70 | private String fromNode;
71 |
72 | /**
73 | * 接收方节点
74 | */
75 | @Protobuf(fieldType = FieldType.STRING, order = 9, required = true)
76 | private String toNode;
77 |
78 | /**
79 | * 开始时间
80 | */
81 | @Protobuf(fieldType = FieldType.INT64, order = 10, required = true)
82 | private long startTime;
83 |
84 | /**
85 | * 超时时间
86 | */
87 | @Protobuf(fieldType = FieldType.INT32, order = 11)
88 | private Integer timeout;
89 |
90 | /**
91 | * 下行指令描述
92 | */
93 | @Protobuf(fieldType = FieldType.STRING, order = 12)
94 | private String downCommandDesc;
95 |
96 | /**
97 | * 透传消息体
98 | */
99 | @Protobuf(fieldType = FieldType.BYTES, order = 13)
100 | private byte[] messageBody;
101 | }
102 |
--------------------------------------------------------------------------------
/gnss-mqutil/src/main/java/com/gnss/mqutil/converter/ProtobufMessageConverter.java:
--------------------------------------------------------------------------------
1 | package com.gnss.mqutil.converter;
2 |
3 | import com.baidu.bjf.remoting.protobuf.Codec;
4 | import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
5 | import lombok.extern.slf4j.Slf4j;
6 | import org.reflections.Reflections;
7 | import org.springframework.amqp.core.Message;
8 | import org.springframework.amqp.core.MessageProperties;
9 | import org.springframework.amqp.support.converter.MessageConversionException;
10 | import org.springframework.amqp.support.converter.MessageConverter;
11 |
12 | import java.util.HashMap;
13 | import java.util.Map;
14 |
15 | /**
16 | * Description: Protobuf转换器
17 | * Company: www.gps-pro.cn
18 | *
19 | * @author huangguangbin
20 | * @version 1.0.1
21 | * @date 2018/4/13
22 | */
23 | @Slf4j
24 | public class ProtobufMessageConverter implements MessageConverter {
25 | private static Map codecMap = new HashMap<>();
26 |
27 | static {
28 | Reflections reflections = new Reflections("com.gnss.common.proto");
29 | reflections.getTypesAnnotatedWith(ProtobufClass.class).stream()
30 | .forEach(clazz -> {
31 | try {
32 | Codec codec = (Codec) Class.forName(clazz.getName() + "$$JProtoBufClass").newInstance();
33 | codecMap.put(clazz.getSimpleName(), codec);
34 | log.info("加载Protobuf转换器{}", clazz.getName());
35 | } catch (Exception e) {
36 | log.error("加载Protobuf转换器{}失败", clazz.getName(), e);
37 | }
38 | });
39 | }
40 |
41 | @Override
42 | public Message toMessage(Object obj, MessageProperties messageProperties) throws MessageConversionException {
43 | String messageType = obj.getClass().getSimpleName();
44 | Codec