Sfoglia il codice sorgente

新增阅读记录两个接口

tianyun 3 anni fa
parent
commit
4a1021fc04

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

@@ -1,6 +1,7 @@
 package com.book.server.controller;
 
 import com.book.dao.cps.pojo.SearchKeyword;
+import com.book.dao.cpsshard.entity.UserRecentlyRead;
 import com.book.server.common.entity.Result;
 import com.book.server.common.entity.ResultCode;
 import com.book.dao.VO.*;
@@ -158,4 +159,22 @@ public class BookController extends BaseController {
         return Result.byObject(bookService.getSearchKeywordBySex(sex));
     }
 
+    /**
+     * 获取指定书籍的阅读记录
+     * @param userRecentlyRead
+     * @return
+     */
+    @PostMapping("/getRecentReadByUserIdAndBookId")
+    public Result<UserRecentlyRead> getRecentReadByUserIdAndBookId(@RequestBody UserRecentlyRead userRecentlyRead) {
+        return Result.byObject(bookService.getRecentReadByUserIdAndBookId(userRecentlyRead));
+    }
+    /**
+     * 获取指定用户的阅读记录
+     * @param userRecentlyRead
+     * @return
+     */
+    @PostMapping("/getRecentReadByUserId")
+    public Result<List<UserRecentlyRead>> getRecentReadByUserId(@RequestBody UserRecentlyRead userRecentlyRead) {
+        return Result.byObject(bookService.getRecentReadByUserId(userRecentlyRead));
+    }
 }

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

@@ -2,6 +2,7 @@ package com.book.server.service;
 
 import com.book.dao.VO.*;
 import com.book.dao.cps.pojo.SearchKeyword;
+import com.book.dao.cpsshard.entity.UserRecentlyRead;
 
 import java.util.List;
 
@@ -22,4 +23,8 @@ public interface BookService {
     List<BookRes> smartRecommand(QueryVO queryVO);
 
     BookContent getContentByContentId(String bookId,String contentId);
+
+    UserRecentlyRead getRecentReadByUserIdAndBookId(UserRecentlyRead userRecentlyRead);
+
+    List<UserRecentlyRead> getRecentReadByUserId(UserRecentlyRead userRecentlyRead);
 }

+ 60 - 34
book-server/src/main/java/com/book/server/service/impl/BookServiceImpl.java

@@ -6,6 +6,9 @@ import com.book.dao.cps.pojo.Book;
 import com.book.dao.cps.pojo.BookCategory;
 import com.book.dao.cps.pojo.ManageBlock;
 import com.book.dao.cps.pojo.SearchKeyword;
+import com.book.dao.cpsshard.entity.UserRecentlyRead;
+import com.book.dao.cpsshard.mapper.UserRecentlyReadMapper;
+import com.book.dao.cpsshard.pojo.example.UserRecentlyReadExample;
 import com.book.server.common.util.JsonUtils;
 import com.book.dao.cps.pojo.example.*;
 import com.book.dao.VO.*;
@@ -212,42 +215,42 @@ public class BookServiceImpl implements BookService {
     public List<Chapter> getChaptersByBookId(String bookId) {
         List<Chapter> list = new ArrayList<>();
 
-            if (StringUtils.isEmpty(bookId)) {
-                throw new IllegalArgumentException("bookId cannot be null or empty");
-            }
-            final String chaptersUrl = "http://new.emeixs.com/index.php/Home/Interface/chapters/bid/" + bookId;
-            String result = HttpTool.sendGet(chaptersUrl, "");
-            if (StringUtils.isEmpty(result)) {
-                return list;
-            }
-            JsonParser parser = new JsonParser();
-            JsonArray jsonArray = parser.parse(result).getAsJsonArray();
-            Book book = bookMapper.selectByPrimaryKey(Long.parseLong(bookId));
-            if (book == null) {
-                return list;
-            }
-            Integer freeChapterNum = book.getFreeChapterNum();
+        if (StringUtils.isEmpty(bookId)) {
+            throw new IllegalArgumentException("bookId cannot be null or empty");
+        }
+        final String chaptersUrl = "http://new.emeixs.com/index.php/Home/Interface/chapters/bid/" + bookId;
+        String result = HttpTool.sendGet(chaptersUrl, "");
+        if (StringUtils.isEmpty(result)) {
+            return list;
+        }
+        JsonParser parser = new JsonParser();
+        JsonArray jsonArray = parser.parse(result).getAsJsonArray();
+        Book book = bookMapper.selectByPrimaryKey(Long.parseLong(bookId));
+        if (book == null) {
+            return list;
+        }
+        Integer freeChapterNum = book.getFreeChapterNum();
 
-            if (freeChapterNum==null){
-                freeChapterNum = 20;
-            }
-            for (int i = 0; i < jsonArray.size(); i++) {
-                JsonObject jsonObject = jsonArray.get(i).getAsJsonObject();
-                Chapter chapter = new Chapter();
-                chapter.setReadAble("1");
-                chapter.setBookId(jsonObject.get("book_id").getAsString());
-                chapter.setContentId(jsonObject.get("content_id").getAsString());
-                chapter.setIsPay(jsonObject.get("ispay").getAsString());
-                chapter.setName(jsonObject.get("name").getAsString());
-                chapter.setNum(jsonObject.get("num").getAsString());
-                chapter.setType(jsonObject.get("type").getAsString());
-                chapter.setVolumeId(jsonObject.get("volume_id").getAsString());
-                chapter.setWords(jsonObject.get("words").getAsString());
-                if (i + 1 == freeChapterNum) {
-                    chapter.setReadAble("0");
-                }
-                list.add(chapter);
+        if (freeChapterNum == null) {
+            freeChapterNum = 20;
+        }
+        for (int i = 0; i < jsonArray.size(); i++) {
+            JsonObject jsonObject = jsonArray.get(i).getAsJsonObject();
+            Chapter chapter = new Chapter();
+            chapter.setReadAble("1");
+            chapter.setBookId(jsonObject.get("book_id").getAsString());
+            chapter.setContentId(jsonObject.get("content_id").getAsString());
+            chapter.setIsPay(jsonObject.get("ispay").getAsString());
+            chapter.setName(jsonObject.get("name").getAsString());
+            chapter.setNum(jsonObject.get("num").getAsString());
+            chapter.setType(jsonObject.get("type").getAsString());
+            chapter.setVolumeId(jsonObject.get("volume_id").getAsString());
+            chapter.setWords(jsonObject.get("words").getAsString());
+            if (i + 1 == freeChapterNum) {
+                chapter.setReadAble("0");
             }
+            list.add(chapter);
+        }
 
         return list;
     }
@@ -301,6 +304,29 @@ public class BookServiceImpl implements BookService {
         return content;
     }
 
+    @Autowired
+    private UserRecentlyReadMapper userRecentlyReadMapper;
+
+    @Override
+    public UserRecentlyRead getRecentReadByUserIdAndBookId(UserRecentlyRead userRecentlyRead) {
+        UserRecentlyReadExample example = UserRecentlyReadExample.newAndCreateCriteria()
+                .andUserIdEqualTo(userRecentlyRead.getUserId())
+                .andBookIdEqualTo(userRecentlyRead.getBookId())
+                .example();
+        return userRecentlyReadMapper.selectOneByExample(example);
+    }
+
+    @Override
+    public List<UserRecentlyRead> getRecentReadByUserId(UserRecentlyRead userRecentlyRead) {
+        UserRecentlyReadExample example = UserRecentlyReadExample.newAndCreateCriteria()
+                .andUserIdEqualTo(userRecentlyRead.getUserId())
+                .example();
+        example.orderBy(UserRecentlyRead.Column.updatetime.desc());
+        //暂定为获取30条
+        example.page(0, 30);
+        return userRecentlyReadMapper.selectByExample(example);
+    }
+
     private List<BookRes> getRandom(List<BookRes> bookRes) {
         if (bookRes.size() <= 4) {
             return bookRes;