.
This commit is contained in:
@@ -17,7 +17,7 @@ import java.util.function.Function;
|
||||
/**
|
||||
* @author: liangxianyou at 2018/11/18 9:02.
|
||||
*/
|
||||
@RestService(automapping = false, comment = "Arango服务")
|
||||
@RestService(automapping = true, comment = "Arango服务")
|
||||
public class ArangoService extends BaseService {
|
||||
|
||||
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||
@@ -43,7 +43,6 @@ public class ArangoService extends BaseService {
|
||||
protected static ArangoDatabase dbDev;
|
||||
protected static ArangoCollection colVisLog;
|
||||
|
||||
/* todo:启用本service 打开注释
|
||||
@Override
|
||||
public void init(AnyValue config) {
|
||||
System.out.println("isDev :" + isDev);
|
||||
@@ -58,7 +57,7 @@ public class ArangoService extends BaseService {
|
||||
if (!colVisLog.exists()) {
|
||||
colVisLog.create();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@RestMapping(auth = false)
|
||||
public List<Map> hi() {
|
||||
@@ -77,7 +76,7 @@ public class ArangoService extends BaseService {
|
||||
});
|
||||
}
|
||||
|
||||
/*public static long findInt(String aql) {
|
||||
public static long findInt(String aql) {
|
||||
return dbDev.query(aql, long.class).first();
|
||||
}
|
||||
public static long findInt(String aql, Map para) {
|
||||
@@ -91,6 +90,6 @@ public class ArangoService extends BaseService {
|
||||
public static <T> List<T> find(String aql, Map para, Class<T> clazz) {
|
||||
|
||||
return dbDev.query(aql, para, clazz).asListRemaining();
|
||||
}*/
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.lxyer.bbs.base;
|
||||
|
||||
import com.arangodb.Predicate;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.source.CacheSource;
|
||||
@@ -7,6 +8,9 @@ import org.redkale.source.DataSource;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/10/3 13:50.
|
||||
@@ -34,6 +38,20 @@ public class BaseService implements Service {
|
||||
|
||||
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||
|
||||
public static Predicate isEmpty = (x) -> {
|
||||
if (x == null)
|
||||
return true;
|
||||
if (x instanceof List)
|
||||
return ((List) x).isEmpty();
|
||||
if (x instanceof String)
|
||||
return ((String) x).isEmpty();
|
||||
if (x instanceof Map)
|
||||
return ((Map) x).isEmpty();
|
||||
if (x instanceof Collection)
|
||||
return ((Collection) x).isEmpty();
|
||||
return false;
|
||||
};
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
public DataSource getSource() {
|
||||
return source;
|
||||
|
@@ -1,39 +0,0 @@
|
||||
package com.lxyer.bbs.base;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.bson.Document;
|
||||
import org.redkale.net.http.RestService;
|
||||
import org.redkale.util.AnyValue;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestService(comment = "Mongo服务")
|
||||
public class MongoService extends BaseService {
|
||||
|
||||
@Resource(name = "property.mongo.host")
|
||||
private String mongoHost;
|
||||
@Resource(name = "property.mongo.database")
|
||||
private String databaseName;
|
||||
@Resource(name = "property.mongo.port")
|
||||
private int port;
|
||||
|
||||
//日志存放doc名称
|
||||
private static final String VIS_LOG = "vis_log";
|
||||
|
||||
private static MongoClient mongoClient;
|
||||
private static MongoDatabase database;
|
||||
private static MongoCollection<Document> visLog;
|
||||
|
||||
/* todo:启用本service 打开注释
|
||||
@Override
|
||||
public void init(AnyValue config) {
|
||||
mongoClient = new MongoClient(mongoHost, port);
|
||||
database = mongoClient.getDatabase(isDev ? databaseName + "_dev": databaseName);
|
||||
visLog = database.getCollection(VIS_LOG);
|
||||
}*/
|
||||
|
||||
//todo: 编写mongo操作逻辑 待完成
|
||||
|
||||
}
|
@@ -15,6 +15,7 @@ import org.redkale.source.FilterNode;
|
||||
import org.redkale.source.Flipper;
|
||||
import org.redkale.util.Comment;
|
||||
import org.redkale.util.Sheet;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
@@ -57,8 +58,7 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
|
||||
//记录访问日志,如果是访问的文章详情:对文章访问数量更新
|
||||
if (task instanceof VisLog) {
|
||||
System.out.println(task);
|
||||
/* todo: 需要记录 访问日志,此处添加记录日志逻辑
|
||||
//System.out.println(task);
|
||||
ArangoService.save(task).thenAcceptAsync((_task) -> {
|
||||
VisLog visLog = (VisLog) _task;
|
||||
//[访问量]
|
||||
@@ -67,7 +67,6 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
updateViewNum(visLog);
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
@@ -84,7 +83,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 = 2;//ArangoService.findInt(aql);
|
||||
long total = ArangoService.findInt(aql);
|
||||
|
||||
if (total <= 1) {
|
||||
String uri = visLog.getUri();
|
||||
@@ -97,16 +96,14 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
public Sheet<ContentInfo> hotView(String sessionid){
|
||||
int limit = 8;
|
||||
String cacheKey = "hotView";
|
||||
Object ids = null;//cacheSource.get(cacheKey);
|
||||
if (ids == null){
|
||||
Object ids = cacheSource.get(cacheKey);
|
||||
if (isEmpty.test(ids)){
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.DAY_OF_MONTH, -7);
|
||||
|
||||
Map para = new HashMap();
|
||||
para.put("time", cal.getTimeInMillis());
|
||||
//查询一周某热帖记录
|
||||
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" +
|
||||
@@ -115,7 +112,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<>();
|
||||
|
@@ -62,7 +62,7 @@ public class ContentServlet extends BaseServlet {
|
||||
/*Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
|
||||
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", sessionid);*/
|
||||
|
||||
Sheet<ContentInfo> hotView = Sheet.empty();//logQueue.hotView(sessionid); TODO: 依赖日志记录,需记录日志后可使用
|
||||
Sheet<ContentInfo> hotView = logQueue.hotView(sessionid);
|
||||
|
||||
Kv kv = Kv.by("bean", content).set("comments", comments).set("hotView", hotView)/*.set("hotReply", hotReply)*/;
|
||||
response.finish(HttpScope.refer("/jie/detail.html").attr(kv));
|
||||
@@ -87,7 +87,7 @@ public class ContentServlet extends BaseServlet {
|
||||
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(request, setPrivate(request, filterNode)));
|
||||
|
||||
//热帖
|
||||
Sheet<ContentInfo> hotView = Sheet.empty();//logQueue.hotView(sessionid); TODO: 依赖日志记录,需记录日志后可使用
|
||||
Sheet<ContentInfo> hotView = logQueue.hotView(sessionid);
|
||||
|
||||
Kv kv = Kv.by("contents", contents).set("hotView", hotView)
|
||||
.set("solved", solved).set("wonderful", wonderful)
|
||||
|
@@ -42,7 +42,7 @@ public class IndexServlet extends BaseServlet {
|
||||
/*Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
|
||||
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", sessionid);*/
|
||||
|
||||
Sheet<ContentInfo> hotView = Sheet.empty();//logQueue.hotView(sessionid); TODO: 依赖日志记录,需记录日志后可使用
|
||||
Sheet<ContentInfo> hotView = logQueue.hotView(sessionid);
|
||||
|
||||
//最新加入
|
||||
Sheet<UserInfo> lastReg = userService.lastReg();
|
||||
|
Reference in New Issue
Block a user