|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.zhili.zkstationserver.configuration.ServerConfig;
|
|
|
import com.zhili.zkstationserver.dto.StationControlEvent;
|
|
|
import com.zhili.zkstationserver.dto.StationMessage;
|
|
|
+import com.zhili.zkstationserver.util.BytesUtil;
|
|
|
import com.zhili.zkstationserver.util.StationCenter;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.curator.framework.CuratorFramework;
|
|
@@ -16,6 +17,7 @@ import org.springframework.kafka.support.Acknowledgment;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
|
|
|
@Component
|
|
|
@Slf4j
|
|
@@ -33,13 +35,27 @@ public class KafkaMessageHandler {
|
|
|
}
|
|
|
|
|
|
@KafkaListener(topics = {"#{serverConfig.getInstanceId()}"}, groupId = "#{serverConfig.getServiceName()}")
|
|
|
- public void processExchangeEvent(ConsumerRecord<String, String> record, Acknowledgment ack){
|
|
|
- log.info("recv:"+record.value());
|
|
|
+ public void processExchangeEvent(ConsumerRecord<String, String> record, Acknowledgment ack) throws UnsupportedEncodingException {
|
|
|
+ log.info("recv************:"+record.value());
|
|
|
StationControlEvent stationControlEvent = JSON.parseObject(record.value(), StationControlEvent.class);
|
|
|
if(stationControlEvent.getType().equals("startExchange")){
|
|
|
StationMessage stationMessage = new StationMessage();
|
|
|
- stationMessage.setCommand(504);
|
|
|
- stationMessage.setData(new byte[2]);
|
|
|
+ stationMessage.setCommand(StationMessage.CommandType.START_EXCHANGE);
|
|
|
+ byte[] data = new byte[144];
|
|
|
+ BytesUtil.setSubBytes(data,0, BytesUtil.fromString(stationControlEvent.getExchangeNo(),32,(byte)0));
|
|
|
+ BytesUtil.setSubBytes(data,32, BytesUtil.fromString(stationControlEvent.getCmdNo(),32,(byte)0));
|
|
|
+ BytesUtil.setSubBytes(data,64, BytesUtil.fromIntWithLowerFirst(stationControlEvent.getControlSource(),1));
|
|
|
+ BytesUtil.setSubBytes(data,65, BytesUtil.fromIntWithLowerFirst(Integer.valueOf(stationControlEvent.getDriverId()),4));
|
|
|
+ if(stationControlEvent.getMobile()!=null){
|
|
|
+ BytesUtil.setSubBytes(data,69, BytesUtil.fromString(stationControlEvent.getMobile(),11,(byte)0));
|
|
|
+ }
|
|
|
+ if(stationControlEvent.getName()!=null){
|
|
|
+ BytesUtil.setSubBytes(data,80, BytesUtil.fromStringUnicode(stationControlEvent.getName(),32,(byte)0));
|
|
|
+ }
|
|
|
+ if(stationControlEvent.getFleetName()!=null){
|
|
|
+ BytesUtil.setSubBytes(data,112, BytesUtil.fromStringUnicode(stationControlEvent.getFleetName(),32,(byte)0));
|
|
|
+ }
|
|
|
+ stationMessage.setData(data);
|
|
|
StationCenter.sendToChannel(stationControlEvent.getStationConnInfo().getConnIdStr(),stationMessage);
|
|
|
}
|
|
|
ack.acknowledge();
|