Search in sources :

Example 1 with PageQuery

use of com.github.lybgeek.common.model.PageQuery in project springboot-learning by lyb-geek.

the class ElasticsearchAspect method around.

@Around(value = "@annotation(operate)")
public Object around(ProceedingJoinPoint pjp, EsOperate operate) {
    OperateType type = operate.type();
    Object[] args = pjp.getArgs();
    Object result = null;
    String methodName = pjp.getSignature().getName();
    if (ArrayUtils.isNotEmpty(args) && args.length == 1) {
        Object param = args[0];
        switch(type) {
            case QUERY:
                if (param instanceof PageQuery) {
                    PageQuery pageQuery = (PageQuery) param;
                    result = this.pageQuery(pageQuery, operate.indexName());
                } else {
                    result = this.query(param, operate.indexName());
                }
                break;
        }
    }
    if (ObjectUtils.isEmpty(result)) {
        try {
            log.info("{} load data from db", methodName);
            return pjp.proceed();
        } catch (Throwable throwable) {
            log.error(throwable.getMessage(), throwable);
        }
    }
    if (OperateType.QUERY == type) {
        log.info("{} load data from es", methodName);
    }
    return result;
}
Also used : PageQuery(com.github.lybgeek.common.model.PageQuery) OperateType(com.github.lybgeek.elasticsearch.enu.OperateType) Around(org.aspectj.lang.annotation.Around)

Example 2 with PageQuery

use of com.github.lybgeek.common.model.PageQuery in project springboot-learning by lyb-geek.

the class ShortUrlServiceImpl method getShortUrlPageQuery.

private PageQuery<ShortUrl> getShortUrlPageQuery(PageQuery<ShortUrlDTO> pageQuery) {
    PageQuery<ShortUrl> query = new PageQuery<>();
    BeanUtils.copyProperties(pageQuery, query);
    ShortUrl shortUrl = BeanMapperUtil.map(pageQuery.getQueryParams(), ShortUrl.class);
    query.setQueryParams(shortUrl);
    return query;
}
Also used : ShortUrl(com.github.lybgeek.shorturl.model.ShortUrl) PageQuery(com.github.lybgeek.common.model.PageQuery)

Example 3 with PageQuery

use of com.github.lybgeek.common.model.PageQuery in project springboot-learning by lyb-geek.

the class ElasticsearchApplicationTest method testPage.

@Test
public void testPage() {
    PageQuery pageQuery = new PageQuery<>().setPageNo(1).setPageSize(5);
    ShortUrlDTO dto = new ShortUrlDTO();
    dto.setUrlName("门户");
    // dto.setRemark("门户");
    pageQuery.setQueryParams(dto);
    PageResult<ShortUrlDTO> pageResult = shortUrlService.pageShortUrl(pageQuery);
    System.out.println(pageResult);
}
Also used : PageQuery(com.github.lybgeek.common.model.PageQuery) ShortUrlDTO(com.github.lybgeek.shorturl.dto.ShortUrlDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with PageQuery

use of com.github.lybgeek.common.model.PageQuery in project springboot-learning by lyb-geek.

the class ElasticsearchApplicationTest method testCustomPageShortUrl.

@Test
public void testCustomPageShortUrl() {
    PageQuery pageQuery = new PageQuery<>().setPageNo(5).setPageSize(5);
    ShortUrlDTO dto = new ShortUrlDTO();
    // dto.setUrlName("优酷");
    // dto.setRemark("视频");
    // pageQuery.setQueryParams(dto);
    PageResult<ShortUrlDTO> pageResult = customShortUrlEsService.pageShortUrl(pageQuery);
    System.out.println(pageResult);
}
Also used : PageQuery(com.github.lybgeek.common.model.PageQuery) ShortUrlDTO(com.github.lybgeek.shorturl.dto.ShortUrlDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with PageQuery

use of com.github.lybgeek.common.model.PageQuery in project springboot-learning by lyb-geek.

the class RedisApplicationTest method testPageBook.

@Test
public void testPageBook() {
    PageQuery pageQuery = new PageQuery<>().setPageNo(1).setPageSize(5);
    BookDTO bookDTO = new BookDTO();
    bookDTO.setAuthor("张三");
    // bookDTO.setBookName("图解Http");
    // bookDTO.setId(4L);
    pageQuery.setQueryParams(bookDTO);
    PageResult<BookDTO> pageResult = bookService.pageBook(pageQuery);
    if (pageResult != null) {
        pageResult.getList().forEach(book -> System.out.println(book));
    }
}
Also used : PageQuery(com.github.lybgeek.common.model.PageQuery) BookDTO(com.github.lybgeek.redis.dto.BookDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

PageQuery (com.github.lybgeek.common.model.PageQuery)6 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 ShortUrlDTO (com.github.lybgeek.shorturl.dto.ShortUrlDTO)2 OperateType (com.github.lybgeek.elasticsearch.enu.OperateType)1 BookDTO (com.github.lybgeek.httpclient.dto.BookDTO)1 BookDTO (com.github.lybgeek.redis.dto.BookDTO)1 ShortUrl (com.github.lybgeek.shorturl.model.ShortUrl)1 Around (org.aspectj.lang.annotation.Around)1