|
@@ -2,18 +2,25 @@ package com.tzld.piaoquan.sde.integration;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.tzld.piaoquan.sde.common.enums.ContentTypeEnum;
|
|
import com.tzld.piaoquan.sde.common.enums.ContentTypeEnum;
|
|
|
import com.tzld.piaoquan.sde.common.enums.ExceptionEnum;
|
|
import com.tzld.piaoquan.sde.common.enums.ExceptionEnum;
|
|
|
-import com.tzld.piaoquan.sde.common.enums.deconstruction.DeconstructionTaskStatusEnum;
|
|
|
|
|
|
|
+import com.tzld.piaoquan.sde.common.enums.IsDeleteEnum;
|
|
|
import com.tzld.piaoquan.sde.common.enums.deconstruction.SenceTypeEnum;
|
|
import com.tzld.piaoquan.sde.common.enums.deconstruction.SenceTypeEnum;
|
|
|
import com.tzld.piaoquan.sde.common.exception.BizException;
|
|
import com.tzld.piaoquan.sde.common.exception.BizException;
|
|
|
import com.tzld.piaoquan.sde.common.exception.HttpServiceException;
|
|
import com.tzld.piaoquan.sde.common.exception.HttpServiceException;
|
|
|
|
|
+//import com.tzld.piaoquan.sde.mapper.SdContentMapper;
|
|
|
|
|
+//import com.tzld.piaoquan.sde.mapper.SdExecutionTaskContentRelMapper;
|
|
|
|
|
+import com.tzld.piaoquan.sde.mapper.SdExecutionTaskContentMapper;
|
|
|
import com.tzld.piaoquan.sde.model.dto.deconstruction.ApiResponse;
|
|
import com.tzld.piaoquan.sde.model.dto.deconstruction.ApiResponse;
|
|
|
import com.tzld.piaoquan.sde.model.dto.deconstruction.QueryResponseDataDTO;
|
|
import com.tzld.piaoquan.sde.model.dto.deconstruction.QueryResponseDataDTO;
|
|
|
import com.tzld.piaoquan.sde.model.dto.deconstruction.SubmitResponseDataDTO;
|
|
import com.tzld.piaoquan.sde.model.dto.deconstruction.SubmitResponseDataDTO;
|
|
|
import com.tzld.piaoquan.sde.model.dto.longvideoapi.JsonView;
|
|
import com.tzld.piaoquan.sde.model.dto.longvideoapi.JsonView;
|
|
|
import com.tzld.piaoquan.sde.model.dto.longvideoapi.WxVideoV2VO;
|
|
import com.tzld.piaoquan.sde.model.dto.longvideoapi.WxVideoV2VO;
|
|
|
|
|
+//import com.tzld.piaoquan.sde.model.entity.SdContent;
|
|
|
import com.tzld.piaoquan.sde.model.entity.SdExecutionTask;
|
|
import com.tzld.piaoquan.sde.model.entity.SdExecutionTask;
|
|
|
|
|
+import com.tzld.piaoquan.sde.model.entity.SdExecutionTaskContent;
|
|
|
|
|
+import com.tzld.piaoquan.sde.model.request.ClusterTaskSubmitParam;
|
|
|
import com.tzld.piaoquan.sde.model.request.DeconstructionTaskSubmitParam;
|
|
import com.tzld.piaoquan.sde.model.request.DeconstructionTaskSubmitParam;
|
|
|
import com.tzld.piaoquan.sde.model.request.VideoInfoGetParam;
|
|
import com.tzld.piaoquan.sde.model.request.VideoInfoGetParam;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -21,9 +28,8 @@ import okhttp3.*;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import javax.management.Query;
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
@@ -34,15 +40,21 @@ import java.util.concurrent.TimeUnit;
|
|
|
*/
|
|
*/
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
-public class ContentDeconstructionClient {
|
|
|
|
|
|
|
+public class ContentDeconstructionClusterClient {
|
|
|
|
|
|
|
|
private static final MediaType MEDIA_TYPE = MediaType.parse("application/json, charset=utf-8");
|
|
private static final MediaType MEDIA_TYPE = MediaType.parse("application/json, charset=utf-8");
|
|
|
|
|
+ private final SdExecutionTaskContentMapper sdExecutionTaskContentMapper;
|
|
|
|
|
+// private final SdContentMapper sdContentMapper;
|
|
|
|
|
+// private final SdExecutionTaskContentRelMapper sdExecutionTaskContentRelMapper;
|
|
|
|
|
|
|
|
@Value("${deconstruction.task.submit.url:http://supply-content-deconstruction-api.piaoquantv.com/api/v1/content/tasks/decode}")
|
|
@Value("${deconstruction.task.submit.url:http://supply-content-deconstruction-api.piaoquantv.com/api/v1/content/tasks/decode}")
|
|
|
private String deconstructionTaskSubmitUrl;
|
|
private String deconstructionTaskSubmitUrl;
|
|
|
|
|
|
|
|
@Value("${deconstruction.task.query.url:http://supply-content-deconstruction-api.piaoquantv.com/api/v1/content/tasks/%s}")
|
|
@Value("${deconstruction.task.query.url:http://supply-content-deconstruction-api.piaoquantv.com/api/v1/content/tasks/%s}")
|
|
|
- private String deconstructionTaskQueryUrl;
|
|
|
|
|
|
|
+ private String taskQueryUrl;
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${cluster.task.submit.url:http://supply-content-deconstruction-api.piaoquantv.com/api/v1/content/tasks/pattern}")
|
|
|
|
|
+ private String clusterTaskSubmitUrl;
|
|
|
|
|
|
|
|
@Value("${longvideoapi.videoinfo.get.url:http://longvideoapi-internal.piaoquantv.com/longvideoapi/openapi/video/getVideoInfo}")
|
|
@Value("${longvideoapi.videoinfo.get.url:http://longvideoapi-internal.piaoquantv.com/longvideoapi/openapi/video/getVideoInfo}")
|
|
|
private String longVideoApiVideoInfoGetUrl;
|
|
private String longVideoApiVideoInfoGetUrl;
|
|
@@ -50,6 +62,10 @@ public class ContentDeconstructionClient {
|
|
|
private static final OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(10, TimeUnit.SECONDS)
|
|
private static final OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(10, TimeUnit.SECONDS)
|
|
|
.readTimeout(10, TimeUnit.SECONDS).writeTimeout(10, TimeUnit.SECONDS).build();
|
|
.readTimeout(10, TimeUnit.SECONDS).writeTimeout(10, TimeUnit.SECONDS).build();
|
|
|
|
|
|
|
|
|
|
+ public ContentDeconstructionClusterClient(SdExecutionTaskContentMapper sdExecutionTaskContentMapper) {
|
|
|
|
|
+ this.sdExecutionTaskContentMapper = sdExecutionTaskContentMapper;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 提交解构任务
|
|
* 提交解构任务
|
|
|
*
|
|
*
|
|
@@ -57,15 +73,24 @@ public class ContentDeconstructionClient {
|
|
|
* @return 解构任务ID
|
|
* @return 解构任务ID
|
|
|
*/
|
|
*/
|
|
|
public String submitDeconstructionTask(SdExecutionTask sdExecutionTask) {
|
|
public String submitDeconstructionTask(SdExecutionTask sdExecutionTask) {
|
|
|
- if (Objects.isNull(sdExecutionTask) || Objects.isNull(sdExecutionTask.getContentType())
|
|
|
|
|
- || Objects.isNull(sdExecutionTask.getContentId())) {
|
|
|
|
|
|
|
+ if (Objects.isNull(sdExecutionTask) || Objects.isNull(sdExecutionTask.getId())
|
|
|
|
|
+ || Objects.isNull(sdExecutionTask.getContentType())) {
|
|
|
throw new IllegalArgumentException("sdExecutionTask is null");
|
|
throw new IllegalArgumentException("sdExecutionTask is null");
|
|
|
}
|
|
}
|
|
|
DeconstructionTaskSubmitParam param = new DeconstructionTaskSubmitParam();
|
|
DeconstructionTaskSubmitParam param = new DeconstructionTaskSubmitParam();
|
|
|
param.setScene(SenceTypeEnum.TOPIC_SELECTION.getValue());
|
|
param.setScene(SenceTypeEnum.TOPIC_SELECTION.getValue());
|
|
|
param.setContent_type(sdExecutionTask.getContentType());
|
|
param.setContent_type(sdExecutionTask.getContentType());
|
|
|
DeconstructionTaskSubmitParam.Content content = new DeconstructionTaskSubmitParam.Content();
|
|
DeconstructionTaskSubmitParam.Content content = new DeconstructionTaskSubmitParam.Content();
|
|
|
- String contentId = sdExecutionTask.getContentId();
|
|
|
|
|
|
|
+ Long executionTaskId = sdExecutionTask.getId();
|
|
|
|
|
+ LambdaQueryWrapper<SdExecutionTaskContent> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(SdExecutionTaskContent::getExecutionTaskId, executionTaskId)
|
|
|
|
|
+ .eq(SdExecutionTaskContent::getIsDeleted, IsDeleteEnum.NORMAL.getValue());
|
|
|
|
|
+ List<SdExecutionTaskContent> contentList = sdExecutionTaskContentMapper.selectList(wrapper);
|
|
|
|
|
+ if (contentList == null || contentList.isEmpty()) {
|
|
|
|
|
+ throw new BizException(ExceptionEnum.DATA_NOT_EXIST, "任务内容不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+// String contentId = sdExecutionTask.getContentId();
|
|
|
|
|
+ String contentId = contentList.get(0).getContentId();
|
|
|
content.setChannel_content_id(contentId);
|
|
content.setChannel_content_id(contentId);
|
|
|
if (Objects.equals(sdExecutionTask.getContentType(), ContentTypeEnum.VIDEO.getValue())) {
|
|
if (Objects.equals(sdExecutionTask.getContentType(), ContentTypeEnum.VIDEO.getValue())) {
|
|
|
Long videoId = Long.parseLong(contentId);
|
|
Long videoId = Long.parseLong(contentId);
|
|
@@ -155,8 +180,8 @@ public class ContentDeconstructionClient {
|
|
|
* @param jobId 解构任务ID
|
|
* @param jobId 解构任务ID
|
|
|
* @return 解构结果
|
|
* @return 解构结果
|
|
|
*/
|
|
*/
|
|
|
- public QueryResponseDataDTO getDeconstructionTaskResult(String jobId) {
|
|
|
|
|
- String url = String.format(deconstructionTaskQueryUrl, jobId);
|
|
|
|
|
|
|
+ public QueryResponseDataDTO getTaskResult(String jobId) {
|
|
|
|
|
+ String url = String.format(taskQueryUrl, jobId);
|
|
|
Request request = new Request.Builder()
|
|
Request request = new Request.Builder()
|
|
|
.url(url)
|
|
.url(url)
|
|
|
.get()
|
|
.get()
|
|
@@ -179,4 +204,80 @@ public class ContentDeconstructionClient {
|
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 提交聚类任务
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param sdExecutionTask
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public String submitClusterTask(SdExecutionTask sdExecutionTask) {
|
|
|
|
|
+ if (Objects.isNull(sdExecutionTask) || Objects.isNull(sdExecutionTask.getContentType())) {
|
|
|
|
|
+ throw new IllegalArgumentException("sdExecutionTask is null");
|
|
|
|
|
+ }
|
|
|
|
|
+ ClusterTaskSubmitParam param = new ClusterTaskSubmitParam();
|
|
|
|
|
+ param.setScene(SenceTypeEnum.TOPIC_SELECTION.getValue());
|
|
|
|
|
+ param.setContent_type(sdExecutionTask.getContentType());
|
|
|
|
|
+ DeconstructionTaskSubmitParam.Content content = new DeconstructionTaskSubmitParam.Content();
|
|
|
|
|
+ Long executionTaskId = sdExecutionTask.getId();
|
|
|
|
|
+ LambdaQueryWrapper<SdExecutionTaskContent> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(SdExecutionTaskContent::getExecutionTaskId, executionTaskId)
|
|
|
|
|
+ .eq(SdExecutionTaskContent::getIsDeleted, IsDeleteEnum.NORMAL.getValue());
|
|
|
|
|
+ List<SdExecutionTaskContent> contentList = sdExecutionTaskContentMapper.selectList(wrapper);
|
|
|
|
|
+ if (contentList == null || contentList.isEmpty()) {
|
|
|
|
|
+ throw new BizException(ExceptionEnum.DATA_NOT_EXIST, "任务内容不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+// String contentId = sdExecutionTask.getContentId();
|
|
|
|
|
+ String contentId = contentList.get(0).getContentId();
|
|
|
|
|
+ content.setChannel_content_id(contentId);
|
|
|
|
|
+ if (Objects.equals(sdExecutionTask.getContentType(), ContentTypeEnum.VIDEO.getValue())) {
|
|
|
|
|
+ Long videoId = Long.parseLong(contentId);
|
|
|
|
|
+ //获取视频信息
|
|
|
|
|
+ WxVideoV2VO wxVideoV2VO = getVideoInfo(videoId);
|
|
|
|
|
+ if (Objects.isNull(wxVideoV2VO)) {
|
|
|
|
|
+ throw new BizException(ExceptionEnum.DATA_NOT_EXIST, "videoInfo get error videoId:" + videoId);
|
|
|
|
|
+ }
|
|
|
|
|
+ String videoPath = wxVideoV2VO.getVideoPath();
|
|
|
|
|
+ if (Objects.isNull(videoPath) || videoPath.endsWith(".m3u8")) {
|
|
|
|
|
+ throw new BizException(ExceptionEnum.DATA_ERROR, "视频格式不支持解构 videoId:" + videoId + ",videoPath:" + videoPath);
|
|
|
|
|
+ }
|
|
|
|
|
+ content.setTitle(wxVideoV2VO.getTitle());
|
|
|
|
|
+ content.setVideo_url(videoPath);
|
|
|
|
|
+ content.setChannel_account_id(wxVideoV2VO.getUid().toString());
|
|
|
|
|
+ if (Objects.nonNull(wxVideoV2VO.getUser())) {
|
|
|
|
|
+ content.setChannel_account_name(wxVideoV2VO.getUser().getNickName());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+// param.setContents(content);
|
|
|
|
|
+ //提交任务
|
|
|
|
|
+ return submitClusterTask(param);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private String submitClusterTask(ClusterTaskSubmitParam param) {
|
|
|
|
|
+ RequestBody body = RequestBody.create(MEDIA_TYPE, JSON.toJSONString(param));
|
|
|
|
|
+ Request request = new Request.Builder()
|
|
|
|
|
+ .url(deconstructionTaskSubmitUrl)
|
|
|
|
|
+ .post(body)
|
|
|
|
|
+ .addHeader("Content-Type", "application/json")
|
|
|
|
|
+ .addHeader("Accept", "application/json")
|
|
|
|
|
+ .build();
|
|
|
|
|
+ log.info("submitDeconstructionTask deconstructionTaskSubmitUrl= {} param = {}", deconstructionTaskSubmitUrl, JSON.toJSONString(param));
|
|
|
|
|
+ try (Response response = client.newCall(request).execute()) {
|
|
|
|
|
+ if (!response.isSuccessful()) {
|
|
|
|
|
+ throw new HttpServiceException(ExceptionEnum.HTTP_REQUEST_ERROR.getCode(), "code: " + response.code() + ", msg: " + response.message());
|
|
|
|
|
+ }
|
|
|
|
|
+ String respBody = response.body().string();
|
|
|
|
|
+ log.info("submitDeconstructionTask respBody = {}", respBody);
|
|
|
|
|
+ // 5. 反序列化返回值
|
|
|
|
|
+ ApiResponse<SubmitResponseDataDTO> apiResponse = JSON.parseObject(respBody, new TypeReference<ApiResponse<SubmitResponseDataDTO>>() {
|
|
|
|
|
+ });
|
|
|
|
|
+ if (apiResponse.getCode() != 0) {
|
|
|
|
|
+ throw new BizException(ExceptionEnum.API_REQUEST_ERROR.getCode(), JSON.toJSONString(apiResponse));
|
|
|
|
|
+ }
|
|
|
|
|
+ return apiResponse.getData().getTaskId();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|