|
@@ -1,6 +1,8 @@
|
|
|
package com.fdkankan.indoor.core.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.img.ImgUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.core.util.ZipUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -23,12 +25,14 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Created by owen on 2021/7/28 0028 20:05
|
|
@@ -61,6 +65,13 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 平面图初始化
|
|
|
+ * 初始化是使用平面图是: /laserData/cover
|
|
|
+ * 修改上传使用的工作目录是:/results/laserData/cover
|
|
|
+ * @param sceneCode
|
|
|
+ * @param from
|
|
|
+ */
|
|
|
@Override
|
|
|
public void init(String sceneCode, String from) {
|
|
|
TiledMapEntity entity = findById(sceneCode);
|
|
@@ -168,11 +179,119 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
*/
|
|
|
@Override
|
|
|
public Result download(String sceneCode) {
|
|
|
- String basePath = "data/" + sceneCode + "/upload_cover/cover.zip";
|
|
|
+ String basePath = "data/" + sceneCode + "/download/final_freespace.png";
|
|
|
return Result.success(basePath);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public Result upload2(String sceneCode, MultipartFile file) {
|
|
|
+
|
|
|
+ // 只接受png格式
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ originalFilename = originalFilename.toLowerCase();
|
|
|
+ if (!originalFilename.endsWith(".png")){
|
|
|
+ return Result.failure("文件格式有误, 只接收png图片");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 只接受info.json里的图片大小尺寸
|
|
|
+ String basePath = redisPath(sceneCode);
|
|
|
+
|
|
|
+ // 全景图工作目录
|
|
|
+ String tiledBasePath = StrUtil.subBefore(basePath, "/laserData", true);
|
|
|
+
|
|
|
+ String infoPath = tiledBasePath + "/extras/info.json";
|
|
|
+ if (!FileUtil.exist(infoPath)){
|
|
|
+ String msg = "info.json文件不存在, 请检查";
|
|
|
+ log.error(msg + ": " +infoPath);
|
|
|
+ return Result.failure(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ String info = FileUtil.readUtf8String(infoPath);
|
|
|
+ JSONObject infoJ = JSONObject.parseObject(info);
|
|
|
+ JSONObject resolution = infoJ.getJSONObject("resolution");
|
|
|
+ Integer width = resolution.getInteger("width");
|
|
|
+ Integer height = resolution.getInteger("height");
|
|
|
+
|
|
|
+ BufferedImage read = null;
|
|
|
+ String tiledMapPath = tiledBasePath + "/extras/final_freespace.png";
|
|
|
+ try {
|
|
|
+
|
|
|
+ FileUtil.writeFromStream(file.getInputStream(), tiledMapPath);
|
|
|
+
|
|
|
+ read = ImgUtil.read(tiledMapPath);
|
|
|
+ int widthImg = read.getWidth();
|
|
|
+ int heightImg = read.getHeight();
|
|
|
+ if (width != widthImg || height != heightImg) {
|
|
|
+ String msg = "上传图片尺寸跟原图不一致";
|
|
|
+ log.error(msg + ", width:{}, height:{}, widthImg:{}, heightImg:{}" , width, height,widthImg, heightImg);
|
|
|
+ return Result.failure(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 调用算法切图
|
|
|
+ cmdTiledMap(tiledBasePath);
|
|
|
+
|
|
|
+ // 上传平面图到download目录
|
|
|
+ uplodaOss(tiledBasePath, sceneCode);
|
|
|
+ return Result.success();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2021-09-24
|
|
|
+ * 这里使用路径判断场景码删除
|
|
|
+ * 删除合并的平面图信息
|
|
|
+ * @param sceneCode
|
|
|
+ * @param mergeCode
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void removeMerge(String sceneCode, String mergeCode) {
|
|
|
+ TiledMapEntity mapEntity = findById(sceneCode);
|
|
|
+ List<TiledMapDto> data = mapEntity.getData();
|
|
|
+ data = data.stream().filter(p -> !p.getFile_path().contains(mergeCode)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ mapEntity.setData(data);
|
|
|
+ this.save(mapEntity);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 切图上传oss
|
|
|
+ * @param tiledBasePath
|
|
|
+ * @param sceneCode
|
|
|
+ */
|
|
|
+ private void uplodaOss(String tiledBasePath, String sceneCode){
|
|
|
+ String tiledMapPath = tiledBasePath + "/results/laserData/cover/final_freespace.png";
|
|
|
+// String tiledMaptInfoPath = tiledBasePath + "/results/laserData/cover/info.json";
|
|
|
+
|
|
|
+ // 提供前端下载使用
|
|
|
+ String ossTiledMap = "data/" + sceneCode + "/download/final_freespace.png";
|
|
|
+ aliYunOssUtil.upload(tiledMapPath, ossTiledMap);
|
|
|
+
|
|
|
+ // 上传切片后的平面图
|
|
|
+ String uploadDir = tiledBasePath + "/results/laserData/cover";
|
|
|
+ uploadDiyCover(sceneCode, uploadDir );
|
|
|
+ log.info("切图上传oss完成");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 平面图算法调用
|
|
|
+ * @param inPath 工作目录
|
|
|
+ */
|
|
|
+ private void cmdTiledMap(String inPath){
|
|
|
+ String cmd = CmdConstant.TILED_MAP;
|
|
|
+ cmd = cmd.replace("@inPath", inPath);
|
|
|
+ CmdUtils.callLineSh(cmd, 50);
|
|
|
+ log.info("平面图算法调用完成");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
public void remove(String sceneCode) {
|
|
|
entityMapper.deleteById(sceneCode);
|
|
|
}
|
|
@@ -338,6 +457,7 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
dto.setQuadtree(quadTree);
|
|
|
dto.setType("TILED_PYRAMID");
|
|
|
dto.setTile_size_px(256);
|
|
|
+ dto.setSceneCode(sceneCode);
|
|
|
|
|
|
dto.setMap_size_m(mapSize_m);
|
|
|
// 使用dataSet.location
|
|
@@ -356,11 +476,24 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
String ossTarget = "data/" + sceneCode + "/" + dto.getFile_path();
|
|
|
String uploadDir = path + "/cover";
|
|
|
ossUploadDir(ossTarget, uploadDir);
|
|
|
- // 压缩并上传oss
|
|
|
- zipAndUploadOss(path, uploadDir, sceneCode);
|
|
|
+ // 压缩并上传oss提供下载
|
|
|
+// zipAndUploadOss(path, uploadDir, sceneCode);
|
|
|
+ tiledMapUploadOss(path, sceneCode);
|
|
|
|
|
|
return list;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 长传平面图提供下载
|
|
|
+ * @param basePath
|
|
|
+ * @param sceneCode
|
|
|
+ */
|
|
|
+ private void tiledMapUploadOss(String basePath, String sceneCode){
|
|
|
+ String tiledMapPath = basePath + "/cover/final_freespace.png";
|
|
|
+ // 提供前端下载使用
|
|
|
+ String ossTiledMap = "data/" + sceneCode + "/download/final_freespace.png";
|
|
|
+ aliYunOssUtil.upload(tiledMapPath, ossTiledMap);
|
|
|
+ log.info("平面图上传完成");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -387,7 +520,6 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
|
|
|
// 将cover上传oss
|
|
|
private void uploadCover(String sceneCode){
|
|
|
-// String path = redisPath(sceneCode) + "/laserData";
|
|
|
String path = redisPath(sceneCode) ;
|
|
|
// 11=floor_id值:site_model.type:floor的id
|
|
|
String bundlePath = "data/bundle_" + sceneCode +"/building_1/map_tiles/11";
|
|
@@ -396,7 +528,8 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
ossUploadDir(ossTarget, uploadDir);
|
|
|
|
|
|
// 压缩并上传oss
|
|
|
- zipAndUploadOss(path, uploadDir, sceneCode);
|
|
|
+// zipAndUploadOss(path, uploadDir, sceneCode);
|
|
|
+ tiledMapUploadOss(path, sceneCode);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -451,7 +584,10 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
// String out = "F:\\test\\ngin\\age_laser_data\\w-60\\results\\laserData\\1\\cover.zip";
|
|
|
// 有个bug, 如果路径中是以压缩包前缀命名包含在路径斜杠后面中会出错
|
|
|
String out = "F:\\test\\ngin\\age_laser_data\\w-60\\results\\laserData\\upload_cover\\cover.zip";
|
|
|
- ZipUtil.zip(new File(out), false, new File(filePath));
|
|
|
- }
|
|
|
+// ZipUtil.zip(new File(out), false, new File(filePath));
|
|
|
+
|
|
|
+ System.out.println(out.contains("w-60"));
|
|
|
+ System.out.println("w-60".contains(out));
|
|
|
+}
|
|
|
|
|
|
}
|