|
@@ -1,12 +1,14 @@
|
|
|
package com.fdkankan.indoor.core.service.impl;
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.ZipUtil;
|
|
|
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.AliYunOssUtil;
|
|
|
import com.fdkankan.indoor.base.util.CmdUtils;
|
|
|
import com.fdkankan.indoor.base.util.Result;
|
|
|
import com.fdkankan.indoor.core.entity.DataSetEntity;
|
|
@@ -16,12 +18,15 @@ 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 com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.junit.Test;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -40,6 +45,9 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
@Autowired
|
|
|
DataSetServiceImpl dataSetService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ AliYunOssUtil aliYunOssUtil;
|
|
|
+
|
|
|
@Override
|
|
|
public TiledMapEntity findById(String sceneCode){
|
|
|
Optional<TiledMapEntity> optional = entityMapper.findById(sceneCode);
|
|
@@ -57,23 +65,114 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
|
|
|
@Override
|
|
|
public void init(String sceneCode) {
|
|
|
- TiledMapEntity entity = new TiledMapEntity();
|
|
|
- entity.setId(sceneCode);
|
|
|
- entity.setCreateTime(LocalDateTime.now());
|
|
|
- // 2021.09.03
|
|
|
- entity.setData(initData(sceneCode));
|
|
|
- entityMapper.save(entity);
|
|
|
+ TiledMapEntity entity = findById(sceneCode);
|
|
|
+ if (entity == null) {
|
|
|
+ entity = new TiledMapEntity();
|
|
|
+ entity.setCreateTime(LocalDateTime.now());
|
|
|
+ entity.setId(sceneCode);
|
|
|
+ // 2021.09.03
|
|
|
+ entity.setData(initData(sceneCode));
|
|
|
+ } else {
|
|
|
+ // web端重算, 把cover重新上传oss就行
|
|
|
+ uploadCover(sceneCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ entity.setStatus(0);
|
|
|
+ entity.setDisplay(0);
|
|
|
+ this.save(entity);
|
|
|
|
|
|
log.info("TiledMap数据初始化完成");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void save(TiledMapEntity entity) {
|
|
|
- entity.setCreateTime(LocalDateTime.now());
|
|
|
+ entity.setUpdateTime(LocalDateTime.now());
|
|
|
entityMapper.save(entity);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public Result getDetail(String sceneCode) {
|
|
|
+ return Result.success(findById(sceneCode));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result updateDisplay(String sceneCode, Integer display) {
|
|
|
+ TiledMapEntity entity = findById(sceneCode);
|
|
|
+ entity.setDisplay(display);
|
|
|
+ this.save(entity);
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result upload(String sceneCode, MultipartFile file) {
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
+ if (originalFilename == null || !originalFilename.toLowerCase().endsWith(".zip")) {
|
|
|
+ log.error("文件名: {}", originalFilename);
|
|
|
+ return Result.failure("文件不能为空, 或者不是zip文件");
|
|
|
+ }
|
|
|
+ String basePath = redisPath(sceneCode) + "/laserData/upload_cover";
|
|
|
+ String savePath = basePath + "/cover.zip";
|
|
|
+ if ("dev".equals(configConstant.active)) {
|
|
|
+ savePath = configConstant.serverBasePath + "/" + sceneCode + "/results/laserData/upload_cover/cover.zip";
|
|
|
+ }
|
|
|
+ log.info("上传平面图保存路径:{}", savePath);
|
|
|
+ try {
|
|
|
+ FileUtil.writeFromStream(file.getInputStream(), savePath);
|
|
|
+ log.info("平面图写入服务器完成");
|
|
|
+
|
|
|
+ if (!FileUtil.isFile(savePath)) {
|
|
|
+ log.error("cover.zip不存:{}" + savePath);
|
|
|
+ return Result.failure("服务器cover.zip不存");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解压cover.zip
|
|
|
+ ZipUtil.unzip(savePath);
|
|
|
+ log.info("cover.zip解压完成");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 目录上传oss
|
|
|
+ String uploadDir = basePath + "/cover";
|
|
|
+
|
|
|
+ // 判断上传的cover.zip 是否包含目录,如有,抛异常
|
|
|
+ if (!FileUtil.exist(uploadDir + "/0")){
|
|
|
+ String msg = "上传的zip包目录结构有误, 不能包含目录,请检查";
|
|
|
+ log.error(msg);
|
|
|
+ return Result.failure(msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ uploadDiyCover(sceneCode, uploadDir );
|
|
|
+
|
|
|
+ // 将cover.zip 更新到oss. data/sceneCode/upload_cover/cover.zip
|
|
|
+ String ossCoverZip = "data/" + sceneCode + "upload_cover/cover.zip";
|
|
|
+ aliYunOssUtil.upload(savePath, ossCoverZip);
|
|
|
+ log.info("ossCoverZip更新oss完成:{}", ossCoverZip);
|
|
|
+
|
|
|
+ TiledMapEntity entity = findById(sceneCode);
|
|
|
+ entity.setStatus(1);
|
|
|
+ this.save(entity);
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * oss目录下载平面图
|
|
|
+ * @param sceneCode
|
|
|
+ * @return 前端自己拼接oss域名
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result download(String sceneCode) {
|
|
|
+ String basePath = "data/" + sceneCode + "/upload_cover/cover.zip";
|
|
|
+ return Result.success(basePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public void remove(String sceneCode) {
|
|
|
entityMapper.deleteById(sceneCode);
|
|
|
}
|
|
@@ -246,10 +345,54 @@ 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);
|
|
|
+
|
|
|
return list;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 压缩并上传oss
|
|
|
+ * @param path 服务器基础路径
|
|
|
+ * @param uploadDir 需要压缩的目录
|
|
|
+ * @param sceneCode 场景码
|
|
|
+ */
|
|
|
+ private void zipAndUploadOss(String path, String uploadDir, String sceneCode){
|
|
|
+ // cover压缩上传oss, 提供平面图下载, 存放在data/sceneCode/upload_cover
|
|
|
+ String outPath = path + "/upload_cover/cover.zip";
|
|
|
+ log.info("cover.zip path: {}", outPath);
|
|
|
+ ZipUtil.zip(new File(outPath), false, new File(uploadDir));
|
|
|
+ log.info("文件压缩成功: {}", outPath);
|
|
|
+
|
|
|
+ String ossZipPath = "data/" + sceneCode + "/upload_cover/cover.zip";
|
|
|
+ aliYunOssUtil.upload(outPath, ossZipPath);
|
|
|
+ log.info("cover.zip上传oss完成:{}", ossZipPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将cover上传oss
|
|
|
+ private void uploadCover(String sceneCode){
|
|
|
+ String path = redisPath(sceneCode) + "/laserData";
|
|
|
+ // 11=floor_id值:site_model.type:floor的id
|
|
|
+ String bundlePath = "data/bundle_" + sceneCode +"/building_1/map_tiles/11";
|
|
|
+ String ossTarget = "data/" + sceneCode + "/" + bundlePath;
|
|
|
+ String uploadDir = path + "/cover";
|
|
|
+ ossUploadDir(ossTarget, uploadDir);
|
|
|
+
|
|
|
+ // 压缩并上传oss
|
|
|
+ zipAndUploadOss(path, uploadDir, sceneCode);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 自定义cover上传oss
|
|
|
+ private void uploadDiyCover(String sceneCode, String uploadDir){
|
|
|
+ // 11=floor_id值:site_model.type:floor的id
|
|
|
+ String bundlePath = "data/bundle_" + sceneCode +"/building_1/map_tiles/11";
|
|
|
+ String ossTarget = "data/" + sceneCode + "/" + bundlePath;
|
|
|
+ ossUploadDir(ossTarget, uploadDir);
|
|
|
+ }
|
|
|
+
|
|
|
private void ossUploadDir(String ossTarget, String uploadDir){
|
|
|
String cmd = CmdConstant.OSSUTIL_UPLOAD_DIR;
|
|
|
cmd = cmd.replaceAll("@uploadDir", uploadDir);
|
|
@@ -286,4 +429,13 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testZip(){
|
|
|
+ String filePath = "F:\\test\\ngin\\age_laser_data\\w-60\\results\\laserData\\cover";
|
|
|
+// 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));
|
|
|
+ }
|
|
|
+
|
|
|
}
|