代码格式调整,升级优化

This commit is contained in:
lxyer 2019-12-15 17:10:08 +08:00
parent eb12c48a78
commit 5e0c309aba
40 changed files with 340 additions and 303 deletions

36
pom.xml
View File

@ -7,39 +7,26 @@
<groupId>com.lxyer</groupId>
<artifactId>redbbs</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<finalName>redbbs</finalName>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!--maven 打包使用下面的包 -->
<dependency>
<groupId>org.redkale</groupId>
<artifactId>redkale</artifactId>
<version>2.0.0.alpha1</version>
<version>2.0.0.rc3</version>
</dependency>
<dependency>
<groupId>org.redkalex</groupId>
<artifactId>redkale-plugins</artifactId>
<version>2.0.0.alpha1</version>
<version>2.0.0.rc3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
<version>8.0.18</version>
</dependency>
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>enjoy</artifactId>
@ -60,5 +47,18 @@
</dependency>-->
</dependencies>
<build>
<finalName>redbbs</finalName>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -22,11 +22,6 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util', 'face'], f
if(device.ie && device.ie < 8){
layer.alert('如果您非得使用 IE 浏览器访问社区,那么请使用 IE8+');
}
//1216.top都统一访问到www.1216.top; 考虑SEO
var addr = window.location.href
if(addr.indexOf("1216.top") > -1 && addr.indexOf("www.1216.top") == -1){
window.location.href = addr.replace("1216.top", "www.1216.top");
}
layui.focusInsert = function(obj, str){
var result, val = obj.value;

View File

@ -17,7 +17,7 @@ public class ArangoKit {
protected static final boolean winos = System.getProperty("os.name").contains("Window");
protected static Function<String, String> chDev = (s) -> s + (winos ? "_dev" : "");
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();
@ -50,6 +50,7 @@ public class ArangoKit {
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();
}

View File

@ -22,7 +22,7 @@ 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" : "");
protected Function<String, String> chDev = (s) -> s + (isDev ? "_dev" : "");
@Resource(name = "property.arango.host")
private String arangoHost = "127.0.0.1";
@ -45,18 +45,20 @@ public class ArangoService extends BaseService {
@Override
public void init(AnyValue config) {
System.out.println("isDev :" + isDev);
CompletableFuture.runAsync(() -> {
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));
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();
}
if (!db.exists()) {
db.create();
}
if (!colVisLog.exists()) {
colVisLog.create();
}
});
}
@RestMapping(auth = false)
@ -79,6 +81,7 @@ public class ArangoService extends BaseService {
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();
}

View File

@ -58,15 +58,15 @@ public class BaseService implements Service {
}
@RestMapping(ignore = true)
public int currentUserid(String sessionid){
public int currentUserid(String sessionid) {
if (sessionid == null) return 0;
long userid = 0;
try {
userid = sessions.getLong(sessionid, 0);
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
return (int)userid;
return (int) userid;
}
}

View File

@ -22,6 +22,7 @@ import static net.tccn.bbs.base.kit.RetCodes.RET_USER_UNLOGIN;
/**
* Created by Lxy at 2017/10/3 13:39.
*/
@HttpUserType(UserInfo.class)
public class BaseServlet extends HttpServlet {
protected static final boolean winos = System.getProperty("os.name").contains("Window");
@ -61,26 +62,26 @@ public class BaseServlet extends HttpServlet {
}
String uri = request.getRequestURI();
if (uri.startsWith("/res")){
if (uri.startsWith("/res")) {
File file = new File(webroot + uri);
response.finish(file);
return;
}
if (uri.endsWith(".html")){
if (uri.endsWith(".html")) {
response.finish(HttpScope.refer(uri));
return;
}
//异步记录访问日志
final int userid = currentid;
CompletableFuture.runAsync(()->{
CompletableFuture.runAsync(() -> {
Kv para = Kv.create();
for (String key : request.getParameterNames()){
for (String key : request.getParameterNames()) {
para.set(key, request.getParameter(key));
}
Kv headers = Kv.create();
request.getHeaders().forEach((k,v)->{
request.getHeaders().forEach((k, v) -> {
headers.set(k, request.getHeader(k));
});
@ -106,9 +107,9 @@ public class BaseServlet extends HttpServlet {
@Override
protected void authenticate(HttpRequest request, HttpResponse response) throws IOException {
if (request.currentUser() == null) {
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))){
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) {
response.finish(RetCodes.retResult(RET_USER_UNLOGIN, "未登录,登录后重试").toString());
}else {
} else {
response.finish(HttpScope.refer("/user/login.html"));
}
return;
@ -116,55 +117,60 @@ public class BaseServlet extends HttpServlet {
response.nextEvent();
}
public int getLimit(HttpRequest request){
public int getLimit(HttpRequest request) {
return request.getIntParameter("limit", 1);
}
public int getOffset(HttpRequest request){
public int getOffset(HttpRequest request) {
return request.getIntParameter("offset", 10);
}
public String getPara(HttpRequest request){
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){
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];
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);
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);
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){
public int getParaToInt(HttpRequest request, int index) {
int n = 0;
String para = getPara(request,index);
String para = getPara(request, index);
if (para == null || "".equals(para)) n = 0;
try {
n = Integer.parseInt(para);
}catch (Exception e){
} catch (Exception e) {
}
return n;
}
//设置私密帖子过滤
protected FilterNode setPrivate(HttpRequest request,FilterNode node){
protected FilterNode setPrivate(HttpRequest request, FilterNode node) {
UserInfo userInfo = request.currentUser();
if (userInfo == null){
if (userInfo == null) {
node.and("status", FilterExpress.NOTEQUAL, 30);
}else if (!userService.isAdmin(userInfo.getUserid())){
} 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())));
}

View File

@ -27,15 +27,15 @@ public class FileService extends BaseService {
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{
if (!tmpFile.renameTo(destFile)) {
try {
Files.copy(tmpFile.toPath(), destFile.toPath(), StandardCopyOption.ATOMIC_MOVE);
}finally {
} finally {
tmpFile.delete();//删除临时文件
}
}
RetResult result = RetResult.success();
result.setRetinfo((winos ? "/tem/": view) + path);
result.setRetinfo((winos ? "/tem/" : view) + path);
return result;
}
}

View File

@ -21,12 +21,12 @@ public class JBean<T> /*extends RetResult*/ {
this.retinfo = retinfo;
}
public static JBean by(int retcode, String 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){
public static JBean by(int retcode, String retinfo, Object t) {
JBean jBean = new JBean(retcode, retinfo);
jBean.setResult(t);
return jBean;
@ -68,7 +68,7 @@ public class JBean<T> /*extends RetResult*/ {
this.attach = attach;
}
public JBean attach(String key, Object object){
public JBean attach(String key, Object object) {
if (attach == null)
attach = new HashMap<>();
attach.put(key, object);
@ -76,11 +76,12 @@ public class JBean<T> /*extends RetResult*/ {
}
private static final JBean ok = new JBean(0);
public static JBean ok(){
public static JBean ok() {
return ok;
}
public static JBean faild(String retinfo){
public static JBean faild(String retinfo) {
return new JBean(-1, retinfo);
}

View File

@ -25,7 +25,7 @@ import java.util.function.Function;
/**
* Created by liangxianyou at 2018/6/20 22:54.
*/
@RestService(name = "xxx",automapping = true, comment = "日志记录")
@RestService(name = "xxx", automapping = true, comment = "日志记录")
public class TaskQueue<T extends Object> extends BaseService implements Runnable {
@Resource
@ -63,7 +63,7 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
VisLog visLog = (VisLog) _task;
//[访问量]
String uri = visLog.getUri();
if (uri != null && uri.startsWith("/jie/detail/")){
if (uri != null && uri.startsWith("/jie/detail/")) {
updateViewNum(visLog);
}
});
@ -93,11 +93,11 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
}
@RestMapping(ignore = true, comment = "访问热帖数据")
public Sheet<ContentInfo> hotView(String sessionid){
public Sheet<ContentInfo> hotView(String sessionid) {
int limit = 8;
String cacheKey = "hotView";
Object ids = cacheSource.get(cacheKey);
if (isEmpty.test(ids)){
if (isEmpty.test(ids)) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, -7);
@ -136,9 +136,9 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
//权限过滤
UserInfo userInfo = userService.current(sessionid);
if (userInfo == null){ //访客
if (userInfo == null) { //访客
node.and("status", FilterExpress.NOTEQUAL, 30);
}else if (!userService.isAdmin(userInfo.getUserid())){ //非管理员
} 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);
@ -148,7 +148,7 @@ public class TaskQueue<T extends Object> extends BaseService implements Runnable
* TODO:帖子访客记录 --待完成
*/
@RestMapping(ignore = true, comment = "帖子访客记录")
public Sheet<Map> readRecordAsync(Flipper flipper ,int contentid){
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());

View File

@ -8,5 +8,6 @@ import net.tccn.bbs.base.iface.UI;
*/
public interface UF<I extends UI> {
int getUserid();
I createInfo();
}

View File

@ -7,7 +7,6 @@ import javax.persistence.Column;
import java.io.Serializable;
/**
*
* @author lxyer
*/
public class ActLogBean implements Serializable, FilterBean {

View File

@ -1,18 +1,17 @@
package net.tccn.bbs.base.entity;
import org.redkale.convert.json.JsonConvert;
import javax.persistence.*;
import org.redkale.convert.json.*;
/**
*
* @author lxyer
*/
@Cacheable(interval = 5*60)
@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;

View File

@ -8,10 +8,9 @@ import javax.persistence.Id;
import javax.persistence.Table;
/**
*
* @author lxyer
*/
@Cacheable(interval = 5*60)
@Cacheable(interval = 5 * 60)
@Table(catalog = "redbbs", name = "sys_dynattr", comment = "[动态属性表]")
public class DynAttr implements java.io.Serializable {

View File

@ -12,16 +12,16 @@ import java.util.List;
public interface CService<I extends UI> {
@RestMapping(ignore = true)
default <A extends C> Sheet<I> createInfo(Sheet<A> fSheet){
default <A extends C> Sheet<I> createInfo(Sheet<A> fSheet) {
Sheet<I> sheet = new Sheet<>();
if (fSheet == null || fSheet.getTotal() < 1){
if (fSheet == null || fSheet.getTotal() < 1) {
sheet.setTotal(0);
sheet.setRows(new ArrayList<>());
}else {
int total = (int)fSheet.getTotal();
} else {
int total = (int) fSheet.getTotal();
List<I> rows = new ArrayList<>(total);
fSheet.forEach(x->rows.add((I)x.createInfo()));
fSheet.forEach(x -> rows.add((I) x.createInfo()));
sheet.setTotal(total);
sheet.setRows(rows);

View File

@ -9,23 +9,29 @@ public interface UI<I extends UI> {
//抽象方法
int getUserid();
UserRecord getUser();
I setUser(UserRecord user);
//默认实现方法
default String getRealname(){
default String getRealname() {
return getUser() == null ? null : getUser().getRealname();
}
default String getNickname(){
default String getNickname() {
return getUser() == null ? null : getUser().getNickname();
}
default String getSite(){
default String getSite() {
return getUser() == null ? "" : getUser().getSite();
}
default String getGit(){
default String getGit() {
return getUser() == null ? "" : getUser().getGit();
}
default String getAvatar(){
default String getAvatar() {
return getUser() == null ? null : getUser().getAvatar();
}
}

View File

@ -17,11 +17,11 @@ public interface UIService<I extends UI> extends CService<I> {
DataSource getSource();
@RestMapping(ignore = true)
default Sheet<I> setIUser(Sheet<I> sheet){
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->{
sheet.forEach(x -> {
UserRecord user = users.stream().filter(u -> u.getUserid() == x.getUserid()).findAny().orElse(null);
x.setUser(user);
});
@ -29,7 +29,7 @@ public interface UIService<I extends UI> extends CService<I> {
}
@RestMapping(ignore = true)
default I setIUser(I i){
default I setIUser(I i) {
UserRecord user = getSource().find(UserRecord.class, i.getUserid());
return (I) i.setUser(user);

View File

@ -12,10 +12,11 @@ import java.text.SimpleDateFormat;
@RestService
public class EJ {
public String date(long time){
public String date(long time) {
return date(time, "yyyy-MM-dd HH:mm:ss");
}
public String date(long time, String pattern){
public String date(long time, String pattern) {
return new SimpleDateFormat(pattern).format(time);
}

View File

@ -10,7 +10,7 @@ import java.util.regex.Pattern;
*/
public final class LxyKit {
public static String dateFmt(long time){
public static String dateFmt(long time) {
/**
* 刚刚 60秒内 60 * 1000
* x分钟前 1小时候内 60 * 60*1000
@ -23,45 +23,45 @@ public final class LxyKit {
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 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标签的正则表达式
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_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_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标签
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){
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){
public static int[] listToArray(List list, int[] ts) {
for (int i = 0; i < list.size(); i++) {
ts[0] = (int) list.get(i);
}

View File

@ -55,7 +55,6 @@ public abstract class RetCodes {
public static final int RET_COMMENT_PARA_ILLEGAL = 3004_0002;
public static RetResult retResult(int retcode) {
return new RetResult(retcode);
}

View File

@ -8,7 +8,6 @@ import javax.persistence.Column;
import javax.persistence.Id;
/**
*
* @author lxyer
*/
public class UserInfo implements java.io.Serializable {
@ -58,7 +57,7 @@ public class UserInfo implements java.io.Serializable {
this.sex = sex;
}
@ConvertColumn(ignore = true,type = ConvertType.JSON)
@ConvertColumn(ignore = true, type = ConvertType.JSON)
public String getPassword() {
return password;
}
@ -178,6 +177,7 @@ public class UserInfo implements java.io.Serializable {
/**
* 检查用户权限
*
* @param moduleid
* @param actionid
* @return

View File

@ -9,10 +9,9 @@ import javax.persistence.Id;
import javax.persistence.Table;
/**
*
* @author lxyer
*/
@Cacheable(interval = 5*60)
@Cacheable(interval = 5 * 60)
@Table(catalog = "redbbs", name = "sys_userrecord")
public class UserRecord implements java.io.Serializable {
@ -221,11 +220,11 @@ public class UserRecord implements java.io.Serializable {
return userInfo;
}
public String passwordForMd5(){
public String passwordForMd5() {
return md5IfNeed(password);
}
public static String md5IfNeed(String password){
public static String md5IfNeed(String password) {
return Utility.md5Hex(password);
}
}

View File

@ -30,44 +30,45 @@ import static net.tccn.bbs.base.kit.RetCodes.*;
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, "参数错误");
public RetResult<UserInfo> login(LoginBean bean) {
if (bean == null || bean.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())){
UserRecord user = source.find(UserRecord.class, "username", bean.getUsername());
if (user == null || !Objects.equals(user.getPassword(), bean.getPassword())) {
//log(null, 0, "用户或密码错误");
return RetCodes.retResult(RetCodes.RET_USER_ACCOUNT_PWD_ILLEGAL, "用户名或密码错误");
}
sessions.setAsync(sessionExpireSeconds, loginBean.getSessionid(), (long)user.getUserid());
sessions.setAsync(sessionExpireSeconds, bean.getSessionid(), (long) user.getUserid());
retResult.setRetcode(0);
retResult.setResult(Kv.by("token", loginBean.getSessionid()));
retResult.setResult(Kv.by("token", bean.getSessionid()));
retResult.setRetinfo("登录成功.");
return retResult;
}
public UserInfo current(String sessionid){
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){
} catch (Exception e) {
e.printStackTrace();
}
return userid == 0 ? null : findUserInfo((int)userid);
return userid == 0 ? null : find((int) userid);
}
@RestMapping(name = "info", comment = "用户信息")
public UserInfo findUserInfo(int userid) {
public UserInfo find(int userid) {
UserRecord user = source.find(UserRecord.class, userid);
return user == null ? null : user.createUserInfo();
UserInfo bean = user.createUserInfo();
return bean;
}
@RestMapping(name = "logout", auth = false, comment = "退出登录")
public RetResult logout(@RestSessionid String sessionid){
public RetResult logout(@RestSessionid String sessionid) {
sessions.remove(sessionid);
return RetResult.success();
@ -75,14 +76,14 @@ public class UserService extends BaseService {
}
@RestMapping(name = "query", auth = false, comment = "用户数据查询")
public Sheet<UserRecord> queryUser(Flipper flipper, @RestParam(name = "bean", comment = "过滤条件") final UserBean userBean){
public Sheet<UserRecord> query(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){
public RetResult updatePwd(@RestSessionid String sessionid, String pass, String nowpass) {
UserInfo userInfo = current(sessionid);//不会为空
if (!Objects.equals(userInfo.getPassword(), UserRecord.md5IfNeed(nowpass)))
@ -94,50 +95,51 @@ public class UserService extends BaseService {
}
@RestMapping(name = "register", auth = false, comment = "用户注册")
public RetResult register(@RestParam(name = "bean") UserRecord user){
public RetResult register(UserRecord bean) {
/*用户名、密码、邮箱*/
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, "密码设置无效");
if (bean.getEmail() == null) return RetCodes.retResult(RET_USER_EMAIL_ILLEGAL, "邮件地址无效");
if (bean.getPassword() == null || bean.getPassword().length() < 6)
return RetCodes.retResult(RET_USER_PASSWORD_ILLEGAL, "密码设置无效");
UserRecord _user = source.find(UserRecord.class, FilterNode.create("email", user.getEmail()));
UserRecord _user = source.find(UserRecord.class, FilterNode.create("email", bean.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");//默认头像
bean.setCreatetime(System.currentTimeMillis());
bean.setPassword(bean.passwordForMd5());
bean.setStatus((short) 10);
bean.setUsername(bean.getEmail());
bean.setAvatar("/res/images/avatar/" + new Random().nextInt(21) + ".jpg");//默认头像
int maxId = source.getNumberResult(UserRecord.class, FilterFunc.MAX, 10_0000, "userid").intValue();
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);
bean.setUserid(maxId + 1);
source.insert(bean);
//记录日志
return RetResult.success();
}
@RestMapping(name = "update", comment = "用户信息修改")
public RetResult userUpdate(@RestSessionid String sessionid, @RestParam(name = "bean") UserRecord user, String[] columns){
String nickname = user.getNickname();
public RetResult userUpdate(UserInfo user, UserRecord bean, String[] columns) {
String nickname = bean.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))
if (_user != null && _user.getUserid() != user.getUserid())
return RetCodes.retResult(RET_USER_NICKNAME_EXISTS, "昵称已存在");
user.setNickname(nickname);//去除昵称中的空格
source.updateColumn(user
,FilterNode.create("userid", currentUserid(sessionid))
,SelectColumn.includes(columns)
bean.setNickname(nickname);//去除昵称中的空格
source.updateColumn(bean
, FilterNode.create("userid", user.getUserid())
, SelectColumn.includes(columns)
);
return RetResult.success();
}
//最新加入
public Sheet<UserInfo> lastReg(){
public Sheet<UserInfo> lastReg() {
Sheet<UserRecord> users = source.querySheet(UserRecord.class
, SelectColumn.includes("userid", "nickname", "avatar", "createtime")
, new Flipper().sort("createtime DESC").limit(8)
@ -146,7 +148,7 @@ public class UserService extends BaseService {
Sheet<UserInfo> infos = new Sheet<>();
ArrayList<UserInfo> list = new ArrayList<>();
users.forEach(x->{
users.forEach(x -> {
UserInfo info = x.createUserInfo();
info.setTime(LxyKit.dateFmt(x.getCreatetime()));
list.add(info);
@ -164,7 +166,7 @@ public class UserService extends BaseService {
}
@RestMapping(ignore = true, comment = "判断用户是否是管理员")
public boolean isAdmin(int userid){
public boolean isAdmin(int userid) {
if (userid <= 0) return false;
List<Integer> userIds = source.queryColumnList("userid", UserRecord.class, FilterNode.create("roleid", 1));

View File

@ -1,23 +1,20 @@
package net.tccn.bbs.comment;
import javax.persistence.*;
import net.tccn.bbs.base.iface.C;
import net.tccn.bbs.base.kit.LxyKit;
import org.redkale.convert.json.*;
import org.redkale.convert.json.JsonConvert;
import javax.persistence.*;
import java.io.Serializable;
/**
*
* @author lxyer
*/
@Cacheable(interval = 5*60)
@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;
@ -122,7 +119,7 @@ public class Comment implements Serializable, C<CommentInfo> {
return JsonConvert.root().convertTo(this);
}
public CommentInfo createInfo(){
public CommentInfo createInfo() {
CommentInfo info = new CommentInfo();
info.setCommentid(commentid);
info.setUserid(userid);

View File

@ -9,10 +9,9 @@ import javax.persistence.Column;
import java.io.Serializable;
/**
*
* @author lxyer
*/
public class CommentInfo implements UI<CommentInfo>,Serializable, CI<CommentInfo> {
public class CommentInfo implements UI<CommentInfo>, Serializable, CI<CommentInfo> {
@Column(comment = "[评论id]")
private int commentid;

View File

@ -24,11 +24,11 @@ import static net.tccn.bbs.base.kit.RetCodes.RET_COMMENT_PARA_ILLEGAL;
/**
* Created by Lxy at 2017/11/29 10:00.
*/
@RestService(automapping = true, comment = "评论服务")
@RestService(name = "comment", comment = "评论服务")
public class CommentService extends BaseService implements UIService<CommentInfo> {
@RestMapping(name = "save", comment = "评论保存")
public RetResult commentSave(@RestSessionid String sessionid, @RestParam(name = "bean") Comment comment){
public RetResult save(@RestSessionid String sessionid, @RestParam(name = "bean") Comment comment) {
int contentid = comment.getContentid();
//数据校验
@ -50,14 +50,14 @@ public class CommentService extends BaseService implements UIService<CommentInfo
//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 {
} 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){
@RestMapping(name = "query", auth = false, comment = "查询评论")
public Sheet<CommentInfo> query(@RestSessionid String sessionid, int contentId, Flipper flipper) {
int userid = currentUserid(sessionid);
flipper.setSort("supportnum DESC,commentid ASC");
@ -67,12 +67,12 @@ public class CommentService extends BaseService implements UIService<CommentInfo
setIUser(infos);
//用户点赞的评论
if (userid > 0){
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->{
infos.forEach(x -> {
x.setHadsupport(hadSupport.contains(x.getCommentid()) ? 1 : -1);//
});
}
@ -80,15 +80,15 @@ public class CommentService extends BaseService implements UIService<CommentInfo
return infos;
}
@RestMapping(ignore = true, comment = "查询用户评论数据")
public Sheet<CommentInfo> queryByUserid(int userid){
@org.redkale.util.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));
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->{
infos.forEach(x -> {
Content content = contents.stream().filter(k -> k.getContentid() == x.getContentid()).findFirst().orElse(new Content());
x.setTitle(content.getTitle());
});
@ -96,15 +96,15 @@ public class CommentService extends BaseService implements UIService<CommentInfo
}
@RestMapping(name = "support", comment = "点赞")
public RetResult support(@RestSessionid String sessionid, int commentid, int ok){
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){
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){
} else if (actLog != null && actLog.getStatus() != ok) {
actLog.setStatus((short) -10);
source.update(actLog);
}/*else {
@ -112,7 +112,7 @@ public class CommentService extends BaseService implements UIService<CommentInfo
}*/
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);
source.updateColumn(Comment.class, commentid, "supportnum", count);
});
return RetResult.success();
@ -120,10 +120,11 @@ public class CommentService extends BaseService implements UIService<CommentInfo
/**
* todo:用户评论榜 待完成
*
* @return
*/
@RestMapping(ignore = true, name = "rankuser", auth = false, comment = "用户评论榜")
public Map<String, Number> commentRank(){
@org.redkale.util.Comment("用户评论榜")
public Map<String, Number> commentRank() {
Flipper flipper = new Flipper().limit(8);
source.querySheet(Comment.class, flipper, FilterNode.create("userid", FilterExpress.IN));

View File

@ -9,15 +9,13 @@ import javax.persistence.*;
import java.io.Serializable;
/**
*
* @author lxyer
*/
@Cacheable(interval = 5*60)
@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;
@ -195,7 +193,7 @@ public class Content implements Serializable, C<ContentInfo> {
info.setSolved(solved);
info.setStatus(status);
info.setTypename(types.getOrDefault((int)type, "其他").toString());
info.setTypename(types.getOrDefault((int) type, "其他").toString());
info.setCreatetime(LxyKit.dateFmt(createtime));
return info;
}

View File

@ -4,19 +4,16 @@ 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 {
public class ContentBean implements FilterBean, java.io.Serializable {
@Id
@GeneratedValue
@Column(comment = "[内容id]")
private int contentid;

View File

@ -10,7 +10,7 @@ import java.io.Serializable;
/**
* Created by Lxy at 2017/11/26 20:52.
*/
public class ContentInfo implements UI<ContentInfo>,Serializable, CI {
public class ContentInfo implements UI<ContentInfo>, Serializable, CI {
private int contentid;
private int userid;
@ -161,6 +161,7 @@ public class ContentInfo implements UI<ContentInfo>,Serializable, CI {
//-----------
private UserRecord user;
@ConvertColumn(ignore = true)
@Override
public UserRecord getUser() {

View File

@ -7,9 +7,15 @@ import net.tccn.bbs.base.iface.UIService;
import net.tccn.bbs.base.kit.RetCodes;
import net.tccn.bbs.base.user.UserInfo;
import net.tccn.bbs.base.user.UserService;
import org.redkale.net.http.*;
import org.redkale.net.http.HttpScope;
import org.redkale.net.http.RestMapping;
import org.redkale.net.http.RestService;
import org.redkale.net.http.RestSessionid;
import org.redkale.service.RetResult;
import org.redkale.source.*;
import org.redkale.source.FilterExpress;
import org.redkale.source.FilterFunc;
import org.redkale.source.FilterNode;
import org.redkale.source.Flipper;
import org.redkale.util.Comment;
import org.redkale.util.SelectColumn;
import org.redkale.util.Sheet;
@ -19,14 +25,14 @@ import javax.annotation.Resource;
/**
* Created by Lxy at 2017/11/26 9:33.
*/
@RestService(automapping = true, comment = "文章帖子服务")
@RestService(name = "content", 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){
@Comment("根据条件查询帖子数据")
public Sheet<ContentInfo> contentQuery(Flipper flipper, FilterNode filterNode) {
Sheet<Content> contents = source.querySheet(Content.class, flipper, filterNode);
createInfo(contents);
@ -37,22 +43,32 @@ public class ContentService extends BaseService implements UIService<ContentInfo
}
@RestMapping(name = "query", auth = false, comment = "内容列表")
public Sheet<ContentInfo> contentQuery(Flipper flipper, String actived, String sessionid){
public Sheet<ContentInfo> query(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;
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)){//私密贴非管理员限制查看
if (!userService.isAdmin(currentid)) {//私密贴非管理员限制查看
filterNode.and(FilterNode.create("status", FilterExpress.NOTEQUAL, 30).or(FilterNode.create("status", 30).and("userid", currentid)));
}else if (currentid <= 0){//私密贴未登录限制查看
} else if (currentid <= 0) {//私密贴未登录限制查看
filterNode.and("status", FilterExpress.NOTEQUAL, 30);
}
@ -61,25 +77,25 @@ public class ContentService extends BaseService implements UIService<ContentInfo
@RestMapping(name = "save", comment = "帖子保存")
public RetResult contentSave(@RestParam(name = "bean")Content content, @RestSessionid String sessionid){
public RetResult save(UserInfo user, Content bean) {
//数据校验
if (content.getTitle().isEmpty() || content.getTitle().length() > 64){
if (bean.getTitle().isEmpty() || bean.getTitle().length() > 64) {
return RetCodes.retResult(-1, "少年你的文章标题太长啦精简化标题吧为了更好的SEO长度请少于64个字节");
}
int userid = currentUserid(sessionid);
int userid = user.getUserid();
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);
if (bean.getContentid() < 1) {
int maxId = source.getNumberResult(Content.class, FilterFunc.MAX, 10_0000, "contentid").intValue();
bean.setContentid(maxId + 1);
bean.setCreatetime(System.currentTimeMillis());
bean.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"));
source.insert(bean);
} else {
source.findAsync(Content.class, bean.getContentid()).thenAccept(x -> {
if (x.getUserid() == userid || userService.isAdmin(userid)) {//身份验证 后修改内容
source.updateColumnAsync(bean, SelectColumn.includes("title", "digest", "content", "type", "status"));
}
});
}
@ -88,8 +104,8 @@ public class ContentService extends BaseService implements UIService<ContentInfo
}
@RestMapping(name = "info", auth = false, comment = "帖子详情")
public ContentInfo contentInfo(@RestSessionid String sessionid, int contentid){
int userId = userService.currentUserid(sessionid);
public ContentInfo info(UserInfo user, int contentid) {
int userId = user != null ? user.getUserid() : 0;
Content content = source.find(Content.class, contentid);
if (content == null) return null;
@ -97,7 +113,7 @@ public class ContentService extends BaseService implements UIService<ContentInfo
ContentInfo contentInfo = setIUser(content.createInfo());
//收藏状态
if (userId > 0){
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);
}
@ -105,19 +121,19 @@ public class ContentService extends BaseService implements UIService<ContentInfo
}
@RestMapping(name = "collect", comment = "帖子收藏")
public RetResult collect(@RestSessionid String sessionid, int contentid, int ok){
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){
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){
} else if (actLog != null && actLog.getStatus() != ok) {
actLog.setStatus((short) ok);
actLog.setCreatetime(System.currentTimeMillis());
source.update(actLog);
}else {
} else {
return RetCodes.retResult(-1, ok == 1 ? "已收藏" : "已取消收藏");
}
@ -125,7 +141,7 @@ public class ContentService extends BaseService implements UIService<ContentInfo
}
@RestMapping(name = "collectquery", comment = "收藏列表")
public Sheet<ContentInfo> collectQuery(@RestSessionid String sessionid){
public Sheet<ContentInfo> collectQuery(@RestSessionid String sessionid) {
int userid = currentUserid(sessionid);
Flipper flipper = new Flipper().sort("createtime DESC");
@ -144,24 +160,24 @@ public class ContentService extends BaseService implements UIService<ContentInfo
public RetResult contentSet(@RestSessionid String sessionid,
@Comment("帖子id") int id,
@Comment("status|top|wonderful") String field,
@Comment("目标修改值")short v){
@Comment("目标修改值") short v) {
//只有管理员可访问
int userid = currentUserid(sessionid);
//身份验证 后修改内容
source.findAsync(Content.class, id).thenAccept(content -> {
if (content.getUserid() == userid && userService.isAdmin(userid)){//管理员可以做更多
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))){//非管理员只能修改状态
} 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){
@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");
//置顶贴
@ -174,7 +190,7 @@ public class ContentService extends BaseService implements UIService<ContentInfo
//热议
Flipper flipper3 = new Flipper().limit(8).sort("replynum DESC");
Sheet<ContentInfo> hotReply = contentService.contentQuery(flipper3, "", sessionid);
Sheet<ContentInfo> hotReply = contentService.query(flipper3, "", sessionid);
//最新加入
Sheet<UserInfo> lastReg = userService.lastReg();

View File

@ -2,6 +2,7 @@ package net.tccn.bbs.servlet;
import com.jfinal.kit.Kv;
import net.tccn.bbs.base.BaseServlet;
import net.tccn.bbs.base.user.UserInfo;
import net.tccn.bbs.comment.CommentInfo;
import net.tccn.bbs.content.ContentInfo;
import org.redkale.net.http.*;
@ -15,16 +16,16 @@ import static org.redkale.source.FilterExpress.NOTEQUAL;
* 帖子相关
* Created by liangxianyou at 2018/6/4 13:15.
*/
@WebServlet(value = {"/jie" ,"/jie/*","/column","/column/*"}, comment = "文章帖子入口")
@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){
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));
Flipper flipper = new Flipper().offset((curr - 1) * 15).limit(15).sort("top DESC,createtime DESC");
Sheet<ContentInfo> contents = contentService.query(flipper, actived, request.getSessionid(false));
Kv kv = Kv.by("contents", contents).set("url", request.getRequestURI())
.set("actived", actived).set("curr", curr);
@ -34,12 +35,14 @@ public class ContentServlet extends BaseServlet {
@HttpMapping(url = "/jie/add", comment = "发表/编辑问答")
@HttpParam(name = "#", type = int.class, comment = "内容ID")
public void add(HttpRequest request, HttpResponse response){
public void add(HttpRequest request, HttpResponse response) {
int contentid = getParaToInt(request, 0);
String sessionid = request.getSessionid(false);
UserInfo user = userService.current(sessionid);
ContentInfo contentInfo = null;
if (contentid > 0){
contentInfo = contentService.contentInfo(request.getSessionid(false), contentid);
if (contentid > 0) {
contentInfo = contentService.info(user, contentid);
}
Kv kv = Kv.by("bean", contentInfo);
@ -47,12 +50,13 @@ public class ContentServlet extends BaseServlet {
}
@HttpMapping(url = "/jie/detail", auth = false, comment = "问答详情")
public void detail(HttpRequest request, HttpResponse response){
int contentid = getParaToInt(request,0);
public void detail(HttpRequest request, HttpResponse response) {
int contentid = getParaToInt(request, 0);
String sessionid = request.getSessionid(false);
UserInfo user = userService.current(sessionid);
ContentInfo content = contentService.contentInfo(sessionid, contentid);
Sheet<CommentInfo> comments = commentService.commentQuery(sessionid,contentid, new Flipper().limit(30));
ContentInfo content = contentService.info(user, contentid);
Sheet<CommentInfo> comments = commentService.query(sessionid, contentid, new Flipper().limit(30));
//热帖
//Flipper flipper2 = new Flipper().limit(8).sort("viewNum DESC");
@ -69,7 +73,7 @@ public class ContentServlet extends BaseServlet {
}
@HttpMapping(url = "/column", auth = false, comment = "帖子栏目")
public void column(HttpRequest request, HttpResponse response){
public void column(HttpRequest request, HttpResponse response) {
String sessionid = request.getSessionid(false);
String para = getPara(request);//qzfxjyggdt
@ -79,7 +83,7 @@ public class ContentServlet extends BaseServlet {
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");
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);

View File

@ -14,7 +14,7 @@ import java.util.Map;
* 文件相关
* Created by liangxianyou at 2018/6/4 13:17.
*/
@WebServlet(value = {"/upload","/upload/*"}, comment = "文件管理入口")
@WebServlet(value = {"/upload", "/upload/*"}, comment = "文件管理入口")
public class FileServlet extends BaseServlet {
private static final String dir = "/var/www/upload/redbbs/";
@ -22,7 +22,7 @@ public class FileServlet extends BaseServlet {
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){
public void uploadImg(HttpRequest request, HttpResponse response) {
try {
Map ret = new HashMap();
ret.put("errno", 0);
@ -32,12 +32,12 @@ public class FileServlet extends BaseServlet {
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);
File destFile = new File((winos ? "E:/wk/own/redbbs/root/tem/" : dir) + path);
destFile.getParentFile().mkdir();
part.save(destFile);
data.add((winos ? "/tem/": view) + path);
data.add((winos ? "/tem/" : view) + path);
}
ret.put("data", data);

View File

@ -17,11 +17,11 @@ import static org.redkale.source.FilterExpress.NOTEQUAL;
/**
* Created by Lxy at 2017/11/25 12:31.
*/
@WebServlet(value = {"/","/project" /* ,"/article","/article/*" */}, comment = "首页一级菜单入口")
@WebServlet(value = {"/", "/project" /* ,"/article","/article/*" */}, comment = "首页一级菜单入口")
public class IndexServlet extends BaseServlet {
@HttpMapping(url = "/", auth = false, comment = "社区首页")
public void abc(HttpRequest request, HttpResponse response){
public void abc(HttpRequest request, HttpResponse response) {
String sessionid = request.getSessionid(false);
@ -55,7 +55,7 @@ public class IndexServlet extends BaseServlet {
}
@HttpMapping(url = "/site", auth = false, comment = "网站首页")
public void site(HttpRequest request, HttpResponse response){
public void site(HttpRequest request, HttpResponse response) {
response.finish(HttpScope.refer("/site.html"));
}
@ -69,12 +69,13 @@ public class IndexServlet extends BaseServlet {
//====================================项目相关====================================
@HttpMapping(url = "/project", auth = false, comment = "项目首页")
public void project(HttpRequest request, HttpResponse response){
public void project(HttpRequest request, HttpResponse response) {
String sessionid = request.getSessionid(false);
UserInfo user = userService.current(sessionid);
int contentid = 22;
ContentInfo content = contentService.contentInfo(sessionid, contentid);
Sheet<CommentInfo> comments = commentService.commentQuery(sessionid,contentid, new Flipper().limit(30));
ContentInfo content = contentService.info(user, contentid);
Sheet<CommentInfo> comments = commentService.query(sessionid, contentid, new Flipper().limit(30));
Kv kv = Kv.by("bean", content).set("comments", comments);
response.finish(HttpScope.refer("/project/index.html").attr(kv));

View File

@ -22,12 +22,13 @@ public class UserServlet extends BaseServlet {
@HttpMapping(url = "/user/login", auth = false, comment = "前往登录页")
public void login(HttpRequest request, HttpResponse response){
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){
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));
@ -38,19 +39,19 @@ public class UserServlet extends BaseServlet {
}
@HttpMapping(url = "/user/set", auth = true, comment = "用户设置")
public void set(HttpRequest request, HttpResponse response){
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){
public void user(HttpRequest request, HttpResponse response) {
String para = getPara(request);
//-------个人中心---------
if ("user".equals(para) || "".equals(para)){
if ("user".equals(para) || "".equals(para)) {
UserInfo user = request.currentUser();
if (user == null){
if (user == null) {
response.finish(HttpScope.refer("/user/login.html"));
return;
}
@ -71,25 +72,25 @@ public class UserServlet extends BaseServlet {
//-------用户主页------
int userid = 0;
if ("nick".equals(para)){//通过@ 点击跳转
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){
Sheet<UserRecord> users = userService.query(new Flipper().limit(1), userBean);
if (users.getTotal() > 0) {
userid = users.stream().findFirst().orElse(null).getUserid();
}
}else {//直接访问
userid = getParaToInt(request,0);
} else {//直接访问
userid = getParaToInt(request, 0);
}
//用户信息
UserInfo user = userService.findUserInfo(userid);
UserInfo user = userService.find(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<ContentInfo> contents = contentService.contentQuery(flipper, setPrivate(request, node));
//回复
Sheet<CommentInfo> comments = commentService.queryByUserid(userid);

View File

@ -14,7 +14,6 @@ import java.util.Random;
import java.util.concurrent.CompletableFuture;
/**
*
* Created by liangxianyou at 2018/7/8 22:51.
*/
@RestWebSocket(name = "chat", catalog = "ws", comment = "文字聊天", anyuser = true)
@ -41,32 +40,32 @@ public class ChatWebSocket extends WebSocket {
@Override
public CompletableFuture createUserid() {
return CompletableFuture.supplyAsync(()-> {
return CompletableFuture.supplyAsync(() -> {
int userid = 0;
//fixme: 1isyk => tour; 2set cate to user global
if (getAttribute("isyk") == null){//tour
if (getAttribute("isyk") == null) {//tour
userid = imFriendService.currentUserid(getSessionid());
setAttribute("isyk", true);
}
//如果未获取登录信息使用token.hashCode 负值 作为登录用户
if (userid == 0){
if (userid == 0) {
//MsgInfo msgInfo = new MsgInfo();
userid = - Math.abs(getSessionid().hashCode());
userid = -Math.abs(getSessionid().hashCode());
}
//接收离线信息
int finalUserid = userid;
CompletableFuture.runAsync(()->{
CompletableFuture.runAsync(() -> {
JBean<List<MsgRecord>> list = chatService.offlineMsg(finalUserid);
List<net.tccn.redim.entity.MsgRecord> recordList = list.getResult();
if (recordList != null && recordList.size() > 0){
recordList.forEach(msgRecord->{
if (recordList != null && recordList.size() > 0) {
recordList.forEach(msgRecord -> {
JBean<net.tccn.redim.info.MsgInfo> msgInfo = chatService.createMsgInfo(msgRecord);
send(msgInfo.getResult()).thenAccept(x->{
if ((Integer)x == 0){//发送成功
send(msgInfo.getResult()).thenAccept(x -> {
if ((Integer) x == 0) {//发送成功
msgRecord.setStatus((short) 20);
}
chatService.update(msgRecord);
@ -90,8 +89,8 @@ public class ChatWebSocket extends WebSocket {
JBean<MsgInfo> msgInfo = chatService.createMsgInfo(msg);
sendMessage(msgInfo.getResult(), msg.getTouserid()).thenAccept(x->{
if ((Integer)x == 0){//发送成功
sendMessage(msgInfo.getResult(), msg.getTouserid()).thenAccept(x -> {
if ((Integer) x == 0) {//发送成功
msg.setStatus((short) 20);
}
chatService.insert(msg);

View File

@ -5,15 +5,13 @@ import org.redkale.convert.json.JsonConvert;
import javax.persistence.*;
/**
*
* @author lxyer
*/
@Cacheable(interval = 5*60)
@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;

View File

@ -23,7 +23,7 @@ import java.util.List;
import java.util.stream.Collectors;
@ResourceType(net.tccn.redim.service.ImFriendService.class)
@RestService(name = "imfriend",automapping = true, comment = "好友管理")
@RestService(name = "imfriend", automapping = true, comment = "好友管理")
public class ImFriendServiceImpl extends BaseService implements ImFriendService {
@Resource
@ -39,9 +39,9 @@ public class ImFriendServiceImpl extends BaseService implements ImFriendService
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");
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){
if (userInfo != null) {
mine.set("username", userInfo.getNickname());
mine.set("id", userInfo.getUserid());
mine.set("sign", userInfo.getSign());
@ -54,7 +54,7 @@ public class ImFriendServiceImpl extends BaseService implements ImFriendService
List<Kv> group = new ArrayList<>();
List<Kv> list = new ArrayList();
records.forEach(x->{
records.forEach(x -> {
Kv _friend = Kv.by("id", x.getUserid());
_friend.set("username", x.getNickname());
_friend.set("sign", x.getSign());
@ -92,7 +92,6 @@ public class ImFriendServiceImpl extends BaseService implements ImFriendService
//sncpTransportFactory.addGroupInfo(groupInfo);
return friends(sessionid);
}

View File

@ -16,7 +16,7 @@ import java.util.List;
* @author: liangxianyou at 2018/8/12 13:10.
*/
@ResourceType(net.tccn.redim.service.ImMsgService.class)
@RestService(name = "immsg",automapping = true, comment = "聊天记录管理")
@RestService(name = "immsg", automapping = true, comment = "聊天记录管理")
public class ImMsgServiceImpl extends BaseService implements ImMsgService {
/**
@ -36,7 +36,7 @@ public class ImMsgServiceImpl extends BaseService implements ImMsgService {
* @param msg
*/
@Override
public JBean update(MsgRecord ... msg) {
public JBean update(MsgRecord... msg) {
source.updateAsync(msg);
return JBean.ok();
}
@ -62,12 +62,12 @@ public class ImMsgServiceImpl extends BaseService implements ImMsgService {
int fromuserid = msg.getFromuserid();
UserRecord userRecord;
if (fromuserid > 0){
if (fromuserid > 0) {
userRecord = source.find(UserRecord.class, fromuserid);
info.setUsername(userRecord.getUsername());
info.setAvatar(userRecord.getAvatar());
info.setType("friend");
}else {
} else {
info.setUsername("游客");
info.setAvatar("/res/images/avatar/12.jpg");
info.setType("friend");

View File

@ -6,52 +6,64 @@ 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
*/

View File

@ -12,6 +12,7 @@ public interface ImMsgService extends Service {
/**
* 消息入库
*
* @param msg
*/
JBean insert(MsgRecord... msg);
@ -23,6 +24,7 @@ public interface ImMsgService extends Service {
/**
* 历史消息
*
* @return
*/
JBean list();
@ -36,6 +38,7 @@ public interface ImMsgService extends Service {
/**
* 获取离线消息
*
* @param userid
* @return
*/

View File

@ -19,7 +19,7 @@ public class ImServlet extends HttpServlet {
ImFriendService imFriendService;
@HttpMapping(url = "/imx/friends", comment = "测试函数")
public void abc(HttpRequest request, HttpResponse response){
public void abc(HttpRequest request, HttpResponse response) {
String token = request.getParameter("token");