|
@@ -7,28 +7,44 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.tzld.piaoquan.longarticle.model.dto.ArticleSortRequest;
|
|
import com.tzld.piaoquan.longarticle.model.dto.ArticleSortRequest;
|
|
|
import com.tzld.piaoquan.longarticle.model.dto.ArticleSortResponse;
|
|
import com.tzld.piaoquan.longarticle.model.dto.ArticleSortResponse;
|
|
|
import com.tzld.piaoquan.longarticle.service.remote.SortService;
|
|
import com.tzld.piaoquan.longarticle.service.remote.SortService;
|
|
|
-import com.tzld.piaoquan.longarticle.utils.HttpClientUtil;
|
|
|
|
|
-import com.tzld.piaoquan.longarticle.utils.HttpPoolClientUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import okhttp3.MediaType;
|
|
|
|
|
+import okhttp3.OkHttpClient;
|
|
|
|
|
+import okhttp3.Request;
|
|
|
|
|
+import okhttp3.RequestBody;
|
|
|
|
|
+import okhttp3.Response;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
public class SortServiceImpl implements SortService {
|
|
public class SortServiceImpl implements SortService {
|
|
|
|
|
|
|
|
- HttpPoolClientUtil HTTP_POOL_CLIENT_UTIL_DEFAULT = HttpClientUtil.create(5000, 200000, 20, 100, 3, 3000);
|
|
|
|
|
|
|
+ private static final MediaType JSON_MEDIA_TYPE = MediaType.parse("application/json; charset=utf-8");
|
|
|
|
|
+
|
|
|
|
|
+ private final OkHttpClient HTTP_CLIENT = new OkHttpClient.Builder()
|
|
|
|
|
+ .connectTimeout(15, TimeUnit.SECONDS)
|
|
|
|
|
+ .readTimeout(200, TimeUnit.SECONDS)
|
|
|
|
|
+ .writeTimeout(200, TimeUnit.SECONDS)
|
|
|
|
|
+ .build();
|
|
|
|
|
|
|
|
public ArticleSortResponse publishArticleSort(ArticleSortRequest request) {
|
|
public ArticleSortResponse publishArticleSort(ArticleSortRequest request) {
|
|
|
ArticleSortResponse response = new ArticleSortResponse();
|
|
ArticleSortResponse response = new ArticleSortResponse();
|
|
|
String apiUrl = "http://101.37.174.139:80/recommend";
|
|
String apiUrl = "http://101.37.174.139:80/recommend";
|
|
|
long startTime = System.currentTimeMillis();
|
|
long startTime = System.currentTimeMillis();
|
|
|
try {
|
|
try {
|
|
|
- String res = HTTP_POOL_CLIENT_UTIL_DEFAULT.post(apiUrl, JSON.toJSONString(request));
|
|
|
|
|
|
|
+ RequestBody body = RequestBody.create(JSON_MEDIA_TYPE, JSON.toJSONString(request));
|
|
|
|
|
+ Request httpRequest = new Request.Builder()
|
|
|
|
|
+ .url(apiUrl)
|
|
|
|
|
+ .post(body)
|
|
|
|
|
+ .build();
|
|
|
|
|
+ Response httpResponse = HTTP_CLIENT.newCall(httpRequest).execute();
|
|
|
|
|
+ String res = httpResponse.body() != null ? httpResponse.body().string() : null;
|
|
|
log.info("publishArticleSort request={} res={}", request, res);
|
|
log.info("publishArticleSort request={} res={}", request, res);
|
|
|
response = JSON.parseObject(res, ArticleSortResponse.class);
|
|
response = JSON.parseObject(res, ArticleSortResponse.class);
|
|
|
if (Objects.nonNull(response) && Objects.nonNull(response.getData())) {
|
|
if (Objects.nonNull(response) && Objects.nonNull(response.getData())) {
|
|
@@ -51,7 +67,12 @@ public class SortServiceImpl implements SortService {
|
|
|
String apiUrl = "http://101.37.174.139:80/deleteGzhWaiting?planId=" + planId
|
|
String apiUrl = "http://101.37.174.139:80/deleteGzhWaiting?planId=" + planId
|
|
|
+ "&publishAccountId=" + publishAccountId;
|
|
+ "&publishAccountId=" + publishAccountId;
|
|
|
try {
|
|
try {
|
|
|
- String res = HTTP_POOL_CLIENT_UTIL_DEFAULT.get(apiUrl);
|
|
|
|
|
|
|
+ Request httpRequest = new Request.Builder()
|
|
|
|
|
+ .url(apiUrl)
|
|
|
|
|
+ .get()
|
|
|
|
|
+ .build();
|
|
|
|
|
+ Response httpResponse = HTTP_CLIENT.newCall(httpRequest).execute();
|
|
|
|
|
+ String res = httpResponse.body() != null ? httpResponse.body().string() : null;
|
|
|
log.info("deleteGzhWaiting planId={} publishAccountId={} res={}", planId, publishAccountId, res);
|
|
log.info("deleteGzhWaiting planId={} publishAccountId={} res={}", planId, publishAccountId, res);
|
|
|
if (StringUtils.isBlank(res)) {
|
|
if (StringUtils.isBlank(res)) {
|
|
|
return false;
|
|
return false;
|
|
@@ -82,7 +103,12 @@ public class SortServiceImpl implements SortService {
|
|
|
long startTime = System.currentTimeMillis();
|
|
long startTime = System.currentTimeMillis();
|
|
|
try {
|
|
try {
|
|
|
apiUrl += "?gzhId=" + ghId + "&appId=" + appId + "&groupNum=8";
|
|
apiUrl += "?gzhId=" + ghId + "&appId=" + appId + "&groupNum=8";
|
|
|
- String res = HTTP_POOL_CLIENT_UTIL_DEFAULT.get(apiUrl);
|
|
|
|
|
|
|
+ Request httpRequest = new Request.Builder()
|
|
|
|
|
+ .url(apiUrl)
|
|
|
|
|
+ .get()
|
|
|
|
|
+ .build();
|
|
|
|
|
+ Response httpResponse = HTTP_CLIENT.newCall(httpRequest).execute();
|
|
|
|
|
+ String res = httpResponse.body() != null ? httpResponse.body().string() : null;
|
|
|
log.info("addBatchGroupGZH ghId={} appId={} res={}", ghId, appId, res);
|
|
log.info("addBatchGroupGZH ghId={} appId={} res={}", ghId, appId, res);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("addBatchGroupGZH error:{}", e.getMessage());
|
|
log.error("addBatchGroupGZH error:{}", e.getMessage());
|