New file |
| | |
| | | package com.yeshi.fanli.aspect;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.lang.reflect.Method;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.aspectj.lang.ProceedingJoinPoint;
|
| | | import org.aspectj.lang.Signature;
|
| | | import org.aspectj.lang.annotation.Around;
|
| | | import org.aspectj.lang.annotation.Aspect;
|
| | | import org.aspectj.lang.reflect.MethodSignature;
|
| | | import org.springframework.core.DefaultParameterNameDiscoverer;
|
| | | import org.springframework.expression.EvaluationContext;
|
| | | import org.springframework.expression.Expression;
|
| | | import org.springframework.expression.ExpressionParser;
|
| | | import org.springframework.expression.spel.standard.SpelExpressionParser;
|
| | | import org.springframework.expression.spel.support.StandardEvaluationContext;
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.yeshi.utils.NumberUtil;
|
| | |
|
| | | import com.yeshi.fanli.entity.bus.user.UserActiveLog;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.user.UserActiveLogService;
|
| | | import com.yeshi.fanli.util.VersionUtil;
|
| | | import com.yeshi.fanli.util.annotation.RequestSerializableByKey;
|
| | | import com.yeshi.fanli.util.annotation.integral.IntegralGetVersionLimit;
|
| | |
|
| | | @Component
|
| | | @Aspect
|
| | | public class IntegralGetVersionLimitAspect {
|
| | |
|
| | | @Resource
|
| | | private UserActiveLogService userActiveLogService;
|
| | |
|
| | | private ExpressionParser parser = new SpelExpressionParser();
|
| | |
|
| | | private DefaultParameterNameDiscoverer nameDiscoverer = new DefaultParameterNameDiscoverer();
|
| | |
|
| | | public String generateKeyBySpEL(String spELString, ProceedingJoinPoint joinPoint) {
|
| | | MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
|
| | | String[] paramNames = nameDiscoverer.getParameterNames(methodSignature.getMethod());
|
| | | Expression expression = parser.parseExpression(spELString);
|
| | | EvaluationContext context = new StandardEvaluationContext();
|
| | | Object[] args = joinPoint.getArgs();
|
| | | for (int i = 0; i < args.length; i++) {
|
| | | context.setVariable(paramNames[i], args[i]);
|
| | | }
|
| | | return expression.getValue(context).toString();
|
| | | }
|
| | |
|
| | | @Around("execution(public * com.yeshi.fanli.service.impl.integral.*.*(..))")
|
| | | public Object requestSerializable(ProceedingJoinPoint joinPoint) throws IOException {
|
| | | Signature signature = joinPoint.getSignature();
|
| | | MethodSignature methodSignature = (MethodSignature) signature;
|
| | | Method targetMethod = methodSignature.getMethod();
|
| | | try {
|
| | | Method realMethod = joinPoint.getTarget().getClass().getDeclaredMethod(joinPoint.getSignature().getName(),
|
| | | targetMethod.getParameterTypes());
|
| | | if (realMethod.isAnnotationPresent(IntegralGetVersionLimit.class)) {
|
| | | IntegralGetVersionLimit rs = realMethod.getAnnotation(IntegralGetVersionLimit.class);
|
| | | String key = rs.uid();
|
| | | String uid = generateKeyBySpEL(key, joinPoint);
|
| | | if (uid != null && NumberUtil.isNumeric(uid)) {
|
| | | UserActiveLog activeLog = userActiveLogService.getUserLatestActiveInfo(Long.parseLong(uid));
|
| | | if (activeLog != null) {
|
| | | // 小于1.6.5版本不增加积分
|
| | | if (!VersionUtil.greaterThan_1_6_5(
|
| | | "appstore".equalsIgnoreCase(activeLog.getChannel()) ? "ios" : "android",
|
| | | activeLog.getVersionCode()))
|
| | | return null;
|
| | | }
|
| | | }
|
| | | }
|
| | | } catch (NoSuchMethodException e) {
|
| | | e.printStackTrace();
|
| | | } catch (SecurityException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | try {
|
| | | return joinPoint.proceed();
|
| | | } catch (Throwable e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } finally {
|
| | |
|
| | | }
|
| | |
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|