|  |  |  | 
|---|
|  |  |  | import org.aspectj.lang.reflect.MethodSignature; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.moral.common.bean.AppData; | 
|---|
|  |  |  | import com.moral.common.bean.ResultBean; | 
|---|
|  |  |  | import com.moral.common.exception.BusinessException; | 
|---|
|  |  |  | import com.moral.common.exception.ValidateException; | 
|---|
|  |  |  | 
|---|
|  |  |  | Object target = pjp.getTarget(); | 
|---|
|  |  |  | Method currentMethod = target.getClass().getMethod(msig.getName(), msig.getParameterTypes()); | 
|---|
|  |  |  | Type type = currentMethod.getGenericReturnType(); | 
|---|
|  |  |  | String message = ""; | 
|---|
|  |  |  | String message = e.getMessage(); | 
|---|
|  |  |  | if (e instanceof BusinessException) { | 
|---|
|  |  |  | message = e.getLocalizedMessage(); | 
|---|
|  |  |  | } else if (e instanceof ValidateException) { | 
|---|
|  |  |  | message = e.getLocalizedMessage(); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | log.error(pjp.getSignature() + " error ", e); | 
|---|
|  |  |  | message = e.toString(); | 
|---|
|  |  |  | log.error(pjp.getSignature() + " error: " + e.toString(), e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (type instanceof ParameterizedType) { | 
|---|
|  |  |  | Type rawType = ((ParameterizedType) type).getRawType(); | 
|---|
|  |  |  | if (rawType == ResultBean.class) { | 
|---|
|  |  |  | ResultBean<?> resultBean = new ResultBean(ResultBean.FAIL); | 
|---|
|  |  |  | resultBean.setMessage(message); | 
|---|
|  |  |  | return resultBean; | 
|---|
|  |  |  | } else if (rawType == Map.class) { | 
|---|
|  |  |  | Map<String, Object> result = new HashMap<String, Object>(); | 
|---|
|  |  |  | result.put("msg",message); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | type = ((ParameterizedType) type).getRawType(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (type == AppData.class) { | 
|---|
|  |  |  | return new AppData(message, AppData.FAIL); | 
|---|
|  |  |  | } else if (type == ResultBean.class) { | 
|---|
|  |  |  | return new ResultBean(e); | 
|---|
|  |  |  | } else if (type == Map.class) { | 
|---|
|  |  |  | Map<String, Object> resultMap = new HashMap<String, Object>(); | 
|---|
|  |  |  | resultMap.put("msg", message); | 
|---|
|  |  |  | return resultMap; | 
|---|
|  |  |  | } else if (type == Void.TYPE) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return type.getClass().newInstance(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|