ProtobufConvert.java
2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package cn.com.glsx.smartkafka.modules.utils;
import cn.com.glsx.smartkafka.commons.constants.Constants;
import cn.com.glsx.smartkafka.modules.model.pb.Event;
import cn.com.glsx.smartkafka.modules.model.pb.Fence;
import cn.com.glsx.smartkafka.modules.model.pb.kafkasvr;
import org.apache.log4j.Logger;
public class ProtobufConvert {
protected final static Logger LOGGER = Logger.getLogger(ProtobufConvert.class);
// 点火启动转换
public static Event convertIgnition(byte[] message) {
kafkasvr.EventStateReportReq protobufIgnition ;
try {
protobufIgnition = kafkasvr.EventStateReportReq.parseFrom(message);
} catch (Exception e) {
e.printStackTrace();
protobufIgnition = null;
}
if (null == protobufIgnition) {
return null;
}
Event event = new Event();
event.setSn(protobufIgnition.getDevicesn().trim());
event.setTime(DateUtils.parseDate(DateUtils.parseTimeStampDate(protobufIgnition.getTime())));
event.setDeviceType(Constants.MACHINE_STATUS_ORDER);
event.setValue("true");
return event;
}
/**
* 熄火转换
* @param message 入参
* @return 返回值
*/
public static Event convertFlameOut(byte[] message) {
kafkasvr.EventStateReportReq protobufFlameOut;
try {
protobufFlameOut = kafkasvr.EventStateReportReq.parseFrom(message);
} catch (Exception e) {
e.printStackTrace();
protobufFlameOut = null;
}
if (null == protobufFlameOut) {
return null;
}
Event event = new Event();
event.setSn(protobufFlameOut.getDevicesn().trim());
event.setTime(DateUtils.parseDate(DateUtils.parseTimeStampDate(protobufFlameOut.getTime())));
event.setDeviceType(Constants.MACHINE_STATUS_ORDER);
event.setValue("false");
return event;
}
/**
* 回家离家转换
*
* @param message 入参
* @return 返回值
*/
public static Event convertLeaveHome(byte[] message) {
Fence.TriggerDeviceFamilyInfo protobufFlameOut;
try {
protobufFlameOut = Fence.TriggerDeviceFamilyInfo.parseFrom(message);
} catch (Exception e) {
e.printStackTrace();
protobufFlameOut = null;
}
if (null == protobufFlameOut) {
return null;
}
Event event = new Event();
LOGGER.info("离家数据推送,设备号{}"+protobufFlameOut.getSn());
event.setSn(String.valueOf(protobufFlameOut.getSn()));
event.setDeviceType(Constants.MACHINE_LEAVE_ORDER);
event.setTime(DateUtils.parseDate(DateUtils.parseTimeStampDate(protobufFlameOut.getTriggerTime())));
if(("1").equals((protobufFlameOut.getStatus()+""))) {
event.setValue("true");
}else{
event.setValue("false");
}
return event;
}
}