|
@@ -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;
|
|
|
+ }
|
|
|
|
|
|
}
|