Search in sources :

Example 1 with Book

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());
}
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 Book

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;
}
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 Book

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

Example 4 with Book

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;
}
Also used : BookDTO(com.github.lybgeek.redis.dto.BookDTO) Book(com.github.lybgeek.redis.model.Book) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 5 with Book

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;
}
Also used : BookDTO(com.github.lybgeek.redis.dto.BookDTO) Book(com.github.lybgeek.redis.model.Book) BizException(com.github.lybgeek.common.exception.BizException) Date(java.util.Date) Cacheable(org.springframework.cache.annotation.Cacheable) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Book (com.github.lybgeek.redis.model.Book)5 RedisCache (com.github.lybgeek.redis.annotation.RedisCache)3 BookDTO (com.github.lybgeek.redis.dto.BookDTO)3 Date (java.util.Date)2 Cacheable (org.springframework.cache.annotation.Cacheable)2 Transactional (org.springframework.transaction.annotation.Transactional)2 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 BizException (com.github.lybgeek.common.exception.BizException)1 ArrayList (java.util.ArrayList)1