'合并分支'
This commit is contained in:
66
src/net/tccn/bbs/base/ArangoKit.java
Normal file
66
src/net/tccn/bbs/base/ArangoKit.java
Normal file
@@ -0,0 +1,66 @@
|
||||
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("abc123").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();
|
||||
}
|
||||
|
||||
}
|
95
src/net/tccn/bbs/base/ArangoService.java
Normal file
95
src/net/tccn/bbs/base/ArangoService.java
Normal file
@@ -0,0 +1,95 @@
|
||||
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 = true, 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 db;
|
||||
protected static ArangoCollection colVisLog;
|
||||
|
||||
@Override
|
||||
public void init(AnyValue config) {
|
||||
System.out.println("isDev :" + isDev);
|
||||
|
||||
arangoDb = new ArangoDB.Builder().host(arangoHost, port).user(user).password(password).build();
|
||||
db = arangoDb.db(chDev.apply(database));
|
||||
colVisLog = db.collection(chDev.apply(VIS_LOG));
|
||||
|
||||
if (!db.exists()) {
|
||||
db.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 = db.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 db.query(aql, long.class).first();
|
||||
}
|
||||
public static long findInt(String aql, Map para) {
|
||||
return db.query(aql, long.class).first();
|
||||
}
|
||||
|
||||
public static <T> List<T> find(String aql, Class<T> clazz) {
|
||||
return db.query(aql, clazz).asListRemaining();
|
||||
}
|
||||
|
||||
public static <T> List<T> find(String aql, Map para, Class<T> clazz) {
|
||||
|
||||
return db.query(aql, para, clazz).asListRemaining();
|
||||
}
|
||||
|
||||
}
|
72
src/net/tccn/bbs/base/BaseService.java
Normal file
72
src/net/tccn/bbs/base/BaseService.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package com.lxyer.bbs.base;
|
||||
|
||||
import com.arangodb.Predicate;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.source.CacheSource;
|
||||
import org.redkale.source.DataSource;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/10/3 13:50.
|
||||
*/
|
||||
public class BaseService implements Service {
|
||||
|
||||
protected final int sessionExpireSeconds = 7 * 24 * 60 * 60;
|
||||
|
||||
@Resource(name = "property.isDev")
|
||||
public boolean isDev = true;
|
||||
|
||||
@Resource(name = "SERVER_ROOT")
|
||||
protected File webroot;
|
||||
|
||||
@Resource(name = "art123")
|
||||
protected DataSource source;
|
||||
|
||||
/* 使用redis 代码中配置此处即可
|
||||
@Resource(name = "redis")*/
|
||||
@Resource(name = "cacheSource")
|
||||
protected CacheSource<Long> sessions;
|
||||
|
||||
@Resource(name = "cacheSource")
|
||||
protected CacheSource cacheSource;
|
||||
|
||||
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||
|
||||
public static Predicate isEmpty = (x) -> {
|
||||
if (x == null)
|
||||
return true;
|
||||
if (x instanceof List)
|
||||
return ((List) x).isEmpty();
|
||||
if (x instanceof String)
|
||||
return ((String) x).isEmpty();
|
||||
if (x instanceof Map)
|
||||
return ((Map) x).isEmpty();
|
||||
if (x instanceof Collection)
|
||||
return ((Collection) x).isEmpty();
|
||||
return false;
|
||||
};
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
public DataSource getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
public int currentUserid(String sessionid){
|
||||
if (sessionid == null) return 0;
|
||||
long userid = 0;
|
||||
try {
|
||||
userid = sessions.getLong(sessionid, 0);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return (int)userid;
|
||||
}
|
||||
|
||||
}
|
174
src/net/tccn/bbs/base/BaseServlet.java
Normal file
174
src/net/tccn/bbs/base/BaseServlet.java
Normal file
@@ -0,0 +1,174 @@
|
||||
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;
|
||||
import com.lxyer.bbs.comment.CommentService;
|
||||
import com.lxyer.bbs.content.ContentService;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.source.FilterExpress;
|
||||
import org.redkale.source.FilterNode;
|
||||
import org.redkale.util.AnyValue;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.lxyer.bbs.base.kit.RetCodes.RET_USER_UNLOGIN;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/10/3 13:39.
|
||||
*/
|
||||
public class BaseServlet extends HttpServlet {
|
||||
|
||||
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||
|
||||
@Resource(name = "SERVER_ROOT")
|
||||
protected File webroot;
|
||||
|
||||
@Resource
|
||||
protected UserService userService;
|
||||
|
||||
@Resource
|
||||
protected ContentService contentService;
|
||||
|
||||
@Resource
|
||||
protected CommentService commentService;
|
||||
|
||||
@Resource
|
||||
protected TaskQueue<VisLog> logQueue;
|
||||
|
||||
@Override
|
||||
public void init(HttpContext context, AnyValue config) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void preExecute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
/*if (true){
|
||||
response.finish(HttpScope.refer("404.html"));
|
||||
return;
|
||||
}*/
|
||||
|
||||
String sessionid = request.getSessionid(true);
|
||||
int currentid = 0;
|
||||
if (sessionid != null) {
|
||||
request.setCurrentUser(userService.current(sessionid));
|
||||
currentid = userService.currentUserid(sessionid);
|
||||
}
|
||||
|
||||
String uri = request.getRequestURI();
|
||||
if (uri.startsWith("/res")){
|
||||
File file = new File(webroot + uri);
|
||||
response.finish(file);
|
||||
return;
|
||||
}
|
||||
if (uri.endsWith(".html")){
|
||||
response.finish(HttpScope.refer(uri));
|
||||
return;
|
||||
}
|
||||
|
||||
//异步记录访问日志
|
||||
final int userid = currentid;
|
||||
CompletableFuture.runAsync(()->{
|
||||
|
||||
Kv para = Kv.create();
|
||||
for (String key : request.getParameterNames()){
|
||||
para.set(key, request.getParameter(key));
|
||||
}
|
||||
Kv headers = Kv.create();
|
||||
request.getHeaders().forEach((k,v)->{
|
||||
headers.set(k, request.getHeader(k));
|
||||
});
|
||||
|
||||
VisLog visLog = new VisLog();
|
||||
visLog.setIp(request.getRemoteAddr());
|
||||
visLog.setUri(request.getRequestURI());
|
||||
visLog.setHeaders(headers);
|
||||
visLog.setUserid(userid);
|
||||
visLog.setPara(para);
|
||||
visLog.setTime(System.currentTimeMillis());
|
||||
visLog.setFtime(String.format("%1$tY%1$tm%1$td%1$tH%1$tM%1$tS", visLog.getTime()));
|
||||
|
||||
try {
|
||||
logQueue.put(visLog);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
response.nextEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void authenticate(HttpRequest request, HttpResponse response) throws IOException {
|
||||
if (request.currentUser() == null) {
|
||||
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))){
|
||||
response.finish(RetCodes.retResult(RET_USER_UNLOGIN, "未登录,登录后重试").toString());
|
||||
}else {
|
||||
response.finish(HttpScope.refer("/user/login.html"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
response.nextEvent();
|
||||
}
|
||||
|
||||
public int getLimit(HttpRequest request){
|
||||
return request.getIntParameter("limit", 1);
|
||||
}
|
||||
public int getOffset(HttpRequest request){
|
||||
return request.getIntParameter("offset", 10);
|
||||
}
|
||||
|
||||
public String getPara(HttpRequest request){
|
||||
String requestURI = request.getRequestURI();
|
||||
String subStr = requestURI.substring(requestURI.lastIndexOf("/") + 1);
|
||||
return subStr.contains("-") ? subStr.substring(0, subStr.indexOf("-")) : subStr;
|
||||
}
|
||||
public String getPara(HttpRequest request,int index){
|
||||
String requestURI = request.getRequestURI();
|
||||
String subStr = requestURI.substring(requestURI.lastIndexOf("/") + 1);
|
||||
|
||||
String[] paraArr = subStr.split("-");
|
||||
if (index < 0){
|
||||
return paraArr.length < -index ? null : paraArr[paraArr.length+index];
|
||||
}else {
|
||||
return paraArr.length < index+1 ? null : paraArr[index];
|
||||
}
|
||||
}
|
||||
public <T> T getPara(HttpRequest request, int index, T defaultValue){
|
||||
T para = (T)getPara(request,index);
|
||||
return para == null || "".equals(para) ? defaultValue : para;
|
||||
}
|
||||
public int getParaToInt(HttpRequest request,int index, int defaultValue){
|
||||
String para = getPara(request,index);
|
||||
return para == null || "".equals(para) ? defaultValue : Integer.parseInt(para);
|
||||
}
|
||||
public int getParaToInt(HttpRequest request,int index){
|
||||
int n = 0;
|
||||
String para = getPara(request,index);
|
||||
if (para == null || "".equals(para)) n = 0;
|
||||
try {
|
||||
n = Integer.parseInt(para);
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
//设置私密帖子过滤
|
||||
protected FilterNode setPrivate(HttpRequest request,FilterNode node){
|
||||
UserInfo userInfo = request.currentUser();
|
||||
if (userInfo == null){
|
||||
node.and("status", FilterExpress.NOTEQUAL, 30);
|
||||
}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))
|
||||
node.and(FilterNode.create("status", FilterExpress.NOTEQUAL, 30).or(FilterNode.create("status", 30).and("userid", userInfo.getUserid())));
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
}
|
52
src/net/tccn/bbs/base/EnjoyRender.java
Normal file
52
src/net/tccn/bbs/base/EnjoyRender.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.lxyer.bbs.base;
|
||||
|
||||
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.user.UserInfo;
|
||||
import org.redkale.convert.Convert;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.util.AnyValue;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by JUECHENG at 2018/1/30 0:18.
|
||||
*/
|
||||
public class EnjoyRender implements HttpRender<HttpScope> {
|
||||
|
||||
@Resource(name = "SERVER_ROOT")
|
||||
protected File webroot;
|
||||
|
||||
private static final Engine engine = new Engine();
|
||||
|
||||
@Override
|
||||
public void init(HttpContext context, AnyValue config) {
|
||||
engine.setBaseTemplatePath(webroot.getPath());
|
||||
engine.addSharedObject("EJ", new EJ());
|
||||
engine.addSharedFunction("/_t/layout.html");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTo(HttpRequest request, HttpResponse response, Convert convert, HttpScope scope) {
|
||||
UserInfo mine = request.currentUser();//当前登录人
|
||||
|
||||
Template template = engine.getTemplate(scope.getReferid());
|
||||
Map attr = scope.getAttributes();
|
||||
if (attr == null) attr = Kv.create();
|
||||
attr.put("mine", mine);
|
||||
attr.put("token", request.getSessionid(false));
|
||||
|
||||
String str = template.renderToString(attr);
|
||||
response.setContentType("text/html; charset=UTF-8");
|
||||
response.finish(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getType() {
|
||||
return HttpScope.class;
|
||||
}
|
||||
}
|
41
src/net/tccn/bbs/base/FileService.java
Normal file
41
src/net/tccn/bbs/base/FileService.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.lxyer.bbs.base;
|
||||
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestService;
|
||||
import org.redkale.net.http.RestUploadFile;
|
||||
import org.redkale.service.RetResult;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/10/3 13:48.
|
||||
*/
|
||||
@RestService(automapping = true, comment = "文件服务")
|
||||
public class FileService extends BaseService {
|
||||
|
||||
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";
|
||||
|
||||
@RestMapping(name = "upload", comment = "文件上传")
|
||||
public RetResult upload(@RestUploadFile File tmpFile) throws IOException {
|
||||
String name = tmpFile.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();
|
||||
if (!tmpFile.renameTo(destFile)){
|
||||
try{
|
||||
Files.copy(tmpFile.toPath(), destFile.toPath(), StandardCopyOption.ATOMIC_MOVE);
|
||||
}finally {
|
||||
tmpFile.delete();//删除临时文件
|
||||
}
|
||||
}
|
||||
RetResult result = RetResult.success();
|
||||
result.setRetinfo((winos ? "/tem/": view) + path);
|
||||
return result;
|
||||
}
|
||||
}
|
90
src/net/tccn/bbs/base/JBean.java
Normal file
90
src/net/tccn/bbs/base/JBean.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package net.tccn.base;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou
|
||||
*/
|
||||
public class JBean<T> /*extends RetResult*/ {
|
||||
private int retcode;
|
||||
private String retinfo = "";
|
||||
private T result;
|
||||
private Map<String, Object> attach;
|
||||
|
||||
public JBean(int retcode) {
|
||||
this.retcode = retcode;
|
||||
}
|
||||
|
||||
public JBean(int retcode, String retinfo) {
|
||||
this.retcode = retcode;
|
||||
this.retinfo = retinfo;
|
||||
}
|
||||
|
||||
public static JBean by(int retcode, String retinfo){
|
||||
JBean jBean = new JBean(retcode, retinfo);
|
||||
return jBean;
|
||||
}
|
||||
|
||||
public static JBean by(int retcode, String retinfo, Object t){
|
||||
JBean jBean = new JBean(retcode, retinfo);
|
||||
jBean.setResult(t);
|
||||
return jBean;
|
||||
}
|
||||
|
||||
public JBean(T result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public int getRetcode() {
|
||||
return retcode;
|
||||
}
|
||||
|
||||
public void setRetcode(int retcode) {
|
||||
this.retcode = retcode;
|
||||
}
|
||||
|
||||
public String getRetinfo() {
|
||||
return retinfo;
|
||||
}
|
||||
|
||||
public void setRetinfo(String retinfo) {
|
||||
this.retinfo = retinfo;
|
||||
}
|
||||
|
||||
public T getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(T result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public Map<String, Object> getAttach() {
|
||||
return attach;
|
||||
}
|
||||
|
||||
public void setAttach(Map<String, Object> attach) {
|
||||
this.attach = attach;
|
||||
}
|
||||
|
||||
public JBean attach(String key, Object object){
|
||||
if (attach == null)
|
||||
attach = new HashMap<>();
|
||||
attach.put(key, object);
|
||||
return this;
|
||||
}
|
||||
|
||||
private static final JBean ok = new JBean(0);
|
||||
public static JBean ok(){
|
||||
return ok;
|
||||
}
|
||||
|
||||
public static JBean faild(String retinfo){
|
||||
return new JBean(-1, retinfo);
|
||||
}
|
||||
|
||||
public static JBean by(Object object) {
|
||||
return new JBean(object);
|
||||
}
|
||||
}
|
184
src/net/tccn/bbs/base/TaskQueue.java
Normal file
184
src/net/tccn/bbs/base/TaskQueue.java
Normal file
@@ -0,0 +1,184 @@
|
||||
package com.lxyer.bbs.base;
|
||||
|
||||
import com.lxyer.bbs.base.entity.Count;
|
||||
import com.lxyer.bbs.base.entity.VisLog;
|
||||
import com.lxyer.bbs.base.user.UserInfo;
|
||||
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 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.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.Function;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/6/20 22:54.
|
||||
*/
|
||||
@RestService(name = "xxx",automapping = true, comment = "日志记录")
|
||||
public class TaskQueue<T extends Object> extends BaseService implements Runnable {
|
||||
|
||||
@Resource
|
||||
private ContentService contentService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
protected static LinkedBlockingQueue queue = new LinkedBlockingQueue();
|
||||
|
||||
public TaskQueue() {
|
||||
new Thread(this).start();
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
public T take() throws InterruptedException {
|
||||
return (T) queue.take();
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
public void put(T t) throws InterruptedException {
|
||||
queue.put(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
@RestMapping(ignore = true, comment = "独立线程,用户访问行为记录到数据库")
|
||||
public void run() {
|
||||
do {
|
||||
try {
|
||||
T task = take();
|
||||
|
||||
//记录访问日志,如果是访问的文章详情:对文章访问数量更新
|
||||
if (task instanceof VisLog) {
|
||||
//System.out.println(task);
|
||||
ArangoService.save(task).thenAcceptAsync((_task) -> {
|
||||
VisLog visLog = (VisLog) _task;
|
||||
//[访问量]
|
||||
String uri = visLog.getUri();
|
||||
if (uri != null && uri.startsWith("/jie/detail/")){
|
||||
updateViewNum(visLog);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
@Comment("帖子阅读数处理")
|
||||
private void updateViewNum(VisLog visLog) {
|
||||
|
||||
String aql = String.format("for d in vis_log_dev\n" +
|
||||
" filter d.uri == '%s' and d.ip == '%s' and (d.userid == %s or d.userid==0)\n" +
|
||||
" collect WITH COUNT INTO total\n" +
|
||||
" return total", visLog.getUri(), visLog.getIp(), visLog.getUserid());
|
||||
|
||||
long total = ArangoService.findInt(aql);
|
||||
|
||||
if (total <= 1) {
|
||||
String uri = visLog.getUri();
|
||||
int contentid = Integer.parseInt(uri.replace("/jie/detail/", ""));
|
||||
source.updateColumn(Content.class, contentid, ColumnValue.inc("viewnum", 1));
|
||||
}
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true, comment = "访问热帖数据")
|
||||
public Sheet<ContentInfo> hotView(String sessionid){
|
||||
int limit = 8;
|
||||
String cacheKey = "hotView";
|
||||
Object ids = cacheSource.get(cacheKey);
|
||||
if (isEmpty.test(ids)){
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.DAY_OF_MONTH, -7);
|
||||
|
||||
Map para = new HashMap();
|
||||
para.put("time", cal.getTimeInMillis());
|
||||
//查询一周某热帖记录
|
||||
List<Count> hotArticle = ArangoService.find(
|
||||
"for d in " + (isDev ? "vis_log_dev" : "vis_log") + "\n" +
|
||||
" filter d.uri =~ '^/jie/detail/[0-9]+$' and d.userid != 100001 and d.time > @time\n" +
|
||||
" COLLECT uri=d.uri WITH COUNT INTO total\n" +
|
||||
" sort total desc\n" +
|
||||
" limit 10\n" +
|
||||
" return {name: uri,total:total}",
|
||||
Utility.ofMap("time", cal.getTimeInMillis()),
|
||||
Count.class);
|
||||
|
||||
Function<List<Count>, List<Integer>> deal = (counts) -> {
|
||||
List<Integer> _ids = new ArrayList<>();
|
||||
counts.forEach(x -> {
|
||||
_ids.add(Integer.parseInt(x.getName().replace("/jie/detail/", "")));
|
||||
});
|
||||
return _ids;
|
||||
};
|
||||
|
||||
ids = deal.apply(hotArticle);
|
||||
cacheSource.set(30 * 60, cacheKey, ids);
|
||||
}
|
||||
|
||||
int[] contentids = new int[((List<Integer>) ids).size()];
|
||||
for (int i = 0; i < ((List<Integer>) ids).size(); i++) {
|
||||
contentids[i] = ((List<Integer>) ids).get(i);
|
||||
}
|
||||
|
||||
Flipper flipper = new Flipper().limit(limit);
|
||||
FilterNode node = FilterNode.create("contentid", FilterExpress.IN, contentids).and("status", FilterExpress.NOTEQUAL, -10);
|
||||
|
||||
//权限过滤
|
||||
UserInfo userInfo = userService.current(sessionid);
|
||||
if (userInfo == null){ //访客
|
||||
node.and("status", FilterExpress.NOTEQUAL, 30);
|
||||
}else if (!userService.isAdmin(userInfo.getUserid())){ //非管理员
|
||||
node.and(FilterNode.create("status", FilterExpress.NOTEQUAL, 30).or(FilterNode.create("status", 30).and("userid", userInfo.getUserid())));
|
||||
}
|
||||
return contentService.contentQuery(flipper, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO:帖子访客记录 --待完成
|
||||
*/
|
||||
@RestMapping(ignore = true, comment = "帖子访客记录")
|
||||
public Sheet<Map> readRecordAsync(Flipper flipper ,int 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);
|
||||
|
||||
List<Map> rows = new ArrayList<>();
|
||||
List<Integer> uids = new ArrayList<>();
|
||||
documents.forEach((Consumer<? super Document>) x->{
|
||||
Integer userid = x.getInteger("userid");
|
||||
if (userid > 0) uids.add(userid);
|
||||
|
||||
Map row = new HashMap<String, Object>();
|
||||
row.put("userid", userid);
|
||||
row.put("ip", x.getString("ip"));
|
||||
});
|
||||
|
||||
int[] userids = LxyKit.listToArray(uids, new int[uids.size()]);
|
||||
List<UserRecord> records = source.queryList(UserRecord.class, FilterNode.create("userid", FilterExpress.IN, userids));
|
||||
|
||||
rows.forEach(x->{
|
||||
UserRecord record = records.stream().filter(y -> (Integer) x.get("userid") == y.getUserid()).findFirst().orElse(new UserRecord());
|
||||
x.put("nickname", record.getRealname());
|
||||
x.put("avatar", record.getAvatar());
|
||||
});
|
||||
|
||||
Sheet<Map> sheet = new Sheet<>();
|
||||
sheet.setTotal(total);
|
||||
sheet.setRows(rows);
|
||||
|
||||
return sheet;*/
|
||||
return null;
|
||||
}
|
||||
}
|
12
src/net/tccn/bbs/base/UF.java
Normal file
12
src/net/tccn/bbs/base/UF.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.lxyer.bbs.base;
|
||||
|
||||
import com.lxyer.bbs.base.iface.UI;
|
||||
|
||||
/**
|
||||
* user foreign key (userId)
|
||||
* Created by liangxianyou at 2018/6/9 14:50.
|
||||
*/
|
||||
public interface UF<I extends UI> {
|
||||
int getUserid();
|
||||
I createInfo();
|
||||
}
|
96
src/net/tccn/bbs/base/bean/ActLogBean.java
Normal file
96
src/net/tccn/bbs/base/bean/ActLogBean.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package com.lxyer.bbs.base.bean;
|
||||
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.source.FilterBean;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lxyer
|
||||
*/
|
||||
public class ActLogBean implements Serializable, FilterBean {
|
||||
|
||||
@Column(comment = "[日志id]")
|
||||
private int logid;
|
||||
|
||||
@Column(comment = "[日志类型]")
|
||||
private int cate;
|
||||
|
||||
@Column(comment = "[目标数据id]")
|
||||
private int tid;
|
||||
|
||||
@Column(comment = "[用户id]")
|
||||
private int userId;
|
||||
|
||||
@Column(comment = "[创建时间]")
|
||||
private long createTime;
|
||||
|
||||
@Column(length = 128, comment = "[说明]")
|
||||
private String remark = "";
|
||||
|
||||
@Column(comment = "[状态]-1删除 1正常")
|
||||
private int status = 1;
|
||||
|
||||
public void setLogid(int logid) {
|
||||
this.logid = logid;
|
||||
}
|
||||
|
||||
public int getLogid() {
|
||||
return this.logid;
|
||||
}
|
||||
|
||||
public void setCate(int cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public int getCate() {
|
||||
return this.cate;
|
||||
}
|
||||
|
||||
public void setTid(int tid) {
|
||||
this.tid = tid;
|
||||
}
|
||||
|
||||
public int getTid() {
|
||||
return this.tid;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return this.userId;
|
||||
}
|
||||
|
||||
public void setCreateTime(long createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public long getCreateTime() {
|
||||
return this.createTime;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return this.remark;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
}
|
110
src/net/tccn/bbs/base/entity/ActLog.java
Normal file
110
src/net/tccn/bbs/base/entity/ActLog.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package com.lxyer.bbs.base.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lxyer
|
||||
*/
|
||||
@Cacheable(interval = 5*60)
|
||||
@Table(catalog = "redbbs", name = "sys_actlog")
|
||||
public class ActLog implements java.io.Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(comment = "[日志id]")
|
||||
private int logid;
|
||||
|
||||
@Column(comment = "[日志类型]10赞,20收藏,30阅读")
|
||||
private short cate;
|
||||
|
||||
@Column(comment = "[目标数据id]")
|
||||
private int tid;
|
||||
|
||||
@Column(comment = "[用户id]")
|
||||
private int userid;
|
||||
|
||||
@Column(updatable = false, comment = "[创建时间]")
|
||||
private long createtime;
|
||||
|
||||
@Column(length = 128, comment = "[说明]")
|
||||
private String remark = "";
|
||||
|
||||
@Column(comment = "[状态]-1删除 1正常")
|
||||
private short status = 10;
|
||||
|
||||
public void setLogid(int logid) {
|
||||
this.logid = logid;
|
||||
}
|
||||
|
||||
public int getLogid() {
|
||||
return this.logid;
|
||||
}
|
||||
|
||||
public void setCate(short cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public short getCate() {
|
||||
return this.cate;
|
||||
}
|
||||
|
||||
public void setTid(int tid) {
|
||||
this.tid = tid;
|
||||
}
|
||||
|
||||
public int getTid() {
|
||||
return this.tid;
|
||||
}
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public int getUserid() {
|
||||
return this.userid;
|
||||
}
|
||||
|
||||
public void setCreatetime(long createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
public long getCreatetime() {
|
||||
return this.createtime;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return this.remark;
|
||||
}
|
||||
|
||||
public void setStatus(short status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public short getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
//----
|
||||
public ActLog() {
|
||||
|
||||
}
|
||||
|
||||
public ActLog(int cate, int tid, int userid) {
|
||||
this.cate = (short) cate;
|
||||
this.tid = tid;
|
||||
this.userid = userid;
|
||||
}
|
||||
}
|
37
src/net/tccn/bbs/base/entity/Count.java
Normal file
37
src/net/tccn/bbs/base/entity/Count.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.lxyer.bbs.base.entity;
|
||||
|
||||
/**
|
||||
* 用来计数用
|
||||
*
|
||||
* @author: liangxianyou at 2018/11/18 20:42.
|
||||
*/
|
||||
public class Count {
|
||||
private String name;
|
||||
private long total;
|
||||
|
||||
//-------------------
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(long total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Count{" +
|
||||
"name='" + name + '\'' +
|
||||
", total=" + total +
|
||||
'}';
|
||||
}
|
||||
}
|
67
src/net/tccn/bbs/base/entity/DynAttr.java
Normal file
67
src/net/tccn/bbs/base/entity/DynAttr.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package com.lxyer.bbs.base.entity;
|
||||
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
import javax.persistence.Cacheable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lxyer
|
||||
*/
|
||||
@Cacheable(interval = 5*60)
|
||||
@Table(catalog = "redbbs", name = "sys_dynattr", comment = "[动态属性表]")
|
||||
public class DynAttr implements java.io.Serializable {
|
||||
|
||||
@Id
|
||||
@Column(comment = "[目标数据id]")
|
||||
private int tid;
|
||||
|
||||
@Column(comment = "[类型]1文章, 2xx, 3...,")
|
||||
private short cate;
|
||||
|
||||
@Column(length = 32, comment = "")
|
||||
private String attr = "";
|
||||
|
||||
@Column(comment = "[属性值]")
|
||||
private String value = "";
|
||||
|
||||
public void setTid(int tid) {
|
||||
this.tid = tid;
|
||||
}
|
||||
|
||||
public int getTid() {
|
||||
return this.tid;
|
||||
}
|
||||
|
||||
public void setCate(short cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public short getCate() {
|
||||
return this.cate;
|
||||
}
|
||||
|
||||
public void setAttr(String attr) {
|
||||
this.attr = attr;
|
||||
}
|
||||
|
||||
public String getAttr() {
|
||||
return this.attr;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
}
|
81
src/net/tccn/bbs/base/entity/VisLog.java
Normal file
81
src/net/tccn/bbs/base/entity/VisLog.java
Normal file
@@ -0,0 +1,81 @@
|
||||
package com.lxyer.bbs.base.entity;
|
||||
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 存贮数据到 非关系型数据库
|
||||
*
|
||||
* @author: liangxianyou at 2018/11/18 8:47.
|
||||
*/
|
||||
public class VisLog {
|
||||
private String ip;
|
||||
private int 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 int getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(int 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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
}
|
9
src/net/tccn/bbs/base/iface/C.java
Normal file
9
src/net/tccn/bbs/base/iface/C.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.lxyer.bbs.base.iface;
|
||||
|
||||
/**
|
||||
* 创建信息
|
||||
* Created by liangxianyou at 2018/6/16 17:43.
|
||||
*/
|
||||
public interface C<I extends CI> {
|
||||
I createInfo();
|
||||
}
|
7
src/net/tccn/bbs/base/iface/CI.java
Normal file
7
src/net/tccn/bbs/base/iface/CI.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package com.lxyer.bbs.base.iface;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/6/16 18:39.
|
||||
*/
|
||||
public interface CI<I extends CI> {
|
||||
}
|
32
src/net/tccn/bbs/base/iface/CService.java
Normal file
32
src/net/tccn/bbs/base/iface/CService.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.lxyer.bbs.base.iface;
|
||||
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.util.Sheet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/6/16 17:56.
|
||||
*/
|
||||
public interface CService<I extends UI> {
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
default <A extends C> Sheet<I> createInfo(Sheet<A> fSheet){
|
||||
Sheet<I> sheet = new Sheet<>();
|
||||
|
||||
if (fSheet == null || fSheet.getTotal() < 1){
|
||||
sheet.setTotal(0);
|
||||
sheet.setRows(new ArrayList<>());
|
||||
}else {
|
||||
int total = (int)fSheet.getTotal();
|
||||
List<I> rows = new ArrayList<>(total);
|
||||
fSheet.forEach(x->rows.add((I)x.createInfo()));
|
||||
|
||||
sheet.setTotal(total);
|
||||
sheet.setRows(rows);
|
||||
}
|
||||
|
||||
return sheet;
|
||||
}
|
||||
}
|
31
src/net/tccn/bbs/base/iface/UI.java
Normal file
31
src/net/tccn/bbs/base/iface/UI.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.lxyer.bbs.base.iface;
|
||||
|
||||
import com.lxyer.bbs.base.user.UserRecord;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/6/9 13:45.
|
||||
*/
|
||||
public interface UI<I extends UI> {
|
||||
|
||||
//抽象方法
|
||||
int getUserid();
|
||||
UserRecord getUser();
|
||||
I setUser(UserRecord user);
|
||||
|
||||
//默认实现方法
|
||||
default String getRealname(){
|
||||
return getUser() == null ? null : getUser().getRealname();
|
||||
}
|
||||
default String getNickname(){
|
||||
return getUser() == null ? null : getUser().getNickname();
|
||||
}
|
||||
default String getSite(){
|
||||
return getUser() == null ? "" : getUser().getSite();
|
||||
}
|
||||
default String getGit(){
|
||||
return getUser() == null ? "" : getUser().getGit();
|
||||
}
|
||||
default String getAvatar(){
|
||||
return getUser() == null ? null : getUser().getAvatar();
|
||||
}
|
||||
}
|
38
src/net/tccn/bbs/base/iface/UIService.java
Normal file
38
src/net/tccn/bbs/base/iface/UIService.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.lxyer.bbs.base.iface;
|
||||
|
||||
import com.lxyer.bbs.base.user.UserRecord;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.source.DataSource;
|
||||
import org.redkale.source.FilterExpress;
|
||||
import org.redkale.source.FilterNode;
|
||||
import org.redkale.util.Sheet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by liangxianyou at 2018/6/16 18:25.
|
||||
*/
|
||||
public interface UIService<I extends UI> extends CService<I> {
|
||||
|
||||
DataSource getSource();
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
default Sheet<I> setIUser(Sheet<I> sheet){
|
||||
int[] userids = sheet.stream().mapToInt(I::getUserid).toArray();
|
||||
|
||||
List<UserRecord> users = getSource().queryList(UserRecord.class, FilterNode.create("userid", FilterExpress.IN, userids));
|
||||
sheet.forEach(x->{
|
||||
UserRecord user = users.stream().filter(u -> u.getUserid() == x.getUserid()).findAny().orElse(null);
|
||||
x.setUser(user);
|
||||
});
|
||||
return sheet;
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true)
|
||||
default I setIUser(I i){
|
||||
UserRecord user = getSource().find(UserRecord.class, i.getUserid());
|
||||
|
||||
return (I) i.setUser(user);
|
||||
}
|
||||
|
||||
}
|
22
src/net/tccn/bbs/base/kit/EJ.java
Normal file
22
src/net/tccn/bbs/base/kit/EJ.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.lxyer.bbs.base.kit;
|
||||
|
||||
import org.redkale.net.http.RestService;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
* enjoy模板引擎使用共享方法类,
|
||||
* 更多关于enjoy的共享方法请查阅jfinal使用文档
|
||||
* Created by Lxy at 2017/11/26 17:19.
|
||||
*/
|
||||
@RestService
|
||||
public class EJ {
|
||||
|
||||
public String date(long time){
|
||||
return date(time, "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
public String date(long time, String pattern){
|
||||
return new SimpleDateFormat(pattern).format(time);
|
||||
}
|
||||
|
||||
}
|
70
src/net/tccn/bbs/base/kit/LxyKit.java
Normal file
70
src/net/tccn/bbs/base/kit/LxyKit.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package com.lxyer.bbs.base.kit;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/11/29 15:17.
|
||||
*/
|
||||
public final class LxyKit {
|
||||
|
||||
public static String dateFmt(long time){
|
||||
/**
|
||||
* 刚刚 60秒内 60 * 1000
|
||||
* x分钟前 1小时候内 60 * 60*1000
|
||||
* x小时前 1天内 24 * 60*60*1000
|
||||
* x天前 1周内 7 * 24*60*60*1000
|
||||
* 年-月-日 1周前
|
||||
*/
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
long diff = now - time;
|
||||
if (diff < 60 * 1000)
|
||||
return "刚刚";
|
||||
else if (diff < 60 * 60 *1000)
|
||||
return Math.floorDiv(diff, 60 *1000) + "分钟前";
|
||||
else if (diff < 24 * 60*60*1000)
|
||||
return Math.floorDiv(diff, 60 *60*1000) + "小时前";
|
||||
else if (diff > 24 * 60*60*1000 && diff < 7 * 24*60*60*1000)
|
||||
return Math.floorDiv(diff, 24 * 60*60*1000) + "天前";
|
||||
else
|
||||
return new SimpleDateFormat("yyyy-MM-dd").format(time);
|
||||
|
||||
}
|
||||
|
||||
public static String delHTMLTag(String htmlStr){
|
||||
String regEx_script="<script[^>]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式
|
||||
String regEx_style="<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式
|
||||
String regEx_html="<[^>]+>"; //定义HTML标签的正则表达式
|
||||
|
||||
Pattern p_script=Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE);
|
||||
Matcher m_script=p_script.matcher(htmlStr);
|
||||
htmlStr=m_script.replaceAll(""); //过滤script标签
|
||||
|
||||
Pattern p_style=Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE);
|
||||
Matcher m_style=p_style.matcher(htmlStr);
|
||||
htmlStr=m_style.replaceAll(""); //过滤style标签
|
||||
|
||||
Pattern p_html=Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE);
|
||||
Matcher m_html=p_html.matcher(htmlStr);
|
||||
htmlStr=m_html.replaceAll(""); //过滤html标签
|
||||
|
||||
return htmlStr.trim(); //返回文本字符串
|
||||
}
|
||||
|
||||
public static <T> T[] listToArray(List list, T[] ts){
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ts[0] = (T) list.get(i);
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
public static int[] listToArray(List list, int[] ts){
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ts[0] = (int) list.get(i);
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
}
|
66
src/net/tccn/bbs/base/kit/RetCodes.java
Normal file
66
src/net/tccn/bbs/base/kit/RetCodes.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package com.lxyer.bbs.base.kit;
|
||||
|
||||
import org.redkale.service.RetLabel;
|
||||
import org.redkale.service.RetResult;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/10/1 11:21.
|
||||
*/
|
||||
public abstract class RetCodes {
|
||||
|
||||
@RetLabel("参数无效")
|
||||
public static final int RET_PARAMS_ILLEGAL = 3001_0001;
|
||||
|
||||
//------------------------------------- 用户模块 -----------------------------------------
|
||||
@RetLabel("未登陆")
|
||||
public static final int RET_USER_UNLOGIN = 3002_0001;
|
||||
|
||||
@RetLabel("用户或密码错误")
|
||||
public static final int RET_USER_ACCOUNT_PWD_ILLEGAL = 3002_0002;
|
||||
|
||||
@RetLabel("用户权限不够")
|
||||
public static final int RET_USER_AUTH_ILLEGAL = 3002_0003;
|
||||
|
||||
@RetLabel("密码设置无效")
|
||||
public static final int RET_USER_PASSWORD_ILLEGAL = 3002_0004;
|
||||
|
||||
@RetLabel("用户不存在")
|
||||
public static final int RET_USER_NOTEXISTS = 3002_0005;
|
||||
|
||||
@RetLabel("用户名已存在")
|
||||
public static final int RET_USER_USERNAME_EXISTS = 3002_0006;
|
||||
|
||||
@RetLabel("用户名无效")
|
||||
public static final int RET_USER_USERNAME_ILLEGAL = 3002_0007;
|
||||
|
||||
@RetLabel("邮箱已存在")
|
||||
public static final int RET_USER_EMAIL_EXISTS = 3002_0008;
|
||||
|
||||
@RetLabel("邮箱无效")
|
||||
public static final int RET_USER_EMAIL_ILLEGAL = 3002_0009;
|
||||
|
||||
@RetLabel("昵称无效")
|
||||
public static final int RET_USER_NICKNAME_ILLEGAL = 3002_0010;
|
||||
|
||||
@RetLabel("昵称已存在")
|
||||
public static final int RET_USER_NICKNAME_EXISTS = 3002_0011;
|
||||
|
||||
//------------------------------------- 内容模块 -----------------------------------------
|
||||
|
||||
//------------------------------------- 评论模块 -----------------------------------------
|
||||
@RetLabel("评论内容无效")
|
||||
public static final int RET_COMMENT_CONTENT_ILLEGAL = 3004_0001;
|
||||
|
||||
@RetLabel("评论参数无效")
|
||||
public static final int RET_COMMENT_PARA_ILLEGAL = 3004_0002;
|
||||
|
||||
|
||||
|
||||
public static RetResult retResult(int retcode) {
|
||||
return new RetResult(retcode);
|
||||
}
|
||||
|
||||
public static RetResult retResult(int retcode, String retinfo) {
|
||||
return new RetResult(retcode, retinfo);
|
||||
}
|
||||
}
|
48
src/net/tccn/bbs/base/user/LoginBean.java
Normal file
48
src/net/tccn/bbs/base/user/LoginBean.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package com.lxyer.bbs.base.user;
|
||||
|
||||
import org.redkale.net.http.RestSessionid;
|
||||
import org.redkale.source.FilterBean;
|
||||
import org.redkale.util.Comment;
|
||||
|
||||
import javax.persistence.Transient;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/10/1 10:40.
|
||||
*/
|
||||
public class LoginBean implements FilterBean {
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
@Transient
|
||||
@Comment("会话SESSIONID")
|
||||
@RestSessionid(create = true)
|
||||
private String sessionid = "";
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return UserRecord.md5IfNeed(password);
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getSessionid() {
|
||||
return sessionid;
|
||||
}
|
||||
|
||||
public void setSessionid(String sessionid) {
|
||||
this.sessionid = sessionid;
|
||||
}
|
||||
|
||||
public boolean emptyUsername() {
|
||||
return username == null || username.isEmpty();
|
||||
}
|
||||
}
|
67
src/net/tccn/bbs/base/user/UserBean.java
Normal file
67
src/net/tccn/bbs/base/user/UserBean.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package com.lxyer.bbs.base.user;
|
||||
|
||||
import org.redkale.source.FilterBean;
|
||||
|
||||
import javax.persistence.Column;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/10/10 8:30.
|
||||
*/
|
||||
public class UserBean implements FilterBean {
|
||||
|
||||
|
||||
@Column(length = 32, comment = "[登录名]")
|
||||
private String username;
|
||||
|
||||
@Column(length = 32, comment = "[电话号码]")
|
||||
private String phone;
|
||||
|
||||
@Column(length = 64, comment = "[昵称]")
|
||||
private String nickname;
|
||||
|
||||
@Column(length = 32, comment = "[真实姓名]")
|
||||
private String realname;
|
||||
|
||||
@Column(length = 32, comment = "[邮箱]")
|
||||
private String email;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getRealname() {
|
||||
return realname;
|
||||
}
|
||||
|
||||
public void setRealname(String realname) {
|
||||
this.realname = realname;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
189
src/net/tccn/bbs/base/user/UserInfo.java
Normal file
189
src/net/tccn/bbs/base/user/UserInfo.java
Normal file
@@ -0,0 +1,189 @@
|
||||
package com.lxyer.bbs.base.user;
|
||||
|
||||
import org.redkale.convert.ConvertColumn;
|
||||
import org.redkale.convert.ConvertType;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lxyer
|
||||
*/
|
||||
public class UserInfo implements java.io.Serializable {
|
||||
|
||||
@Id
|
||||
@Column(comment = "[用户id]")
|
||||
private int userid;
|
||||
|
||||
private String username = "";
|
||||
private int sex = 1;
|
||||
private String password = "";
|
||||
private String phone = "";
|
||||
private String nickname = "";
|
||||
private String avatar = "";
|
||||
private String relaname = "";
|
||||
private String email = "";
|
||||
private int roleid = 0;
|
||||
private String site = "";
|
||||
private String git = "";
|
||||
private long createtime;
|
||||
private String sign = "";
|
||||
private String city = "";
|
||||
private int status = 1;
|
||||
private String time = "";
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public int getUserid() {
|
||||
return this.userid;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public int getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(int sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
@ConvertColumn(ignore = true,type = ConvertType.JSON)
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return this.phone;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return this.nickname;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return this.avatar;
|
||||
}
|
||||
|
||||
public void setRelaname(String relaname) {
|
||||
this.relaname = relaname;
|
||||
}
|
||||
|
||||
public String getRelaname() {
|
||||
return this.relaname;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return this.email == null || this.email.isEmpty() ? "" : this.email;
|
||||
}
|
||||
|
||||
public int getRoleid() {
|
||||
return roleid;
|
||||
}
|
||||
|
||||
public void setRoleid(int roleid) {
|
||||
this.roleid = roleid;
|
||||
}
|
||||
|
||||
public String getSite() {
|
||||
return site;
|
||||
}
|
||||
|
||||
public void setSite(String site) {
|
||||
this.site = site;
|
||||
}
|
||||
|
||||
public String getGit() {
|
||||
return git;
|
||||
}
|
||||
|
||||
public void setGit(String git) {
|
||||
this.git = git;
|
||||
}
|
||||
|
||||
public void setCreatetime(long createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
public long getCreatetime() {
|
||||
return this.createtime;
|
||||
}
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户权限
|
||||
* @param moduleid
|
||||
* @param actionid
|
||||
* @return
|
||||
*/
|
||||
public boolean checkAuth(int moduleid, int actionid) {
|
||||
|
||||
return !(moduleid == 2 && actionid == 1);
|
||||
}
|
||||
}
|
231
src/net/tccn/bbs/base/user/UserRecord.java
Normal file
231
src/net/tccn/bbs/base/user/UserRecord.java
Normal file
@@ -0,0 +1,231 @@
|
||||
package com.lxyer.bbs.base.user;
|
||||
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
import javax.persistence.Cacheable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lxyer
|
||||
*/
|
||||
@Cacheable(interval = 5*60)
|
||||
@Table(catalog = "redbbs", name = "sys_userrecord")
|
||||
public class UserRecord implements java.io.Serializable {
|
||||
|
||||
@Id
|
||||
@Column(comment = "[用户id]")
|
||||
private int userid;
|
||||
|
||||
@Column(length = 32, comment = "[登录名]")
|
||||
private String username = "";
|
||||
|
||||
@Column(length = 64, comment = "[密码]")
|
||||
private String password = "";
|
||||
|
||||
@Column(comment = "[性别]默认 10男,20女")
|
||||
private short sex;
|
||||
|
||||
@Column(length = 32, comment = "[电话号码]")
|
||||
private String phone = "";
|
||||
|
||||
@Column(length = 64, comment = "[昵称]")
|
||||
private String nickname = "";
|
||||
|
||||
@Column(length = 128, comment = "[头像地址]")
|
||||
private String avatar = "";
|
||||
|
||||
@Column(length = 32, comment = "[真实姓名]")
|
||||
private String realname = "";
|
||||
|
||||
@Column(length = 32, comment = "[邮箱]")
|
||||
private String email = "";
|
||||
|
||||
@Column(comment = "")
|
||||
private int roleid;
|
||||
|
||||
@Column(length = 128, comment = "[个人博客地址]")
|
||||
private String site = "";
|
||||
|
||||
@Column(length = 128, comment = "[码云/GitHub]")
|
||||
private String git = "";
|
||||
|
||||
@Column(updatable = false, comment = "[创建时间]")
|
||||
private long createtime;
|
||||
|
||||
@Column(length = 256, comment = "[签名]")
|
||||
private String sign = "";
|
||||
|
||||
@Column(length = 64, comment = "[所在城市]")
|
||||
private String city = "";
|
||||
|
||||
@Column(comment = "[状态]-10删除 10正常")
|
||||
private short status = 10;
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public int getUserid() {
|
||||
return this.userid;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
public void setSex(short sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public short getSex() {
|
||||
return this.sex;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return this.phone;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return this.nickname;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return this.avatar;
|
||||
}
|
||||
|
||||
public void setRealname(String realname) {
|
||||
this.realname = realname;
|
||||
}
|
||||
|
||||
public String getRealname() {
|
||||
return this.realname;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return this.email;
|
||||
}
|
||||
|
||||
public void setRoleid(int roleid) {
|
||||
this.roleid = roleid;
|
||||
}
|
||||
|
||||
public int getRoleid() {
|
||||
return this.roleid;
|
||||
}
|
||||
|
||||
public void setSite(String site) {
|
||||
this.site = site;
|
||||
}
|
||||
|
||||
public String getSite() {
|
||||
return this.site;
|
||||
}
|
||||
|
||||
public void setGit(String git) {
|
||||
this.git = git;
|
||||
}
|
||||
|
||||
public String getGit() {
|
||||
return this.git;
|
||||
}
|
||||
|
||||
public void setCreatetime(long createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
public long getCreatetime() {
|
||||
return this.createtime;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public String getSign() {
|
||||
return this.sign;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return this.city;
|
||||
}
|
||||
|
||||
public void setStatus(short status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public short getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
//------
|
||||
|
||||
public UserInfo createUserInfo() {
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setUserid(userid);
|
||||
userInfo.setUsername(username);
|
||||
userInfo.setSex(sex);
|
||||
userInfo.setPassword(password);
|
||||
userInfo.setPhone(phone);
|
||||
userInfo.setNickname(nickname);
|
||||
userInfo.setAvatar(avatar);
|
||||
userInfo.setRelaname(realname);
|
||||
userInfo.setEmail(email);
|
||||
userInfo.setRoleid(roleid);
|
||||
userInfo.setSite(site);
|
||||
userInfo.setGit(git);
|
||||
userInfo.setCreatetime(createtime);
|
||||
userInfo.setSign(sign);
|
||||
userInfo.setCity(city);
|
||||
userInfo.setStatus(getStatus());
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
public String passwordForMd5(){
|
||||
return md5IfNeed(password);
|
||||
}
|
||||
|
||||
public static String md5IfNeed(String password){
|
||||
return Utility.md5Hex(password);
|
||||
}
|
||||
}
|
179
src/net/tccn/bbs/base/user/UserService.java
Normal file
179
src/net/tccn/bbs/base/user/UserService.java
Normal file
@@ -0,0 +1,179 @@
|
||||
package com.lxyer.bbs.base.user;
|
||||
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.lxyer.bbs.base.BaseService;
|
||||
import com.lxyer.bbs.base.kit.LxyKit;
|
||||
import com.lxyer.bbs.base.kit.RetCodes;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestParam;
|
||||
import org.redkale.net.http.RestService;
|
||||
import org.redkale.net.http.RestSessionid;
|
||||
import org.redkale.service.RetResult;
|
||||
import org.redkale.source.FilterExpress;
|
||||
import org.redkale.source.FilterFunc;
|
||||
import org.redkale.source.FilterNode;
|
||||
import org.redkale.source.Flipper;
|
||||
import org.redkale.util.SelectColumn;
|
||||
import org.redkale.util.Sheet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
import static com.lxyer.bbs.base.kit.RetCodes.*;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/10/3 14:02.
|
||||
*/
|
||||
@RestService(automapping = true, comment = "用户服务")
|
||||
public class UserService extends BaseService {
|
||||
|
||||
@RestMapping(auth = false, comment = "登录校验")
|
||||
public RetResult<UserInfo> login(@RestParam(name = "bean") LoginBean loginBean){
|
||||
if (loginBean == null || loginBean.emptyUsername()) return RetCodes.retResult(RetCodes.RET_PARAMS_ILLEGAL, "参数错误");
|
||||
|
||||
final RetResult retResult = new RetResult();
|
||||
|
||||
UserRecord user = source.find(UserRecord.class, "username", loginBean.getUsername());
|
||||
if (user == null || !Objects.equals(user.getPassword(), loginBean.getPassword())){
|
||||
//log(null, 0, "用户或密码错误");
|
||||
return RetCodes.retResult(RetCodes.RET_USER_ACCOUNT_PWD_ILLEGAL, "用户名或密码错误");
|
||||
}
|
||||
sessions.setAsync(sessionExpireSeconds, loginBean.getSessionid(), (long)user.getUserid());
|
||||
retResult.setRetcode(0);
|
||||
retResult.setResult(Kv.by("token", loginBean.getSessionid()));
|
||||
retResult.setRetinfo("登录成功.");
|
||||
return retResult;
|
||||
}
|
||||
|
||||
public UserInfo current(String sessionid){
|
||||
if (sessionid == null) return null;
|
||||
|
||||
long userid = 0;
|
||||
try {
|
||||
userid = sessions.getLong(sessionid, 0);
|
||||
sessions.getAndRefresh(sessionid, sessionExpireSeconds);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return userid == 0 ? null : findUserInfo((int)userid);
|
||||
}
|
||||
|
||||
@RestMapping(name = "info", comment = "用户信息")
|
||||
public UserInfo findUserInfo(int userid) {
|
||||
UserRecord user = source.find(UserRecord.class, userid);
|
||||
return user == null ? null : user.createUserInfo();
|
||||
}
|
||||
|
||||
@RestMapping(name = "logout", auth = false, comment = "退出登录")
|
||||
public RetResult logout(@RestSessionid String sessionid){
|
||||
sessions.remove(sessionid);
|
||||
|
||||
return RetResult.success();
|
||||
//return new HttpResult().header("Location", "/").status(302);
|
||||
}
|
||||
|
||||
@RestMapping(name = "query", auth = false, comment = "用户数据查询")
|
||||
public Sheet<UserRecord> queryUser(Flipper flipper, @RestParam(name = "bean", comment = "过滤条件") final UserBean userBean){
|
||||
Sheet<UserRecord> users = source.querySheet(UserRecord.class, flipper, userBean);
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
@RestMapping(name = "changepwd", comment = "修改密码")
|
||||
public RetResult updatePwd(@RestSessionid String sessionid, String pass, String nowpass){
|
||||
UserInfo userInfo = current(sessionid);//不会为空
|
||||
|
||||
if (!Objects.equals(userInfo.getPassword(), UserRecord.md5IfNeed(nowpass)))
|
||||
return RetCodes.retResult(RET_USER_ACCOUNT_PWD_ILLEGAL, "密码错误");
|
||||
if (pass == null || pass.length() < 6 || Objects.equals(pass, nowpass))
|
||||
return RetCodes.retResult(RET_USER_PASSWORD_ILLEGAL, "密码设置无效");
|
||||
source.updateColumn(UserRecord.class, userInfo.getUserid(), "password", UserRecord.md5IfNeed(pass));
|
||||
return RetResult.success();
|
||||
}
|
||||
|
||||
@RestMapping(name = "register", auth = false, comment = "用户注册")
|
||||
public RetResult register(@RestParam(name = "bean") UserRecord user){
|
||||
/*用户名、密码、邮箱*/
|
||||
if (user.getEmail() == null) return RetCodes.retResult(RET_USER_EMAIL_ILLEGAL, "邮件地址无效");
|
||||
if (user.getPassword() == null || user.getPassword().length() < 6) return RetCodes.retResult(RET_USER_PASSWORD_ILLEGAL, "密码设置无效");
|
||||
|
||||
UserRecord _user = source.find(UserRecord.class, FilterNode.create("email", user.getEmail()));
|
||||
if (_user != null) return RetCodes.retResult(RET_USER_USERNAME_EXISTS, "用户名已存在");
|
||||
|
||||
user.setCreatetime(System.currentTimeMillis());
|
||||
user.setPassword(user.passwordForMd5());
|
||||
user.setStatus((short) 10);
|
||||
user.setUsername(user.getEmail());
|
||||
user.setAvatar("/res/images/avatar/"+ new Random().nextInt(21) +".jpg");//默认头像
|
||||
|
||||
int maxId = source.getNumberResult(UserRecord.class, FilterFunc.MAX, 10_0000, "userid").intValue();
|
||||
if (maxId < 10_0000) maxId = 10_0000;
|
||||
user.setUserid(maxId+1);
|
||||
source.insert(user);
|
||||
|
||||
//记录日志
|
||||
return RetResult.success();
|
||||
}
|
||||
|
||||
@RestMapping(name = "update", comment = "用户信息修改")
|
||||
public RetResult userUpdate(@RestSessionid String sessionid, @RestParam(name = "bean") UserRecord user, String[] columns){
|
||||
String nickname = user.getNickname();
|
||||
if (nickname == null && nickname.isEmpty())
|
||||
return RetCodes.retResult(RET_USER_NICKNAME_ILLEGAL, "昵称无效");
|
||||
|
||||
nickname = nickname.replace(" ", "");
|
||||
UserRecord _user = source.find(UserRecord.class, FilterNode.create("nickname", nickname));
|
||||
if (_user != null && _user.getUserid() != currentUserid(sessionid))
|
||||
return RetCodes.retResult(RET_USER_NICKNAME_EXISTS, "昵称已存在");
|
||||
|
||||
user.setNickname(nickname);//去除昵称中的空格
|
||||
source.updateColumn(user
|
||||
,FilterNode.create("userid", currentUserid(sessionid))
|
||||
,SelectColumn.includes(columns)
|
||||
);
|
||||
return RetResult.success();
|
||||
}
|
||||
|
||||
//最新加入
|
||||
public Sheet<UserInfo> lastReg(){
|
||||
Sheet<UserRecord> users = source.querySheet(UserRecord.class
|
||||
, SelectColumn.includes("userid", "nickname", "avatar", "createtime")
|
||||
, new Flipper().sort("createtime DESC").limit(8)
|
||||
, FilterNode.create("status", 10));
|
||||
|
||||
Sheet<UserInfo> infos = new Sheet<>();
|
||||
ArrayList<UserInfo> list = new ArrayList<>();
|
||||
|
||||
users.forEach(x->{
|
||||
UserInfo info = x.createUserInfo();
|
||||
info.setTime(LxyKit.dateFmt(x.getCreatetime()));
|
||||
list.add(info);
|
||||
});
|
||||
|
||||
infos.setRows(list);
|
||||
infos.setTotal(users.getTotal());
|
||||
|
||||
return infos;
|
||||
}
|
||||
|
||||
@RestMapping(name = "usercount", auth = false, comment = "用户数据统计")
|
||||
public Number userCount() {
|
||||
return source.getNumberResult(UserRecord.class, FilterFunc.COUNT, "userid", FilterNode.create("status", FilterExpress.NOTEQUAL, -10));
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true, comment = "判断用户是否是管理员")
|
||||
public boolean isAdmin(int userid){
|
||||
if (userid <= 0) return false;
|
||||
|
||||
List<Integer> userIds = source.queryColumnList("userid", UserRecord.class, FilterNode.create("roleid", 1));
|
||||
for (Integer x : userIds) {
|
||||
if (userid == x) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
141
src/net/tccn/bbs/comment/Comment.java
Normal file
141
src/net/tccn/bbs/comment/Comment.java
Normal file
@@ -0,0 +1,141 @@
|
||||
package com.lxyer.bbs.comment;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
import com.lxyer.bbs.base.UF;
|
||||
import com.lxyer.bbs.base.iface.C;
|
||||
import com.lxyer.bbs.base.iface.UI;
|
||||
import com.lxyer.bbs.base.kit.LxyKit;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lxyer
|
||||
*/
|
||||
@Cacheable(interval = 5*60)
|
||||
@Table(catalog = "redbbs", name = "sys_comment", comment = "[评论表]")
|
||||
public class Comment implements Serializable, C<CommentInfo> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(comment = "[评论id]")
|
||||
private int commentid;
|
||||
|
||||
@Column(comment = "[评论用户id]")
|
||||
private int userid;
|
||||
|
||||
@Column(comment = "[评论父id]")
|
||||
private int pid;
|
||||
|
||||
@Column(comment = "[评论的类型]")
|
||||
private short cate = 1;
|
||||
|
||||
@Column(comment = "[被评论内容的id]")
|
||||
private int contentid;
|
||||
|
||||
@Column(comment = "[评论内容]")
|
||||
private String content = "";
|
||||
|
||||
@Column(updatable = false, comment = "[创建时间]")
|
||||
private long createtime;
|
||||
|
||||
@Column(comment = "[支持数]")
|
||||
private int supportnum;
|
||||
|
||||
@Column(comment = "[状态]1正常,-1删除")
|
||||
private short status = 10;
|
||||
|
||||
public void setCommentid(int commentid) {
|
||||
this.commentid = commentid;
|
||||
}
|
||||
|
||||
public int getCommentid() {
|
||||
return this.commentid;
|
||||
}
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public int getUserid() {
|
||||
return this.userid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return this.pid;
|
||||
}
|
||||
|
||||
public void setCate(short cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public short getCate() {
|
||||
return this.cate;
|
||||
}
|
||||
|
||||
public void setContentid(int contentid) {
|
||||
this.contentid = contentid;
|
||||
}
|
||||
|
||||
public int getContentid() {
|
||||
return this.contentid;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return this.content;
|
||||
}
|
||||
|
||||
public void setCreatetime(long createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
public long getCreatetime() {
|
||||
return this.createtime;
|
||||
}
|
||||
|
||||
public void setSupportnum(int supportnum) {
|
||||
this.supportnum = supportnum;
|
||||
}
|
||||
|
||||
public int getSupportnum() {
|
||||
return this.supportnum;
|
||||
}
|
||||
|
||||
public void setStatus(short status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public short getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
public CommentInfo createInfo(){
|
||||
CommentInfo info = new CommentInfo();
|
||||
info.setCommentid(commentid);
|
||||
info.setUserid(userid);
|
||||
info.setPid(pid);
|
||||
info.setCate(cate);
|
||||
info.setContentid(contentid);
|
||||
info.setContent(content);
|
||||
info.setSupportnum(supportnum);
|
||||
info.setStatus(status);
|
||||
|
||||
info.setCreatetime(LxyKit.dateFmt(createtime));
|
||||
return info;
|
||||
}
|
||||
}
|
163
src/net/tccn/bbs/comment/CommentInfo.java
Normal file
163
src/net/tccn/bbs/comment/CommentInfo.java
Normal file
@@ -0,0 +1,163 @@
|
||||
package com.lxyer.bbs.comment;
|
||||
|
||||
import com.lxyer.bbs.base.iface.CI;
|
||||
import com.lxyer.bbs.base.iface.UI;
|
||||
import com.lxyer.bbs.base.user.UserRecord;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lxyer
|
||||
*/
|
||||
public class CommentInfo implements UI<CommentInfo>,Serializable, CI<CommentInfo> {
|
||||
|
||||
@Column(comment = "[评论id]")
|
||||
private int commentid;
|
||||
|
||||
@Column(comment = "[评论用户id]")
|
||||
private int userid;
|
||||
|
||||
@Column(comment = "[评论父id]")
|
||||
private int pid;
|
||||
|
||||
@Column(comment = "[评论的类型]")
|
||||
private int cate;
|
||||
|
||||
@Column(comment = "[被评论内容的id]")
|
||||
private int contentid;
|
||||
|
||||
@Column(comment = "[评论内容]")
|
||||
private String content = "";
|
||||
|
||||
@Column(comment = "[支持数]")
|
||||
private int supportnum;
|
||||
|
||||
@Column(comment = "[状态]1正常,-1删除")
|
||||
private int status = 1;
|
||||
|
||||
|
||||
private String createtime;
|
||||
|
||||
private CommentInfo pCommentInfo;
|
||||
|
||||
private String title;
|
||||
private int hadsupport = -1;
|
||||
|
||||
public void setCommentid(int commentid) {
|
||||
this.commentid = commentid;
|
||||
}
|
||||
|
||||
public int getCommentid() {
|
||||
return this.commentid;
|
||||
}
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public int getUserid() {
|
||||
return this.userid;
|
||||
}
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
public void setPid(int pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
public int getCate() {
|
||||
return cate;
|
||||
}
|
||||
|
||||
public void setCate(int cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public void setContentid(int contentid) {
|
||||
this.contentid = contentid;
|
||||
}
|
||||
|
||||
public int getContentid() {
|
||||
return this.contentid;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public int getSupportnum() {
|
||||
return supportnum;
|
||||
}
|
||||
|
||||
public void setSupportnum(int supportnum) {
|
||||
this.supportnum = supportnum;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public String getCreatetime() {
|
||||
return createtime;
|
||||
}
|
||||
|
||||
public void setCreatetime(String createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
public CommentInfo getpCommentInfo() {
|
||||
return pCommentInfo;
|
||||
}
|
||||
|
||||
public void setpCommentInfo(CommentInfo pCommentInfo) {
|
||||
this.pCommentInfo = pCommentInfo;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public int getHadsupport() {
|
||||
return hadsupport;
|
||||
}
|
||||
|
||||
public void setHadsupport(int hadsupport) {
|
||||
this.hadsupport = hadsupport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
//----
|
||||
private UserRecord user;
|
||||
|
||||
@Override
|
||||
public UserRecord getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentInfo setUser(UserRecord user) {
|
||||
this.user = user;
|
||||
return this;
|
||||
}
|
||||
}
|
134
src/net/tccn/bbs/comment/CommentService.java
Normal file
134
src/net/tccn/bbs/comment/CommentService.java
Normal file
@@ -0,0 +1,134 @@
|
||||
package com.lxyer.bbs.comment;
|
||||
|
||||
import com.lxyer.bbs.base.BaseService;
|
||||
import com.lxyer.bbs.base.entity.ActLog;
|
||||
import com.lxyer.bbs.base.iface.UIService;
|
||||
import com.lxyer.bbs.base.kit.LxyKit;
|
||||
import com.lxyer.bbs.base.kit.RetCodes;
|
||||
import com.lxyer.bbs.content.Content;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestParam;
|
||||
import org.redkale.net.http.RestService;
|
||||
import org.redkale.net.http.RestSessionid;
|
||||
import org.redkale.service.RetResult;
|
||||
import org.redkale.source.*;
|
||||
import org.redkale.util.SelectColumn;
|
||||
import org.redkale.util.Sheet;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.lxyer.bbs.base.kit.RetCodes.RET_COMMENT_CONTENT_ILLEGAL;
|
||||
import static com.lxyer.bbs.base.kit.RetCodes.RET_COMMENT_PARA_ILLEGAL;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/11/29 10:00.
|
||||
*/
|
||||
@RestService(automapping = true, comment = "评论服务")
|
||||
public class CommentService extends BaseService implements UIService<CommentInfo> {
|
||||
|
||||
@RestMapping(name = "save", comment = "评论保存")
|
||||
public RetResult commentSave(@RestSessionid String sessionid, @RestParam(name = "bean") Comment comment){
|
||||
int contentid = comment.getContentid();
|
||||
|
||||
//数据校验
|
||||
if (contentid < 1)
|
||||
return RetCodes.retResult(RET_COMMENT_PARA_ILLEGAL, "评论参数无效");
|
||||
if (comment.getContent() == null)
|
||||
return RetCodes.retResult(RET_COMMENT_CONTENT_ILLEGAL, "评论内容无效");
|
||||
String content = LxyKit.delHTMLTag(comment.getContent());
|
||||
if (content.isEmpty())
|
||||
return RetCodes.retResult(RET_COMMENT_CONTENT_ILLEGAL, "评论内容无效");
|
||||
|
||||
if (comment.getCommentid() < 1) {
|
||||
int userid = currentUserid(sessionid);
|
||||
comment.setUserid(userid);
|
||||
comment.setCreatetime(System.currentTimeMillis());
|
||||
//todo:@用户处理
|
||||
source.insert(comment);
|
||||
|
||||
//update replyNum
|
||||
int count = source.getNumberResult(Comment.class, FilterFunc.COUNT, "commentid", FilterNode.create("contentid", contentid)).intValue();
|
||||
source.updateColumn(Content.class, contentid, ColumnValue.create("replynum", count));
|
||||
}else {
|
||||
source.updateColumn(comment, SelectColumn.includes("content"));
|
||||
}
|
||||
return RetResult.success();
|
||||
}
|
||||
|
||||
@RestMapping(name = "query", auth = false,comment = "查询评论")
|
||||
public Sheet<CommentInfo> commentQuery(@RestSessionid String sessionid , int contentId, Flipper flipper){
|
||||
int userid = currentUserid(sessionid);
|
||||
|
||||
flipper.setSort("supportnum DESC,commentid ASC");
|
||||
Sheet<Comment> comments = source.querySheet(Comment.class, flipper, FilterNode.create("contentid", contentId));
|
||||
|
||||
Sheet<CommentInfo> infos = createInfo(comments);
|
||||
setIUser(infos);
|
||||
|
||||
//用户点赞的评论
|
||||
if (userid > 0){
|
||||
int[] commentids = comments.stream().mapToInt(Comment::getCommentid).toArray();
|
||||
FilterNode node = FilterNode.create("cate", 10).and("status", 10).and("userid", userid).and("tid", FilterExpress.IN, commentids);
|
||||
List<Integer> hadSupport = source.queryColumnList("tid", ActLog.class, node);
|
||||
|
||||
infos.forEach(x->{
|
||||
x.setHadsupport(hadSupport.contains(x.getCommentid()) ? 1 : -1);//
|
||||
});
|
||||
}
|
||||
|
||||
return infos;
|
||||
}
|
||||
|
||||
@RestMapping(ignore = true, comment = "查询用户评论数据")
|
||||
public Sheet<CommentInfo> queryByUserid(int userid){
|
||||
Sheet<Comment> comments = source.querySheet(Comment.class, new Flipper().sort("createtime DESC"), FilterNode.create("userid", userid));
|
||||
|
||||
int[] contentIds = comments.stream().mapToInt(x -> x.getCommentid()).toArray();
|
||||
List<Content> contents = source.queryList(Content.class, SelectColumn.includes("contentid","title"), FilterNode.create("contentid", FilterExpress.IN, contentIds));
|
||||
|
||||
Sheet<CommentInfo> infos = createInfo(comments);
|
||||
infos.forEach(x->{
|
||||
Content content = contents.stream().filter(k -> k.getContentid() == x.getContentid()).findFirst().orElse(new Content());
|
||||
x.setTitle(content.getTitle());
|
||||
});
|
||||
return infos;
|
||||
}
|
||||
|
||||
@RestMapping(name = "support", comment = "点赞")
|
||||
public RetResult support(@RestSessionid String sessionid, int commentid, int ok){
|
||||
int userid = currentUserid(sessionid);
|
||||
|
||||
source.findAsync(ActLog.class, FilterNode.create("userid", userid).and("tid", commentid).and("cate", 10)).thenAccept(actLog -> {
|
||||
if (actLog == null && ok == 1){
|
||||
actLog = new ActLog(10, commentid, userid);
|
||||
actLog.setCreatetime(System.currentTimeMillis());
|
||||
source.insert(actLog);
|
||||
}else if (actLog != null && actLog.getStatus() != ok){
|
||||
actLog.setStatus((short) -10);
|
||||
source.update(actLog);
|
||||
}/*else {
|
||||
return RetCodes.retResult(-1, ok == 1 ? "已赞" : "已取消赞");
|
||||
}*/
|
||||
|
||||
int count = source.getNumberResult(ActLog.class, FilterFunc.COUNT, 0, "logid", FilterNode.create("tid", commentid).and("status", 10)).intValue();
|
||||
source.updateColumn(Comment.class, commentid,"supportnum", count);
|
||||
});
|
||||
|
||||
return RetResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* todo:用户评论榜 待完成
|
||||
* @return
|
||||
*/
|
||||
@RestMapping(ignore = true, name = "rankuser", auth = false, comment = "用户评论榜")
|
||||
public Map<String, Number> commentRank(){
|
||||
Flipper flipper = new Flipper().limit(8);
|
||||
source.querySheet(Comment.class, flipper, FilterNode.create("userid", FilterExpress.IN));
|
||||
|
||||
Map<String, Number> numberMap = source.getNumberMap(Comment.class, FilterFuncColumn.create(FilterFunc.DISTINCTCOUNT, "userid"));
|
||||
|
||||
return numberMap;
|
||||
}
|
||||
}
|
202
src/net/tccn/bbs/content/Content.java
Normal file
202
src/net/tccn/bbs/content/Content.java
Normal file
@@ -0,0 +1,202 @@
|
||||
package com.lxyer.bbs.content;
|
||||
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.lxyer.bbs.base.iface.C;
|
||||
import com.lxyer.bbs.base.kit.LxyKit;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lxyer
|
||||
*/
|
||||
@Cacheable(interval = 5*60)
|
||||
@Table(catalog = "redbbs", name = "sys_content", comment = "[内容表]")
|
||||
public class Content implements Serializable, C<ContentInfo> {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(comment = "[内容id]")
|
||||
private int contentid;
|
||||
|
||||
@Column(comment = "[用户id]")
|
||||
private int userid;
|
||||
|
||||
@Column(length = 64, comment = "[标题]")
|
||||
private String title = "";
|
||||
|
||||
@Column(length = 256, comment = "[摘要]")
|
||||
private String digest = "";
|
||||
|
||||
@Column(comment = "[内容]")
|
||||
private String content = "";
|
||||
|
||||
@Column(updatable = false, comment = "[创建时间]")
|
||||
private long createtime;
|
||||
|
||||
@Column(comment = "[类别]")
|
||||
private short cate;
|
||||
|
||||
@Column(comment = "[内容栏目]10求助,20分享,30建议,40公告,50动态")
|
||||
private short type;
|
||||
|
||||
@Column(comment = "[评论数]")
|
||||
private int replynum;
|
||||
|
||||
@Column(comment = "[阅读量]")
|
||||
private int viewnum;
|
||||
|
||||
@Column(comment = "[精] 10否,20是")
|
||||
private short wonderful = 10;
|
||||
|
||||
@Column(comment = "[置顶]10否,20是")
|
||||
private short top = 10;
|
||||
|
||||
@Column(comment = "[结帖]10否,20是")
|
||||
private short solved = 10;
|
||||
|
||||
@Column(comment = "[状态] -10删除 10未结帖 20结帖 30私密")
|
||||
private short status = 10;
|
||||
|
||||
public void setContentid(int contentid) {
|
||||
this.contentid = contentid;
|
||||
}
|
||||
|
||||
public int getContentid() {
|
||||
return this.contentid;
|
||||
}
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public int getUserid() {
|
||||
return this.userid;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void setDigest(String digest) {
|
||||
this.digest = digest;
|
||||
}
|
||||
|
||||
public String getDigest() {
|
||||
return this.digest;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return this.content;
|
||||
}
|
||||
|
||||
public void setCreatetime(long createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
public long getCreatetime() {
|
||||
return this.createtime;
|
||||
}
|
||||
|
||||
public void setCate(short cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public short getCate() {
|
||||
return this.cate;
|
||||
}
|
||||
|
||||
public void setType(short type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public short getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setReplynum(int replynum) {
|
||||
this.replynum = replynum;
|
||||
}
|
||||
|
||||
public int getReplynum() {
|
||||
return this.replynum;
|
||||
}
|
||||
|
||||
public void setViewnum(int viewnum) {
|
||||
this.viewnum = viewnum;
|
||||
}
|
||||
|
||||
public int getViewnum() {
|
||||
return this.viewnum;
|
||||
}
|
||||
|
||||
public void setWonderful(short wonderful) {
|
||||
this.wonderful = wonderful;
|
||||
}
|
||||
|
||||
public short getWonderful() {
|
||||
return this.wonderful;
|
||||
}
|
||||
|
||||
public void setTop(short top) {
|
||||
this.top = top;
|
||||
}
|
||||
|
||||
public short getTop() {
|
||||
return this.top;
|
||||
}
|
||||
|
||||
public void setSolved(short solved) {
|
||||
this.solved = solved;
|
||||
}
|
||||
|
||||
public short getSolved() {
|
||||
return this.solved;
|
||||
}
|
||||
|
||||
public void setStatus(short status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public short getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
private static final Kv types = Kv.by(10, "求助").set(20, "分享").set(30, "讨论").set(40, "公告").set(50, "动态");
|
||||
|
||||
@Override
|
||||
public ContentInfo createInfo() {
|
||||
ContentInfo info = new ContentInfo();
|
||||
info.setContentid(contentid);
|
||||
info.setUserid(userid);
|
||||
info.setTitle(title);
|
||||
info.setContent(content);
|
||||
info.setCate(cate);
|
||||
info.setType(type);
|
||||
info.setViewnum(viewnum);
|
||||
info.setReplynum(replynum);
|
||||
info.setWonderful(wonderful);
|
||||
info.setTop(top);
|
||||
info.setSolved(solved);
|
||||
info.setStatus(status);
|
||||
|
||||
info.setTypename(types.getOrDefault((int)type, "其他").toString());
|
||||
info.setCreatetime(LxyKit.dateFmt(createtime));
|
||||
return info;
|
||||
}
|
||||
}
|
146
src/net/tccn/bbs/content/ContentBean.java
Normal file
146
src/net/tccn/bbs/content/ContentBean.java
Normal file
@@ -0,0 +1,146 @@
|
||||
package com.lxyer.bbs.content;
|
||||
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.source.FilterBean;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lxyer
|
||||
*/
|
||||
@Table(catalog = "db_redbbs", name = "content", comment = "[内容表]")
|
||||
public class ContentBean implements FilterBean,java.io.Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(comment = "[内容id]")
|
||||
private int contentid;
|
||||
|
||||
@Column(comment = "[用户id]")
|
||||
private int userid;
|
||||
|
||||
@Column(length = 64, comment = "[标题]")
|
||||
private String title = "";
|
||||
|
||||
@Column(length = 256, comment = "[摘要]")
|
||||
private String digest = "";
|
||||
|
||||
@Column(comment = "[内容]")
|
||||
private String content = "";
|
||||
|
||||
@Column(comment = "[创建时间]")
|
||||
private long createtime;
|
||||
|
||||
@Column(comment = "[类别]")
|
||||
private int cate;
|
||||
|
||||
@Column(comment = "[内容类型]1新闻,2作品")
|
||||
private int type;
|
||||
|
||||
@Column(comment = "[评论数]")
|
||||
private int replynum;
|
||||
|
||||
@Column(comment = "[阅读量]")
|
||||
private int viewnum;
|
||||
|
||||
/* @Column(comment = "[精] 0否,1是")
|
||||
private int wonderful;
|
||||
|
||||
@Column(comment = "[置顶] 0否,1是")
|
||||
private int top;
|
||||
|
||||
@Column(comment = "[结帖]大于0结帖")
|
||||
private int solved;
|
||||
|
||||
@Column(comment = "[状态]")
|
||||
private int status = 1;*/
|
||||
|
||||
public void setContentid(int contentid) {
|
||||
this.contentid = contentid;
|
||||
}
|
||||
|
||||
public int getContentid() {
|
||||
return this.contentid;
|
||||
}
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public int getUserid() {
|
||||
return this.userid;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void setDigest(String digest) {
|
||||
this.digest = digest;
|
||||
}
|
||||
|
||||
public String getDigest() {
|
||||
return this.digest;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public void setCreatetime(long createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
public long getCreatetime() {
|
||||
return this.createtime;
|
||||
}
|
||||
|
||||
public int getCate() {
|
||||
return cate;
|
||||
}
|
||||
|
||||
public void setCate(int cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public int getReplynum() {
|
||||
return replynum;
|
||||
}
|
||||
|
||||
public void setReplynum(int replynum) {
|
||||
this.replynum = replynum;
|
||||
}
|
||||
|
||||
public int getViewnum() {
|
||||
return viewnum;
|
||||
}
|
||||
|
||||
public void setViewnum(int viewnum) {
|
||||
this.viewnum = viewnum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
}
|
175
src/net/tccn/bbs/content/ContentInfo.java
Normal file
175
src/net/tccn/bbs/content/ContentInfo.java
Normal file
@@ -0,0 +1,175 @@
|
||||
package com.lxyer.bbs.content;
|
||||
|
||||
import com.lxyer.bbs.base.iface.CI;
|
||||
import com.lxyer.bbs.base.iface.UI;
|
||||
import com.lxyer.bbs.base.user.UserRecord;
|
||||
import org.redkale.convert.ConvertColumn;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/11/26 20:52.
|
||||
*/
|
||||
public class ContentInfo implements UI<ContentInfo>,Serializable, CI {
|
||||
|
||||
private int contentid;
|
||||
private int userid;
|
||||
private String title = "";
|
||||
private String digest = "";
|
||||
private String content = "";
|
||||
private String createtime;
|
||||
private int cate;
|
||||
private int type;
|
||||
private int replynum;
|
||||
private int viewnum;
|
||||
private int wonderful;
|
||||
private int top;
|
||||
private int solved;
|
||||
private int status = 10;
|
||||
|
||||
private String typename;
|
||||
private int hadcollect = -1;
|
||||
|
||||
public int getContentid() {
|
||||
return contentid;
|
||||
}
|
||||
|
||||
public void setContentid(int contentid) {
|
||||
this.contentid = contentid;
|
||||
}
|
||||
|
||||
public int getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(int userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDigest() {
|
||||
return digest;
|
||||
}
|
||||
|
||||
public void setDigest(String digest) {
|
||||
this.digest = digest;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public int getCate() {
|
||||
return cate;
|
||||
}
|
||||
|
||||
public void setCate(int cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getReplynum() {
|
||||
return replynum;
|
||||
}
|
||||
|
||||
public void setReplynum(int replynum) {
|
||||
this.replynum = replynum;
|
||||
}
|
||||
|
||||
public int getViewnum() {
|
||||
return viewnum;
|
||||
}
|
||||
|
||||
public void setViewnum(int viewnum) {
|
||||
this.viewnum = viewnum;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getWonderful() {
|
||||
return wonderful;
|
||||
}
|
||||
|
||||
public void setWonderful(int wonderful) {
|
||||
this.wonderful = wonderful;
|
||||
}
|
||||
|
||||
public int getTop() {
|
||||
return top;
|
||||
}
|
||||
|
||||
public void setTop(int top) {
|
||||
this.top = top;
|
||||
}
|
||||
|
||||
public int getSolved() {
|
||||
return solved;
|
||||
}
|
||||
|
||||
public void setSolved(int solved) {
|
||||
this.solved = solved;
|
||||
}
|
||||
|
||||
public String getCreatetime() {
|
||||
return createtime;
|
||||
}
|
||||
|
||||
public void setCreatetime(String createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
public String getTypename() {
|
||||
return typename;
|
||||
}
|
||||
|
||||
public void setTypename(String typename) {
|
||||
this.typename = typename;
|
||||
}
|
||||
|
||||
public int getHadcollect() {
|
||||
return hadcollect;
|
||||
}
|
||||
|
||||
public void setHadcollect(int hadcollect) {
|
||||
this.hadcollect = hadcollect;
|
||||
}
|
||||
|
||||
|
||||
//-----------
|
||||
private UserRecord user;
|
||||
@ConvertColumn(ignore = true)
|
||||
@Override
|
||||
public UserRecord getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentInfo setUser(UserRecord user) {
|
||||
this.user = user;
|
||||
return this;
|
||||
}
|
||||
}
|
190
src/net/tccn/bbs/content/ContentService.java
Normal file
190
src/net/tccn/bbs/content/ContentService.java
Normal file
@@ -0,0 +1,190 @@
|
||||
package com.lxyer.bbs.content;
|
||||
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.lxyer.bbs.base.BaseService;
|
||||
import com.lxyer.bbs.base.entity.ActLog;
|
||||
import com.lxyer.bbs.base.iface.UIService;
|
||||
import com.lxyer.bbs.base.kit.RetCodes;
|
||||
import com.lxyer.bbs.base.user.UserInfo;
|
||||
import com.lxyer.bbs.base.user.UserService;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.service.RetResult;
|
||||
import org.redkale.source.*;
|
||||
import org.redkale.util.Comment;
|
||||
import org.redkale.util.SelectColumn;
|
||||
import org.redkale.util.Sheet;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/11/26 9:33.
|
||||
*/
|
||||
@RestService(automapping = true, comment = "文章帖子服务")
|
||||
public class ContentService extends BaseService implements UIService<ContentInfo> {
|
||||
|
||||
@Resource
|
||||
protected UserService userService;
|
||||
|
||||
@RestMapping(ignore = true, comment = "根据条件查询帖子数据")
|
||||
public Sheet<ContentInfo> contentQuery(Flipper flipper, FilterNode filterNode){
|
||||
Sheet<Content> contents = source.querySheet(Content.class, flipper, filterNode);
|
||||
|
||||
createInfo(contents);
|
||||
Sheet<ContentInfo> infos = createInfo(contents);
|
||||
setIUser(infos);
|
||||
|
||||
return infos;
|
||||
}
|
||||
|
||||
@RestMapping(name = "query", auth = false, comment = "内容列表")
|
||||
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, -10);
|
||||
switch (actived){
|
||||
case "top": filterNode.and("top", FilterExpress.GREATERTHANOREQUALTO, 20);break;
|
||||
case "untop": filterNode.and("top", 10);break;
|
||||
case "unsolved": filterNode.and("solved", 10);break;
|
||||
case "solved": filterNode.and("solved", 20);break;
|
||||
case "wonderful": filterNode.and("wonderful", FilterExpress.GREATERTHANOREQUALTO, 20);break;
|
||||
}
|
||||
|
||||
if (!userService.isAdmin(currentid)){//私密贴:非管理员限制查看
|
||||
filterNode.and(FilterNode.create("status", FilterExpress.NOTEQUAL, 30).or(FilterNode.create("status", 30).and("userid", currentid)));
|
||||
}else if (currentid <= 0){//私密贴:未登录限制查看
|
||||
filterNode.and("status", FilterExpress.NOTEQUAL, 30);
|
||||
}
|
||||
|
||||
return contentQuery(flipper, filterNode);
|
||||
}
|
||||
|
||||
|
||||
@RestMapping(name = "save", comment = "帖子保存")
|
||||
public RetResult contentSave(@RestParam(name = "bean")Content content, @RestSessionid String sessionid){
|
||||
//数据校验
|
||||
if (content.getTitle().isEmpty() || content.getTitle().length() > 64){
|
||||
return RetCodes.retResult(-1, "少年你的文章标题太长啦,精简化标题吧,为了更好的SEO长度请少于64个字节");
|
||||
}
|
||||
|
||||
int userid = currentUserid(sessionid);
|
||||
|
||||
if (content.getContentid() < 1){
|
||||
int maxId = source.getNumberResult(Content.class, FilterFunc.MAX, 10_0000, "contentid").intValue();
|
||||
content.setContentid(maxId+1);
|
||||
content.setCreatetime(System.currentTimeMillis());
|
||||
content.setUserid(userid);
|
||||
|
||||
source.insert(content);
|
||||
}else {
|
||||
source.findAsync(Content.class, content.getContentid()).thenAccept(x->{
|
||||
if (x.getUserid() == userid || userService.isAdmin(userid)){//身份验证 后修改内容
|
||||
source.updateColumnAsync(content,SelectColumn.includes("title", "digest", "content","type", "status"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return RetResult.success();
|
||||
}
|
||||
|
||||
@RestMapping(name = "info", auth = false, comment = "帖子详情")
|
||||
public ContentInfo contentInfo(@RestSessionid String sessionid, int contentid){
|
||||
int userId = userService.currentUserid(sessionid);
|
||||
|
||||
Content content = source.find(Content.class, contentid);
|
||||
if (content == null) return null;
|
||||
|
||||
ContentInfo contentInfo = setIUser(content.createInfo());
|
||||
|
||||
//收藏状态
|
||||
if (userId > 0){
|
||||
ActLog actLog = source.find(ActLog.class, FilterNode.create("cate", 20).and("tid", contentid).and("status", 10));
|
||||
if (actLog != null) contentInfo.setHadcollect(1);
|
||||
}
|
||||
return contentInfo;
|
||||
}
|
||||
|
||||
@RestMapping(name = "collect", comment = "帖子收藏")
|
||||
public RetResult collect(@RestSessionid String sessionid, int contentid, int ok){
|
||||
int userid = userService.currentUserid(sessionid);//不会为空
|
||||
|
||||
ActLog actLog = source.find(ActLog.class, FilterNode.create("userid", userid).and("tid", contentid).and("cate", 20));
|
||||
if (actLog == null && ok == 1){
|
||||
actLog = new ActLog(20, contentid, userid);//.cate(2).tid(contentId).userId(userId);
|
||||
actLog.setCreatetime(System.currentTimeMillis());
|
||||
source.insert(actLog);
|
||||
}else if (actLog != null && actLog.getStatus() != ok){
|
||||
actLog.setStatus((short) ok);
|
||||
actLog.setCreatetime(System.currentTimeMillis());
|
||||
source.update(actLog);
|
||||
}else {
|
||||
return RetCodes.retResult(-1, ok == 1 ? "已收藏" : "已取消收藏");
|
||||
}
|
||||
|
||||
return RetResult.success();
|
||||
}
|
||||
|
||||
@RestMapping(name = "collectquery", comment = "收藏列表")
|
||||
public Sheet<ContentInfo> collectQuery(@RestSessionid String sessionid){
|
||||
int userid = currentUserid(sessionid);
|
||||
|
||||
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.includes("tid", "createtime"), flipper, filterNode);
|
||||
|
||||
int[] contentids = actLogs.stream().mapToInt(x -> x.getTid()).toArray();
|
||||
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);
|
||||
|
||||
return infos;
|
||||
}
|
||||
|
||||
@RestMapping(name = "set", comment = "便捷的修改内容")
|
||||
public RetResult contentSet(@RestSessionid String sessionid,
|
||||
@Comment("帖子id") int id,
|
||||
@Comment("status|top|wonderful") String field,
|
||||
@Comment("目标修改值")short v){
|
||||
//只有管理员可访问
|
||||
int userid = currentUserid(sessionid);
|
||||
//身份验证 后修改内容
|
||||
source.findAsync(Content.class, id).thenAccept(content -> {
|
||||
if (content.getUserid() == userid && userService.isAdmin(userid)){//管理员可以做更多
|
||||
//field: status|top|wonderful
|
||||
// update content set {field}={v} where id={id}
|
||||
source.updateColumn(Content.class, id, field, v);
|
||||
}else if (content.getUserid() == userid && ("status".equals(field))){//非管理员只能修改状态
|
||||
source.updateColumn(Content.class, id, field, v);
|
||||
}
|
||||
});
|
||||
return RetResult.success();
|
||||
}
|
||||
|
||||
@RestMapping(name = "t",auth = false, comment = "测试HttpScope 模板使用")
|
||||
public HttpScope t(@RestSessionid String sessionid){
|
||||
ContentService contentService = this;
|
||||
Flipper flipper = new Flipper().limit(30).sort("top DESC,createtime DESC");
|
||||
//置顶贴
|
||||
FilterNode topNode = FilterNode.create("status", FilterExpress.NOTEQUAL, -10).and("top", FilterExpress.GREATERTHANOREQUALTO, 20);
|
||||
Sheet<ContentInfo> top = contentService.contentQuery(flipper, topNode);
|
||||
|
||||
//非置顶贴
|
||||
FilterNode untopNode = FilterNode.create("status", FilterExpress.NOTEQUAL, -10).and("top", 0);
|
||||
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, untopNode);
|
||||
|
||||
//热议
|
||||
Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
|
||||
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", sessionid);
|
||||
|
||||
//最新加入
|
||||
Sheet<UserInfo> lastReg = userService.lastReg();
|
||||
|
||||
Kv kv = Kv.by("top", top)
|
||||
.set("contents", contents)
|
||||
.set("hotReply", hotReply)
|
||||
.set("lastReg", lastReg);
|
||||
|
||||
return HttpScope.refer("index.html").attr(kv);
|
||||
}
|
||||
|
||||
}
|
97
src/net/tccn/bbs/servlet/ContentServlet.java
Normal file
97
src/net/tccn/bbs/servlet/ContentServlet.java
Normal file
@@ -0,0 +1,97 @@
|
||||
package com.lxyer.bbs.servlet;
|
||||
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.lxyer.bbs.base.BaseServlet;
|
||||
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 static org.redkale.source.FilterExpress.NOTEQUAL;
|
||||
|
||||
/**
|
||||
* 帖子相关
|
||||
* Created by liangxianyou at 2018/6/4 13:15.
|
||||
*/
|
||||
@WebServlet(value = {"/jie" ,"/jie/*","/column","/column/*"}, comment = "文章帖子入口")
|
||||
public class ContentServlet extends BaseServlet {
|
||||
@HttpMapping(url = "/jie", auth = false, comment = "问答列表")
|
||||
public void jie(HttpRequest request, HttpResponse response){
|
||||
String actived = getPara(request, 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, request.getSessionid(false));
|
||||
|
||||
Kv kv = Kv.by("contents", contents).set("url", request.getRequestURI())
|
||||
.set("actived", actived).set("curr", curr);
|
||||
|
||||
response.finish(HttpScope.refer("/jie/index.html").attr(kv));
|
||||
}
|
||||
|
||||
@HttpMapping(url = "/jie/add", comment = "发表/编辑问答")
|
||||
@HttpParam(name = "#", type = int.class, comment = "内容ID")
|
||||
public void add(HttpRequest request, HttpResponse response){
|
||||
int contentid = getParaToInt(request, 0);
|
||||
|
||||
ContentInfo contentInfo = null;
|
||||
if (contentid > 0){
|
||||
contentInfo = contentService.contentInfo(request.getSessionid(false), contentid);
|
||||
}
|
||||
|
||||
Kv kv = Kv.by("bean", contentInfo);
|
||||
response.finish(HttpScope.refer("/jie/add.html").attr(kv));
|
||||
}
|
||||
|
||||
@HttpMapping(url = "/jie/detail", auth = false, comment = "问答详情")
|
||||
public void detail(HttpRequest request, HttpResponse response){
|
||||
int contentid = getParaToInt(request,0);
|
||||
String sessionid = request.getSessionid(false);
|
||||
|
||||
ContentInfo content = contentService.contentInfo(sessionid, contentid);
|
||||
Sheet<CommentInfo> comments = commentService.commentQuery(sessionid,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, "", sessionid);*/
|
||||
|
||||
Sheet<ContentInfo> hotView = logQueue.hotView(sessionid);
|
||||
|
||||
Kv kv = Kv.by("bean", content).set("comments", comments).set("hotView", hotView)/*.set("hotReply", hotReply)*/;
|
||||
response.finish(HttpScope.refer("/jie/detail.html").attr(kv));
|
||||
}
|
||||
|
||||
@HttpMapping(url = "/column", auth = false, comment = "帖子栏目")
|
||||
public void column(HttpRequest request, HttpResponse response){
|
||||
String sessionid = request.getSessionid(false);
|
||||
|
||||
String para = getPara(request);//空,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, -10).and("type", column.getAs(para));
|
||||
if (solved > 0) filterNode.and("solved", 20);
|
||||
if (wonderful > 0) filterNode.and("wonderful", 20);
|
||||
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(request, setPrivate(request, filterNode)));
|
||||
|
||||
//热帖
|
||||
Sheet<ContentInfo> hotView = logQueue.hotView(sessionid);
|
||||
|
||||
Kv kv = Kv.by("contents", contents).set("hotView", hotView)
|
||||
.set("solved", solved).set("wonderful", wonderful)
|
||||
.set("column", para).set("curr", curr);
|
||||
response.finish(HttpScope.refer("/jie/index.html").attr(kv));
|
||||
}
|
||||
}
|
51
src/net/tccn/bbs/servlet/FileServlet.java
Normal file
51
src/net/tccn/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(value = {"/upload","/upload/*"}, comment = "文件管理入口")
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
83
src/net/tccn/bbs/servlet/IndexServlet.java
Normal file
83
src/net/tccn/bbs/servlet/IndexServlet.java
Normal file
@@ -0,0 +1,83 @@
|
||||
package com.lxyer.bbs.servlet;
|
||||
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.lxyer.bbs.base.BaseServlet;
|
||||
import com.lxyer.bbs.base.user.UserInfo;
|
||||
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 static org.redkale.source.FilterExpress.GREATERTHANOREQUALTO;
|
||||
import static org.redkale.source.FilterExpress.NOTEQUAL;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/11/25 12:31.
|
||||
*/
|
||||
@WebServlet(value = {"/","/project" /* ,"/article","/article/*" */}, comment = "首页一级菜单入口")
|
||||
public class IndexServlet extends BaseServlet {
|
||||
|
||||
@HttpMapping(url = "/", auth = false, comment = "社区首页")
|
||||
public void abc(HttpRequest request, HttpResponse response){
|
||||
|
||||
String sessionid = request.getSessionid(false);
|
||||
|
||||
Flipper flipper = new Flipper().limit(15).sort("top DESC,createtime DESC");
|
||||
//置顶贴
|
||||
FilterNode topNode = FilterNode.create("status", NOTEQUAL, -10).and("top", GREATERTHANOREQUALTO, 20);
|
||||
Sheet<ContentInfo> top = contentService.contentQuery(flipper, setPrivate(request, topNode));
|
||||
|
||||
//非置顶贴
|
||||
FilterNode untopNode = FilterNode.create("status", NOTEQUAL, -10).and("top", 10);
|
||||
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(request, untopNode));
|
||||
|
||||
//热帖
|
||||
/*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, "", sessionid);*/
|
||||
|
||||
Sheet<ContentInfo> hotView = logQueue.hotView(sessionid);
|
||||
|
||||
//最新加入
|
||||
Sheet<UserInfo> lastReg = userService.lastReg();
|
||||
|
||||
//用户统计
|
||||
Number userCount = userService.userCount();
|
||||
|
||||
Kv kv = Kv.by("top", top).set("contents", contents).set("hotView", hotView).set("lastReg", lastReg).set("userCount", userCount);
|
||||
response.finish(HttpScope.refer("index.html").attr(kv));
|
||||
}
|
||||
|
||||
@HttpMapping(url = "/site", auth = false, comment = "网站首页")
|
||||
public void site(HttpRequest request, HttpResponse response){
|
||||
|
||||
response.finish(HttpScope.refer("/site.html"));
|
||||
}
|
||||
|
||||
//====================================文章相关====================================
|
||||
/*@HttpMapping(url = "/article", auth = false, comment = "文章首页")
|
||||
public void article(HttpRequest request, HttpResponse response){
|
||||
|
||||
finish("/article/index.html");
|
||||
}*/
|
||||
|
||||
//====================================项目相关====================================
|
||||
@HttpMapping(url = "/project", auth = false, comment = "项目首页")
|
||||
public void project(HttpRequest request, HttpResponse response){
|
||||
String sessionid = request.getSessionid(false);
|
||||
int contentid = 22;
|
||||
|
||||
ContentInfo content = contentService.contentInfo(sessionid, contentid);
|
||||
Sheet<CommentInfo> comments = commentService.commentQuery(sessionid,contentid, new Flipper().limit(30));
|
||||
|
||||
Kv kv = Kv.by("bean", content).set("comments", comments);
|
||||
response.finish(HttpScope.refer("/project/index.html").attr(kv));
|
||||
}
|
||||
|
||||
}
|
100
src/net/tccn/bbs/servlet/UserServlet.java
Normal file
100
src/net/tccn/bbs/servlet/UserServlet.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package com.lxyer.bbs.servlet;
|
||||
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.lxyer.bbs.base.BaseServlet;
|
||||
import com.lxyer.bbs.base.user.UserBean;
|
||||
import com.lxyer.bbs.base.user.UserInfo;
|
||||
import com.lxyer.bbs.base.user.UserRecord;
|
||||
import com.lxyer.bbs.comment.CommentInfo;
|
||||
import com.lxyer.bbs.content.ContentInfo;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.source.FilterExpress;
|
||||
import org.redkale.source.FilterNode;
|
||||
import org.redkale.source.Flipper;
|
||||
import org.redkale.util.Sheet;
|
||||
|
||||
/**
|
||||
* 用户相关的servlet
|
||||
* Created by liangxianyou at 2018/6/4 13:12.
|
||||
*/
|
||||
@WebServlet(value = {"/user", "/user/*"}, comment = "用户请求入口")
|
||||
public class UserServlet extends BaseServlet {
|
||||
|
||||
|
||||
@HttpMapping(url = "/user/login", auth = false, comment = "前往登录页")
|
||||
public void login(HttpRequest request, HttpResponse response){
|
||||
|
||||
response.finish(HttpScope.refer("/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));*/
|
||||
|
||||
response.finish(HttpScope.refer("/user/login.html"));
|
||||
}
|
||||
|
||||
@HttpMapping(url = "/user/set", auth = true, comment = "用户设置")
|
||||
public void set(HttpRequest request, HttpResponse response){
|
||||
response.finish(HttpScope.refer("/user/set.html"));
|
||||
}
|
||||
|
||||
|
||||
@HttpMapping(url = "/user", auth = false, comment = "用户首页")
|
||||
public void user(HttpRequest request, HttpResponse response){
|
||||
String para = getPara(request);
|
||||
|
||||
//-------个人中心---------
|
||||
if ("user".equals(para) || "".equals(para)){
|
||||
UserInfo user = request.currentUser();
|
||||
if (user == null){
|
||||
response.finish(HttpScope.refer("/user/login.html"));
|
||||
return;
|
||||
}
|
||||
|
||||
//创建的帖子
|
||||
Flipper flipper = new Flipper().limit(8).sort("createtime DESC");
|
||||
|
||||
FilterNode node = FilterNode.create("userid", user.getUserid()).and("status", FilterExpress.NOTEQUAL, -10);
|
||||
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(request, node));//queryByBean(flipper, bean);
|
||||
|
||||
//收藏的帖子
|
||||
Sheet<ContentInfo> collects = contentService.collectQuery(request.getSessionid(false));
|
||||
|
||||
Kv kv = Kv.by("contents", contents).set("collects", collects);
|
||||
response.finish(HttpScope.refer("/user/index.html").attr(kv));
|
||||
return;
|
||||
}
|
||||
|
||||
//-------用户主页------
|
||||
int userid = 0;
|
||||
if ("nick".equals(para)){//通过@ 点击跳转
|
||||
String nickname = request.getParameter("nickname");
|
||||
UserBean userBean = new UserBean();
|
||||
userBean.setNickname(nickname);
|
||||
Sheet<UserRecord> users = userService.queryUser(new Flipper().limit(1), userBean);
|
||||
if (users.getTotal() > 0){
|
||||
userid = users.stream().findFirst().orElse(null).getUserid();
|
||||
}
|
||||
}else {//直接访问
|
||||
userid = getParaToInt(request,0);
|
||||
}
|
||||
|
||||
//用户信息
|
||||
UserInfo user = userService.findUserInfo(userid);
|
||||
|
||||
//帖子
|
||||
Flipper flipper = new Flipper().limit(8).sort("createtime DESC");
|
||||
FilterNode node = FilterNode.create("userid", userid).and("status", FilterExpress.NOTEQUAL, -10);
|
||||
Sheet<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(request,node));
|
||||
|
||||
//回复
|
||||
Sheet<CommentInfo> comments = commentService.queryByUserid(userid);
|
||||
|
||||
Kv kv = Kv.by("contents", contents).set("user", user).set("comments", comments);
|
||||
response.finish(HttpScope.refer("/user/home.html").attr(kv));
|
||||
}
|
||||
}
|
109
src/net/tccn/redim/ChatWebSocket.java
Normal file
109
src/net/tccn/redim/ChatWebSocket.java
Normal file
@@ -0,0 +1,109 @@
|
||||
package com.lxyer.redim;
|
||||
|
||||
import com.lxyer.base.JBean;
|
||||
import com.lxyer.redim.entity.MsgRecord;
|
||||
import com.lxyer.redim.info.MsgInfo;
|
||||
import com.lxyer.redim.service.ImFriendService;
|
||||
import com.lxyer.redim.service.ImMsgService;
|
||||
import org.redkale.net.http.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
*
|
||||
* Created by liangxianyou at 2018/7/8 22:51.
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
@RestWebSocket(name = "chat", catalog = "ws", comment = "文字聊天", anyuser = true)
|
||||
public class ChatWebSocket extends WebSocket {
|
||||
|
||||
@Resource
|
||||
protected ImMsgService chatService;
|
||||
@Resource
|
||||
protected ImFriendService imFriendService;
|
||||
|
||||
protected Random random = new Random();
|
||||
|
||||
@Override
|
||||
protected CompletableFuture<String> onOpen(HttpRequest request) {
|
||||
String token = request.getParameter("token");
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
if (token == null) {
|
||||
setAttribute("isyk", true);
|
||||
return request.getSessionid(false);
|
||||
}
|
||||
return token;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture createUserid() {
|
||||
return CompletableFuture.supplyAsync(()-> {
|
||||
int userid = 0;
|
||||
|
||||
//fixme: 1、isyk => tour; 2、set cate to user global
|
||||
if (getAttribute("isyk") == null){//tour
|
||||
userid = imFriendService.currentUserid(getSessionid());
|
||||
setAttribute("isyk", true);
|
||||
}
|
||||
|
||||
//如果未获取登录信息,使用token.hashCode 负值 作为登录用户
|
||||
if (userid == 0){
|
||||
//MsgInfo msgInfo = new MsgInfo();
|
||||
userid = - Math.abs(getSessionid().hashCode());
|
||||
}
|
||||
|
||||
//接收离线信息
|
||||
int finalUserid = userid;
|
||||
CompletableFuture.runAsync(()->{
|
||||
JBean<List<MsgRecord>> list = chatService.offlineMsg(finalUserid);
|
||||
List<MsgRecord> recordList = list.getResult();
|
||||
|
||||
if (recordList != null && recordList.size() > 0){
|
||||
recordList.forEach(msgRecord->{
|
||||
JBean<MsgInfo> msgInfo = chatService.createMsgInfo(msgRecord);
|
||||
send(msgInfo.getResult()).thenAccept(x->{
|
||||
if ((Integer)x == 0){//发送成功
|
||||
msgRecord.setStatus((short) 20);
|
||||
}
|
||||
chatService.update(msgRecord);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return userid;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preOnMessage(String restmapping, WebSocketParam param, Runnable messageEvent) {
|
||||
super.preOnMessage(restmapping, param, messageEvent);
|
||||
}
|
||||
|
||||
@RestOnMessage(name = "text")
|
||||
public void onChatMessage(MsgRecord msg, Map<String, String> extmap) {
|
||||
msg.setFromuserid((Integer) getUserid());
|
||||
|
||||
JBean<MsgInfo> msgInfo = chatService.createMsgInfo(msg);
|
||||
|
||||
sendMessage(msgInfo.getResult(), msg.getTouserid()).thenAccept(x->{
|
||||
if ((Integer)x == 0){//发送成功
|
||||
msg.setStatus((short) 20);
|
||||
}
|
||||
chatService.insert(msg);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@RestOnMessage(name = "close")
|
||||
public void onClose(int code, String reason) {
|
||||
System.out.println("close!");
|
||||
super.onClose(code, reason);
|
||||
}
|
||||
}
|
16
src/net/tccn/redim/RedbbsListener.java
Normal file
16
src/net/tccn/redim/RedbbsListener.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.lxyer.redim;
|
||||
|
||||
import com.lxyer.redim.impl.ImFriendServiceImpl;
|
||||
import org.redkale.boot.Application;
|
||||
import org.redkale.boot.ApplicationListener;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/8/10 22:51.
|
||||
*/
|
||||
public class RedbbsListener implements ApplicationListener {
|
||||
|
||||
@Override
|
||||
public void preStart(Application application) {
|
||||
ImFriendServiceImpl.application = application;
|
||||
}
|
||||
}
|
87
src/net/tccn/redim/entity/MsgRecord.java
Normal file
87
src/net/tccn/redim/entity/MsgRecord.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package com.lxyer.redim.entity;
|
||||
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lxyer
|
||||
*/
|
||||
@Cacheable(interval = 5*60)
|
||||
@Table(catalog = "redbbs", name = "im_msgrecord", comment = "[聊天记录表]")
|
||||
public class MsgRecord implements java.io.Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(comment = "[主键id]")
|
||||
private int msgid;
|
||||
|
||||
@Column(comment = "[发送人]")
|
||||
private int fromuserid;
|
||||
|
||||
@Column(comment = "[接收人]")
|
||||
private int touserid;
|
||||
|
||||
@Column(comment = "[内容]")
|
||||
private String content = "";
|
||||
|
||||
@Column(updatable = false, comment = "[发送时间]")
|
||||
private long createtime = System.currentTimeMillis();
|
||||
|
||||
@Column(comment = "[状态]-10删除,10未发送 20已发送 30已读")
|
||||
private short status = 10;
|
||||
|
||||
public void setMsgid(int msgid) {
|
||||
this.msgid = msgid;
|
||||
}
|
||||
|
||||
public int getMsgid() {
|
||||
return this.msgid;
|
||||
}
|
||||
|
||||
public void setFromuserid(int fromuserid) {
|
||||
this.fromuserid = fromuserid;
|
||||
}
|
||||
|
||||
public int getFromuserid() {
|
||||
return this.fromuserid;
|
||||
}
|
||||
|
||||
public void setTouserid(int touserid) {
|
||||
this.touserid = touserid;
|
||||
}
|
||||
|
||||
public int getTouserid() {
|
||||
return this.touserid;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public void setCreatetime(long createtime) {
|
||||
this.createtime = createtime;
|
||||
}
|
||||
|
||||
public long getCreatetime() {
|
||||
return this.createtime;
|
||||
}
|
||||
|
||||
public void setStatus(short status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public short getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
}
|
124
src/net/tccn/redim/impl/ImFriendServiceImpl.java
Normal file
124
src/net/tccn/redim/impl/ImFriendServiceImpl.java
Normal file
@@ -0,0 +1,124 @@
|
||||
package com.lxyer.redim.impl;
|
||||
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.lxyer.base.JBean;
|
||||
import com.lxyer.bbs.base.BaseService;
|
||||
import com.lxyer.bbs.base.user.UserInfo;
|
||||
import com.lxyer.bbs.base.user.UserRecord;
|
||||
import com.lxyer.bbs.base.user.UserService;
|
||||
import com.lxyer.redim.service.ImFriendService;
|
||||
import org.redkale.boot.Application;
|
||||
import org.redkale.net.TransportFactory;
|
||||
import org.redkale.net.TransportGroupInfo;
|
||||
import org.redkale.net.http.RestService;
|
||||
import org.redkale.source.FilterExpress;
|
||||
import org.redkale.source.FilterNode;
|
||||
import org.redkale.util.ResourceType;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ResourceType(ImFriendService.class)
|
||||
@RestService(name = "imfriend",automapping = true, comment = "好友管理")
|
||||
public class ImFriendServiceImpl extends BaseService implements ImFriendService {
|
||||
|
||||
@Resource
|
||||
UserService userService;
|
||||
|
||||
@Resource
|
||||
public static Application application;
|
||||
|
||||
@Override
|
||||
public JBean friends(String sessionid) {
|
||||
List<UserRecord> records = source.queryList(UserRecord.class, FilterNode.create("status", FilterExpress.NOTEQUAL, -10));
|
||||
|
||||
Kv data = Kv.create();
|
||||
|
||||
//mine
|
||||
Kv mine = Kv.by("username", "游客").set("id", "0").set("sign","").set("status", "online").set("avatar", "/res/images/avatar/13.jpg");
|
||||
UserInfo userInfo = userService.current(sessionid);
|
||||
if (userInfo != null){
|
||||
mine.set("username", userInfo.getNickname());
|
||||
mine.set("id", userInfo.getUserid());
|
||||
mine.set("sign", userInfo.getSign());
|
||||
mine.set("avatar", userInfo.getAvatar());
|
||||
mine.set("status", "online");
|
||||
}
|
||||
|
||||
//friend
|
||||
List<Kv> friend = new ArrayList<>();
|
||||
List<Kv> group = new ArrayList<>();
|
||||
|
||||
List<Kv> list = new ArrayList();
|
||||
records.forEach(x->{
|
||||
Kv _friend = Kv.by("id", x.getUserid());
|
||||
_friend.set("username", x.getNickname());
|
||||
_friend.set("sign", x.getSign());
|
||||
_friend.set("avatar", x.getAvatar());
|
||||
_friend.set("status", "online");
|
||||
list.add(_friend);
|
||||
});
|
||||
|
||||
//把自己排在最上面
|
||||
List<Kv> _list = list.stream().sorted(Comparator.comparing(x -> !x.getStr("username").equals(mine.getStr("username")))).collect(Collectors.toList());
|
||||
|
||||
friend.add(Kv.by("groupname", "默认分组").set("id", 1).set("online", _list.size()).set("list", _list));
|
||||
group.add(Kv.by("groupname", "默认分组").set("id", 1).set("avatar", "/res/images/avatar/13.jpg"));
|
||||
|
||||
data.set("mine", mine).set("friend", friend).set("group", group);
|
||||
|
||||
return JBean.by(Kv.by("code", 0).set("msg", "").set("data", data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JBean friendList(String sessionid) {
|
||||
|
||||
/*SncpClient sncpClient = new SncpClient("", ImFriendService.class, this, transportFactory,
|
||||
true, this.getClass(), new InetSocketAddress("192.168.227.1", 7070));*/
|
||||
|
||||
|
||||
TransportFactory sncpTransportFactory = application.getSncpTransportFactory();
|
||||
TransportGroupInfo groupInfo = sncpTransportFactory.findGroupInfo("ALL");
|
||||
|
||||
System.out.println(groupInfo.toString());
|
||||
|
||||
groupInfo.putAddress(new InetSocketAddress("120.24.230.60", 7070));
|
||||
|
||||
|
||||
//sncpTransportFactory.addGroupInfo(groupInfo);
|
||||
|
||||
|
||||
|
||||
return friends(sessionid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JBean groups(String sessionid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JBean itemSave(String sessionid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JBean addFriend(String sessionid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JBean groupSave(String sessionid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JBean addGroup(String sessionid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
93
src/net/tccn/redim/impl/ImMsgServiceImpl.java
Normal file
93
src/net/tccn/redim/impl/ImMsgServiceImpl.java
Normal file
@@ -0,0 +1,93 @@
|
||||
package com.lxyer.redim.impl;
|
||||
|
||||
import com.lxyer.base.JBean;
|
||||
import com.lxyer.bbs.base.BaseService;
|
||||
import com.lxyer.bbs.base.user.UserRecord;
|
||||
import com.lxyer.redim.entity.MsgRecord;
|
||||
import com.lxyer.redim.info.MsgInfo;
|
||||
import com.lxyer.redim.service.ImMsgService;
|
||||
import org.redkale.net.http.RestService;
|
||||
import org.redkale.source.FilterNode;
|
||||
import org.redkale.util.ResourceType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/8/12 13:10.
|
||||
*/
|
||||
@ResourceType(ImMsgService.class)
|
||||
@RestService(name = "immsg",automapping = true, comment = "聊天记录管理")
|
||||
public class ImMsgServiceImpl extends BaseService implements ImMsgService {
|
||||
|
||||
/**
|
||||
* 消息入库
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
@Override
|
||||
public JBean insert(MsgRecord... msg) {
|
||||
source.insertAsync(msg);
|
||||
return JBean.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息修改
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
@Override
|
||||
public JBean update(MsgRecord ... msg) {
|
||||
source.updateAsync(msg);
|
||||
return JBean.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 历史消息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public JBean list() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建消息体
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
@Override
|
||||
public JBean<MsgInfo> createMsgInfo(MsgRecord msg) {
|
||||
MsgInfo info = new MsgInfo();
|
||||
int fromuserid = msg.getFromuserid();
|
||||
|
||||
UserRecord userRecord;
|
||||
if (fromuserid > 0){
|
||||
userRecord = source.find(UserRecord.class, fromuserid);
|
||||
info.setUsername(userRecord.getUsername());
|
||||
info.setAvatar(userRecord.getAvatar());
|
||||
info.setType("friend");
|
||||
}else {
|
||||
info.setUsername("游客");
|
||||
info.setAvatar("/res/images/avatar/12.jpg");
|
||||
info.setType("friend");
|
||||
}
|
||||
|
||||
info.setId(msg.getFromuserid());
|
||||
info.setContent(msg.getContent());
|
||||
info.setCid(msg.getMsgid());
|
||||
info.setMine(false);
|
||||
info.setFromid(msg.getFromuserid());
|
||||
info.setTimestamp(msg.getCreatetime());
|
||||
|
||||
return JBean.by(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JBean<List<MsgRecord>> offlineMsg(int userid) {
|
||||
List<MsgRecord> records = source.queryList(MsgRecord.class, FilterNode.create("touserid", userid).and("status", 10));
|
||||
return JBean.by(records);
|
||||
}
|
||||
|
||||
|
||||
}
|
101
src/net/tccn/redim/info/MsgInfo.java
Normal file
101
src/net/tccn/redim/info/MsgInfo.java
Normal file
@@ -0,0 +1,101 @@
|
||||
package com.lxyer.redim.info;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/8/12 15:04.
|
||||
*/
|
||||
public class MsgInfo {
|
||||
|
||||
private String username;
|
||||
private String avatar;
|
||||
private int id;
|
||||
private String type;
|
||||
private String content;
|
||||
private int cid;
|
||||
private boolean mine;
|
||||
private int fromid;
|
||||
private long timestamp;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar;
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public int getCid() {
|
||||
return cid;
|
||||
}
|
||||
|
||||
public void setCid(int cid) {
|
||||
this.cid = cid;
|
||||
}
|
||||
|
||||
public boolean isMine() {
|
||||
return mine;
|
||||
}
|
||||
|
||||
public void setMine(boolean mine) {
|
||||
this.mine = mine;
|
||||
}
|
||||
|
||||
public int getFromid() {
|
||||
return fromid;
|
||||
}
|
||||
|
||||
public void setFromid(int fromid) {
|
||||
this.fromid = fromid;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
/*var message = {
|
||||
username: "纸飞机" //消息来源用户名
|
||||
,avatar: "http://tp1.sinaimg.cn/1571889140/180/40030060651/1" //消息来源用户头像
|
||||
,id: "100000" //消息的来源ID(如果是私聊,则是用户id,如果是群聊,则是群组id)
|
||||
,type: "friend" //聊天窗口来源类型,从发送消息传递的to里面获取
|
||||
,content: "嗨,你好!本消息系离线消息。" //消息内容
|
||||
,cid: 0 //消息id,可不传。除非你要对消息进行一些操作(如撤回)
|
||||
,mine: false //是否我发送的消息,如果为true,则会显示在右方
|
||||
,fromid: "100000" //消息的发送者id(比如群组中的某个消息发送者),可用于自动解决浏览器多窗口时的一些问题
|
||||
,timestamp: 1467475443306 //服务端时间戳毫秒数。注意:如果你返回的是标准的 unix 时间戳,记得要 *1000
|
||||
}*/
|
||||
}
|
59
src/net/tccn/redim/service/ImFriendService.java
Normal file
59
src/net/tccn/redim/service/ImFriendService.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package com.lxyer.redim.service;
|
||||
|
||||
import com.lxyer.base.JBean;
|
||||
import org.redkale.service.Service;
|
||||
|
||||
public interface ImFriendService extends Service {
|
||||
|
||||
//================ 查询相关 =================
|
||||
/**
|
||||
* 分组好友数据
|
||||
* @return
|
||||
*/
|
||||
JBean friends(String sessionid);
|
||||
|
||||
/**
|
||||
* 根据条件查询好友
|
||||
* @return
|
||||
*/
|
||||
JBean friendList(String sessionid);
|
||||
|
||||
/**
|
||||
* 群组数据
|
||||
* @return
|
||||
*/
|
||||
JBean groups(String sessionid);
|
||||
|
||||
|
||||
//================ 操作好友相关 =================
|
||||
/**
|
||||
* 保存好友分组
|
||||
* @return
|
||||
*/
|
||||
JBean itemSave(String sessionid);
|
||||
/**
|
||||
* 添加好友
|
||||
* @return
|
||||
*/
|
||||
JBean addFriend(String sessionid);
|
||||
|
||||
//================ 操作群组相关 =================
|
||||
/**
|
||||
* 保存群组
|
||||
* @return
|
||||
*/
|
||||
JBean groupSave(String sessionid);
|
||||
|
||||
/**
|
||||
* 加入群组
|
||||
* @return
|
||||
*/
|
||||
JBean addGroup(String sessionid);
|
||||
|
||||
/**
|
||||
* 登录人用户id
|
||||
* @param sessionid
|
||||
* @return
|
||||
*/
|
||||
int currentUserid(String sessionid);
|
||||
}
|
43
src/net/tccn/redim/service/ImMsgService.java
Normal file
43
src/net/tccn/redim/service/ImMsgService.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.lxyer.redim.service;
|
||||
|
||||
import com.lxyer.base.JBean;
|
||||
import com.lxyer.redim.entity.MsgRecord;
|
||||
import com.lxyer.redim.info.MsgInfo;
|
||||
import org.redkale.service.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface ImMsgService extends Service {
|
||||
|
||||
/**
|
||||
* 消息入库
|
||||
* @param msg
|
||||
*/
|
||||
JBean insert(MsgRecord... msg);
|
||||
|
||||
/**
|
||||
* 消息修改
|
||||
*/
|
||||
JBean update(MsgRecord... msg);
|
||||
|
||||
/**
|
||||
* 历史消息
|
||||
* @return
|
||||
*/
|
||||
JBean list();
|
||||
|
||||
/**
|
||||
* 创建消息体
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
JBean<MsgInfo> createMsgInfo(MsgRecord msg);
|
||||
|
||||
/**
|
||||
* 获取离线消息
|
||||
* @param userid
|
||||
* @return
|
||||
*/
|
||||
JBean<List<MsgRecord>> offlineMsg(int userid);
|
||||
}
|
30
src/net/tccn/redim/servlet/ImServlet.java
Normal file
30
src/net/tccn/redim/servlet/ImServlet.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.lxyer.redim.servlet;
|
||||
|
||||
import com.lxyer.base.JBean;
|
||||
import com.lxyer.redim.service.ImFriendService;
|
||||
import org.redkale.net.http.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author: liangxianyou at 2018/8/5 23:55.
|
||||
*/
|
||||
@WebServlet(value = {"/imx/*"}, comment = "测试servlet")
|
||||
public class ImServlet extends HttpServlet {
|
||||
|
||||
public Logger log = Logger.getLogger(this.getClass().getSimpleName());
|
||||
|
||||
@Resource
|
||||
ImFriendService imFriendService;
|
||||
|
||||
@HttpMapping(url = "/imx/friends", comment = "测试函数")
|
||||
public void abc(HttpRequest request, HttpResponse response){
|
||||
|
||||
String token = request.getParameter("token");
|
||||
|
||||
JBean jBean = imFriendService.friends(token);
|
||||
response.finish(jBean.getResult());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user