Bläddra i källkod

修改 filter 表的过滤逻辑

wuweihao 4 år sedan
förälder
incheckning
764cb1e0fb

+ 119 - 23
laser/src/main/java/com/fdkankan/indoor/base/convert/ConvertToVision.java

@@ -57,8 +57,15 @@ public class ConvertToVision {
 		
 		return result;
 	}
-	
-	private  JSONArray createPanoInfos(String sceneCode, JSONArray panoInfos,  ControlPointEntity dto) {
+
+	/**
+	 * 初始化vision数据
+	 * @param sceneCode
+	 * @param panoInfos
+	 * @param dto
+	 * @return
+	 */
+	private  JSONArray createVisionToFilter(String sceneCode, JSONArray panoInfos,  ControlPointEntity dto) {
 		
 		JSONArray laserPanos = new JSONArray();
 		for(int i=0;i<panoInfos.size();++i) {
@@ -67,12 +74,11 @@ public class ConvertToVision {
 			int id = item.getInt("id");
 			laserPano.put("camera_head_id", 12);
 			laserPano.put("dataset_id", 1);
-			laserPano.put("dataset_orientation", null);
 			laserPano.put("file_path", "data/chunk1");
 			laserPano.put("hidden", false);
 			laserPano.put("id", id);
-			laserPano.put("site_model_entity_id", 11);
-			
+			laserPano.put("site_model_entity_id", 12);
+
 			//JSONObject pose = item.getJSONObject("pose");
 			JSONObject position2 = item.getJSONObject("puck");
 			JSONObject position1 = item.getJSONObject("translation");
@@ -95,7 +101,7 @@ public class ConvertToVision {
 			floor_location[1] = _floor_location[1];
 			laserPano.put("location", location);
 			laserPano.put("floor_location", floor_location);
-			
+
 			//���
 			double[] dataset_location = new double[3];
 			dataset_location[0] = position2.getDouble("x");
@@ -109,15 +115,19 @@ public class ConvertToVision {
 
 			laserPano.put("dataset_location", dataset_location);
 			laserPano.put("dataset_floor_location", dataset_floor_location);
-			
+
 			JSONObject rotation = item.getJSONObject("rotation");
 			double[] quaternation = new double[4];
 			quaternation[0] = rotation.getDouble("w");
 			quaternation[1] = rotation.getDouble("x");
 			quaternation[2] = rotation.getDouble("y");
 			quaternation[3] = rotation.getDouble("z");
+
 			laserPano.put("orientation", quaternation);
-			
+			// 2021-08-11
+			laserPano.put("dataset_orientation", quaternation);
+			laserPano.put("dataset_floor_orientation", quaternation);
+
 			String fileId = String.valueOf(id);
 			while(fileId.length()<5) {
 				fileId = "0"+fileId;
@@ -130,10 +140,7 @@ public class ConvertToVision {
 				//保存初始点的gis坐标
 				// _location 存入数据库
 				SpecialPointEntity pointEntity = new SpecialPointEntity();
-				// 纬度 113
-//				pointEntity.setLat(_location[0]);
-//				// 经度 22
-//				pointEntity.setLon(_location[1]);
+				// 经度 22 纬度 113
 				Double[] edit = {_location[0], _location[1]};
 				pointEntity.setPoi(edit);
 				pointEntity.setSceneCode(sceneCode);
@@ -148,6 +155,89 @@ public class ConvertToVision {
 	}
 
 
+	private static   JSONArray createVisionToFilter(JSONArray panoInfos) {
+
+		JSONArray laserPanos = new JSONArray();
+		for(int i=0;i<panoInfos.size();++i) {
+			JSONObject item = panoInfos.getJSONObject(i);
+			JSONObject laserPano = new JSONObject();
+			int id = item.getInt("id");
+			laserPano.put("camera_head_id", 12);
+			laserPano.put("dataset_id", 1);
+			laserPano.put("file_path", "data/chunk1");
+			laserPano.put("hidden", false);
+			laserPano.put("id", id);
+			laserPano.put("site_model_entity_id", 12);
+
+			//JSONObject pose = item.getJSONObject("pose");
+			JSONObject position2 = item.getJSONObject("puck");
+			JSONObject position1 = item.getJSONObject("translation");
+			//���
+			double[] location = new double[3];
+			location[0] = position1.getDouble("x");
+			location[1] = position1.getDouble("y");
+			location[2] = position1.getDouble("z");
+			//����
+			double[] floor_location = new double[3];
+			floor_location[0] = position2.getDouble("x");
+			floor_location[1] = position2.getDouble("y");
+			floor_location[2] = position2.getDouble("z");
+			//gis����
+			double[] _location = TransformGPS.convert(location);
+			double[] _floor_location = TransformGPS.convert(floor_location);
+			location[0] = _location[0];
+			location[1] = _location[1];
+			floor_location[0] = _floor_location[0];
+			floor_location[1] = _floor_location[1];
+			laserPano.put("location", location);
+			laserPano.put("floor_location", floor_location);
+
+			//���
+			double[] dataset_location = new double[3];
+			dataset_location[0] = position2.getDouble("x");
+			dataset_location[1] = position2.getDouble("y");
+			dataset_location[2] = position1.getDouble("z");
+			//����
+			double[] dataset_floor_location = new double[3];
+			dataset_floor_location[0] = position2.getDouble("x");
+			dataset_floor_location[1] = position2.getDouble("y");
+			dataset_floor_location[2] = position2.getDouble("z");
+
+			laserPano.put("dataset_location", dataset_location);
+			laserPano.put("dataset_floor_location", dataset_floor_location);
+
+			JSONObject rotation = item.getJSONObject("rotation");
+			double[] quaternation = new double[4];
+			quaternation[0] = rotation.getDouble("w");
+			quaternation[1] = rotation.getDouble("x");
+			quaternation[2] = rotation.getDouble("y");
+			quaternation[3] = rotation.getDouble("z");
+
+			laserPano.put("orientation", quaternation);
+			// 2021-08-11
+			laserPano.put("dataset_orientation", quaternation);
+			laserPano.put("dataset_floor_orientation", quaternation);
+
+			String fileId = String.valueOf(id);
+			while(fileId.length()<5) {
+				fileId = "0"+fileId;
+			}
+			laserPano.put("file_id", fileId);
+
+			laserPanos.add(laserPano);
+			//firstView
+			if(id == 0) {
+				//保存初始点的gis坐标
+				// _location 存入数据库
+//				// 经度 22 纬度 113
+				Double[] edit = {_location[0], _location[1]};
+
+				log.info("firstView保存成功");
+			}
+		}
+		return laserPanos;
+	}
+
 	public  JSONArray createFilter(String sceneCode, String path, ControlPointEntity dto){
 		if (!cn.hutool.core.io.FileUtil.isFile(path)) {
 			log.error("文件路径不存在: {}", path);
@@ -155,23 +245,29 @@ public class ConvertToVision {
 		}
 		try {
 			JSONArray panoInfos = readVisionTxt(path);
-			return createPanoInfos(sceneCode, panoInfos, dto);
+			return createVisionToFilter(sceneCode, panoInfos, dto);
 		} catch (IOException e) {
 			e.printStackTrace();
 		}
 		return null;
 	}
 
-//	public static void main(String[] args) {
-//		String inputFilePath = "F:\\test\\project\\age_laser\\vision-indoor.txt";
-//		try {
-//			JSONArray panoInfos = readVisionTxt(inputFilePath);
-//			createPanoInfos("111", panoInfos);
-//		}
-//		catch(Exception e){
-//			e.printStackTrace();
-//		}
-//	}
+
+	/**
+	 * 测试热点- vision, filter
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		String inputFilePath = "F:\\test\\project\\age_laser\\laserData\\vision.txt";
+		try {
+			JSONArray panoInfos = readVisionTxt(inputFilePath);
+			JSONArray jsonArray = createVisionToFilter(panoInfos);
+			System.out.println();
+		}
+		catch(Exception e){
+			e.printStackTrace();
+		}
+	}
 
 	/**
 	 * 测试控制点, 还有filter热点

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

@@ -6,6 +6,7 @@ import com.fdkankan.indoor.base.util.SnowFlakeUUidUtils;
 import com.fdkankan.indoor.core.entity.OwenEntity;
 import com.fdkankan.indoor.core.entity.SpecialPointEntity;
 import com.fdkankan.indoor.core.service.OwenService;
+import com.fdkankan.indoor.core.service.SiteService;
 import com.fdkankan.indoor.core.service.SpecialPointService;
 import com.fdkankan.indoor.core.service.TestService;
 import com.fdkankan.indoor.core.entity.vo.HaoVo;
@@ -36,6 +37,9 @@ public class TestController {
     @Autowired
     SpecialPointService specialPointService;
 
+    @Autowired
+    SiteService siteService;
+
     @ApiOperation("修改数据")
     @PostMapping("edit/{sceneCode}")
     public Result edit(@PathVariable String sceneCode, @RequestBody List<HaoVo> param){
@@ -113,5 +117,15 @@ public class TestController {
     }
 
 
+    @ApiOperation("siteModel-获取自己或者儿子id")
+    @GetMapping("site/findBySon/{sceneCode}/{siteModelId}")
+    public Result findBySon(@PathVariable String sceneCode, @PathVariable Integer siteModelId){
+        List<Integer> son = siteService.findBySceneCodeAndIdAndSon(sceneCode, siteModelId);
+        return Result.success(son);
+
+
+    }
+
+
 
 }

+ 7 - 2
laser/src/main/java/com/fdkankan/indoor/core/entity/dto/FilterHotDto.java

@@ -36,9 +36,14 @@ public class FilterHotDto {
 
 
     // 2021-8-6 新增
-    private Double[] dataset_orientation = {0.0, 0.0, 0.0, 1.0};
+//    private Double[] dataset_orientation = {0.0, 0.0, 0.0, 1.0};
+
+//    private Double[] dataset_floor_orientation =  {0.0, 0.0, 0.0, 1.0};
+
+    private Double[] dataset_orientation ;
+
+    private Double[] dataset_floor_orientation ;
 
-    private Double[] dataset_floor_orientation =  {0.0, 0.0, 0.0, 1.0};
 
 
 }

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

@@ -5,6 +5,8 @@ import com.fdkankan.indoor.base.util.Result;
 import com.fdkankan.indoor.core.entity.SiteModelEntity;
 import com.fdkankan.indoor.core.entity.dto.SiteModelSearchDto;
 
+import java.util.List;
+
 /**
  * Created by owen on 2021/7/28 0028 12:02
  */
@@ -22,4 +24,6 @@ public interface SiteService {
     void save(SiteModelEntity entity);
 
     void remove(String sceneCode);
+
+    List<Integer> findBySceneCodeAndIdAndSon(String code, Integer site_model_entity);
 }

+ 22 - 3
laser/src/main/java/com/fdkankan/indoor/core/service/impl/FilterServiceImpl.java

@@ -11,6 +11,7 @@ import com.fdkankan.indoor.core.entity.po.DataSetPo;
 import com.fdkankan.indoor.core.entity.vo.FilterDataSetHotVo;
 import com.fdkankan.indoor.core.mapper.FilterMapper;
 import com.fdkankan.indoor.core.service.FilterService;
+import com.fdkankan.indoor.core.service.SiteService;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.Test;
 import org.springframework.beans.BeanUtils;
@@ -35,6 +36,9 @@ public class FilterServiceImpl implements FilterService {
     @Autowired
     MongoTemplate mongoTemplate;
 
+    @Autowired
+    SiteService siteService;
+
 
 
     @Override
@@ -91,11 +95,21 @@ public class FilterServiceImpl implements FilterService {
         Integer dataset = param.getDataset();
         if (dataset != null) {
             data = data.stream().filter(p -> dataset.equals(p.getDataset_id())).collect(Collectors.toList());
+            if (data.size() == 0) {
+                return Result.success();
+            }
         }
 
         Integer site_model_entity = param.getSite_model_entity();
         if (site_model_entity != null) {
-            data = data.stream().filter(p -> site_model_entity.equals(p.getSite_model_entity_id())).collect(Collectors.toList());
+
+            //根据site_model_entity_id 获取它自己或者儿子的id
+            List<Integer> siteModelIds = siteService.findBySceneCodeAndIdAndSon(code, site_model_entity);
+            // 包含关系
+            data = data.stream().filter(p -> siteModelIds.contains(p.getSite_model_entity_id())).collect(Collectors.toList());
+            if (data.size() == 0) {
+                return Result.success();
+            }
         }
 
 
@@ -108,9 +122,10 @@ public class FilterServiceImpl implements FilterService {
             if (radius != null) {
                 data = calcule(param, data);
             } else {
-                // 没有半径,算最近的距离, 返回值只有一数据
+                // 没有半径,算最近的距离, 返回值只有一数据
                 data = calculeMin(param, data);
             }
+
             log.info("lat、lon-输出数量:{}", data.size());
         }
 
@@ -160,7 +175,11 @@ public class FilterServiceImpl implements FilterService {
 
         log.info("输出数量:{}", data.size());
 
-        return Result.success(data);
+        if (data.size() > 0) {
+            return Result.success(data);
+        }
+
+        return Result.success();
     }
 
     @Override

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

@@ -39,7 +39,7 @@ public class InitServiceImpl implements InitService {
     InitMapper initMapper;
 
     @Autowired
-    ConvertToVision convertToPanoInfoFor4dkk;
+    ConvertToVision convertToVision;
 
     @Autowired
     FilterService filterService;
@@ -190,7 +190,7 @@ public class InitServiceImpl implements InitService {
         // step1: 处理vision.txt 创建filter表, 处理特殊点:firstView
         createFilter(sceneCode, laserDataPath, controlPoint);
 
-        // step2 处理could.js 使用的是代码初始化,创建site_model, 处理原点、中心点、最大点、最小点
+        // step2 处理could.js、创建sitModel, 使用的是代码初始化,创建site_model, 处理原点、中心点、最大点、最小点
         processCould(sceneCode, laserDataPath, controlPoint);
 
         // step6 创建t_configs表, 使用的是模板数据 , 需要firstView;
@@ -384,11 +384,11 @@ public class InitServiceImpl implements InitService {
         if (!cn.hutool.core.io.FileUtil.isFile(path)){
             throw new BaseRuntimeException(MsgCode.e3001, "vision.txt不存在");
         }
-        JSONArray jsonArray = convertToPanoInfoFor4dkk.createFilter(sceneCode, path, dto);
+        JSONArray jsonArray = convertToVision.createFilter(sceneCode, path, dto);
         FilterEntity entity = new FilterEntity();
         entity.setId(sceneCode);
         entity.setCreateTime(LocalDateTime.now());
-        //将array数组转换成字符串
+        //将array数组转换成对象
         List<FilterHotDto> list = JSONArray.toList(jsonArray, FilterHotDto.class);
         entity.setData(list);
         filterService.save(entity);

+ 92 - 0
laser/src/main/java/com/fdkankan/indoor/core/service/impl/SiteServiceImpl.java

@@ -11,6 +11,7 @@ import com.fdkankan.indoor.core.entity.dto.SiteModelSearchDto;
 import com.fdkankan.indoor.core.entity.dto.SitePolygon;
 import com.fdkankan.indoor.core.mapper.SiteModelMapper;
 import com.fdkankan.indoor.core.service.SiteService;
+import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -166,6 +167,97 @@ public class SiteServiceImpl implements SiteService {
         entityMapper.deleteById(sceneCode);
     }
 
+    /**
+     * 获取自己或者儿子的id
+     * @param code
+     * @param site_model_entity
+     * @return
+     */
+    @Override
+    public List<Integer> findBySceneCodeAndIdAndSon(String code, Integer site_model_entity) {
+        List<SiteDto> data = getDataBySceneCode(code);
+        // 递归为对象
+        SiteDto siteDto = data.get(0);
+        List<Integer> result = new ArrayList<>();
+        Integer buildingId = siteDto.getId();
+        // 父id符合, 子id必须加入
+        boolean flag = false;
+        if (site_model_entity.equals(buildingId)) {
+            result.add(buildingId);
+            flag = true;
+        }
+        // 是否有儿子
+        List<SiteDto> floorChildren = siteDto.getChildren();
+        // 为空:直接返回
+        if (floorChildren.size() == 0) {
+            return result;
+        }
+        // 处理floorChildren
+        for (SiteDto floorChild : floorChildren) {
+            Integer floorId = floorChild.getId();
+
+            if (flag) {
+                result.add(floorId);
+            } else {
+                if (site_model_entity.equals(floorId)) {
+                    result.add(floorId);
+                    flag = true;
+                }
+            }
+
+            // 处理roomChildren
+            List<SiteDto> roomChildren = floorChild.getChildren();
+            for (SiteDto roomChild : roomChildren) {
+                Integer roomChildId = roomChild.getId();
+                if (flag){
+                    result.add(roomChildId);
+                } else {
+                    if (site_model_entity.equals(roomChildId)) {
+                        result.add(roomChildId);
+                    }
+                }
+            }
+
+        }
+
+
+//        System.out.println();
+        return result;
+    }
+
+//    /**
+//     * 递归获取对象id
+//     * @param siteDto
+//     * @return
+//     */
+//
+//    private Object test(){
+//        List<Integer> result = new ArrayList<>();
+//        // 父id符合, 子id必须加入
+//        boolean flag = false;
+//        SiteDto siteDto = new SiteDto();
+//        getRecursionIdAndSonId(siteDto);
+//
+//        return null;
+//    }
+//
+//    private void getRecursionIdAndSonId(SiteDto siteDto , boolean flag, List<Integer> result, Integer site_model_entity){
+//        Integer floorId = siteDto.getId();
+//
+//        if (flag) {
+//            result.add(floorId);
+//        } else {
+//            if (site_model_entity.equals(floorId)) {
+//                result.add(floorId);
+//                flag = true;
+//            }
+//        }
+//        if (siteDto.getChildren().size() > 0){
+//            getRecursionIdAndSonId()
+//        }
+//    }
+
+
 
     // 判断的坐标在那个空间位置
     private boolean getSm(SiteDto model, Point2D.Double pointParam) {

+ 3 - 3
laser/src/main/resources/data/site_model.json

@@ -1,6 +1,6 @@
 [
   {
-    "_id" : 1,
+    "_id" : 10,
     "type" : "BUILDING",
     "name" : "港湾一号",
     "polygon" : {
@@ -13,7 +13,7 @@
     "z_max" : null,
     "children" : [
       {
-        "_id" : 2,
+        "_id" : 11,
         "type" : "FLOOR",
         "name" : "一楼",
         "polygon" : null,
@@ -21,7 +21,7 @@
         "z_max" : null,
         "children" : [
           {
-            "_id" : 16,
+            "_id" : 12,
             "type" : "ROOM",
             "name" : "港10",
             "polygon" : {