Browse Source

修改获取阅读记录 bug

tianyunperfect 3 years ago
parent
commit
2ce474863e

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

@@ -187,11 +187,15 @@ public class CacheService {
     @Autowired
     private UserMapper userMapper;
 
-    @CacheFind(key = "user")
     public User getUserByIdCache(Long id) {
         return bookService.getUserById(id);
     }
 
+    @CacheFind(key = "freeCoin")
+    public Integer getFreeCoinCache(Long id) {
+        return bookService.getFreeCoin(id);
+    }
+
     @CacheFind(key = "user", delete = true)
     public void deleteUserByIdCache(Long id) {
     }

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

@@ -478,7 +478,7 @@ public class BookServiceImpl implements BookService {
         example.page(vo.getPage(), vo.getSize());
         List<UserRecentlyRead> userRecentlyReads = userRecentlyReadMapper.selectByExample(example);
 
-        if (userRecentlyReads == null) {
+        if (userRecentlyReads == null || userRecentlyReads.size() == 0) {
             return res;
         }
 
@@ -715,10 +715,9 @@ public class BookServiceImpl implements BookService {
 
     public User getUserById(Long id) {
         User user = userMapper.selectByPrimaryKey(id);
-        int freeCount = getFreeCountFromCharges(getFreeCharges(id));
+        int freeCount = cacheService.getFreeCoinCache(id);
         if (user.getFreeKandian() != freeCount) {
             user.setFreeKandian(freeCount);
-
             // 更新免费看点
             User user1 = new User();
             user1.setId(user.getId());
@@ -829,4 +828,7 @@ public class BookServiceImpl implements BookService {
         }
     }
 
+    public Integer getFreeCoin(Long id) {
+        return getFreeCountFromCharges(getFreeCharges(id));
+    }
 }