Commit a252c834 by chenweitao

修改热搜多条储存方式

parent 65547f90
...@@ -32,7 +32,7 @@ public class HotSearchListDAO{ ...@@ -32,7 +32,7 @@ public class HotSearchListDAO{
public HotSearchListDAO() { public HotSearchListDAO() {
String time = TimeParse.dateFormartString(new Date(), "yyyy-MM-dd"); String time = TimeParse.dateFormartString(new Date(), "yyyy-MM-dd");
String year = time.substring(0,4); String year = time.substring(0,4);
String month = time.substring(5,7); String month = time.substring(5,7);
String collName = DBConfig.searchCollName + year + "_" + month; String collName = DBConfig.searchCollName + year + "_" + month;
mongoCollection = mongoDatabase.getCollection(collName); mongoCollection = mongoDatabase.getCollection(collName);
...@@ -43,19 +43,21 @@ public class HotSearchListDAO{ ...@@ -43,19 +43,21 @@ public class HotSearchListDAO{
/** /**
* 添加数据入库 * 添加数据入库
* @param list * @param list
*/ */
public void addHotSearchList(List<Document> list){ public void addHotSearchList(List<Document> list){
try { try {
mongoCollection.insertMany(list); for (Document document : list) {
addHotSearch(document);
}
} catch (Exception e) { } catch (Exception e) {
log.error("存储数据时出错,错误为:{}", e); log.error("存储数据时出错,错误为:{}", e);
} }
} }
public void addHotSearch(Document doc){ public void addHotSearch(Document doc){
try { try {
mongoCollection.insertOne(doc); mongoCollection.insertOne(doc);
...@@ -92,5 +94,5 @@ public class HotSearchListDAO{ ...@@ -92,5 +94,5 @@ public class HotSearchListDAO{
mongoCollection.replaceOne(basicDBObject,document); mongoCollection.replaceOne(basicDBObject,document);
} }
} }
} }
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