mirror of
https://github.com/201206030/novel-cloud.git
synced 2025-04-27 01:40:50 +00:00
一期开发已完成
This commit is contained in:
parent
bcff5f76db
commit
d066ecb982
@ -8,7 +8,7 @@
|
||||
|
||||
#### 介绍
|
||||
|
||||
基于[小说精品屋-plus](https://www.oschina.net/p/novel-plus)构建的Spring Cloud 微服务小说门户平台,可用于学习和商用。采用了Spring Boot 2 、Spring Cloud Greenwich、 MyBatis3DynamicSql、Redis、Mq、Elasticsearch、Docker等流行技术,集成了Nacos注册中心/配置中心、Spring Cloud Gateway网关、Spring Boot Admin监控中心等基础服务。前端计划使用Vue开发,目前还在 **<u>开发中</u>**,感兴趣的可以提前关注。
|
||||
基于[小说精品屋-plus](https://www.oschina.net/p/novel-plus)构建的Spring Cloud 微服务小说门户平台,可用于学习和商用。采用了Spring Boot 2 、Spring Cloud Greenwich、 MyBatis3DynamicSql、Redis、Mq、Elasticsearch、Docker等流行技术,集成了Nacos注册中心/配置中心、Spring Cloud Gateway网关、Spring Boot Admin监控中心等基础服务。前端计划使用Vue开发,后台接口一期开发已完成(充值/作家专区除外的所有接口)。
|
||||
|
||||
#### 演示地址
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 143 KiB After Width: | Height: | Size: 139 KiB |
@ -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);
|
||||
}
|
||||
|
@ -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)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.java2nb.novel.user.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.java2nb.novel.book.entity.BookComment;
|
||||
import com.java2nb.novel.common.base.BaseController;
|
||||
import com.java2nb.novel.common.bean.PageBean;
|
||||
import com.java2nb.novel.common.bean.ResultBean;
|
||||
@ -9,6 +11,7 @@ import com.java2nb.novel.common.enums.ResponseStatus;
|
||||
import com.java2nb.novel.common.utils.RandomValidateCodeUtil;
|
||||
import com.java2nb.novel.user.entity.User;
|
||||
import com.java2nb.novel.user.entity.UserFeedback;
|
||||
import com.java2nb.novel.user.feign.BookFeignClient;
|
||||
import com.java2nb.novel.user.form.UserForm;
|
||||
import com.java2nb.novel.user.service.UserService;
|
||||
import com.java2nb.novel.user.vo.BookReadHistoryVO;
|
||||
@ -41,6 +44,8 @@ public class UserController extends BaseController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
private final BookFeignClient bookFeignClient;
|
||||
|
||||
/**
|
||||
* 登陆
|
||||
*/
|
||||
@ -274,6 +279,33 @@ public class UserController extends BaseController {
|
||||
return ResultBean.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布评价
|
||||
* */
|
||||
@ApiOperation("发布评价接口")
|
||||
@PostMapping("addBookComment")
|
||||
public ResultBean addBookComment(BookComment comment, HttpServletRequest request) {
|
||||
UserDetails userDetails = getUserDetails(request);
|
||||
if (userDetails == null) {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
bookFeignClient.addBookComment(userDetails.getId(),comment);
|
||||
return ResultBean.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户书评分页查询
|
||||
* */
|
||||
@ApiOperation("用户书评分页查询接口")
|
||||
@GetMapping("listCommentByPage")
|
||||
public ResultBean<PageBean<BookComment>> listCommentByPage(@RequestParam(value = "curr", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "5") int pageSize,HttpServletRequest request) {
|
||||
UserDetails userDetails = getUserDetails(request);
|
||||
if (userDetails == null) {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
return ResultBean.ok(new PageBean<>(bookFeignClient.listUserCommentByPage(userDetails.getId(),page,pageSize)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -147,4 +147,5 @@ public interface UserService {
|
||||
* @param newPassword 新密码
|
||||
* */
|
||||
void updatePassword(Long userId, String oldPassword, String newPassword);
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.java2nb.novel.user.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.java2nb.novel.book.entity.Book;
|
||||
import com.java2nb.novel.book.entity.BookComment;
|
||||
import com.java2nb.novel.common.bean.UserDetails;
|
||||
import com.java2nb.novel.common.enums.ResponseStatus;
|
||||
import com.java2nb.novel.common.exception.BusinessException;
|
||||
@ -42,6 +43,7 @@ import static org.mybatis.dynamic.sql.select.SelectDSL.select;
|
||||
|
||||
/**
|
||||
* 小说服务接口实现
|
||||
*
|
||||
* @author xiongxiaoyang
|
||||
* @version 1.0
|
||||
* @since 2020/5/28
|
||||
@ -287,6 +289,7 @@ public class UserServiceImpl implements UserService {
|
||||
.build()
|
||||
.render(RenderingStrategies.MYBATIS3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public User userInfo(Long userId) {
|
||||
SelectStatementProvider selectStatement = select(UserDynamicSqlSupport.username, UserDynamicSqlSupport.nickName,
|
||||
@ -331,4 +334,5 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user