tianyunperfect пре 3 година
родитељ
комит
c79f59b10c

+ 0 - 1
book-dao/pom.xml

@@ -10,7 +10,6 @@
     <modelVersion>4.0.0</modelVersion>
 
     <artifactId>book-dao</artifactId>
-    <packaging>jar</packaging>
     <properties>
         <maven.compiler.source>8</maven.compiler.source>
         <maven.compiler.target>8</maven.compiler.target>

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

@@ -95,11 +95,11 @@ public class BookController extends BaseController {
      *
      * @return
      */
-    @GetMapping("/resetBlockCache")
-    @CacheEvict(value = "block", allEntries = true)
-    public Result resetBlockCache() {
-        return Result.byObject("OK");
-    }
+    //@GetMapping("/resetBlockCache")
+    //@CacheEvict(value = "block", allEntries = true)
+    //public Result resetBlockCache() {
+    //    return Result.byObject("OK");
+    //}
 
 
     /**

+ 26 - 17
book-server/src/main/java/com/book/server/service/CacheService.java

@@ -1,11 +1,13 @@
 package com.book.server.service;
 
 import com.book.dao.VO.*;
+import com.book.dao.cps.entity.UploadBook;
 import com.book.dao.cps.mapper.*;
 import com.book.dao.cps.pojo.*;
 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.server.annotation.CacheFind;
 import com.book.server.service.BookService;
 import com.book.server.service.impl.BookServiceImpl;
@@ -106,9 +108,30 @@ public class CacheService {
         return list;
     }
 
+    @Autowired
+    private UploadBookMapper uploadBookMapper;
+
     @CacheFind(key = "chapters")
     public List<Chapter> setChaptersByBookIdCache(Long bookId) {
         List<Chapter> list = new ArrayList<>();
+        //如果是本地书籍
+        if (isUploadBook(bookId)) {
+            List<UploadBook> uploadBooks = uploadBookMapper.selectByExample(
+                    UploadBookExample.newAndCreateCriteria()
+                            .andBookIdEqualTo(bookId)
+                            .example()
+            );
+            uploadBooks.forEach(x->{
+                Chapter chapter = new Chapter();
+                chapter.setBookId(x.getBookId().toString());
+                chapter.setContentId(x.getChapterId().toString());
+                chapter.setName(x.getChapterName());
+                chapter.setReadAble(x.getReadAble().toString());
+                chapter.setWords(x.getWords().toString());
+                list.add(chapter);
+            });
+            return list;
+        }
 
         final String chaptersUrl = "http://new.emeixs.com/index.php/Home/Interface/chapters/bid/" + bookId;
         String result = HttpTool.sendGet(chaptersUrl, "");
@@ -146,23 +169,8 @@ public class CacheService {
         return list;
     }
 
-    @CacheFind(key = "bookContent")
-    public BookContent setBookContentCache(Long bookId, long contendId, String contentName) {
-
-        BookContent bookContent;
-        // 修改过的章节
-        String content = bookService.getEditBookContentById(bookId, contendId);
-        if (content != null) {
-            return bookService.getBookContentFromVO(bookId, contendId, contentName, content);
-        }
-
-        if (bookId > 110_0000 && bookId < 110_9999) {
-            // 自定义的书籍
-            bookContent = bookService.getBookContentFromDB(bookId, contendId, contentName);
-        } else {
-            bookContent = bookService.getBookContentFromRemote(bookId, contendId);
-        }
-        return bookContent;
+    public Boolean isUploadBook(Long bookId) {
+        return bookId > 110_0000 && bookId < 110_9999;
     }
 
     @CacheFind(key = "defaultFreeChapterNum")
@@ -205,4 +213,5 @@ public class CacheService {
         List<BookRes> bookRes = bookMapper2.topRecommend(queryVO, 0, 20);
         return bookRes;
     }
+
 }

+ 37 - 38
book-server/src/main/java/com/book/server/service/impl/BookServiceImpl.java

@@ -236,14 +236,7 @@ public class BookServiceImpl implements BookService {
 
     @Override
     public List<BookRes> smartRecommand(QueryVO queryVO) {
-        String key = getKey("smartRecommand", queryVO.getSex());
-        Object o = redisUtil.get(key);
-        if (o == null) {
-            List<BookRes> bookRes = cacheService.setSmartRecommandCache(queryVO.getSex());
-            return bookRes;
-        } else {
-            return (List<BookRes>) o;
-        }
+        return cacheService.setSmartRecommandCache(queryVO.getSex());
     }
 
 
@@ -373,7 +366,27 @@ public class BookServiceImpl implements BookService {
     }
 
     private BookContent getBookContent(BookContentVO bookContentVO) {
-        return cacheService.setBookContentCache(bookContentVO.getBookId(), bookContentVO.getContentId(), bookContentVO.getContentName());
+        String key = getKey("edit_book", bookContentVO.getBookId(), bookContentVO.getContentId());
+        Object o = redisUtil.get(key);
+        if (o != null) {
+            return JsonUtils.getObject(o.toString(), BookContent.class);
+        } else {
+            BookContent bookContent;
+            // 修改过的章节
+            String content = getEditBookContentById(bookContentVO.getBookId(), bookContentVO.getContentId());
+
+            if (content != null) {
+                return getBookContentFromVO(bookContentVO.getBookId(), bookContentVO.getContentId(), bookContentVO.getContentName(), content);
+            }
+
+            if (cacheService.isUploadBook(bookContentVO.getBookId())) {
+                // 自定义的书籍
+                bookContent = getBookContentFromDB(bookContentVO.getBookId(), bookContentVO.getContentId(), bookContentVO.getContentName());
+            } else {
+                bookContent = getBookContentFromRemote(bookContentVO.getBookId(), bookContentVO.getContentId());
+            }
+            return bookContent;
+        }
     }
 
 
@@ -427,27 +440,6 @@ public class BookServiceImpl implements BookService {
         checkUpdate(i);
     }
 
-    /**
-     * 减去多少充值看点
-     *
-     * @param reduceNum 消费多少看点
-     * @param recharge
-     */
-    @Transactional
-    void subtractRecharge(int reduceNum, Recharge recharge) {
-        rechargeMapper.updateByExampleSelective(
-                Recharge.builder().remainFreeKandian(recharge.getRemainFreeKandian() - reduceNum).build(),
-                RechargeExample.newAndCreateCriteria()
-                        .andIdEqualTo(recharge.getId())
-                        .andRemainFreeKandianEqualTo(recharge.getRemainFreeKandian()).example(),
-                Recharge.Column.remainFreeKandian
-        );
-    }
-
-    public Book getBookById(Long id) {
-        return cacheService.getBookById(id);
-    }
-
     /**
      * 获取版权方章节内容
      *
@@ -651,8 +643,8 @@ public class BookServiceImpl implements BookService {
                         .example()
                 , EditBook.Column.content, EditBook.Column.updateTime
         );
-        if (i < 0) {
-            int insert = editBookMapper.insert(EditBook.builder()
+        if (i <= 0) {
+            i = editBookMapper.insert(EditBook.builder()
                     .bookId(bookContentVO.getBookId())
                     .chapterId(bookContentVO.getContentId())
                     .chapterName(bookContentVO.getContentName())
@@ -660,10 +652,11 @@ public class BookServiceImpl implements BookService {
                     .createTime(DateUtils.getNow())
                     .updateTime(DateUtils.getNow())
                     .build());
-            return insert > 0;
         }
-        updateEditBookById(bookContentVO.getBookId(), bookContentVO.getContentId());
-        return true;
+        if (i > 0) {
+            updateEditBookByIdCache(bookContentVO.getBookId(), bookContentVO.getContentId());
+        }
+        return i > 0;
     }
 
     public BookContent getBookContentFromDB(Long bookId, Long contentId, String contentName) {
@@ -726,7 +719,7 @@ public class BookServiceImpl implements BookService {
         return sb.toString();
     }
 
-    public synchronized void updateEditBookById(Long bookId, Long chapterId) {
+    public void updateEditBookByIdCache(Long bookId, Long chapterId) {
         String key = getKey("edit_book", bookId, chapterId);
         EditBook obj = editBookMapper.selectOneByExampleSelective(
                 EditBookExample.newAndCreateCriteria()
@@ -735,7 +728,7 @@ public class BookServiceImpl implements BookService {
                         .example(),
                 EditBook.Column.content
         );
-        redisUtil.set(key, obj);
+        redisUtil.set(key, JsonUtils.toJsonStr(obj));
     }
 
     @PostConstruct
@@ -744,7 +737,7 @@ public class BookServiceImpl implements BookService {
                 EditBook.Column.bookId, EditBook.Column.chapterId, EditBook.Column.content);
         editBooks.forEach(x -> {
             String key = getKey("edit_book", x.getBookId(), x.getChapterId());
-            redisUtil.set(key, x.getContent());
+            redisUtil.set(key, JsonUtils.toJsonStr(x));
         });
     }
 
@@ -756,5 +749,11 @@ public class BookServiceImpl implements BookService {
         return bookRes.subList(0, 4);
     }
 
+    public int insertFreeKandian(Long userId, int freeKandian) {
+        // 签到看点
+
+        // 更新到用户信息
+        return 1;
+    }
 
 }