|
@@ -1,16 +1,26 @@
|
|
|
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.CmdConstant;
|
|
|
+import com.fdkankan.indoor.base.convert.PlanGraph;
|
|
|
+import com.fdkankan.indoor.base.convert.quadTree.Solution;
|
|
|
import com.fdkankan.indoor.base.exception.BaseRuntimeException;
|
|
|
+import com.fdkankan.indoor.base.util.CmdUtils;
|
|
|
import com.fdkankan.indoor.base.util.Result;
|
|
|
+import com.fdkankan.indoor.core.entity.DataSetEntity;
|
|
|
import com.fdkankan.indoor.core.entity.TiledMapEntity;
|
|
|
import com.fdkankan.indoor.core.entity.dto.TiledEditDto;
|
|
|
import com.fdkankan.indoor.core.entity.dto.TiledMapDto;
|
|
|
+import com.fdkankan.indoor.core.entity.po.DataSetPo;
|
|
|
import com.fdkankan.indoor.core.mapper.TiledMapMapper;
|
|
|
import com.fdkankan.indoor.core.service.TiledMapService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -26,6 +36,9 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
@Autowired
|
|
|
TiledMapMapper entityMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ DataSetServiceImpl dataSetService;
|
|
|
+
|
|
|
|
|
|
private TiledMapEntity findById(String sceneCode){
|
|
|
Optional<TiledMapEntity> optional = entityMapper.findById(sceneCode);
|
|
@@ -46,7 +59,10 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
TiledMapEntity entity = new TiledMapEntity();
|
|
|
entity.setId(sceneCode);
|
|
|
entity.setCreateTime(LocalDateTime.now());
|
|
|
+ // 2021.09.03
|
|
|
+ entity.setData(initData(sceneCode));
|
|
|
entityMapper.save(entity);
|
|
|
+
|
|
|
log.info("TiledMap数据初始化完成");
|
|
|
}
|
|
|
|
|
@@ -68,7 +84,10 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
}
|
|
|
entity.setData(editData(param));
|
|
|
entity.setUpdateTime(LocalDateTime.now());
|
|
|
+
|
|
|
entityMapper.save(entity);
|
|
|
+
|
|
|
+
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
@@ -115,6 +134,8 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
* 2:1024*1024
|
|
|
* 3:2048*2048
|
|
|
* 4:4096*4096
|
|
|
+ *
|
|
|
+ * Max_dept=读取info值,zoom.size()-1
|
|
|
*/
|
|
|
dto.setMax_depth(3);
|
|
|
dto.setQuadtree("fccf7fffcff3bf7f");
|
|
@@ -132,4 +153,97 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private List<TiledMapDto> initData(String sceneCode){
|
|
|
+ String path = redisPath(sceneCode) + "/laserData";
|
|
|
+ if ("dev".equals(configConstant.active)) {
|
|
|
+ path = "F:\\test\\ngin\\age_laser_data\\" + sceneCode + "\\results\\laserData";
|
|
|
+ }
|
|
|
+ String infoPath = path + "/cover/info.json";
|
|
|
+ log.info("info.json path: {}", infoPath);
|
|
|
+
|
|
|
+ if (!FileUtil.isFile(infoPath)){
|
|
|
+ log.error("info.json文件不存在");
|
|
|
+ throw new BaseRuntimeException("info.json文件不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ String str = FileUtil.readUtf8String(infoPath);
|
|
|
+ JSONObject strJson = JSONObject.parseObject(str);
|
|
|
+ JSONArray zoom = strJson.getJSONArray("zoom");
|
|
|
+ Integer maxDepth = zoom.size()-1;
|
|
|
+ log.info("maxDepth: {}", maxDepth);
|
|
|
+
|
|
|
+ JSONObject resolution = strJson.getJSONObject("resolution");
|
|
|
+ Integer width = resolution.getInteger("width");
|
|
|
+ Integer height = resolution.getInteger("height");
|
|
|
+ Integer imgWidth = width >= height? width: height;
|
|
|
+ log.info("imgWidth: {}", imgWidth);
|
|
|
+
|
|
|
+
|
|
|
+ double mapSize_m = PlanGraph.getSize(imgWidth, 1);
|
|
|
+ List<DataSetPo> data = dataSetService.getDataBySceneCode(sceneCode);
|
|
|
+ DataSetPo dataSetPo = data.get(0);
|
|
|
+ Double orientation = dataSetPo.getOrientation();
|
|
|
+ Double[] location = dataSetPo.getLocation();
|
|
|
+
|
|
|
+ double[] quaternion = PlanGraph.getQuaternion(orientation);
|
|
|
+
|
|
|
+
|
|
|
+ // 四查收书
|
|
|
+ String dirPath = path + "/cover/" + maxDepth;
|
|
|
+ log.info("quadTree dirPath: {}", dirPath);
|
|
|
+ Solution solution = new Solution();
|
|
|
+ File file = solution.readFiles(dirPath);
|
|
|
+ String quadTree = "";
|
|
|
+ if(file!=null) {
|
|
|
+ quadTree = solution.getXYTiles(file);
|
|
|
+ }
|
|
|
+ log.info("quadTree : {}", quadTree);
|
|
|
+
|
|
|
+
|
|
|
+ TiledMapDto dto = new TiledMapDto();
|
|
|
+ dto.setId(1);
|
|
|
+ // 默认1
|
|
|
+ dto.setBundle_id(1);
|
|
|
+ // 小地图oss路径
|
|
|
+ /**
|
|
|
+ * data/bundle/building_1/map_tiles/11
|
|
|
+ * building_1: bundle_id值
|
|
|
+ * 11=floor_id值:site_model.type:floor的id
|
|
|
+ */
|
|
|
+ dto.setFile_path("data/bundle/building_1/map_tiles/11");
|
|
|
+ dto.setFile_name("$DEPTH/$X/$Y.png");
|
|
|
+ // 11=floor_id值:site_model.type:floor的id
|
|
|
+ dto.setFloor_id(11);
|
|
|
+
|
|
|
+ dto.setMax_depth(maxDepth);
|
|
|
+ dto.setQuadtree(quadTree);
|
|
|
+ dto.setType("TILED_PYRAMID");
|
|
|
+ dto.setTile_size_px(256);
|
|
|
+
|
|
|
+ dto.setMap_size_m(mapSize_m);
|
|
|
+ // 使用dataSet.location
|
|
|
+ dto.setLocation(location);
|
|
|
+ // 前端提供
|
|
|
+ Double[] calcQuaternion = {quaternion[0],quaternion[1],quaternion[2],quaternion[3]};
|
|
|
+ dto.setOrientation(calcQuaternion);
|
|
|
+ List<TiledMapDto> list = new ArrayList<>();
|
|
|
+ list.add(dto);
|
|
|
+
|
|
|
+ // 将cover上传oss
|
|
|
+ String ossTarget = "data/" + sceneCode + "/" + dto.getFile_path();
|
|
|
+ String uploadDir = path + "/cover";
|
|
|
+ ossUploadDir(ossTarget, uploadDir);
|
|
|
+ return list;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ossUploadDir(String ossTarget, String uploadDir){
|
|
|
+ String cmd = CmdConstant.OSSUTIL_UPLOAD_DIR;
|
|
|
+ cmd = cmd.replaceAll("@uploadDir", uploadDir);
|
|
|
+ cmd = cmd.replaceAll("@target", ossTarget);
|
|
|
+ CmdUtils.ossUploadDir(cmd);
|
|
|
+ log.info("切图上传oss完成");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|