diff --git a/src/main/java/io/github/xxyopen/novel/controller/front/BookController.java b/src/main/java/io/github/xxyopen/novel/controller/front/BookController.java index f4f8115..334f226 100644 --- a/src/main/java/io/github/xxyopen/novel/controller/front/BookController.java +++ b/src/main/java/io/github/xxyopen/novel/controller/front/BookController.java @@ -27,39 +27,39 @@ public class BookController { /** * 小说搜索接口 - * */ + */ @GetMapping("search") - public RestResp> searchBooks(BookSearchReqDto condition){ + public RestResp> searchBooks(BookSearchReqDto condition) { return bookService.searchBooks(condition); } /** * 小说信息查询接口 - * */ + */ @GetMapping("{bookId}") - public RestResp getBookById(@PathVariable("bookId") Long bookId){ + public RestResp getBookById(@PathVariable("bookId") Long bookId) { return bookService.getBookById(bookId); } /** * 增加小说点击量接口 - * */ + */ @PostMapping("visit") - public RestResp addVisitCount(Long bookId){ + public RestResp addVisitCount(Long bookId) { return bookService.addVisitCount(bookId); } /** * 小说最新章节相关信息查询接口 - * */ + */ @GetMapping("lastChapterAbout") - public RestResp getLastChapterAbout(Long bookId){ + public RestResp getLastChapterAbout(Long bookId) { return bookService.getLastChapterAbout(bookId); } /** * 小说推荐列表查询接口 - * */ + */ @GetMapping("recList") public RestResp> listRecBooks(Long bookId) throws NoSuchAlgorithmException { return bookService.listRecBooks(bookId); @@ -67,59 +67,58 @@ public class BookController { /** * 小说章节列表查询接口 - * */ + */ @GetMapping("chapterList") - public RestResp> listChapters(Long bookId){ + public RestResp> listChapters(Long bookId) { return bookService.listChapters(bookId); } /** * 小说内容相关信息查询接口 - * */ + */ @GetMapping("content/{chapterId}") - public RestResp getBookContentAbout(@PathVariable("chapterId") Long chapterId){ + public RestResp getBookContentAbout(@PathVariable("chapterId") Long chapterId) { return bookService.getBookContentAbout(chapterId); } /** * 获取上一章节ID接口 - * */ + */ @GetMapping("preChapterId/{chapterId}") - public RestResp getPreChapterId(@PathVariable("chapterId") Long chapterId){ + public RestResp getPreChapterId(@PathVariable("chapterId") Long chapterId) { return bookService.getPreChapterId(chapterId); } /** * 获取下一章节ID接口 - * */ + */ @GetMapping("nextChapterId/{chapterId}") - public RestResp nextChapterId(@PathVariable("chapterId") Long chapterId){ + public RestResp nextChapterId(@PathVariable("chapterId") Long chapterId) { return bookService.nextChapterId(chapterId); } /** * 小说点击榜查询接口 - * */ + */ @GetMapping("visitRank") - public RestResp> listVisitRankBooks(){ + public RestResp> listVisitRankBooks() { return bookService.listVisitRankBooks(); } /** * 小说新书榜查询接口 - * */ + */ @GetMapping("newestRank") - public RestResp> listNewestRankBooks(){ + public RestResp> listNewestRankBooks() { return bookService.listNewestRankBooks(); } /** * 小说更新榜查询接口 - * */ + */ @GetMapping("updateRank") - public RestResp> listUpdateRankBooks(){ + public RestResp> listUpdateRankBooks() { return bookService.listUpdateRankBooks(); } - } diff --git a/src/main/java/io/github/xxyopen/novel/controller/front/HomeController.java b/src/main/java/io/github/xxyopen/novel/controller/front/HomeController.java index eb34223..2f388fe 100644 --- a/src/main/java/io/github/xxyopen/novel/controller/front/HomeController.java +++ b/src/main/java/io/github/xxyopen/novel/controller/front/HomeController.java @@ -27,17 +27,17 @@ public class HomeController { /** * 首页小说推荐查询接口 - * */ + */ @GetMapping("books") - public RestResp> listHomeBooks(){ + public RestResp> listHomeBooks() { return homeService.listHomeBooks(); } /** * 首页友情链接列表查询接口 - * */ + */ @GetMapping("friendLinks") - public RestResp> listHomeFriendLinks(){ + public RestResp> listHomeFriendLinks() { return homeService.listHomeFriendLinks(); } diff --git a/src/main/java/io/github/xxyopen/novel/controller/front/NewsController.java b/src/main/java/io/github/xxyopen/novel/controller/front/NewsController.java index 891e519..daf5e94 100644 --- a/src/main/java/io/github/xxyopen/novel/controller/front/NewsController.java +++ b/src/main/java/io/github/xxyopen/novel/controller/front/NewsController.java @@ -6,6 +6,7 @@ import io.github.xxyopen.novel.dto.resp.NewsInfoRespDto; import io.github.xxyopen.novel.service.NewsService; import lombok.RequiredArgsConstructor; 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; @@ -26,9 +27,17 @@ public class NewsController { /** * 最新新闻列表查询接口 - * */ + */ @GetMapping("latestList") - public RestResp> listLatestNews(){ + public RestResp> listLatestNews() { return newsService.listLatestNews(); } + + /** + * 新闻信息查询接口 + */ + @GetMapping("{id}") + public RestResp getNews(@PathVariable Long id) { + return newsService.getNews(id); + } } diff --git a/src/main/java/io/github/xxyopen/novel/core/constant/DatabaseConsts.java b/src/main/java/io/github/xxyopen/novel/core/constant/DatabaseConsts.java index a3f7084..265573b 100644 --- a/src/main/java/io/github/xxyopen/novel/core/constant/DatabaseConsts.java +++ b/src/main/java/io/github/xxyopen/novel/core/constant/DatabaseConsts.java @@ -20,8 +20,7 @@ public class DatabaseConsts { CATEGORY_ID("category_id"), VISIT_COUNT("visit_count"), - LAST_CHAPTER_UPDATE_TIME("last_chapter_update_time") - ; + LAST_CHAPTER_UPDATE_TIME("last_chapter_update_time"); private String name; @@ -43,8 +42,7 @@ public class DatabaseConsts { BOOK_ID("book_id"), CHAPTER_NUM("chapter_num"), - LAST_CHAPTER_UPDATE_TIME("last_chapter_update_time") - ; + LAST_CHAPTER_UPDATE_TIME("last_chapter_update_time"); private String name; @@ -64,8 +62,27 @@ public class DatabaseConsts { @Getter public enum ColumnEnum { - CHAPTER_ID("chapter_id") - ; + CHAPTER_ID("chapter_id"); + + private String name; + + ColumnEnum(String name) { + this.name = name; + } + + } + + } + + /** + * 新闻内容表 + */ + public static class NewsContentTable { + + @Getter + public enum ColumnEnum { + + NEWS_ID("news_id"); private String name; @@ -79,9 +96,9 @@ public class DatabaseConsts { /** * 通用列枚举类 - * */ + */ @Getter - public enum CommonColumnEnum{ + public enum CommonColumnEnum { ID("id"), SORT("sort"), @@ -90,7 +107,7 @@ public class DatabaseConsts { private String name; - CommonColumnEnum(String name){ + CommonColumnEnum(String name) { this.name = name; } @@ -99,15 +116,14 @@ public class DatabaseConsts { /** * SQL语句枚举类 - * */ + */ @Getter public enum SqlEnum { LIMIT_1("limit 1"), LIMIT_2("limit 2"), LIMIT_30("limit 30"), - LIMIT_500("limit 500") - ; + LIMIT_500("limit 500"); private String sql; diff --git a/src/main/java/io/github/xxyopen/novel/dto/resp/NewsInfoRespDto.java b/src/main/java/io/github/xxyopen/novel/dto/resp/NewsInfoRespDto.java index 5c9d681..91d2e54 100644 --- a/src/main/java/io/github/xxyopen/novel/dto/resp/NewsInfoRespDto.java +++ b/src/main/java/io/github/xxyopen/novel/dto/resp/NewsInfoRespDto.java @@ -1,6 +1,7 @@ package io.github.xxyopen.novel.dto.resp; import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Builder; import lombok.Data; import java.time.LocalDateTime; @@ -12,6 +13,7 @@ import java.time.LocalDateTime; * @date 2022/5/14 */ @Data +@Builder public class NewsInfoRespDto { /** @@ -45,5 +47,10 @@ public class NewsInfoRespDto { @JsonFormat(pattern = "yyyy-MM-dd") private LocalDateTime updateTime; + /** + * 新闻内容 + * */ + private String content; + } diff --git a/src/main/java/io/github/xxyopen/novel/manager/NewsCacheManager.java b/src/main/java/io/github/xxyopen/novel/manager/NewsCacheManager.java index da7f2d4..b60f4ad 100644 --- a/src/main/java/io/github/xxyopen/novel/manager/NewsCacheManager.java +++ b/src/main/java/io/github/xxyopen/novel/manager/NewsCacheManager.java @@ -34,16 +34,14 @@ public class NewsCacheManager { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.orderByDesc(DatabaseConsts.CommonColumnEnum.CREATE_TIME.getName()) .last(DatabaseConsts.SqlEnum.LIMIT_2.getSql()); - return newsInfoMapper.selectList(queryWrapper).stream().map(v -> { - NewsInfoRespDto respDto = new NewsInfoRespDto(); - respDto.setId(v.getId()); - respDto.setCategoryId(v.getCategoryId()); - respDto.setCategoryName(v.getCategoryName()); - respDto.setTitle(v.getTitle()); - respDto.setSourceName(v.getSourceName()); - respDto.setUpdateTime(v.getUpdateTime()); - return respDto; - }).toList(); + return newsInfoMapper.selectList(queryWrapper).stream().map(v -> NewsInfoRespDto.builder() + .id(v.getId()) + .categoryId(v.getCategoryId()) + .categoryName(v.getCategoryName()) + .title(v.getTitle()) + .sourceName(v.getSourceName()) + .updateTime(v.getUpdateTime()) + .build()).toList(); } } diff --git a/src/main/java/io/github/xxyopen/novel/service/NewsService.java b/src/main/java/io/github/xxyopen/novel/service/NewsService.java index 4f4b5aa..d676f2b 100644 --- a/src/main/java/io/github/xxyopen/novel/service/NewsService.java +++ b/src/main/java/io/github/xxyopen/novel/service/NewsService.java @@ -18,4 +18,11 @@ public interface NewsService { * @return 新闻列表 * */ RestResp> listLatestNews(); + + /** + * 新闻信息查询 + * @param id 新闻ID + * @return 新闻信息 + * */ + RestResp getNews(Long id); } diff --git a/src/main/java/io/github/xxyopen/novel/service/impl/NewsServiceImpl.java b/src/main/java/io/github/xxyopen/novel/service/impl/NewsServiceImpl.java index 733c9c1..cf2819f 100644 --- a/src/main/java/io/github/xxyopen/novel/service/impl/NewsServiceImpl.java +++ b/src/main/java/io/github/xxyopen/novel/service/impl/NewsServiceImpl.java @@ -1,6 +1,12 @@ package io.github.xxyopen.novel.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.github.xxyopen.novel.core.common.resp.RestResp; +import io.github.xxyopen.novel.core.constant.DatabaseConsts; +import io.github.xxyopen.novel.dao.entity.NewsContent; +import io.github.xxyopen.novel.dao.entity.NewsInfo; +import io.github.xxyopen.novel.dao.mapper.NewsContentMapper; +import io.github.xxyopen.novel.dao.mapper.NewsInfoMapper; import io.github.xxyopen.novel.dto.resp.NewsInfoRespDto; import io.github.xxyopen.novel.manager.NewsCacheManager; import io.github.xxyopen.novel.service.NewsService; @@ -21,8 +27,27 @@ public class NewsServiceImpl implements NewsService { private final NewsCacheManager newsCacheManager; + private final NewsInfoMapper newsInfoMapper; + + private final NewsContentMapper newsContentMapper; + @Override public RestResp> listLatestNews() { return RestResp.ok(newsCacheManager.listLatestNews()); } + + @Override + public RestResp getNews(Long id) { + NewsInfo newsInfo = newsInfoMapper.selectById(id); + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq(DatabaseConsts.NewsContentTable.ColumnEnum.NEWS_ID.getName(), id) + .last(DatabaseConsts.SqlEnum.LIMIT_1.getSql()); + NewsContent newsContent = newsContentMapper.selectOne(queryWrapper); + return RestResp.ok(NewsInfoRespDto.builder() + .title(newsInfo.getTitle()) + .sourceName(newsInfo.getSourceName()) + .updateTime(newsInfo.getUpdateTime()) + .content(newsContent.getContent()) + .build()); + } }