From a86f2b2e14733149d8c7813ce1e049f6b2ca5605 Mon Sep 17 00:00:00 2001 From: xhxu Date: Mon, 10 Jul 2023 20:24:05 +0800 Subject: [PATCH] //.. --- .../controller/VideoCallbackController.java | 77 ++++++------ .../sm/impl/PhotoSpeakVideoServiceImpl.java | 116 ++++++++---------- 2 files changed, 94 insertions(+), 99 deletions(-) diff --git a/suimangCApi/src/main/java/com/iformall/controller/VideoCallbackController.java b/suimangCApi/src/main/java/com/iformall/controller/VideoCallbackController.java index 002473a..8c60ee7 100644 --- a/suimangCApi/src/main/java/com/iformall/controller/VideoCallbackController.java +++ b/suimangCApi/src/main/java/com/iformall/controller/VideoCallbackController.java @@ -62,16 +62,6 @@ public class VideoCallbackController extends BaseController { Long task_id = (Long) paranMap.get("task_id");//任务ID String code = (String) paranMap.get("code");//code String msg = (String) paranMap.get("msg"); - Object data = paranMap.get("data"); - - String jsonString = JSONObject.toJSONString(data); - Map dataMap = JSONObject.parseObject(jsonString,Map.class); - Boolean sr = (Boolean) dataMap.get("sr");//判断 sr=True 就是超分的, False 是没超分的 - String url = (String) dataMap.get("url"); - String save_dir = null; - if (!sr){ - save_dir = (String) dataMap.get("save_dir"); - } if (task_id == null){ return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"任务ID不能为空"); @@ -82,44 +72,57 @@ public class VideoCallbackController extends BaseController { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未找到任务数据"); } - if (Integer.parseInt(code) != 4000){ - String returnMsg; - if (sr){ - photoSpeakVideo.setVideoStatus(EnumVideoStatus.hy_fail.getCode()); - returnMsg = "超分视频生成失败"; - }else { - photoSpeakVideo.setVideoStatus(EnumVideoStatus.fail.getCode()); - returnMsg = "视频生成失败"; + Object data = paranMap.get("data"); + String jsonString = JSONObject.toJSONString(data); + Map dataMap = JSONObject.parseObject(jsonString,Map.class); + Boolean sr = (Boolean) dataMap.get("sr");//判断 sr=True 就是超分的, False 是没超分的 + String url = (String) dataMap.get("url"); + String save_dir = null; + String audio_path = null; + if(sr){ + if(!EnumVideoStatus.hy_ing.getCode().equals(photoSpeakVideo.getVideoStatus())){ + return new ResultData(); } - photoSpeakVideo.setVideoMsg("(MetaService)"+msg); - photoSpeakVideo.setUpdateDate(new Date()); - photoSpeakVideoService.updateById(photoSpeakVideo); - return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(),returnMsg); + }else{ + if(!EnumVideoStatus.ing.getCode().equals(photoSpeakVideo.getVideoStatus())){ + return new ResultData(); + } + save_dir = (String) dataMap.get("save_dir"); + audio_path = (String) dataMap.get("audio_path"); } - if (StringUtils.isEmpty(url)){ return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"视频URL不能为空"); } - if (save_dir != null && !save_dir.equals(photoSpeakVideo.getSaveDir())){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"save_dir参数不一致"); - } + PhotoSpeakVideo speakVideoUpd = new PhotoSpeakVideo(); + speakVideoUpd.setId(photoSpeakVideo.getId()); - if (sr){ - photoSpeakVideo.setVideoStatus(EnumVideoStatus.hy_success.getCode()); - photoSpeakVideo.setVideoPath(url); - }else { - photoSpeakVideo.setVideoStatus(EnumVideoStatus.success.getCode()); - photoSpeakVideo.setVideoPath(url); + if("4000".equals(code)){ + if (sr){ + speakVideoUpd.setVideoStatus(EnumVideoStatus.hy_success.getCode()); + }else { + speakVideoUpd.setVideoStatus(EnumVideoStatus.success.getCode()); + speakVideoUpd.setSaveDir(save_dir); + speakVideoUpd.setAudioPath(audio_path); + } + speakVideoUpd.setVideoPath(url); + speakVideoUpd.setVideoMsg("视频生成成功"); + }else{ + if (sr){ + speakVideoUpd.setVideoStatus(EnumVideoStatus.hy_fail.getCode()); + }else { + speakVideoUpd.setVideoStatus(EnumVideoStatus.fail.getCode()); + } + speakVideoUpd.setVideoMsg("(MetaService)"+msg); } - photoSpeakVideo.setVideoMsg("success"); - photoSpeakVideo.setUpdateDate(new Date()); - photoSpeakVideoService.updateById(photoSpeakVideo); + speakVideoUpd.setUpdateDate(new Date()); + photoSpeakVideoService.updateById(speakVideoUpd); + //TODO 用户相关操作 if (sr){ - photoSpeakVideoService.uploadHyVideo(photoSpeakVideo); + photoSpeakVideoService.uploadHyVideo(speakVideoUpd); }else { - photoSpeakVideoService.uploadVideo(photoSpeakVideo); + photoSpeakVideoService.uploadVideo(speakVideoUpd); } return new ResultData(); diff --git a/suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java b/suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java index 5735fdc..8cdf2c1 100644 --- a/suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java +++ b/suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java @@ -264,8 +264,7 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { @Async @Override public void uploadVideo(PhotoSpeakVideo mouldVideo){ - if(EnumVideoStatus.success.getCode().equals(mouldVideo.getVideoStatus()) - || EnumVideoStatus.upload_fail.getCode().equals(mouldVideo.getVideoStatus())){ + if(EnumVideoStatus.success.getCode().equals(mouldVideo.getVideoStatus())){ String url1 = url + mouldVideo.getVideoPath(); VideUploadResult result = videoFactory.getExcutor(videoType).uploadVideoPath(mouldVideo.getTitle(), url1); if(result.isSuccess()){ @@ -273,40 +272,38 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { videoUpd.setId(mouldVideo.getId()); videoUpd.setVideoId(result.getVideoId()); videoUpd.setVideoStatus(EnumVideoStatus.upload_ing.getCode()); + videoUpd.setUpdateDate(new Date()); this.saveOrUpdate(videoUpd); - AtomicInteger integer = new AtomicInteger(30); - while (true){ + PhotoSpeakVideo videoUrlUpd = new PhotoSpeakVideo(); + videoUrlUpd.setId(mouldVideo.getId()); + for (int i = 0;i <= 30; i++){ try { - String progress = videoFactory.getExcutor(videoType).getVedioUploadProgress(result.getVideoId()); - Thread.sleep(1000); - if (StringUtils.isNotEmpty(progress) && progress.equals("complete")) { - VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(result.getVideoId(),true); - if (videoDetail.isSuccess() - && StringUtils.isNotBlank(videoDetail.getDuration()) - && !"0.0".equals(videoDetail.getDuration())) { - mouldVideo.setCoverImg(videoDetail.getCoverURL()); - mouldVideo.setVideoPlayUrl(videoDetail.getVideoUrl()); - mouldVideo.setVideoTime(videoDetail.getDuration()); - mouldVideo.setVideoSize(videoDetail.getSize()); - mouldVideo.setVideoStatus(EnumVideoStatus.upload_success.getCode()); - this.updateById(mouldVideo); - break; - } - } - - if (integer.getAndDecrement() <= 0){ - mouldVideo.setVideoStatus(EnumVideoStatus.fail.getCode()); - mouldVideo.setVideoMsg("视频上传失败,点击“编辑”重试"); - this.updateById(mouldVideo); - break; - } + Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); - mouldVideo.setVideoStatus(EnumVideoStatus.fail.getCode()); - mouldVideo.setVideoMsg("视频上传失败,点击“编辑”重试"); - this.updateById(mouldVideo); } + String progress = videoFactory.getExcutor(videoType).getVedioUploadProgress(result.getVideoId()); + if (progress.equals("complete")) { + VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(result.getVideoId(),true); + if (videoDetail.isSuccess()){ + videoUrlUpd.setCoverImg(videoDetail.getCoverURL()); + videoUrlUpd.setVideoPlayUrl(videoDetail.getVideoUrl()); + videoUrlUpd.setVideoTime(videoDetail.getDuration()); + videoUrlUpd.setVideoSize(videoDetail.getSize()); + videoUrlUpd.setVideoStatus(EnumVideoStatus.upload_success.getCode()); + videoUrlUpd.setVideoMsg("视频上传成功"); + videoUrlUpd.setUpdateDate(new Date()); + this.updateById(videoUrlUpd); + break; + } + } + } + if(videoUrlUpd.getVideoStatus() == null){ + videoUrlUpd.setVideoStatus(EnumVideoStatus.upload_fail.getCode()); + videoUrlUpd.setVideoMsg("视频上传超时"); + videoUrlUpd.setUpdateDate(new Date()); + this.updateById(videoUrlUpd); } } } @@ -392,8 +389,7 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { @Async @Override public void uploadHyVideo(PhotoSpeakVideo mouldVideo){ - if(EnumVideoStatus.hy_success.getCode().equals(mouldVideo.getVideoStatus()) - || EnumVideoStatus.hy_upload_fail.getCode().equals(mouldVideo.getVideoStatus())){ + if(EnumVideoStatus.hy_success.getCode().equals(mouldVideo.getVideoStatus())){ String url = hy_url + mouldVideo.getVideoPath(); VideUploadResult result = videoFactory.getExcutor(videoType).uploadVideoPath(mouldVideo.getTitle(), url); if(result.isSuccess()){ @@ -401,42 +397,38 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { videoUpd.setId(mouldVideo.getId()); videoUpd.setVideoId(result.getVideoId()); videoUpd.setVideoStatus(EnumVideoStatus.hy_upload_ing.getCode()); + videoUpd.setUpdateDate(new Date()); this.saveOrUpdate(videoUpd); - AtomicInteger integer = new AtomicInteger(30); - while (true){ + PhotoSpeakVideo videoUrlUpd = new PhotoSpeakVideo(); + videoUrlUpd.setId(mouldVideo.getId()); + for (int i = 0;i <= 30; i++){ try { - String progress = videoFactory.getExcutor(videoType).getVedioUploadProgress(result.getVideoId()); - Thread.sleep(1000); - if (progress.equals("complete")) { - VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(result.getVideoId(),true); - if (videoDetail.isSuccess() - && StringUtils.isNotBlank(videoDetail.getDuration()) - && !"0.0".equals(videoDetail.getDuration())) { - mouldVideo.setCoverImg(videoDetail.getCoverURL()); - mouldVideo.setVideoPlayUrl(videoDetail.getVideoUrl()); - mouldVideo.setVideoTime(videoDetail.getDuration()); - mouldVideo.setVideoSize(videoDetail.getSize()); - mouldVideo.setVideoStatus(EnumVideoStatus.hy_upload_success.getCode()); - this.updateById(mouldVideo); - break; - } - } - - if (integer.getAndDecrement() <= 0){ - mouldVideo.setVideoStatus(EnumVideoStatus.hy_fail.getCode()); - mouldVideo.setIsHy(EnumYesOrNo.NO.getCode()); - mouldVideo.setVideoMsg("视频上传失败,点击“编辑”重试"); - this.updateById(mouldVideo); - break; - } + Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); - mouldVideo.setVideoStatus(EnumVideoStatus.hy_fail.getCode()); - mouldVideo.setIsHy(EnumYesOrNo.NO.getCode()); - mouldVideo.setVideoMsg("视频上传失败,点击“编辑”重试"); - this.updateById(mouldVideo); } + String progress = videoFactory.getExcutor(videoType).getVedioUploadProgress(result.getVideoId()); + if (progress.equals("complete")) { + VideUploadResult videoDetail = videoFactory.getExcutor(videoType).getVideoDetailWithCache(result.getVideoId(),true); + if (videoDetail.isSuccess()){ + videoUrlUpd.setCoverImg(videoDetail.getCoverURL()); + videoUrlUpd.setVideoPlayUrl(videoDetail.getVideoUrl()); + videoUrlUpd.setVideoTime(videoDetail.getDuration()); + videoUrlUpd.setVideoSize(videoDetail.getSize()); + videoUrlUpd.setVideoStatus(EnumVideoStatus.hy_upload_success.getCode()); + videoUrlUpd.setVideoMsg("视频上传成功"); + videoUrlUpd.setUpdateDate(new Date()); + this.updateById(videoUrlUpd); + break; + } + } + } + if(videoUrlUpd.getVideoStatus() == null){ + videoUrlUpd.setVideoStatus(EnumVideoStatus.hy_upload_fail.getCode()); + videoUrlUpd.setVideoMsg("视频上传超时"); + videoUrlUpd.setUpdateDate(new Date()); + this.updateById(videoUrlUpd); } } }