From 24a8d17e007545f7426c48352109aa1a9c6587ee Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 06 五月 2020 12:02:09 +0800 Subject: [PATCH] IOS上线隐藏我的界面的banner与超级会员升级信息 --- fanli/src/main/java/com/yeshi/fanli/aspect/ActiveUserAspect.java | 162 ++++++++++++++++++++++++++++++++--------------------- 1 files changed, 98 insertions(+), 64 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/aspect/ActiveUserAspect.java b/fanli/src/main/java/com/yeshi/fanli/aspect/ActiveUserAspect.java index 5c9d268..e15ff24 100644 --- a/fanli/src/main/java/com/yeshi/fanli/aspect/ActiveUserAspect.java +++ b/fanli/src/main/java/com/yeshi/fanli/aspect/ActiveUserAspect.java @@ -1,19 +1,41 @@ package com.yeshi.fanli.aspect; +import java.lang.reflect.Method; +import java.util.Date; + import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.Signature; import org.aspectj.lang.annotation.Aspect; -import org.springframework.core.annotation.Order; -import org.springframework.core.task.TaskExecutor; +import org.aspectj.lang.annotation.Before; +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.springframework.web.context.request.RequestContextHolder; -import org.springframework.web.context.request.ServletRequestAttributes; +import org.yeshi.utils.NumberUtil; -import com.yeshi.fanli.service.inter.user.UserSystemCouponService; -import com.yeshi.fanli.util.RedisManager; +import com.aliyun.openservices.ons.api.Message; +import com.aliyun.openservices.ons.api.Producer; +import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum; +import com.yeshi.fanli.dto.mq.user.body.UserActiveMQMsg; +import com.yeshi.fanli.service.inter.user.UserInfoExtraService; +import com.yeshi.fanli.service.inter.user.UserInfoModifyRecordService; +import com.yeshi.fanli.service.inter.user.integral.IntegralGetService; +import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.StringUtil; +import com.yeshi.fanli.util.ThreadUtil; +import com.yeshi.fanli.util.annotation.UserActive; +import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory; +import com.yeshi.fanli.util.rocketmq.MQTopicName; + +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.params.SetParams; /** * 娲昏穬鐢ㄦ埛澶勭悊 @@ -21,72 +43,84 @@ * @author Administrator * */ -//@Component -//@Aspect -//@Order(6) +@Component +@Aspect public class ActiveUserAspect { - - @Resource(name = "taskExecutor") - private TaskExecutor executor; + @Resource + private JedisPool jedisPool; @Resource - private RedisManager redisManager; + private UserInfoModifyRecordService userInfoModifyRecordService; @Resource - private UserSystemCouponService userSystemCouponService; + private UserInfoExtraService userInfoExtraService; + @Resource + private IntegralGetService integralGetService; - public static final String EDP = "execution(* com.yeshi.fanli.controller.client.*.*(..))"; - - @Around(EDP) - public Object activeAround(ProceedingJoinPoint joinPoint) throws Throwable { - - Long uid = null; + @Resource(name = "producer") + private Producer producer; - ServletRequestAttributes servletContainer = (ServletRequestAttributes) RequestContextHolder - .getRequestAttributes(); - HttpServletRequest request = servletContainer.getRequest(); - - String str_uid = request.getParameter("uid"); - if (str_uid != null && str_uid.trim().length() > 0) { - uid = Long.parseLong(str_uid); + + private ExpressionParser parser = new SpelExpressionParser(); + + private DefaultParameterNameDiscoverer nameDiscoverer = new DefaultParameterNameDiscoverer(); + + public String generateKeyBySpEL(String spELString, JoinPoint 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]); } - - - final Long uuid = uid; - - executor.execute(new Runnable() { - @Override - public void run() { - - if (uuid == null) { - return; - } - -// // 缂撳瓨uid鐨凨ey -// String key = "activeUid_" + uuid; -// -// // 缂撳瓨涓槸鍚﹀瓨鍦╱id -// String cacheValue = redisManager.getCommonString(key); -// if (cacheValue != null && cacheValue.trim().length() > 0) { -// return; -// } -// -// // 鍔犲叆缂撳瓨 20鍒嗛挓 -// redisManager.cacheCommonString("activeUid_" + uuid, uuid.toString(), 60 * 20); -// - - // 鎺ユ敹鍒� - try { - userSystemCouponService.receivedCoupon(uuid); - } catch (Exception e) { - e.printStackTrace(); + return expression.getValue(context).toString(); + } + + public static final String EDP = "execution(* com.yeshi.fanli.controller.client.*.*.*(..))"; + + @Before(EDP) + public void activeBefore(JoinPoint joinPoint) { + try { + Signature signature = joinPoint.getSignature(); + MethodSignature methodSignature = (MethodSignature) signature; + Method targetMethod = methodSignature.getMethod(); + Method realMethod = joinPoint.getTarget().getClass().getDeclaredMethod(joinPoint.getSignature().getName(), + targetMethod.getParameterTypes()); + if (realMethod.isAnnotationPresent(UserActive.class)) { + UserActive rs = realMethod.getAnnotation(UserActive.class); + String uidStr = generateKeyBySpEL(rs.uid(), joinPoint); + if (!StringUtil.isNullOrEmpty(uidStr) && NumberUtil.isNumeric(uidStr)) { + ThreadUtil.run(new Runnable() { + @Override + public void run() { + String key = "useractive-" + uidStr; + Jedis jedis = jedisPool.getResource(); + try { + if (!StringUtil.isNullOrEmpty(jedis.set(key, "1", new SetParams().nx().ex(Constant.IS_TEST?10:300)))) { + try { +// Long uid = Long.parseLong(uidStr); +// if (!Constant.IS_TEST) { // 娲昏穬閫氱煡 +// UserActiveMQMsg msg = new UserActiveMQMsg(uid, new Date()); +// Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userActve, msg); +// message.setStartDeliverTime(System.currentTimeMillis()+1000*10L);//10s鍚庡彂閫佹椿璺冩秷鎭� +// producer.send(message); +// } + } catch (Exception e) { + + } + } + } finally { + jedis.close(); + } + } + }); } } - }); - - Object[] args = joinPoint.getArgs(); - return joinPoint.proceed(args); + } catch (Exception e) { + + } } } -- Gitblit v1.8.0