use of com.github.lybgeek.redis.model.Book in project springboot-learning by lyb-geek.
the class BookServiceImpl method editBook.
@Override
@Transactional
// @CachePut(cacheNames = "book",key="'edit_'+#id")
@RedisCache(type = CacheOperateType.UPDTAE, cacheKeyPrefix = "editBook", expireTime = 120)
public BookDTO editBook(BookDTO bookDTO) {
Book book = dozerMapper.map(bookDTO, Book.class);
book.setUpdateDate(new Date());
baseMapper.updateById(book);
return getBookById(book.getId());
}
use of com.github.lybgeek.redis.model.Book in project springboot-learning by lyb-geek.
the class BookServiceImpl method pageBook.
@Override
@RedisCache(type = CacheOperateType.QUERY, cacheKeyPrefix = "pageBook", expireTime = 180)
public PageResult<BookDTO> pageBook(PageQuery<BookDTO> pageQuery) {
log.info("pageBook走db");
BookDTO bookDTO = pageQuery.getQueryParams();
Wrapper<Book> wrapper = wrapperQueryCondition(bookDTO);
IPage<Book> page = new Page<>(pageQuery.getPageNo(), pageQuery.getPageSize());
IPage<Book> bookIPage = baseMapper.selectPage(page, wrapper);
if (bookIPage != null) {
List<BookDTO> bookDTOS = new ArrayList<>();
if (CollectionUtils.isNotEmpty(bookIPage.getRecords())) {
bookDTOS = BeanMapperUtils.mapList(bookIPage.getRecords(), BookDTO.class);
}
return PageUtil.INSTANCE.getPage(bookIPage, bookDTOS);
}
return null;
}
use of com.github.lybgeek.redis.model.Book in project springboot-learning by lyb-geek.
the class BookServiceImpl method getBookByName.
@Override
@RedisCache(type = CacheOperateType.QUERY, expireTime = 180)
public BookDTO getBookByName(String bookName) {
log.info("getBookByName走db");
Wrapper<Book> wrapper = new QueryWrapper<>();
((QueryWrapper<Book>) wrapper).eq("book_name", bookName);
Book book = bookMapper.selectOne(wrapper);
if (ObjectUtils.isNotEmpty(book)) {
return dozerMapper.map(book, BookDTO.class);
}
return null;
}
use of com.github.lybgeek.redis.model.Book in project springboot-learning by lyb-geek.
the class BookServiceImpl method getBookById.
@Override
@Cacheable(cacheNames = "book", key = "#id", unless = "#result == null")
public BookDTO getBookById(Long id) {
log.info("getBookById走db");
Book dbBook = baseMapper.selectById(id);
BookDTO bookDTO = dozerMapper.map(dbBook, BookDTO.class);
return bookDTO;
}
use of com.github.lybgeek.redis.model.Book in project springboot-learning by lyb-geek.
the class BookServiceImpl method addBook.
@Override
@Transactional
@Cacheable(cacheNames = "book", key = "'add_'+#bookDTO.bookName")
public BookDTO addBook(BookDTO bookDTO) {
Book book = dozerMapper.map(bookDTO, Book.class);
boolean isExitBookByName = ObjectUtils.isNotEmpty(getBookByName(bookDTO.getBookName()));
if (isExitBookByName) {
throw new BizException("书名已经存在");
}
book.setCreateDate(new Date());
book.setUpdateDate(new Date());
baseMapper.insert(book);
bookDTO = dozerMapper.map(book, BookDTO.class);
return bookDTO;
}
Aggregations