.
This commit is contained in:
@@ -2,38 +2,25 @@ package com.lxyer.bbs.base;
|
||||
|
||||
import com.lxyer.bbs.base.entity.Count;
|
||||
import com.lxyer.bbs.base.entity.VisLog;
|
||||
import com.lxyer.bbs.base.kit.LxyKit;
|
||||
import com.lxyer.bbs.base.user.UserInfo;
|
||||
import com.lxyer.bbs.base.user.UserRecord;
|
||||
import com.lxyer.bbs.base.user.UserService;
|
||||
import com.lxyer.bbs.content.Content;
|
||||
import com.lxyer.bbs.content.ContentInfo;
|
||||
import com.lxyer.bbs.content.ContentService;
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.client.FindIterable;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestService;
|
||||
import org.redkale.source.ColumnValue;
|
||||
import org.redkale.source.FilterExpress;
|
||||
import org.redkale.source.FilterNode;
|
||||
import org.redkale.source.Flipper;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.Comment;
|
||||
import org.redkale.util.Sheet;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static com.mongodb.client.model.Filters.eq;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/6/20 22:54.
|
||||
*/
|
||||
@@ -45,28 +32,12 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Resource(name = "property.mongo.host")
|
||||
private String mongoHost;
|
||||
@Resource(name = "property.mongo.database")
|
||||
private String mongoDatabase;
|
||||
|
||||
protected static LinkedBlockingQueue queue = new LinkedBlockingQueue();
|
||||
|
||||
private static MongoClient mongoClient;
|
||||
private static MongoDatabase database;
|
||||
private static MongoCollection<Document> visLog;
|
||||
|
||||
public TaskQueue() {
|
||||
new Thread(this).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(AnyValue config) {
|
||||
mongoClient = new MongoClient(mongoHost, 27017);
|
||||
database = mongoClient.getDatabase(winos ? mongoDatabase + "_dev": mongoDatabase);
|
||||
visLog = database.getCollection("vis_log");
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
public T take() throws InterruptedException {
|
||||
return (T) queue.take();
|
||||
@@ -88,7 +59,7 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
if (task instanceof VisLog) {
|
||||
System.out.println(task);
|
||||
/* todo: 需要记录 访问日志,此处添加记录日志逻辑
|
||||
ArangoKit.save(task).thenAcceptAsync((_task) -> {
|
||||
ArangoService.save(task).thenAcceptAsync((_task) -> {
|
||||
VisLog visLog = (VisLog) _task;
|
||||
//[访问量]
|
||||
String uri = visLog.getUri();
|
||||
@@ -113,8 +84,7 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
" collect WITH COUNT INTO total\n" +
|
||||
" return total", visLog.getUri(), visLog.getIp(), visLog.getUserid());
|
||||
|
||||
long total = ArangoKit.findInt(aql);
|
||||
|
||||
long total = 2;//ArangoService.findInt(aql);
|
||||
|
||||
if (total <= 1) {
|
||||
String uri = visLog.getUri();
|
||||
@@ -135,7 +105,9 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
Map para = new HashMap();
|
||||
para.put("time", cal.getTimeInMillis());
|
||||
//查询一周某热帖记录
|
||||
List<Count> hotArticle = ArangoKit.find(
|
||||
List<Count> hotArticle = new ArrayList<>();
|
||||
/* TODO: 依赖日志记录,需记录日志后可使用
|
||||
List<Count> hotArticle = ArangoService.find(
|
||||
"for d in vis_log_dev\n" +
|
||||
" filter d.uri =~ '^/jie/detail/[0-9]+$' and d.userid != 100001 and d.time > @time\n" +
|
||||
" COLLECT uri=d.uri WITH COUNT INTO total\n" +
|
||||
@@ -143,7 +115,7 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
" limit 10\n" +
|
||||
" return {name: uri,total:total}",
|
||||
Utility.ofMap("time", cal.getTimeInMillis()),
|
||||
Count.class);
|
||||
Count.class);*/
|
||||
|
||||
Function<List<Count>, List<Integer>> deal = (counts) -> {
|
||||
List<Integer> _ids = new ArrayList<>();
|
||||
@@ -180,7 +152,7 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
*/
|
||||
@RestMapping(ignore = true, comment = "帖子访客记录")
|
||||
public Sheet<Map> readRecordAsync(Flipper flipper ,int contentid){
|
||||
Bson filter = eq("uri", "/jie/detail/"+ contentid);
|
||||
/*Bson filter = eq("uri", "/jie/detail/"+ contentid);
|
||||
|
||||
FindIterable<Document> documents = visLog.find(filter).limit(flipper.getLimit()).skip(flipper.getOffset());
|
||||
long total = visLog.countDocuments(filter);
|
||||
@@ -209,6 +181,7 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
sheet.setTotal(total);
|
||||
sheet.setRows(rows);
|
||||
|
||||
return sheet;
|
||||
return sheet;*/
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user