Browse Source

重新逻辑修改 , 允许四维看看多少重算

wuweihao 4 years ago
parent
commit
0123f5046a

+ 274 - 35
laser/src/main/java/com/fdkankan/indoor/base/convert/GetRoute.java

@@ -13,8 +13,7 @@ import com.fdkankan.indoor.core.entity.dto.RouteInputDto;
 import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
 
-public class GetRoute
-{
+public class GetRoute {
 
 	/*
 	public static void main(String[] args)
@@ -46,30 +45,9 @@ public class GetRoute
 	}
 	*/
 
-
-	/**
-	 * 读取文件,获取文件内容
-	 *   F:\test\project\age_laser\routeMap.txt
-	 *
-	 *   list 是routeMap的结果集
-	 * @return
-	 */
-	public static JSONArray getRoute(List<String> list, RouteInputDto dto, ControlPointEntity controlPoint){
-		try {
-			JSONArray maps = readMap(list, dto);
-			MapInfo info=new MapInfo(maps,start,end);
-			List<Node> path = g_AStar.start(info);
-			JSONArray jsonArray = convertFromPath(path, dto, controlPoint);
-			return jsonArray;
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		return null;
-	}
-	
-//	public static String inputFilePath = "F:\\2021\\navvis\\���Ի���\\test3(v2.7.3)\\map.txt";
+	//	public static String inputFilePath = "F:\\2021\\navvis\\���Ի���\\test3(v2.7.3)\\map.txt";
 	private static String inputFilePath = "F:\\test\\project\\age_laser\\routeMap.txt";
-	
+
 //	private static float startX = 5.358192084229412f;
 //	private static float startY = -7.905951689748807f;
 //	private static float startZ = -1.3145928255248511f;
@@ -88,11 +66,109 @@ public class GetRoute
 
 	private static int minStartId = -1;
 	private static int minEndId = -1;
-	
+
 	private static Node start = null;
 	private static Node end = null;
 	private static AStar g_AStar = new AStar();
 
+
+	/**
+	 * 读取文件,获取文件内容
+	 *   F:\test\project\age_laser\routeMap.txt
+	 *
+	 *   list 是routeMap的结果集
+	 * @return
+	 */
+	public static JSONArray getRoute(List<String> list, RouteInputDto dto, ControlPointEntity controlPoint){
+		try {
+			JSONArray maps = readMap(list, dto);
+			MapInfo info=new MapInfo(maps,start,end);
+			List<Node> path = g_AStar.start(info);
+			JSONArray jsonArray = convertFromPath(path, dto, controlPoint);
+			return jsonArray;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+//	private static JSONArray readMap(List<String> list, RouteInputDto dto) throws Exception {
+////    List<String> list = FileUtil.readFileByLines2(inputFilePath);
+//		JSONArray maps = new JSONArray();
+//
+//		Double startX = dto.getSource_longitude();
+//		Double startY = dto.getSource_latitude();
+//		Double startZ = dto.getSource_z();
+//
+//		Double endX = dto.getDestination_longitude();
+//		Double endY = dto.getDestination_latitude();
+//		Double endZ = dto.getDestination_z();
+//
+//
+//		Coord _start = new Coord(startX,startY,startZ);
+//		Coord _end = new Coord(endX,endY,endZ);
+//
+//		double startDistance=1.5;
+//		double endDistance = 1.5;
+//
+//		double minStartDistance = 1000.0;
+//		double minEndDistance = 1000.0;
+//
+//		for(int i=0;i<list.size();++i) {
+//			String str = list.get(i);
+//			String[] strArray = str.trim().split(" ");
+//			JSONObject item = new JSONObject();
+//			//item.put("id", i);
+//			item.put("x", strArray[0]);
+//			item.put("y", strArray[1]);
+//			item.put("z", strArray[2]);
+//			//item.put("weight", strArray[3]);
+//			item.put("weight", 1);
+//			String linkedIds = "";
+//			for(int j = 4;j<strArray.length;++j) {
+//				if(Integer.valueOf(strArray[j])>0) {
+//					linkedIds += strArray[j]+",";
+//				}
+//			}
+//
+//			item.put("linkedIds", linkedIds.substring(0, linkedIds.length()-1));
+//			maps.add(item);
+//
+//			Coord coord = new Coord(Double.valueOf(strArray[0]),Double.valueOf(strArray[1]),Double.valueOf(strArray[2]));
+//			//先找起点附近的点
+//			double _startDistance = g_AStar.calcH(_start, coord);
+//
+//
+//			if(_startDistance<startDistance) {
+//				//附近点里,离终点的距离最小的
+//				if(minStartDistance>g_AStar.calcH(_end, coord)){
+//					minStartId = i;
+//					minStartDistance = g_AStar.calcH(_end, coord);
+//				}
+//			}
+//			//先找终点附近的点
+//			double _endDistance = g_AStar.calcH(_end, coord);
+//			if(_endDistance<endDistance) {
+//				//附近点里,离起点的距离最小的
+//				if(minEndDistance>g_AStar.calcH(_start, coord)){
+//					minEndId = i;
+//					minEndDistance = g_AStar.calcH(_start, coord);
+//				}
+//			}
+//		}
+//
+//		JSONObject virtualStart = maps.getJSONObject(minStartId);
+//		JSONObject virtualEnd = maps.getJSONObject(minEndId);
+//		Coord startVirtualCoord = new Coord(virtualStart.getDouble("x"), virtualStart.getDouble("y"),virtualStart.getDouble("z"));
+//		Coord endVirtualCoord = new Coord(virtualEnd.getDouble("x"), virtualEnd.getDouble("y"),virtualEnd.getDouble("z"));
+//		Double startH = g_AStar.calcH(startVirtualCoord, endVirtualCoord);
+//
+//		start = new Node(minStartId,0.0,startVirtualCoord, null, 0.0, startH);
+//		end = new Node(minEndId,0.0,endVirtualCoord, null, 0.0, 0.0);
+//
+//		return maps;
+//	}
+
 	private static JSONArray readMap(List<String> list, RouteInputDto dto) throws Exception {
 //		List<String> list = FileUtil.readFileByLines2(inputFilePath);
 		JSONArray maps = new JSONArray();
@@ -157,7 +233,9 @@ public class GetRoute
 		return maps;
 	}
 
+
 	private static JSONArray convertFromPath(List<Node> mappath, RouteInputDto dto, ControlPointEntity controlPoint) {
+		double defaultdistance = 0.36;
 		if(mappath == null||mappath.size() == 0) {
 			return null;
 		}
@@ -172,10 +250,43 @@ public class GetRoute
 		Double endY = dto.getDestination_latitude();
 		Double endZ = dto.getDestination_z();
 
+		if(mappath.size()>5){
+
+			//从前三个和后三个路径点开始优化,防止绕来绕去
+			Node tempNode = mappath.get(mappath.size()-2);
+			double dis = g_AStar.calcH(tempNode.coord,new Coord(startX,startY,startZ));
+			if(dis<defaultdistance){
+				mappath.remove(mappath.size()-1);
+			}
+
+			tempNode = mappath.get(mappath.size()-2);
+			dis = g_AStar.calcH(tempNode.coord,new Coord(startX,startY,startZ));
+			if(dis<defaultdistance){
+				mappath.remove(mappath.size()-1);
+			}
+
+			tempNode = mappath.get(0);
+			dis = g_AStar.calcH(tempNode.coord,new Coord(startX,startY,startZ));
+			if(dis<defaultdistance){
+				mappath.remove(0);
+			}
+
+			tempNode = mappath.get(0);
+			dis = g_AStar.calcH(tempNode.coord,new Coord(startX,startY,startZ));
+			if(dis<defaultdistance){
+				mappath.remove(0);
+			}
+		}
 
 		List<Node> path = new ArrayList<Node>();
-		for(int i = mappath.size()-1;i>-1;--i) {
+//		for(int i = mappath.size()-1;i>-1;--i) {
+//			Node node = mappath.get(i);
+//			path.add(node);
+//		}
+
+		for(int i = mappath.size()-1;i>-1;) {
 			Node node = mappath.get(i);
+			i -= 3;
 			path.add(node);
 		}
 
@@ -183,8 +294,7 @@ public class GetRoute
 
 		//起点不在path上,path的第一个点对应的是格子
 		JSONObject start = new JSONObject();
-//		start.put("longitude", startX);
-//		start.put("latitude", startY);
+
 
 		double[] startPosition = {startX,startY};
 		startPosition = TransformGPS.convert(startPosition, controlPoint);
@@ -192,8 +302,7 @@ public class GetRoute
 		start.put("latitude", startPosition[1]);
 		start.put("z", startZ);
 		Double[] location = new Double[3];
-//		location[0] = startX;
-//		location[1] = startY;
+
 
 		location[0] = startPosition[0];
 		location[1] = startPosition[1];
@@ -216,12 +325,10 @@ public class GetRoute
 			item.put("longitude", position[0]);
 			item.put("latitude", position[1]);
 
-//			item.put("longitude", node.coord.x);
-//			item.put("latitude", node.coord.y);
+
 			item.put("z", node.coord.z);
 			location = new Double[3];
-//			location[0] = node.coord.x;
-//			location[1] = node.coord.y;
+
 
 			location[0] = position[0];
 			location[1] = position[1];
@@ -289,6 +396,138 @@ public class GetRoute
 		return route;
 	}
 
+//	private static JSONArray convertFromPath(List<Node> mappath, RouteInputDto dto, ControlPointEntity controlPoint) {
+//		if(mappath == null||mappath.size() == 0) {
+//			return null;
+//		}
+//
+//		// 起始点
+//		Double startX = dto.getSource_longitude();
+//		Double startY = dto.getSource_latitude();
+//		Double startZ = dto.getSource_z();
+//
+//		// 终点
+//		Double endX = dto.getDestination_longitude();
+//		Double endY = dto.getDestination_latitude();
+//		Double endZ = dto.getDestination_z();
+//
+//
+//		List<Node> path = new ArrayList<Node>();
+//		for(int i = mappath.size()-1;i>-1;--i) {
+//			Node node = mappath.get(i);
+//			path.add(node);
+//		}
+//
+//		JSONArray route = new JSONArray();
+//
+//		//起点不在path上,path的第一个点对应的是格子
+//		JSONObject start = new JSONObject();
+////		start.put("longitude", startX);
+////		start.put("latitude", startY);
+//
+//		double[] startPosition = {startX,startY};
+//		startPosition = TransformGPS.convert(startPosition, controlPoint);
+//		start.put("longitude", startPosition[0]);
+//		start.put("latitude", startPosition[1]);
+//		start.put("z", startZ);
+//		Double[] location = new Double[3];
+////		location[0] = startX;
+////		location[1] = startY;
+//
+//		location[0] = startPosition[0];
+//		location[1] = startPosition[1];
+//		location[2] = startZ;
+//
+//		start.put("location", location);
+//		start.put("distance", 0);
+//		start.put("distance_to_previous", 0);
+//		start.put("instruction", null);
+//		route.add(start);
+//
+//		Double[] virtualEndPosition = new Double[3];
+//		for(int i=0;i<path.size();++i) {
+//			Node node = path.get(i);
+//			JSONObject item = new JSONObject();
+//
+//			//转经纬度
+//			double[] position = {node.coord.x,node.coord.y};
+//			position = TransformGPS.convert(position, controlPoint);
+//			item.put("longitude", position[0]);
+//			item.put("latitude", position[1]);
+//
+////			item.put("longitude", node.coord.x);
+////			item.put("latitude", node.coord.y);
+//			item.put("z", node.coord.z);
+//			location = new Double[3];
+////			location[0] = node.coord.x;
+////			location[1] = node.coord.y;
+//
+//			location[0] = position[0];
+//			location[1] = position[1];
+//
+//			location[2] = node.coord.z;
+//			item.put("location", location);
+//			item.put("id", node.id);
+//
+//			JSONObject instruction = null;
+//
+//			if(i == 0) {
+//				item.put("distance", g_AStar.calcH(node.coord,new Coord(startX,startY,startZ)));
+//				item.put("distance_to_previous", g_AStar.calcH(node.coord,new Coord(startX,startY,startZ)));
+//				item.put("instruction", instruction);
+//
+//				instruction = new JSONObject();
+//				instruction.put("type", "source_projection_to_navgraph");
+//				item.put("instruction", instruction);
+//			}
+//			else {
+//				Node prenode = path.get(i-1);
+//				JSONObject preitem = route.getJSONObject(i);
+//				Double distance_to_previous = g_AStar.calcH(node.coord,prenode.coord);
+//				item.put("distance_to_previous", distance_to_previous);
+//				Double distance = preitem.getDouble("distance")+distance_to_previous;
+//				item.put("distance", distance);
+//				if(i == path.size()-1) {
+//					instruction = new JSONObject();
+//					instruction.put("type", "destination_projection_to_navgraph");
+//					item.put("instruction", instruction);
+//
+//					virtualEndPosition[0] = node.coord.x;
+//					virtualEndPosition[1] = node.coord.y;
+//					virtualEndPosition[2] = node.coord.z;
+//
+//				}
+//				else {
+//					item.put("instruction", instruction);
+//				}
+//				System.out.println("distance:"+distance_to_previous);
+//			}
+//
+//			route.add(item);
+//		}
+//
+//		JSONObject endItem = route.getJSONObject(route.size()-1);
+//		JSONObject end = new JSONObject();
+//		double[] endPosition = {endX,endY};
+//		endPosition = TransformGPS.convert(endPosition, controlPoint);
+//
+//		end.put("longitude", endPosition[0]);
+//		end.put("latitude", endPosition[1]);
+//		end.put("z", endZ);
+//		location = new Double[3];
+//		location[0] = endPosition[0];
+//		location[1] = endPosition[1];
+//		location[2] = endZ;
+//		end.put("location", location);
+//		Double enddistance = g_AStar.calcH(new Coord(virtualEndPosition[0],virtualEndPosition[1],virtualEndPosition[2]),new Coord(endX,endY,endZ));
+//		end.put("distance", enddistance+(float)endItem.getDouble("distance"));
+//		end.put("distance_to_previous", enddistance);
+//		end.put("instruction", null);
+//		route.add(end);
+//
+//		return route;
+//	}
+
 
 	private static JSONArray readMap() throws Exception {
 		List<String> list = FileUtil.readFileByLines2(inputFilePath);

+ 6 - 1
laser/src/main/java/com/fdkankan/indoor/base/convert/kesar/AStar.java

@@ -90,7 +90,12 @@ public class AStar
 			{
 				Node end=mapInfo.end;
 				//Coord coord = new Coord(x, y);
-				Double G = current.G + current.weight; // 计算邻结点的G值
+				//Double G = current.G + current.weight; // 计算邻结点的G值
+
+				JSONObject linkedNode = mapInfo.maps.getJSONObject(linkedId);
+				double weight = calcH(current.coord,new Coord(linkedNode.getDouble("x"),linkedNode.getDouble("y"),linkedNode.getDouble("z")));
+				Double G = current.G + weight; // 计算邻结点的G值
+				//Double G = current.G + current.weight; // 计算邻结点的G值
 				Node child = findNodeInOpen(linkedId);
 				if (child == null)
 				{

+ 3 - 3
laser/src/main/java/com/fdkankan/indoor/core/controller/InitController.java

@@ -37,8 +37,8 @@ public class InitController {
     @WebControllerLog(description = "创建初始数据")
     @ApiOperation(value = "创建初始数据")
     @GetMapping("indoor/{sceneCode}/api/init")
-    public Result initData(@PathVariable String sceneCode, String path) {
-        return initService.initData(sceneCode, path, "age");
+    public Result initData(@PathVariable String sceneCode, String path, String title) {
+        return initService.initData(sceneCode, path, "age", title);
     }
 
     @WebControllerLog(description = "删除初始化数据")
@@ -48,7 +48,7 @@ public class InitController {
         return  initService.testRemove(sceneCode);
     }
 
-    @WebControllerLog(description = "重算场景")
+    @WebControllerLog(description = "手动重算场景")
     @ApiOperation(value = "重算场景")
     @GetMapping("indoor/{sceneCode}/api/initRecount")
     public Result initRecount(@PathVariable String sceneCode){

+ 4 - 0
laser/src/main/java/com/fdkankan/indoor/core/controller/RouteController.java

@@ -25,6 +25,10 @@ public class RouteController {
 
     /**
      * http://192.168.0.135:9294/indoor/test3/api/route?destination_latitude=-3.3754012098200965&destination_longitude=-2.143694831230416&destination_z=-1.1803865408990568&source_latitude=-7.905951689748807&source_longitude=5.358192084229412&source_z=-1.3145928255248511
+     *
+     * http://192.168.0.135:9294/indoor/t-vFElhv8/api/route?destination_latitude=-3.3754012098200965&destination_longitude=-2.143694831230416&destination_z=-1.1803865408990568&source_latitude=-7.905951689748807&source_longitude=5.358192084229412&source_z=-1.3145928255248511
+     *
+     * http://192.168.0.135:9294/indoor/t-iksBApb/api/route?destination_latitude=4.7298610693198135&destination_longitude=1.66892876971179&destination_z=-2.769043712143716&source_latitude=1.6655948019557476&source_longitude=-3.8255355848162087&source_z=-1.320309108746421
      * @param sceneCode
      * @param param
      * @return

+ 17 - 0
laser/src/main/java/com/fdkankan/indoor/core/controller/TestController.java

@@ -136,5 +136,22 @@ public class TestController {
     }
 
 
+    @ApiOperation("poi_type_group-读模板文件")
+    @GetMapping("poiTypeGroup/{sceneCode}")
+    public Result poiTypeGroup(@PathVariable String sceneCode){
+        return  owenService.readPoiTypeGroup(sceneCode);
+
+
+    }
+
+    @ApiOperation("controlPoint.json-读模板文件")
+    @GetMapping("controlPoint/{sceneCode}")
+    public Result controlPoint(@PathVariable String sceneCode){
+        return  owenService.controlPoint(sceneCode);
+
+
+    }
+
+
 
 }

+ 3 - 0
laser/src/main/java/com/fdkankan/indoor/core/entity/InitEntity.java

@@ -33,4 +33,7 @@ public class InitEntity {
 
     @ApiModelProperty(value = "重算次数")
     private Integer recount;
+
+    @ApiModelProperty(value = "标题" )
+    private String title;
 }

+ 1 - 1
laser/src/main/java/com/fdkankan/indoor/core/service/InitService.java

@@ -9,7 +9,7 @@ import java.util.List;
  * Created by owen on 2021/7/28 0028 9:10
  */
 public interface InitService {
-    Result initData(String sceneCode, String path, String from);
+    Result initData(String sceneCode, String path, String from, String title);
 
     void initDataStep2(String sceneCode);
 

+ 4 - 0
laser/src/main/java/com/fdkankan/indoor/core/service/OwenService.java

@@ -16,4 +16,8 @@ public interface OwenService {
     Result list();
 
     Result delete(String id);
+
+    Result readPoiTypeGroup(String sceneCode);
+
+    Result controlPoint(String sceneCode);
 }

+ 121 - 23
laser/src/main/java/com/fdkankan/indoor/core/service/impl/InitServiceImpl.java

@@ -89,12 +89,13 @@ public class InitServiceImpl implements InitService {
      * 有顺序分,不能乱
      * @param sceneCode
      * @param path
-     * @param from:age  四维看看重算,其他:手动重算
+     * @param from :age  四维看看重算,其他:手动重算
      *
+     * @param title
      * @return
      */
     @Override
-    public Result initData(String sceneCode, String path, String from) {
+    public Result initData(String sceneCode, String path, String from, String title) {
 
         if (StrUtil.isAllEmpty(sceneCode)) {
             return Result.failure("场景码不能为空");
@@ -103,22 +104,30 @@ public class InitServiceImpl implements InitService {
         // 防止为四维看看重复调用重算
         InitEntity init = findById(sceneCode);
         if (init != null) {
-            if ("age".equals(from)){
-                log.error("场景:[{}] 已存在,不需要重算", sceneCode);
-                return Result.failure(MsgCode.e3001, "场景已存在,不需要重算:" + sceneCode);
-            }
+//            if ("age".equals(from)){
+//                log.error("场景:[{}] 已存在,不需要重算", sceneCode);
+//                return Result.failure(MsgCode.e3001, "场景已存在,不需要重算:" + sceneCode);
+//            }
 
             // 重算
             if ("recount".equals(from)){
                 path = init.getPath();
+                title = init.getTitle();
             }
         }
 
+        // 删除旧数据, 重算使用
+        initRemove(sceneCode);
+
         // 路径在这里检测
         if (StrUtil.isAllEmpty(path)) {
             return Result.failure("路径不能为空");
         }
 
+        if (StrUtil.isAllEmpty(title)) {
+            return Result.failure("标题不能为空");
+        }
+
 
         String laserDataPath = path + "/laserData";
         log.info("laserDataPath: {}", laserDataPath);
@@ -139,20 +148,42 @@ public class InitServiceImpl implements InitService {
         copyDefault(sceneCode);
 
 
-         //step8 替换index.html、/locat/addDataSet.html的场景码, @replace
-        replaceHtml(sceneCode);
+         //step8 替换index.html、/locat/addDataSet.html的场景码, @replace, @title
+        replaceHtml(sceneCode, title);
 
         // step9 创建 t_measurement表, 测量表,空数据
         createMeasurement(sceneCode);
 
+
+        /**
+         * 这方法很重要, 会自动初始化initData2 的说有方法
+         * step10 创建控制点表 t_controlPoint, 读取服务器controlPoint.json文件
+         */
+
+        String controlPointPath = laserDataPath + "/controlPoint.json";
+        log.info("控制点文件路径:{}", controlPointPath);
+        boolean flag = false;
+        if (cn.hutool.core.io.FileUtil.exist(controlPointPath)){
+            log.info("处理控制点逻辑");
+            createControlPoint(sceneCode, laserDataPath);
+            flag = true;
+        } else {
+            log.info("控制点文件不存在:{}", controlPointPath);
+        }
+
+
+
+
         // 保存initDataStep1 状态
         if (init == null) {
              init = new InitEntity();
             init.setId(sceneCode);
             init.setPath(path);
             init.setCreateTime(LocalDateTime.now());
+            init.setTitle(title);
         } else {
             init.setUpdateTime(LocalDateTime.now());
+            init.setTitle(title);
             Integer recount = init.getRecount();
             recount = recount == null ? 1 : recount + 1;
             init.setRecount(recount);
@@ -160,18 +191,61 @@ public class InitServiceImpl implements InitService {
 
         init.setStatus(0);
         initMapper.save(init);
-        log.info("initDataStep_1处理完成");
+
+        if (flag){
+            log.info("完全初始化完成");
+        } else {
+            log.info("initDataStep_1处理完成");
+        }
 
         return Result.success();
     }
 
-    private void createMeasurement(String sceneCode) {
-        MeasurementEntity entity = new MeasurementEntity();
-        entity.setCreateTime(LocalDateTime.now());
+    /**
+     * 初始化控制点
+     * @param sceneCode
+     * @param laserDataPath
+     */
+    private void createControlPoint(String sceneCode, String laserDataPath) {
+        String path = laserDataPath + "/controlPoint.json";
+        if (!cn.hutool.core.io.FileUtil.exist(path)){
+            throw new BaseRuntimeException("控制点文件不存在: " + path);
+        }
+
+        String s = cn.hutool.core.io.FileUtil.readUtf8String(path);
+        com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(s);
+        com.alibaba.fastjson.JSONArray points = jsonObject.getJSONArray("points");
+
+        com.alibaba.fastjson.JSONObject poi_1 = points.getJSONObject(0);
+        com.alibaba.fastjson.JSONObject poi_2 = points.getJSONObject(1);
+
+        // 第一个点
+        double gpsLat_1 = poi_1.getJSONObject("coordinate").getDouble("latitude");
+        double gpsLon_1 = poi_1.getJSONObject("coordinate").getDouble("longitude");
+        double ageX_1 = poi_1.getJSONObject("location").getDouble("x");
+        double ageY_1 = poi_1.getJSONObject("location").getDouble("y");
+
+        // 第二个点
+        double gpsLat_2 = poi_2.getJSONObject("coordinate").getDouble("latitude");
+        double gpsLon_2 = poi_2.getJSONObject("coordinate").getDouble("longitude");
+        double ageX_2 = poi_2.getJSONObject("location").getDouble("x");
+        double ageY_2 = poi_2.getJSONObject("location").getDouble("y");
+
+        double[] gpsCoord1 = {gpsLat_1, gpsLon_1};
+        double[] gpsCoord2 = {gpsLat_2, gpsLon_2};
+        double[] ageLocation1 = {ageX_1, ageY_1};
+        double[] ageLocation2 = {ageX_2, ageY_2};
+
+        ControlPointEntity entity = new ControlPointEntity();
+        entity.setGpsControlCoordinate1(gpsCoord1);
+        entity.setGpsControlCoordinate2(gpsCoord2);
+        entity.setAgeControlLocation1(ageLocation1);
+        entity.setAgeControlLocation2(ageLocation2);
+
         entity.setId(sceneCode);
-        entity.setData(new ArrayList<>());
-        measurementService.save(entity);
-        log.info("初始化Measurement完成");
+        entity.setCreateTime(LocalDateTime.now());
+        controlPointService.save(entity);
+        log.info("controlPoint控制点初始化完成");
     }
 
 
@@ -226,6 +300,10 @@ public class InitServiceImpl implements InitService {
     }
 
 
+
+
+
+
     /**
      * 输入控制点,需要把相关数据从新初始化
      * @param sceneCode
@@ -250,11 +328,11 @@ public class InitServiceImpl implements InitService {
     public Result initRecount(String sceneCode) {
 
         // 删除旧数据
-        this.initRemove(sceneCode);
+//        this.initRemove(sceneCode);
 
 
         // 重新初始化数据, 地址在里面处理
-        this.initData(sceneCode, null, "recount");
+        this.initData(sceneCode, null, "recount", null);
 
 
         // 记录重算日志
@@ -272,30 +350,48 @@ public class InitServiceImpl implements InitService {
      * index.html
      * /locat/addDataSet.html
      * @param sceneCode
+     * @param title
      */
-    private void replaceHtml(String sceneCode) {
+    private void replaceHtml(String sceneCode, String title) {
         String indexName = "index.html";
-        String addDataSetName = "addDataSet.html";
+//        String addDataSetName = "addDataSet.html";
 
         String basePath = configConstant.serverBasePath + "/" + sceneCode + "/" ;
         String indexPath = basePath + indexName;
-        String addDateSetPath = basePath + "locat/" + addDataSetName;
+//        String addDateSetPath = basePath + "locat/" + addDataSetName;
 
         String indexStr = cn.hutool.core.io.FileUtil.readUtf8String(indexPath);
-        String dataSetStr = cn.hutool.core.io.FileUtil.readUtf8String(addDateSetPath);
+//        String dataSetStr = cn.hutool.core.io.FileUtil.readUtf8String(addDateSetPath);
         if (!indexStr.contains("@replace")) {
             throw new BaseRuntimeException(MsgCode.e3001, "index.html不包含默认值, 请查看default文件是否正确");
         }
+
+//        if (!dataSetStr.contains("@replace")) {
+//            throw new BaseRuntimeException(MsgCode.e3001, "addDataSet.html不包含默认值, 请查看default文件是否正确");
+//        }
+
         indexStr = indexStr.replaceAll("@replace", sceneCode);
-        dataSetStr = dataSetStr.replaceAll("@replace", sceneCode);
+        indexStr = indexStr.replaceAll("@title", title);
+//        dataSetStr = dataSetStr.replaceAll("@replace", sceneCode);
 
         cn.hutool.core.io.FileUtil.writeUtf8String(indexStr, indexPath);
-        cn.hutool.core.io.FileUtil.writeUtf8String(dataSetStr, addDateSetPath);
+//        cn.hutool.core.io.FileUtil.writeUtf8String(dataSetStr, addDateSetPath);
         log.info("html文件替完成");
 
     }
 
 
+    private void createMeasurement(String sceneCode) {
+        MeasurementEntity entity = new MeasurementEntity();
+        entity.setCreateTime(LocalDateTime.now());
+        entity.setId(sceneCode);
+        entity.setData(new ArrayList<>());
+        measurementService.save(entity);
+        log.info("初始化Measurement完成");
+    }
+
+
+
     /**
      * 复制静态资源
      * @param sceneCode
@@ -630,6 +726,8 @@ public class InitServiceImpl implements InitService {
     }
 
 
+
+
     /**
      * 初始化DataSet
      * location: 原点坐标(特殊点表)

+ 71 - 0
laser/src/main/java/com/fdkankan/indoor/core/service/impl/OwenServiceImpl.java

@@ -1,14 +1,27 @@
 package com.fdkankan.indoor.core.service.impl;
 
+import cn.hutool.core.io.FileUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.indoor.base.constant.ConfigConstant;
 import com.fdkankan.indoor.base.util.Result;
+import com.fdkankan.indoor.core.entity.ControlPointEntity;
 import com.fdkankan.indoor.core.entity.OwenEntity;
+import com.fdkankan.indoor.core.entity.PoiTypeEntity;
+import com.fdkankan.indoor.core.entity.PoiTypeGroupEntity;
+import com.fdkankan.indoor.core.entity.dto.PoiTypeDto;
+import com.fdkankan.indoor.core.entity.dto.PoiTypeGroupDto;
 import com.fdkankan.indoor.core.mapper.OwenMapper;
 import com.fdkankan.indoor.core.service.OwenService;
+import com.fdkankan.indoor.core.service.PoiTypeGroupService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.time.LocalDateTime;
+import java.util.List;
+
 /**
  * Created by owen on 2021/7/28 0028 20:05
  */
@@ -19,6 +32,12 @@ public class OwenServiceImpl implements OwenService {
     @Autowired
     OwenMapper entityMapper;
 
+    @Autowired
+    ConfigConstant configConstant;
+
+    @Autowired
+    PoiTypeGroupService poiTypeGroupService;
+
     /**
      * save: 新增或修改,若id存在侧修改, id不存在则新增
      * @param
@@ -69,5 +88,57 @@ public class OwenServiceImpl implements OwenService {
         return Result.success();
     }
 
+    @Override
+    public Result readPoiTypeGroup(String sceneCode) {
+
+        PoiTypeGroupEntity entity = new PoiTypeGroupEntity();
+        entity.setId(sceneCode);
+        entity.setUpdateTime(LocalDateTime.now());
+        // 读取初始文件
+        String resourceContent = cn.hutool.core.io.FileUtil.readUtf8String(configConstant.templatePath + "/poi_type_group.json");
+        List<PoiTypeGroupDto> dtoList = com.alibaba.fastjson.JSONArray.parseArray(resourceContent, PoiTypeGroupDto.class);
+        entity.setData(dtoList);
+        poiTypeGroupService.save(entity);
+        log.info("PoiTypeGroup数据初始化创建完成");
+        return Result.success(dtoList);
+    }
+
+    @Override
+    public Result controlPoint(String sceneCode) {
+
+        String basePath = "F:\\test\\project\\age_laser\\laserData";
+        String s = FileUtil.readUtf8String(basePath + "/controlPoint.json");
+        JSONObject jsonObject = JSONObject.parseObject(s);
+        JSONArray points = jsonObject.getJSONArray("points");
+
+        JSONObject poi_1 = points.getJSONObject(0);
+        JSONObject poi_2 = points.getJSONObject(1);
+
+        // 第一个点
+        double gpsLat_1 = poi_1.getJSONObject("coordinate").getDouble("latitude");
+        double gpsLon_1 = poi_1.getJSONObject("coordinate").getDouble("longitude");
+        double ageX_1 = poi_1.getJSONObject("location").getDouble("x");
+        double ageY_1 = poi_1.getJSONObject("location").getDouble("y");
+
+        // 第二个点
+        double gpsLat_2 = poi_2.getJSONObject("coordinate").getDouble("latitude");
+        double gpsLon_2 = poi_2.getJSONObject("coordinate").getDouble("longitude");
+        double ageX_2 = poi_2.getJSONObject("location").getDouble("x");
+        double ageY_2 = poi_2.getJSONObject("location").getDouble("y");
+
+        double[] gpsCoord1 = {gpsLat_1, gpsLon_1};
+        double[] gpsCoord2 = {gpsLat_2, gpsLon_2};
+        double[] ageLocation1 = {ageX_1, ageY_1};
+        double[] ageLocation2 = {ageX_2, ageY_2};
+
+        ControlPointEntity entity = new ControlPointEntity();
+        entity.setGpsControlCoordinate1(gpsCoord1);
+        entity.setGpsControlCoordinate2(gpsCoord2);
+        entity.setAgeControlLocation1(ageLocation1);
+        entity.setAgeControlLocation2(ageLocation2);
+
+        return Result.success(entity);
+    }
+
 
 }

+ 2 - 29
laser/src/main/java/com/fdkankan/indoor/core/service/impl/PoiServiceImpl.java

@@ -156,23 +156,7 @@ public class PoiServiceImpl extends IBaseServiceImpl implements PoiService {
         return Result.success(changeSecurityUnLoginList(data));
     }
 
-//    private void update(PoiEntity vo){
-//        Query query = new Query();
-//        query.addCriteria(Criteria.where("sceneCode").is(vo.getSceneCode()));
-//        mongoTemplate.upsert(query, Update.update("data", vo.getData()),  PoiEntity.class,"t_poi");
-//
-//    }
-
-
-//    private PoiEntity findBySceneCode(String sceneCode){
-//        Query query = new Query();
-//        query.addCriteria(Criteria.where("sceneCode").is(sceneCode));
-//        PoiEntity vo = mongoTemplate.findOne(query, PoiEntity.class, "t_poi");
-//        if (vo == null) {
-//            throw new RuntimeException("没有此场景数据");
-//        }
-//        return vo;
-//    }
+
 
     private PoiEntity findById(String sceneCode){
         Optional<PoiEntity> optional = entityMapper.findById(sceneCode);
@@ -208,18 +192,7 @@ public class PoiServiceImpl extends IBaseServiceImpl implements PoiService {
 
     }
 
-    /**
-     * 未登录, can_write: false
-     * @param
-     * @return
-     */
-//    private SecurityDto changeSecurityUnLogin(){
-//        SecurityDto dto = new SecurityDto();
-//        dto.setCan_write(false);
-//        dto.setGroup_read(0);
-//        dto.setGroup_write(1);
-//        return dto;
-//    }
+
 
     private List<PoiHotDto> changeSecurityUnLoginList(List<PoiHotDto> param){
 

+ 31 - 22
laser/src/main/java/com/fdkankan/indoor/core/service/impl/PoiTypeGroupServiceImpl.java

@@ -18,6 +18,7 @@ import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.data.mongodb.core.query.Update;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Optional;
@@ -28,7 +29,7 @@ import java.util.stream.Collectors;
  */
 @Slf4j
 @Service
-public class PoiTypeGroupServiceImpl implements PoiTypeGroupService {
+public class PoiTypeGroupServiceImpl extends IBaseServiceImpl implements PoiTypeGroupService {
 
     @Autowired
     MongoTemplate mongoTemplate;
@@ -90,9 +91,31 @@ public class PoiTypeGroupServiceImpl implements PoiTypeGroupService {
 
         save(entity);
 
-        return Result.success(findDataBySceneCode(sceneCode));
+        List<PoiTypeGroupDto> newData = findDataBySceneCode(sceneCode);
+        if (isLogin()){
+            return Result.success(newData);
+        }
+
+        return Result.success(changeSecurityUnLoginList(newData));
+    }
+
+    /**
+     * 处理登录问题
+     * @param param
+     * @return
+     */
+    private List<PoiTypeGroupDto> changeSecurityUnLoginList(List<PoiTypeGroupDto> param){
+
+        List<PoiTypeGroupDto> result = new ArrayList<>();
+        for (PoiTypeGroupDto dto : param) {
+            dto.setSecurity(changeSecurityUnLogin());
+            result.add(dto);
+        }
+        return result;
     }
 
+
+
     private List<PoiTypeGroupDto> findDataBySceneCode(String sceneCode){
         PoiTypeGroupEntity entity = findById(sceneCode);
         return entity.getData();
@@ -100,20 +123,14 @@ public class PoiTypeGroupServiceImpl implements PoiTypeGroupService {
 
 
 
-
-//    private PoiTypeGroupEntity findBySceneCode(String sceneCode){
-//        Query query = new Query();
-//        query.addCriteria(Criteria.where("sceneCode").is(sceneCode));
-//        PoiTypeGroupEntity entity = mongoTemplate.findOne(query, PoiTypeGroupEntity.class, "t_poi_type_groups");
-//        if (entity == null) {
-//            throw new RuntimeException("没有此场景数据");
-//        }
-//        return entity;
-//    }
-
     @Override
     public Result poiTypes(String sceneCode) {
-        return Result.success(findDataBySceneCode(sceneCode));
+        List<PoiTypeGroupDto> newData = findDataBySceneCode(sceneCode);
+        if (isLogin()){
+            return Result.success(newData);
+        }
+
+        return Result.success(changeSecurityUnLoginList(newData));
     }
 
     @Override
@@ -141,12 +158,4 @@ public class PoiTypeGroupServiceImpl implements PoiTypeGroupService {
         entityMapper.save(entity);
 
     }
-
-//    private void update(PoiTypeGroupEntity vo){
-//        Query query = new Query();
-//        query.addCriteria(Criteria.where("sceneCode").is(vo.getSceneCode()));
-//        mongoTemplate.upsert(query, Update.update("data", vo.getData()),  PoiTypeGroupEntity.class,"t_poi_type_groups");
-//
-//    }
-
 }

+ 1 - 16
laser/src/main/java/com/fdkankan/indoor/core/service/impl/PoiTypeServiceImpl.java

@@ -101,28 +101,13 @@ public class PoiTypeServiceImpl implements PoiTypeService {
     }
 
 
-//    private PoiTypeEntity findBySceneCode(String sceneCode){
-//        Query query = new Query();
-//        query.addCriteria(Criteria.where("sceneCode").is(sceneCode));
-//        PoiTypeEntity vo = mongoTemplate.findOne(query, PoiTypeEntity.class, "t_poi_types");
-//        if (vo == null) {
-//            throw new RuntimeException("没有此场景数据");
-//        }
-//
-//        return vo;
-//    }
+
 
     private List<PoiTypeDto> findDataBySceneCode(String sceneCode){
         PoiTypeEntity entity = findById(sceneCode);
         return entity.getData();
     }
 
-//    private void update(PoiTypeEntity vo){
-//        Query query = new Query();
-//        query.addCriteria(Criteria.where("sceneCode").is(vo.getSceneCode()));
-//        mongoTemplate.upsert(query, Update.update("data", vo.getData()),  PoiTypeEntity.class,"t_poi_types");
-//
-//    }
 
     private PoiTypeEntity findById(String sceneCode){
         Optional<PoiTypeEntity> optional = entityMapper.findById(sceneCode);

+ 12 - 3
laser/src/main/java/com/fdkankan/indoor/core/service/impl/RouteServiceImpl.java

@@ -22,6 +22,7 @@ import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Optional;
 
@@ -76,10 +77,10 @@ public class RouteServiceImpl implements RouteService {
             boolean flag = json.has("id");
             if (flag){
                 int id = json.getInt("id");
-                // 行数 是id -1
-                ids.add(id -1 );
+                ids.add(id);
             }
         }
+        log.info("ids: {}", ids);
         // 写文件
         writeRouteData(ids, data, sceneCode);
     }
@@ -88,6 +89,9 @@ public class RouteServiceImpl implements RouteService {
     // 根据id写文件
     private void writeRouteData(List<Integer> ids, List<String> data, String  sceneCode){
         List<String> result = new ArrayList<>();
+
+        HashMap<Integer, Object> map = new HashMap<>();
+
         // 行数
         for (int i = 0; i < data.size() ; i++) {
             // 从相等行数获取到结束, 数据格式: v x y z
@@ -95,10 +99,15 @@ public class RouteServiceImpl implements RouteService {
                 String s = data.get(i);
                 String[] str = s.split(" ");
                 String res = "v "+ str[0] + " " + str[1] + " " + str[2] ;
-                result.add(res);
+                map.put(i, res);
             }
         }
 
+        for (Integer id : ids) {
+            String o = (String)map.get(id);
+            result.add(o);
+        }
+
         log.info("ids数量: {}", ids.size());
         log.info("result数量: {}", result.size());
 

+ 1 - 1
laser/src/main/resources/application-dev.properties

@@ -16,7 +16,7 @@ swagger.description=${swagger.title}
 swagger.version=1.0
 
 server.file.path=F:\\test\\ngin\\${project.en}_data
-my.template.path=F:/test/project/age_laser/laserData
+my.template.path=F:/test/project/age_laser/laserData/baseData
 
 
 oss.point=http://oss-cn-shenzhen-internal.aliyuncs.com