feat(api): 提交跨端客户端相关接口
This commit is contained in:
1 parent
537027cd61
commit
e8daac0a0a
7 files changed
+90
-5
No files matched your search
+1
-1
@@ -4,4 +4,4 @@
|
||||
**/target
|
||||
**/*.iml
|
||||
**/.DS_Store
|
||||
|
||||
/templates/app/
|
||||
@@ -44,6 +44,8 @@ public enum ResponseStatus implements IResultCode {
|
||||
* 小说相关错误
|
||||
*/
|
||||
BOOK_EXISTS(5001,"该小说已存在"),
|
||||
INDEX_NOT_EXISTS(5002,"该章节不存在!"),
|
||||
NEWS_NOT_EXISTS(5003,"该新闻不存在!"),
|
||||
|
||||
/**
|
||||
* 书单相关错误
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.java2nb.novel.service.BookParagraphCommentService;
|
||||
import com.java2nb.novel.service.BookService;
|
||||
import com.java2nb.novel.service.IpLocationService;
|
||||
import com.java2nb.novel.service.LikeService;
|
||||
import com.java2nb.novel.service.UserService;
|
||||
import com.java2nb.novel.vo.*;
|
||||
import io.github.xxyopen.model.page.PageBean;
|
||||
import io.github.xxyopen.model.page.builder.pagehelper.PageBuilder;
|
||||
@@ -42,6 +43,8 @@ public class BookController extends BaseController {
|
||||
|
||||
private final BookParagraphCommentService bookParagraphCommentService;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
/**
|
||||
* 查询首页小说设置列表数据
|
||||
*/
|
||||
@@ -143,6 +146,53 @@ public class BookController extends BaseController {
|
||||
return RestResult.ok(bookService.listRecBookByCatId(catId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 读者端查询章节正文(供跨端客户端使用)
|
||||
*/
|
||||
@GetMapping("queryBookIndexContent/{indexId}")
|
||||
public RestResult<?> queryBookIndexContent(@PathVariable("indexId") Long indexId,
|
||||
HttpServletRequest request) {
|
||||
BookIndex bookIndex;
|
||||
try {
|
||||
// queryBookIndex 对不存在的章节会抛异常,统一转为业务错误码
|
||||
bookIndex = bookService.queryBookIndex(indexId);
|
||||
} catch (RuntimeException e) {
|
||||
bookIndex = null;
|
||||
}
|
||||
if (bookIndex == null) {
|
||||
return RestResult.fail(ResponseStatus.INDEX_NOT_EXISTS);
|
||||
}
|
||||
Long bookId = bookIndex.getBookId();
|
||||
// 判断是否需要购买(与页面端渲染逻辑保持一致)
|
||||
boolean needBuy = false;
|
||||
if (bookIndex.getIsVip() != null && bookIndex.getIsVip() == 1) {
|
||||
UserDetails user = getUserDetails(request);
|
||||
if (user == null) {
|
||||
// 未登录,需要购买
|
||||
needBuy = true;
|
||||
} else {
|
||||
// 判断用户是否购买过该目录
|
||||
needBuy = !userService.queryIsBuyBookIndex(user.getId(), indexId);
|
||||
}
|
||||
}
|
||||
Map<String, Object> data = new HashMap<>(10);
|
||||
data.put("bookId", bookId);
|
||||
data.put("indexId", indexId);
|
||||
data.put("indexNum", bookIndex.getIndexNum());
|
||||
data.put("indexName", bookIndex.getIndexName());
|
||||
data.put("isVip", bookIndex.getIsVip());
|
||||
data.put("bookPrice", bookIndex.getBookPrice());
|
||||
data.put("preBookIndexId", bookService.queryPreBookIndexId(bookId, bookIndex.getIndexNum()));
|
||||
data.put("nextBookIndexId", bookService.queryNextBookIndexId(bookId, bookIndex.getIndexNum()));
|
||||
data.put("needBuy", needBuy);
|
||||
if (!needBuy) {
|
||||
BookContent bookContent = bookContentServiceMap.get(bookIndex.getStorageType())
|
||||
.queryBookContent(bookId, indexId);
|
||||
data.put("content", bookContent == null ? null : bookContent.getContent());
|
||||
}
|
||||
return RestResult.ok(data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询书籍评论列表
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.java2nb.novel.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import io.github.xxyopen.model.page.PageBean;
|
||||
import com.java2nb.novel.core.enums.ResponseStatus;
|
||||
import com.java2nb.novel.entity.News;
|
||||
import com.java2nb.novel.service.NewsService;
|
||||
import io.github.xxyopen.model.resp.RestResult;
|
||||
@@ -38,6 +39,24 @@ public class NewsController {
|
||||
return RestResult.ok(newsService.listByPage(page,pageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询新闻详情(含正文,供跨端客户端使用)
|
||||
* */
|
||||
@GetMapping("detail/{newsId}")
|
||||
public RestResult<?> detail(@PathVariable("newsId") Long newsId){
|
||||
News news;
|
||||
try {
|
||||
// queryNewsInfo 对不存在的新闻会抛异常,统一转为业务错误码
|
||||
news = newsService.queryNewsInfo(newsId);
|
||||
} catch (RuntimeException e) {
|
||||
news = null;
|
||||
}
|
||||
if (news == null) {
|
||||
return RestResult.fail(ResponseStatus.NEWS_NOT_EXISTS);
|
||||
}
|
||||
return RestResult.ok(news);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加新闻阅读量
|
||||
* */
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.java2nb.novel.core.config;
|
||||
import com.java2nb.novel.core.converter.DateConverter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.format.FormatterRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
@@ -14,4 +15,17 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
public void addFormatters(FormatterRegistry registry) {
|
||||
registry.addConverter(new DateConverter());
|
||||
}
|
||||
|
||||
/**
|
||||
* 跨域配置:供 uni-app 跨端客户端(H5 开发调试/独立部署)直连 REST 接口
|
||||
*/
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOriginPatterns("*")
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
.allowedHeaders("*")
|
||||
.allowCredentials(true)
|
||||
.maxAge(3600);
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class NewsServiceImpl implements NewsService {
|
||||
@Override
|
||||
public PageBean<News> listByPage(int page, int pageSize) {
|
||||
PageHelper.startPage(page, pageSize);
|
||||
SelectStatementProvider selectStatement = select(id, catName, catId, title, createTime)
|
||||
SelectStatementProvider selectStatement = select(id, catName, catId, title, readCount, createTime)
|
||||
.from(news)
|
||||
.orderBy(createTime.descending())
|
||||
.build()
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
<select id="getById" resultType="com.java2nb.novel.vo.BookListVO">
|
||||
select t1.id, t1.user_id, t1.list_name, t1.description, t1.book_count, t1.status,
|
||||
t1.create_time, t1.update_time, t2.username create_user_name, t2.user_photo create_user_photo
|
||||
t1.create_time, t1.update_time, IFNULL(NULLIF(t2.nick_name, ''), t2.username) create_user_name, t2.user_photo create_user_photo
|
||||
from user_book_list t1
|
||||
inner join user t2 on t1.user_id = t2.id
|
||||
where t1.id = #{id}
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
<select id="listMine" resultType="com.java2nb.novel.vo.BookListVO">
|
||||
select t1.id, t1.user_id, t1.list_name, t1.description, t1.book_count, t1.status,
|
||||
t1.create_time, t1.update_time, t2.username create_user_name, t2.user_photo create_user_photo
|
||||
t1.create_time, t1.update_time, IFNULL(NULLIF(t2.nick_name, ''), t2.username) create_user_name, t2.user_photo create_user_photo
|
||||
from user_book_list t1
|
||||
inner join user t2 on t1.user_id = t2.id
|
||||
where t1.user_id = #{userId}
|
||||
@@ -61,7 +61,7 @@
|
||||
|
||||
<select id="listPlaza" resultType="com.java2nb.novel.vo.BookListVO">
|
||||
select t1.id, t1.user_id, t1.list_name, t1.description, t1.book_count, t1.status,
|
||||
t1.create_time, t1.update_time, t2.username create_user_name, t2.user_photo create_user_photo
|
||||
t1.create_time, t1.update_time, IFNULL(NULLIF(t2.nick_name, ''), t2.username) create_user_name, t2.user_photo create_user_photo
|
||||
from user_book_list t1
|
||||
inner join user t2 on t1.user_id = t2.id
|
||||
where t1.status = 1
|
||||
|
||||
Reference in new issue
Block a user