Search in sources :

Example 1 with RedisCache

use of com.github.lybgeek.redis.annotation.RedisCache 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());
}
Also used : Book(com.github.lybgeek.redis.model.Book) Date(java.util.Date) RedisCache(com.github.lybgeek.redis.annotation.RedisCache) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with RedisCache

use of com.github.lybgeek.redis.annotation.RedisCache 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;
}
Also used : BookDTO(com.github.lybgeek.redis.dto.BookDTO) Book(com.github.lybgeek.redis.model.Book) ArrayList(java.util.ArrayList) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) RedisCache(com.github.lybgeek.redis.annotation.RedisCache)

Example 3 with RedisCache

use of com.github.lybgeek.redis.annotation.RedisCache 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;
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Book(com.github.lybgeek.redis.model.Book) RedisCache(com.github.lybgeek.redis.annotation.RedisCache)

Aggregations

RedisCache (com.github.lybgeek.redis.annotation.RedisCache)3 Book (com.github.lybgeek.redis.model.Book)3 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 BookDTO (com.github.lybgeek.redis.dto.BookDTO)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Transactional (org.springframework.transaction.annotation.Transactional)1