1、用户资料加入[个人博客地址、码云/GitHub地址](部分用户开放设置)
2、加入用户信息接口UF/UI,优化用户信息设置代码
This commit is contained in:
parent
9e117e9e5b
commit
4a41fe20a1
@ -79,6 +79,17 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="detail-body photos">
|
<div class="detail-body photos">
|
||||||
#(bean.content??)
|
#(bean.content??)
|
||||||
|
|
||||||
|
#if(bean.site?? || bean.git??)
|
||||||
|
<blockquote class="layui-elem-quote layui-quote-nm">
|
||||||
|
#if(bean.site??)
|
||||||
|
<b>个人博客地址:<a href="#(bean.site??)" target="_blank">#(bean.site??)</a></b>
|
||||||
|
#end
|
||||||
|
#if(bean.git??)
|
||||||
|
<b>码云/GitHub:<a href="#(bean.git??)" target="_blank">#(bean.git??)</a></b>
|
||||||
|
#end
|
||||||
|
</blockquote>
|
||||||
|
#end
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -307,7 +307,6 @@ layui.define(['laypage', 'fly', 'element', 'flow'], function(exports){
|
|||||||
$.post("/os/user/register",{
|
$.post("/os/user/register",{
|
||||||
bean:JSON.stringify(bean)
|
bean:JSON.stringify(bean)
|
||||||
},function (data) {
|
},function (data) {
|
||||||
data = JSON.parse(data);
|
|
||||||
if(data.retcode != 0){
|
if(data.retcode != 0){
|
||||||
layer.msg(data.retinfo);
|
layer.msg(data.retinfo);
|
||||||
return false;
|
return false;
|
||||||
@ -357,6 +356,25 @@ layui.define(['laypage', 'fly', 'element', 'flow'], function(exports){
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
form.on('submit(set-blog)', function (data) {
|
||||||
|
var bean = {},columns = ['site', 'git'];
|
||||||
|
columns.forEach(function (value) {
|
||||||
|
bean[value] = data.field[value]
|
||||||
|
});
|
||||||
|
|
||||||
|
$.post("/os/user/update",{
|
||||||
|
bean:JSON.stringify(bean)
|
||||||
|
,columns:JSON.stringify(columns)
|
||||||
|
},function (res) {
|
||||||
|
if(res.retcode != 0){
|
||||||
|
layer.msg(res.retinfo);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//帐号绑定
|
//帐号绑定
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
<li class="layui-this" lay-id="info">我的资料</li>
|
<li class="layui-this" lay-id="info">我的资料</li>
|
||||||
<li lay-id="avatar">头像</li>
|
<li lay-id="avatar">头像</li>
|
||||||
<li lay-id="pass">密码</li>
|
<li lay-id="pass">密码</li>
|
||||||
|
#if(mine.roleId == 1)
|
||||||
|
<li lay-id="blog">博客地址</li>
|
||||||
|
#end
|
||||||
<!--<li lay-id="bind">帐号绑定</li>-->
|
<!--<li lay-id="bind">帐号绑定</li>-->
|
||||||
</ul>
|
</ul>
|
||||||
<div class="layui-tab-content" style="padding: 20px 0;">
|
<div class="layui-tab-content" style="padding: 20px 0;">
|
||||||
@ -48,7 +51,7 @@
|
|||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label for="L_city" class="layui-form-label">城市</label>
|
<label for="L_city" class="layui-form-label">城市</label>
|
||||||
<div class="layui-input-inline">
|
<div class="layui-input-inline">
|
||||||
<input type="text" id="L_city" name="city" autocomplete="off" value="" class="layui-input">
|
<input type="text" id="L_city" name="city" autocomplete="off" value="#(mine.city)" class="layui-input">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-form-item layui-form-text">
|
<div class="layui-form-item layui-form-text">
|
||||||
@ -105,6 +108,27 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!--博客/码云-->
|
||||||
|
<div class="layui-form layui-form-pane layui-tab-item">
|
||||||
|
<form method="post">
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label for="L_nowpass" class="layui-form-label">个人博客地址</label>
|
||||||
|
<div class="layui-input-inline">
|
||||||
|
<input type="input" id="L_site" name="site" value="#(mine.site??)" autocomplete="off" class="layui-input">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<label for="L_nowpass" class="layui-form-label">码云/GitHub</label>
|
||||||
|
<div class="layui-input-inline">
|
||||||
|
<input type="input" id="L_git" name="git" value="#(mine.git??)" autocomplete="off" class="layui-input">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="layui-form-item">
|
||||||
|
<button class="layui-btn" key="set-mine" lay-filter="set-blog" lay-submit>确认修改</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!--账号绑定-->
|
<!--账号绑定-->
|
||||||
<div class="layui-form layui-form-pane layui-tab-item">
|
<div class="layui-form layui-form-pane layui-tab-item">
|
||||||
<ul class="app-bind">
|
<ul class="app-bind">
|
||||||
|
@ -1,18 +1,24 @@
|
|||||||
package com.lxyer.bbs.base;
|
package com.lxyer.bbs.base;
|
||||||
|
|
||||||
|
import com.lxyer.bbs.base.user.User;
|
||||||
import com.lxyer.bbs.base.user.UserInfo;
|
import com.lxyer.bbs.base.user.UserInfo;
|
||||||
import org.redkale.service.Service;
|
import org.redkale.service.Service;
|
||||||
import org.redkale.source.CacheSource;
|
import org.redkale.source.CacheSource;
|
||||||
import org.redkale.source.DataSource;
|
import org.redkale.source.DataSource;
|
||||||
|
import org.redkale.source.FilterExpress;
|
||||||
|
import org.redkale.source.FilterNode;
|
||||||
|
import org.redkale.util.Sheet;
|
||||||
import org.redkalex.cache.RedisCacheSource;
|
import org.redkalex.cache.RedisCacheSource;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Lxy at 2017/10/3 13:50.
|
* Created by Lxy at 2017/10/3 13:50.
|
||||||
*/
|
*/
|
||||||
public class BaseService implements Service {
|
public class BaseService<F extends UF,I extends UI> implements Service {
|
||||||
|
|
||||||
protected final int sessionExpireSeconds = 7 * 24 * 60 * 60;
|
protected final int sessionExpireSeconds = 7 * 24 * 60 * 60;
|
||||||
|
|
||||||
@ -30,4 +36,50 @@ public class BaseService implements Service {
|
|||||||
|
|
||||||
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
protected static final boolean winos = System.getProperty("os.name").contains("Window");
|
||||||
|
|
||||||
|
|
||||||
|
protected Sheet<I> createInfo(Sheet<F> fSheet){
|
||||||
|
if (fSheet == null || fSheet.getTotal() < 1){
|
||||||
|
Sheet<I> sheet = new Sheet<>();
|
||||||
|
sheet.setTotal(0);
|
||||||
|
sheet.setRows(new ArrayList<>());
|
||||||
|
return sheet;
|
||||||
|
}
|
||||||
|
List<I> list = new ArrayList<>((int)fSheet.getTotal());
|
||||||
|
fSheet.forEach(x->{
|
||||||
|
list.add((I)x.createInfo());
|
||||||
|
});
|
||||||
|
|
||||||
|
Sheet<I> sheet = new Sheet<>();
|
||||||
|
sheet.setTotal(fSheet.getTotal());
|
||||||
|
sheet.setRows(list);
|
||||||
|
return sheet;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <I extends UI> Sheet<I> setIUser(Sheet<I> ufSheet){
|
||||||
|
int[] userIds = ufSheet.stream().mapToInt(I::getUserId).toArray();
|
||||||
|
List<User> users = source.queryList(User.class, FilterNode.create("userId", FilterExpress.IN, userIds));
|
||||||
|
List<I> infos = new ArrayList((int) ufSheet.getTotal());
|
||||||
|
|
||||||
|
ufSheet.forEach(x->{
|
||||||
|
User user = users.stream().filter(u -> u.getUserId() == x.getUserId()).findAny().orElse(null);
|
||||||
|
infos.add((I) x.setUser(user));
|
||||||
|
});
|
||||||
|
|
||||||
|
Sheet<I> sheet = new Sheet<>();
|
||||||
|
sheet.setTotal(ufSheet.getTotal());
|
||||||
|
sheet.setRows(infos);
|
||||||
|
|
||||||
|
return sheet;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将含有用户外键的实体,转为info,并加入用户信息
|
||||||
|
* @param uf
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected I setIUser(I uf){
|
||||||
|
User user = source.find(User.class, uf.getUserId());
|
||||||
|
|
||||||
|
return (I) uf.setUser(user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
10
src/com/lxyer/bbs/base/UF.java
Normal file
10
src/com/lxyer/bbs/base/UF.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package com.lxyer.bbs.base;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* user foreign key (userId)
|
||||||
|
* Created by liangxianyou at 2018/6/9 14:50.
|
||||||
|
*/
|
||||||
|
public interface UF<I extends UI> {
|
||||||
|
int getUserId();
|
||||||
|
I createInfo();
|
||||||
|
}
|
31
src/com/lxyer/bbs/base/UI.java
Normal file
31
src/com/lxyer/bbs/base/UI.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package com.lxyer.bbs.base;
|
||||||
|
|
||||||
|
import com.lxyer.bbs.base.user.User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by liangxianyou at 2018/6/9 13:45.
|
||||||
|
*/
|
||||||
|
public interface UI<I extends UI> {
|
||||||
|
|
||||||
|
//抽象方法
|
||||||
|
int getUserId();
|
||||||
|
User getUser();
|
||||||
|
I setUser(User 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();
|
||||||
|
}
|
||||||
|
}
|
@ -52,6 +52,12 @@ public class User implements java.io.Serializable {
|
|||||||
@Column(length = 2, comment = "[用户角色]")
|
@Column(length = 2, comment = "[用户角色]")
|
||||||
private int roleId = 0;
|
private int roleId = 0;
|
||||||
|
|
||||||
|
@Column(length = 128, comment = "[个人博客地址]")
|
||||||
|
private String site = "";
|
||||||
|
|
||||||
|
@Column(length = 128, comment = "[码云/GitHub]")
|
||||||
|
private String git = "";
|
||||||
|
|
||||||
@Column(comment = "[创建时间]", updatable = false)
|
@Column(comment = "[创建时间]", updatable = false)
|
||||||
private long createTime;
|
private long createTime;
|
||||||
|
|
||||||
@ -164,6 +170,22 @@ public class User implements java.io.Serializable {
|
|||||||
this.roleId = 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 long getCreateTime() {
|
public long getCreateTime() {
|
||||||
return createTime;
|
return createTime;
|
||||||
}
|
}
|
||||||
@ -213,6 +235,8 @@ public class User implements java.io.Serializable {
|
|||||||
userInfo.setRelaname(realname);
|
userInfo.setRelaname(realname);
|
||||||
userInfo.setEmail(email);
|
userInfo.setEmail(email);
|
||||||
userInfo.setRoleId(roleId);
|
userInfo.setRoleId(roleId);
|
||||||
|
userInfo.setSite(site);
|
||||||
|
userInfo.setGit(git);
|
||||||
userInfo.setCreateTime(createTime);
|
userInfo.setCreateTime(createTime);
|
||||||
userInfo.setSign(sign);
|
userInfo.setSign(sign);
|
||||||
userInfo.setCity(city);
|
userInfo.setCity(city);
|
||||||
|
@ -26,6 +26,8 @@ public class UserInfo implements java.io.Serializable {
|
|||||||
private String relaname = "";
|
private String relaname = "";
|
||||||
private String email = "";
|
private String email = "";
|
||||||
private int roleId = 0;
|
private int roleId = 0;
|
||||||
|
private String site = "";
|
||||||
|
private String git = "";
|
||||||
private long createTime;
|
private long createTime;
|
||||||
private String sign = "";
|
private String sign = "";
|
||||||
private String city = "";
|
private String city = "";
|
||||||
@ -113,6 +115,22 @@ public class UserInfo implements java.io.Serializable {
|
|||||||
this.roleId = 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) {
|
public void setCreateTime(long createTime) {
|
||||||
this.createTime = createTime;
|
this.createTime = createTime;
|
||||||
}
|
}
|
||||||
|
@ -48,14 +48,15 @@ public class UserService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public UserInfo current(String sessionid){
|
public UserInfo current(String sessionid){
|
||||||
Integer userid = sessions.getAndRefresh(sessionid, sessionExpireSeconds);
|
Object userid = sessions.getAndRefresh(sessionid, sessionExpireSeconds);
|
||||||
return userid == null ? null : findUserInfo(userid);
|
sessions.getAndRefresh(sessionid, sessionExpireSeconds);
|
||||||
|
return userid == null ? null : findUserInfo((Integer) userid);
|
||||||
}
|
}
|
||||||
@RestMapping(name = "userid")
|
@RestMapping(name = "userid")
|
||||||
public int currentUserId(String sessionid){
|
public int currentUserId(String sessionid){
|
||||||
if (sessionid == null) return 0;
|
if (sessionid == null) return 0;
|
||||||
Integer userid = sessions.getAndRefresh(sessionid, sessionExpireSeconds);
|
Object userid = sessions.getAndRefresh(sessionid, sessionExpireSeconds);
|
||||||
return userid == null ? 0 : userid;
|
return userid == null ? 0 : (Integer)userid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RestMapping(name = "info", comment = "用户信息")
|
@RestMapping(name = "info", comment = "用户信息")
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package com.lxyer.bbs.comment;
|
package com.lxyer.bbs.comment;
|
||||||
|
|
||||||
|
import com.lxyer.bbs.base.UF;
|
||||||
import com.lxyer.bbs.base.kit.LxyKit;
|
import com.lxyer.bbs.base.kit.LxyKit;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -11,7 +13,7 @@ import javax.persistence.*;
|
|||||||
*/
|
*/
|
||||||
@Cacheable(interval = 5*60)
|
@Cacheable(interval = 5*60)
|
||||||
@Table(catalog = "redbbs", name = "comment", comment = "[评论表]")
|
@Table(catalog = "redbbs", name = "comment", comment = "[评论表]")
|
||||||
public class Comment implements java.io.Serializable {
|
public class Comment implements UF<CommentInfo>,Serializable {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
@ -119,7 +121,7 @@ public class Comment implements java.io.Serializable {
|
|||||||
return JsonConvert.root().convertTo(this);
|
return JsonConvert.root().convertTo(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommentInfo createCommentInfo(){
|
public CommentInfo createInfo(){
|
||||||
CommentInfo info = new CommentInfo();
|
CommentInfo info = new CommentInfo();
|
||||||
info.setCommentId(commentId);
|
info.setCommentId(commentId);
|
||||||
info.setUserId(userId);
|
info.setUserId(userId);
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
package com.lxyer.bbs.comment;
|
package com.lxyer.bbs.comment;
|
||||||
|
|
||||||
|
import com.lxyer.bbs.base.UI;
|
||||||
|
import com.lxyer.bbs.base.user.User;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author lxyer
|
* @author lxyer
|
||||||
*/
|
*/
|
||||||
public class CommentInfo implements java.io.Serializable {
|
public class CommentInfo implements UI<CommentInfo>,Serializable {
|
||||||
|
|
||||||
@Column(comment = "[评论id]")
|
@Column(comment = "[评论id]")
|
||||||
private int commentId;
|
private int commentId;
|
||||||
@ -38,8 +41,6 @@ public class CommentInfo implements java.io.Serializable {
|
|||||||
private String createTime;
|
private String createTime;
|
||||||
|
|
||||||
private CommentInfo pCommentInfo;
|
private CommentInfo pCommentInfo;
|
||||||
private String nickname = "";
|
|
||||||
private String avatar = "";
|
|
||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
private int hadSupport = -1;
|
private int hadSupport = -1;
|
||||||
@ -124,22 +125,6 @@ public class CommentInfo implements java.io.Serializable {
|
|||||||
this.pCommentInfo = pCommentInfo;
|
this.pCommentInfo = pCommentInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNickname() {
|
|
||||||
return nickname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNickname(String nickname) {
|
|
||||||
this.nickname = nickname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAvatar() {
|
|
||||||
return avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAvatar(String avatar) {
|
|
||||||
this.avatar = avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
@ -160,4 +145,18 @@ public class CommentInfo implements java.io.Serializable {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return JsonConvert.root().convertTo(this);
|
return JsonConvert.root().convertTo(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommentInfo setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package com.lxyer.bbs.comment;
|
package com.lxyer.bbs.comment;
|
||||||
|
|
||||||
import com.lxyer.bbs.base.BaseService;
|
import com.lxyer.bbs.base.BaseService;
|
||||||
|
import com.lxyer.bbs.base.entity.ActLog;
|
||||||
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.entity.ActLog;
|
|
||||||
import com.lxyer.bbs.base.user.User;
|
|
||||||
import com.lxyer.bbs.base.user.UserService;
|
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;
|
||||||
@ -28,7 +27,7 @@ import static com.lxyer.bbs.base.kit.RetCodes.RET_COMMENT_PARA_ILLEGAL;
|
|||||||
* Created by Lxy at 2017/11/29 10:00.
|
* Created by Lxy at 2017/11/29 10:00.
|
||||||
*/
|
*/
|
||||||
@RestService(automapping = true, comment = "评论服务")
|
@RestService(automapping = true, comment = "评论服务")
|
||||||
public class CommentService extends BaseService {
|
public class CommentService extends BaseService<Comment, CommentInfo> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
@ -62,36 +61,20 @@ public class CommentService extends BaseService {
|
|||||||
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));
|
||||||
|
|
||||||
Sheet<CommentInfo> infos = new Sheet<>();
|
Sheet<CommentInfo> infos = createInfo(comments);
|
||||||
List<CommentInfo> list = new ArrayList<>();
|
setIUser(infos);
|
||||||
|
|
||||||
if (comments.getRows() == null) return infos;
|
|
||||||
|
|
||||||
//映射用户信息
|
|
||||||
int[] userids = comments.stream().mapToInt(x -> x.getUserId()).toArray();
|
|
||||||
List<User> users = source.queryList(User.class, SelectColumn.createIncludes("userId","avatar", "nickname"), FilterNode.create("userId", FilterExpress.IN, userids));
|
|
||||||
|
|
||||||
//用户点赞的评论
|
//用户点赞的评论
|
||||||
List<Integer> hadSupport = new ArrayList<>();
|
|
||||||
if (userId > 0){
|
if (userId > 0){
|
||||||
FilterNode node = FilterNode.create("cate", 1).and("status", 1).and("userId", userId);
|
int[] commentIds = comments.stream().mapToInt(Comment::getCommentId).toArray();
|
||||||
List<ActLog> actLogs = source.queryList(ActLog.class, SelectColumn.createIncludes("tid"), node);
|
FilterNode node = FilterNode.create("cate", 1).and("status", 1).and("userId", userId).and("tid", FilterExpress.IN, commentIds);
|
||||||
actLogs.forEach(x->hadSupport.add(x.getTid()));
|
List<Integer> hadSupport = source.queryColumnList("tid", ActLog.class, node);
|
||||||
|
|
||||||
|
infos.forEach(x->{
|
||||||
|
x.setHadSupport(hadSupport.contains(x.getCommentId()) ? 1 : -1);//
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
comments.forEach(x->{
|
|
||||||
CommentInfo info = x.createCommentInfo();
|
|
||||||
User user = users.stream().filter(k -> k.getUserId() == x.getUserId()).findFirst().orElse(new User());
|
|
||||||
info.setAvatar(user.getAvatar());
|
|
||||||
info.setNickname(user.getNickname());
|
|
||||||
|
|
||||||
info.setHadSupport(hadSupport.contains(x.getCommentId()) ? 1 : -1);//
|
|
||||||
|
|
||||||
list.add(info);
|
|
||||||
});
|
|
||||||
|
|
||||||
infos.setRows(list);
|
|
||||||
infos.setTotal(comments.getTotal());
|
|
||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +89,7 @@ public class CommentService extends BaseService {
|
|||||||
List<CommentInfo> list = new ArrayList<>();
|
List<CommentInfo> list = new ArrayList<>();
|
||||||
|
|
||||||
comments.forEach(x->{
|
comments.forEach(x->{
|
||||||
CommentInfo info = x.createCommentInfo();
|
CommentInfo info = x.createInfo();
|
||||||
Content content = contents.stream().filter(k -> k.getContentId() == x.getContentId()).findFirst().orElse(new Content());
|
Content content = contents.stream().filter(k -> k.getContentId() == x.getContentId()).findFirst().orElse(new Content());
|
||||||
info.setTitle(content.getTitle());
|
info.setTitle(content.getTitle());
|
||||||
list.add(info);
|
list.add(info);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.lxyer.bbs.content;
|
package com.lxyer.bbs.content;
|
||||||
|
|
||||||
import com.jfinal.kit.Kv;
|
import com.jfinal.kit.Kv;
|
||||||
|
import com.lxyer.bbs.base.UF;
|
||||||
import com.lxyer.bbs.base.kit.LxyKit;
|
import com.lxyer.bbs.base.kit.LxyKit;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ import javax.persistence.*;
|
|||||||
*/
|
*/
|
||||||
@Cacheable(interval = 5*60)
|
@Cacheable(interval = 5*60)
|
||||||
@Table(catalog = "redbbs", name = "content", comment = "[内容表]")
|
@Table(catalog = "redbbs", name = "content", comment = "[内容表]")
|
||||||
public class Content implements java.io.Serializable {
|
public class Content implements UF<ContentInfo>,java.io.Serializable {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
@ -177,7 +178,9 @@ public class Content implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final Kv types = Kv.by(10, "求助").set(20, "分享").set(30, "讨论").set(40, "公告").set(50, "动态");
|
private static final Kv types = Kv.by(10, "求助").set(20, "分享").set(30, "讨论").set(40, "公告").set(50, "动态");
|
||||||
public ContentInfo createContentInfo(){
|
|
||||||
|
@Override
|
||||||
|
public ContentInfo createInfo() {
|
||||||
ContentInfo info = new ContentInfo();
|
ContentInfo info = new ContentInfo();
|
||||||
info.setContentId(contentId);
|
info.setContentId(contentId);
|
||||||
info.setUserId(userId);
|
info.setUserId(userId);
|
||||||
|
@ -1,17 +1,22 @@
|
|||||||
package com.lxyer.bbs.content;
|
package com.lxyer.bbs.content;
|
||||||
|
|
||||||
|
import com.lxyer.bbs.base.UI;
|
||||||
|
import com.lxyer.bbs.base.user.User;
|
||||||
|
import org.redkale.convert.ConvertColumn;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Lxy at 2017/11/26 20:52.
|
* Created by Lxy at 2017/11/26 20:52.
|
||||||
*/
|
*/
|
||||||
public class ContentInfo implements Serializable {
|
public class ContentInfo implements UI<ContentInfo>,Serializable {
|
||||||
|
|
||||||
private int contentId;
|
private int contentId;
|
||||||
private int userId;
|
private int userId;
|
||||||
private String title = "";
|
private String title = "";
|
||||||
private String digest = "";
|
private String digest = "";
|
||||||
private String content = "";
|
private String content = "";
|
||||||
|
private String createTime;
|
||||||
private int cate;
|
private int cate;
|
||||||
private int type;
|
private int type;
|
||||||
private int replyNum;
|
private int replyNum;
|
||||||
@ -21,10 +26,7 @@ public class ContentInfo implements Serializable {
|
|||||||
private int solved;
|
private int solved;
|
||||||
private int status = 1;
|
private int status = 1;
|
||||||
|
|
||||||
private String createTime;
|
|
||||||
private String typeName;
|
private String typeName;
|
||||||
private String nickname = "";
|
|
||||||
private String avatar = "";
|
|
||||||
private int hadCollect = -1;
|
private int hadCollect = -1;
|
||||||
|
|
||||||
public int getContentId() {
|
public int getContentId() {
|
||||||
@ -147,22 +149,6 @@ public class ContentInfo implements Serializable {
|
|||||||
this.typeName = typeName;
|
this.typeName = typeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNickname() {
|
|
||||||
return nickname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNickname(String nickname) {
|
|
||||||
this.nickname = nickname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAvatar() {
|
|
||||||
return avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAvatar(String avatar) {
|
|
||||||
this.avatar = avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHadCollect() {
|
public int getHadCollect() {
|
||||||
return hadCollect;
|
return hadCollect;
|
||||||
}
|
}
|
||||||
@ -170,4 +156,19 @@ public class ContentInfo implements Serializable {
|
|||||||
public void setHadCollect(int hadCollect) {
|
public void setHadCollect(int hadCollect) {
|
||||||
this.hadCollect = hadCollect;
|
this.hadCollect = hadCollect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-----------
|
||||||
|
private User user;
|
||||||
|
@ConvertColumn(ignore = true)
|
||||||
|
@Override
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContentInfo setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,8 @@ package com.lxyer.bbs.content;
|
|||||||
|
|
||||||
import com.jfinal.kit.Kv;
|
import com.jfinal.kit.Kv;
|
||||||
import com.lxyer.bbs.base.BaseService;
|
import com.lxyer.bbs.base.BaseService;
|
||||||
import com.lxyer.bbs.base.kit.LxyKit;
|
|
||||||
import com.lxyer.bbs.base.kit.RetCodes;
|
|
||||||
import com.lxyer.bbs.base.entity.ActLog;
|
import com.lxyer.bbs.base.entity.ActLog;
|
||||||
import com.lxyer.bbs.base.user.User;
|
import com.lxyer.bbs.base.kit.RetCodes;
|
||||||
import com.lxyer.bbs.base.user.UserInfo;
|
import com.lxyer.bbs.base.user.UserInfo;
|
||||||
import com.lxyer.bbs.base.user.UserService;
|
import com.lxyer.bbs.base.user.UserService;
|
||||||
import org.redkale.net.http.*;
|
import org.redkale.net.http.*;
|
||||||
@ -15,14 +13,12 @@ import org.redkale.util.SelectColumn;
|
|||||||
import org.redkale.util.Sheet;
|
import org.redkale.util.Sheet;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Lxy at 2017/11/26 9:33.
|
* Created by Lxy at 2017/11/26 9:33.
|
||||||
*/
|
*/
|
||||||
@RestService(automapping = true, comment = "内容管理")
|
@RestService(automapping = true, comment = "内容管理")
|
||||||
public class ContentService extends BaseService{
|
public class ContentService extends BaseService<Content,ContentInfo>{
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected UserService userService;
|
protected UserService userService;
|
||||||
@ -36,22 +32,9 @@ public class ContentService extends BaseService{
|
|||||||
public Sheet<ContentInfo> contentQuery(Flipper flipper, FilterNode filterNode){
|
public Sheet<ContentInfo> contentQuery(Flipper flipper, FilterNode filterNode){
|
||||||
Sheet<Content> contents = source.querySheet(Content.class, flipper, filterNode);
|
Sheet<Content> contents = source.querySheet(Content.class, flipper, filterNode);
|
||||||
|
|
||||||
int[] userids = contents.stream().mapToInt(x -> x.getUserId()).distinct().toArray();
|
Sheet<ContentInfo> infos = createInfo(contents);
|
||||||
|
setIUser(infos);
|
||||||
|
|
||||||
Sheet<ContentInfo> infos = new Sheet<>();
|
|
||||||
List<ContentInfo> list = new ArrayList<>();
|
|
||||||
|
|
||||||
List<User> users = source.queryList(User.class, SelectColumn.createIncludes("userId","avatar", "nickname"), FilterNode.create("userId", FilterExpress.IN, userids));
|
|
||||||
contents.forEach(x->{
|
|
||||||
ContentInfo contentInfo = x.createContentInfo();
|
|
||||||
User user = users.stream().filter(k -> k.getUserId() == x.getUserId()).findFirst().orElse(new User());
|
|
||||||
contentInfo.setAvatar(user.getAvatar());
|
|
||||||
contentInfo.setNickname(user.getNickname());
|
|
||||||
list.add(contentInfo);
|
|
||||||
});
|
|
||||||
|
|
||||||
infos.setRows(list);
|
|
||||||
infos.setTotal(contents.getTotal());
|
|
||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,15 +62,7 @@ public class ContentService extends BaseService{
|
|||||||
public Sheet<ContentInfo> queryByBean(Flipper flipper, FilterBean bean){
|
public Sheet<ContentInfo> queryByBean(Flipper flipper, FilterBean bean){
|
||||||
Sheet<Content> contents = source.querySheet(Content.class, flipper, bean);
|
Sheet<Content> contents = source.querySheet(Content.class, flipper, bean);
|
||||||
|
|
||||||
Sheet<ContentInfo> infos = new Sheet<>();
|
Sheet<ContentInfo> infos = createInfo(contents);
|
||||||
List<ContentInfo> list = new ArrayList<>();
|
|
||||||
|
|
||||||
contents.forEach(x->{
|
|
||||||
list.add(x.createContentInfo());
|
|
||||||
});
|
|
||||||
|
|
||||||
infos.setRows(list);
|
|
||||||
infos.setTotal(contents.getTotal());
|
|
||||||
|
|
||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
@ -122,10 +97,7 @@ public class ContentService extends BaseService{
|
|||||||
Content content = source.find(Content.class, contentid);
|
Content content = source.find(Content.class, contentid);
|
||||||
if (content == null) return null;
|
if (content == null) return null;
|
||||||
|
|
||||||
ContentInfo contentInfo = content.createContentInfo();
|
ContentInfo contentInfo = setIUser(content.createInfo());
|
||||||
User user = source.find(User.class, content.getUserId());
|
|
||||||
contentInfo.setAvatar(user.getAvatar());
|
|
||||||
contentInfo.setNickname(user.getNickname());
|
|
||||||
|
|
||||||
//收藏状态
|
//收藏状态
|
||||||
if (userId > 0){
|
if (userId > 0){
|
||||||
@ -171,20 +143,7 @@ public class ContentService extends BaseService{
|
|||||||
int[] contentids = actLogs.stream().mapToInt(x -> x.getTid()).toArray();
|
int[] contentids = actLogs.stream().mapToInt(x -> x.getTid()).toArray();
|
||||||
Sheet<Content> contents = source.querySheet(Content.class, SelectColumn.createIncludes("contentId", "title"), flipper.sort(null), FilterNode.create("contentId", FilterExpress.IN, contentids));
|
Sheet<Content> contents = source.querySheet(Content.class, SelectColumn.createIncludes("contentId", "title"), flipper.sort(null), FilterNode.create("contentId", FilterExpress.IN, contentids));
|
||||||
|
|
||||||
Sheet<ContentInfo> infos = new Sheet<>();
|
Sheet<ContentInfo> infos = createInfo(contents);
|
||||||
ArrayList<ContentInfo> list = new ArrayList<>();
|
|
||||||
|
|
||||||
actLogs.forEach(x->{
|
|
||||||
Content content = contents.stream().filter(k -> k.getContentId() == x.getTid()).findFirst().orElse(null);
|
|
||||||
if (content != null){
|
|
||||||
ContentInfo info = content.createContentInfo();
|
|
||||||
info.setCreateTime(LxyKit.dateFmt(x.getCreateTime()));
|
|
||||||
list.add(info);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
infos.setRows(list);
|
|
||||||
infos.setTotal(actLogs.getTotal());
|
|
||||||
|
|
||||||
return infos;
|
return infos;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user