107 lines
3.0 KiB
Java
107 lines
3.0 KiB
Java
package com.hivekion.room.bean;
|
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.hivekion.Global;
|
|
import com.hivekion.common.MultiPointGeoPosition;
|
|
import com.hivekion.common.entity.ResponseCmdInfo;
|
|
import com.hivekion.room.func.TaskAction;
|
|
import com.hivekion.scenario.entity.ScenarioTask;
|
|
import java.util.Map;
|
|
import java.util.TreeMap;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.ScheduledFuture;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.core.env.Environment;
|
|
|
|
/**
|
|
* [类的简要说明]
|
|
* <p>
|
|
* [详细描述,可选]
|
|
* <p>
|
|
*
|
|
* @author LiDongYU
|
|
* @since 2025/7/22
|
|
*/
|
|
@Slf4j
|
|
public class MoveRootTask extends AbtParentTask implements TaskAction {
|
|
|
|
protected final ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
|
|
1);
|
|
protected ScheduledFuture<?> scheduledFuture;
|
|
private final double SPEED = 170;
|
|
private double accumulatedDistance = 0;
|
|
|
|
public MoveRootTask(ScenarioTask scenarioTask, String roomId) {
|
|
super(scenarioTask, roomId);
|
|
}
|
|
|
|
private final Map<Double, String> distanceInfoMap = new TreeMap<Double, String>();
|
|
|
|
@Override
|
|
public void doSomeThing() {
|
|
log.info("move task running");
|
|
//累计距离
|
|
|
|
String url = SpringUtil.getBean(Environment.class).getProperty("path.planning.url");
|
|
String params = url + "?"
|
|
+ "profile=car"
|
|
+ "&point=" + scenarioTask.getFromLat() + ","
|
|
+ scenarioTask.getFromLng()
|
|
+ "&point=" + scenarioTask.getToLat() + ","
|
|
+ scenarioTask.getToLng()
|
|
+ "points_encoded=false"
|
|
+ "&algorithm=alternative_route&alternative_route.max_paths=3";
|
|
String result = webClient.get().uri(params)
|
|
.retrieve()
|
|
.bodyToMono(String.class)
|
|
.block();
|
|
JSONObject pointJson = JSON.parseObject(result);
|
|
//获取路径点
|
|
if (pointJson != null) {
|
|
JSONObject pointsObj = pointJson.getJSONArray("paths").getJSONObject(0)
|
|
.getJSONObject("points");
|
|
//推送路径任务
|
|
Global.sendCmdInfoQueue.add(
|
|
ResponseCmdInfo.create("path_init", roomId, scenarioTask.getScenarioId(), pointsObj));
|
|
JSONArray coordinates = pointsObj.getJSONArray("coordinates");
|
|
Double beforeLng = null;
|
|
Double beforeLat = null;
|
|
for (int i = 0; i < coordinates.size(); i++) {
|
|
JSONArray coordinate = coordinates.getJSONArray(i);
|
|
Double lng = coordinate.getDouble(0);
|
|
Double lat = coordinate.getDouble(1);
|
|
if (beforeLng == null && beforeLat == null) {
|
|
distanceInfoMap.put((double) 0, lng + "," + lat);
|
|
} else {
|
|
double distance = MultiPointGeoPosition.haversine(beforeLat, beforeLng, lng, lat);
|
|
distanceInfoMap.put(distance, lng + "," + lat);
|
|
}
|
|
beforeLng = lng;
|
|
beforeLat = lat;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
protected void finished() {
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void setMag(int mag) {
|
|
|
|
}
|
|
|
|
|
|
}
|