Search in sources :

Example 1 with OperateType

use of com.github.lybgeek.elasticsearch.enu.OperateType 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)

Aggregations

PageQuery (com.github.lybgeek.common.model.PageQuery)1 OperateType (com.github.lybgeek.elasticsearch.enu.OperateType)1 Around (org.aspectj.lang.annotation.Around)1