Forráskód Böngészése

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	book-server/src/main/java/com/book/server/config/Const.java
lijilei 3 éve
szülő
commit
311ca4e035

+ 2 - 0
book-server/src/main/java/com/book/server/config/Const.java

@@ -4,4 +4,6 @@ public class Const {
     public static final String CacheSplit = "_";
     public static final String EDIT_BOOK_PRE = "edit_book";
     public static  final  String URL_PAY_CENTER = "http://{appid}.{host}/home.html#/{page}?userId={userId}&payOpenid={openid}";
+    public static final Long bookIdMin = 110_0001L;
+    public static final Long bookInMax = 110_9999L;
 }

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

@@ -6,6 +6,7 @@ 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.*;
+import com.book.server.service.BlockCacheGuava;
 import com.book.server.service.BookService;
 import com.book.server.service.CacheService;
 import lombok.extern.slf4j.Slf4j;
@@ -91,17 +92,6 @@ public class BookController extends BaseController {
         return Result.byObject(list);
     }
 
-    /**
-     * 更新block缓存
-     *
-     * @return
-     */
-    //@GetMapping("/resetBlockCache")
-    //@CacheEvict(value = "block", allEntries = true)
-    //public Result resetBlockCache() {
-    //    return Result.byObject("OK");
-    //}
-
 
     /**
      * 导入书库
@@ -193,6 +183,7 @@ public class BookController extends BaseController {
 
     @Autowired
     private CacheService cacheService;
+
     /**
      * 自定义书籍上传
      *
@@ -201,7 +192,7 @@ public class BookController extends BaseController {
      * @return
      * @throws IOException
      */
-    @PostMapping("/upload")
+    @PostMapping("/upload-8F80F0A4-E084-44C6-8659-61612C9D9D44")
     public Result uploadFile(@RequestParam("file") MultipartFile file, Long bookId) throws IOException {
         if (file.isEmpty() || bookId == null || bookId < 100_0000) {
             return Result.failure(ResultCode.PARAMERROR);
@@ -215,6 +206,16 @@ public class BookController extends BaseController {
         return Result.success("添加成功");
     }
 
+    /**
+     * 后台-删除上传的书籍
+     * @param id
+     * @return
+     */
+    @GetMapping("deleteUpload-8F80F0A4-E084-44C6-8659-61612C9D9D44")
+    public Result deleteUploadFile(Long id) {
+        return Result.success(bookService.deleteUploadFile(id));
+    }
+
     /**
      * 后台-获取章节书籍内容
      *
@@ -236,4 +237,28 @@ public class BookController extends BaseController {
     public Result updateBookContent(@RequestBody BookContentVO bookContentVO) {
         return Result.byObject(bookService.updateBookContent(bookContentVO));
     }
+
+    /**
+     * 后台-获取建议的 ID
+     *
+     * @return
+     */
+    @GetMapping("/getRecommendId-584CBBC1-DBD9-47A9-AAF1-EBC684B82B55")
+    public Result getRecommendId() {
+        return Result.byObject(bookService.getRecommendId());
+    }
+
+    @Autowired
+    private BlockCacheGuava blockCacheGuava;
+
+    /**
+     * 更新 block 缓存
+     *
+     * @return
+     */
+    @GetMapping("/updateBlockCache-8AA34230-157C-4EF6-98CE-0D928B3DE9EF")
+    public Result updateBlockCache() {
+        blockCacheGuava.clearCache();
+        return Result.success();
+    }
 }

+ 6 - 2
book-server/src/main/java/com/book/server/service/BlockCacheGuava.java

@@ -1,7 +1,6 @@
 package com.book.server.service;
 
 import com.book.dao.VO.BlockRes;
-import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
@@ -28,7 +27,7 @@ public class BlockCacheGuava {
                 .build(new CacheLoader<Integer, List<BlockRes>>() {
                     @Override
                     public List<BlockRes> load(Integer key) throws Exception {
-                        return cacheService.getBlockByPageIdCache(key);
+                        return cacheService.getBlockByPageId(key);
                     }
                 });
     }
@@ -36,4 +35,9 @@ public class BlockCacheGuava {
     public List<BlockRes> getBlockRes(Integer key) throws ExecutionException {
         return blockResCache.get(key);
     }
+
+    public void clearCache() {
+        blockResCache.refresh(1);
+        blockResCache.refresh(2);
+    }
 }

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

@@ -41,4 +41,8 @@ public interface BookService {
 
     Boolean updateBookContent(BookContentVO bookContentVO);
     int insertKandian(Long userId, String type, int kandian, int freeKandian);
+
+    Long getRecommendId();
+
+    int deleteUploadFile(Long id);
 }

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

@@ -11,6 +11,7 @@ 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.config.Const;
 import com.book.server.service.impl.BookServiceImpl;
 import com.book.server.utils.HttpTool;
 import com.google.gson.JsonArray;
@@ -76,7 +77,7 @@ public class CacheService {
                 queryVO.getPage() * queryVO.getSize(), queryVO.getSize());
     }
 
-    public ArrayList<BlockRes> getBlockByPageIdCache(Integer pageId) {
+    public ArrayList<BlockRes> getBlockByPageId(Integer pageId) {
         //没有缓存
         ArrayList<BlockRes> list = new ArrayList<>();
         // 获取板块
@@ -170,7 +171,7 @@ public class CacheService {
     }
 
     public Boolean isUploadBook(Long bookId) {
-        return bookId > 110_0000 && bookId < 110_9999;
+        return bookId >= Const.bookIdMin && bookId <= Const.bookInMax;
     }
 
     @CacheFind(key = "defaultFreeChapterNum")

+ 28 - 0
book-server/src/main/java/com/book/server/service/impl/BookServiceImpl.java

@@ -801,4 +801,32 @@ public class BookServiceImpl implements BookService {
         return i;
     }
 
+    @Override
+    public Long getRecommendId() {
+        BookExample example = BookExample.newAndCreateCriteria()
+                .andIdBetween(Const.bookIdMin, Const.bookInMax)
+                .example();
+        example.orderBy(Book.Column.id.desc());
+        Book book = bookMapper.selectOneByExampleSelective(example, Book.Column.id);
+        if (book == null) {
+            return Const.bookIdMin;
+        }
+        return book.getId() + 1;
+    }
+
+    @Override
+    public int deleteUploadFile(Long id) {
+        if (cacheService.isUploadBook(id)) {
+            bookMapper.deleteByPrimaryKey(id);
+            uploadBookMapper.deleteByExample(
+                    UploadBookExample.newAndCreateCriteria()
+                            .andBookIdEqualTo(id)
+                            .example()
+            );
+            return 1;
+        } else {
+            return 0;
+        }
+    }
+
 }