|
@@ -7,6 +7,7 @@ import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.backendsys.exception.CustException;
|
|
|
import com.backendsys.modules.ai.media.dao.MediaTtvDao;
|
|
|
+import com.backendsys.modules.ai.media.entity.JobStatusEnums;
|
|
|
import com.backendsys.modules.ai.media.entity.MediaTtv;
|
|
|
import com.backendsys.modules.ai.media.entity.MediaTtvConfig;
|
|
|
import com.backendsys.modules.ai.media.entity.MediaTtvSource;
|
|
@@ -18,12 +19,14 @@ import com.backendsys.modules.sdk.douyincloud.tos.service.DouyinTosService;
|
|
|
import com.backendsys.modules.sdk.tencentcloud.cos.service.TencentCosService;
|
|
|
import com.backendsys.modules.system.service.SysCommonService;
|
|
|
import com.backendsys.modules.upload.entity.SysFileResult;
|
|
|
+import com.backendsys.modules.upload.service.SysFileService;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
@Service
|
|
|
public class MediaTtvServiceImpl implements MediaTtvService {
|
|
@@ -38,6 +41,9 @@ public class MediaTtvServiceImpl implements MediaTtvService {
|
|
|
@Autowired
|
|
|
private DouyinTosService douyinTosService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysFileService sysFileService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private BaiduBceMediaService baiduBceMediaService;
|
|
|
|
|
@@ -73,12 +79,14 @@ public class MediaTtvServiceImpl implements MediaTtvService {
|
|
|
if (detail == null) throw new CustException("任务记录不存在,请重新生成");
|
|
|
|
|
|
// -- 静态赋值 -------------------------------
|
|
|
- String request_params_str = detail.getRequest_params();
|
|
|
- JSONObject request_params = JSONUtil.parseObj(request_params_str);
|
|
|
+ JSONObject request_params_json = JSONUtil.parseObj(detail.getRequest_params());
|
|
|
+ JSONObject response_params_json = JSONUtil.parseObj(detail.getResponse_params());
|
|
|
+ detail.setRequest_params_json(request_params_json);
|
|
|
+ detail.setResponse_params_json(response_params_json);
|
|
|
|
|
|
// source
|
|
|
List<MediaTtvSource> source = new ArrayList<>();
|
|
|
- JSONObject request_params_source = JSONUtil.parseObj(request_params.get("source"));
|
|
|
+ JSONObject request_params_source = JSONUtil.parseObj(request_params_json.get("source"));
|
|
|
JSONArray request_params_source_structs = JSONUtil.parseArray(request_params_source.get("structs"));
|
|
|
for(Object obj : request_params_source_structs) {
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(obj);
|
|
@@ -98,13 +106,12 @@ public class MediaTtvServiceImpl implements MediaTtvService {
|
|
|
|
|
|
// config
|
|
|
MediaTtvConfig config = new MediaTtvConfig();
|
|
|
- JSONObject request_params_config = JSONUtil.parseObj(request_params.get("config"));
|
|
|
+ JSONObject request_params_config = JSONUtil.parseObj(request_params_json.get("config"));
|
|
|
config.setTts_voice_type(Convert.toInt(request_params_config.get("ttsPer")));
|
|
|
config.setResolution(Convert.toIntArray(request_params_config.get("resolution")));
|
|
|
detail.setConfig(config);
|
|
|
// ---------------------------------------
|
|
|
|
|
|
-
|
|
|
// 任务状态 (0任务排队中,1任务完成,3任务执行中)
|
|
|
Integer job_status = detail.getJob_status();
|
|
|
if (job_status != 1) {
|
|
@@ -112,39 +119,30 @@ public class MediaTtvServiceImpl implements MediaTtvService {
|
|
|
// [百度AI] AI成片-查询结果
|
|
|
BaiduBceMediaJobResult response = baiduBceMediaService.queryMediaTtv(mediaTtv.getJob_id());
|
|
|
|
|
|
- // -- 静态赋值 ------------------------
|
|
|
- // progress: 查询进度
|
|
|
- // System.out.println("(queryMediaTtv) user_id: " + detail.getUser_id() + ", job_id: " + mediaTtv.getJob_id() + ", progress: " + response.getProgress());
|
|
|
+ // 查询进度百分比
|
|
|
detail.setJob_progress(response.getProgress());
|
|
|
- // ----------------------------------
|
|
|
|
|
|
+ // 生成成功
|
|
|
if (StrUtil.isNotEmpty(response.getVideo_origin_url())) {
|
|
|
- String video_url = "";
|
|
|
- String object_key = "";
|
|
|
-
|
|
|
- // -- [转存] 将查询结果转存 --------------------------------------
|
|
|
- Integer UPLOAD_TARGET = Convert.toInt(sysCommonService.getCommonByTag("UPLOAD_TARGET"));
|
|
|
- // target: 上传目标 (-1:本地, 1:腾讯云, 2:阿里云, 3.抖音云)
|
|
|
- if (UPLOAD_TARGET == 1) {
|
|
|
- SysFileResult sysFileResult = tencentCosService.uploadFileFromUrlToCOS(response.getVideo_origin_url());
|
|
|
- object_key = sysFileResult.getKey();
|
|
|
- video_url = sysFileResult.getDomain() + "/" + sysFileResult.getKey();
|
|
|
- }
|
|
|
- // 3: 抖音云
|
|
|
- if (UPLOAD_TARGET == 3) {
|
|
|
-
|
|
|
- }
|
|
|
- // ------------------------------------------------------------
|
|
|
+
|
|
|
+ job_status = 1;
|
|
|
+
|
|
|
+ // URL转存文件
|
|
|
+ SysFileResult sysFileResult = sysFileService.urlToUploadFile(response.getVideo_origin_url());
|
|
|
+ String object_key = sysFileResult.getKey();
|
|
|
+ String video_url = sysFileResult.getDomain() + "/" + sysFileResult.getKey();
|
|
|
|
|
|
// [DB] 更新表记录
|
|
|
detail.setVideo_origin_url(response.getVideo_origin_url());
|
|
|
detail.setVideo_url(video_url);
|
|
|
detail.setObject_key(object_key);
|
|
|
- detail.setJob_status(1);
|
|
|
+ detail.setJob_status(job_status);
|
|
|
mediaTtvDao.updateById(detail);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ detail.setJob_status_label(JobStatusEnums.jobStatusToLabel(job_status));
|
|
|
return detail;
|
|
|
|
|
|
}
|