|
@@ -7,24 +7,28 @@ 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.ErrorCode;
|
|
|
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.exception.BusinessException;
|
|
|
import com.fdkankan.common.response.ResultData;
|
|
|
import com.fdkankan.common.util.FileUtils;
|
|
|
import com.fdkankan.download.bean.CurrentDownloadNumUtil;
|
|
|
+import com.fdkankan.download.bean.DownLoadProgressBean;
|
|
|
+import com.fdkankan.download.bean.DownLoadTaskBean;
|
|
|
import com.fdkankan.download.bean.ImageType;
|
|
|
import com.fdkankan.download.bean.ImageTypeDetail;
|
|
|
-import com.fdkankan.fyun.constant.StorageType;
|
|
|
-import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
+import com.fdkankan.download.entity.ScenePlus;
|
|
|
+import com.fdkankan.download.entity.ScenePlusExt;
|
|
|
+import com.fdkankan.download.service.IScenePlusExtService;
|
|
|
+import com.fdkankan.download.service.IScenePlusService;
|
|
|
+import com.fdkankan.fyun.constant.FYunTypeEnum;
|
|
|
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
-import com.fdkankan.scene.api.dto.SceneInfoDTO;
|
|
|
-import com.fdkankan.scene.api.feign.SceneUserSceneClient;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
@@ -81,27 +85,18 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
imageTypes.add(ImageType.builder().name("512_face").size("512").ranges(new String[]{"0"}).build());
|
|
|
}
|
|
|
|
|
|
- @Autowired
|
|
|
- private SceneUserSceneClient sceneUserSceneClient;
|
|
|
-
|
|
|
@Value("${path.v4school}")
|
|
|
private String v4localPath;
|
|
|
-
|
|
|
@Value("${path.zip-local}")
|
|
|
private String zipLocalFormat;
|
|
|
-
|
|
|
@Value("${path.zip-oss}")
|
|
|
private String zipOssFormat;
|
|
|
-
|
|
|
@Value("${path.zip-root}")
|
|
|
private String wwwroot;
|
|
|
-
|
|
|
@Value("${zip.nThreads}")
|
|
|
private int zipNthreads;
|
|
|
-
|
|
|
@Value("${oss.bucket:4dkankan}")
|
|
|
private String bucket;
|
|
|
-
|
|
|
@Value("${upload.type:oss}")
|
|
|
private String uploadType;
|
|
|
@Value("${download.config.resource-url}")
|
|
@@ -112,13 +107,15 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
private String exeName;
|
|
|
@Value("${download.config.exe-content}")
|
|
|
private String exeContent;
|
|
|
- @Autowired
|
|
|
- RestTemplate restTemplate;
|
|
|
|
|
|
@Autowired
|
|
|
- RedisUtil redisUtil;
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ private FYunFileServiceInterface fYunFileService;
|
|
|
@Autowired
|
|
|
- UploadToOssUtil uploadToOssUtil;
|
|
|
+ private IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusExtService scenePlusExtService;
|
|
|
|
|
|
@Async("sceneDownLoadExecutror")
|
|
|
public void download(DownLoadTaskBean downLoadTaskBean){
|
|
@@ -159,9 +156,16 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
String zipPath = null;
|
|
|
|
|
|
try {
|
|
|
+
|
|
|
+ ScenePlus scenePlus = scenePlusService.getByNum(num);
|
|
|
+ if(Objects.isNull(scenePlus))
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ ScenePlusExt scenePlusExt = scenePlusExtService.getByScenePlusId(scenePlus.getId());
|
|
|
+ String bucket = scenePlusExt.getYunFileBucket();
|
|
|
+
|
|
|
Set<String> cacheKeys = new ConcurrentHashSet<>();
|
|
|
|
|
|
- Map<String, List<String>> allFiles = this.getAllFiles(num, v4localPath);
|
|
|
+ Map<String, List<String>> allFiles = this.getAllFiles(num, v4localPath, bucket);
|
|
|
List<String> ossFilePaths = allFiles.get("ossFilePaths");
|
|
|
List<String> v3localFilePaths = allFiles.get("v3localFilePaths");
|
|
|
|
|
@@ -176,8 +180,7 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
}
|
|
|
ZipOutputStream out = new ZipOutputStream(zipFile);
|
|
|
|
|
|
-// JSONObject getInfoJson = this.zipGetInfoJson(out, this.wwwroot, num);
|
|
|
- String sceneJsonData = uploadToOssUtil.getObjectContent(bucket, String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json");
|
|
|
+ String sceneJsonData = fYunFileService.getFileContent(bucket, String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json");
|
|
|
JSONObject sceneJson = JSONUtil.parseObj(sceneJsonData);
|
|
|
String resolution = "4k";
|
|
|
String sceneForm = sceneJson.getStr("sceneFrom");
|
|
@@ -191,10 +194,6 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
}
|
|
|
|
|
|
int imagesVersion = -1;
|
|
|
- // TODO: 2022/3/29 V4版本目前没有imagesVersion字段,暂时用version字段替代
|
|
|
-// if(getInfoJson.getInt("imagesVersion") != null){
|
|
|
-// imagesVersion = getInfoJson.getInt("imagesVersion");
|
|
|
-// }
|
|
|
Integer version = sceneJson.getInt("version");
|
|
|
if(Objects.nonNull(version)){
|
|
|
imagesVersion = version;
|
|
@@ -223,27 +222,16 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
|
|
|
//上传压缩包
|
|
|
String uploadPath = String.format(this.zipOssFormat, num);
|
|
|
- uploadToOssUtil.uploadBySh(zipPath, uploadPath);
|
|
|
+ fYunFileService.uploadFileByCommand(bucket, zipPath, uploadPath);
|
|
|
|
|
|
//更新进度100
|
|
|
String url = this.publicUrl + uploadPath + "?t=" + Calendar.getInstance().getTimeInMillis();
|
|
|
this.updateProgress(null, num, SceneDownloadProgressStatus.DOWNLOAD_SUCCESS.code(), url);
|
|
|
|
|
|
- // TODO: 2022/5/24 v3 停止后要开启-----------------------start
|
|
|
- //更新用户场景已下载次数
|
|
|
-// platformUserClient.updateDownloadNum(userId, 1);
|
|
|
-//
|
|
|
-// //更新下载log状态为成功
|
|
|
-// sceneUserSceneClient.updateSceneDownloadLog(num, DownloadStatus.SUCCESS.code(), url, null);
|
|
|
- // TODO: 2022/5/24 v3 停止后要开启-----------------------end
|
|
|
|
|
|
}catch (Exception e){
|
|
|
//更新进度为下载失败
|
|
|
this.updateProgress( null, num, SceneDownloadProgressStatus.DOWNLOAD_FAILED.code(), null);
|
|
|
- //更新下载log状态为成功
|
|
|
- // TODO: 2022/5/24 v3 停止后要开启-----------------------start
|
|
|
-// sceneUserSceneClient.updateSceneDownloadLog(num, DownloadStatus.FAILD.code(), null, ExceptionUtil.stacktraceToString(e));
|
|
|
- // TODO: 2022/5/24 v3 停止后要开启-----------------------send
|
|
|
throw e;
|
|
|
}finally {
|
|
|
if(StrUtil.isNotBlank(zipPath)){
|
|
@@ -338,16 +326,16 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
SceneDownloadProgressStatus.DOWNLOAD_COMPRESSING.code(), null);
|
|
|
}
|
|
|
|
|
|
- private Map<String, List<String>> getAllFiles(String num, String v3localPath) throws Exception{
|
|
|
+ private Map<String, List<String>> getAllFiles(String num, String v3localPath, String bucket) throws Exception{
|
|
|
//列出oss所有文件路径
|
|
|
List<String> ossFilePaths = new ArrayList<>();
|
|
|
for (String prefix : prefixArr) {
|
|
|
prefix = String.format(prefix, num);
|
|
|
- List<String> keys = uploadToOssUtil.listKeys(prefix);
|
|
|
+ List<String> keys = fYunFileService.listRemoteFiles(bucket, prefix);
|
|
|
if(CollUtil.isEmpty(keys)){
|
|
|
continue;
|
|
|
}
|
|
|
- if(StorageType.AWS.code().equals(this.uploadType)){
|
|
|
+ if(FYunTypeEnum.AWS.code().equals(this.uploadType)){
|
|
|
keys = keys.stream().filter(key->{
|
|
|
if(key.contains("x-oss-process")){
|
|
|
return false;
|
|
@@ -369,29 +357,6 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- private JSONObject zipGetInfoJson(ZipOutputStream out, String root, String num) throws Exception{
|
|
|
-
|
|
|
- ResultData<SceneInfoDTO> sceneViewInfo = sceneUserSceneClient.getSceneViewInfo(num);
|
|
|
- if(!sceneViewInfo.getSuccess()){
|
|
|
- throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
|
|
|
- }
|
|
|
- SceneInfoDTO data = sceneViewInfo.getData();
|
|
|
- JSONObject getInfoJson = null;
|
|
|
- if(Objects.isNull(data)){
|
|
|
- getInfoJson = new JSONObject();
|
|
|
- }else {
|
|
|
- getInfoJson = JSONUtil.parseObj(data);
|
|
|
- }
|
|
|
-
|
|
|
- getInfoJson.set("sceneScheme", 3);
|
|
|
- getInfoJson.set("needKey", 0);
|
|
|
- getInfoJson.set("sceneKey","");
|
|
|
- //写入getInfo.json
|
|
|
- String getInfoJsonPath = root + String.format(UploadFilePath.DATA_VIEW_PATH, num) + "getInfo.json";
|
|
|
- this.zipBytes(out, getInfoJsonPath, getInfoJson.toString().getBytes());
|
|
|
- return getInfoJson;
|
|
|
- }
|
|
|
-
|
|
|
private void zipSceneJson(ZipOutputStream out, String root, String num, JSONObject sceneJson) throws Exception{
|
|
|
|
|
|
//访问密码置0
|
|
@@ -440,13 +405,13 @@ public class SceneDownloadHandlerServiceImpl {
|
|
|
}
|
|
|
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(StorageType.AWS.code().equals(uploadType)){
|
|
|
+ if(FYunTypeEnum.AWS.code().equals(uploadType)){
|
|
|
par += "&imagesVersion="+ imagesVersion;
|
|
|
}
|
|
|
|
|
|
var url = this.
|
|
|
resourceUrl + key;
|
|
|
- StorageType storageType = StorageType.get(uploadType);
|
|
|
+ FYunTypeEnum storageType = FYunTypeEnum.get(uploadType);
|
|
|
switch (storageType){
|
|
|
case OSS:
|
|
|
url += par;
|