整理代码结构
This commit is contained in:
parent
7e2f99675b
commit
08ef1781dd
@ -1,7 +1,10 @@
|
|||||||
package com.lxyer.bbs.base;
|
package com.lxyer.bbs.base;
|
||||||
|
|
||||||
|
import com.lxyer.bbs.base.user.UserInfo;
|
||||||
import org.redkale.service.Service;
|
import org.redkale.service.Service;
|
||||||
|
import org.redkale.source.CacheSource;
|
||||||
import org.redkale.source.DataSource;
|
import org.redkale.source.DataSource;
|
||||||
|
import org.redkalex.cache.RedisCacheSource;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -19,6 +22,12 @@ public class BaseService implements Service {
|
|||||||
@Resource(name = "art123")
|
@Resource(name = "art123")
|
||||||
protected DataSource source;
|
protected DataSource source;
|
||||||
|
|
||||||
|
@Resource(name = "redis")
|
||||||
|
protected RedisCacheSource<Integer> sessions;
|
||||||
|
|
||||||
|
@Resource(name = "userInfos")
|
||||||
|
protected CacheSource<UserInfo> userInfos;
|
||||||
|
|
||||||
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,12 @@ package com.lxyer.bbs.base;
|
|||||||
import com.jfinal.kit.Kv;
|
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.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.content.ContentService;
|
||||||
import org.redkale.net.http.HttpContext;
|
import org.redkale.net.http.HttpContext;
|
||||||
import org.redkale.net.http.HttpRequest;
|
import org.redkale.net.http.HttpRequest;
|
||||||
import org.redkale.net.http.HttpResponse;
|
import org.redkale.net.http.HttpResponse;
|
||||||
@ -17,12 +21,20 @@ import javax.annotation.Resource;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static com.lxyer.bbs.base.RetCodes.RET_USER_UNLOGIN;
|
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");
|
||||||
|
|
||||||
@Resource(name = "SERVER_ROOT")
|
@Resource(name = "SERVER_ROOT")
|
||||||
protected File webroot;
|
protected File webroot;
|
||||||
@ -35,11 +47,12 @@ public class BaseServlet extends HttpServlet {
|
|||||||
/*@Resource(name = "redis")
|
/*@Resource(name = "redis")
|
||||||
protected RedisCacheSource<String> cache;*/
|
protected RedisCacheSource<String> cache;*/
|
||||||
|
|
||||||
private HttpRequest request;
|
@Resource
|
||||||
private HttpResponse response;
|
protected ContentService contentService;
|
||||||
private static final Kv _kv = Kv.create();
|
|
||||||
private static Engine engine;
|
@Resource
|
||||||
protected String sessionid;
|
protected CommentService commentService;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(HttpContext context, AnyValue config) {
|
public void init(HttpContext context, AnyValue config) {
|
||||||
@ -56,6 +69,7 @@ public class BaseServlet extends HttpServlet {
|
|||||||
sessionid = request.getSessionid(false);
|
sessionid = request.getSessionid(false);
|
||||||
if (sessionid != null) {
|
if (sessionid != null) {
|
||||||
request.setCurrentUser(userService.current(sessionid));
|
request.setCurrentUser(userService.current(sessionid));
|
||||||
|
currentId = userService.currentUserId(sessionid);
|
||||||
_kv.set("mine", request.currentUser());
|
_kv.set("mine", request.currentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,8 +185,4 @@ public class BaseServlet extends HttpServlet {
|
|||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
protected int currentId(){
|
|
||||||
UserInfo userInfo = request.currentUser();
|
|
||||||
return userInfo == null ? 0 : userInfo.getUserId();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.lxyer.bbs.base;
|
|||||||
|
|
||||||
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 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;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.lxyer.bbs.base;
|
package com.lxyer.bbs.base.kit;
|
||||||
|
|
||||||
import org.redkale.net.http.RestService;
|
import org.redkale.net.http.RestService;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.lxyer.bbs.base;
|
package com.lxyer.bbs.base.kit;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
@ -1,4 +1,4 @@
|
|||||||
package com.lxyer.bbs.base;
|
package com.lxyer.bbs.base.kit;
|
||||||
|
|
||||||
import org.redkale.service.RetLabel;
|
import org.redkale.service.RetLabel;
|
||||||
import org.redkale.service.RetResult;
|
import org.redkale.service.RetResult;
|
@ -1,8 +1,8 @@
|
|||||||
package com.lxyer.bbs.base.user;
|
package com.lxyer.bbs.base.user;
|
||||||
|
|
||||||
import com.lxyer.bbs.base.BaseService;
|
import com.lxyer.bbs.base.BaseService;
|
||||||
import com.lxyer.bbs.base.LxyKit;
|
import com.lxyer.bbs.base.kit.LxyKit;
|
||||||
import com.lxyer.bbs.base.RetCodes;
|
import com.lxyer.bbs.base.kit.RetCodes;
|
||||||
import org.redkale.net.http.RestMapping;
|
import org.redkale.net.http.RestMapping;
|
||||||
import org.redkale.net.http.RestParam;
|
import org.redkale.net.http.RestParam;
|
||||||
import org.redkale.net.http.RestService;
|
import org.redkale.net.http.RestService;
|
||||||
@ -11,14 +11,12 @@ import org.redkale.service.RetResult;
|
|||||||
import org.redkale.source.*;
|
import org.redkale.source.*;
|
||||||
import org.redkale.util.SelectColumn;
|
import org.redkale.util.SelectColumn;
|
||||||
import org.redkale.util.Sheet;
|
import org.redkale.util.Sheet;
|
||||||
import org.redkalex.cache.RedisCacheSource;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static com.lxyer.bbs.base.RetCodes.*;
|
import static com.lxyer.bbs.base.kit.RetCodes.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Lxy at 2017/10/3 14:02.
|
* Created by Lxy at 2017/10/3 14:02.
|
||||||
@ -26,12 +24,6 @@ import static com.lxyer.bbs.base.RetCodes.*;
|
|||||||
@RestService(automapping = true, comment = "用户服务")
|
@RestService(automapping = true, comment = "用户服务")
|
||||||
public class UserService extends BaseService {
|
public class UserService extends BaseService {
|
||||||
|
|
||||||
@Resource(name = "redis")
|
|
||||||
protected RedisCacheSource<Integer> sessions;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
protected CacheSource<UserInfo> userInfos;
|
|
||||||
|
|
||||||
@RestMapping(auth = false, comment = "登录校验")
|
@RestMapping(auth = false, comment = "登录校验")
|
||||||
public RetResult<UserInfo> login(@RestParam(name = "bean") LoginBean loginBean){
|
public RetResult<UserInfo> login(@RestParam(name = "bean") LoginBean loginBean){
|
||||||
if (loginBean == null || loginBean.emptyUsername()) return RetCodes.retResult(RetCodes.RET_PARAMS_ILLEGAL, "参数错误");
|
if (loginBean == null || loginBean.emptyUsername()) return RetCodes.retResult(RetCodes.RET_PARAMS_ILLEGAL, "参数错误");
|
||||||
@ -47,7 +39,7 @@ public class UserService extends BaseService {
|
|||||||
//log(user, 0, "用户登录成功.");
|
//log(user, 0, "用户登录成功.");
|
||||||
UserInfo userInfo = user.createUserInfo();
|
UserInfo userInfo = user.createUserInfo();
|
||||||
|
|
||||||
this.sessions.setAsync(sessionExpireSeconds, loginBean.getSessionid(), userInfo.getUserId());
|
sessions.setAsync(sessionExpireSeconds, loginBean.getSessionid(), userInfo.getUserId());
|
||||||
retResult.setRetcode(0);
|
retResult.setRetcode(0);
|
||||||
retResult.setResult(userInfo);
|
retResult.setResult(userInfo);
|
||||||
retResult.setRetinfo("登录成功.");
|
retResult.setRetinfo("登录成功.");
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.lxyer.bbs.comment;
|
package com.lxyer.bbs.comment;
|
||||||
|
|
||||||
import com.lxyer.bbs.base.LxyKit;
|
import com.lxyer.bbs.base.kit.LxyKit;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.lxyer.bbs.comment;
|
package com.lxyer.bbs.comment;
|
||||||
|
|
||||||
import com.lxyer.bbs.base.BaseService;
|
import com.lxyer.bbs.base.BaseService;
|
||||||
import com.lxyer.bbs.base.LxyKit;
|
import com.lxyer.bbs.base.kit.LxyKit;
|
||||||
import com.lxyer.bbs.base.RetCodes;
|
import com.lxyer.bbs.base.kit.RetCodes;
|
||||||
import com.lxyer.bbs.base.entity.ActLog;
|
import com.lxyer.bbs.base.entity.ActLog;
|
||||||
import com.lxyer.bbs.base.user.User;
|
import com.lxyer.bbs.base.user.User;
|
||||||
import com.lxyer.bbs.base.user.UserService;
|
import com.lxyer.bbs.base.user.UserService;
|
||||||
@ -21,8 +21,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.lxyer.bbs.base.RetCodes.RET_COMMENT_CONTENT_ILLEGAL;
|
import static com.lxyer.bbs.base.kit.RetCodes.RET_COMMENT_CONTENT_ILLEGAL;
|
||||||
import static com.lxyer.bbs.base.RetCodes.RET_COMMENT_PARA_ILLEGAL;
|
import static com.lxyer.bbs.base.kit.RetCodes.RET_COMMENT_PARA_ILLEGAL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Lxy at 2017/11/29 10:00.
|
* Created by Lxy at 2017/11/29 10:00.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.lxyer.bbs.content;
|
package com.lxyer.bbs.content;
|
||||||
|
|
||||||
import com.jfinal.kit.Kv;
|
import com.jfinal.kit.Kv;
|
||||||
import com.lxyer.bbs.base.LxyKit;
|
import com.lxyer.bbs.base.kit.LxyKit;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
@ -2,8 +2,8 @@ package com.lxyer.bbs.content;
|
|||||||
|
|
||||||
import com.jfinal.kit.Kv;
|
import com.jfinal.kit.Kv;
|
||||||
import com.lxyer.bbs.base.BaseService;
|
import com.lxyer.bbs.base.BaseService;
|
||||||
import com.lxyer.bbs.base.LxyKit;
|
import com.lxyer.bbs.base.kit.LxyKit;
|
||||||
import com.lxyer.bbs.base.RetCodes;
|
import com.lxyer.bbs.base.kit.RetCodes;
|
||||||
import com.lxyer.bbs.base.entity.ActLog;
|
import com.lxyer.bbs.base.entity.ActLog;
|
||||||
import com.lxyer.bbs.base.user.User;
|
import com.lxyer.bbs.base.user.User;
|
||||||
import com.lxyer.bbs.base.user.UserInfo;
|
import com.lxyer.bbs.base.user.UserInfo;
|
||||||
|
108
src/com/lxyer/bbs/servlet/ContentServlet.java
Normal file
108
src/com/lxyer/bbs/servlet/ContentServlet.java
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
package com.lxyer.bbs.servlet;
|
||||||
|
|
||||||
|
import com.jfinal.kit.Kv;
|
||||||
|
import com.lxyer.bbs.base.BaseServlet;
|
||||||
|
import com.lxyer.bbs.base.user.User;
|
||||||
|
import com.lxyer.bbs.comment.CommentInfo;
|
||||||
|
import com.lxyer.bbs.content.ContentInfo;
|
||||||
|
import org.redkale.net.http.*;
|
||||||
|
import org.redkale.source.FilterNode;
|
||||||
|
import org.redkale.source.Flipper;
|
||||||
|
import org.redkale.util.Sheet;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import static org.redkale.source.FilterExpress.NOTEQUAL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 帖子相关
|
||||||
|
* Created by liangxianyou at 2018/6/4 13:15.
|
||||||
|
*/
|
||||||
|
@WebServlet({"/jie" ,"/jie/*"
|
||||||
|
,"/column","/column/*"})
|
||||||
|
public class ContentServlet extends BaseServlet {
|
||||||
|
@HttpMapping(url = "/jie", auth = false, comment = "问答列表")
|
||||||
|
public void jie(HttpRequest request, HttpResponse response){
|
||||||
|
String actived = getPara(0, "all");
|
||||||
|
int curr = request.getIntParameter("curr", 1);
|
||||||
|
|
||||||
|
//分页帖子列表
|
||||||
|
Flipper flipper = new Flipper().offset((curr-1)*15).limit(15).sort("top DESC,createTime DESC");
|
||||||
|
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, actived, currentId);
|
||||||
|
|
||||||
|
Kv kv = Kv.by("contents", contents).set("url", request.getRequestURI())
|
||||||
|
.set("actived", actived).set("curr", curr);
|
||||||
|
finish("/jie/index.html", kv);
|
||||||
|
}
|
||||||
|
|
||||||
|
@HttpMapping(url = "/jie/add", comment = "发表/编辑问答")
|
||||||
|
@HttpParam(name = "#", type = int.class, comment = "内容ID")
|
||||||
|
public void add(HttpRequest request, HttpResponse response){
|
||||||
|
int contentid = getParaToInt(0);
|
||||||
|
|
||||||
|
ContentInfo contentInfo = null;
|
||||||
|
if (contentid > 0){
|
||||||
|
contentInfo = contentService.contentInfo(sessionid, contentid);
|
||||||
|
}
|
||||||
|
|
||||||
|
finish("/jie/add.html", Kv.by("bean", contentInfo));
|
||||||
|
}
|
||||||
|
|
||||||
|
@HttpMapping(url = "/jie/detail", auth = false, comment = "问答详情")
|
||||||
|
public void detail(HttpRequest request, HttpResponse response){
|
||||||
|
int contentid = getParaToInt(0);
|
||||||
|
|
||||||
|
ContentInfo content = contentService.contentInfo(sessionid, contentid);
|
||||||
|
Sheet<CommentInfo> comments = commentService.commentQuery(request.getSessionid(false) ,contentid, new Flipper().limit(30));
|
||||||
|
|
||||||
|
//热帖
|
||||||
|
//Flipper flipper2 = new Flipper().limit(8).sort("viewNum DESC");
|
||||||
|
//Sheet<ContentInfo> hotView = contentService.contentQuery(flipper2, "");
|
||||||
|
|
||||||
|
//热议
|
||||||
|
Flipper flipper3 = new Flipper().limit(8).sort("replyNum DESC");
|
||||||
|
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", currentId);
|
||||||
|
|
||||||
|
//更新
|
||||||
|
CompletableFuture.supplyAsync(new Supplier<String>() {
|
||||||
|
@Override
|
||||||
|
public String get() {
|
||||||
|
User user = request.currentUser();
|
||||||
|
if (user == null || user.getUserId() > 10_0003)
|
||||||
|
contentService.incrViewNum(contentid);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Kv kv = Kv.by("bean", content).set("comments", comments)/*.set("hotView", hotView)*/.set("hotReply", hotReply);
|
||||||
|
finish("/jie/detail.html", kv);
|
||||||
|
}
|
||||||
|
|
||||||
|
@HttpMapping(url = "/column", auth = false, comment = "帖子栏目")
|
||||||
|
public void column(HttpRequest request, HttpResponse response){
|
||||||
|
String para = getPara();//空,qz,fx,jy,gg,dt,
|
||||||
|
int solved = request.getIntParameter("solved", -1);
|
||||||
|
int wonderful = request.getIntParameter("wonderful", -1);
|
||||||
|
int curr = request.getIntParameter("curr", 1);
|
||||||
|
|
||||||
|
Kv column = Kv.by("qz", 10).set("fx", 20).set("jy", 30).set("gg", 40).set("dt", 50);//栏目
|
||||||
|
|
||||||
|
Flipper flipper = new Flipper().offset((curr-1) * 20).limit(20).sort("top DESC,createTime DESC");
|
||||||
|
//帖子列表
|
||||||
|
FilterNode filterNode = FilterNode.create("status", NOTEQUAL, -1).and("type", column.getAs(para));
|
||||||
|
if (solved > -1) filterNode.and("solved", solved);
|
||||||
|
if (wonderful > -1) filterNode.and("wonderful", wonderful);
|
||||||
|
|
||||||
|
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(filterNode));
|
||||||
|
|
||||||
|
//热议
|
||||||
|
Flipper flipper3 = new Flipper().limit(8).sort("replyNum DESC");
|
||||||
|
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", currentId);
|
||||||
|
|
||||||
|
|
||||||
|
Kv kv = Kv.by("contents", contents).set("hotReply", hotReply)
|
||||||
|
.set("solved", solved).set("wonderful", wonderful).set("column", para).set("curr", curr);
|
||||||
|
finish("/jie/index.html", kv);
|
||||||
|
}
|
||||||
|
}
|
51
src/com/lxyer/bbs/servlet/FileServlet.java
Normal file
51
src/com/lxyer/bbs/servlet/FileServlet.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package com.lxyer.bbs.servlet;
|
||||||
|
|
||||||
|
import com.lxyer.bbs.base.BaseServlet;
|
||||||
|
import org.redkale.net.http.*;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件相关
|
||||||
|
* Created by liangxianyou at 2018/6/4 13:17.
|
||||||
|
*/
|
||||||
|
@WebServlet({"/upload","/upload/*"})
|
||||||
|
public class FileServlet extends BaseServlet {
|
||||||
|
|
||||||
|
private static final String dir = "/var/www/upload/redbbs/";
|
||||||
|
private static final String view = "http://img.1216.top/redbbs/";
|
||||||
|
private static final String format = "%1$tY%1$tm%1$td%1$tH%1$tM%1$tS";
|
||||||
|
|
||||||
|
@HttpMapping(url = "/upload/img", auth = false, comment = "图片上传")
|
||||||
|
public void uploadImg(HttpRequest request, HttpResponse response){
|
||||||
|
try {
|
||||||
|
Map ret = new HashMap();
|
||||||
|
ret.put("errno", 0);
|
||||||
|
List data = new ArrayList();
|
||||||
|
|
||||||
|
for (MultiPart part : request.multiParts()) {
|
||||||
|
String name = part.getName();
|
||||||
|
String suffix = name.substring(name.lastIndexOf("."));
|
||||||
|
String path = String.format(format, System.currentTimeMillis()) + suffix;
|
||||||
|
File destFile = new File((winos ? "D:/wk/_own/redbbs/root/tem/" : dir) + path);
|
||||||
|
destFile.getParentFile().mkdir();
|
||||||
|
|
||||||
|
part.save(destFile);
|
||||||
|
|
||||||
|
data.add((winos ? "/tem/": view) + path);
|
||||||
|
}
|
||||||
|
ret.put("data", data);
|
||||||
|
|
||||||
|
response.setContentType("application/json; charset=utf-8");
|
||||||
|
response.finish(ret);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -2,55 +2,37 @@ 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.User;
|
|
||||||
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.comment.CommentInfo;
|
|
||||||
import com.lxyer.bbs.comment.CommentService;
|
|
||||||
import com.lxyer.bbs.content.ContentBean;
|
|
||||||
import com.lxyer.bbs.content.ContentInfo;
|
import com.lxyer.bbs.content.ContentInfo;
|
||||||
import com.lxyer.bbs.content.ContentService;
|
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.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;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import static org.redkale.source.FilterExpress.GREATERTHAN;
|
||||||
import java.io.File;
|
import static org.redkale.source.FilterExpress.NOTEQUAL;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Lxy at 2017/11/25 12:31.
|
* Created by Lxy at 2017/11/25 12:31.
|
||||||
*/
|
*/
|
||||||
@WebServlet({"/","/column","/column/*"
|
@WebServlet({"/"
|
||||||
,"/user", "/user/*"
|
/* ,"/article","/article/*" */
|
||||||
,"/jie" ,"/jie/*"
|
|
||||||
,"/upload","/upload/*"
|
|
||||||
})
|
})
|
||||||
public class IndexServlet extends BaseServlet {
|
public class IndexServlet extends BaseServlet {
|
||||||
|
|
||||||
@Resource
|
|
||||||
private ContentService contentService;
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private CommentService commentService;
|
|
||||||
|
|
||||||
@HttpMapping(url = "/", auth = false, comment = "社区首页")
|
@HttpMapping(url = "/", auth = false, comment = "社区首页")
|
||||||
public void abc(HttpRequest request, HttpResponse response){
|
public void abc(HttpRequest request, HttpResponse response){
|
||||||
Flipper flipper = new Flipper().limit(30).sort("top DESC,createTime DESC");
|
Flipper flipper = new Flipper().limit(30).sort("top DESC,createTime DESC");
|
||||||
//置顶贴
|
//置顶贴
|
||||||
FilterNode topNode = FilterNode.create("status", FilterExpress.NOTEQUAL, -1).and("top", FilterExpress.GREATERTHAN, 0);
|
FilterNode topNode = FilterNode.create("status", NOTEQUAL, -1).and("top", GREATERTHAN, 0);
|
||||||
Sheet<ContentInfo> top = contentService.contentQuery(flipper, setPrivate(topNode));
|
Sheet<ContentInfo> top = contentService.contentQuery(flipper, setPrivate(topNode));
|
||||||
|
|
||||||
//非置顶贴
|
//非置顶贴
|
||||||
FilterNode untopNode = FilterNode.create("status", FilterExpress.NOTEQUAL, -1).and("top", 0);
|
FilterNode untopNode = FilterNode.create("status", NOTEQUAL, -1).and("top", 0);
|
||||||
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(untopNode));
|
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(untopNode));
|
||||||
|
|
||||||
//热帖
|
//热帖
|
||||||
@ -59,7 +41,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, "", currentId);
|
||||||
|
|
||||||
//最新加入
|
//最新加入
|
||||||
Sheet<UserInfo> lastReg = userService.lastReg();
|
Sheet<UserInfo> lastReg = userService.lastReg();
|
||||||
@ -71,215 +53,16 @@ public class IndexServlet extends BaseServlet {
|
|||||||
finish("index.html", kv);
|
finish("index.html", kv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@HttpMapping(url = "/column", auth = false, comment = "社区首页")
|
|
||||||
public void column(HttpRequest request, HttpResponse response){
|
|
||||||
String para = getPara();//空,qz,fx,jy,gg,dt,
|
|
||||||
int solved = request.getIntParameter("solved", -1);
|
|
||||||
int wonderful = request.getIntParameter("wonderful", -1);
|
|
||||||
int curr = request.getIntParameter("curr", 1);
|
|
||||||
|
|
||||||
Kv column = Kv.by("qz", 10).set("fx", 20).set("jy", 30).set("gg", 40).set("dt", 50);//栏目
|
|
||||||
|
|
||||||
Flipper flipper = new Flipper().offset((curr-1) * 20).limit(20).sort("top DESC,createTime DESC");
|
|
||||||
//帖子列表
|
|
||||||
FilterNode filterNode = FilterNode.create("status", FilterExpress.NOTEQUAL, -1).and("type", column.getAs(para));
|
|
||||||
if (solved > -1) filterNode.and("solved", solved);
|
|
||||||
if (wonderful > -1) filterNode.and("wonderful", wonderful);
|
|
||||||
|
|
||||||
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(filterNode));
|
|
||||||
|
|
||||||
//热议
|
|
||||||
Flipper flipper3 = new Flipper().limit(8).sort("replyNum DESC");
|
|
||||||
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", currentId());
|
|
||||||
|
|
||||||
|
|
||||||
Kv kv = Kv.by("contents", contents).set("hotReply", hotReply)
|
|
||||||
.set("solved", solved).set("wonderful", wonderful).set("column", para).set("curr", curr);
|
|
||||||
finish("/jie/index.html", 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");
|
finish("/site.html");
|
||||||
}
|
}
|
||||||
|
|
||||||
//====================================用户相关====================================
|
//====================================文章相关====================================
|
||||||
|
/*@HttpMapping(url = "/article", auth = false, comment = "文章首页")
|
||||||
@HttpMapping(url = "/user/login", auth = false, comment = "前往登录页")
|
public void article(HttpRequest request, HttpResponse response){
|
||||||
public void login(HttpRequest request, HttpResponse response){
|
|
||||||
|
|
||||||
finish("/user/login.html");
|
|
||||||
}
|
|
||||||
@HttpMapping(url = "/user/reg", auth = false, comment = "前往登录页")
|
|
||||||
public void reg(HttpRequest request, HttpResponse response){
|
|
||||||
/*List<Kv> list = new ArrayList<>();
|
|
||||||
list.add(Kv.by("k", 1).set("a", "1+1=?").set("q", 2));
|
|
||||||
list.add(Kv.by("k", 2).set("a", "1*1=?").set("q", 1));
|
|
||||||
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));*/
|
|
||||||
|
|
||||||
finish("/user/login.html");
|
|
||||||
}
|
|
||||||
|
|
||||||
@HttpMapping(url = "/user/set", auth = true, comment = "用户设置")
|
|
||||||
public void set(HttpRequest request, HttpResponse response){
|
|
||||||
finish("/user/set.html");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@HttpMapping(url = "/user", auth = false, comment = "用户首页")
|
|
||||||
public void user(HttpRequest request, HttpResponse response){
|
|
||||||
String para = getPara();
|
|
||||||
|
|
||||||
//-------个人中心---------
|
|
||||||
if ("user".equals(para) || "".equals(para)){
|
|
||||||
UserInfo user = request.currentUser();
|
|
||||||
if (user == null){
|
|
||||||
finish("/user/login.html");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//创建的帖子
|
|
||||||
Flipper flipper = new Flipper().limit(8).sort("createTime DESC");
|
|
||||||
ContentBean bean = new ContentBean();
|
|
||||||
bean.setUserId(user.getUserId());
|
|
||||||
Sheet<ContentInfo> contents = contentService.queryByBean(flipper, bean);
|
|
||||||
|
|
||||||
//收藏的帖子
|
|
||||||
Sheet<ContentInfo> collects = contentService.collectQuery(sessionid);
|
|
||||||
|
|
||||||
Kv kv = Kv.by("contents", contents).set("collects", collects);
|
|
||||||
finish("/user/index.html", kv);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------用户主页------
|
|
||||||
int userId = 0;
|
|
||||||
if ("nick".equals(para)){//通过@ 点击跳转
|
|
||||||
String nickname = request.getParameter("nickname");
|
|
||||||
UserBean userBean = new UserBean();
|
|
||||||
userBean.setNickname(nickname);
|
|
||||||
Sheet<User> users = userService.queryUser(new Flipper().limit(1), userBean);
|
|
||||||
if (users.getTotal() > 0){
|
|
||||||
userId = users.stream().findFirst().orElse(null).getUserId();
|
|
||||||
}
|
|
||||||
}else {//直接访问
|
|
||||||
userId = getParaToInt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//用户信息
|
|
||||||
UserInfo user = userService.findUserInfo(userId);
|
|
||||||
|
|
||||||
//帖子
|
|
||||||
Flipper flipper = new Flipper().limit(8).sort("createTime DESC");
|
|
||||||
ContentBean bean = new ContentBean();
|
|
||||||
bean.setUserId(userId);
|
|
||||||
Sheet<ContentInfo> contents = contentService.queryByBean(flipper, bean);
|
|
||||||
|
|
||||||
//回复
|
|
||||||
Sheet<CommentInfo> comments = commentService.queryByUserid(userId);
|
|
||||||
|
|
||||||
Kv kv = Kv.by("contents", contents).set("user", user).set("comments", comments);
|
|
||||||
finish("/user/home.html", kv);
|
|
||||||
}
|
|
||||||
|
|
||||||
//====================================帖子相关====================================
|
|
||||||
|
|
||||||
|
|
||||||
@HttpMapping(url = "/jie", auth = false, comment = "问答列表")
|
|
||||||
public void jie(HttpRequest request, HttpResponse response){
|
|
||||||
String actived = getPara(0, "all");
|
|
||||||
int curr = request.getIntParameter("curr", 1);
|
|
||||||
|
|
||||||
//分页帖子列表
|
|
||||||
Flipper flipper = new Flipper().offset((curr-1)*15).limit(15).sort("top DESC,createTime DESC");
|
|
||||||
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, actived, currentId());
|
|
||||||
|
|
||||||
Kv kv = Kv.by("contents", contents).set("url", request.getRequestURI())
|
|
||||||
.set("actived", actived).set("curr", curr);
|
|
||||||
finish("/jie/index.html", kv);
|
|
||||||
}
|
|
||||||
|
|
||||||
@HttpMapping(url = "/jie/add", comment = "发表/编辑问答")
|
|
||||||
@HttpParam(name = "#", type = int.class, comment = "内容ID")
|
|
||||||
public void add(HttpRequest request, HttpResponse response){
|
|
||||||
int contentid = getParaToInt(0);
|
|
||||||
|
|
||||||
ContentInfo contentInfo = null;
|
|
||||||
if (contentid > 0){
|
|
||||||
contentInfo = contentService.contentInfo(sessionid, contentid);
|
|
||||||
}
|
|
||||||
|
|
||||||
finish("/jie/add.html", Kv.by("bean", contentInfo));
|
|
||||||
}
|
|
||||||
|
|
||||||
@HttpMapping(url = "/jie/detail", auth = false, comment = "问答详情")
|
|
||||||
public void detail(HttpRequest request, HttpResponse response){
|
|
||||||
int contentid = getParaToInt(0);
|
|
||||||
|
|
||||||
ContentInfo content = contentService.contentInfo(sessionid, contentid);
|
|
||||||
Sheet<CommentInfo> comments = commentService.commentQuery(request.getSessionid(false) ,contentid, new Flipper().limit(30));
|
|
||||||
|
|
||||||
//热帖
|
|
||||||
//Flipper flipper2 = new Flipper().limit(8).sort("viewNum DESC");
|
|
||||||
//Sheet<ContentInfo> hotView = contentService.contentQuery(flipper2, "");
|
|
||||||
|
|
||||||
//热议
|
|
||||||
Flipper flipper3 = new Flipper().limit(8).sort("replyNum DESC");
|
|
||||||
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", currentId());
|
|
||||||
|
|
||||||
//更新
|
|
||||||
CompletableFuture.supplyAsync(new Supplier<String>() {
|
|
||||||
@Override
|
|
||||||
public String get() {
|
|
||||||
User user = request.currentUser();
|
|
||||||
if (user == null || user.getUserId() > 10_0003)
|
|
||||||
contentService.incrViewNum(contentid);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Kv kv = Kv.by("bean", content).set("comments", comments)/*.set("hotView", hotView)*/.set("hotReply", hotReply);
|
|
||||||
finish("/jie/detail.html", kv);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//====================================帖子相关====================================
|
|
||||||
|
|
||||||
//====================================上传相关====================================、
|
|
||||||
|
|
||||||
private static final String dir = "/var/www/upload/redbbs/";
|
|
||||||
private static final String view = "http://img.1216.top/redbbs/";
|
|
||||||
private static final String format = "%1$tY%1$tm%1$td%1$tH%1$tM%1$tS";
|
|
||||||
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
|
||||||
@HttpMapping(url = "/upload/img", auth = false, comment = "图片上传")
|
|
||||||
public void uploadImg(HttpRequest request, HttpResponse response){
|
|
||||||
try {
|
|
||||||
Map ret = new HashMap();
|
|
||||||
ret.put("errno", 0);
|
|
||||||
List data = new ArrayList();
|
|
||||||
|
|
||||||
for (MultiPart part : request.multiParts()) {
|
|
||||||
String name = part.getName();
|
|
||||||
String suffix = name.substring(name.lastIndexOf("."));
|
|
||||||
String path = String.format(format, System.currentTimeMillis()) + suffix;
|
|
||||||
File destFile = new File((winos ? "D:/wk/_own/redbbs/root/tem/" : dir) + path);
|
|
||||||
destFile.getParentFile().mkdir();
|
|
||||||
|
|
||||||
part.save(destFile);
|
|
||||||
|
|
||||||
data.add((winos ? "/tem/": view) + path);
|
|
||||||
}
|
|
||||||
ret.put("data", data);
|
|
||||||
|
|
||||||
response.setContentType("application/json; charset=utf-8");
|
|
||||||
response.finish(ret);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
finish("/article/index.html");
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
103
src/com/lxyer/bbs/servlet/UserServlet.java
Normal file
103
src/com/lxyer/bbs/servlet/UserServlet.java
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
package com.lxyer.bbs.servlet;
|
||||||
|
|
||||||
|
import com.jfinal.kit.Kv;
|
||||||
|
import com.lxyer.bbs.base.BaseServlet;
|
||||||
|
import com.lxyer.bbs.base.user.User;
|
||||||
|
import com.lxyer.bbs.base.user.UserBean;
|
||||||
|
import com.lxyer.bbs.base.user.UserInfo;
|
||||||
|
import com.lxyer.bbs.comment.CommentInfo;
|
||||||
|
import com.lxyer.bbs.content.ContentBean;
|
||||||
|
import com.lxyer.bbs.content.ContentInfo;
|
||||||
|
import org.redkale.net.http.HttpMapping;
|
||||||
|
import org.redkale.net.http.HttpRequest;
|
||||||
|
import org.redkale.net.http.HttpResponse;
|
||||||
|
import org.redkale.net.http.WebServlet;
|
||||||
|
import org.redkale.source.Flipper;
|
||||||
|
import org.redkale.util.Sheet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户相关的servlet
|
||||||
|
* Created by liangxianyou at 2018/6/4 13:12.
|
||||||
|
*/
|
||||||
|
@WebServlet({"/user", "/user/*"})
|
||||||
|
public class UserServlet extends BaseServlet {
|
||||||
|
|
||||||
|
|
||||||
|
@HttpMapping(url = "/user/login", auth = false, comment = "前往登录页")
|
||||||
|
public void login(HttpRequest request, HttpResponse response){
|
||||||
|
|
||||||
|
finish("/user/login.html");
|
||||||
|
}
|
||||||
|
@HttpMapping(url = "/user/reg", auth = false, comment = "前往登录页")
|
||||||
|
public void reg(HttpRequest request, HttpResponse response){
|
||||||
|
/*List<Kv> list = new ArrayList<>();
|
||||||
|
list.add(Kv.by("k", 1).set("a", "1+1=?").set("q", 2));
|
||||||
|
list.add(Kv.by("k", 2).set("a", "1*1=?").set("q", 1));
|
||||||
|
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));*/
|
||||||
|
|
||||||
|
finish("/user/login.html");
|
||||||
|
}
|
||||||
|
|
||||||
|
@HttpMapping(url = "/user/set", auth = true, comment = "用户设置")
|
||||||
|
public void set(HttpRequest request, HttpResponse response){
|
||||||
|
finish("/user/set.html");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@HttpMapping(url = "/user", auth = false, comment = "用户首页")
|
||||||
|
public void user(HttpRequest request, HttpResponse response){
|
||||||
|
String para = getPara();
|
||||||
|
|
||||||
|
//-------个人中心---------
|
||||||
|
if ("user".equals(para) || "".equals(para)){
|
||||||
|
UserInfo user = request.currentUser();
|
||||||
|
if (user == null){
|
||||||
|
finish("/user/login.html");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//创建的帖子
|
||||||
|
Flipper flipper = new Flipper().limit(8).sort("createTime DESC");
|
||||||
|
ContentBean bean = new ContentBean();
|
||||||
|
bean.setUserId(user.getUserId());
|
||||||
|
Sheet<ContentInfo> contents = contentService.queryByBean(flipper, bean);
|
||||||
|
|
||||||
|
//收藏的帖子
|
||||||
|
Sheet<ContentInfo> collects = contentService.collectQuery(sessionid);
|
||||||
|
|
||||||
|
Kv kv = Kv.by("contents", contents).set("collects", collects);
|
||||||
|
finish("/user/index.html", kv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------用户主页------
|
||||||
|
int userId = 0;
|
||||||
|
if ("nick".equals(para)){//通过@ 点击跳转
|
||||||
|
String nickname = request.getParameter("nickname");
|
||||||
|
UserBean userBean = new UserBean();
|
||||||
|
userBean.setNickname(nickname);
|
||||||
|
Sheet<User> users = userService.queryUser(new Flipper().limit(1), userBean);
|
||||||
|
if (users.getTotal() > 0){
|
||||||
|
userId = users.stream().findFirst().orElse(null).getUserId();
|
||||||
|
}
|
||||||
|
}else {//直接访问
|
||||||
|
userId = getParaToInt(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//用户信息
|
||||||
|
UserInfo user = userService.findUserInfo(userId);
|
||||||
|
|
||||||
|
//帖子
|
||||||
|
Flipper flipper = new Flipper().limit(8).sort("createTime DESC");
|
||||||
|
ContentBean bean = new ContentBean();
|
||||||
|
bean.setUserId(userId);
|
||||||
|
Sheet<ContentInfo> contents = contentService.queryByBean(flipper, bean);
|
||||||
|
|
||||||
|
//回复
|
||||||
|
Sheet<CommentInfo> comments = commentService.queryByUserid(userId);
|
||||||
|
|
||||||
|
Kv kv = Kv.by("contents", contents).set("user", user).set("comments", comments);
|
||||||
|
finish("/user/home.html", kv);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user