|
@@ -17,9 +17,11 @@ import com.book.dao.cpsshard.pojo.example.UserRecentlyReadExample;
|
|
|
import com.book.server.common.entity.Result;
|
|
|
import com.book.server.common.entity.ResultCode;
|
|
|
import com.book.dao.utils.DateUtils;
|
|
|
+import com.book.server.common.util.CacheUtil;
|
|
|
import com.book.server.common.util.JsonUtils;
|
|
|
import com.book.dao.cps.pojo.example.*;
|
|
|
import com.book.dao.VO.*;
|
|
|
+import com.book.server.config.Const;
|
|
|
import com.book.server.service.BookService;
|
|
|
import com.book.server.service.CacheService;
|
|
|
import com.book.server.utils.HttpTool;
|
|
@@ -261,7 +263,8 @@ public class BookServiceImpl implements BookService {
|
|
|
if (freeChapterNum == null) { //查看默认配置
|
|
|
freeChapterNum = getDefaultFreeChapterNum();
|
|
|
}
|
|
|
- if (bookContentVO.getContentId() > freeChapterNum) { //收费
|
|
|
+ if (bookContentVO.getContentId() > freeChapterNum) {
|
|
|
+ //收费
|
|
|
//是否已购买
|
|
|
Consume consume = consumeMapper.selectOneByExample(ConsumeExample.newAndCreateCriteria()
|
|
|
.andUserIdEqualTo(bookContentVO.getUserId())
|
|
@@ -366,7 +369,7 @@ public class BookServiceImpl implements BookService {
|
|
|
}
|
|
|
|
|
|
private BookContent getBookContent(BookContentVO bookContentVO) {
|
|
|
- String key = getKey("edit_book", bookContentVO.getBookId(), bookContentVO.getContentId());
|
|
|
+ String key = CacheUtil.getKey(Const.EDIT_BOOK_PRE, bookContentVO.getBookId(), bookContentVO.getContentId());
|
|
|
Object o = redisUtil.get(key);
|
|
|
if (o != null) {
|
|
|
return JsonUtils.getObject(o.toString(), BookContent.class);
|
|
@@ -378,18 +381,19 @@ public class BookServiceImpl implements BookService {
|
|
|
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());
|
|
|
}
|
|
|
+ redisUtil.setWithTime(key, JsonUtils.toJsonStr(bookContent));
|
|
|
return bookContent;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
private void checkUpdate(int i) {
|
|
|
if (i <= 0) {
|
|
|
throw new RuntimeException("请稍后重试");
|
|
@@ -702,17 +706,17 @@ public class BookServiceImpl implements BookService {
|
|
|
}
|
|
|
|
|
|
public String getEditBookContentById(Long bookId, Long chapterId) {
|
|
|
- String key = getKey("edit_book", bookId, chapterId);
|
|
|
+ String key = CacheUtil.getKey(Const.EDIT_BOOK_PRE, bookId, chapterId);
|
|
|
Object o = redisUtil.get(key);
|
|
|
if (o == null) {
|
|
|
return null;
|
|
|
} else {
|
|
|
- return (String) o;
|
|
|
+ return o.toString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public String getKey(Object... keys) {
|
|
|
- StringBuilder sb = new StringBuilder("t_");
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
for (Object key : keys) {
|
|
|
sb.append(key).append("_");
|
|
|
}
|
|
@@ -720,7 +724,7 @@ public class BookServiceImpl implements BookService {
|
|
|
}
|
|
|
|
|
|
public void updateEditBookByIdCache(Long bookId, Long chapterId) {
|
|
|
- String key = getKey("edit_book", bookId, chapterId);
|
|
|
+ String key = CacheUtil.getKey(Const.EDIT_BOOK_PRE, bookId, chapterId);
|
|
|
EditBook obj = editBookMapper.selectOneByExampleSelective(
|
|
|
EditBookExample.newAndCreateCriteria()
|
|
|
.andBookIdEqualTo(bookId)
|
|
@@ -736,11 +740,12 @@ public class BookServiceImpl implements BookService {
|
|
|
List<EditBook> editBooks = editBookMapper.selectByExampleSelective(EditBookExample.newAndCreateCriteria().example(),
|
|
|
EditBook.Column.bookId, EditBook.Column.chapterId, EditBook.Column.content);
|
|
|
editBooks.forEach(x -> {
|
|
|
- String key = getKey("edit_book", x.getBookId(), x.getChapterId());
|
|
|
+ String key = CacheUtil.getKey(Const.EDIT_BOOK_PRE, x.getBookId(), x.getChapterId());
|
|
|
redisUtil.set(key, JsonUtils.toJsonStr(x));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private List<BookRes> getRandom(List<BookRes> bookRes) {
|
|
|
if (bookRes.size() <= 4) {
|
|
|
return bookRes;
|