瀏覽代碼

- 阅读记录添加书籍名称和图片

tianyunperfect 3 年之前
父節點
當前提交
d95d778201

+ 10 - 0
book-dao/src/main/java/com/book/dao/VO/UserRecentlyReadRes.java

@@ -0,0 +1,10 @@
+package com.book.dao.VO;
+
+import com.book.dao.cpsshard.entity.UserRecentlyRead;
+import lombok.Data;
+
+@Data
+public class UserRecentlyReadRes extends UserRecentlyRead {
+    private String bookName;
+    private String image;
+}

+ 17 - 0
book-dao/src/main/java/com/book/dao/cpsshard/mapper/UserRecentlyRead2Mapper.java

@@ -0,0 +1,17 @@
+package com.book.dao.cpsshard.mapper;
+
+import com.book.dao.VO.UserRecentlyReadRes;
+import com.book.dao.cpsshard.entity.UserRecentlyRead;
+import com.book.dao.cpsshard.pojo.example.UserRecentlyReadExample;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Mapper
+@Repository
+public interface UserRecentlyRead2Mapper {
+
+    List<UserRecentlyReadRes> getRecentReadByUserId(Long userId, int page, int size);
+}

+ 27 - 0
book-dao/src/main/resources/mapper/cpsshard/UserRecentlyRead2Mapper.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.book.dao.cpsshard.mapper.UserRecentlyRead2Mapper">
+  <resultMap id="BaseResultMap" type="com.book.dao.VO.UserRecentlyReadRes">
+    <!--
+      WARNING - @mbg.generated
+      This element is automatically generated by MyBatis Generator, do not modify.
+      This element was generated on Sun Aug 22 13:51:10 CST 2021.
+    -->
+    <id column="id" jdbcType="INTEGER" property="id" />
+    <result column="user_id" jdbcType="BIGINT" property="userId" />
+    <result column="book_id" jdbcType="BIGINT" property="bookId" />
+    <result column="chapter_id" jdbcType="BIGINT" property="chapterId" />
+    <result column="chapter_name" jdbcType="VARCHAR" property="chapterName" />
+    <result column="flag" jdbcType="TINYINT" property="flag" />
+    <result column="createtime" jdbcType="INTEGER" property="createtime" />
+    <result column="updatetime" jdbcType="INTEGER" property="updatetime" />
+    <result column="book_shelf_add" jdbcType="TINYINT" property="bookShelfAdd" />
+    <result column="book_shelf_flag" jdbcType="TINYINT" property="bookShelfFlag" />
+    <result column="bookName" jdbcType="TINYINT" property="bookName" />
+    <result column="cover" jdbcType="TINYINT" property="cover" />
+  </resultMap>
+  <select id="getRecentReadByUserId" resultMap="BaseResultMap">
+
+  </select>
+
+</mapper>

+ 1 - 1
book-server/src/main/java/com/book/server/controller/BookController.java

@@ -175,7 +175,7 @@ public class BookController extends BaseController {
      * @return
      */
     @PostMapping("/getRecentReadByUserId")
-    public Result<List<UserRecentlyRead>> getRecentReadByUserId(@RequestBody UserRecentReadVO userRecentlyRead) {
+    public Result<List<UserRecentlyReadRes>> getRecentReadByUserId(@RequestBody UserRecentReadVO userRecentlyRead) {
         return Result.success(bookService.getRecentReadByUserId(userRecentlyRead));
     }
 

+ 1 - 1
book-server/src/main/java/com/book/server/service/BookService.java

@@ -30,7 +30,7 @@ public interface BookService {
 
     UserRecentlyRead getRecentReadByUserIdAndBookId(UserRecentlyRead userRecentlyRead);
 
-    List<UserRecentlyRead> getRecentReadByUserId(UserRecentReadVO userRecentlyRead);
+    List<UserRecentlyReadRes> getRecentReadByUserId(UserRecentReadVO userRecentlyRead);
 
     List<Long> getUserConsumerChapter(BookContentVO bookContentVO);
 

+ 3 - 0
book-server/src/main/java/com/book/server/service/CacheService.java

@@ -8,6 +8,7 @@ import com.book.dao.cps.pojo.example.BookCategoryExample;
 import com.book.dao.cps.pojo.example.ManageBlockExample;
 import com.book.dao.cps.pojo.example.SearchKeywordExample;
 import com.book.dao.cps.pojo.example.UploadBookExample;
+import com.book.dao.cpsshard.entity.UserRecentlyRead;
 import com.book.server.annotation.CacheFind;
 import com.book.server.service.BookService;
 import com.book.server.service.impl.BookServiceImpl;
@@ -222,4 +223,6 @@ public class CacheService {
         return bookRes;
     }
 
+
+
 }

+ 30 - 5
book-server/src/main/java/com/book/server/service/impl/BookServiceImpl.java

@@ -10,6 +10,7 @@ import com.book.dao.cpsshard.entity.Recharge;
 import com.book.dao.cpsshard.entity.UserRecentlyRead;
 import com.book.dao.cpsshard.mapper.ConsumeMapper;
 import com.book.dao.cpsshard.mapper.RechargeMapper;
+import com.book.dao.cpsshard.mapper.UserRecentlyRead2Mapper;
 import com.book.dao.cpsshard.mapper.UserRecentlyReadMapper;
 import com.book.dao.cpsshard.pojo.example.ConsumeExample;
 import com.book.dao.cpsshard.pojo.example.RechargeExample;
@@ -475,17 +476,41 @@ public class BookServiceImpl implements BookService {
     }
 
     @Override
-    public List<UserRecentlyRead> getRecentReadByUserId(UserRecentReadVO userRecentlyRead) {
+    public List<UserRecentlyReadRes> getRecentReadByUserId(UserRecentReadVO vo) {
+        ArrayList<UserRecentlyReadRes> res = new ArrayList<>();
         UserRecentlyReadExample example = UserRecentlyReadExample.newAndCreateCriteria()
-                .andUserIdEqualTo(userRecentlyRead.getUserId())
+                .andUserIdEqualTo(vo.getUserId())
                 .example();
         example.orderBy(UserRecentlyRead.Column.updatetime.desc());
-        example.page(userRecentlyRead.getPage(), userRecentlyRead.getSize());
+        example.page(vo.getPage(), vo.getSize());
         List<UserRecentlyRead> userRecentlyReads = userRecentlyReadMapper.selectByExample(example);
+
         if (userRecentlyReads == null) {
-            userRecentlyReads = new ArrayList<>();
+            return res;
+        }
+
+        //获取 bookId 和 cover
+        List<Long> bookIds = userRecentlyReads.stream().map(x -> x.getBookId()).collect(Collectors.toList());
+        List<Book> books = bookMapper.selectByExampleSelective(
+                BookExample.newAndCreateCriteria()
+                        .andIdIn(bookIds).example()
+                , Book.Column.id, Book.Column.name, Book.Column.image
+        );
+        HashMap<Long, Book> map = new HashMap<>();
+        for (Book book : books) {
+            map.put(book.getId(), book);
+        }
+
+        // 填充 res
+        for (UserRecentlyRead userRecentlyRead : userRecentlyReads) {
+            UserRecentlyReadRes recentlyReadRes = new UserRecentlyReadRes();
+            BeanUtils.copyProperties(userRecentlyRead, recentlyReadRes);
+            recentlyReadRes.setBookName(map.get(userRecentlyRead.getBookId()).getName());
+            recentlyReadRes.setImage(map.get(userRecentlyRead.getBookId()).getImage());
+            res.add(recentlyReadRes);
         }
-        return userRecentlyReads;
+
+        return res;
     }
 
     @Override