diff --git a/src/main/java/com/peanut/modules/book/controller/BookForumArticlesServiceController.java b/src/main/java/com/peanut/modules/book/controller/BookForumArticlesServiceController.java index edecec7e..7d4242b7 100644 --- a/src/main/java/com/peanut/modules/book/controller/BookForumArticlesServiceController.java +++ b/src/main/java/com/peanut/modules/book/controller/BookForumArticlesServiceController.java @@ -1,7 +1,15 @@ package com.peanut.modules.book.controller; +import com.baomidou.mybatisplus.core.conditions.Wrapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.R; +import com.peanut.modules.app.entity.UserEntity; +import com.peanut.modules.app.service.UserService; +import com.peanut.modules.book.dao.BookForumArticlesDao; import com.peanut.modules.book.entity.*; import com.peanut.modules.book.service.*; import com.peanut.modules.book.vo.BookForumArticlesVO; @@ -23,6 +31,10 @@ public class BookForumArticlesServiceController { private AuthorService authorService; @Autowired private PublisherService publisherService; + @Autowired + private BookForumArticlesDao bookForumArticlesDao; + @Autowired + private UserService userService; /** * 列表 (开始时间倒叙) 后台get请求 @@ -46,6 +58,174 @@ public class BookForumArticlesServiceController { return R.ok().put("page", page); } + /** + * 获取书评首页列表(最新) + * @return + */ + @RequestMapping("getForumsNew") + public R getForumsNew(@RequestParam Integer limit,@RequestParam Integer page){ + MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); + wrapper.selectAll(BookForumArticlesEntity.class); + wrapper.selectAs(BookEntity::getImages,"bookimage"); + wrapper.selectAs(BookEntity::getName,"bookname"); + wrapper.selectAs(AuthorEntity::getAuthorName,"bookauthor"); + wrapper.leftJoin(BookEntity.class,BookEntity::getId,BookForumArticlesEntity::getBookid); + wrapper.leftJoin(AuthorEntity.class,AuthorEntity::getId,BookEntity::getAuthorId); + wrapper.eq(BookForumArticlesEntity::getDelflag,0); + wrapper.eq(BookEntity::getDelFlag,0); + Page bookForumArticlesEntityPage = bookForumArticlesDao.selectJoinPage(new Page<>(page, limit), BookForumArticlesEntity.class, wrapper); + + for (BookForumArticlesEntity b : bookForumArticlesEntityPage.getRecords()){ + List commentsLimit = bookForumCommenService.getCommentsLimit(b.getId(), 3); + Integer commentcount = bookForumCommenService.getCommentcount(b.getId()); + b.setComment(commentsLimit); + b.setCommentNum(commentcount); + } + + + return R.ok().put("page",bookForumArticlesEntityPage); + } + + /** + * 获取书评首页列表(最热) + * @param limit + * @param page + * @return + */ + @RequestMapping("/getForumsHot") + public R getForumsHot(@RequestParam Integer limit,@RequestParam Integer page){ + + MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); + wrapper.selectAll(BookForumArticlesEntity.class); + wrapper.selectAs(BookEntity::getImages,"bookimage"); + wrapper.selectAs(BookEntity::getName,"bookname"); + wrapper.selectAs(AuthorEntity::getAuthorName,"bookauthor"); + wrapper.leftJoin(BookEntity.class,BookEntity::getId,BookForumArticlesEntity::getBookid); + wrapper.leftJoin(AuthorEntity.class,AuthorEntity::getId,BookEntity::getAuthorId); + wrapper.eq(BookForumArticlesEntity::getDelflag,0); + wrapper.eq(BookEntity::getDelFlag,0); + wrapper.orderByDesc(BookForumArticlesEntity::getContlike); + Page bookForumArticlesEntityPage = bookForumArticlesDao.selectJoinPage(new Page<>(page, limit), BookForumArticlesEntity.class, wrapper); + + for (BookForumArticlesEntity b : bookForumArticlesEntityPage.getRecords()){ + List commentsLimit = bookForumCommenService.getCommentsLimit(b.getId(), 3); + Integer commentcount = bookForumCommenService.getCommentcount(b.getId()); + b.setComment(commentsLimit); + b.setCommentNum(commentcount); + } + + + return R.ok().put("page",bookForumArticlesEntityPage); + } + + /** + * 获取书评首页列表 + * @param userId + * @return + */ + @RequestMapping("/getForumsAndBook") + public R getForumsAndBook(@RequestParam Integer userId,@RequestParam Integer limit,@RequestParam Integer page){ + String existSql = "select 1 from book_forum_articles where book.id = bookid"; + LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); + wrapper.eq(BookEntity::getDelFlag,0); + wrapper.exists(existSql); + Page bookEntityPage = bookService.getBaseMapper().selectPage(new Page<>(page, limit), wrapper); + + for (BookEntity b :bookEntityPage.getRecords()){ + List forumsLimit = bookForumArticlesService.getForumsLimit(b.getId(), 4); + b.setForums(forumsLimit); + } + + return R.ok().put("page",bookEntityPage); + } + + /** + * 点赞书评帖子 + * @param forum_id + * @return + */ + @RequestMapping("/chickForumContlike") + public R chickForumContlike(@RequestParam Integer forum_id){ + UpdateWrapper wrapper = new UpdateWrapper<>(); + wrapper.setSql("contlike = contlike + 1"); + wrapper.eq("id",forum_id); + boolean update = bookForumArticlesService.update(null, wrapper); + return R.ok(); + } + + /** + * 点赞书评帖子回复 + * @param comment_id + * @return + */ + @RequestMapping("/chickCommentConlike") + public R chickCommentConlike(@RequestParam Integer comment_id){ + UpdateWrapper wrapper = new UpdateWrapper(); + wrapper.setSql("contlike = contlike + 1"); + wrapper.eq("id",comment_id); + boolean update = bookForumCommenService.update(null, wrapper); + return R.ok(); + } + + + /** + * 获取单本书的书评列表 + * @return + */ + @RequestMapping("/getForumByBook") + public R getForumByBook(@RequestParam Integer bookId,@RequestParam Integer limit,@RequestParam Integer page){ + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(BookForumArticlesEntity::getDelflag,0); + wrapper.orderByDesc(BookForumArticlesEntity::getCreateTime); + Page bookForumArticlesEntityPage = bookForumArticlesService.getBaseMapper().selectPage(new Page<>(page, limit), wrapper); + for (BookForumArticlesEntity b:bookForumArticlesEntityPage.getRecords()){ + b.setUser(userService.getById(b.getUserid())); + b.setComment(bookForumCommenService.getCommentsLimit(b.getId(),3)); + } + return R.ok().put("page",bookForumArticlesEntityPage); + } + + /** + * 获取单帖子的全部回复 + * @param forumId + * @param limit + * @param page + * @return + */ + @RequestMapping("/getCommentByForum") + public R getCommentByForum(@RequestParam Integer forumId,@RequestParam Integer limit,@RequestParam Integer page){ + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(BookForumCommentEntity::getDelflag,0); + wrapper.gt(BookForumCommentEntity::getPid,0); + wrapper.orderByAsc(BookForumCommentEntity::getCreateTime); + Page bookForumCommentEntityPage = bookForumCommenService.getBaseMapper().selectPage(new Page<>(page, limit), wrapper); + for (BookForumCommentEntity b : bookForumCommentEntityPage.getRecords()){ + b.setComments(bookForumCommenService.getChildComments(b.getId())); + b.setUser(userService.getById(b.getUserid())); + b.setPuser(userService.getById(b.getPuserid())); + } + return R.ok().put("page",bookForumCommentEntityPage); + } + + + @RequestMapping("/pushMsgToForum") + public R pushMsgToForum( + @RequestParam Integer forumId, + @RequestParam String content, + @RequestParam Integer userId, + @RequestParam(required = false,value = "0") Integer pid, + @RequestParam(required = false,value = "0") Integer puserId){ + BookForumArticlesEntity forumInfo = bookForumArticlesService.getById(forumId); + BookForumCommentEntity bookForumCommentEntity = new BookForumCommentEntity(); + bookForumCommentEntity.setBfaid(forumId); + bookForumCommentEntity.setUserid(userId); + bookForumCommentEntity.setContent(content.trim()); + bookForumCommentEntity.setBookid(forumInfo.getBookid()); + bookForumCommentEntity.setPid(pid); + bookForumCommentEntity.setPuserid(puserId); + bookForumCommenService.save(bookForumCommentEntity); + return R.ok(); + } @RequestMapping("/desc/{page}") diff --git a/src/main/java/com/peanut/modules/book/entity/BookEntity.java b/src/main/java/com/peanut/modules/book/entity/BookEntity.java index 5c3b1768..d1270589 100644 --- a/src/main/java/com/peanut/modules/book/entity/BookEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/BookEntity.java @@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.*; import java.math.BigDecimal; import java.io.Serializable; import java.util.Date; +import java.util.List; + import lombok.Data; /** @@ -158,6 +160,8 @@ public class BookEntity implements Serializable { @TableField(exist = false) private Boolean isBuy; + @TableField(exist = false) + private List forums; // @TableField(exist = false) diff --git a/src/main/java/com/peanut/modules/book/entity/BookForumArticlesEntity.java b/src/main/java/com/peanut/modules/book/entity/BookForumArticlesEntity.java index ceb787f3..d59b589e 100644 --- a/src/main/java/com/peanut/modules/book/entity/BookForumArticlesEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/BookForumArticlesEntity.java @@ -1,9 +1,12 @@ package com.peanut.modules.book.entity; import com.baomidou.mybatisplus.annotation.*; +import com.peanut.modules.app.entity.UserEntity; import lombok.Data; import java.util.Date; +import java.util.List; +import java.util.Map; /** * 文章表主表 @@ -63,7 +66,7 @@ public class BookForumArticlesEntity { * 点赞数 */ @TableField("contlike") - private Date contlike; + private Integer contlike; @TableField("del_flag") @TableLogic @@ -81,6 +84,24 @@ public class BookForumArticlesEntity { @TableField("bookdesc") private String bookdesc; + @TableField(exist = false) + private String bookimage; + + @TableField(exist = false) + private String bookname; + + @TableField(exist = false) + private String bookauthor; + + @TableField(exist = false) + private List comment; + + @TableField(exist = false) + private Integer commentNum; + + //说话的人 + @TableField(exist = false) + private UserEntity user; diff --git a/src/main/java/com/peanut/modules/book/entity/BookForumCommentEntity.java b/src/main/java/com/peanut/modules/book/entity/BookForumCommentEntity.java index 3a7d12c9..bfce4957 100644 --- a/src/main/java/com/peanut/modules/book/entity/BookForumCommentEntity.java +++ b/src/main/java/com/peanut/modules/book/entity/BookForumCommentEntity.java @@ -2,9 +2,11 @@ package com.peanut.modules.book.entity; import com.baomidou.mybatisplus.annotation.*; +import com.peanut.modules.app.entity.UserEntity; import lombok.Data; import java.util.Date; +import java.util.List; /** * 评价文章表 @@ -24,12 +26,16 @@ public class BookForumCommentEntity { *文章父id */ @TableField("bfa_id") - private String bfaid; + private Integer bfaid; /** *用户评论id */ @TableField("userid") - private String userid; + private Integer userid; + @TableField("puserid") + private Integer puserid; + @TableField("pid") + private Integer pid; /** *内容 */ @@ -50,6 +56,10 @@ public class BookForumCommentEntity { */ @TableField(fill = FieldFill.UPDATE) private Date updateTime; + + @TableField("contlike") + private Integer contlike; + /** * 删除 */ @@ -58,4 +68,16 @@ public class BookForumCommentEntity { private Integer delflag; @TableField("book_id") private Integer bookid; + + //发言者 + @TableField(exist = false) + private UserEntity user; + + //对谁说 + @TableField(exist = false) + private UserEntity puser; + + //子对话 + @TableField(exist = false) + private List comments; } diff --git a/src/main/java/com/peanut/modules/book/service/BookForumArticlesService.java b/src/main/java/com/peanut/modules/book/service/BookForumArticlesService.java index 08e89f55..bbf88dc6 100644 --- a/src/main/java/com/peanut/modules/book/service/BookForumArticlesService.java +++ b/src/main/java/com/peanut/modules/book/service/BookForumArticlesService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.peanut.common.utils.PageUtils; import com.peanut.modules.book.entity.BookForumArticlesEntity; +import java.util.List; import java.util.Map; public interface BookForumArticlesService extends IService { @@ -12,5 +13,8 @@ public interface BookForumArticlesService extends IService params); + List getForumsLimit(Integer book_id,Integer limit); + + Integer getForumsCount(Integer book_id); } diff --git a/src/main/java/com/peanut/modules/book/service/BookForumCommenService.java b/src/main/java/com/peanut/modules/book/service/BookForumCommenService.java index 577ffb26..f30fb1d1 100644 --- a/src/main/java/com/peanut/modules/book/service/BookForumCommenService.java +++ b/src/main/java/com/peanut/modules/book/service/BookForumCommenService.java @@ -4,10 +4,18 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.peanut.common.utils.PageUtils; import com.peanut.modules.book.entity.BookForumCommentEntity; +import java.util.List; import java.util.Map; public interface BookForumCommenService extends IService { PageUtils queryPage(Map params); PageUtils importlistqueryPages(Map params); + + + List getCommentsLimit(Integer forum_id,Integer limit); + + Integer getCommentcount(Integer forum_id); + + List getChildComments(Integer cid); } diff --git a/src/main/java/com/peanut/modules/book/service/impl/BookForumArticlesServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/BookForumArticlesServiceImpl.java index 890ba025..910ce131 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/BookForumArticlesServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/BookForumArticlesServiceImpl.java @@ -1,10 +1,12 @@ package com.peanut.modules.book.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.Query; +import com.peanut.modules.app.service.UserService; import com.peanut.modules.book.dao.BookForumArticlesDao; import com.peanut.modules.book.entity.AuthorEntity; import com.peanut.modules.book.entity.BookEntity; @@ -24,6 +26,8 @@ import java.util.Map; @Service public class BookForumArticlesServiceImpl extends ServiceImpl implements BookForumArticlesService { + @Autowired + UserService userService; @Override @@ -57,5 +61,27 @@ public class BookForumArticlesServiceImpl extends ServiceImpl getForumsLimit(Integer book_id,Integer limit) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(BookForumArticlesEntity::getDelflag,0); + wrapper.eq(BookForumArticlesEntity::getBookid,book_id); + wrapper.orderByDesc(BookForumArticlesEntity::getCreateTime); + wrapper.last("limit "+limit); + List bookForumArticlesEntities = this.getBaseMapper().selectList(wrapper); + //补充说话的人的用户信息 + for (BookForumArticlesEntity b : bookForumArticlesEntities){ + b.setUser(userService.getById(b.getUserid())); + } + return bookForumArticlesEntities; + } + @Override + public Integer getForumsCount(Integer book_id) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(BookForumArticlesEntity::getDelflag,0); + wrapper.eq(BookForumArticlesEntity::getBookid,book_id); + int count = this.count(wrapper); + return count; + } } diff --git a/src/main/java/com/peanut/modules/book/service/impl/BookForumCommenServiceImpl.java b/src/main/java/com/peanut/modules/book/service/impl/BookForumCommenServiceImpl.java index 14385e1e..735b1483 100644 --- a/src/main/java/com/peanut/modules/book/service/impl/BookForumCommenServiceImpl.java +++ b/src/main/java/com/peanut/modules/book/service/impl/BookForumCommenServiceImpl.java @@ -1,22 +1,29 @@ package com.peanut.modules.book.service.impl; import cn.com.marsoft.base.impl.BaseServiceImpl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.peanut.common.utils.PageUtils; import com.peanut.common.utils.Query; +import com.peanut.modules.app.entity.UserEntity; +import com.peanut.modules.app.service.UserService; import com.peanut.modules.book.dao.BookForumCommentDao; import com.peanut.modules.book.entity.BookForumArticlesEntity; import com.peanut.modules.book.entity.BookForumCommentEntity; import com.peanut.modules.book.service.BookForumCommenService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; import java.util.Map; @Service public class BookForumCommenServiceImpl extends ServiceImpl implements BookForumCommenService { + @Autowired + private UserService userService; @Override public PageUtils queryPage(Map params) { @@ -39,4 +46,43 @@ public class BookForumCommenServiceImpl extends ServiceImpl getCommentsLimit(Integer forum_id, Integer limit) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(BookForumCommentEntity::getBfaid,forum_id); + wrapper.eq(BookForumCommentEntity::getDelflag,0); + wrapper.orderByDesc(BookForumCommentEntity::getCreateTime); + wrapper.last("limit "+limit); + List bookForumCommentEntities = this.getBaseMapper().selectList(wrapper); + + //完善人员信息 + for (BookForumCommentEntity b : bookForumCommentEntities){ + b.setUser(userService.getById(b.getUserid())); + b.setPuser(userService.getById(b.getPuserid())); + } + + return bookForumCommentEntities; + } + + @Override + public Integer getCommentcount(Integer forum_id) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(BookForumCommentEntity::getBfaid,forum_id); + wrapper.eq(BookForumCommentEntity::getDelflag,0); + int count = this.count(wrapper); + return count; + } + + + @Override + public List getChildComments(Integer cid) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(BookForumCommentEntity::getPid,cid); + wrapper.eq(BookForumCommentEntity::getDelflag,0); + wrapper.orderByAsc(BookForumCommentEntity::getCreateTime); + List bookForumCommentEntities = this.getBaseMapper().selectList(wrapper); + return bookForumCommentEntities; + } }