Commit 1431b869 by huangjinxin

Merge remote-tracking branch 'origin/develop' into develop

2 parents da5ee96a 2fcb9cf6
...@@ -14,15 +14,11 @@ spring: ...@@ -14,15 +14,11 @@ spring:
uri: lb://project-gis uri: lb://project-gis
predicates: predicates:
- Path=/gis/** - Path=/gis/**
- id: district
uri: lb://project-district
predicates:
- Path=/district/**
- id: dispatch - id: dispatch
uri: lb://project-dispatch uri: lb://project-dispatch
predicates: predicates:
- Path=/dispatch/** - Path=/pea-dispatch/**
auth: auth:
path: /pea-user/**,/pea-role/**,/pea-order/**,/test/**,/v1/**,/gis/** # 需要认证的路边列表,多个用逗号连接 path: /pea-user/**,/pea-role/**,/pea-order/**,/test/**,/v1/**,/pea-dispatch/** # 需要认证的路边列表,多个用逗号连接
...@@ -25,6 +25,9 @@ public class PathController implements IPath { ...@@ -25,6 +25,9 @@ public class PathController implements IPath {
@Autowired @Autowired
OrderInfoRepository orderInfoRepository; OrderInfoRepository orderInfoRepository;
@Autowired
RoadDistanceUtils roadDistanceUtils;
@Override @Override
public Result<DistanceDTO> getRoadDistance(String fromOrderId, String toOrderId, Integer vehicleType) { public Result<DistanceDTO> getRoadDistance(String fromOrderId, String toOrderId, Integer vehicleType) {
...@@ -47,7 +50,7 @@ public class PathController implements IPath { ...@@ -47,7 +50,7 @@ public class PathController implements IPath {
return Result.failure("missing coordinates"); return Result.failure("missing coordinates");
} }
// 获取距离 // 获取距离
Distance distance = RoadDistanceUtils.getDistance( Distance distance = roadDistanceUtils.getDistance2(
new Location(0L, Float.parseFloat(fromOrders.get(0).getX()), new Location(0L, Float.parseFloat(fromOrders.get(0).getX()),
Float.parseFloat(fromOrders.get(0).getY())), Float.parseFloat(fromOrders.get(0).getY())),
new Location(0L, Float.parseFloat(toOrders.get(0).getX()), new Location(0L, Float.parseFloat(toOrders.get(0).getX()),
......
...@@ -10,11 +10,15 @@ import java.util.HashMap; ...@@ -10,11 +10,15 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.stereotype.Component;
import com.dituhui.pea.dispatch.pojo.Location; import com.dituhui.pea.dispatch.pojo.Location;
import com.dituhui.pea.dispatch.service.impl.SolveServiceImpl;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.gson.Gson; import com.google.gson.Gson;
import lombok.Data; import lombok.Data;
import lombok.extern.slf4j.Slf4j;
/** /**
* 路网组件<br> * 路网组件<br>
...@@ -24,6 +28,8 @@ import lombok.Data; ...@@ -24,6 +28,8 @@ import lombok.Data;
* @author gpzhang * @author gpzhang
* *
*/ */
@Component
@Slf4j
public class RoadDistanceUtils { public class RoadDistanceUtils {
public static String URL = "https://api.map.baidu.com/routematrix/v2/"; public static String URL = "https://api.map.baidu.com/routematrix/v2/";
...@@ -37,6 +43,40 @@ public class RoadDistanceUtils { ...@@ -37,6 +43,40 @@ public class RoadDistanceUtils {
/** /**
* 获取路网距离和时间<br> * 获取路网距离和时间<br>
*
* @param from
* @param to
* @param vehicleType 不能为空
* @return
*/
public Distance getDistance2(Location from, Location to, int vehicleType) {
try {
String key = from.getLongitude() + "," + from.getLatitude() + ";" + to.getLongitude() + ","
+ to.getLatitude() + "|" + vehicleType;
Distance distance = distanceCache.get(key);
if (null == distance) {
distance = getDistance(from.getLatitude() + "," + from.getLongitude(),
to.getLatitude() + "," + to.getLongitude(), vehicleType);
log.info(key + " " + distance);
if (null == distance) {
Distance dis = new Distance();
return dis;
} else {
distanceCache.put(key, distance);
}
return distance;
} else {
log.info(key + " from cache " + distance);
return distance;
}
} catch (Exception e) {
Distance dis = new Distance();
return dis;
}
}
/**
* 获取路网距离和时间<br>
* TODO 需要做成分布式缓存模式,这里会造成内存问题<br> * TODO 需要做成分布式缓存模式,这里会造成内存问题<br>
* TODO 调用方式需要改成批量调用方式 * TODO 调用方式需要改成批量调用方式
* *
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!