调整包结构
This commit is contained in:
198
src/com/lxyer/bbs/content/Content.java
Normal file
198
src/com/lxyer/bbs/content/Content.java
Normal file
@@ -0,0 +1,198 @@
|
||||
package com.lxyer.bbs.content;
|
||||
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.lxyer.bbs.base.LxyKit;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lxyer
|
||||
*/
|
||||
@Cacheable(interval = 5*60)
|
||||
@Table(catalog = "db_redbbs", name = "content", comment = "[内容表]")
|
||||
public class Content implements java.io.Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(comment = "[内容id]")
|
||||
private int contentId;
|
||||
|
||||
@Column(comment = "[用户id]")
|
||||
private int userId;
|
||||
|
||||
@Column(length = 64, comment = "[标题]")
|
||||
private String title = "";
|
||||
|
||||
@Column(length = 256, comment = "[摘要]")
|
||||
private String digest = "";
|
||||
|
||||
@Column(comment = "[内容]")
|
||||
private String content = "";
|
||||
|
||||
@Column(comment = "[创建时间]")
|
||||
private long createTime;
|
||||
|
||||
@Column(comment = "[类别]")
|
||||
private int cate;
|
||||
|
||||
@Column(comment = "[内容类型]1新闻,2作品")
|
||||
private int type;
|
||||
|
||||
@Column(comment = "[评论数]")
|
||||
private int replyNum;
|
||||
|
||||
@Column(comment = "[阅读量]")
|
||||
private int viewNum;
|
||||
|
||||
@Column(comment = "[精] 0否,1是")
|
||||
private int wonderful;
|
||||
|
||||
@Column(comment = "[置顶] 0否,1是")
|
||||
private int top;
|
||||
|
||||
@Column(comment = "[结帖]大于0结帖")
|
||||
private int solved;
|
||||
|
||||
@Column(comment = "[状态]")
|
||||
private int status = 1;
|
||||
|
||||
public void setContentId(int contentId) {
|
||||
this.contentId = contentId;
|
||||
}
|
||||
|
||||
public int getContentId() {
|
||||
return this.contentId;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return this.userId;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void setDigest(String digest) {
|
||||
this.digest = digest;
|
||||
}
|
||||
|
||||
public String getDigest() {
|
||||
return this.digest;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public void setCreateTime(long createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public long getCreateTime() {
|
||||
return this.createTime;
|
||||
}
|
||||
|
||||
public int getCate() {
|
||||
return cate;
|
||||
}
|
||||
|
||||
public void setCate(int cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
|
||||
public int getReplyNum() {
|
||||
return replyNum;
|
||||
}
|
||||
|
||||
public void setReplyNum(int replyNum) {
|
||||
this.replyNum = replyNum;
|
||||
}
|
||||
|
||||
public int getViewNum() {
|
||||
return viewNum;
|
||||
}
|
||||
|
||||
public void setViewNum(int viewNum) {
|
||||
this.viewNum = viewNum;
|
||||
}
|
||||
|
||||
public int getWonderful() {
|
||||
return wonderful;
|
||||
}
|
||||
|
||||
public void setWonderful(int wonderful) {
|
||||
this.wonderful = wonderful;
|
||||
}
|
||||
|
||||
public int getTop() {
|
||||
return top;
|
||||
}
|
||||
|
||||
public void setTop(int top) {
|
||||
this.top = top;
|
||||
}
|
||||
|
||||
public int getSolved() {
|
||||
return solved;
|
||||
}
|
||||
|
||||
public void setSolved(int solved) {
|
||||
this.solved = solved;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
|
||||
private static final Kv types = Kv.by(10, "求助").set(20, "分享").set(30, "讨论").set(40, "公告").set(50, "动态");
|
||||
public ContentInfo createContentInfo(){
|
||||
ContentInfo info = new ContentInfo();
|
||||
info.setContentId(contentId);
|
||||
info.setUserId(userId);
|
||||
info.setTitle(title);
|
||||
info.setContent(content);
|
||||
info.setCate(cate);
|
||||
info.setType(type);
|
||||
info.setViewNum(viewNum);
|
||||
info.setReplyNum(replyNum);
|
||||
info.setWonderful(wonderful);
|
||||
info.setTop(top);
|
||||
info.setSolved(solved);
|
||||
|
||||
info.setTypeName(types.getOrDefault(type, "其他").toString());
|
||||
info.setCreateTime(LxyKit.dateFmt(createTime));
|
||||
return info;
|
||||
}
|
||||
}
|
154
src/com/lxyer/bbs/content/ContentBean.java
Normal file
154
src/com/lxyer/bbs/content/ContentBean.java
Normal file
@@ -0,0 +1,154 @@
|
||||
package com.lxyer.bbs.content;
|
||||
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.source.FilterBean;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lxyer
|
||||
*/
|
||||
@Table(catalog = "db_redbbs", name = "content", comment = "[内容表]")
|
||||
public class ContentBean implements FilterBean,java.io.Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(comment = "[内容id]")
|
||||
private int contentId;
|
||||
|
||||
@Column(comment = "[用户id]")
|
||||
private int userId;
|
||||
|
||||
@Column(length = 64, comment = "[标题]")
|
||||
private String title = "";
|
||||
|
||||
@Column(length = 256, comment = "[摘要]")
|
||||
private String digest = "";
|
||||
|
||||
@Column(comment = "[内容]")
|
||||
private String content = "";
|
||||
|
||||
@Column(comment = "[创建时间]")
|
||||
private long createTime;
|
||||
|
||||
@Column(comment = "[类别]")
|
||||
private int cate;
|
||||
|
||||
@Column(comment = "[内容类型]1新闻,2作品")
|
||||
private int type;
|
||||
|
||||
@Column(comment = "[评论数]")
|
||||
private int replyNum;
|
||||
|
||||
@Column(comment = "[阅读量]")
|
||||
private int viewNum;
|
||||
|
||||
/* @Column(comment = "[精] 0否,1是")
|
||||
private int wonderful;
|
||||
|
||||
@Column(comment = "[置顶] 0否,1是")
|
||||
private int top;
|
||||
|
||||
@Column(comment = "[结帖]大于0结帖")
|
||||
private int solved;*/
|
||||
|
||||
@Column(comment = "[状态]")
|
||||
private int status = 1;
|
||||
|
||||
public void setContentId(int contentId) {
|
||||
this.contentId = contentId;
|
||||
}
|
||||
|
||||
public int getContentId() {
|
||||
return this.contentId;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return this.userId;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void setDigest(String digest) {
|
||||
this.digest = digest;
|
||||
}
|
||||
|
||||
public String getDigest() {
|
||||
return this.digest;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public void setCreateTime(long createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public long getCreateTime() {
|
||||
return this.createTime;
|
||||
}
|
||||
|
||||
public int getCate() {
|
||||
return cate;
|
||||
}
|
||||
|
||||
public void setCate(int cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public int getReplyNum() {
|
||||
return replyNum;
|
||||
}
|
||||
|
||||
public void setReplyNum(int replyNum) {
|
||||
this.replyNum = replyNum;
|
||||
}
|
||||
|
||||
public int getViewNum() {
|
||||
return viewNum;
|
||||
}
|
||||
|
||||
public void setViewNum(int viewNum) {
|
||||
this.viewNum = viewNum;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
}
|
173
src/com/lxyer/bbs/content/ContentInfo.java
Normal file
173
src/com/lxyer/bbs/content/ContentInfo.java
Normal file
@@ -0,0 +1,173 @@
|
||||
package com.lxyer.bbs.content;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/11/26 20:52.
|
||||
*/
|
||||
public class ContentInfo implements Serializable {
|
||||
|
||||
private int contentId;
|
||||
private int userId;
|
||||
private String title = "";
|
||||
private String digest = "";
|
||||
private String content = "";
|
||||
private int cate;
|
||||
private int type;
|
||||
private int replyNum;
|
||||
private int viewNum;
|
||||
private int wonderful;
|
||||
private int top;
|
||||
private int solved;
|
||||
private int status = 1;
|
||||
|
||||
private String createTime;
|
||||
private String typeName;
|
||||
private String nickname = "";
|
||||
private String avatar = "";
|
||||
private int hadCollect = -1;
|
||||
|
||||
public int getContentId() {
|
||||
return contentId;
|
||||
}
|
||||
|
||||
public void setContentId(int contentId) {
|
||||
this.contentId = contentId;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDigest() {
|
||||
return digest;
|
||||
}
|
||||
|
||||
public void setDigest(String digest) {
|
||||
this.digest = digest;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public int getCate() {
|
||||
return cate;
|
||||
}
|
||||
|
||||
public void setCate(int cate) {
|
||||
this.cate = cate;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public int getReplyNum() {
|
||||
return replyNum;
|
||||
}
|
||||
|
||||
public void setReplyNum(int replyNum) {
|
||||
this.replyNum = replyNum;
|
||||
}
|
||||
|
||||
public int getViewNum() {
|
||||
return viewNum;
|
||||
}
|
||||
|
||||
public void setViewNum(int viewNum) {
|
||||
this.viewNum = viewNum;
|
||||
}
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public int getWonderful() {
|
||||
return wonderful;
|
||||
}
|
||||
|
||||
public void setWonderful(int wonderful) {
|
||||
this.wonderful = wonderful;
|
||||
}
|
||||
|
||||
public int getTop() {
|
||||
return top;
|
||||
}
|
||||
|
||||
public void setTop(int top) {
|
||||
this.top = top;
|
||||
}
|
||||
|
||||
public int getSolved() {
|
||||
return solved;
|
||||
}
|
||||
|
||||
public void setSolved(int solved) {
|
||||
this.solved = solved;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getTypeName() {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
public void setTypeName(String typeName) {
|
||||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
public 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() {
|
||||
return hadCollect;
|
||||
}
|
||||
|
||||
public void setHadCollect(int hadCollect) {
|
||||
this.hadCollect = hadCollect;
|
||||
}
|
||||
}
|
189
src/com/lxyer/bbs/content/ContentService.java
Normal file
189
src/com/lxyer/bbs/content/ContentService.java
Normal file
@@ -0,0 +1,189 @@
|
||||
package com.lxyer.bbs.content;
|
||||
|
||||
import com.lxyer.bbs.base.BaseService;
|
||||
import com.lxyer.bbs.base.LxyKit;
|
||||
import com.lxyer.bbs.base.RetCodes;
|
||||
import com.lxyer.bbs.base.user.UserService;
|
||||
import com.lxyer.bbs.content.ContentInfo;
|
||||
import com.lxyer.bbs.base.entity.ActLog;
|
||||
import com.lxyer.bbs.content.Content;
|
||||
import com.lxyer.bbs.base.user.User;
|
||||
import org.redkale.net.http.RestMapping;
|
||||
import org.redkale.net.http.RestParam;
|
||||
import org.redkale.net.http.RestService;
|
||||
import org.redkale.net.http.RestSessionid;
|
||||
import org.redkale.service.RetResult;
|
||||
import org.redkale.source.*;
|
||||
import org.redkale.util.SelectColumn;
|
||||
import org.redkale.util.Sheet;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/11/26 9:33.
|
||||
*/
|
||||
@RestService(automapping = true, comment = "内容管理")
|
||||
public class ContentService extends BaseService{
|
||||
|
||||
@Resource
|
||||
protected UserService userService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param flipper
|
||||
* @param filterNode
|
||||
* @return
|
||||
*/
|
||||
public Sheet<ContentInfo> contentQuery(Flipper flipper, FilterNode filterNode){
|
||||
Sheet<Content> contents = source.querySheet(Content.class, flipper, filterNode);
|
||||
|
||||
int[] userids = contents.stream().mapToInt(x -> x.getUserId()).distinct().toArray();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@RestMapping(name = "query", auth = false, comment = "内容列表")
|
||||
public Sheet<ContentInfo> contentQuery(Flipper flipper, String actived){
|
||||
FilterNode filterNode = FilterNode.create("status", FilterExpress.NOTEQUAL, -1);
|
||||
switch (actived){
|
||||
case "top": filterNode.and("top", 1);break;
|
||||
case "untop": filterNode.and("top", 0);break;
|
||||
case "unsolved": filterNode.and("solved", 0);break;
|
||||
case "solved": filterNode.and("solved", 1);break;
|
||||
case "wonderful": filterNode.and("wonderful", 1);break;
|
||||
}
|
||||
return contentQuery(flipper, filterNode);
|
||||
}
|
||||
|
||||
|
||||
public Sheet<ContentInfo> queryByBean(Flipper flipper, FilterBean bean){
|
||||
Sheet<Content> contents = source.querySheet(Content.class, flipper, bean);
|
||||
|
||||
Sheet<ContentInfo> infos = new Sheet<>();
|
||||
List<ContentInfo> list = new ArrayList<>();
|
||||
|
||||
contents.forEach(x->{
|
||||
list.add(x.createContentInfo());
|
||||
});
|
||||
|
||||
infos.setRows(list);
|
||||
infos.setTotal(contents.getTotal());
|
||||
|
||||
return infos;
|
||||
}
|
||||
|
||||
@RestMapping(name = "save", auth = true, comment = "内容保存")
|
||||
public RetResult contentSave(@RestParam(name = "bean")Content content, @RestSessionid String sessionid){
|
||||
if (content.getContentId() < 1){
|
||||
int maxId = source.getNumberResult(Content.class, FilterFunc.MAX, 10_0000, "contentId").intValue();
|
||||
int userId = userService.currentUserId(sessionid);
|
||||
|
||||
content.setContentId(maxId+1);
|
||||
content.setCreateTime(System.currentTimeMillis());
|
||||
content.setUserId(userId);
|
||||
|
||||
source.insert(content);
|
||||
}else {
|
||||
source.updateColumn(content, SelectColumn.createIncludes("title", "digest", "content","type"));
|
||||
}
|
||||
|
||||
return RetResult.success();
|
||||
}
|
||||
|
||||
@RestMapping(name = "info", auth = false, comment = "内容详情")
|
||||
public ContentInfo contentInfo(@RestSessionid String sessionid, int contentid){
|
||||
int userId = userService.currentUserId(sessionid);
|
||||
|
||||
Content content = source.find(Content.class, contentid);
|
||||
if (content == null) return null;
|
||||
|
||||
ContentInfo contentInfo = content.createContentInfo();
|
||||
User user = source.find(User.class, content.getUserId());
|
||||
contentInfo.setAvatar(user.getAvatar());
|
||||
contentInfo.setNickname(user.getNickname());
|
||||
|
||||
//收藏状态
|
||||
if (userId > 0){
|
||||
ActLog actLog = source.find(ActLog.class, FilterNode.create("cate", 2).and("tid", contentid).and("status", 1));
|
||||
if (actLog != null) contentInfo.setHadCollect(1);
|
||||
}
|
||||
return contentInfo;
|
||||
}
|
||||
|
||||
@RestMapping(name = "upview", comment = "增加文章1个访问量")
|
||||
public void incrViewNum(int contentId){
|
||||
source.updateColumn(Content.class, contentId, ColumnValue.inc("viewNum", 1));
|
||||
}
|
||||
|
||||
@RestMapping(name = "collect", comment = "内容收藏")
|
||||
public RetResult collect(@RestSessionid String sessionid, int contentId, int ok){
|
||||
int userId = userService.currentUserId(sessionid);//不会为空
|
||||
|
||||
ActLog actLog = source.find(ActLog.class, FilterNode.create("userId", userId).and("tid", contentId).and("cate", 2));
|
||||
if (actLog == null && ok == 1){
|
||||
actLog = new ActLog().cate(2).tid(contentId).userId(userId);
|
||||
actLog.setCreateTime(System.currentTimeMillis());
|
||||
source.insert(actLog);
|
||||
}else if (actLog != null && actLog.getStatus() != ok){
|
||||
actLog.setStatus(ok);
|
||||
actLog.setCreateTime(System.currentTimeMillis());
|
||||
source.update(actLog);
|
||||
}else {
|
||||
return RetCodes.retResult(-1, ok == 1 ? "已收藏" : "已取消收藏");
|
||||
}
|
||||
|
||||
return RetResult.success();
|
||||
}
|
||||
|
||||
@RestMapping(name = "collectquery", comment = "收藏列表")
|
||||
public Sheet<ContentInfo> collectQuery(@RestSessionid String sessionid){
|
||||
int userId = userService.currentUserId(sessionid);
|
||||
|
||||
Flipper flipper = new Flipper().sort("createTime DESC");
|
||||
FilterNode filterNode = FilterNode.create("cate", 2).and("status", 1);
|
||||
Sheet<ActLog> actLogs = source.querySheet(ActLog.class, SelectColumn.createIncludes("tid", "createTime"), flipper, filterNode);
|
||||
|
||||
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<ContentInfo> infos = new Sheet<>();
|
||||
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;
|
||||
}
|
||||
|
||||
@RestMapping(name = "set", comment = "内容操作")
|
||||
public RetResult contentSet(int id, String field, int v){
|
||||
source.updateColumn(Content.class, id, field, v);
|
||||
return RetResult.success();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user