Commit fa3b5b7e by zhiwei

处理微博推荐位的微博热搜,因为无排名所以不纳入总的排名缓存数据表

parent de934c9d
...@@ -68,59 +68,66 @@ public class HotSearchCacheDAO { ...@@ -68,59 +68,66 @@ public class HotSearchCacheDAO {
String url = document.getString("url")!=null?document.getString("url"):null; String url = document.getString("url")!=null?document.getString("url"):null;
String id = name + "_" + type; String id = name + "_" + type;
Document query = new Document("_id", id); Document query = new Document("_id", id);
Document nowDoc = (Document) collection.find(query).first();
if (Objects.nonNull(nowDoc)) { //判断是否为微博推荐位,推荐位微博无排名,所以不纳入总的缓存表
Integer highestRank = nowDoc.getInteger("highestRank"); if(Objects.nonNull(lastRank) && lastRank >0 ){
Integer highestCount = nowDoc.getInteger("highestCount"); Document nowDoc = (Document) collection.find(query).first();
Integer preRank = nowDoc.getInteger("lastRank"); if (Objects.nonNull(nowDoc)) {
Integer preCount = nowDoc.getInteger("lastCount"); Integer highestRank = nowDoc.getInteger("highestRank");
Integer highestCount = nowDoc.getInteger("highestCount");
//判断最大热度值 Integer preRank = nowDoc.getInteger("lastRank");
if (Objects.nonNull(lastCount) && Objects.nonNull(highestCount) && lastCount > highestCount) { Integer preCount = nowDoc.getInteger("lastCount");
highestCount = lastCount;
} //判断最大热度值
//判断最高排名 if (Objects.nonNull(lastCount) && Objects.nonNull(highestCount) && lastCount > highestCount) {
if (Objects.nonNull(lastRank) && highestRank<0){ highestCount = lastCount;
highestRank = lastRank; }
} //判断最高排名
if (lastRank>0 && highestRank>0 && lastRank < highestRank) { if (Objects.nonNull(lastRank) && highestRank<0){
highestRank = lastRank; highestRank = lastRank;
}
if (lastRank>0 && highestRank>0 && lastRank < highestRank) {
highestRank = lastRank;
}
//计算热搜时长
int duration = nowDoc.getInteger("duration");
int durationNow = getDuration(type, duration);
endTime = getEndTime(type, new Date());
//更新相应信息
nowDoc.put("endTime", endTime);
nowDoc.put("lastRank", lastRank);
nowDoc.put("lastCount", lastCount);
nowDoc.put("highestRank", highestRank);
nowDoc.put("highestCount", highestCount);
nowDoc.put("preRank", preRank);
nowDoc.put("preCount", preCount);
nowDoc.put("duration", durationNow);
collection.replaceOne(query, nowDoc);
} else {
nowDoc = new Document();
int durationNow = getDuration(type, 0);
nowDoc.put("_id", id);
nowDoc.put("url", url);
nowDoc.put("name", name);
nowDoc.put("hot", hot);
nowDoc.put("topicLead", topicLead);
nowDoc.put("type", type);
nowDoc.put("lastRank", lastRank);
nowDoc.put("highestRank", lastRank);
nowDoc.put("lastCount", lastCount);
nowDoc.put("highestCount", lastCount);
nowDoc.put("startTime", startTime);
nowDoc.put("endTime", endTime);
nowDoc.put("duration", durationNow);
nowDoc.put("preRank", null);
nowDoc.put("preCount", null);
collection.insertOne(nowDoc);
} }
//计算热搜时长
int duration = nowDoc.getInteger("duration");
int durationNow = getDuration(type, duration);
endTime = getEndTime(type, new Date());
//更新相应信息
nowDoc.put("endTime", endTime);
nowDoc.put("lastRank", lastRank);
nowDoc.put("lastCount", lastCount);
nowDoc.put("highestRank", highestRank);
nowDoc.put("highestCount", highestCount);
nowDoc.put("preRank", preRank);
nowDoc.put("preCount", preCount);
nowDoc.put("duration", durationNow);
collection.replaceOne(query, nowDoc);
} else {
nowDoc = new Document();
int durationNow = getDuration(type, 0);
nowDoc.put("_id", id);
nowDoc.put("url", url);
nowDoc.put("name", name);
nowDoc.put("hot", hot);
nowDoc.put("topicLead", topicLead);
nowDoc.put("type", type);
nowDoc.put("lastRank", lastRank);
nowDoc.put("highestRank", lastRank);
nowDoc.put("lastCount", lastCount);
nowDoc.put("highestCount", lastCount);
nowDoc.put("startTime", startTime);
nowDoc.put("endTime", endTime);
nowDoc.put("duration", durationNow);
nowDoc.put("preRank", null);
nowDoc.put("preCount", null);
collection.insertOne(nowDoc);
} }
}catch (Exception e){ }catch (Exception e){
log.info("数据存储时出错:{}", e); log.info("数据存储时出错:{}", e);
} }
......
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