|
@@ -1,13 +1,18 @@
|
|
package com.gis.service.impl;
|
|
package com.gis.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.gis.YunDto;
|
|
import com.gis.common.constant.CmdConstant;
|
|
import com.gis.common.constant.CmdConstant;
|
|
import com.gis.common.constant.ConfigConstant;
|
|
import com.gis.common.constant.ConfigConstant;
|
|
import com.gis.common.constant.PathConstant;
|
|
import com.gis.common.constant.PathConstant;
|
|
import com.gis.common.exception.BaseRuntimeException;
|
|
import com.gis.common.exception.BaseRuntimeException;
|
|
import com.gis.common.util.CmdUtils;
|
|
import com.gis.common.util.CmdUtils;
|
|
|
|
+import com.gis.common.util.FileUtils;
|
|
import com.gis.common.util.Result;
|
|
import com.gis.common.util.Result;
|
|
-import com.gis.common.util.StrUtils;
|
|
|
|
import com.gis.service.AliOssService;
|
|
import com.gis.service.AliOssService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -16,6 +21,7 @@ import org.springframework.stereotype.Service;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -28,6 +34,9 @@ public class AliOssServiceImpl implements AliOssService {
|
|
@Autowired
|
|
@Autowired
|
|
ConfigConstant configConstant;
|
|
ConfigConstant configConstant;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ FileUtils fileUtils;
|
|
|
|
+
|
|
static final HashMap<Object, String> bucketMap;
|
|
static final HashMap<Object, String> bucketMap;
|
|
|
|
|
|
static {
|
|
static {
|
|
@@ -38,39 +47,128 @@ public class AliOssServiceImpl implements AliOssService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Result batchDownload(List<String> code, String evn, String workId) {
|
|
|
|
- log.info("输入场景码数量: {}", code.size());
|
|
|
|
|
|
+ public Result batchDownload(YunDto param) {
|
|
|
|
|
|
- String bucket = bucketMap.get(evn);
|
|
|
|
- BaseRuntimeException.isNull(bucket, null, "bucket环境不能为空");
|
|
|
|
|
|
+ String workId = param.getWorkId();
|
|
|
|
+ // 1.删除旧目录
|
|
|
|
+ fileUtils.del("/" + workId);
|
|
|
|
|
|
|
|
+ // 2.下载someData.json
|
|
|
|
+ downloadSomeDataJson(workId);
|
|
|
|
+
|
|
|
|
+ // 3.下载场景
|
|
|
|
+ downloadScenes(param);
|
|
|
|
+
|
|
|
|
+ // 4. 获取导览图集合
|
|
|
|
+ HashMap<String, String> guideThumbs = getGuideThumbBySomeData(workId);
|
|
|
|
+
|
|
|
|
+ // 5.下载导览图
|
|
|
|
+ downloadGuideThumb(guideThumbs, workId);
|
|
|
|
+
|
|
|
|
+ // 6.压缩zip
|
|
|
|
+ zipWork(workId);
|
|
|
|
+ String outPath = configConstant.serverBasePath + "/download/" + workId +".zip";
|
|
|
|
+ return Result.success(outPath);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void zipWork(String workId) {
|
|
|
|
+ String outPath = configConstant.serverBasePath + "/download/" + workId +".zip";
|
|
|
|
+
|
|
|
|
+ String cmd = CmdConstant.zip;
|
|
|
|
+ cmd = cmd.replaceAll("@output", outPath);
|
|
|
|
+ cmd = cmd.replaceAll("@workPace", configConstant.serverBasePath + "/download" );
|
|
|
|
+ // 已引入工作目录, 直接填写目录即可
|
|
|
|
+ cmd = cmd.replaceAll("@inDir", workId);
|
|
|
|
+
|
|
|
|
+ CmdUtils.callShLine(cmd, 100);
|
|
|
|
+ log.info("打包压缩完成: {}", outPath);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 下载场景目录
|
|
|
|
+ * @param param
|
|
|
|
+ */
|
|
|
|
+ private void downloadScenes(YunDto param){
|
|
|
|
+ List<String> sceneCodes = param.getSceneCodes();
|
|
|
|
+ log.info("输入场景码数量: {}", sceneCodes.size());
|
|
|
|
+
|
|
|
|
+ String bucket = bucketMap.get(param.getEvn());
|
|
|
|
+ BaseRuntimeException.isNull(bucket, null, "bucket环境不能为空");
|
|
|
|
|
|
- String dir ;
|
|
|
|
- if (StrUtil.isBlank(workId)){
|
|
|
|
- dir = "720yun_" + StrUtils.getTimeStr();
|
|
|
|
- } else {
|
|
|
|
- dir = "720yun_" + workId + "_" + StrUtils.getTimeStr();
|
|
|
|
- }
|
|
|
|
- String outPath = configConstant.serverBasePath + dir;
|
|
|
|
- log.info("下载目录: {}", outPath);
|
|
|
|
int i = 1;
|
|
int i = 1;
|
|
- for (String sceneCode : code) {
|
|
|
|
- downloadOss(sceneCode, outPath, bucket);
|
|
|
|
|
|
+ for (String sceneCode : sceneCodes) {
|
|
|
|
+ downloadOss(sceneCode, bucket, param.getWorkId());
|
|
log.info("第:{} 下载完成, 场景为:{}", i, sceneCode);
|
|
log.info("第:{} 下载完成, 场景为:{}", i, sceneCode);
|
|
i++;
|
|
i++;
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- return Result.success(outPath);
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 2022-5-30
|
|
|
|
+ * 建议前端将导览图片固定命名
|
|
|
|
+ * 通过读取someData.json获取导图图片
|
|
|
|
+ *
|
|
|
|
+ * @param workId
|
|
|
|
+ */
|
|
|
|
+ private HashMap<String, String> getGuideThumbBySomeData(String workId){
|
|
|
|
+ String someDataPath = configConstant.serverBasePath + "/download/" + workId + "/someData.json";
|
|
|
|
+ String str = FileUtil.readString(someDataPath, "utf-8");
|
|
|
|
+ JSONObject parent = JSONObject.parseObject(str);
|
|
|
|
+ // 场景数组
|
|
|
|
+ JSONArray scenes = parent.getJSONArray("scenes");
|
|
|
|
+ HashMap<String, String> resMap = new HashMap<>();
|
|
|
|
+ for (Object scene : scenes) {
|
|
|
|
+ // 场景对象
|
|
|
|
+ JSONObject row = JSONObject.parseObject(scene.toString());
|
|
|
|
+ resMap.put(row.getString("sceneCode"), row.getString("icon"));
|
|
|
|
+ }
|
|
|
|
+ log.info("处理导览图片完成, 图片数量: {}", resMap.size());
|
|
|
|
+ return resMap;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 下载导览封面图片
|
|
|
|
+ * @param iconMap 需要下载的缩略图
|
|
|
|
+ * @param workId
|
|
|
|
+ */
|
|
|
|
+ private void downloadGuideThumb(Map<String, String> iconMap, String workId){
|
|
|
|
+ String savePath = configConstant.serverBasePath + "/download/" + workId + "/images";
|
|
|
|
+ for (Map.Entry<String, String> m : iconMap.entrySet()) {
|
|
|
|
+ String sceneCode = m.getKey();
|
|
|
|
+ String ossUrl = m.getValue();
|
|
|
|
+ HttpUtil.downloadFile(ossUrl, savePath);
|
|
|
|
+ log.info("场景:{} 保存路径: {} 完成", sceneCode, savePath);
|
|
|
|
+ }
|
|
|
|
+ log.info("下载导览图片完成: {}", savePath);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 下载someData.json
|
|
|
|
+ */
|
|
|
|
+ private void downloadSomeDataJson(String workId){
|
|
|
|
+ String baseUrl = "https://4dkk.4dage.com/720yun_fd_manage/";
|
|
|
|
+ String url = baseUrl + workId + "/someData.json?m="+ System.currentTimeMillis();
|
|
|
|
+ String savePath = configConstant.serverBasePath + "/download/" + workId + "/someData.json";
|
|
|
|
+ HttpUtil.downloadFile(url, savePath);
|
|
|
|
+ log.info("下载someData.json完成: {}", workId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 下载oss目录
|
|
* 下载oss目录
|
|
* @outPath 下载时会以目录形式下载, 指定输出根目录
|
|
* @outPath 下载时会以目录形式下载, 指定输出根目录
|
|
|
|
+ *
|
|
|
|
+ *
|
|
*/
|
|
*/
|
|
- private void downloadOss(String sceneCode, String outPath, String bucket){
|
|
|
|
|
|
+ private void downloadOss(String sceneCode, String bucket, String workId){
|
|
String cmd = CmdConstant.OSSUTIL_DOWNLOAD_DIR;
|
|
String cmd = CmdConstant.OSSUTIL_DOWNLOAD_DIR;
|
|
String inPath = PathConstant.OSS_720YUN_MANAGE + File.separator + sceneCode;
|
|
String inPath = PathConstant.OSS_720YUN_MANAGE + File.separator + sceneCode;
|
|
|
|
+ String outPath = configConstant.serverBasePath + "/" + workId;
|
|
cmd = cmd.replaceAll("@inPath", inPath);
|
|
cmd = cmd.replaceAll("@inPath", inPath);
|
|
cmd = cmd.replaceAll("@outPath", outPath);
|
|
cmd = cmd.replaceAll("@outPath", outPath);
|
|
cmd = cmd.replaceAll("@bucket", bucket);
|
|
cmd = cmd.replaceAll("@bucket", bucket);
|
|
@@ -81,3 +179,5 @@ public class AliOssServiceImpl implements AliOssService {
|
|
log.info("目录下载完成: {}, 耗时:{} s" , sceneCode, (end-start)/1000 );
|
|
log.info("目录下载完成: {}, 耗时:{} s" , sceneCode, (end-start)/1000 );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|