1、【新增/修改】将日志写入到ArangoDb(原来MongoDb)
2、【升级】 升级多个jar依赖
This commit is contained in:
parent
4c5ee1baf2
commit
a5750efce0
26
pom.xml
26
pom.xml
@ -13,8 +13,8 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>10</source>
|
||||
<target>10</target>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
@ -25,12 +25,12 @@
|
||||
<dependency>
|
||||
<groupId>org.redkale</groupId>
|
||||
<artifactId>redkale</artifactId>
|
||||
<version>1.9.6</version>
|
||||
<version>1.9.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.redkalex</groupId>
|
||||
<artifactId>redkale-plugins</artifactId>
|
||||
<version>1.9.6</version>
|
||||
<version>1.9.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -41,17 +41,21 @@
|
||||
<dependency>
|
||||
<groupId>com.jfinal</groupId>
|
||||
<artifactId>enjoy</artifactId>
|
||||
<version>3.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongodb-driver</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<version>3.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- mongodb支持 -->
|
||||
<dependency>
|
||||
<groupId>org.mongodb</groupId>
|
||||
<artifactId>mongo-java-driver</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<version>3.9.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- arangodb支持 -->
|
||||
<dependency>
|
||||
<groupId>com.arangodb</groupId>
|
||||
<artifactId>arangodb-java-driver</artifactId>
|
||||
<version>5.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<!--maven 打包不需要-->
|
||||
|
41
src/com/lxyer/bbs/base/ArangoKit.java
Normal file
41
src/com/lxyer/bbs/base/ArangoKit.java
Normal file
@ -0,0 +1,41 @@
|
||||
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.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("pwd123").build();
|
||||
protected static ArangoDatabase dbDev = arangoDb.db(chDev.apply("redbbs"));
|
||||
protected static ArangoCollection colVisLog = dbDev.collection(chDev.apply("vis_log"));
|
||||
|
||||
//check exists
|
||||
static {
|
||||
if (!dbDev.exists()) {
|
||||
dbDev.create();
|
||||
}
|
||||
|
||||
if (!colVisLog.exists()) {
|
||||
colVisLog.create();
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void save(T t) {
|
||||
if (t instanceof VisLog) {
|
||||
colVisLog.insertDocument(t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.lxyer.bbs.base;
|
||||
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.lxyer.bbs.base.entity.VisLog;
|
||||
import com.lxyer.bbs.base.kit.RetCodes;
|
||||
import com.lxyer.bbs.base.user.UserInfo;
|
||||
import com.lxyer.bbs.base.user.UserService;
|
||||
@ -14,7 +15,6 @@ import org.redkale.util.AnyValue;
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.lxyer.bbs.base.kit.RetCodes.RET_USER_UNLOGIN;
|
||||
@ -39,7 +39,7 @@ public class BaseServlet extends HttpServlet {
|
||||
protected CommentService commentService;
|
||||
|
||||
@Resource
|
||||
protected TaskQueue<Map> logQueue;
|
||||
protected TaskQueue<VisLog> logQueue;
|
||||
|
||||
@Override
|
||||
public void init(HttpContext context, AnyValue config) {
|
||||
@ -74,23 +74,23 @@ public class BaseServlet extends HttpServlet {
|
||||
//异步记录访问日志
|
||||
final int userid = currentid;
|
||||
CompletableFuture.runAsync(()->{
|
||||
Kv visLog = new Kv();//ip、time、userid、uri、para
|
||||
visLog.set("ip", request.getRemoteAddr());
|
||||
visLog.set("time", System.currentTimeMillis());
|
||||
visLog.set("userid", userid);
|
||||
visLog.set("uri", request.getRequestURI());
|
||||
|
||||
Kv headers = Kv.create();
|
||||
request.getHeaders().forEach((k,v)->{
|
||||
headers.set(k, request.getHeader(k));
|
||||
});
|
||||
visLog.set("headers", headers);
|
||||
|
||||
Kv para = Kv.create();
|
||||
for (String key : request.getParameterNames()){
|
||||
para.set(key, request.getParameter(key));
|
||||
}
|
||||
visLog.set("para", para);
|
||||
Kv headers = Kv.create();
|
||||
request.getHeaders().forEach((k,v)->{
|
||||
headers.set(k, request.getHeader(k));
|
||||
});
|
||||
|
||||
VisLog visLog = new VisLog();
|
||||
visLog.setIp(request.getRemoteAddr());
|
||||
visLog.setHeaders(headers);
|
||||
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()));
|
||||
|
||||
try {
|
||||
logQueue.put(visLog);
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.lxyer.bbs.base;
|
||||
|
||||
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;
|
||||
@ -83,7 +84,12 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
public void run() {
|
||||
try {
|
||||
while (true){
|
||||
Map logData = (Map) take();
|
||||
T task = take();
|
||||
if (task instanceof VisLog) {
|
||||
ArangoKit.save(task);
|
||||
}
|
||||
|
||||
/*Map logData = (Map) take();
|
||||
|
||||
logData.put("ftime", String.format("%1$tY%1$tm%1$td%1$tH%1$tM%1$tS", logData.get("time")));
|
||||
visLog.insertOne(new Document(logData));
|
||||
@ -94,7 +100,7 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
||||
//[访问量]
|
||||
if (uri.startsWith("/jie/detail/")){
|
||||
updateViewNumAsync(logData);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
|
74
src/com/lxyer/bbs/base/entity/VisLog.java
Normal file
74
src/com/lxyer/bbs/base/entity/VisLog.java
Normal file
@ -0,0 +1,74 @@
|
||||
package com.lxyer.bbs.base.entity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 存贮数据到 非关系型数据库
|
||||
*
|
||||
* @author: liangxianyou at 2018/11/18 8:47.
|
||||
*/
|
||||
public class VisLog {
|
||||
private String ip;
|
||||
private String userid;
|
||||
private String ftime;
|
||||
private String uri;
|
||||
private long time;
|
||||
private Map para;
|
||||
private Map headers;
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public String getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(String userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getFtime() {
|
||||
return ftime;
|
||||
}
|
||||
|
||||
public void setFtime(String ftime) {
|
||||
this.ftime = ftime;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(long time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public Map getPara() {
|
||||
return para;
|
||||
}
|
||||
|
||||
public void setPara(Map para) {
|
||||
this.para = para;
|
||||
}
|
||||
|
||||
public Map getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public void setHeaders(Map headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
}
|
@ -79,7 +79,7 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
||||
}else {
|
||||
source.findAsync(Content.class, content.getContentid()).thenAccept(x->{
|
||||
if (x.getUserid() == userid || userService.isAdmin(userid)){//身份验证 后修改内容
|
||||
source.updateColumnAsync(content,SelectColumn.createIncludes("title", "digest", "content","type", "status"));
|
||||
source.updateColumnAsync(content,SelectColumn.includes("title", "digest", "content","type", "status"));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -130,10 +130,10 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
||||
|
||||
Flipper flipper = new Flipper().sort("createtime DESC");
|
||||
FilterNode filterNode = FilterNode.create("cate", 20).and("status", 10).and("userid", userid);
|
||||
Sheet<ActLog> actLogs = source.querySheet(ActLog.class, SelectColumn.createIncludes("tid", "createtime"), flipper, filterNode);
|
||||
Sheet<ActLog> actLogs = source.querySheet(ActLog.class, SelectColumn.includes("tid", "createtime"), flipper, filterNode);
|
||||
|
||||
int[] contentids = actLogs.stream().mapToInt(x -> x.getTid()).toArray();
|
||||
Sheet<Content> contents = source.querySheet(Content.class, SelectColumn.createIncludes("contentid", "title"), flipper.sort(null), FilterNode.create("contentid", FilterExpress.IN, contentids));
|
||||
Sheet<Content> contents = source.querySheet(Content.class, SelectColumn.includes("contentid", "title"), flipper.sort(null), FilterNode.create("contentid", FilterExpress.IN, contentids));
|
||||
|
||||
Sheet<ContentInfo> infos = createInfo(contents);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user