Commit 5d43834f by 111-PC\111

[+]代码整改

1 parent 5b91aa26
......@@ -8,8 +8,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
/**
* @author zhouhaibao
* @date 2021/5/6 15:19
......
......@@ -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.SmartSceneDataMapper;
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 com.alibaba.fastjson.JSON;
import com.glsx.plat.core.web.R;
......
......@@ -9,24 +9,10 @@ import org.apache.log4j.Logger;
public class ProtobufConvert {
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) {
kafkasvr.EventStateReportReq protobufIgnition = null;
kafkasvr.EventStateReportReq protobufIgnition ;
try {
protobufIgnition = kafkasvr.EventStateReportReq.parseFrom(message);
} catch (Exception e) {
......@@ -37,16 +23,20 @@ public class ProtobufConvert {
return null;
}
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.setDeviceType(Constants.MACHINE_STATUS_ORDER);
event.setValue("true");
return event;
}
// 熄火转换
/**
* 熄火转换
* @param message 入参
* @return 返回值
*/
public static Event convertFlameOut(byte[] message) {
kafkasvr.EventStateReportReq protobufFlameOut = null;
kafkasvr.EventStateReportReq protobufFlameOut;
try {
protobufFlameOut = kafkasvr.EventStateReportReq.parseFrom(message);
} catch (Exception e) {
......@@ -57,7 +47,7 @@ public class ProtobufConvert {
return null;
}
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.setDeviceType(Constants.MACHINE_STATUS_ORDER);
event.setValue("false");
......@@ -65,11 +55,15 @@ public class ProtobufConvert {
}
// 回家离家转换
/**
* 回家离家转换
*
* @param message 入参
* @return 返回值
*/
public static Event convertLeaveHome(byte[] message) {
Fence.TriggerDeviceFamilyInfo protobufFlameOut = null;
Fence.TriggerDeviceFamilyInfo protobufFlameOut;
try {
protobufFlameOut = Fence.TriggerDeviceFamilyInfo.parseFrom(message);
} catch (Exception e) {
e.printStackTrace();
......@@ -79,11 +73,11 @@ public class ProtobufConvert {
return null;
}
Event event = new Event();
LOGGER.info("离家数据推送,设备号{}"+String.valueOf(protobufFlameOut.getSn()));
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((protobufFlameOut.getStatus()+"").equals("1")) {
if(("1").equals((protobufFlameOut.getStatus()+""))) {
event.setValue("true");
}else{
event.setValue("false");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!