package com.alipay.dtcollectconsole.dtimage.aop;
/**
* Shangshu
* Copyright (c) 2017-2017 All Rights Reserved.
*/
import com.alipay.dtcollectconsole.common.dal.dtimage.domain.PageModel;
import com.alipay.dtcollectconsole.dtimagemodel.exception.DtimageException;
import com.alipay.dtcollectconsole.dtimagemodel.result.AjaxResult;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
/**
* @author wb-wulonghai
* @version 2017/3/20
* 反屏蔽中心服务层切面,统一封装异常返回页面。
* pageNumber、pageSize统一处理异常参数。
*/
@Aspect
public class DtimageExceptionAspect {
@Pointcut("execution(com.alipay.dtcollectconsole.dtimagemodel.result.AjaxResult com.alipay.dtcollectconsole.dtimage.impl.*.*(..))")
private void dtimagePointCut(){}
@Pointcut("execution(com.alipay.dtcollectconsole.dtimagemodel.result.AjaxResult com.alipay.dtcollectconsole.anticrawler.impl.*.*(..))")
private void anticrawlerPointCut(){}
@Pointcut("dtimagePointCut() || anticrawlerPointCut()")
private void pointCut(){}
@Around(value = "pointCut()")
public Object aroundRecordLog(ProceedingJoinPoint pjp) throws Throwable {
AjaxResult ajaxResult = new AjaxResult();
Object result;
Object[] args = pjp.getArgs();
if (args.length > 0 && args[0] instanceof PageModel) {
//转换分页参数,处理异常数据
PageModel arg = (PageModel) args[0];
if (arg.getPageNumber() != null && arg.getPageSize() != null) {
if (arg.getPageNumber() < 1) {
arg.setPageNumber(1);
}
arg.setPageNumber((arg.getPageNumber() - 1) * arg.getPageSize());
}
}
try {
result = pjp.proceed();
} catch (DtimageException e) {
ajaxResult.setSuccess(false);
ajaxResult.setErrorMsg(e.getMessage());
ajaxResult.setErrorCode(e.getDetailMsg() == null ? e.getCode() : e.getDetailMsg());
return ajaxResult;
} catch (Exception e) {
ajaxResult.setSuccess(false);
ajaxResult.setErrorMsg("服务器其他未知异常");
ajaxResult.setErrorCode(e.getMessage());
return ajaxResult;
}
return result;
}
}