重要更新:
1、修改servlet层中BaseServlet中共享request的重大bug 2、将servlet中页面统一使用HttpScope进行渲染
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<property name="mongo.host" value="127.0.0.1"/>
|
<property name="mongo.host" value="127.0.0.1"/>
|
||||||
|
<property name="mongo.database" value="redbbs"/>
|
||||||
</properties>
|
</properties>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
@@ -24,6 +25,11 @@
|
|||||||
<rest path="os" base="com.lxyer.bbs.base.BaseServlet" autoload="true">
|
<rest path="os" base="com.lxyer.bbs.base.BaseServlet" autoload="true">
|
||||||
|
|
||||||
</rest>
|
</rest>
|
||||||
|
|
||||||
|
<request>
|
||||||
|
<!--从X-Real-IP参数中获取IP-->
|
||||||
|
<remoteaddr value="request.headers.X-Real-IP"/>
|
||||||
|
</request>
|
||||||
|
|
||||||
<servlets path="" autoload="true"/>
|
<servlets path="" autoload="true"/>
|
||||||
|
|
||||||
|
BIN
libs/redbbs.jar
BIN
libs/redbbs.jar
Binary file not shown.
@@ -1,18 +1,12 @@
|
|||||||
package com.lxyer.bbs.base;
|
package com.lxyer.bbs.base;
|
||||||
|
|
||||||
import com.jfinal.kit.Kv;
|
import com.jfinal.kit.Kv;
|
||||||
import com.jfinal.template.Engine;
|
|
||||||
import com.jfinal.template.Template;
|
|
||||||
import com.lxyer.bbs.base.kit.EJ;
|
|
||||||
import com.lxyer.bbs.base.kit.RetCodes;
|
import com.lxyer.bbs.base.kit.RetCodes;
|
||||||
import com.lxyer.bbs.base.user.UserInfo;
|
import com.lxyer.bbs.base.user.UserInfo;
|
||||||
import com.lxyer.bbs.base.user.UserService;
|
import com.lxyer.bbs.base.user.UserService;
|
||||||
import com.lxyer.bbs.comment.CommentService;
|
import com.lxyer.bbs.comment.CommentService;
|
||||||
import com.lxyer.bbs.content.ContentService;
|
import com.lxyer.bbs.content.ContentService;
|
||||||
import org.redkale.net.http.HttpContext;
|
import org.redkale.net.http.*;
|
||||||
import org.redkale.net.http.HttpRequest;
|
|
||||||
import org.redkale.net.http.HttpResponse;
|
|
||||||
import org.redkale.net.http.HttpServlet;
|
|
||||||
import org.redkale.source.FilterExpress;
|
import org.redkale.source.FilterExpress;
|
||||||
import org.redkale.source.FilterNode;
|
import org.redkale.source.FilterNode;
|
||||||
import org.redkale.util.AnyValue;
|
import org.redkale.util.AnyValue;
|
||||||
@@ -21,6 +15,7 @@ import javax.annotation.Resource;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import static com.lxyer.bbs.base.kit.RetCodes.RET_USER_UNLOGIN;
|
import static com.lxyer.bbs.base.kit.RetCodes.RET_USER_UNLOGIN;
|
||||||
|
|
||||||
@@ -28,26 +23,15 @@ import static com.lxyer.bbs.base.kit.RetCodes.RET_USER_UNLOGIN;
|
|||||||
* Created by Lxy at 2017/10/3 13:39.
|
* Created by Lxy at 2017/10/3 13:39.
|
||||||
*/
|
*/
|
||||||
public class BaseServlet extends HttpServlet {
|
public class BaseServlet extends HttpServlet {
|
||||||
private HttpRequest request;
|
|
||||||
private HttpResponse response;
|
|
||||||
private static final Kv _kv = Kv.create();
|
|
||||||
private static Engine engine;
|
|
||||||
protected String sessionid;
|
|
||||||
protected int currentid;//登录人id
|
|
||||||
|
|
||||||
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||||
|
|
||||||
@Resource(name = "SERVER_ROOT")
|
@Resource(name = "SERVER_ROOT")
|
||||||
protected File webroot;
|
protected File webroot;
|
||||||
|
|
||||||
/*@Resource
|
|
||||||
protected EnjoyService enjoyService;*/
|
|
||||||
@Resource
|
@Resource
|
||||||
protected UserService userService;
|
protected UserService userService;
|
||||||
|
|
||||||
/*@Resource(name = "redis")
|
|
||||||
protected RedisCacheSource<String> cache;*/
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected ContentService contentService;
|
protected ContentService contentService;
|
||||||
|
|
||||||
@@ -57,28 +41,20 @@ public class BaseServlet extends HttpServlet {
|
|||||||
@Resource
|
@Resource
|
||||||
protected TaskQueue<Map> logQueue;
|
protected TaskQueue<Map> logQueue;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(HttpContext context, AnyValue config) {
|
public void init(HttpContext context, AnyValue config) {
|
||||||
if (engine == null){
|
|
||||||
engine = new Engine();
|
|
||||||
engine.setBaseTemplatePath(webroot.getPath());
|
|
||||||
engine.addSharedObject("EJ", new EJ());
|
|
||||||
engine.addSharedFunction("/_t/layout.html");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void preExecute(HttpRequest request, HttpResponse response) throws IOException {
|
protected void preExecute(HttpRequest request, HttpResponse response) throws IOException {
|
||||||
sessionid = request.getSessionid(false);
|
String sessionid = request.getSessionid(true);
|
||||||
|
int currentid = 0;
|
||||||
if (sessionid != null) {
|
if (sessionid != null) {
|
||||||
request.setCurrentUser(userService.current(sessionid));
|
request.setCurrentUser(userService.current(sessionid));
|
||||||
currentid = userService.currentUserId(sessionid);
|
currentid = userService.currentUserId(sessionid);
|
||||||
_kv.set("mine", request.currentUser());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.request = request;
|
|
||||||
this.response = response;
|
|
||||||
String uri = request.getRequestURI();
|
String uri = request.getRequestURI();
|
||||||
if (uri.startsWith("/res")){
|
if (uri.startsWith("/res")){
|
||||||
File file = new File(webroot + uri);
|
File file = new File(webroot + uri);
|
||||||
@@ -86,34 +62,30 @@ public class BaseServlet extends HttpServlet {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (uri.endsWith(".html")){
|
if (uri.endsWith(".html")){
|
||||||
Kv kv = Kv.by("resSys", "resSys");
|
response.finish(HttpScope.refer(uri));
|
||||||
finish(uri, kv);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Kv visLog = new Kv();//ip、time、userid、uri、para
|
//异步记录访问日志
|
||||||
visLog.set("ip", request.getRemoteAddr());
|
final int userid = currentid;
|
||||||
request.getHost();
|
CompletableFuture.runAsync(()->{
|
||||||
visLog.set("time", System.currentTimeMillis());
|
Kv visLog = new Kv();//ip、time、userid、uri、para
|
||||||
visLog.set("userid", currentid);
|
visLog.set("ip", request.getRemoteAddr());
|
||||||
visLog.set("uri", request.getRequestURI());
|
visLog.set("time", System.currentTimeMillis());
|
||||||
|
visLog.set("userid", userid);
|
||||||
|
visLog.set("uri", request.getRequestURI());
|
||||||
|
|
||||||
Kv para = Kv.create();
|
Kv para = Kv.create();
|
||||||
for (String key : request.getParameterNames()){
|
for (String key : request.getParameterNames()){
|
||||||
para.set(key, request.getParameter(key));
|
para.set(key, request.getParameter(key));
|
||||||
}
|
}
|
||||||
visLog.set("para", para);
|
visLog.set("para", para);
|
||||||
try {
|
try {
|
||||||
logQueue.put(visLog);
|
logQueue.put(visLog);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/*if ("/".equals(uri)){
|
|
||||||
finish("/front/index.html", Kv.by("",""));
|
|
||||||
return;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
response.nextEvent();
|
response.nextEvent();
|
||||||
}
|
}
|
||||||
@@ -124,49 +96,26 @@ public class BaseServlet extends HttpServlet {
|
|||||||
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))){
|
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))){
|
||||||
response.finish(RetCodes.retResult(RET_USER_UNLOGIN, "未登录,登录后重试").toString());
|
response.finish(RetCodes.retResult(RET_USER_UNLOGIN, "未登录,登录后重试").toString());
|
||||||
}else {
|
}else {
|
||||||
finish("/user/login.html");
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
response.nextEvent();
|
response.nextEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finish(String view, Kv kv) {
|
public int getLimit(HttpRequest request){
|
||||||
if (request.currentUser() != null){
|
|
||||||
kv.set("mine", request.currentUser());
|
|
||||||
}
|
|
||||||
|
|
||||||
Template template = engine.getTemplate(view);
|
|
||||||
String str = template.renderToString(kv);
|
|
||||||
response.setContentType("text/html; charset=UTF-8");
|
|
||||||
response.finish(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void finish(String view){
|
|
||||||
finish(view, _kv);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLimit(){
|
|
||||||
return request.getIntParameter("limit", 1);
|
return request.getIntParameter("limit", 1);
|
||||||
}
|
}
|
||||||
public int getOffset(){
|
public int getOffset(HttpRequest request){
|
||||||
return request.getIntParameter("offset", 10);
|
return request.getIntParameter("offset", 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
public String getPara(HttpRequest request){
|
||||||
测试用例
|
|
||||||
System.out.println("sb="+getPara());
|
|
||||||
System.out.println("sb(0)="+getPara(0));
|
|
||||||
System.out.println("sb(1)="+getPara(1));
|
|
||||||
System.out.println("sb(-1)="+getPara(-1));
|
|
||||||
System.out.println("sb(-2)="+getPara(-2));
|
|
||||||
* */
|
|
||||||
public String getPara(){
|
|
||||||
String requestURI = request.getRequestURI();
|
String requestURI = request.getRequestURI();
|
||||||
String subStr = requestURI.substring(requestURI.lastIndexOf("/") + 1);
|
String subStr = requestURI.substring(requestURI.lastIndexOf("/") + 1);
|
||||||
return subStr.contains("-") ? subStr.substring(0, subStr.indexOf("-")) : subStr;
|
return subStr.contains("-") ? subStr.substring(0, subStr.indexOf("-")) : subStr;
|
||||||
}
|
}
|
||||||
public String getPara(int index){
|
public String getPara(HttpRequest request,int index){
|
||||||
String requestURI = request.getRequestURI();
|
String requestURI = request.getRequestURI();
|
||||||
String subStr = requestURI.substring(requestURI.lastIndexOf("/") + 1);
|
String subStr = requestURI.substring(requestURI.lastIndexOf("/") + 1);
|
||||||
|
|
||||||
@@ -177,17 +126,17 @@ public class BaseServlet extends HttpServlet {
|
|||||||
return paraArr.length < index+1 ? null : paraArr[index];
|
return paraArr.length < index+1 ? null : paraArr[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public <T> T getPara(int index, T defaultValue){
|
public <T> T getPara(HttpRequest request, int index, T defaultValue){
|
||||||
T para = (T)getPara(index);
|
T para = (T)getPara(request,index);
|
||||||
return para == null || "".equals(para) ? defaultValue : para;
|
return para == null || "".equals(para) ? defaultValue : para;
|
||||||
}
|
}
|
||||||
public int getParaToInt(int index, int defaultValue){
|
public int getParaToInt(HttpRequest request,int index, int defaultValue){
|
||||||
String para = getPara(index);
|
String para = getPara(request,index);
|
||||||
return para == null || "".equals(para) ? defaultValue : Integer.parseInt(para);
|
return para == null || "".equals(para) ? defaultValue : Integer.parseInt(para);
|
||||||
}
|
}
|
||||||
public int getParaToInt(int index){
|
public int getParaToInt(HttpRequest request,int index){
|
||||||
int n = 0;
|
int n = 0;
|
||||||
String para = getPara(index);
|
String para = getPara(request,index);
|
||||||
if (para == null || "".equals(para)) n = 0;
|
if (para == null || "".equals(para)) n = 0;
|
||||||
try {
|
try {
|
||||||
n = Integer.parseInt(para);
|
n = Integer.parseInt(para);
|
||||||
@@ -198,11 +147,11 @@ public class BaseServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//设置私密帖子过滤
|
//设置私密帖子过滤
|
||||||
protected FilterNode setPrivate(FilterNode node){
|
protected FilterNode setPrivate(HttpRequest request,FilterNode node){
|
||||||
UserInfo userInfo = request.currentUser();
|
UserInfo userInfo = request.currentUser();
|
||||||
if (userInfo == null){
|
if (userInfo == null){
|
||||||
node.and("status", FilterExpress.NOTEQUAL, 30);
|
node.and("status", FilterExpress.NOTEQUAL, 30);
|
||||||
}else if (!userService.isAdmin(currentid)){
|
}else if (!userService.isAdmin(userInfo.getUserid())){
|
||||||
//select * from content c where c.status != -1 and (c.status!=30 or (c.status=30 and c.userid=100001))
|
//select * from content c where c.status != -1 and (c.status!=30 or (c.status=30 and c.userid=100001))
|
||||||
node.and(FilterNode.create("status", FilterExpress.NOTEQUAL, 30).or(FilterNode.create("status", 30).and("userid", userInfo.getUserid())));
|
node.and(FilterNode.create("status", FilterExpress.NOTEQUAL, 30).or(FilterNode.create("status", 30).and("userid", userInfo.getUserid())));
|
||||||
}
|
}
|
||||||
|
@@ -1,14 +1,17 @@
|
|||||||
package com.lxyer.bbs.base;
|
package com.lxyer.bbs.base;
|
||||||
|
|
||||||
|
import com.jfinal.kit.Kv;
|
||||||
import com.jfinal.template.Engine;
|
import com.jfinal.template.Engine;
|
||||||
import com.jfinal.template.Template;
|
import com.jfinal.template.Template;
|
||||||
import com.lxyer.bbs.base.kit.EJ;
|
import com.lxyer.bbs.base.kit.EJ;
|
||||||
|
import com.lxyer.bbs.base.user.UserInfo;
|
||||||
import org.redkale.convert.Convert;
|
import org.redkale.convert.Convert;
|
||||||
import org.redkale.net.http.*;
|
import org.redkale.net.http.*;
|
||||||
import org.redkale.util.AnyValue;
|
import org.redkale.util.AnyValue;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by JUECHENG at 2018/1/30 0:18.
|
* Created by JUECHENG at 2018/1/30 0:18.
|
||||||
@@ -29,8 +32,14 @@ public class EnjoyRender implements HttpRender<HttpScope> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderTo(HttpRequest request, HttpResponse response, Convert convert, HttpScope scope) {
|
public void renderTo(HttpRequest request, HttpResponse response, Convert convert, HttpScope scope) {
|
||||||
|
UserInfo mine = request.currentUser();//当前登录人
|
||||||
|
|
||||||
Template template = engine.getTemplate(scope.getReferid());
|
Template template = engine.getTemplate(scope.getReferid());
|
||||||
String str = template.renderToString(scope.getAttributes());
|
Map attr = scope.getAttributes();
|
||||||
|
if (attr == null) attr = Kv.create();
|
||||||
|
attr.put("mine", mine);
|
||||||
|
|
||||||
|
String str = template.renderToString(attr);
|
||||||
response.setContentType("text/html; charset=UTF-8");
|
response.setContentType("text/html; charset=UTF-8");
|
||||||
response.finish(str);
|
response.finish(str);
|
||||||
}
|
}
|
||||||
|
@@ -17,11 +17,13 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
|||||||
|
|
||||||
@Resource(name = "property.mongo.host")
|
@Resource(name = "property.mongo.host")
|
||||||
private String mongoHost;
|
private String mongoHost;
|
||||||
|
@Resource(name = "property.mongo.database")
|
||||||
|
private String mongoDatabase;
|
||||||
|
|
||||||
protected static LinkedBlockingQueue queue = new LinkedBlockingQueue();
|
protected static LinkedBlockingQueue queue = new LinkedBlockingQueue();
|
||||||
|
|
||||||
private static MongoClient mongoClient;
|
private static MongoClient mongoClient;
|
||||||
private static MongoDatabase redbbs;
|
private static MongoDatabase database;
|
||||||
private static MongoCollection<Document> visLog;
|
private static MongoCollection<Document> visLog;
|
||||||
|
|
||||||
public TaskQueue() {
|
public TaskQueue() {
|
||||||
@@ -31,8 +33,8 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
|||||||
@Override
|
@Override
|
||||||
public void init(AnyValue config) {
|
public void init(AnyValue config) {
|
||||||
mongoClient = new MongoClient(mongoHost, 27017);
|
mongoClient = new MongoClient(mongoHost, 27017);
|
||||||
redbbs = mongoClient.getDatabase(winos ? "redbbs_dev": "redbbs");
|
database = mongoClient.getDatabase(winos ? mongoDatabase + "_dev": mongoDatabase);
|
||||||
visLog = redbbs.getCollection("vis_log");
|
visLog = database.getCollection("vis_log");
|
||||||
}
|
}
|
||||||
|
|
||||||
public T take() throws InterruptedException {
|
public T take() throws InterruptedException {
|
||||||
@@ -49,7 +51,7 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
|||||||
while (true){
|
while (true){
|
||||||
Map take = (Map) take();
|
Map take = (Map) take();
|
||||||
|
|
||||||
take.put("ftime", String.format("%1$tY%1$tm%1$td%1$tH%1$tM", take.get("time")));
|
take.put("ftime", String.format("%1$tY%1$tm%1$td%1$tH%1$tM%1$tS", take.get("time")));
|
||||||
visLog.insertOne(new Document(take));
|
visLog.insertOne(new Document(take));
|
||||||
|
|
||||||
//在这里处理日志数据[访问量]
|
//在这里处理日志数据[访问量]
|
||||||
@@ -58,12 +60,4 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public static void main(String[] args) {
|
|
||||||
//测试mongodb 连通性
|
|
||||||
FindIterable<Document> documents = visLog.find().limit(10);
|
|
||||||
documents.forEach((Block<? super Document>) x->{
|
|
||||||
System.out.println(x);
|
|
||||||
});
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
@@ -48,6 +48,8 @@ public class UserService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public UserInfo current(String sessionid){
|
public UserInfo current(String sessionid){
|
||||||
|
if (sessionid == null) return null;
|
||||||
|
|
||||||
Object userid = sessions.getAndRefresh(sessionid, sessionExpireSeconds);
|
Object userid = sessions.getAndRefresh(sessionid, sessionExpireSeconds);
|
||||||
sessions.getAndRefresh(sessionid, sessionExpireSeconds);
|
sessions.getAndRefresh(sessionid, sessionExpireSeconds);
|
||||||
return userid == null ? null : findUserInfo((Integer) userid);
|
return userid == null ? null : findUserInfo((Integer) userid);
|
||||||
@@ -151,14 +153,6 @@ public class UserService extends BaseService {
|
|||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@RestMapping(name = "stat", auth = false, comment = "用户数据统计")
|
|
||||||
public Map userStat(){
|
|
||||||
|
|
||||||
Number count = source.getNumberResult(User.class, FilterFunc.COUNT, "userId", FilterNode.create("status", FilterExpress.NOTEQUAL, -1));
|
|
||||||
|
|
||||||
return Kv.by("count", count);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@RestMapping(name = "usercount", auth = false, comment = "用户数据统计")
|
@RestMapping(name = "usercount", auth = false, comment = "用户数据统计")
|
||||||
public Number userCount() {
|
public Number userCount() {
|
||||||
return source.getNumberResult(UserRecord.class, FilterFunc.COUNT, "userid", FilterNode.create("status", FilterExpress.NOTEQUAL, -10));
|
return source.getNumberResult(UserRecord.class, FilterFunc.COUNT, "userid", FilterNode.create("status", FilterExpress.NOTEQUAL, -10));
|
||||||
|
@@ -41,7 +41,10 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "query", auth = false, comment = "内容列表")
|
@RestMapping(name = "query", auth = false, comment = "内容列表")
|
||||||
public Sheet<ContentInfo> contentQuery(Flipper flipper, String actived, int currentid){
|
public Sheet<ContentInfo> contentQuery(Flipper flipper, String actived, String sessionid){
|
||||||
|
UserInfo current = userService.current(sessionid);
|
||||||
|
int currentid = current == null ? 0 : current.getUserid();
|
||||||
|
|
||||||
FilterNode filterNode = FilterNode.create("status", FilterExpress.NOTEQUAL, -1);
|
FilterNode filterNode = FilterNode.create("status", FilterExpress.NOTEQUAL, -1);
|
||||||
switch (actived){
|
switch (actived){
|
||||||
case "top": filterNode.and("top", FilterExpress.GREATERTHANOREQUALTO, 20);break;
|
case "top": filterNode.and("top", FilterExpress.GREATERTHANOREQUALTO, 20);break;
|
||||||
@@ -157,7 +160,7 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "t",auth = false, comment = "测试HttpScope 模板使用")
|
@RestMapping(name = "t",auth = false, comment = "测试HttpScope 模板使用")
|
||||||
public HttpScope t(){
|
public HttpScope t(@RestSessionid String sessionid){
|
||||||
ContentService contentService = this;
|
ContentService contentService = this;
|
||||||
Flipper flipper = new Flipper().limit(30).sort("top DESC,createtime DESC");
|
Flipper flipper = new Flipper().limit(30).sort("top DESC,createtime DESC");
|
||||||
//置顶贴
|
//置顶贴
|
||||||
@@ -174,7 +177,7 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
|||||||
|
|
||||||
//热议
|
//热议
|
||||||
Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
|
Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
|
||||||
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", 0);
|
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", sessionid);
|
||||||
|
|
||||||
//最新加入
|
//最新加入
|
||||||
Sheet<UserInfo> lastReg = userService.lastReg();
|
Sheet<UserInfo> lastReg = userService.lastReg();
|
||||||
|
@@ -24,37 +24,40 @@ import static org.redkale.source.FilterExpress.NOTEQUAL;
|
|||||||
public class ContentServlet extends BaseServlet {
|
public class ContentServlet extends BaseServlet {
|
||||||
@HttpMapping(url = "/jie", auth = false, comment = "问答列表")
|
@HttpMapping(url = "/jie", auth = false, comment = "问答列表")
|
||||||
public void jie(HttpRequest request, HttpResponse response){
|
public void jie(HttpRequest request, HttpResponse response){
|
||||||
String actived = getPara(0, "all");
|
String actived = getPara(request, 0, "all");
|
||||||
int curr = request.getIntParameter("curr", 1);
|
int curr = request.getIntParameter("curr", 1);
|
||||||
|
|
||||||
//分页帖子列表
|
//分页帖子列表
|
||||||
Flipper flipper = new Flipper().offset((curr-1)*15).limit(15).sort("top DESC,createtime DESC");
|
Flipper flipper = new Flipper().offset((curr-1)*15).limit(15).sort("top DESC,createtime DESC");
|
||||||
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, actived, currentid);
|
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, actived, request.getSessionid(false));
|
||||||
|
|
||||||
Kv kv = Kv.by("contents", contents).set("url", request.getRequestURI())
|
Kv kv = Kv.by("contents", contents).set("url", request.getRequestURI())
|
||||||
.set("actived", actived).set("curr", curr);
|
.set("actived", actived).set("curr", curr);
|
||||||
finish("/jie/index.html", kv);
|
|
||||||
|
response.finish(HttpScope.refer("/jie/index.html").attr(kv));
|
||||||
}
|
}
|
||||||
|
|
||||||
@HttpMapping(url = "/jie/add", comment = "发表/编辑问答")
|
@HttpMapping(url = "/jie/add", comment = "发表/编辑问答")
|
||||||
@HttpParam(name = "#", type = int.class, comment = "内容ID")
|
@HttpParam(name = "#", type = int.class, comment = "内容ID")
|
||||||
public void add(HttpRequest request, HttpResponse response){
|
public void add(HttpRequest request, HttpResponse response){
|
||||||
int contentid = getParaToInt(0);
|
int contentid = getParaToInt(request, 0);
|
||||||
|
|
||||||
ContentInfo contentInfo = null;
|
ContentInfo contentInfo = null;
|
||||||
if (contentid > 0){
|
if (contentid > 0){
|
||||||
contentInfo = contentService.contentInfo(sessionid, contentid);
|
contentInfo = contentService.contentInfo(request.getSessionid(false), contentid);
|
||||||
}
|
}
|
||||||
|
|
||||||
finish("/jie/add.html", Kv.by("bean", contentInfo));
|
Kv kv = Kv.by("bean", contentInfo);
|
||||||
|
response.finish(HttpScope.refer("/jie/add.html").attr(kv));
|
||||||
}
|
}
|
||||||
|
|
||||||
@HttpMapping(url = "/jie/detail", auth = false, comment = "问答详情")
|
@HttpMapping(url = "/jie/detail", auth = false, comment = "问答详情")
|
||||||
public void detail(HttpRequest request, HttpResponse response){
|
public void detail(HttpRequest request, HttpResponse response){
|
||||||
int contentid = getParaToInt(0);
|
int contentid = getParaToInt(request,0);
|
||||||
|
String sessionid = request.getSessionid(false);
|
||||||
|
|
||||||
ContentInfo content = contentService.contentInfo(sessionid, contentid);
|
ContentInfo content = contentService.contentInfo(sessionid, contentid);
|
||||||
Sheet<CommentInfo> comments = commentService.commentQuery(request.getSessionid(false) ,contentid, new Flipper().limit(30));
|
Sheet<CommentInfo> comments = commentService.commentQuery(sessionid,contentid, new Flipper().limit(30));
|
||||||
|
|
||||||
//热帖
|
//热帖
|
||||||
//Flipper flipper2 = new Flipper().limit(8).sort("viewNum DESC");
|
//Flipper flipper2 = new Flipper().limit(8).sort("viewNum DESC");
|
||||||
@@ -62,7 +65,7 @@ public class ContentServlet extends BaseServlet {
|
|||||||
|
|
||||||
//热议
|
//热议
|
||||||
Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
|
Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
|
||||||
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", currentid);
|
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", sessionid);
|
||||||
|
|
||||||
//更新
|
//更新
|
||||||
CompletableFuture.supplyAsync(new Supplier<String>() {
|
CompletableFuture.supplyAsync(new Supplier<String>() {
|
||||||
@@ -76,12 +79,14 @@ public class ContentServlet extends BaseServlet {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Kv kv = Kv.by("bean", content).set("comments", comments)/*.set("hotView", hotView)*/.set("hotReply", hotReply);
|
Kv kv = Kv.by("bean", content).set("comments", comments)/*.set("hotView", hotView)*/.set("hotReply", hotReply);
|
||||||
finish("/jie/detail.html", kv);
|
response.finish(HttpScope.refer("/jie/detail.html").attr(kv));
|
||||||
}
|
}
|
||||||
|
|
||||||
@HttpMapping(url = "/column", auth = false, comment = "帖子栏目")
|
@HttpMapping(url = "/column", auth = false, comment = "帖子栏目")
|
||||||
public void column(HttpRequest request, HttpResponse response){
|
public void column(HttpRequest request, HttpResponse response){
|
||||||
String para = getPara();//空,qz,fx,jy,gg,dt,
|
String sessionid = request.getSessionid(false);
|
||||||
|
|
||||||
|
String para = getPara(request);//空,qz,fx,jy,gg,dt,
|
||||||
int solved = request.getIntParameter("solved", -1);
|
int solved = request.getIntParameter("solved", -1);
|
||||||
int wonderful = request.getIntParameter("wonderful", -1);
|
int wonderful = request.getIntParameter("wonderful", -1);
|
||||||
int curr = request.getIntParameter("curr", 1);
|
int curr = request.getIntParameter("curr", 1);
|
||||||
@@ -94,15 +99,16 @@ public class ContentServlet extends BaseServlet {
|
|||||||
if (solved > 0) filterNode.and("solved", 20);
|
if (solved > 0) filterNode.and("solved", 20);
|
||||||
if (wonderful > 0) filterNode.and("wonderful", 20);
|
if (wonderful > 0) filterNode.and("wonderful", 20);
|
||||||
|
|
||||||
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(filterNode));
|
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(request,filterNode));
|
||||||
|
|
||||||
//热议
|
//热议
|
||||||
Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
|
Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
|
||||||
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", currentid);
|
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", sessionid);
|
||||||
|
|
||||||
|
|
||||||
Kv kv = Kv.by("contents", contents).set("hotReply", hotReply)
|
Kv kv = Kv.by("contents", contents).set("hotReply", hotReply)
|
||||||
.set("solved", solved).set("wonderful", wonderful).set("column", para).set("curr", curr);
|
.set("solved", solved).set("wonderful", wonderful)
|
||||||
finish("/jie/index.html", kv);
|
.set("column", para).set("curr", curr);
|
||||||
|
response.finish(HttpScope.refer("/jie/index.html").attr(kv));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,10 +5,7 @@ import com.lxyer.bbs.base.BaseServlet;
|
|||||||
import com.lxyer.bbs.base.user.UserInfo;
|
import com.lxyer.bbs.base.user.UserInfo;
|
||||||
import com.lxyer.bbs.comment.CommentInfo;
|
import com.lxyer.bbs.comment.CommentInfo;
|
||||||
import com.lxyer.bbs.content.ContentInfo;
|
import com.lxyer.bbs.content.ContentInfo;
|
||||||
import org.redkale.net.http.HttpMapping;
|
import org.redkale.net.http.*;
|
||||||
import org.redkale.net.http.HttpRequest;
|
|
||||||
import org.redkale.net.http.HttpResponse;
|
|
||||||
import org.redkale.net.http.WebServlet;
|
|
||||||
import org.redkale.source.FilterNode;
|
import org.redkale.source.FilterNode;
|
||||||
import org.redkale.source.Flipper;
|
import org.redkale.source.Flipper;
|
||||||
import org.redkale.util.Sheet;
|
import org.redkale.util.Sheet;
|
||||||
@@ -27,14 +24,17 @@ public class IndexServlet extends BaseServlet {
|
|||||||
|
|
||||||
@HttpMapping(url = "/", auth = false, comment = "社区首页")
|
@HttpMapping(url = "/", auth = false, comment = "社区首页")
|
||||||
public void abc(HttpRequest request, HttpResponse response){
|
public void abc(HttpRequest request, HttpResponse response){
|
||||||
|
|
||||||
|
String sessionid = request.getSessionid(false);
|
||||||
|
|
||||||
Flipper flipper = new Flipper().limit(15).sort("top DESC,createtime DESC");
|
Flipper flipper = new Flipper().limit(15).sort("top DESC,createtime DESC");
|
||||||
//置顶贴
|
//置顶贴
|
||||||
FilterNode topNode = FilterNode.create("status", NOTEQUAL, -10).and("top", GREATERTHANOREQUALTO, 20);
|
FilterNode topNode = FilterNode.create("status", NOTEQUAL, -10).and("top", GREATERTHANOREQUALTO, 20);
|
||||||
Sheet<ContentInfo> top = contentService.contentQuery(flipper, setPrivate(topNode));
|
Sheet<ContentInfo> top = contentService.contentQuery(flipper, setPrivate(request, topNode));
|
||||||
|
|
||||||
//非置顶贴
|
//非置顶贴
|
||||||
FilterNode untopNode = FilterNode.create("status", NOTEQUAL, -10).and("top", 10);
|
FilterNode untopNode = FilterNode.create("status", NOTEQUAL, -10).and("top", 10);
|
||||||
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(untopNode));
|
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(request, untopNode));
|
||||||
|
|
||||||
//热帖
|
//热帖
|
||||||
/*Flipper flipper2 = new Flipper().limit(8).sort("viewNum DESC");
|
/*Flipper flipper2 = new Flipper().limit(8).sort("viewNum DESC");
|
||||||
@@ -42,7 +42,7 @@ public class IndexServlet extends BaseServlet {
|
|||||||
|
|
||||||
//热议
|
//热议
|
||||||
Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
|
Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
|
||||||
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", currentid);
|
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", sessionid);
|
||||||
|
|
||||||
//最新加入
|
//最新加入
|
||||||
Sheet<UserInfo> lastReg = userService.lastReg();
|
Sheet<UserInfo> lastReg = userService.lastReg();
|
||||||
@@ -51,13 +51,13 @@ public class IndexServlet extends BaseServlet {
|
|||||||
Number userCount = userService.userCount();
|
Number userCount = userService.userCount();
|
||||||
|
|
||||||
Kv kv = Kv.by("top", top).set("contents", contents).set("hotReply", hotReply).set("lastReg", lastReg).set("userCount", userCount);
|
Kv kv = Kv.by("top", top).set("contents", contents).set("hotReply", hotReply).set("lastReg", lastReg).set("userCount", userCount);
|
||||||
finish("index.html", kv);
|
response.finish(HttpScope.refer("index.html").attr(kv));
|
||||||
}
|
}
|
||||||
|
|
||||||
@HttpMapping(url = "/site", auth = false, comment = "网站首页")
|
@HttpMapping(url = "/site", auth = false, comment = "网站首页")
|
||||||
public void site(HttpRequest request, HttpResponse response){
|
public void site(HttpRequest request, HttpResponse response){
|
||||||
|
|
||||||
finish("/site.html");
|
response.finish(HttpScope.refer("/site.html"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//====================================文章相关====================================
|
//====================================文章相关====================================
|
||||||
@@ -70,12 +70,14 @@ public class IndexServlet extends BaseServlet {
|
|||||||
//====================================项目相关====================================
|
//====================================项目相关====================================
|
||||||
@HttpMapping(url = "/project", auth = false, comment = "项目首页")
|
@HttpMapping(url = "/project", auth = false, comment = "项目首页")
|
||||||
public void project(HttpRequest request, HttpResponse response){
|
public void project(HttpRequest request, HttpResponse response){
|
||||||
|
String sessionid = request.getSessionid(false);
|
||||||
int contentid = 22;
|
int contentid = 22;
|
||||||
|
|
||||||
ContentInfo content = contentService.contentInfo(sessionid, contentid);
|
ContentInfo content = contentService.contentInfo(sessionid, contentid);
|
||||||
Sheet<CommentInfo> comments = commentService.commentQuery(request.getSessionid(false) ,contentid, new Flipper().limit(30));
|
Sheet<CommentInfo> comments = commentService.commentQuery(sessionid,contentid, new Flipper().limit(30));
|
||||||
|
|
||||||
Kv kv = Kv.by("bean", content).set("comments", comments);
|
Kv kv = Kv.by("bean", content).set("comments", comments);
|
||||||
finish("project/index.html", kv);
|
response.finish(HttpScope.refer("/project/index.html").attr(kv));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -2,16 +2,14 @@ package com.lxyer.bbs.servlet;
|
|||||||
|
|
||||||
import com.jfinal.kit.Kv;
|
import com.jfinal.kit.Kv;
|
||||||
import com.lxyer.bbs.base.BaseServlet;
|
import com.lxyer.bbs.base.BaseServlet;
|
||||||
import com.lxyer.bbs.base.user.UserRecord;
|
|
||||||
import com.lxyer.bbs.base.user.UserBean;
|
import com.lxyer.bbs.base.user.UserBean;
|
||||||
import com.lxyer.bbs.base.user.UserInfo;
|
import com.lxyer.bbs.base.user.UserInfo;
|
||||||
|
import com.lxyer.bbs.base.user.UserRecord;
|
||||||
import com.lxyer.bbs.comment.CommentInfo;
|
import com.lxyer.bbs.comment.CommentInfo;
|
||||||
import com.lxyer.bbs.content.ContentBean;
|
|
||||||
import com.lxyer.bbs.content.ContentInfo;
|
import com.lxyer.bbs.content.ContentInfo;
|
||||||
import org.redkale.net.http.HttpMapping;
|
import org.redkale.net.http.*;
|
||||||
import org.redkale.net.http.HttpRequest;
|
import org.redkale.source.FilterExpress;
|
||||||
import org.redkale.net.http.HttpResponse;
|
import org.redkale.source.FilterNode;
|
||||||
import org.redkale.net.http.WebServlet;
|
|
||||||
import org.redkale.source.Flipper;
|
import org.redkale.source.Flipper;
|
||||||
import org.redkale.util.Sheet;
|
import org.redkale.util.Sheet;
|
||||||
|
|
||||||
@@ -26,7 +24,7 @@ public class UserServlet extends BaseServlet {
|
|||||||
@HttpMapping(url = "/user/login", auth = false, comment = "前往登录页")
|
@HttpMapping(url = "/user/login", auth = false, comment = "前往登录页")
|
||||||
public void login(HttpRequest request, HttpResponse response){
|
public void login(HttpRequest request, HttpResponse response){
|
||||||
|
|
||||||
finish("/user/login.html");
|
response.finish(HttpScope.refer("/user/login.html"));
|
||||||
}
|
}
|
||||||
@HttpMapping(url = "/user/reg", auth = false, comment = "前往登录页")
|
@HttpMapping(url = "/user/reg", auth = false, comment = "前往登录页")
|
||||||
public void reg(HttpRequest request, HttpResponse response){
|
public void reg(HttpRequest request, HttpResponse response){
|
||||||
@@ -36,39 +34,38 @@ public class UserServlet extends BaseServlet {
|
|||||||
list.add(Kv.by("k", 3).set("a", "3+2-5=?").set("q", 0));
|
list.add(Kv.by("k", 3).set("a", "3+2-5=?").set("q", 0));
|
||||||
list.add(Kv.by("k", 4).set("a", "Math.abs(-3)=?").set("q", 3));*/
|
list.add(Kv.by("k", 4).set("a", "Math.abs(-3)=?").set("q", 3));*/
|
||||||
|
|
||||||
finish("/user/login.html");
|
response.finish(HttpScope.refer("/user/login.html"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@HttpMapping(url = "/user/set", auth = true, comment = "用户设置")
|
@HttpMapping(url = "/user/set", auth = true, comment = "用户设置")
|
||||||
public void set(HttpRequest request, HttpResponse response){
|
public void set(HttpRequest request, HttpResponse response){
|
||||||
finish("/user/set.html");
|
response.finish(HttpScope.refer("/user/set.html"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@HttpMapping(url = "/user", auth = false, comment = "用户首页")
|
@HttpMapping(url = "/user", auth = false, comment = "用户首页")
|
||||||
public void user(HttpRequest request, HttpResponse response){
|
public void user(HttpRequest request, HttpResponse response){
|
||||||
String para = getPara();
|
String para = getPara(request);
|
||||||
|
|
||||||
//-------个人中心---------
|
//-------个人中心---------
|
||||||
if ("user".equals(para) || "".equals(para)){
|
if ("user".equals(para) || "".equals(para)){
|
||||||
UserInfo user = request.currentUser();
|
UserInfo user = request.currentUser();
|
||||||
if (user == null){
|
if (user == null){
|
||||||
finish("/user/login.html");
|
response.finish(HttpScope.refer("/user/login.html"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//创建的帖子
|
//创建的帖子
|
||||||
Flipper flipper = new Flipper().limit(8).sort("createtime DESC");
|
Flipper flipper = new Flipper().limit(8).sort("createtime DESC");
|
||||||
ContentBean bean = new ContentBean();
|
|
||||||
bean.setUserid(user.getUserid());
|
FilterNode node = FilterNode.create("userid", user.getUserid()).and("status", FilterExpress.NOTEQUAL, -10);
|
||||||
Sheet<ContentInfo> contents = contentService.queryByBean(flipper, bean);
|
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(request, node));//queryByBean(flipper, bean);
|
||||||
|
|
||||||
//收藏的帖子
|
//收藏的帖子
|
||||||
Sheet<ContentInfo> collects = contentService.collectQuery(sessionid);
|
Sheet<ContentInfo> collects = contentService.collectQuery(request.getSessionid(false));
|
||||||
|
|
||||||
Kv kv = Kv.by("contents", contents).set("collects", collects);
|
Kv kv = Kv.by("contents", contents).set("collects", collects);
|
||||||
finish("/user/index.html", kv);
|
response.finish(HttpScope.refer("/user/index.html").attr(kv));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------用户主页------
|
//-------用户主页------
|
||||||
@@ -82,7 +79,7 @@ public class UserServlet extends BaseServlet {
|
|||||||
userid = users.stream().findFirst().orElse(null).getUserid();
|
userid = users.stream().findFirst().orElse(null).getUserid();
|
||||||
}
|
}
|
||||||
}else {//直接访问
|
}else {//直接访问
|
||||||
userid = getParaToInt(0);
|
userid = getParaToInt(request,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//用户信息
|
//用户信息
|
||||||
@@ -90,14 +87,13 @@ public class UserServlet extends BaseServlet {
|
|||||||
|
|
||||||
//帖子
|
//帖子
|
||||||
Flipper flipper = new Flipper().limit(8).sort("createtime DESC");
|
Flipper flipper = new Flipper().limit(8).sort("createtime DESC");
|
||||||
ContentBean bean = new ContentBean();
|
FilterNode node = FilterNode.create("userid", userid).and("status", FilterExpress.NOTEQUAL, -10);
|
||||||
bean.setUserid(userid);
|
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(request,node));
|
||||||
Sheet<ContentInfo> contents = contentService.queryByBean(flipper, bean);
|
|
||||||
|
|
||||||
//回复
|
//回复
|
||||||
Sheet<CommentInfo> comments = commentService.queryByUserid(userid);
|
Sheet<CommentInfo> comments = commentService.queryByUserid(userid);
|
||||||
|
|
||||||
Kv kv = Kv.by("contents", contents).set("user", user).set("comments", comments);
|
Kv kv = Kv.by("contents", contents).set("user", user).set("comments", comments);
|
||||||
finish("/user/home.html", kv);
|
response.finish(HttpScope.refer("/user/home.html").attr(kv));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user