Commit 5d43834f by 111-PC\111

[+]代码整改

1 parent 5b91aa26
...@@ -8,8 +8,6 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -8,8 +8,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
/** /**
* @author zhouhaibao * @author zhouhaibao
* @date 2021/5/6 15:19 * @date 2021/5/6 15:19
......
...@@ -12,7 +12,6 @@ import cn.com.glsx.smartkafka.modules.mapper.DayInfoMapper; ...@@ -12,7 +12,6 @@ import cn.com.glsx.smartkafka.modules.mapper.DayInfoMapper;
import cn.com.glsx.smartkafka.modules.mapper.SmartDevideStatusMapper; import cn.com.glsx.smartkafka.modules.mapper.SmartDevideStatusMapper;
import cn.com.glsx.smartkafka.modules.mapper.SmartSceneDataMapper; import cn.com.glsx.smartkafka.modules.mapper.SmartSceneDataMapper;
import cn.com.glsx.smartkafka.modules.model.request.scene.SceneRequest; import cn.com.glsx.smartkafka.modules.model.request.scene.SceneRequest;
import cn.com.glsx.smartkafka.modules.model.response.scene.OrderResponse;
import cn.com.glsx.smartkafka.modules.utils.DateUtils; import cn.com.glsx.smartkafka.modules.utils.DateUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
......
...@@ -9,24 +9,10 @@ import org.apache.log4j.Logger; ...@@ -9,24 +9,10 @@ import org.apache.log4j.Logger;
public class ProtobufConvert { public class ProtobufConvert {
protected final static Logger LOGGER = Logger.getLogger(ProtobufConvert.class); protected final static Logger LOGGER = Logger.getLogger(ProtobufConvert.class);
// 点火
private static final String TOPIC_IGNITION = "ignition_ddbox";
// 熄火
private static final String TOPIC_FLAMEOUT = "flameout_ddbox";
public static Object convert(String topic, byte[] message) {
if (topic.contains(TOPIC_IGNITION)) {
return convertIgnition(message);
}
if (topic.contains(TOPIC_FLAMEOUT)) {
return convertFlameOut(message);
}
return null;
}
// 点火启动转换 // 点火启动转换
public static Event convertIgnition(byte[] message) { public static Event convertIgnition(byte[] message) {
kafkasvr.EventStateReportReq protobufIgnition = null; kafkasvr.EventStateReportReq protobufIgnition ;
try { try {
protobufIgnition = kafkasvr.EventStateReportReq.parseFrom(message); protobufIgnition = kafkasvr.EventStateReportReq.parseFrom(message);
} catch (Exception e) { } catch (Exception e) {
...@@ -37,16 +23,20 @@ public class ProtobufConvert { ...@@ -37,16 +23,20 @@ public class ProtobufConvert {
return null; return null;
} }
Event event = new Event(); Event event = new Event();
event.setSn(String.valueOf(protobufIgnition.getDevicesn().trim())); event.setSn(protobufIgnition.getDevicesn().trim());
event.setTime(DateUtils.parseDate(DateUtils.parseTimeStampDate(protobufIgnition.getTime()))); event.setTime(DateUtils.parseDate(DateUtils.parseTimeStampDate(protobufIgnition.getTime())));
event.setDeviceType(Constants.MACHINE_STATUS_ORDER); event.setDeviceType(Constants.MACHINE_STATUS_ORDER);
event.setValue("true"); event.setValue("true");
return event; return event;
} }
// 熄火转换 /**
* 熄火转换
* @param message 入参
* @return 返回值
*/
public static Event convertFlameOut(byte[] message) { public static Event convertFlameOut(byte[] message) {
kafkasvr.EventStateReportReq protobufFlameOut = null; kafkasvr.EventStateReportReq protobufFlameOut;
try { try {
protobufFlameOut = kafkasvr.EventStateReportReq.parseFrom(message); protobufFlameOut = kafkasvr.EventStateReportReq.parseFrom(message);
} catch (Exception e) { } catch (Exception e) {
...@@ -57,7 +47,7 @@ public class ProtobufConvert { ...@@ -57,7 +47,7 @@ public class ProtobufConvert {
return null; return null;
} }
Event event = new Event(); Event event = new Event();
event.setSn(String.valueOf(protobufFlameOut.getDevicesn().trim())); event.setSn(protobufFlameOut.getDevicesn().trim());
event.setTime(DateUtils.parseDate(DateUtils.parseTimeStampDate(protobufFlameOut.getTime()))); event.setTime(DateUtils.parseDate(DateUtils.parseTimeStampDate(protobufFlameOut.getTime())));
event.setDeviceType(Constants.MACHINE_STATUS_ORDER); event.setDeviceType(Constants.MACHINE_STATUS_ORDER);
event.setValue("false"); event.setValue("false");
...@@ -65,11 +55,15 @@ public class ProtobufConvert { ...@@ -65,11 +55,15 @@ public class ProtobufConvert {
} }
// 回家离家转换 /**
* 回家离家转换
*
* @param message 入参
* @return 返回值
*/
public static Event convertLeaveHome(byte[] message) { public static Event convertLeaveHome(byte[] message) {
Fence.TriggerDeviceFamilyInfo protobufFlameOut = null; Fence.TriggerDeviceFamilyInfo protobufFlameOut;
try { try {
protobufFlameOut = Fence.TriggerDeviceFamilyInfo.parseFrom(message); protobufFlameOut = Fence.TriggerDeviceFamilyInfo.parseFrom(message);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -79,11 +73,11 @@ public class ProtobufConvert { ...@@ -79,11 +73,11 @@ public class ProtobufConvert {
return null; return null;
} }
Event event = new Event(); Event event = new Event();
LOGGER.info("离家数据推送,设备号{}"+String.valueOf(protobufFlameOut.getSn())); LOGGER.info("离家数据推送,设备号{}"+protobufFlameOut.getSn());
event.setSn(String.valueOf(protobufFlameOut.getSn())); event.setSn(String.valueOf(protobufFlameOut.getSn()));
event.setDeviceType(Constants.MACHINE_LEAVE_ORDER); event.setDeviceType(Constants.MACHINE_LEAVE_ORDER);
event.setTime(DateUtils.parseDate(DateUtils.parseTimeStampDate(protobufFlameOut.getTriggerTime()))); event.setTime(DateUtils.parseDate(DateUtils.parseTimeStampDate(protobufFlameOut.getTriggerTime())));
if((protobufFlameOut.getStatus()+"").equals("1")) { if(("1").equals((protobufFlameOut.getStatus()+""))) {
event.setValue("true"); event.setValue("true");
}else{ }else{
event.setValue("false"); event.setValue("false");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!