.
This commit is contained in:
parent
9efc36d666
commit
d0f75d17f6
@ -6,11 +6,25 @@
|
||||
<!-- 如果需要使用redis,此处配置 -->
|
||||
<!--<source name="redis" value="org.redkalex.cache.RedisCacheSource" xxx="16">
|
||||
<node addr="redishost" port="6379" password="pwd123"/>
|
||||
</source>
|
||||
</source>-->
|
||||
|
||||
<properties>
|
||||
<property name="mongo.host" value="redishost"/>
|
||||
<property name="isDev" value="true"/>
|
||||
|
||||
<!-- MongoService 使用到的一些配置
|
||||
<property name="mongo.host" value="127.0.0.1"/>
|
||||
<property name="mongo.port" value="27017"/>
|
||||
<property name="mongo.database" value="redbbs"/>
|
||||
</properties>-->
|
||||
-->
|
||||
|
||||
<!-- ArangoService 使用到的配置
|
||||
<property name="arango.host" value="127.0.0.1"/>
|
||||
<property name="arango.port" value="8529"/>
|
||||
<property name="arango.database" value="redbbs"/>
|
||||
<property name="arango.user" value="root"/>
|
||||
<property name="arango.password" value="root"/>
|
||||
-->
|
||||
</properties>
|
||||
</resources>
|
||||
|
||||
<server protocol="HTTP" host="0.0.0.0" port="80" root="root">
|
||||
|
@ -6,7 +6,6 @@
|
||||
<shared-cache-mode>ALL</shared-cache-mode>
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://mysqlhost:3306/?autoReconnect=true&characterEncoding=utf8"/>
|
||||
<property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>
|
||||
<property name="javax.persistence.jdbc.user" value="guest"/>
|
||||
<property name="javax.persistence.jdbc.password" value="hello"/>
|
||||
</properties>
|
||||
|
2
pom.xml
2
pom.xml
@ -37,7 +37,7 @@
|
||||
<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>
|
||||
|
@ -1,66 +0,0 @@
|
||||
package com.lxyer.bbs.base;
|
||||
|
||||
import com.arangodb.ArangoCollection;
|
||||
import com.arangodb.ArangoDB;
|
||||
import com.arangodb.ArangoDatabase;
|
||||
import com.lxyer.bbs.base.entity.VisLog;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/11/18 9:02.
|
||||
*/
|
||||
public class ArangoKit {
|
||||
|
||||
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||
|
||||
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 ArangoDatabase dbDev = arangoDb.db(chDev.apply("redbbs"));
|
||||
protected static ArangoCollection colVisLog = dbDev.collection(chDev.apply("vis_log"));
|
||||
|
||||
static {
|
||||
if (!dbDev.exists()) {
|
||||
dbDev.create();
|
||||
}
|
||||
|
||||
if (!colVisLog.exists()) {
|
||||
colVisLog.create();
|
||||
}
|
||||
|
||||
//java.net.SocketTimeoutException: Read timed out 加入下面两行,观察是否正常
|
||||
System.setProperty("sun.net.client.defaultConnectTimeout", String.valueOf(1000));
|
||||
System.setProperty("sun.net.client.defaultReadTimeout", String.valueOf(1000));
|
||||
}
|
||||
|
||||
public static <T> CompletableFuture<T> save(T t) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
if (t instanceof VisLog) {
|
||||
colVisLog.insertDocument(t);
|
||||
}
|
||||
return t;
|
||||
});
|
||||
}
|
||||
|
||||
public static long findInt(String aql) {
|
||||
return dbDev.query(aql, long.class).first();
|
||||
}
|
||||
public static long findInt(String aql, Map para) {
|
||||
return dbDev.query(aql, long.class).first();
|
||||
}
|
||||
|
||||
public static <T> List<T> find(String aql, Class<T> clazz) {
|
||||
return dbDev.query(aql, clazz).asListRemaining();
|
||||
}
|
||||
|
||||
public static <T> List<T> find(String aql, Map para, Class<T> clazz) {
|
||||
|
||||
return dbDev.query(aql, para, clazz).asListRemaining();
|
||||
}
|
||||
|
||||
}
|
96
src/com/lxyer/bbs/base/ArangoService.java
Normal file
96
src/com/lxyer/bbs/base/ArangoService.java
Normal file
@ -0,0 +1,96 @@
|
||||
package com.lxyer.bbs.base;
|
||||
|
||||
import com.arangodb.ArangoCollection;
|
||||
import com.arangodb.ArangoDB;
|
||||
import com.arangodb.ArangoDatabase;
|
||||
import com.lxyer.bbs.base.entity.VisLog;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestService;
|
||||
import org.redkale.util.AnyValue;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/11/18 9:02.
|
||||
*/
|
||||
@RestService(automapping = false, comment = "Arango服务")
|
||||
public class ArangoService extends BaseService {
|
||||
|
||||
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||
|
||||
protected Function<String, String> chDev = (s) -> s + (isDev ? "_dev" : "");
|
||||
|
||||
@Resource(name = "property.arango.host")
|
||||
private String arangoHost = "127.0.0.1";
|
||||
@Resource(name = "property.arango.port")
|
||||
private int port = 8529;
|
||||
@Resource(name = "property.arango.database")
|
||||
private String database = "redbbs";
|
||||
@Resource(name = "property.arango.user")
|
||||
private String user = "root";
|
||||
@Resource(name = "property.arango.password")
|
||||
private String password = "root";
|
||||
|
||||
//日志存放doc名称
|
||||
private static final String VIS_LOG = "vis_log";
|
||||
|
||||
//Arango
|
||||
protected static ArangoDB arangoDb;
|
||||
protected static ArangoDatabase dbDev;
|
||||
protected static ArangoCollection colVisLog;
|
||||
|
||||
/* todo:启用本service 打开注释
|
||||
@Override
|
||||
public void init(AnyValue config) {
|
||||
System.out.println("isDev :" + isDev);
|
||||
|
||||
arangoDb = new ArangoDB.Builder().host(arangoHost, port).user(user).password(password).build();
|
||||
dbDev = arangoDb.db(chDev.apply(database));
|
||||
colVisLog = dbDev.collection(chDev.apply(VIS_LOG));
|
||||
|
||||
if (!dbDev.exists()) {
|
||||
dbDev.create();
|
||||
}
|
||||
if (!colVisLog.exists()) {
|
||||
colVisLog.create();
|
||||
}
|
||||
}*/
|
||||
|
||||
@RestMapping(auth = false)
|
||||
public List<Map> hi() {
|
||||
System.out.println("colVisLog :" + colVisLog.exists());
|
||||
String aql = String.format("for d in %s limit 10 return d", chDev.apply(VIS_LOG));
|
||||
List<Map> visLogs = dbDev.query(aql, Map.class).asListRemaining();
|
||||
return visLogs;
|
||||
}
|
||||
|
||||
public static <T> CompletableFuture<T> save(T t) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
if (t instanceof VisLog) {
|
||||
colVisLog.insertDocument(t);
|
||||
}
|
||||
return t;
|
||||
});
|
||||
}
|
||||
|
||||
/*public static long findInt(String aql) {
|
||||
return dbDev.query(aql, long.class).first();
|
||||
}
|
||||
public static long findInt(String aql, Map para) {
|
||||
return dbDev.query(aql, long.class).first();
|
||||
}
|
||||
|
||||
public static <T> List<T> find(String aql, Class<T> clazz) {
|
||||
return dbDev.query(aql, clazz).asListRemaining();
|
||||
}
|
||||
|
||||
public static <T> List<T> find(String aql, Map para, Class<T> clazz) {
|
||||
|
||||
return dbDev.query(aql, para, clazz).asListRemaining();
|
||||
}*/
|
||||
|
||||
}
|
@ -15,6 +15,9 @@ 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;
|
||||
|
||||
|
39
src/com/lxyer/bbs/base/MongoService.java
Normal file
39
src/com/lxyer/bbs/base/MongoService.java
Normal file
@ -0,0 +1,39 @@
|
||||
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操作逻辑 待完成
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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 = logQueue.hotView(sessionid);
|
||||
Sheet<ContentInfo> hotView = Sheet.empty();//logQueue.hotView(sessionid); TODO: 依赖日志记录,需记录日志后可使用
|
||||
|
||||
//最新加入
|
||||
Sheet<UserInfo> lastReg = userService.lastReg();
|
||||
|
Loading…
Reference in New Issue
Block a user