Commit 3e9dfec3 by 田超

Merge branch 'feature/1006793' into 'master'

feat: [1006793] 接口优化

See merge request rays/pcloud-book!1516
parents dfe3da7a d8531e97
...@@ -317,4 +317,9 @@ public interface BookService { ...@@ -317,4 +317,9 @@ public interface BookService {
@ApiOperation("更新昨日修改过的书刊的标签") @ApiOperation("更新昨日修改过的书刊的标签")
@GetMapping("updateYesterdayBookNewLabel") @GetMapping("updateYesterdayBookNewLabel")
void updateYesterdayBookNewLabel(); void updateYesterdayBookNewLabel();
@GetMapping("getBookFromRedis")
ResponseEntity<ResponseDto<BookDto>> getBookFromRedis(@RequestParam(value = "bookId") Long bookId);
} }
...@@ -826,4 +826,11 @@ public interface BookBiz { ...@@ -826,4 +826,11 @@ public interface BookBiz {
* 通过isbn,书名等信息去es库里面匹配图书封面 * 通过isbn,书名等信息去es库里面匹配图书封面
*/ */
List<String> listBookCover(String isbn, String bookName, String author, String publish); List<String> listBookCover(String isbn, String bookName, String author, String publish);
/**
* 从缓存中获取基本信息
* @param bookId
* @return
*/
BookDto getBookFromRedis(Long bookId);
} }
...@@ -4668,4 +4668,16 @@ public class BookBizImpl implements BookBiz { ...@@ -4668,4 +4668,16 @@ public class BookBizImpl implements BookBiz {
dto.setPublish(publish); dto.setPublish(publish);
return bookElasticSearchConsr.searchBookExtendImg(dto); return bookElasticSearchConsr.searchBookExtendImg(dto);
} }
@Override
public BookDto getBookFromRedis(Long bookId) {
BookDto bookDto = bookCache.getBookFromRedis(bookId);
if (null == bookDto) {
bookDto = bookDao.getBaseById(bookId);
if (null != bookDto) {
bookCache.setBookInfoToRedis(bookDto);
}
}
return null;
}
} }
...@@ -17,6 +17,8 @@ import java.util.Objects; ...@@ -17,6 +17,8 @@ import java.util.Objects;
@Component("bookCache") @Component("bookCache")
public class BookCache { public class BookCache {
private static String BOOK_BASE_INFO_CACHE = "book:baseinfo:cache";
public void clearCache4BookBaseInfo(Long bookId){ public void clearCache4BookBaseInfo(Long bookId){
if (Objects.nonNull(bookId)){ if (Objects.nonNull(bookId)){
StringBuffer key = new StringBuffer(BookConstant.BOOK_CACHE); StringBuffer key = new StringBuffer(BookConstant.BOOK_CACHE);
...@@ -92,6 +94,7 @@ public class BookCache { ...@@ -92,6 +94,7 @@ public class BookCache {
} }
JedisClusterUtils.del(key.toString()); JedisClusterUtils.del(key.toString());
JedisClusterUtils.del(isbnKey.toString()); JedisClusterUtils.del(isbnKey.toString());
JedisClusterUtils.hdel(BOOK_BASE_INFO_CACHE, bookId.toString());
} }
/** /**
...@@ -145,4 +148,19 @@ public class BookCache { ...@@ -145,4 +148,19 @@ public class BookCache {
} }
public BookDto getBookFromRedis(Long bookId) {
if (null == bookId) {
return null;
}
BookDto bookDto = JedisClusterUtils.hgetJson2Class(BOOK_BASE_INFO_CACHE, bookId.toString(), BookDto.class);
return bookDto;
}
public void setBookInfoToRedis(BookDto bookDto) {
if (null == bookDto || null == bookDto.getBookId()) {
return;
}
JedisClusterUtils.hset2Json(BOOK_BASE_INFO_CACHE, bookDto.getBookId().toString(), bookDto);
}
} }
...@@ -297,4 +297,12 @@ public class BookServiceImpl implements BookService { ...@@ -297,4 +297,12 @@ public class BookServiceImpl implements BookService {
public void updateYesterdayBookNewLabel() { public void updateYesterdayBookNewLabel() {
ThreadPoolUtils.OTHER_THREAD_POOL.execute(()->bookLabelBiz.updateYesterdayBookNewLabel()); ThreadPoolUtils.OTHER_THREAD_POOL.execute(()->bookLabelBiz.updateYesterdayBookNewLabel());
} }
@Override
@GetMapping("getBookFromRedis")
public ResponseEntity<ResponseDto<BookDto>> getBookFromRedis(@RequestParam("bookId") Long bookId) {
return ResponseHandleUtil.toResponse(bookBiz.getBookFromRedis(bookId));
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment