|
@@ -5,19 +5,20 @@ import com.google.common.reflect.TypeToken;
|
|
import com.tzld.piaoquan.recommend.server.util.JSONUtils;
|
|
import com.tzld.piaoquan.recommend.server.util.JSONUtils;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.http.HttpEntity;
|
|
import org.apache.http.HttpEntity;
|
|
-import org.apache.http.NameValuePair;
|
|
|
|
-import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
import org.apache.http.client.methods.HttpPost;
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
import org.apache.http.impl.client.HttpClients;
|
|
import org.apache.http.impl.client.HttpClients;
|
|
-import org.apache.http.message.BasicNameValuePair;
|
|
|
|
import org.apache.http.util.EntityUtils;
|
|
import org.apache.http.util.EntityUtils;
|
|
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.annotation.PostConstruct;
|
|
import javax.annotation.PostConstruct;
|
|
-import java.util.*;
|
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author dyp
|
|
* @author dyp
|
|
@@ -40,6 +41,7 @@ public class ViewedService {
|
|
viewedTypesMap.put(13, Lists.newArrayList(1));
|
|
viewedTypesMap.put(13, Lists.newArrayList(1));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // TODO 如果过滤失败,那么认为所有视频都被过滤掉
|
|
public List<Long> filterViewedVideo(int appType, String mid, String uid, List<Long> videoIds) {
|
|
public List<Long> filterViewedVideo(int appType, String mid, String uid, List<Long> videoIds) {
|
|
List<Integer> viewedTypes = viewedTypesMap.getOrDefault(appType, defaultViewedTypes);
|
|
List<Integer> viewedTypes = viewedTypesMap.getOrDefault(appType, defaultViewedTypes);
|
|
|
|
|
|
@@ -49,24 +51,23 @@ public class ViewedService {
|
|
|
|
|
|
HttpPost post = new HttpPost(videoFilterUrl);
|
|
HttpPost post = new HttpPost(videoFilterUrl);
|
|
post.addHeader("Connection", "close");
|
|
post.addHeader("Connection", "close");
|
|
|
|
+ post.addHeader("content-type", "application/json");
|
|
|
|
|
|
- List<NameValuePair> nvps = new ArrayList<NameValuePair>();
|
|
|
|
- nvps.add(new BasicNameValuePair("appType", String.valueOf(appType)));
|
|
|
|
- nvps.add(new BasicNameValuePair("mid", mid));
|
|
|
|
- nvps.add(new BasicNameValuePair("uid", uid));
|
|
|
|
- nvps.add(new BasicNameValuePair("types", JSONUtils.toJson(viewedTypes)));
|
|
|
|
- nvps.add(new BasicNameValuePair("videoIds", JSONUtils.toJson(videoIds)));
|
|
|
|
-
|
|
|
|
- post.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
|
|
|
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
|
+ param.put("appType", appType);
|
|
|
|
+ param.put("mid", mid);
|
|
|
|
+ param.put("uid", uid);
|
|
|
|
+ param.put("types", viewedTypes);
|
|
|
|
+ param.put("videoIds", videoIds);
|
|
|
|
+ post.setEntity(new StringEntity(JSONUtils.toJson(param)));
|
|
|
|
|
|
|
|
+ log.info("request HttpPost={}", JSONUtils.toJson(post));
|
|
chr = clients.execute(post);
|
|
chr = clients.execute(post);
|
|
if (chr == null
|
|
if (chr == null
|
|
|| chr.getStatusLine() == null
|
|
|| chr.getStatusLine() == null
|
|
|| chr.getStatusLine().getStatusCode() != 200) {
|
|
|| chr.getStatusLine().getStatusCode() != 200) {
|
|
- log.info("request videoFilterUrl exception! videoFilterUrl={},statusCode={}", videoFilterUrl,
|
|
|
|
- chr != null && chr.getStatusLine() != null
|
|
|
|
- ? chr.getStatusLine().getStatusCode()
|
|
|
|
- : -1);
|
|
|
|
|
|
+ log.error("filterViewedVideo failed http status exception! videoFilterUrl={}, CloseableHttpResponse={}",
|
|
|
|
+ videoFilterUrl, chr);
|
|
return Collections.emptyList();
|
|
return Collections.emptyList();
|
|
}
|
|
}
|
|
HttpEntity entity = chr.getEntity();
|
|
HttpEntity entity = chr.getEntity();
|
|
@@ -79,6 +80,8 @@ public class ViewedService {
|
|
Collections.emptyMap());
|
|
Collections.emptyMap());
|
|
if (data.get("code") == null
|
|
if (data.get("code") == null
|
|
|| !data.get("code").equals("0")) {
|
|
|| !data.get("code").equals("0")) {
|
|
|
|
+ log.error("filterViewedVideo failed videoFilterUrl return code exception! data={}",
|
|
|
|
+ JSONUtils.toJson(data));
|
|
return Collections.emptyList();
|
|
return Collections.emptyList();
|
|
}
|
|
}
|
|
return JSONUtils.fromJson(data.get("data"),
|
|
return JSONUtils.fromJson(data.get("data"),
|