diff --git a/conf/conf.txt b/conf/conf.txt index 8b13789..1d270c7 100644 --- a/conf/conf.txt +++ b/conf/conf.txt @@ -1 +1,18 @@ +# 是否开发模式 +isDev=true +----------- mongo conf ---------- +mongo.host=127.0.0.1 +mongo.port=27017 +mongo.database=redbbs + +----------- arango conf ---------- +arango.host=120.24.230.60 +arango.port=8529 +arango.database=redbbs +arango.user=root +arango.password=abc123 + +----------- file conf ---------- +file.upload_dir=D:/wk/_own/redbbs/root/file_pub/ +file.view_path=http://127.0.0.1/file_pub/ diff --git a/lib/arangodb-java-driver-5.0.4.jar b/lib/arangodb-java-driver-5.0.4.jar new file mode 100644 index 0000000..f0b5c72 Binary files /dev/null and b/lib/arangodb-java-driver-5.0.4.jar differ diff --git a/lib/enjoy-3.6.jar b/lib/enjoy-3.6.jar new file mode 100644 index 0000000..1431a56 Binary files /dev/null and b/lib/enjoy-3.6.jar differ diff --git a/lib/mongo-java-driver-3.9.0.jar b/lib/mongo-java-driver-3.9.0.jar deleted file mode 100644 index 502541f..0000000 Binary files a/lib/mongo-java-driver-3.9.0.jar and /dev/null differ diff --git a/lib/netty-all-4.1.29.Final.jar b/lib/netty-all-4.1.29.Final.jar deleted file mode 100644 index b84979f..0000000 Binary files a/lib/netty-all-4.1.29.Final.jar and /dev/null differ diff --git a/lib/redkale-1.9.8.jar b/lib/redkale-1.9.9.jar similarity index 55% rename from lib/redkale-1.9.8.jar rename to lib/redkale-1.9.9.jar index c19e9e7..3e91209 100644 Binary files a/lib/redkale-1.9.8.jar and b/lib/redkale-1.9.9.jar differ diff --git a/lib/redkale-plugins-1.9.9.jar b/lib/redkale-plugins-1.9.9.jar new file mode 100644 index 0000000..c1ad9df Binary files /dev/null and b/lib/redkale-plugins-1.9.9.jar differ diff --git a/pom.xml b/pom.xml index c16e0f9..4c72c07 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ com.lxyer redbbs 1.0-SNAPSHOT + war src @@ -26,12 +27,12 @@ org.redkale redkale - 1.9.8 + 1.9.9 org.redkalex redkale-plugins - 1.9.8 + 1.9.9 @@ -42,21 +43,14 @@ com.jfinal enjoy - 3.5 - - - - - org.mongodb - mongo-java-driver - 3.9.0 + 3.6 com.arangodb arangodb-java-driver - 5.0.1 + 5.0.4 diff --git a/src/com/lxyer/bbs/base/ArangoService.java b/src/com/lxyer/bbs/base/ArangoService.java index 3b0964f..572ad66 100644 --- a/src/com/lxyer/bbs/base/ArangoService.java +++ b/src/com/lxyer/bbs/base/ArangoService.java @@ -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 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 List find(String aql, Map para, Class clazz) { return dbDev.query(aql, para, clazz).asListRemaining(); - }*/ + } } diff --git a/src/com/lxyer/bbs/base/BaseService.java b/src/com/lxyer/bbs/base/BaseService.java index f093e6e..d57a591 100644 --- a/src/com/lxyer/bbs/base/BaseService.java +++ b/src/com/lxyer/bbs/base/BaseService.java @@ -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; diff --git a/src/com/lxyer/bbs/base/MongoService.java b/src/com/lxyer/bbs/base/MongoService.java deleted file mode 100644 index 1f939bd..0000000 --- a/src/com/lxyer/bbs/base/MongoService.java +++ /dev/null @@ -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 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操作逻辑 待完成 - -} diff --git a/src/com/lxyer/bbs/base/TaskQueue.java b/src/com/lxyer/bbs/base/TaskQueue.java index ab1204d..434e68b 100644 --- a/src/com/lxyer/bbs/base/TaskQueue.java +++ b/src/com/lxyer/bbs/base/TaskQueue.java @@ -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 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 extends BaseService implements Runnable updateViewNum(visLog); } }); - */ } } catch (InterruptedException e) { @@ -84,7 +83,7 @@ public class TaskQueue 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 extends BaseService implements Runnable public Sheet 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 hotArticle = new ArrayList<>(); - /* TODO: 依赖日志记录,需记录日志后可使用 List 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 extends BaseService implements Runnable " limit 10\n" + " return {name: uri,total:total}", Utility.ofMap("time", cal.getTimeInMillis()), - Count.class);*/ + Count.class); Function, List> deal = (counts) -> { List _ids = new ArrayList<>(); diff --git a/src/com/lxyer/bbs/servlet/ContentServlet.java b/src/com/lxyer/bbs/servlet/ContentServlet.java index 09a342d..5b0a50a 100644 --- a/src/com/lxyer/bbs/servlet/ContentServlet.java +++ b/src/com/lxyer/bbs/servlet/ContentServlet.java @@ -62,7 +62,7 @@ public class ContentServlet extends BaseServlet { /*Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC"); Sheet hotReply = contentService.contentQuery(flipper3, "", sessionid);*/ - Sheet hotView = Sheet.empty();//logQueue.hotView(sessionid); TODO: 依赖日志记录,需记录日志后可使用 + Sheet 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 contents = contentService.contentQuery(flipper, setPrivate(request, setPrivate(request, filterNode))); //热帖 - Sheet hotView = Sheet.empty();//logQueue.hotView(sessionid); TODO: 依赖日志记录,需记录日志后可使用 + Sheet hotView = logQueue.hotView(sessionid); Kv kv = Kv.by("contents", contents).set("hotView", hotView) .set("solved", solved).set("wonderful", wonderful) diff --git a/src/com/lxyer/bbs/servlet/IndexServlet.java b/src/com/lxyer/bbs/servlet/IndexServlet.java index 0f6e595..a7d5a6f 100644 --- a/src/com/lxyer/bbs/servlet/IndexServlet.java +++ b/src/com/lxyer/bbs/servlet/IndexServlet.java @@ -42,7 +42,7 @@ public class IndexServlet extends BaseServlet { /*Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC"); Sheet hotReply = contentService.contentQuery(flipper3, "", sessionid);*/ - Sheet hotView = Sheet.empty();//logQueue.hotView(sessionid); TODO: 依赖日志记录,需记录日志后可使用 + Sheet hotView = logQueue.hotView(sessionid); //最新加入 Sheet lastReg = userService.lastReg();