|
@@ -22,6 +22,8 @@ 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.myevent.TestEvent;
|
|
|
+import com.book.server.myevent.UserRecentReadEvent;
|
|
|
import com.book.server.service.BookService;
|
|
|
import com.book.server.service.CacheService;
|
|
|
import com.book.server.utils.HttpTool;
|
|
@@ -34,6 +36,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.ApplicationEventPublisher;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -219,7 +222,7 @@ public class BookServiceImpl implements BookService {
|
|
|
}
|
|
|
|
|
|
//缓存
|
|
|
- return cacheService.setChaptersByBookIdCache(bookId);
|
|
|
+ return cacheService.getChaptersByBookIdCache(bookId);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -323,7 +326,7 @@ public class BookServiceImpl implements BookService {
|
|
|
// 更新到 user
|
|
|
int i = userMapper.updateUserKandian(user, kandian, 0, DateUtils.getNow());
|
|
|
checkUpdate(i);
|
|
|
- cacheService.updateUserByIdCache(user.getId());
|
|
|
+ cacheService.deleteUserByIdCache(user.getId());
|
|
|
|
|
|
} else {
|
|
|
return Result.failure(ResultCode.NOMONEY);
|
|
@@ -335,39 +338,15 @@ public class BookServiceImpl implements BookService {
|
|
|
content = getBookContent(bookContentVO);
|
|
|
// 添加到阅读记录
|
|
|
if (content != null) {
|
|
|
- //之前是否读过
|
|
|
- UserRecentlyRead userRecentlyRead = userRecentlyReadMapper.selectOneByExample(UserRecentlyReadExample.newAndCreateCriteria()
|
|
|
- .andUserIdEqualTo(bookContentVO.getUserId())
|
|
|
- .andBookIdEqualTo(bookContentVO.getBookId())
|
|
|
- .example());
|
|
|
- if (userRecentlyRead == null) {
|
|
|
- int i = userRecentlyReadMapper.insert(UserRecentlyRead.builder()
|
|
|
- .userId(bookContentVO.getUserId())
|
|
|
- .bookId(book.getId())
|
|
|
- .chapterId(bookContentVO.getContentId())
|
|
|
- .chapterName(bookContentVO.getContentName())
|
|
|
- .createtime(DateUtils.getNow())
|
|
|
- .updatetime(DateUtils.getNow())
|
|
|
- .bookShelfAdd((byte) 0)
|
|
|
- .bookShelfFlag((byte) 0)
|
|
|
- .build());
|
|
|
- //checkUpdate(i);
|
|
|
- } else {
|
|
|
- userRecentlyRead.setChapterId(bookContentVO.getContentId());
|
|
|
- userRecentlyRead.setChapterName(bookContentVO.getContentName());
|
|
|
- userRecentlyRead.setUpdatetime(DateUtils.getNow());
|
|
|
- int i = userRecentlyReadMapper.updateByPrimaryKeySelective(userRecentlyRead,
|
|
|
- UserRecentlyRead.Column.chapterId,
|
|
|
- UserRecentlyRead.Column.chapterName,
|
|
|
- UserRecentlyRead.Column.updatetime
|
|
|
- );
|
|
|
- //checkUpdate(i);
|
|
|
- }
|
|
|
-
|
|
|
+ applicationEventPublisher.publishEvent(new UserRecentReadEvent(this, bookContentVO));
|
|
|
+ //applicationEventPublisher.publishEvent(new TestEvent(this, "!!!!!!!"));
|
|
|
}
|
|
|
return Result.byObject(content);
|
|
|
}
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ApplicationEventPublisher applicationEventPublisher;
|
|
|
+
|
|
|
private BookContent getBookContent(BookContentVO bookContentVO) {
|
|
|
String key = CacheUtil.getKey(Const.EDIT_BOOK_PRE, bookContentVO.getBookId(), bookContentVO.getContentId());
|
|
|
Object o = redisUtil.get(key);
|
|
@@ -387,13 +366,13 @@ public class BookServiceImpl implements BookService {
|
|
|
} else {
|
|
|
bookContent = getBookContentFromRemote(bookContentVO.getBookId(), bookContentVO.getContentId());
|
|
|
}
|
|
|
+ bookContentVO.setContentName(bookContent.getName());
|
|
|
redisUtil.setWithTime(key, JsonUtils.toJsonStr(bookContent));
|
|
|
return bookContent;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
private void checkUpdate(int i) {
|
|
|
if (i <= 0) {
|
|
|
throw new RuntimeException("请稍后重试");
|
|
@@ -702,7 +681,7 @@ public class BookServiceImpl implements BookService {
|
|
|
}
|
|
|
|
|
|
public User getUserById(Long id) {
|
|
|
- return cacheService.updateUserByIdCache(id);
|
|
|
+ return cacheService.getUserByIdCache(id);
|
|
|
}
|
|
|
|
|
|
private String getUserKey(Long id) {
|