|
@@ -90,6 +90,8 @@ public class DownloadServiceImpl implements IDownloadService {
|
|
|
private String exeName;
|
|
|
@Value("${path.zip-oss}")
|
|
|
private String zipOssFormat;
|
|
|
+// @Value("${cutImgType}")
|
|
|
+// private String cutImgType;
|
|
|
|
|
|
@Autowired
|
|
|
private IScenePlusService scenePlusService;
|
|
@@ -101,6 +103,7 @@ public class DownloadServiceImpl implements IDownloadService {
|
|
|
private RedisUtil redisUtil;
|
|
|
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public void downloadHandler(String num) throws Exception {
|
|
|
|
|
@@ -120,13 +123,13 @@ public class DownloadServiceImpl implements IDownloadService {
|
|
|
|
|
|
Set<String> cacheKeys = new ConcurrentHashSet<>();
|
|
|
|
|
|
- Map<String, List<String>> allFiles = this.getAllFiles(num, v4localPath, bucket);
|
|
|
- List<String> ossFilePaths = allFiles.get("ossFilePaths");
|
|
|
- List<String> v4localFilePaths = allFiles.get("localFilePaths");
|
|
|
+// Map<String, List<String>> allFiles = this.getAllFiles(num, v4localPath, bucket);
|
|
|
+// List<String> ossFilePaths = allFiles.get("ossFilePaths");
|
|
|
+// List<String> v4localFilePaths = allFiles.get("localFilePaths");
|
|
|
|
|
|
//key总个数
|
|
|
- int total = ossFilePaths.size() + v4localFilePaths.size();
|
|
|
- AtomicInteger count = new AtomicInteger(0);
|
|
|
+// int total = ossFilePaths.size() + v4localFilePaths.size();
|
|
|
+// AtomicInteger count = new AtomicInteger(0);
|
|
|
|
|
|
//定义压缩包
|
|
|
zipPath = String.format(this.zipLocalFormat, num);
|
|
@@ -149,11 +152,11 @@ public class DownloadServiceImpl implements IDownloadService {
|
|
|
}
|
|
|
|
|
|
//固定文件写入
|
|
|
- this.zipLocalFiles(v4localFilePaths, v4localPath, num, count, total, "v4");
|
|
|
+ this.zipLocalFiles(num, "v4");
|
|
|
log.info("打包固定文件耗时, num:{}, time:{}", num, timer.intervalRestart());
|
|
|
|
|
|
//oss文件写入
|
|
|
- this.zipOssFiles(ossFilePaths, num, count, total, resolution, imagesVersion, cacheKeys, "v4");
|
|
|
+ this.zipOssFiles(num, resolution, imagesVersion, cacheKeys, "v4");
|
|
|
log.info("打包oss文件耗时, num:{}, time:{}", num, timer.intervalRestart());
|
|
|
|
|
|
//重新写入scene.json(去掉密码访问设置)
|
|
@@ -196,70 +199,74 @@ public class DownloadServiceImpl implements IDownloadService {
|
|
|
FileUtil.writeUtf8String(JSON.toJSONString(sceneViewInfo, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullNumberAsZero), String.format(this.sourceLocal, num, this.wwwroot + sceneJsonPath));
|
|
|
}
|
|
|
|
|
|
- private void zipOssFiles(List<String> ossFilePaths, String num, AtomicInteger count,
|
|
|
- int total, String resolution, int imagesVersion, Set<String> cacheKeys, String version) throws Exception{
|
|
|
- if(CollUtil.isEmpty(ossFilePaths)){
|
|
|
- return;
|
|
|
- }
|
|
|
+ private void zipOssFiles(String num, String resolution, int imagesVersion, Set<String> cacheKeys, String version) throws Exception{
|
|
|
+
|
|
|
+ fYunFileService.downloadFileByCommand(String.format(sourceLocal, num, this.wwwroot), String.format(UploadFilePath.VIEW_PATH, num));
|
|
|
+
|
|
|
+ //特殊文件处理
|
|
|
+ this.reWriteFile(num);
|
|
|
+
|
|
|
+ //切图
|
|
|
+ String filePath = String.format(sourceLocal, num, this.wwwroot + String.format(UploadFilePath.IMG_VIEW_PATH, num) + "tiles/");
|
|
|
+ this.cutImg(num, filePath, resolution, "tiles");
|
|
|
+
|
|
|
+ //切图-场景关联
|
|
|
+
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void cutImg(String num, String path, String resolution, String subPath) throws Exception {
|
|
|
+
|
|
|
String imageNumPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
|
|
|
- if("v3".equals(version)){
|
|
|
- imageNumPath = String.format("images/images%s/", num);
|
|
|
- }
|
|
|
+ String tilesOssPath = imageNumPath.concat(subPath + "/" + resolution);
|
|
|
+ List<String> cubeList = fYunFileService.listRemoteFiles(tilesOssPath);
|
|
|
ExecutorService executorService = Executors.newFixedThreadPool(this.zipNthreads);
|
|
|
List<Future> futureList = new ArrayList<>();
|
|
|
- for (String filePath : ossFilePaths) {
|
|
|
- String finalImageNumPath = imageNumPath;
|
|
|
+ for (String key : cubeList) {
|
|
|
Callable<Boolean> call = new Callable() {
|
|
|
@Override
|
|
|
public Boolean call() throws Exception {
|
|
|
- zipOssFilesHandler(num, count, total, resolution,
|
|
|
- imagesVersion, cacheKeys,filePath, finalImageNumPath, version);
|
|
|
+ processImage(key, resolution, path);
|
|
|
return true;
|
|
|
}
|
|
|
};
|
|
|
futureList.add(executorService.submit(call));
|
|
|
}
|
|
|
- //这里一定要加阻塞,不然会导致oss文件还没打包好,主程序已经结束返回了
|
|
|
- Boolean zipSuccess = true;
|
|
|
for (Future future : futureList) {
|
|
|
try {
|
|
|
future.get();
|
|
|
}catch (Exception e){
|
|
|
- log.error("打包oss文件失败", e);
|
|
|
- zipSuccess = false;
|
|
|
+ log.error("切图失败", e);
|
|
|
+ executorService.shutdownNow();
|
|
|
+ throw new Exception("切图失败");
|
|
|
}
|
|
|
}
|
|
|
- if(!zipSuccess){
|
|
|
- throw new Exception("打包oss文件失败");
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- private void zipOssFilesHandler(String num,
|
|
|
- AtomicInteger count, int total, String resolution,
|
|
|
- int imagesVersion, Set<String> cacheKeys,
|
|
|
- String filePath, String imageNumPath, String version) throws Exception{
|
|
|
-
|
|
|
- if(filePath.endsWith("/")){
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //某个目录不需要打包
|
|
|
- if(filePath.contains(imageNumPath + "panorama/panorama_edit/"))
|
|
|
- return;
|
|
|
-
|
|
|
- //切图
|
|
|
- if(!"notNeadCut".equals(resolution)){
|
|
|
- if((filePath.contains(imageNumPath + "panorama/") && filePath.contains("tiles/" + resolution))
|
|
|
- || filePath.contains(imageNumPath + "tiles/" + resolution + "/")) {
|
|
|
- this.processImage(num, filePath, resolution, imagesVersion, cacheKeys);
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //其他文件打包
|
|
|
- this.ProcessFiles(num, filePath, this.wwwroot, cacheKeys);
|
|
|
-
|
|
|
- }
|
|
|
+// private void zipOssFilesHandler(String num, String resolution,
|
|
|
+// int imagesVersion, Set<String> cacheKeys,
|
|
|
+// String filePath, String imageNumPath, String version) throws Exception{
|
|
|
+//
|
|
|
+// if(filePath.endsWith("/")){
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// //某个目录不需要打包
|
|
|
+// if(filePath.contains(imageNumPath + "panorama/panorama_edit/"))
|
|
|
+// return;
|
|
|
+//
|
|
|
+// //切图
|
|
|
+// if(!"notNeadCut".equals(resolution)){
|
|
|
+// if((filePath.contains(imageNumPath + "panorama/") && filePath.contains("tiles/" + resolution))
|
|
|
+// || filePath.contains(imageNumPath + "tiles/" + resolution + "/")) {
|
|
|
+// this.processImage(num, filePath, resolution, imagesVersion, cacheKeys);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// //其他文件打包
|
|
|
+// this.ProcessFiles(num, filePath, this.wwwroot, cacheKeys);
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
public void ProcessFiles(String num, String key, String prefix, Set<String> cacheKeys) throws Exception{
|
|
|
if(cacheKeys.contains(key)){
|
|
@@ -291,7 +298,18 @@ public class DownloadServiceImpl implements IDownloadService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void processImage(String sceneNum, String key, String resolution, int imagesVersion, Set<String> imgKeys) throws Exception{
|
|
|
+ private void reWriteFile(String num){
|
|
|
+ String filePath = String.format(sourceLocal, num, this.wwwroot + String.format(UploadFilePath.USER_VIEW_PATH, num) + "hot.json");
|
|
|
+ if(FileUtil.exist(filePath)){
|
|
|
+ String content = FileUtil.readUtf8String(filePath);
|
|
|
+ content = content.replace(publicUrl, "")
|
|
|
+ .replace("https://spc.html","spc.html")
|
|
|
+ .replace("https://smobile.html", "smobile.html");
|
|
|
+ FileUtil.writeUtf8String(content, filePath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processImage(String key, String resolution, String path) throws Exception{
|
|
|
|
|
|
if(key.contains("x-oss-process") || key.endsWith("/")){
|
|
|
return;
|
|
@@ -315,11 +333,6 @@ public class DownloadServiceImpl implements IDownloadService {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
-// imageTypes.add(ImageType.builder().name("4k_face").size("4096").ranges(new String[]{"0", "511", "1023", "1535", "2047","2559","3071","3583"}).build());
|
|
|
-// 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());
|
|
|
-
|
|
|
List<ImageTypeDetail> items = Lists.newArrayList();
|
|
|
String[] ranges = imageType.getRanges();
|
|
|
for(int i = 0; i < ranges.length; i++){
|
|
@@ -338,9 +351,9 @@ public class DownloadServiceImpl implements IDownloadService {
|
|
|
}
|
|
|
for (ImageTypeDetail item : items) {
|
|
|
String par = "?x-oss-process=image/resize,m_lfit,w_" + imageType.getSize() + "/crop,w_512,h_512,x_" + item.getX() + ",y_" + item.getY();
|
|
|
- if(FYunTypeEnum.AWS.code().equals(uploadType)){
|
|
|
- par += "&imagesVersion="+ imagesVersion;
|
|
|
- }
|
|
|
+// if(FYunTypeEnum.AWS.code().equals(uploadType)){
|
|
|
+// par += "&imagesVersion="+ imagesVersion;
|
|
|
+// }
|
|
|
|
|
|
var url = this.resourceUrl + key;
|
|
|
FYunTypeEnum storageType = FYunTypeEnum.get(uploadType);
|
|
@@ -352,13 +365,10 @@ public class DownloadServiceImpl implements IDownloadService {
|
|
|
url += URLEncoder.encode(par.replace("/", "@"), "UTF-8");
|
|
|
break;
|
|
|
}
|
|
|
- //scene_view_data/t-jp-WXWxmOuj4Kf/images/tiles/0/4k_face_0_0_0.jpg
|
|
|
- var fky = key.split("/" + resolution + "/")[0] + "/" + dir + "/" + imageType.getName() + num + "_" + item.getI() + "_" + item.getJ() + ext;
|
|
|
- if(imgKeys.contains(fky)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- imgKeys.add(fky);
|
|
|
- this.downloadFile(url, String.format(sourceLocal, sceneNum, this.wwwroot + fky));
|
|
|
+ //key.split("/" + resolution + "/")[0] + "/" +
|
|
|
+ var fky = dir + "/" + imageType.getName() + num + "_" + item.getI() + "_" + item.getJ() + ext;
|
|
|
+ this.downloadFile(url, path + fky);
|
|
|
+// this.downloadFile(url, path);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -373,16 +383,10 @@ public class DownloadServiceImpl implements IDownloadService {
|
|
|
HttpUtil.downloadFile(url, path);
|
|
|
}
|
|
|
|
|
|
- private void zipLocalFiles(List<String> localFilePaths, String v3localPath, String num, AtomicInteger count, int total, String version) throws Exception{
|
|
|
+ private void zipLocalFiles(String num, String version) throws Exception{
|
|
|
String sourcePath = String.format(this.sourceLocal, num, "");
|
|
|
String localPath = "v4".equals(version) ? this.v4localPath : this.v3localPath;
|
|
|
- for (String localFilePath : localFilePaths) {
|
|
|
- try (FileInputStream in = new FileInputStream(new File(localFilePath));){
|
|
|
- FileUtil.copy(localFilePath, localFilePath.replace(localPath, sourcePath), true);
|
|
|
- }catch (Exception e){
|
|
|
- throw e;
|
|
|
- }
|
|
|
- }
|
|
|
+ FileUtil.copyContent(FileUtil.newFile(localPath), FileUtil.newFile(sourcePath), true);
|
|
|
//写入code.txt
|
|
|
FileUtil.writeUtf8String(num, String.format(sourceLocal, num, "code.txt"));
|
|
|
}
|