Commit bddbe436 authored by duanruiming's avatar duanruiming

[update] 测试轨迹

parent 7439d1d4
package net.wanji.web.task;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import net.wanji.web.common.constant.Constant;
import net.wanji.web.kafka.ConsumerHandler;
......@@ -12,9 +14,8 @@ import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author duanruiming
......@@ -27,20 +28,46 @@ public class RealTimeCarTask {
@Resource
private ConsumerHandler consumerHandler;
@Scheduled(fixedRate = 1000)
private static final List<TempPojo> tempList = new ArrayList<>(7);
private final AtomicInteger atomicInteger = new AtomicInteger(0);
static {
tempList.add(new TempPojo(112.967134, 28.182384));
tempList.add(new TempPojo(112.966402, 28.182420));
tempList.add(new TempPojo(112.964600, 28.182618));
tempList.add(new TempPojo(112.963046, 28.182838));
tempList.add(new TempPojo(112.963092, 28.184083));
tempList.add(new TempPojo(112.963606, 28.188246));
tempList.add(new TempPojo(112.963711, 28.189290));
}
@Scheduled(fixedRate = 2000)
public void pushRealTimeCarInfo() {
try {
Set<WebSocketServer> events = WebSocketServer.getWebSocketSet(Constant.WEBSOCKET_TOPIC_CAR_TRAIL_INFO);
for (WebSocketServer socketServer : events) {
String picLicense = socketServer.getUserId();
JNMatchResultMiniData jnMatchResultMiniData = consumerHandler.getTopicMessage("CSMatchResultMiniData_0");
if (Objects.nonNull(jnMatchResultMiniData) ) {
if (Objects.nonNull(jnMatchResultMiniData)) {
List<JNMatchResultMiniData.E1FrameParticipant> list = jnMatchResultMiniData.getE1FrameParticipant();
if (!CollectionUtils.isEmpty(list)) {
for (JNMatchResultMiniData.E1FrameParticipant e1FrameParticipant : list) {
int id = e1FrameParticipant.getId();
String license = e1FrameParticipant.getPicLicense();
if (3573 == e1FrameParticipant.getId() || StringUtils.equals(license, picLicense)) {
if (3573 == e1FrameParticipant.getId() || StringUtils.equals(license, picLicense)) {
for (int i = 0; i < tempList.size(); i++) {
if (i == atomicInteger.get()) {
atomicInteger.getAndIncrement();
if (i == 6) {
atomicInteger.set(0);
}
TempPojo tempPojo = tempList.get(i);
e1FrameParticipant.setLongitude(tempPojo.getLongitude());
e1FrameParticipant.setLatitude(tempPojo.getLatitude());
break;
}
}
socketServer.sendMessage(JSONObject.toJSONString(e1FrameParticipant));
}
}
......@@ -52,4 +79,11 @@ public class RealTimeCarTask {
}
}
@Data
@AllArgsConstructor
static class TempPojo {
private Double longitude;
private Double latitude;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment