.
This commit is contained in:
parent
60791825e5
commit
af9cbaf0d3
@ -5,22 +5,17 @@
|
||||
<!-- 详细配置说明见: http://redkale.org/redkale.html#redkale_confxml -->
|
||||
<resources>
|
||||
<listener value="com.lxyer.redim.RedbbsListener"/>
|
||||
<group name="ALL">
|
||||
<node addr="192.168.227.1" port="7070"/>
|
||||
<!--<group name="ALL">
|
||||
<node addr="192.168.124.6" port="7070"/>
|
||||
<node addr="192.168.227.138" port="7070"/>
|
||||
<!--<node addr="120.24.230.60" port="7070"/>-->
|
||||
</group>
|
||||
<node addr="120.24.230.60" port="7070"/>
|
||||
</group>-->
|
||||
<source name="redis" value="org.redkalex.cache.RedisCacheSource" xxx="16">
|
||||
<node addr="redishost" port="6379" password="hello"/>
|
||||
</source>
|
||||
|
||||
<!--<source name="mongo" value="com.lxyer.bbs.base.TaskQueue">
|
||||
<node addr="redishost" port="27017"/>
|
||||
</source>-->
|
||||
<properties load="conf.txt">
|
||||
|
||||
<properties>
|
||||
<property name="mongo.host" value="redishost"/>
|
||||
<property name="mongo.database" value="redbbs"/>
|
||||
</properties>
|
||||
</resources>
|
||||
|
||||
@ -30,10 +25,7 @@
|
||||
|
||||
<!--<filters autoload="true"/>-->
|
||||
|
||||
<!--<rest path="" autoload="true"/>--> <!-- base指定的自定义HttpServlet子类必须标记@HttpUserType, 不设置base则视为没有当前用户信息设置 -->
|
||||
<rest path="os" base="com.lxyer.bbs.base.BaseServlet" autoload="true">
|
||||
|
||||
</rest>
|
||||
<rest path="os" base="com.lxyer.bbs.base.BaseServlet" autoload="true"/>
|
||||
|
||||
<request>
|
||||
<!--从X-Real-IP参数中获取IP-->
|
||||
@ -42,32 +34,11 @@
|
||||
|
||||
<servlets path="" autoload="true"/>
|
||||
|
||||
<!--<resource-servlet webroot="root" index="index.html">
|
||||
<cache limit="2M" lengthmax="1M" watch="false"/>
|
||||
|
||||
<rewrite type="location" match="^/([^-]+)-[^-\.]+\.png(.*)" forward="/$1.png"/>
|
||||
</resource-servlet>-->
|
||||
<!--
|
||||
【节点在<server>中唯一】
|
||||
当Server为HTTP协议时,render才有效. 指定输出引擎的实现类
|
||||
value: 输出引擎的实现类, 必须是org.redkale.net.http.HttpRender的子类
|
||||
-->
|
||||
<render value="com.lxyer.bbs.base.EnjoyRender"/>
|
||||
</server>
|
||||
|
||||
<!-- SNCP 监听 Server -->
|
||||
<server protocol="SNCP" port="7070">
|
||||
<services autoload="true" groups="ALL">
|
||||
<!--<service name="hs" value="com.lxyer.service.HelloService" />-->
|
||||
<!-- 有WebSocketServlet的服务必须配置WebSocketNodeService,且Redkale同时会自动创建一个同名(ws_notify)的 CacheSource -->
|
||||
<!--<service name="ws_notify" value="org.redkale.service.WebSocketNodeService"/>-->
|
||||
<!-- 存在DataSource必须配置DataSourceService -->
|
||||
<!--<service name="demodb" value="org.redkale.service.DataSourceService"/>-->
|
||||
<!-- 存放用户HTTP session信息的CacheSource -->
|
||||
<!--<service name="usersessions" value="org.redkale.service.CacheSourceService">
|
||||
<property name="key-type" value="java.lang.String"/>
|
||||
<property name="value-type" value="java.lang.Integer"/>
|
||||
</service>-->
|
||||
</services>
|
||||
</server>
|
||||
<!--<server protocol="SNCP" port="7070">
|
||||
<services autoload="true" groups="ALL"/>
|
||||
</server>-->
|
||||
</application>
|
||||
|
@ -1,11 +1,6 @@
|
||||
# 是否开发模式
|
||||
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
|
||||
|
Binary file not shown.
BIN
lib/redkale.jar
BIN
lib/redkale.jar
Binary file not shown.
19
pom.xml
19
pom.xml
@ -8,6 +8,7 @@
|
||||
<artifactId>redbbs</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<finalName>redbbs</finalName>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@ -22,40 +23,34 @@
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!--maven 打包使用下面的包 -->
|
||||
<dependency>
|
||||
<groupId>org.redkale</groupId>
|
||||
<artifactId>redkale</artifactId>
|
||||
<version>1.9.8</version>
|
||||
<version>1.9.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redkalex</groupId>
|
||||
<artifactId>redkale-plugins</artifactId>
|
||||
<version>1.9.8</version>
|
||||
<version>1.9.9</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>6.0.6</version>
|
||||
<version>5.1.34</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jfinal</groupId>
|
||||
<artifactId>enjoy</artifactId>
|
||||
<version>3.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- mongodb支持 -->
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongo-java-driver</artifactId>
|
||||
<version>3.9.0</version>
|
||||
<version>3.6</version>
|
||||
</dependency>
|
||||
|
||||
<!-- arangodb支持 -->
|
||||
<dependency>
|
||||
<groupId>com.arangodb</groupId>
|
||||
<artifactId>arangodb-java-driver</artifactId>
|
||||
<version>5.0.1</version>
|
||||
<version>5.0.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lxyer</groupId>
|
||||
|
@ -20,7 +20,7 @@ public class ArangoKit {
|
||||
protected static Function<String, String> chDev = (s) -> s + (winos ? "_dev" : "");
|
||||
|
||||
//Arango
|
||||
protected static ArangoDB arangoDb = new ArangoDB.Builder().host("120.24.230.60", 8529).user("root").password("root").build();
|
||||
protected static ArangoDB arangoDb = new ArangoDB.Builder().host("120.24.230.60", 8529).user("root").password("abc123").build();
|
||||
protected static ArangoDatabase dbDev = arangoDb.db(chDev.apply("redbbs"));
|
||||
protected static ArangoCollection colVisLog = dbDev.collection(chDev.apply("vis_log"));
|
||||
|
||||
|
@ -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.
|
||||
@ -15,20 +19,39 @@ public class BaseService implements Service {
|
||||
|
||||
protected final int sessionExpireSeconds = 7 * 24 * 60 * 60;
|
||||
|
||||
@Resource(name = "property.isDev")
|
||||
public boolean isDev = true;
|
||||
|
||||
@Resource(name = "SERVER_ROOT")
|
||||
protected File webroot;
|
||||
|
||||
@Resource(name = "art123")
|
||||
protected DataSource source;
|
||||
|
||||
@Resource(name = "redis")
|
||||
protected CacheSource<Integer> sessions;
|
||||
/* 使用redis 代码中配置此处即可
|
||||
@Resource(name = "redis")*/
|
||||
@Resource(name = "cacheSource")
|
||||
protected CacheSource<Long> sessions;
|
||||
|
||||
@Resource(name = "cacheSource")
|
||||
protected CacheSource cacheSource;
|
||||
|
||||
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;
|
||||
|
@ -88,6 +88,7 @@ public class BaseServlet extends HttpServlet {
|
||||
visLog.setIp(request.getRemoteAddr());
|
||||
visLog.setUri(request.getRequestURI());
|
||||
visLog.setHeaders(headers);
|
||||
visLog.setUserid(userid);
|
||||
visLog.setPara(para);
|
||||
visLog.setTime(System.currentTimeMillis());
|
||||
visLog.setFtime(String.format("%1$tY%1$tm%1$td%1$tH%1$tM%1$tS", visLog.getTime()));
|
||||
|
@ -2,37 +2,26 @@ 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.
|
||||
*/
|
||||
@ -44,28 +33,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();
|
||||
@ -85,7 +58,8 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
|
||||
//记录访问日志,如果是访问的文章详情:对文章访问数量更新
|
||||
if (task instanceof VisLog) {
|
||||
ArangoKit.save(task).thenAcceptAsync((_task) -> {
|
||||
//System.out.println(task);
|
||||
ArangoService.save(task).thenAcceptAsync((_task) -> {
|
||||
VisLog visLog = (VisLog) _task;
|
||||
//[访问量]
|
||||
String uri = visLog.getUri();
|
||||
@ -109,8 +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 = ArangoKit.findInt(aql);
|
||||
|
||||
long total = ArangoService.findInt(aql);
|
||||
|
||||
if (total <= 1) {
|
||||
String uri = visLog.getUri();
|
||||
@ -123,22 +96,22 @@ 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 = ArangoKit.find(
|
||||
"for d in vis_log_dev\n" +
|
||||
List<Count> hotArticle = ArangoService.find(
|
||||
"for d in " + (isDev ? "vis_log_dev" : "vis_log") + "\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" +
|
||||
" sort total desc\n" +
|
||||
" limit 10\n" +
|
||||
" return {name: uri,total:total}",
|
||||
Map.of("time", cal.getTimeInMillis()),
|
||||
Utility.ofMap("time", cal.getTimeInMillis()),
|
||||
Count.class);
|
||||
|
||||
Function<List<Count>, List<Integer>> deal = (counts) -> {
|
||||
@ -159,13 +132,13 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
}
|
||||
|
||||
Flipper flipper = new Flipper().limit(limit);
|
||||
FilterNode node = FilterNode.create("contentid", FilterExpress.IN, contentids);
|
||||
FilterNode node = FilterNode.create("contentid", FilterExpress.IN, contentids).and("status", FilterExpress.NOTEQUAL, -10);
|
||||
|
||||
//权限过滤
|
||||
UserInfo userInfo = userService.current(sessionid);
|
||||
if (userInfo == null){
|
||||
if (userInfo == null){ //访客
|
||||
node.and("status", FilterExpress.NOTEQUAL, 30);
|
||||
}else if (!userService.isAdmin(userInfo.getUserid())){
|
||||
}else if (!userService.isAdmin(userInfo.getUserid())){ //非管理员
|
||||
node.and(FilterNode.create("status", FilterExpress.NOTEQUAL, 30).or(FilterNode.create("status", 30).and("userid", userInfo.getUserid())));
|
||||
}
|
||||
return contentService.contentQuery(flipper, node);
|
||||
@ -176,7 +149,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);
|
||||
@ -205,6 +178,7 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
sheet.setTotal(total);
|
||||
sheet.setRows(rows);
|
||||
|
||||
return sheet;
|
||||
return sheet;*/
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.lxyer.bbs.base.entity;
|
||||
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -9,7 +11,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class VisLog {
|
||||
private String ip;
|
||||
private String userid;
|
||||
private int userid;
|
||||
private String ftime;
|
||||
private String uri;
|
||||
private long time;
|
||||
@ -24,11 +26,11 @@ public class VisLog {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public String getUserid() {
|
||||
public int getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(String userid) {
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
@ -74,14 +76,6 @@ public class VisLog {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "VisLog{" +
|
||||
"ip='" + ip + '\'' +
|
||||
", userid='" + userid + '\'' +
|
||||
", ftime='" + ftime + '\'' +
|
||||
", uri='" + uri + '\'' +
|
||||
", time=" + time +
|
||||
", para=" + para +
|
||||
", headers=" + headers +
|
||||
'}';
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
package com.lxyer.bbs.base.user;
|
||||
|
||||
import javax.persistence.*;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import javax.persistence.Cacheable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -8,7 +8,10 @@ import org.redkale.net.http.RestParam;
|
||||
import org.redkale.net.http.RestService;
|
||||
import org.redkale.net.http.RestSessionid;
|
||||
import org.redkale.service.RetResult;
|
||||
import org.redkale.source.*;
|
||||
import org.redkale.source.FilterExpress;
|
||||
import org.redkale.source.FilterFunc;
|
||||
import org.redkale.source.FilterNode;
|
||||
import org.redkale.source.Flipper;
|
||||
import org.redkale.util.SelectColumn;
|
||||
import org.redkale.util.Sheet;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user