Commit d3049158 by 马黎滨

Merge branch 'mlb-template-local' into 'mlbWork'

B站全日榜图片信息添加

See merge request !71
parents da89439e d231d355
...@@ -94,6 +94,11 @@ public class HotSearchList implements Serializable{ ...@@ -94,6 +94,11 @@ public class HotSearchList implements Serializable{
*/ */
private Integer barrage; private Integer barrage;
/**
* 图片地址
*/
private String pictureUrl;
public HotSearchList(){} public HotSearchList(){}
public HotSearchList(String url, String name, Integer count,Boolean hot,Integer rank,String type,String icon,Date date){ public HotSearchList(String url, String name, Integer count,Boolean hot,Integer rank,String type,String icon,Date date){
...@@ -151,7 +156,7 @@ public class HotSearchList implements Serializable{ ...@@ -151,7 +156,7 @@ public class HotSearchList implements Serializable{
this.topicResult = topicResult; this.topicResult = topicResult;
} }
public HotSearchList(String url, String name, String topicLead, Integer count, Boolean hot, Date time, Integer rank, String type, Integer view, Integer barrage) { public HotSearchList(String url, String name, String topicLead, Integer count, Boolean hot, Date time, Integer rank, String type, Integer view, Integer barrage, String pictureUrl) {
this.id = name + "_" + new Date().getTime()+ "_" + type; this.id = name + "_" + new Date().getTime()+ "_" + type;
this.url = url; this.url = url;
this.name = name; this.name = name;
...@@ -164,5 +169,6 @@ public class HotSearchList implements Serializable{ ...@@ -164,5 +169,6 @@ public class HotSearchList implements Serializable{
this.type = type; this.type = type;
this.view = view; this.view = view;
this.barrage = barrage; this.barrage = barrage;
this.pictureUrl =pictureUrl;
} }
} }
...@@ -54,6 +54,7 @@ public class BililiCrawler { ...@@ -54,6 +54,7 @@ public class BililiCrawler {
String topicLead = data.getString("desc"); String topicLead = data.getString("desc");
int count = data.getIntValue("score"); int count = data.getIntValue("score");
String bvid = data.getString("bvid"); String bvid = data.getString("bvid");
String pic = data.getString("pic");
String bUrl = "https://www.bilibili.com/video/"+bvid; String bUrl = "https://www.bilibili.com/video/"+bvid;
Integer view = null; Integer view = null;
Integer barrage = null; Integer barrage = null;
...@@ -62,7 +63,7 @@ public class BililiCrawler { ...@@ -62,7 +63,7 @@ public class BililiCrawler {
view = stat.getIntValue("view"); view = stat.getIntValue("view");
barrage = stat.getIntValue("danmaku"); barrage = stat.getIntValue("danmaku");
} }
HotSearchList hotSearchList = new HotSearchList(bUrl,name,topicLead,count,null,date,rank,HotSearchType.B站排行榜.name(),view,barrage); HotSearchList hotSearchList = new HotSearchList(bUrl,name,topicLead,count,null,date,rank,HotSearchType.B站排行榜.name(),view,barrage,pic);
hotSearchLists.add(hotSearchList); hotSearchLists.add(hotSearchList);
} }
} }
......
...@@ -12,10 +12,7 @@ import lombok.extern.log4j.Log4j2; ...@@ -12,10 +12,7 @@ import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Strings;
import org.bson.Document; import org.bson.Document;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/** /**
* 热搜基础结果表 * 热搜基础结果表
...@@ -25,6 +22,7 @@ public class HotSearchCacheDAO { ...@@ -25,6 +22,7 @@ public class HotSearchCacheDAO {
private static MongoCollection collection = MongoDBTemplate.getCollection(DBConfig.dbName, DBConfig.searchCacheCollName); private static MongoCollection collection = MongoDBTemplate.getCollection(DBConfig.dbName, DBConfig.searchCacheCollName);
private static List<String> picTypes = Arrays.asList("B站排行榜");
/** /**
* 存储数据 * 存储数据
...@@ -59,6 +57,7 @@ public class HotSearchCacheDAO { ...@@ -59,6 +57,7 @@ public class HotSearchCacheDAO {
document.put("topic_lead", hotSearch.getTopicLead()); document.put("topic_lead", hotSearch.getTopicLead());
document.put("view",hotSearch.getView()); document.put("view",hotSearch.getView());
document.put("barrage",hotSearch.getBarrage()); document.put("barrage",hotSearch.getBarrage());
document.put("pictureUrl",hotSearch.getPictureUrl());
} }
addAndUpdateData(document); addAndUpdateData(document);
dataes.add(document); dataes.add(document);
...@@ -86,6 +85,7 @@ public class HotSearchCacheDAO { ...@@ -86,6 +85,7 @@ public class HotSearchCacheDAO {
boolean hot = document.getBoolean("hot")!=null?document.getBoolean("hot"):true; boolean hot = document.getBoolean("hot")!=null?document.getBoolean("hot"):true;
String url = document.getString("url")!=null?document.getString("url"):null; String url = document.getString("url")!=null?document.getString("url"):null;
String topicResult = document.getString("topic_result")!=null?document.getString("topic_result"):null; String topicResult = document.getString("topic_result")!=null?document.getString("topic_result"):null;
String pictureUrl = document.getString("pictureUrl")!=null?document.getString("pictureUrl"):null;
String id = name + "_" + type; String id = name + "_" + type;
boolean recommend = false; boolean recommend = false;
// Integer readCount = document.getInteger("comment_count"); // Integer readCount = document.getInteger("comment_count");
...@@ -147,6 +147,13 @@ public class HotSearchCacheDAO { ...@@ -147,6 +147,13 @@ public class HotSearchCacheDAO {
if(topicResult != null){ if(topicResult != null){
nowDoc.put("topicResult",topicResult); nowDoc.put("topicResult",topicResult);
} }
if(picTypes.contains(type)){
if(Strings.isNotEmpty(pictureUrl)){
if(!nowDoc.containsKey("pictureUrl") || !nowDoc.getString("pictureUrl").equals(pictureUrl)) {
nowDoc.put("pictureUrl", pictureUrl);
}
}
}
collection.replaceOne(query, nowDoc); collection.replaceOne(query, nowDoc);
} else { } else {
nowDoc = new Document(); nowDoc = new Document();
...@@ -175,6 +182,9 @@ public class HotSearchCacheDAO { ...@@ -175,6 +182,9 @@ public class HotSearchCacheDAO {
if(topicResult != null){ if(topicResult != null){
nowDoc.put("topicResult",topicResult); nowDoc.put("topicResult",topicResult);
} }
if(picTypes.contains(type)){
nowDoc.put("pictureUrl",pictureUrl);
}
if("微博热搜".equals(type)){ if("微博热搜".equals(type)){
nowDoc = WeiboHotSearchCrawler.weiboUpdate(nowDoc); nowDoc = WeiboHotSearchCrawler.weiboUpdate(nowDoc);
if(nowDoc.containsKey("topicLead")){ if(nowDoc.containsKey("topicLead")){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment