|
@@ -0,0 +1,64 @@
|
|
|
+package com.tzld.longarticle.recommend.server.remote.pq;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.tzld.longarticle.recommend.server.common.HttpPoolFactory;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.crawler.ArticleRepository;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
+import org.apache.http.StatusLine;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class PQVideoAuditStartProcessService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ArticleRepository articleRepository;
|
|
|
+
|
|
|
+ private final CloseableHttpClient client = HttpPoolFactory.aigcPool();
|
|
|
+ private static final String url = "https://longvideoapi.piaoquantv.com/longvideoapi/openai/audit/startProcess";
|
|
|
+
|
|
|
+ public Long startProcess(Long videoId) {
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("videoId", videoId);
|
|
|
+ try {
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
+ StringEntity stringEntity = new StringEntity(params.toJSONString(), StandardCharsets.UTF_8);
|
|
|
+ httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
|
|
|
+ httpPost.setEntity(stringEntity);
|
|
|
+ CloseableHttpResponse response = client.execute(httpPost);
|
|
|
+ StatusLine statusLine = response.getStatusLine();
|
|
|
+ if (statusLine.getStatusCode() == 200) {
|
|
|
+ HttpEntity responseEntity = response.getEntity();
|
|
|
+ if (Objects.nonNull(responseEntity)) {
|
|
|
+ String responseBody = EntityUtils.toString(responseEntity, "UTF-8");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(responseBody);
|
|
|
+ if (jsonObject.getInteger("code") == 0) {
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ if (data.containsKey("taskId")) {
|
|
|
+ return data.getLong("taskId");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // todo 任务处理失败
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("articleGetProducePlanDetail error", e);
|
|
|
+ }
|
|
|
+ // todo 失败增加重试
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|