.
This commit is contained in:
parent
162eec4a9d
commit
d6a6f315f6
@ -1,6 +1,5 @@
|
|||||||
package com.lxyer.bbs.base;
|
package com.lxyer.bbs.base;
|
||||||
|
|
||||||
import com.lxyer.bbs.base.user.UserInfo;
|
|
||||||
import org.redkale.net.http.RestMapping;
|
import org.redkale.net.http.RestMapping;
|
||||||
import org.redkale.service.Service;
|
import org.redkale.service.Service;
|
||||||
import org.redkale.source.CacheSource;
|
import org.redkale.source.CacheSource;
|
||||||
@ -9,6 +8,9 @@ import org.redkalex.cache.RedisCacheSource;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
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:50.
|
* Created by Lxy at 2017/10/3 13:50.
|
||||||
@ -29,9 +31,6 @@ public class BaseService implements Service {
|
|||||||
@Resource(name = "cacheSource")
|
@Resource(name = "cacheSource")
|
||||||
protected CacheSource cacheSource;
|
protected CacheSource cacheSource;
|
||||||
|
|
||||||
@Resource(name = "userInfos")
|
|
||||||
protected CacheSource<UserInfo> userInfos;
|
|
||||||
|
|
||||||
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||||
|
|
||||||
@RestMapping(ignore = true)
|
@RestMapping(ignore = true)
|
||||||
@ -40,7 +39,7 @@ public class BaseService implements Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(ignore = true)
|
@RestMapping(ignore = true)
|
||||||
public int currentUserId(String sessionid){
|
public int currentUserid(String sessionid){
|
||||||
if (sessionid == null) return 0;
|
if (sessionid == null) return 0;
|
||||||
Object userid = null;
|
Object userid = null;
|
||||||
try {
|
try {
|
||||||
@ -50,4 +49,36 @@ public class BaseService implements Service {
|
|||||||
}
|
}
|
||||||
return userid == null ? 0 : (Integer)userid;
|
return userid == null ? 0 : (Integer)userid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件上传
|
||||||
|
*/
|
||||||
|
private static final String dir = "/var/www/upload/redbbs/";
|
||||||
|
private static final String view = "http://img.1216.top/redbbs/";
|
||||||
|
private static final String format = "%1$tY%1$tm%1$td%1$tH%1$tM%1$tS";
|
||||||
|
protected PicRecord upFile(File tmpFile, IPic bean){
|
||||||
|
String name = tmpFile.getName();
|
||||||
|
String suffix = name.substring(name.lastIndexOf("."));
|
||||||
|
String path = String.format(format, System.currentTimeMillis()) + suffix;
|
||||||
|
File destFile = new File((winos ? "root/tem/" : dir) + path);
|
||||||
|
destFile.getParentFile().mkdir();
|
||||||
|
if (!tmpFile.renameTo(destFile)){
|
||||||
|
try{
|
||||||
|
Files.copy(tmpFile.toPath(), destFile.toPath(), StandardCopyOption.ATOMIC_MOVE);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
tmpFile.delete();//删除临时文件
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//存贮资源数据
|
||||||
|
String src = (winos ? "/tem/" : view) + path;//资源访问地址
|
||||||
|
PicRecord pic = bean.crearePic();
|
||||||
|
pic.setSrc(src);
|
||||||
|
pic.setName(name);
|
||||||
|
pic.setLen((int) destFile.length());
|
||||||
|
source.insertAsync(pic);
|
||||||
|
return pic;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,11 +48,16 @@ public class BaseServlet extends HttpServlet {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void preExecute(HttpRequest request, HttpResponse response) throws IOException {
|
protected void preExecute(HttpRequest request, HttpResponse response) throws IOException {
|
||||||
|
/*if (true){
|
||||||
|
response.finish(HttpScope.refer("404.html"));
|
||||||
|
return;
|
||||||
|
}*/
|
||||||
|
|
||||||
String sessionid = request.getSessionid(true);
|
String sessionid = request.getSessionid(true);
|
||||||
int currentid = 0;
|
int currentid = 0;
|
||||||
if (sessionid != null) {
|
if (sessionid != null) {
|
||||||
request.setCurrentUser(userService.current(sessionid));
|
request.setCurrentUser(userService.current(sessionid));
|
||||||
currentid = userService.currentUserId(sessionid);
|
currentid = userService.currentUserid(sessionid);
|
||||||
}
|
}
|
||||||
|
|
||||||
String uri = request.getRequestURI();
|
String uri = request.getRequestURI();
|
||||||
|
@ -125,12 +125,12 @@ public class UserService extends BaseService {
|
|||||||
|
|
||||||
nickname = nickname.replace(" ", "");
|
nickname = nickname.replace(" ", "");
|
||||||
UserRecord _user = source.find(UserRecord.class, FilterNode.create("nickname", nickname));
|
UserRecord _user = source.find(UserRecord.class, FilterNode.create("nickname", nickname));
|
||||||
if (_user != null && _user.getUserid() != currentUserId(sessionid))
|
if (_user != null && _user.getUserid() != currentUserid(sessionid))
|
||||||
return RetCodes.retResult(RET_USER_NICKNAME_EXISTS, "昵称已存在");
|
return RetCodes.retResult(RET_USER_NICKNAME_EXISTS, "昵称已存在");
|
||||||
|
|
||||||
user.setNickname(nickname);//去除昵称中的空格
|
user.setNickname(nickname);//去除昵称中的空格
|
||||||
source.updateColumn(user
|
source.updateColumn(user
|
||||||
,FilterNode.create("userid", currentUserId(sessionid))
|
,FilterNode.create("userid", currentUserid(sessionid))
|
||||||
,SelectColumn.createIncludes(columns)
|
,SelectColumn.createIncludes(columns)
|
||||||
);
|
);
|
||||||
return RetResult.success();
|
return RetResult.success();
|
||||||
|
@ -2,11 +2,9 @@ package com.lxyer.bbs.comment;
|
|||||||
|
|
||||||
import com.lxyer.bbs.base.BaseService;
|
import com.lxyer.bbs.base.BaseService;
|
||||||
import com.lxyer.bbs.base.entity.ActLog;
|
import com.lxyer.bbs.base.entity.ActLog;
|
||||||
import com.lxyer.bbs.base.iface.UI;
|
|
||||||
import com.lxyer.bbs.base.iface.UIService;
|
import com.lxyer.bbs.base.iface.UIService;
|
||||||
import com.lxyer.bbs.base.kit.LxyKit;
|
import com.lxyer.bbs.base.kit.LxyKit;
|
||||||
import com.lxyer.bbs.base.kit.RetCodes;
|
import com.lxyer.bbs.base.kit.RetCodes;
|
||||||
import com.lxyer.bbs.base.user.UserService;
|
|
||||||
import com.lxyer.bbs.content.Content;
|
import com.lxyer.bbs.content.Content;
|
||||||
import org.redkale.net.http.RestMapping;
|
import org.redkale.net.http.RestMapping;
|
||||||
import org.redkale.net.http.RestParam;
|
import org.redkale.net.http.RestParam;
|
||||||
@ -17,8 +15,6 @@ import org.redkale.source.*;
|
|||||||
import org.redkale.util.SelectColumn;
|
import org.redkale.util.SelectColumn;
|
||||||
import org.redkale.util.Sheet;
|
import org.redkale.util.Sheet;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -31,9 +27,6 @@ import static com.lxyer.bbs.base.kit.RetCodes.RET_COMMENT_PARA_ILLEGAL;
|
|||||||
@RestService(automapping = true, comment = "评论服务")
|
@RestService(automapping = true, comment = "评论服务")
|
||||||
public class CommentService extends BaseService implements UIService<CommentInfo> {
|
public class CommentService extends BaseService implements UIService<CommentInfo> {
|
||||||
|
|
||||||
/*@Resource
|
|
||||||
private UserService userService;*/
|
|
||||||
|
|
||||||
@RestMapping(name = "save", comment = "评论保存")
|
@RestMapping(name = "save", comment = "评论保存")
|
||||||
public RetResult commentSave(@RestSessionid String sessionid, @RestParam(name = "bean") Comment comment){
|
public RetResult commentSave(@RestSessionid String sessionid, @RestParam(name = "bean") Comment comment){
|
||||||
int contentid = comment.getContentid();
|
int contentid = comment.getContentid();
|
||||||
@ -48,7 +41,7 @@ public class CommentService extends BaseService implements UIService<CommentInfo
|
|||||||
return RetCodes.retResult(RET_COMMENT_CONTENT_ILLEGAL, "评论内容无效");
|
return RetCodes.retResult(RET_COMMENT_CONTENT_ILLEGAL, "评论内容无效");
|
||||||
|
|
||||||
if (comment.getCommentid() < 1) {
|
if (comment.getCommentid() < 1) {
|
||||||
int userid = currentUserId(sessionid);
|
int userid = currentUserid(sessionid);
|
||||||
comment.setUserid(userid);
|
comment.setUserid(userid);
|
||||||
comment.setCreatetime(System.currentTimeMillis());
|
comment.setCreatetime(System.currentTimeMillis());
|
||||||
//todo:@用户处理
|
//todo:@用户处理
|
||||||
@ -65,7 +58,7 @@ public class CommentService extends BaseService implements UIService<CommentInfo
|
|||||||
|
|
||||||
@RestMapping(name = "query", auth = false,comment = "查询评论")
|
@RestMapping(name = "query", auth = false,comment = "查询评论")
|
||||||
public Sheet<CommentInfo> commentQuery(@RestSessionid String sessionid , int contentId, Flipper flipper){
|
public Sheet<CommentInfo> commentQuery(@RestSessionid String sessionid , int contentId, Flipper flipper){
|
||||||
int userid = currentUserId(sessionid);
|
int userid = currentUserid(sessionid);
|
||||||
|
|
||||||
flipper.setSort("supportnum DESC,commentid ASC");
|
flipper.setSort("supportnum DESC,commentid ASC");
|
||||||
Sheet<Comment> comments = source.querySheet(Comment.class, flipper, FilterNode.create("contentid", contentId));
|
Sheet<Comment> comments = source.querySheet(Comment.class, flipper, FilterNode.create("contentid", contentId));
|
||||||
@ -103,7 +96,7 @@ public class CommentService extends BaseService implements UIService<CommentInfo
|
|||||||
|
|
||||||
@RestMapping(name = "support", comment = "评论点赞")
|
@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);
|
int userid = currentUserid(sessionid);
|
||||||
|
|
||||||
source.findAsync(ActLog.class, FilterNode.create("userid", userid).and("tid", commentid).and("cate", 10)).thenAccept(actLog -> {
|
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){
|
||||||
|
@ -93,7 +93,7 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
|||||||
|
|
||||||
@RestMapping(name = "info", auth = false, comment = "内容详情")
|
@RestMapping(name = "info", auth = false, comment = "内容详情")
|
||||||
public ContentInfo contentInfo(@RestSessionid String sessionid, int contentid){
|
public ContentInfo contentInfo(@RestSessionid String sessionid, int contentid){
|
||||||
int userId = userService.currentUserId(sessionid);
|
int userId = userService.currentUserid(sessionid);
|
||||||
|
|
||||||
Content content = source.find(Content.class, contentid);
|
Content content = source.find(Content.class, contentid);
|
||||||
if (content == null) return null;
|
if (content == null) return null;
|
||||||
@ -110,7 +110,7 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
|||||||
|
|
||||||
@RestMapping(name = "collect", comment = "内容收藏")
|
@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);//不会为空
|
int userid = userService.currentUserid(sessionid);//不会为空
|
||||||
|
|
||||||
ActLog actLog = source.find(ActLog.class, FilterNode.create("userid", userid).and("tid", contentid).and("cate", 20));
|
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){
|
||||||
@ -130,7 +130,7 @@ public class ContentService extends BaseService implements UIService<ContentInfo
|
|||||||
|
|
||||||
@RestMapping(name = "collectquery", comment = "收藏列表")
|
@RestMapping(name = "collectquery", comment = "收藏列表")
|
||||||
public Sheet<ContentInfo> collectQuery(@RestSessionid String sessionid){
|
public Sheet<ContentInfo> collectQuery(@RestSessionid String sessionid){
|
||||||
int userid = currentUserId(sessionid);
|
int userid = currentUserid(sessionid);
|
||||||
|
|
||||||
Flipper flipper = new Flipper().sort("createtime DESC");
|
Flipper flipper = new Flipper().sort("createtime DESC");
|
||||||
FilterNode filterNode = FilterNode.create("cate", 20).and("status", 10).and("userid", userid);
|
FilterNode filterNode = FilterNode.create("cate", 20).and("status", 10).and("userid", userid);
|
||||||
|
@ -66,6 +66,7 @@ public class UserServlet extends BaseServlet {
|
|||||||
|
|
||||||
Kv kv = Kv.by("contents", contents).set("collects", collects);
|
Kv kv = Kv.by("contents", contents).set("collects", collects);
|
||||||
response.finish(HttpScope.refer("/user/index.html").attr(kv));
|
response.finish(HttpScope.refer("/user/index.html").attr(kv));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------用户主页------
|
//-------用户主页------
|
||||||
|
Loading…
Reference in New Issue
Block a user