mirror of
https://github.com/201206030/novel-plus.git
synced 2025-07-06 01:06:39 +00:00
上传代码
This commit is contained in:
@ -0,0 +1,44 @@
|
||||
package com.java2nb.novel.controller;
|
||||
|
||||
import com.java2nb.novel.core.bean.UserDetails;
|
||||
import com.java2nb.novel.core.utils.JwtTokenUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author 11797
|
||||
*/
|
||||
public class BaseController {
|
||||
|
||||
protected JwtTokenUtil jwtTokenUtil;
|
||||
|
||||
|
||||
protected String getToken(HttpServletRequest request){
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if(cookies != null) {
|
||||
for (Cookie cookie : cookies) {
|
||||
if (cookie.getName().equals("Authorization")) {
|
||||
return cookie.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return request.getHeader("Authorization");
|
||||
}
|
||||
|
||||
protected UserDetails getUserDetails(HttpServletRequest request) {
|
||||
String token = getToken(request);
|
||||
if(StringUtils.isBlank(token)){
|
||||
return null;
|
||||
}else{
|
||||
return jwtTokenUtil.getUserDetailsFromToken(token);
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setJwtTokenUtil(JwtTokenUtil jwtTokenUtil) {
|
||||
this.jwtTokenUtil = jwtTokenUtil;
|
||||
}
|
||||
}
|
@ -0,0 +1,164 @@
|
||||
package com.java2nb.novel.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.java2nb.novel.core.bean.ResultBean;
|
||||
import com.java2nb.novel.core.bean.UserDetails;
|
||||
import com.java2nb.novel.core.enums.ResponseStatus;
|
||||
import com.java2nb.novel.entity.Book;
|
||||
import com.java2nb.novel.entity.BookComment;
|
||||
import com.java2nb.novel.entity.BookIndex;
|
||||
import com.java2nb.novel.search.BookSP;
|
||||
import com.java2nb.novel.service.BookService;
|
||||
import com.java2nb.novel.vo.BookVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 11797
|
||||
*/
|
||||
@RequestMapping("book")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class BookController extends BaseController{
|
||||
|
||||
private final BookService bookService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询首页小说设置列表数据
|
||||
* */
|
||||
@PostMapping("listBookSetting")
|
||||
public ResultBean listBookSetting(){
|
||||
return ResultBean.ok(bookService.listBookSettingVO());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询首页点击榜单数据
|
||||
* */
|
||||
@PostMapping("listClickRank")
|
||||
public ResultBean listClickRank(){
|
||||
return ResultBean.ok(bookService.listClickRank());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询首页新书榜单数据
|
||||
* */
|
||||
@PostMapping("listNewRank")
|
||||
public ResultBean listNewRank(){
|
||||
return ResultBean.ok(bookService.listNewRank());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询首页更新榜单数据
|
||||
* */
|
||||
@PostMapping("listUpdateRank")
|
||||
public ResultBean listUpdateRank(){
|
||||
return ResultBean.ok(bookService.listUpdateRank());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询小说分类列表
|
||||
* */
|
||||
@PostMapping("listBookCategory")
|
||||
public ResultBean listBookCategory(){
|
||||
return ResultBean.ok(bookService.listBookCategory());
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页搜索
|
||||
* */
|
||||
@PostMapping("searchByPage")
|
||||
public ResultBean searchByPage(BookSP bookSP, @RequestParam(value = "curr", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "20") int pageSize){
|
||||
List<BookVO> books = bookService.searchByPage(bookSP,page,pageSize);
|
||||
return ResultBean.ok(new PageInfo<>(books));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询小说详情信息
|
||||
* */
|
||||
@PostMapping("queryBookDetail")
|
||||
public ResultBean queryBookDetail(Long id){
|
||||
return ResultBean.ok(bookService.queryBookDetail(id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询小说排行信息
|
||||
* */
|
||||
@PostMapping("listRank")
|
||||
public ResultBean listRank(@RequestParam(value = "type",defaultValue = "0") Byte type,@RequestParam(value = "limit",defaultValue = "30") Integer limit){
|
||||
return ResultBean.ok(bookService.listRank(type,limit));
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加点击次数
|
||||
* */
|
||||
@PostMapping("addVisitCount")
|
||||
public ResultBean addVisitCount(Long bookId){
|
||||
bookService.addVisitCount(bookId);
|
||||
return ResultBean.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询章节相关信息
|
||||
* */
|
||||
@PostMapping("queryBookIndexAbout")
|
||||
public ResultBean queryBookIndexAbout(Long bookId,Long lastBookIndexId) {
|
||||
Map<String,Object> data = new HashMap<>(2);
|
||||
data.put("bookIndexCount",bookService.queryIndexCount(bookId));
|
||||
data.put("lastBookContent",bookService.queryBookContent(lastBookIndexId).getContent().substring(0,42));
|
||||
return ResultBean.ok(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类id查询同类推荐书籍
|
||||
* */
|
||||
@PostMapping("listRecBookByCatId")
|
||||
public ResultBean listRecBookByCatId(Integer catId) {
|
||||
return ResultBean.ok(bookService.listRecBookByCatId(catId));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*分页查询书籍评论列表
|
||||
* */
|
||||
@PostMapping("listCommentByPage")
|
||||
public ResultBean listCommentByPage(@RequestParam("bookId") Long bookId,@RequestParam(value = "curr", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "5") int pageSize) {
|
||||
return ResultBean.ok(new PageInfo<>(bookService.listCommentByPage(null,bookId,page,pageSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增评价
|
||||
* */
|
||||
@PostMapping("addBookComment")
|
||||
public ResultBean addBookComment(BookComment comment, HttpServletRequest request) {
|
||||
UserDetails userDetails = getUserDetails(request);
|
||||
if (userDetails == null) {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
bookService.addBookComment(userDetails.getId(),comment);
|
||||
return ResultBean.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据小说ID查询小说前十条最新更新目录集合
|
||||
* */
|
||||
@PostMapping("queryNewIndexList")
|
||||
public ResultBean queryNewIndexList(Long bookId){
|
||||
return ResultBean.ok(bookService.queryIndexList(bookId,"index_num desc",10));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package com.java2nb.novel.controller;
|
||||
|
||||
import com.java2nb.novel.core.bean.ResultBean;
|
||||
import com.java2nb.novel.core.cache.CacheKey;
|
||||
import com.java2nb.novel.core.cache.CacheService;
|
||||
import com.java2nb.novel.core.enums.ResponseStatus;
|
||||
import com.java2nb.novel.service.BookService;
|
||||
import com.java2nb.novel.service.FriendLinkService;
|
||||
import com.java2nb.novel.service.NewsService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author 11797
|
||||
*/
|
||||
@RequestMapping("cache")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class CacheController {
|
||||
|
||||
@Value("${cache.manager.password}")
|
||||
private String cacheManagerPass;
|
||||
|
||||
private final CacheService cacheService;
|
||||
|
||||
private final BookService bookService;
|
||||
|
||||
private final NewsService newsService;
|
||||
|
||||
private final FriendLinkService friendLinkService;
|
||||
|
||||
/**
|
||||
* 刷新缓存
|
||||
* @param type 缓存类型,1:首页书籍推荐,2:首页新闻,3:首页友情链接
|
||||
* */
|
||||
@GetMapping("refresh/{pass}/{type}")
|
||||
public ResultBean refreshCache(@PathVariable("type") Byte type, @PathVariable("pass") String pass){
|
||||
if(!cacheManagerPass.equals(pass)){
|
||||
return ResultBean.fail(ResponseStatus.PASSWORD_ERROR);
|
||||
}
|
||||
switch (type){
|
||||
case 1:{
|
||||
//刷新首页推荐书籍缓存
|
||||
cacheService.del(CacheKey.INDEX_BOOK_SETTINGS_KEY);
|
||||
bookService.listBookSettingVO();
|
||||
break;
|
||||
}
|
||||
case 2:{
|
||||
//刷新首页新闻缓存
|
||||
cacheService.del(CacheKey.INDEX_NEWS_KEY);
|
||||
newsService.listIndexNews();
|
||||
break;
|
||||
}
|
||||
case 3:{
|
||||
//刷新首页友情链接
|
||||
cacheService.del(CacheKey.INDEX_LINK_KEY);
|
||||
friendLinkService.listIndexLink();
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ResultBean.ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.java2nb.novel.controller;
|
||||
|
||||
import com.java2nb.novel.core.cache.CacheService;
|
||||
import com.java2nb.novel.core.utils.RandomValidateCodeUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
* @author 11797
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("file")
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class FileController {
|
||||
|
||||
private final CacheService cacheService;
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
*/
|
||||
@GetMapping(value = "getVerify")
|
||||
public void getVerify(HttpServletRequest request, HttpServletResponse response) {
|
||||
try {
|
||||
//设置相应类型,告诉浏览器输出的内容为图片
|
||||
response.setContentType("image/jpeg");
|
||||
//设置响应头信息,告诉浏览器不要缓存此内容
|
||||
response.setHeader("Pragma", "No-cache");
|
||||
response.setHeader("Cache-Control", "no-cache");
|
||||
response.setDateHeader("Expire", 0);
|
||||
RandomValidateCodeUtil randomValidateCode = new RandomValidateCodeUtil();
|
||||
//输出验证码图片方法
|
||||
randomValidateCode.getRandcode(cacheService, response);
|
||||
} catch (Exception e) {
|
||||
log.error("获取验证码失败>>>> ", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.java2nb.novel.controller;
|
||||
|
||||
import com.java2nb.novel.core.bean.ResultBean;
|
||||
import com.java2nb.novel.service.FriendLinkService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author 11797
|
||||
*/
|
||||
@RequestMapping("friendLink")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class FriendLinkController {
|
||||
|
||||
private final FriendLinkService friendLinkService;
|
||||
|
||||
/**
|
||||
* 查询首页友情链接
|
||||
* */
|
||||
@PostMapping("listIndexLink")
|
||||
public ResultBean listIndexLink(){
|
||||
return ResultBean.ok(friendLinkService.listIndexLink());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.java2nb.novel.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.java2nb.novel.core.bean.ResultBean;
|
||||
import com.java2nb.novel.service.NewsService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author 11797
|
||||
*/
|
||||
@RequestMapping("news")
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class NewsController {
|
||||
|
||||
private final NewsService newsService;
|
||||
|
||||
/**
|
||||
* 查询首页新闻
|
||||
* */
|
||||
@PostMapping("listIndexNews")
|
||||
public ResultBean listIndexNews(){
|
||||
return ResultBean.ok(newsService.listIndexNews());
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询新闻列表
|
||||
* */
|
||||
@PostMapping("listByPage")
|
||||
public ResultBean listByPage(@RequestParam(value = "curr", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "5") int pageSize){
|
||||
return ResultBean.ok(new PageInfo<>(newsService.listByPage(page,pageSize)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,144 @@
|
||||
package com.java2nb.novel.controller;
|
||||
|
||||
import com.java2nb.novel.core.utils.TemplateUtil;
|
||||
import com.java2nb.novel.entity.Book;
|
||||
import com.java2nb.novel.entity.BookContent;
|
||||
import com.java2nb.novel.entity.BookIndex;
|
||||
import com.java2nb.novel.entity.News;
|
||||
import com.java2nb.novel.service.BookService;
|
||||
import com.java2nb.novel.service.NewsService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 11797
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Controller
|
||||
public class PageController{
|
||||
|
||||
private final BookService bookService;
|
||||
|
||||
private final NewsService newsService;
|
||||
|
||||
|
||||
@RequestMapping("{url}.html")
|
||||
public String module(@PathVariable("url") String url) {
|
||||
return url;
|
||||
}
|
||||
|
||||
@RequestMapping("{module}/{url}.html")
|
||||
public String module2(@PathVariable("module") String module, @PathVariable("url") String url) {
|
||||
return module + "/" + url;
|
||||
}
|
||||
|
||||
@RequestMapping("{module}/{classify}/{url}.html")
|
||||
public String module3(@PathVariable("module") String module, @PathVariable("classify") String classify, @PathVariable("url") String url) {
|
||||
return module + "/" + classify + "/" + url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页
|
||||
* */
|
||||
@RequestMapping(path = {"/", "/index", "/index.html"})
|
||||
public String index() {
|
||||
return TemplateUtil.getTemplateDir()+"index";
|
||||
}
|
||||
|
||||
/**
|
||||
* 作品页
|
||||
* */
|
||||
@RequestMapping("book/bookclass.html")
|
||||
public String bookClass() {
|
||||
return "book/bookclass";
|
||||
}
|
||||
|
||||
/**
|
||||
* 排行页
|
||||
* */
|
||||
@RequestMapping("book/book_ranking.html")
|
||||
public String bookRank() {
|
||||
|
||||
return TemplateUtil.getTemplateDir()+"book/book_ranking";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 详情页
|
||||
* */
|
||||
@RequestMapping("/book/{bookId}.html")
|
||||
public String bookDetail(@PathVariable("bookId") Long bookId, Model model) {
|
||||
Book book = bookService.queryBookDetail(bookId);
|
||||
model.addAttribute("book",book);
|
||||
//查询首章目录ID
|
||||
Long firstBookIndexId = bookService.queryFirstBookIndexId(bookId);
|
||||
model.addAttribute("firstBookIndexId",firstBookIndexId);
|
||||
return TemplateUtil.getTemplateDir()+"book/book_detail";
|
||||
}
|
||||
|
||||
/**
|
||||
* 目录页
|
||||
* */
|
||||
@RequestMapping("/book/indexList-{bookId}.html")
|
||||
public String indexList(@PathVariable("bookId") Long bookId, Model model) {
|
||||
Book book = bookService.queryBookDetail(bookId);
|
||||
model.addAttribute("book",book);
|
||||
List<BookIndex> bookIndexList = bookService.queryIndexList(bookId,null,null);
|
||||
model.addAttribute("bookIndexList",bookIndexList);
|
||||
model.addAttribute("bookIndexCount",bookIndexList.size());
|
||||
return TemplateUtil.getTemplateDir()+"book/book_index";
|
||||
}
|
||||
|
||||
/**
|
||||
* 内容页
|
||||
* */
|
||||
@RequestMapping("/book/{bookId}/{bookIndexId}.html")
|
||||
public String indexList(@PathVariable("bookId") Long bookId,@PathVariable("bookIndexId") Long bookIndexId, Model model) {
|
||||
//查询书籍
|
||||
Book book = bookService.queryBookDetail(bookId);
|
||||
model.addAttribute("book",book);
|
||||
//查询目录
|
||||
BookIndex bookIndex = bookService.queryBookIndex(bookIndexId);
|
||||
model.addAttribute("bookIndex",bookIndex);
|
||||
//查询上一章节目录ID
|
||||
Long preBookIndexId = bookService.queryPreBookIndexId(bookId,bookIndex.getIndexNum());
|
||||
model.addAttribute("preBookIndexId",preBookIndexId);
|
||||
//查询下一章目录ID
|
||||
Long nextBookIndexId = bookService.queryNextBookIndexId(bookId,bookIndex.getIndexNum());
|
||||
model.addAttribute("nextBookIndexId",nextBookIndexId);
|
||||
//查询内容
|
||||
BookContent bookContent = bookService.queryBookContent(bookIndex.getId());
|
||||
model.addAttribute("bookContent",bookContent);
|
||||
return TemplateUtil.getTemplateDir()+"book/book_content";
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论页面
|
||||
* */
|
||||
@RequestMapping("/book/comment-{bookId}.html")
|
||||
public String commentList(@PathVariable("bookId") Long bookId, Model model) {
|
||||
//查询书籍
|
||||
Book book = bookService.queryBookDetail(bookId);
|
||||
model.addAttribute("book",book);
|
||||
return "book/book_comment";
|
||||
}
|
||||
|
||||
/**
|
||||
* 新闻内容页面
|
||||
* */
|
||||
@RequestMapping("/about/newsInfo-{newsId}.html")
|
||||
public String newsInfo(@PathVariable("newsId") Long newsId, Model model) {
|
||||
//查询新闻
|
||||
News news = newsService.queryNewsInfo(newsId);
|
||||
model.addAttribute("news",news);
|
||||
return "about/news_info";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,269 @@
|
||||
package com.java2nb.novel.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.java2nb.novel.core.bean.ResultBean;
|
||||
import com.java2nb.novel.core.bean.UserDetails;
|
||||
import com.java2nb.novel.core.cache.CacheService;
|
||||
import com.java2nb.novel.core.enums.ResponseStatus;
|
||||
import com.java2nb.novel.core.utils.RandomValidateCodeUtil;
|
||||
import com.java2nb.novel.entity.User;
|
||||
import com.java2nb.novel.form.UserForm;
|
||||
import com.java2nb.novel.service.BookService;
|
||||
import com.java2nb.novel.service.UserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author 11797
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("user")
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class UserController extends BaseController {
|
||||
|
||||
|
||||
private final CacheService cacheService;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
private final BookService bookService;
|
||||
|
||||
/**
|
||||
* 登陆
|
||||
*/
|
||||
@PostMapping("login")
|
||||
public ResultBean login(@Valid UserForm user, BindingResult result) {
|
||||
//判断参数是否合法
|
||||
if (result.hasErrors()) {
|
||||
log.info(result.getAllErrors().toString());
|
||||
return ResultBean.fail(ResponseStatus.PARAM_ERROR);
|
||||
}
|
||||
|
||||
//登陆
|
||||
UserDetails userDetails = userService.login(user);
|
||||
|
||||
Map<String, Object> data = new HashMap<>(1);
|
||||
data.put("token", jwtTokenUtil.generateToken(userDetails));
|
||||
|
||||
return ResultBean.ok(data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
@PostMapping("register")
|
||||
public ResultBean register(@Valid UserForm user, @RequestParam(value = "velCode", defaultValue = "") String velCode, BindingResult result) {
|
||||
|
||||
//判断参数是否合法
|
||||
if (result.hasErrors()) {
|
||||
log.info(result.getAllErrors().toString());
|
||||
return ResultBean.fail(ResponseStatus.PARAM_ERROR);
|
||||
}
|
||||
|
||||
//判断验证码是否正确
|
||||
if (!velCode.equals(cacheService.get(RandomValidateCodeUtil.RANDOM_CODE_KEY))) {
|
||||
return ResultBean.fail(ResponseStatus.VEL_CODE_ERROR);
|
||||
}
|
||||
|
||||
//注册
|
||||
UserDetails userDetails = userService.register(user);
|
||||
Map<String, Object> data = new HashMap<>(1);
|
||||
data.put("token", jwtTokenUtil.generateToken(userDetails));
|
||||
|
||||
return ResultBean.ok(data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 刷新token
|
||||
*/
|
||||
@PostMapping("refreshToken")
|
||||
public ResultBean refreshToken(HttpServletRequest request) {
|
||||
String token = getToken(request);
|
||||
if (jwtTokenUtil.canRefresh(token)) {
|
||||
token = jwtTokenUtil.refreshToken(token);
|
||||
Map<String, Object> data = new HashMap<>(2);
|
||||
data.put("token", token);
|
||||
data.put("username", jwtTokenUtil.getUserDetailsFromToken(token).getUsername());
|
||||
return ResultBean.ok(data);
|
||||
|
||||
} else {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询小说是否已加入书架
|
||||
*/
|
||||
@PostMapping("queryIsInShelf")
|
||||
public ResultBean queryIsInShelf(Long bookId, HttpServletRequest request) {
|
||||
UserDetails userDetails = getUserDetails(request);
|
||||
if (userDetails == null) {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
return ResultBean.ok(userService.queryIsInShelf(userDetails.getId(), bookId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 加入书架
|
||||
* */
|
||||
@PostMapping("addToBookShelf")
|
||||
public ResultBean addToBookShelf(Long bookId,Long preContentId, HttpServletRequest request) {
|
||||
UserDetails userDetails = getUserDetails(request);
|
||||
if (userDetails == null) {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
userService.addToBookShelf(userDetails.getId(),bookId,preContentId);
|
||||
return ResultBean.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 移出书架
|
||||
* */
|
||||
@PostMapping("removeFromBookShelf")
|
||||
public ResultBean removeFromBookShelf(Long bookId, HttpServletRequest request) {
|
||||
UserDetails userDetails = getUserDetails(request);
|
||||
if (userDetails == null) {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
userService.removeFromBookShelf(userDetails.getId(),bookId);
|
||||
return ResultBean.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询书架
|
||||
* */
|
||||
@PostMapping("listBookShelfByPage")
|
||||
public ResultBean listBookShelfByPage(@RequestParam(value = "curr", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "10") int pageSize,HttpServletRequest request) {
|
||||
UserDetails userDetails = getUserDetails(request);
|
||||
if (userDetails == null) {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
return ResultBean.ok(new PageInfo<>(userService.listBookShelfByPage(userDetails.getId(),page,pageSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询阅读记录
|
||||
* */
|
||||
@PostMapping("listReadHistoryByPage")
|
||||
public ResultBean listReadHistoryByPage(@RequestParam(value = "curr", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "10") int pageSize,HttpServletRequest request) {
|
||||
UserDetails userDetails = getUserDetails(request);
|
||||
if (userDetails == null) {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
return ResultBean.ok(new PageInfo<>(userService.listReadHistoryByPage(userDetails.getId(),page,pageSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加阅读记录
|
||||
* */
|
||||
@PostMapping("addReadHistory")
|
||||
public ResultBean addReadHistory(Long bookId,Long preContentId, HttpServletRequest request) {
|
||||
UserDetails userDetails = getUserDetails(request);
|
||||
if (userDetails == null) {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
userService.addReadHistory(userDetails.getId(),bookId,preContentId);
|
||||
return ResultBean.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加反馈
|
||||
* */
|
||||
@PostMapping("addFeedBack")
|
||||
public ResultBean addFeedBack(String content, HttpServletRequest request) {
|
||||
UserDetails userDetails = getUserDetails(request);
|
||||
if (userDetails == null) {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
userService.addFeedBack(userDetails.getId(),content);
|
||||
return ResultBean.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询我的反馈列表
|
||||
* */
|
||||
@PostMapping("listUserFeedBackByPage")
|
||||
public ResultBean listUserFeedBackByPage(@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 PageInfo<>(userService.listUserFeedBackByPage(userDetails.getId(),page,pageSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询个人信息
|
||||
* */
|
||||
@PostMapping("userInfo")
|
||||
public ResultBean userInfo(HttpServletRequest request) {
|
||||
UserDetails userDetails = getUserDetails(request);
|
||||
if (userDetails == null) {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
return ResultBean.ok(userService.userInfo(userDetails.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新个人信息
|
||||
* */
|
||||
@PostMapping("updateUserInfo")
|
||||
public ResultBean updateUserInfo(User user,HttpServletRequest request) {
|
||||
UserDetails userDetails = getUserDetails(request);
|
||||
if (userDetails == null) {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
userService.updateUserInfo(userDetails.getId(),user);
|
||||
return ResultBean.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新密码
|
||||
* */
|
||||
@PostMapping("updatePassword")
|
||||
public ResultBean updatePassword(String oldPassword,String newPassword1,String newPassword2,HttpServletRequest request) {
|
||||
UserDetails userDetails = getUserDetails(request);
|
||||
if (userDetails == null) {
|
||||
return ResultBean.fail(ResponseStatus.NO_LOGIN);
|
||||
}
|
||||
if(!(StringUtils.isNotBlank(newPassword1) && newPassword1.equals(newPassword2))){
|
||||
ResultBean.fail(ResponseStatus.TWO_PASSWORD_DIFF);
|
||||
}
|
||||
userService.updatePassword(userDetails.getId(),oldPassword,newPassword1);
|
||||
return ResultBean.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询用户书评
|
||||
* */
|
||||
@PostMapping("listCommentByPage")
|
||||
public ResultBean 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 PageInfo<>(bookService.listCommentByPage(userDetails.getId(),null,page,pageSize)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user