一期开发已完成

This commit is contained in:
xiongxiaoyang
2020-05-29 09:22:53 +08:00
parent bcff5f76db
commit d066ecb982
11 changed files with 167 additions and 35 deletions

View File

@ -1,7 +1,10 @@
package com.java2nb.novel.book.api;
import com.java2nb.novel.book.entity.Book;
import com.java2nb.novel.book.entity.BookComment;
import com.java2nb.novel.book.vo.BookCommentVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
@ -50,5 +53,21 @@ public interface BookApi {
@GetMapping("api/book/queryBookById")
Book queryBookById(@RequestParam("id") Long id);
/**
* 新增评论
* @param userId 用户ID
* @param comment 评论数据
* */
@PostMapping("api/book/addBookComment")
void addBookComment(@RequestParam("userId") Long userId,@RequestParam("comment") BookComment comment);
/**
* 分页查询用户评论
* @param userId 用户ID
* @param page 查询页码
* @param pageSize 分页大小
* @return 评论数据
* */
@GetMapping("api/book/listUserCommentByPage")
List<BookComment> listUserCommentByPage(@RequestParam("userId") Long userId,@RequestParam("page") int page, @RequestParam("pageSize") int pageSize);
}

View File

@ -102,7 +102,7 @@ public class BookController {
@ApiOperation("书籍评论列表分页查询接口")
@GetMapping("listCommentByPage")
public ResultBean<List<BookCommentVO>> listCommentByPage(@ApiParam("小说ID") @RequestParam("bookId") Long bookId, @ApiParam("当前页码") @RequestParam(value = "curr", defaultValue = "1") int page, @ApiParam("分页大小") @RequestParam(value = "limit", defaultValue = "5") int pageSize) {
return ResultBean.ok(new PageBean<>(bookService.listCommentByPage(null,bookId,page,pageSize)));
return ResultBean.ok(new PageBean<>(bookService.listBookCommentByPage(bookId,page,pageSize)));
}
/**

View File

@ -1,10 +1,10 @@
package com.java2nb.novel.book.controller.api;
import com.java2nb.novel.book.entity.Book;
import com.java2nb.novel.book.entity.BookComment;
import com.java2nb.novel.book.service.BookService;
import io.swagger.annotations.Api;
import com.java2nb.novel.book.vo.BookCommentVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
@ -69,4 +69,26 @@ public class BookApi {
Book queryBookById(@RequestParam("id") Long id){
return bookService.queryBookDetail(id);
}
/**
* 新增评论
* @param userId 用户ID
* @param comment 评论数据
* */
@PostMapping("addBookComment")
void addBookComment(Long userId, BookComment comment){
bookService.addBookComment(userId,comment);
}
/**
* 分页查询用户评论
* @param userId 用户ID
* @param page 查询页码
* @param pageSize 分页大小
* @return 评论数据
* */
@GetMapping("listUserCommentByPage")
List<BookComment> listUserCommentByPage(@RequestParam("userId") Long userId,@RequestParam("page") int page, @RequestParam("pageSize") int pageSize){
return bookService.listUserCommentByPage(userId,page,pageSize);
}
}

View File

@ -311,4 +311,6 @@ public interface BookMapper {
void addVisitCount(@Param("bookId") Long bookId, @Param("visitCount") Integer visitCount);
List<Book> listRecBookByCatId(@Param("catId") Integer catId);
void addCommentCount(@Param("bookId") Long bookId);
}

View File

@ -1,9 +1,6 @@
package com.java2nb.novel.book.service;
import com.java2nb.novel.book.entity.Book;
import com.java2nb.novel.book.entity.BookCategory;
import com.java2nb.novel.book.entity.BookContent;
import com.java2nb.novel.book.entity.BookIndex;
import com.java2nb.novel.book.entity.*;
import com.java2nb.novel.book.vo.BookCommentVO;
import java.util.Date;
@ -84,13 +81,12 @@ public interface BookService {
/**
*分页查询书籍评论列表
* @param userId 用户ID
* @param bookId 书籍ID
* @param page 页码
* @param pageSize 分页大小
* @return 评论集合
* */
List<BookCommentVO> listCommentByPage(Long userId, Long bookId, int page, int pageSize);
List<BookCommentVO> listBookCommentByPage( Long bookId, int page, int pageSize);
/**
* 查询目录列表
@ -124,4 +120,20 @@ public interface BookService {
* @return 上一章节和下一章节目录ID数据
* */
Map<String,Long> queryPreAndNextBookIndexId(Long bookId, Integer indexNum);
/**
* 新增评价
* @param userId 用户ID
* @param comment 评论内容
* */
void addBookComment(Long userId, BookComment comment);
/**
* 分页查询用户评论
* @param userId 用户ID
* @param page 查询页码
* @param pageSize 分页大小
* @return 评论数据
* */
List<BookComment> listUserCommentByPage(Long userId, int page, int pageSize);
}

View File

@ -6,6 +6,8 @@ import com.java2nb.novel.book.feign.UserFeignClient;
import com.java2nb.novel.book.mapper.*;
import com.java2nb.novel.book.service.BookService;
import com.java2nb.novel.book.vo.BookCommentVO;
import com.java2nb.novel.common.enums.ResponseStatus;
import com.java2nb.novel.common.exception.BusinessException;
import com.java2nb.novel.common.utils.BeanUtil;
import com.java2nb.novel.user.entity.User;
import lombok.RequiredArgsConstructor;
@ -15,6 +17,7 @@ import org.mybatis.dynamic.sql.render.RenderingStrategies;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.orderbyhelper.OrderByHelper;
import java.util.*;
@ -166,7 +169,7 @@ public class BookServiceImpl implements BookService {
}
@Override
public List<BookCommentVO> listCommentByPage(Long userId, Long bookId, int page, int pageSize) {
public List<BookCommentVO> listBookCommentByPage(Long bookId, int page, int pageSize) {
//分页查询小说评论数据
PageHelper.startPage(page, pageSize);
List<BookComment> bookCommentList = bookCommentMapper.selectMany(
@ -280,4 +283,41 @@ public class BookServiceImpl implements BookService {
return result;
}
@Transactional(rollbackFor = Exception.class)
@Override
public void addBookComment(Long userId, BookComment comment) {
//判断该用户是否已评论过该书籍
SelectStatementProvider selectStatement = select(count(BookCommentDynamicSqlSupport.id))
.from(BookCommentDynamicSqlSupport.bookComment)
.where(BookCommentDynamicSqlSupport.createUserId, isEqualTo(userId))
.and(BookCommentDynamicSqlSupport.bookId, isEqualTo(comment.getBookId()))
.build()
.render(RenderingStrategies.MYBATIS3);
if (bookCommentMapper.count(selectStatement) > 0) {
throw new BusinessException(ResponseStatus.HAS_COMMENTS);
}
//增加评论
comment.setCreateUserId(userId);
comment.setCreateTime(new Date());
bookCommentMapper.insertSelective(comment);
//增加书籍评论数
bookMapper.addCommentCount(comment.getBookId());
}
@Override
public List<BookComment> listUserCommentByPage(Long userId, int page, int pageSize) {
PageHelper.startPage(page, pageSize);
return bookCommentMapper.selectMany(
select(BookCommentDynamicSqlSupport.id,BookCommentDynamicSqlSupport.bookId,
BookCommentDynamicSqlSupport.createUserId,
BookCommentDynamicSqlSupport.commentContent,BookCommentDynamicSqlSupport.replyCount,
BookCommentDynamicSqlSupport.createTime)
.from(BookCommentDynamicSqlSupport.bookComment)
.where(BookCommentDynamicSqlSupport.createUserId,isEqualTo(userId))
.orderBy(BookCommentDynamicSqlSupport.createTime.descending())
.build()
.render(RenderingStrategies.MYBATIS3));
}
}