Kaynağa Gözat

1224 cloud alibaba

Qing 1 yıl önce
ebeveyn
işleme
c647fbe118

+ 6 - 0
novel-cloud-demo/novel-home/pom.xml

@@ -30,5 +30,11 @@
             <artifactId>novel-core</artifactId>
             <version>0.0.1-SNAPSHOT</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 </project>

+ 0 - 20
novel-cloud-demo/novel-home/src/main/java/com/sf/controller/HomeController.java

@@ -1,20 +0,0 @@
-package com.sf.controller;
-
-import com.sf.client.BookInfoClient;
-import com.sf.novel.core.resp.RestResp;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-@RestController
-public class HomeController {
-
-    @Autowired
-    private BookInfoClient bookInfoClient;
-
-    @GetMapping("/test")
-    public String test(){
-        return bookInfoClient.getBookInfo("111");
-    }
-
-}

+ 1 - 1
novel-cloud-demo/novel-home/src/main/java/com/sf/NovelHomeApplication.java → novel-cloud-demo/novel-home/src/main/java/com/sf/novel/home/NovelHomeApplication.java

@@ -1,4 +1,4 @@
-package com.sf;
+package com.sf.novel.home;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;

+ 1 - 2
novel-cloud-demo/novel-home/src/main/java/com/sf/client/BookInfoClient.java → novel-cloud-demo/novel-home/src/main/java/com/sf/novel/home/api/BookInfoClient.java

@@ -1,4 +1,4 @@
-package com.sf.client;
+package com.sf.novel.home.api;
 
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.stereotype.Component;
@@ -11,5 +11,4 @@ public interface BookInfoClient {
 
     @GetMapping("/api/bookInfo/{bookId}")
     String getBookInfo(@PathVariable String bookId);
-
 }

+ 15 - 0
novel-cloud-demo/novel-home/src/main/java/com/sf/novel/home/client/BookInfoClient.java

@@ -0,0 +1,15 @@
+package com.sf.novel.home.client;
+
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+
+@Component
+@FeignClient(value = "novel-book-demo")
+public interface BookInfoClient {
+
+    @GetMapping("/api/bookInfo/{bookId}")
+    String getBookInfo(@PathVariable String bookId);
+
+}

+ 48 - 0
novel-cloud-demo/novel-home/src/main/java/com/sf/novel/home/controller/HomeController.java

@@ -0,0 +1,48 @@
+package com.sf.novel.home.controller;
+
+import com.sf.novel.core.resp.RestResp;
+import com.sf.novel.home.api.BookInfoClient;
+import com.sf.novel.home.dto.resp.HomeBookRespDto;
+import com.sf.novel.home.dto.resp.HomeFriendLinkRespDto;
+import com.sf.novel.home.service.IHomeBookService;
+import io.swagger.v3.oas.annotations.Operation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+@RequestMapping("/api/front/home")
+@RestController
+public class HomeController {
+
+    @Autowired
+    private BookInfoClient bookInfoClient;
+    @Autowired
+    private IHomeBookService homeService;
+
+    @GetMapping("/test")
+    public String callBook(){
+        return bookInfoClient.getBookInfo("123");
+    }
+
+    /**
+     * 首页小说推荐查询接口
+     */
+    @Operation(summary = "首页小说推荐查询接口")
+    @GetMapping("books")
+    public RestResp<List<HomeBookRespDto>> listHomeBooks() {
+        return homeService.listHomeBooks();
+    }
+
+    /**
+     * 首页友情链接列表查询接口
+     */
+    @Operation(summary = "首页友情链接列表查询接口")
+    @GetMapping("friend_Link/list")
+    public RestResp<List<HomeFriendLinkRespDto>> listHomeFriendLinks() {
+        return homeService.listHomeFriendLinks();
+    }
+
+}

+ 51 - 0
novel-cloud-demo/novel-home/src/main/java/com/sf/novel/home/dto/resp/HomeBookRespDto.java

@@ -0,0 +1,51 @@
+package com.sf.novel.home.dto.resp;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+/**
+ * 首页小说推荐 响应DTO
+ *
+ * @author xiongxiaoyang
+ * @date 2022/5/13
+ */
+@Data
+public class HomeBookRespDto {
+
+    /**
+     * 类型;0-轮播图 1-顶部栏 2-本周强推 3-热门推荐 4-精品推荐
+     */
+    @Schema(description = "类型;0-轮播图 1-顶部栏 2-本周强推 3-热门推荐 4-精品推荐")
+    private Integer type;
+
+    /**
+     * 推荐小说ID
+     */
+    @Schema(description = "小说ID")
+    private Long bookId;
+
+    /**
+     * 小说封面地址
+     */
+    @Schema(description = "小说封面地址")
+    private String picUrl;
+
+    /**
+     * 小说名
+     */
+    @Schema(description = "小说名")
+    private String bookName;
+
+    /**
+     * 作家名
+     */
+    @Schema(description = "作家名")
+    private String authorName;
+
+    /**
+     * 书籍描述
+     */
+    @Schema(description = "书籍描述")
+    private String bookDesc;
+
+}

+ 32 - 0
novel-cloud-demo/novel-home/src/main/java/com/sf/novel/home/dto/resp/HomeFriendLinkRespDto.java

@@ -0,0 +1,32 @@
+package com.sf.novel.home.dto.resp;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+/**
+ * 首页友情链接 响应DTO
+ *
+ * @author xiongxiaoyang
+ * @date 2022/5/14
+ */
+@Data
+public class HomeFriendLinkRespDto implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 链接名
+     */
+    @Schema(description = "链接名")
+    private String linkName;
+
+    /**
+     * 链接url
+     */
+    @Schema(description = "链接url")
+    private String linkUrl;
+}

+ 9 - 0
novel-cloud-demo/novel-home/src/main/java/com/sf/novel/home/mapper/BookInfoMapper.java

@@ -0,0 +1,9 @@
+package com.sf.novel.home.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sf.novel.home.po.BookInfo;
+import org.apache.ibatis.annotations.Param;
+
+public interface BookInfoMapper extends BaseMapper<BookInfo> {
+    void addVisitCount(@Param("bookId") Long bookId);
+}

+ 16 - 0
novel-cloud-demo/novel-home/src/main/java/com/sf/novel/home/mapper/HomeBookMapper.java

@@ -0,0 +1,16 @@
+package com.sf.novel.home.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.sf.novel.home.po.HomeBook;
+
+/**
+ * <p>
+ * 小说推荐 Mapper 接口
+ * </p>
+ *
+ * @author Qing
+ * @since 2023-12-19
+ */
+public interface HomeBookMapper extends BaseMapper<HomeBook> {
+
+}

+ 250 - 0
novel-cloud-demo/novel-home/src/main/java/com/sf/novel/home/po/BookInfo.java

@@ -0,0 +1,250 @@
+package com.sf.novel.home.po;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+
+/**
+ * <p>
+ * 小说信息
+ * </p>
+ *
+ * @author Qing
+ * @since 2023-12-01
+ */
+@TableName("book_info")
+public class BookInfo implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    private Byte workDirection;
+
+    private Long categoryId;
+
+    private String categoryName;
+
+    private String picUrl;
+
+    private String bookName;
+
+    private Long authorId;
+
+    private String authorName;
+
+    private String bookDesc;
+
+    private Byte score;
+
+    private Byte bookStatus;
+
+    private Long visitCount;
+
+    private Integer wordCount;
+
+    private Integer commentCount;
+
+    private Long lastChapterId;
+
+    private String lastChapterName;
+
+    private LocalDateTime lastChapterUpdateTime;
+
+    private Byte isVip;
+
+    private LocalDateTime createTime;
+
+    private LocalDateTime updateTime;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Byte getWorkDirection() {
+        return workDirection;
+    }
+
+    public void setWorkDirection(Byte workDirection) {
+        this.workDirection = workDirection;
+    }
+
+    public Long getCategoryId() {
+        return categoryId;
+    }
+
+    public void setCategoryId(Long categoryId) {
+        this.categoryId = categoryId;
+    }
+
+    public String getCategoryName() {
+        return categoryName;
+    }
+
+    public void setCategoryName(String categoryName) {
+        this.categoryName = categoryName;
+    }
+
+    public String getPicUrl() {
+        return picUrl;
+    }
+
+    public void setPicUrl(String picUrl) {
+        this.picUrl = picUrl;
+    }
+
+    public String getBookName() {
+        return bookName;
+    }
+
+    public void setBookName(String bookName) {
+        this.bookName = bookName;
+    }
+
+    public Long getAuthorId() {
+        return authorId;
+    }
+
+    public void setAuthorId(Long authorId) {
+        this.authorId = authorId;
+    }
+
+    public String getAuthorName() {
+        return authorName;
+    }
+
+    public void setAuthorName(String authorName) {
+        this.authorName = authorName;
+    }
+
+    public String getBookDesc() {
+        return bookDesc;
+    }
+
+    public void setBookDesc(String bookDesc) {
+        this.bookDesc = bookDesc;
+    }
+
+    public Byte getScore() {
+        return score;
+    }
+
+    public void setScore(Byte score) {
+        this.score = score;
+    }
+
+    public Byte getBookStatus() {
+        return bookStatus;
+    }
+
+    public void setBookStatus(Byte bookStatus) {
+        this.bookStatus = bookStatus;
+    }
+
+    public Long getVisitCount() {
+        return visitCount;
+    }
+
+    public void setVisitCount(Long visitCount) {
+        this.visitCount = visitCount;
+    }
+
+    public Integer getWordCount() {
+        return wordCount;
+    }
+
+    public void setWordCount(Integer wordCount) {
+        this.wordCount = wordCount;
+    }
+
+    public Integer getCommentCount() {
+        return commentCount;
+    }
+
+    public void setCommentCount(Integer commentCount) {
+        this.commentCount = commentCount;
+    }
+
+    public Long getLastChapterId() {
+        return lastChapterId;
+    }
+
+    public void setLastChapterId(Long lastChapterId) {
+        this.lastChapterId = lastChapterId;
+    }
+
+    public String getLastChapterName() {
+        return lastChapterName;
+    }
+
+    public void setLastChapterName(String lastChapterName) {
+        this.lastChapterName = lastChapterName;
+    }
+
+    public LocalDateTime getLastChapterUpdateTime() {
+        return lastChapterUpdateTime;
+    }
+
+    public void setLastChapterUpdateTime(LocalDateTime lastChapterUpdateTime) {
+        this.lastChapterUpdateTime = lastChapterUpdateTime;
+    }
+
+    public Byte getIsVip() {
+        return isVip;
+    }
+
+    public void setIsVip(Byte isVip) {
+        this.isVip = isVip;
+    }
+
+    public LocalDateTime getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(LocalDateTime createTime) {
+        this.createTime = createTime;
+    }
+
+    public LocalDateTime getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(LocalDateTime updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    @Override
+    public String toString() {
+        return "BookInfo{" +
+            "id = " + id +
+            ", workDirection = " + workDirection +
+            ", categoryId = " + categoryId +
+            ", categoryName = " + categoryName +
+            ", picUrl = " + picUrl +
+            ", bookName = " + bookName +
+            ", authorId = " + authorId +
+            ", authorName = " + authorName +
+            ", bookDesc = " + bookDesc +
+            ", score = " + score +
+            ", bookStatus = " + bookStatus +
+            ", visitCount = " + visitCount +
+            ", wordCount = " + wordCount +
+            ", commentCount = " + commentCount +
+            ", lastChapterId = " + lastChapterId +
+            ", lastChapterName = " + lastChapterName +
+            ", lastChapterUpdateTime = " + lastChapterUpdateTime +
+            ", isVip = " + isVip +
+            ", createTime = " + createTime +
+            ", updateTime = " + updateTime +
+        "}";
+    }
+}

+ 95 - 0
novel-cloud-demo/novel-home/src/main/java/com/sf/novel/home/po/HomeBook.java

@@ -0,0 +1,95 @@
+package com.sf.novel.home.po;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+/**
+ * <p>
+ * 小说推荐
+ * </p>
+ *
+ * @author Qing
+ * @since 2023-12-19
+ */
+@TableName("home_book")
+public class HomeBook implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    private Byte type;
+
+    private Byte sort;
+
+    private Long bookId;
+
+    private LocalDateTime createTime;
+
+    private LocalDateTime updateTime;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Byte getType() {
+        return type;
+    }
+
+    public void setType(Byte type) {
+        this.type = type;
+    }
+
+    public Byte getSort() {
+        return sort;
+    }
+
+    public void setSort(Byte sort) {
+        this.sort = sort;
+    }
+
+    public Long getBookId() {
+        return bookId;
+    }
+
+    public void setBookId(Long bookId) {
+        this.bookId = bookId;
+    }
+
+    public LocalDateTime getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(LocalDateTime createTime) {
+        this.createTime = createTime;
+    }
+
+    public LocalDateTime getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(LocalDateTime updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    @Override
+    public String toString() {
+        return "HomeBook{" +
+            "id = " + id +
+            ", type = " + type +
+            ", sort = " + sort +
+            ", bookId = " + bookId +
+            ", createTime = " + createTime +
+            ", updateTime = " + updateTime +
+        "}";
+    }
+}

+ 34 - 0
novel-cloud-demo/novel-home/src/main/java/com/sf/novel/home/service/IHomeBookService.java

@@ -0,0 +1,34 @@
+package com.sf.novel.home.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.sf.novel.core.resp.RestResp;
+import com.sf.novel.home.dto.resp.HomeBookRespDto;
+import com.sf.novel.home.dto.resp.HomeFriendLinkRespDto;
+import com.sf.novel.home.po.HomeBook;
+
+import java.util.List;
+
+/**
+ * <p>
+ * 小说推荐 服务类
+ * </p>
+ *
+ * @author Qing
+ * @since 2023-12-19
+ */
+public interface IHomeBookService extends IService<HomeBook> {
+
+    /**
+     * 查询首页小说推荐列表
+     *
+     * @return 首页小说推荐列表的 rest 响应结果
+     */
+    RestResp<List<HomeBookRespDto>> listHomeBooks();
+
+    /**
+     * 首页友情链接列表查询
+     *
+     * @return 友情链接列表
+     */
+    RestResp<List<HomeFriendLinkRespDto>> listHomeFriendLinks();
+}

+ 93 - 0
novel-cloud-demo/novel-home/src/main/java/com/sf/novel/home/service/impl/HomeBookServiceImpl.java

@@ -0,0 +1,93 @@
+package com.sf.novel.home.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.sf.novel.core.constant.DatabaseConsts;
+import com.sf.novel.core.resp.RestResp;
+import com.sf.novel.home.dto.resp.HomeBookRespDto;
+import com.sf.novel.home.dto.resp.HomeFriendLinkRespDto;
+import com.sf.novel.home.mapper.BookInfoMapper;
+import com.sf.novel.home.mapper.HomeBookMapper;
+import com.sf.novel.home.po.BookInfo;
+import com.sf.novel.home.po.HomeBook;
+import com.sf.novel.home.service.IHomeBookService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * <p>
+ * 小说推荐 服务实现类
+ * </p>
+ *
+ * @author Qing
+ * @since 2023-12-19
+ */
+@Service
+@RequiredArgsConstructor
+public class HomeBookServiceImpl extends ServiceImpl<HomeBookMapper, HomeBook> implements IHomeBookService {
+
+    private final HomeBookMapper homeBookMapper;
+
+    private final BookInfoMapper bookInfoMapper;
+
+    @Override
+    public RestResp<List<HomeBookRespDto>> listHomeBooks() {
+        // 从首页小说推荐表中查询出需要推荐的小说
+        QueryWrapper<HomeBook> queryWrapper = new QueryWrapper<>();
+        queryWrapper.orderByAsc(DatabaseConsts.CommonColumnEnum.SORT.getName());
+        List<HomeBook> homeBooks = homeBookMapper.selectList(queryWrapper);
+
+        // 获取推荐小说ID列表
+        if (!CollectionUtils.isEmpty(homeBooks)) {
+            List<Long> bookIds = homeBooks.stream()
+                    .map(HomeBook::getBookId)
+                    .toList();
+
+            // 根据小说ID列表查询相关的小说信息列表
+            QueryWrapper<BookInfo> bookInfoQueryWrapper = new QueryWrapper<>();
+            bookInfoQueryWrapper.in(DatabaseConsts.CommonColumnEnum.ID.getName(), bookIds);
+            List<BookInfo> bookInfos = bookInfoMapper.selectList(bookInfoQueryWrapper);
+
+            // 组装 HomeBookRespDto 列表数据并返回
+            if (!CollectionUtils.isEmpty(bookInfos)) {
+                Map<Long, BookInfo> bookInfoMap = bookInfos.stream()
+                        .collect(Collectors.toMap(BookInfo::getId, Function.identity()));
+                List<HomeBookRespDto> homeBookRespDtoList = homeBooks.stream().map(v -> {
+                    BookInfo bookInfo = bookInfoMap.get(v.getBookId());
+                    HomeBookRespDto bookRespDto = new HomeBookRespDto();
+                    bookRespDto.setType(v.getType().intValue());
+                    bookRespDto.setBookId(v.getBookId());
+                    bookRespDto.setBookName(bookInfo.getBookName());
+                    bookRespDto.setPicUrl(bookInfo.getPicUrl());
+                    bookRespDto.setAuthorName(bookInfo.getAuthorName());
+                    bookRespDto.setBookDesc(bookInfo.getBookDesc());
+                    return bookRespDto;
+                }).toList();
+                return RestResp.ok(homeBookRespDtoList);
+            }
+
+        }
+        return RestResp.ok(Collections.emptyList());
+    }
+
+    @Override
+    public RestResp<List<HomeFriendLinkRespDto>> listHomeFriendLinks() {
+        // 从友情链接表中查询出友情链接列表
+//        QueryWrapper<HomeFriendLink> queryWrapper = new QueryWrapper<>();
+//        queryWrapper.orderByAsc(DatabaseConsts.CommonColumnEnum.SORT.getName());
+//        List<HomeFriendLinkRespDto> friendLinkRespDtos =  friendLinkMapper.selectList(queryWrapper).stream().map(v -> {
+//            HomeFriendLinkRespDto respDto = new HomeFriendLinkRespDto();
+//            respDto.setLinkName(v.getLinkName());
+//            respDto.setLinkUrl(v.getLinkUrl());
+//            return respDto;
+//        }).toList();
+        return RestResp.ok(Collections.emptyList());
+    }
+}