|
@@ -226,4 +226,98 @@ class PathStrategyDataService {
|
|
|
return algPathStrategyInputData
|
|
|
}
|
|
|
|
|
|
+ @BizApiMethod(matchedApis = ThreeConstant.BIZ_API_NAME, desc = "查询数据")
|
|
|
+ Map<String, Object> queryAllTransTo(@BizRequestPm(key = "mapId", nullable = false, desc = "底图ID") String mapId) throws Exception {
|
|
|
+ AlgPathStrategyInputData algPathStrategyInputData = queryAll(mapId)
|
|
|
+ Map<String, Object> reMap = new HashMap<>()
|
|
|
+ AlgBaseMap algBaseMap = algPathStrategyInputData.getAlgBaseMap()
|
|
|
+ List<AlgObstacle> algObstacleList = algPathStrategyInputData.getAlgObstacleList()
|
|
|
+ if (algBaseMap != null && algObstacleList != null) {
|
|
|
+ // blocks
|
|
|
+ String[] pcss = algBaseMap.getPcsBorder().split(";")
|
|
|
+ int max = Integer.MIN_VALUE;
|
|
|
+ for (String pcs : pcss) {
|
|
|
+ String[] ps = pcs.split(",")
|
|
|
+ for (String p : ps) {
|
|
|
+ int pp = (int) Double.parseDouble(p)
|
|
|
+ if (pp > max) {
|
|
|
+ max = pp;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> blocks = new ArrayList<>()
|
|
|
+ for (int i = 1; i <= max; i++) {
|
|
|
+ for (int j = 1; j <= max; j++) {
|
|
|
+ Map<String, Object> blockMap = new HashMap<>()
|
|
|
+ blockMap.put("id", ((i - 1) * max + j) + "")
|
|
|
+ blockMap.put("x", i)
|
|
|
+ blockMap.put("y", j)
|
|
|
+ boolean fg = false;
|
|
|
+ for (AlgObstacle algObstacle : algObstacleList) {
|
|
|
+ // 解析坐标
|
|
|
+ int[] point = [i, j];
|
|
|
+ double[] polygon = parsePolygonString(algObstacle.getPcsBorder());
|
|
|
+ // 判断点是否在多边形内
|
|
|
+ if (isPointInPolygon(polygon, point[0], point[1])) {
|
|
|
+ fg = true;
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ blockMap.put("isObstacle", fg)
|
|
|
+ blocks.add(blockMap)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reMap.put("blocks", blocks)
|
|
|
+ // tasks
|
|
|
+ List<Map<String, Object>> tasks = new ArrayList<>()
|
|
|
+ List<AlgVehicleTask> algVehicleTaskList = algPathStrategyInputData.getAlgVehicleTaskList()
|
|
|
+ for (int i = 1; i <= algVehicleTaskList.size(); i++) {
|
|
|
+ AlgVehicleTask algVehicleTask = algVehicleTaskList.get(i - 1)
|
|
|
+ Map<String, Object> taskMap = new HashMap<>()
|
|
|
+ taskMap.put("id", algVehicleTask.getVehicleNo())
|
|
|
+ String[] sp = algVehicleTask.getStartPosition().split(",")
|
|
|
+ int fi = (int) Double.parseDouble(sp[0])
|
|
|
+ int fj = (int) Double.parseDouble(sp[1])
|
|
|
+ taskMap.put("from", ((fi - 1) * max + fj) + "")
|
|
|
+ String[] ep = algVehicleTask.getStartPosition().split(",")
|
|
|
+ int ti = (int) Double.parseDouble(ep[0])
|
|
|
+ int tj = (int) Double.parseDouble(ep[1])
|
|
|
+ taskMap.put("to", ((ti - 1) * max + tj) + "")
|
|
|
+ taskMap.put("beginTime", i)
|
|
|
+ tasks.add(taskMap)
|
|
|
+ }
|
|
|
+ reMap.put("tasks", tasks)
|
|
|
+ }
|
|
|
+ return reMap
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析点坐标字符串
|
|
|
+
|
|
|
+ // 解析多边形顶点坐标字符串
|
|
|
+ private static double[] parsePolygonString(String polygonStr) {
|
|
|
+ String[] vertexStrs = polygonStr.split(";");
|
|
|
+ double[] vertices = new double[vertexStrs.length * 2];
|
|
|
+ for (int i = 0; i < vertexStrs.length; i++) {
|
|
|
+ String[] coords = vertexStrs[i].split(",");
|
|
|
+ vertices[i * 2] = Double.parseDouble(coords[0]);
|
|
|
+ vertices[i * 2 + 1] = Double.parseDouble(coords[1]);
|
|
|
+ }
|
|
|
+ return vertices;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断点是否在多边形内
|
|
|
+ public static boolean isPointInPolygon(double[] polygon, int pointX, int pointY) {
|
|
|
+ int n = (int) (polygon.length / 2);
|
|
|
+ boolean c = false;
|
|
|
+ for (int i = 0, j = n - 1; i < n; i++) {
|
|
|
+ if ((polygon[2 * i + 1] > pointY) != (polygon[2 * j + 1] > pointY) &&
|
|
|
+ pointX < (polygon[2 * j] - polygon[2 * i]) * (pointY - polygon[2 * i + 1]) /
|
|
|
+ (polygon[2 * j + 1] - polygon[2 * i + 1]) + polygon[2 * i]) {
|
|
|
+ c = !c;
|
|
|
+ }
|
|
|
+ j = i;
|
|
|
+ }
|
|
|
+ return c;
|
|
|
+ }
|
|
|
+
|
|
|
}
|