|
@@ -0,0 +1,95 @@
|
|
|
+package com.tzld.longarticle.recommend.server.remote.aigc;
|
|
|
+
|
|
|
+import cn.hutool.core.io.resource.ResourceUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.tzld.longarticle.recommend.server.common.HttpPoolFactory;
|
|
|
+import com.tzld.longarticle.recommend.server.model.vo.aigc.CommonListDataVO;
|
|
|
+import com.tzld.longarticle.recommend.server.model.vo.aigc.ProduceContentListItemVO;
|
|
|
+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.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class AIGCProduceContentListService {
|
|
|
+
|
|
|
+ private final CloseableHttpClient client = HttpPoolFactory.aigcPool();
|
|
|
+
|
|
|
+ public CommonListDataVO<ProduceContentListItemVO> list(List<String> planIdList, int pageNum, int pageSize, List<Integer> produceStatus) {
|
|
|
+ CommonListDataVO<ProduceContentListItemVO> result = new CommonListDataVO<ProduceContentListItemVO>();
|
|
|
+ result.setData(new ArrayList<>());
|
|
|
+ result.setTotalCount(0);
|
|
|
+ if (planIdList.isEmpty()) {
|
|
|
+ log.info("getProduceContentListByPlanIdListRaw: planIdList empty");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ String templateFile = ResourceUtil.readUtf8Str("file/长文_生成结果库_根据计划id获取内容.json");
|
|
|
+ // 读取模板文件内容
|
|
|
+ JSONObject template = JSONObject.parseObject(templateFile);
|
|
|
+ String apiUrl = template.getString("api_url");
|
|
|
+ JSONObject data = template.getJSONObject("data");
|
|
|
+
|
|
|
+ data.getJSONObject("params").getJSONArray("filterItems").getJSONObject(0)
|
|
|
+ .put("selectValues", produceStatus);
|
|
|
+ data.getJSONObject("params").getJSONArray("filterItems").getJSONObject(1)
|
|
|
+ .put("selectValues", planIdList);
|
|
|
+ data.getJSONObject("params").put("pageNum", pageNum);
|
|
|
+ data.getJSONObject("params").put("pageSize", pageSize);
|
|
|
+
|
|
|
+ try {
|
|
|
+ HttpPost httpPost = new HttpPost(apiUrl);
|
|
|
+ StringEntity stringEntity = new StringEntity(data.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 dataObj = jsonObject.getJSONObject("data");
|
|
|
+ int totalCnt = dataObj.getInteger("totalCount");
|
|
|
+ JSONArray dataArray = dataObj.getJSONArray("data");
|
|
|
+ List<ProduceContentListItemVO> contentList = dataArray.toJavaList(ProduceContentListItemVO.class);
|
|
|
+ result.setData(contentList);
|
|
|
+ result.setTotalCount(totalCnt);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("articleGetProducePlanDetail error", e);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject getBaseInfo() {
|
|
|
+ JSONObject baseInfo = new JSONObject();
|
|
|
+ baseInfo.put("token", "79dcb40af1de43b1bd9fe3a731dbaa15");
|
|
|
+ baseInfo.put("appType", 9);
|
|
|
+ baseInfo.put("platform", "pc");
|
|
|
+ baseInfo.put("appVersionCode", 1000);
|
|
|
+ baseInfo.put("clientTimestamp", 1);
|
|
|
+ baseInfo.put("fid", 1);
|
|
|
+ baseInfo.put("loginUid", 1);
|
|
|
+ baseInfo.put("pageSource", 1);
|
|
|
+ baseInfo.put("requestId", 1);
|
|
|
+ baseInfo.put("rid", 1);
|
|
|
+ baseInfo.put("uid", 1);
|
|
|
+ return baseInfo;
|
|
|
+ }
|
|
|
+}
|