|
@@ -6,9 +6,12 @@ import cn.hutool.core.exceptions.ExceptionUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.fdkankan.common.bean.DownLoadProgressBean;
|
|
|
import com.fdkankan.common.bean.DownLoadTaskBean;
|
|
|
import com.fdkankan.common.constant.SceneDownloadProgressStatus;
|
|
|
+import com.fdkankan.common.constant.SceneFrom;
|
|
|
+import com.fdkankan.common.constant.SceneResolution;
|
|
|
import com.fdkankan.common.constant.ServerCode;
|
|
|
import com.fdkankan.common.constant.UploadFilePath;
|
|
|
import com.fdkankan.common.response.ResultData;
|
|
@@ -63,13 +66,26 @@ import org.springframework.web.client.RestTemplate;
|
|
|
@Service
|
|
|
public class SceneDownloadHandlerServiceImpl {
|
|
|
|
|
|
- // @Autowired
|
|
|
-// private PlatformUserClient platformUserClient;
|
|
|
+ private static final String[] prefixArr = new String[]{
|
|
|
+ UploadFilePath.DATA_VIEW_PATH,
|
|
|
+ UploadFilePath.VOICE_VIEW_PATH,
|
|
|
+ UploadFilePath.VIDEOS_VIEW_PATH,
|
|
|
+ UploadFilePath.IMG_VIEW_PATH,
|
|
|
+ UploadFilePath.USER_VIEW_PATH,
|
|
|
+ };
|
|
|
+
|
|
|
+ private static final List<ImageType> imageTypes = Lists.newArrayList();
|
|
|
+ static{
|
|
|
+ imageTypes.add(ImageType.builder().name("2k_face").size("2048").ranges(new String[]{"0", "511", "1023", "1535"}).build());
|
|
|
+ imageTypes.add(ImageType.builder().name("1k_face").size("1024").ranges(new String[]{"0", "511"}).build());
|
|
|
+ imageTypes.add(ImageType.builder().name("512_face").size("512").ranges(new String[]{"0"}).build());
|
|
|
+ }
|
|
|
+
|
|
|
@Autowired
|
|
|
private SceneUserSceneClient sceneUserSceneClient;
|
|
|
|
|
|
- @Value("${path.v3school}")
|
|
|
- private String v3localPath;
|
|
|
+ @Value("${path.v4school}")
|
|
|
+ private String v4localPath;
|
|
|
|
|
|
@Value("${path.zip-local}")
|
|
|
private String zipLocalFormat;
|
|
@@ -83,25 +99,11 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
@Value("${zip.nThreads}")
|
|
|
private int zipNthreads;
|
|
|
|
|
|
- private static final String[] prefixArr = new String[]{
|
|
|
- UploadFilePath.DATA_VIEW_PATH,
|
|
|
- UploadFilePath.VOICE_VIEW_PATH,
|
|
|
- UploadFilePath.VIDEOS_VIEW_PATH,
|
|
|
- UploadFilePath.IMG_VIEW_PATH,
|
|
|
- UploadFilePath.USER_VIEW_PATH,
|
|
|
- };
|
|
|
-
|
|
|
- private static final List<ImageType> imageTypes = Lists.newArrayList();
|
|
|
- static{
|
|
|
- imageTypes.add(ImageType.builder().name("2k_face").size("2048").ranges(new String[]{"0", "511", "1023", "1535"}).build());
|
|
|
- imageTypes.add(ImageType.builder().name("1k_face").size("1024").ranges(new String[]{"0", "511"}).build());
|
|
|
- imageTypes.add(ImageType.builder().name("512_face").size("512").ranges(new String[]{"0"}).build());
|
|
|
- }
|
|
|
+ @Value("${oss.bucket:4dkankan}")
|
|
|
+ private String bucket;
|
|
|
|
|
|
@Value("${upload.type:oss}")
|
|
|
private String uploadType;
|
|
|
- @Value("${download.config.server-url}")
|
|
|
- private String serverUrl;
|
|
|
@Value("${download.config.resource-url}")
|
|
|
private String resourceUrl;
|
|
|
@Value("${download.config.public-url}")
|
|
@@ -159,7 +161,7 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
try {
|
|
|
Set<String> cacheKeys = new ConcurrentHashSet<>();
|
|
|
|
|
|
- Map<String, List<String>> allFiles = this.getAllFiles(num, v3localPath);
|
|
|
+ Map<String, List<String>> allFiles = this.getAllFiles(num, v4localPath);
|
|
|
List<String> ossFilePaths = allFiles.get("ossFilePaths");
|
|
|
List<String> v3localFilePaths = allFiles.get("v3localFilePaths");
|
|
|
|
|
@@ -174,25 +176,35 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
}
|
|
|
ZipOutputStream out = new ZipOutputStream(zipFile);
|
|
|
|
|
|
- JSONObject getInfoJson = this.zipGetInfoJson(out, this.wwwroot, num);
|
|
|
- String resolution = "2k";
|
|
|
- if(getInfoJson.getInt("sceneSource") != null &&
|
|
|
- (getInfoJson.getInt("sceneSource") == 3 || getInfoJson.getInt("sceneSource") == 4)){
|
|
|
- resolution = "4k";
|
|
|
+// JSONObject getInfoJson = this.zipGetInfoJson(out, this.wwwroot, num);
|
|
|
+ String sceneJsonData = uploadToOssUtil.getObjectContent(bucket, String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json");
|
|
|
+ JSONObject sceneJson = JSONUtil.parseObj(sceneJsonData);
|
|
|
+ String resolution = "4k";
|
|
|
+ String sceneForm = sceneJson.getStr("sceneFrom");
|
|
|
+ if(StrUtil.isNotEmpty(sceneForm) && SceneFrom.PRO.code().equals(sceneForm)){
|
|
|
+ resolution = "2k";
|
|
|
+ }
|
|
|
+ //国际版存在已经切好图的情况,下载时不需要再切图,只需要把文件直接下载下来打包就可以了
|
|
|
+ String sceneResolution = sceneJson.getStr("sceneResolution");
|
|
|
+ if(SceneResolution.TILES.code().equals(sceneResolution)){
|
|
|
+ resolution = "notNeadCut";
|
|
|
}
|
|
|
+
|
|
|
int imagesVersion = -1;
|
|
|
// TODO: 2022/3/29 V4版本目前没有imagesVersion字段,暂时用version字段替代
|
|
|
// if(getInfoJson.getInt("imagesVersion") != null){
|
|
|
// imagesVersion = getInfoJson.getInt("imagesVersion");
|
|
|
// }
|
|
|
- if(getInfoJson.getInt("version") != null){
|
|
|
- imagesVersion = getInfoJson.getInt("version");
|
|
|
+ Integer version = sceneJson.getInt("version");
|
|
|
+ if(Objects.nonNull(version)){
|
|
|
+ imagesVersion = version;
|
|
|
}
|
|
|
|
|
|
|
|
|
long start = Calendar.getInstance().getTimeInMillis();
|
|
|
+
|
|
|
//固定文件写入
|
|
|
- this.zipLocalFiles(out, v3localFilePaths, v3localPath, num, count, total);
|
|
|
+ this.zipLocalFiles(out, v3localFilePaths, v4localPath, num, count, total);
|
|
|
long end1 = Calendar.getInstance().getTimeInMillis();
|
|
|
log.info("打包固定文件耗时, num:{}, time:{}", num, end1 - start);
|
|
|
|
|
@@ -201,6 +213,8 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
long end2 = Calendar.getInstance().getTimeInMillis();
|
|
|
log.info("打包oss文件耗时, num:{}, time:{}", num, end2 - end1);
|
|
|
|
|
|
+ //重新写入scene.json(去掉密码访问设置)
|
|
|
+ this.zipSceneJson(out, this.wwwroot, num, sceneJson);
|
|
|
|
|
|
//写入启动命令
|
|
|
this.zipBat(out, num);
|
|
@@ -275,14 +289,16 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
return;
|
|
|
|
|
|
//切图
|
|
|
- if((filePath.contains(imageNumPath + "panorama/") && filePath.contains("tiles/" + resolution))
|
|
|
- || filePath.contains(imageNumPath + "tiles/" + resolution + "/")) {
|
|
|
- this.processImage(filePath, out, resolution, imagesVersion, cacheKeys);
|
|
|
- return;
|
|
|
+ if(!"notNeadCut".equals(resolution)){
|
|
|
+ if((filePath.contains(imageNumPath + "panorama/") && filePath.contains("tiles/" + resolution))
|
|
|
+ || filePath.contains(imageNumPath + "tiles/" + resolution + "/")) {
|
|
|
+ this.processImage(filePath, out, resolution, imagesVersion, cacheKeys);
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//其他文件打包
|
|
|
- this.ProcessFiles(filePath, out, this.wwwroot, cacheKeys);
|
|
|
+ this.ProcessFiles(num, filePath, out, this.wwwroot, cacheKeys);
|
|
|
}
|
|
|
|
|
|
private void zipLocalFiles(ZipOutputStream out, List<String> v3localFilePaths, String v3localPath, String num, AtomicInteger count, int total) throws Exception{
|
|
@@ -364,6 +380,16 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
return getInfoJson;
|
|
|
}
|
|
|
|
|
|
+ private void zipSceneJson(ZipOutputStream out, String root, String num, JSONObject sceneJson) throws Exception{
|
|
|
+
|
|
|
+ //访问密码置0
|
|
|
+ JSONObject controls = sceneJson.getJSONObject("controls");
|
|
|
+ controls.set("showLock", 0);
|
|
|
+
|
|
|
+ String sceneJsonPath = root + String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json";
|
|
|
+ this.zipBytes(out, sceneJsonPath, sceneJson.toString().getBytes());
|
|
|
+ }
|
|
|
+
|
|
|
private void processImage(String key, ZipOutputStream out, String resolution, int imagesVersion, Set<String> imgKeys) throws Exception{
|
|
|
|
|
|
String fileName = key.substring(key.lastIndexOf("/")+1, key.indexOf("."));
|
|
@@ -427,10 +453,13 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void ProcessFiles(String key, ZipOutputStream out, String prefix, Set<String> cacheKeys) throws Exception{
|
|
|
+ public void ProcessFiles(String num, String key, ZipOutputStream out, String prefix, Set<String> cacheKeys) throws Exception{
|
|
|
if(cacheKeys.contains(key)){
|
|
|
return;
|
|
|
}
|
|
|
+ if(key.equals(String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json")){
|
|
|
+ return;
|
|
|
+ }
|
|
|
cacheKeys.add(key);
|
|
|
String url = this.resourceUrl + key + "?t=" + Calendar.getInstance().getTimeInMillis();
|
|
|
if(key.contains("hot.json") || key.contains("link-scene.json")){
|