From b6c37e4bc38db88a360d0f2c6099183f9bb75bdc Mon Sep 17 00:00:00 2001 From: yujian <yujian> Date: 星期一, 22 四月 2019 14:31:59 +0800 Subject: [PATCH] 券推送插入 --- fanli/src/main/java/com/yeshi/fanli/aspect/ActiveUserAspect.java | 106 +++++++++++++++++++++++----------------------------- 1 files changed, 47 insertions(+), 59 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 08f1d3e..71ecd98 100644 --- a/fanli/src/main/java/com/yeshi/fanli/aspect/ActiveUserAspect.java +++ b/fanli/src/main/java/com/yeshi/fanli/aspect/ActiveUserAspect.java @@ -1,7 +1,5 @@ package com.yeshi.fanli.aspect; -import java.io.IOException; - import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -9,16 +7,14 @@ import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.core.annotation.Order; +import org.springframework.core.task.TaskExecutor; import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; -import com.yeshi.fanli.entity.accept.AcceptData; -import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.user.UserSystemCouponService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.RedisManager; -import com.yeshi.fanli.util.ThreadUtil; /** * 娲昏穬鐢ㄦ埛澶勭悊 @@ -26,10 +22,13 @@ * @author Administrator * */ -//@Component -//@Aspect -//@Order(6) +@Component +@Aspect +@Order(6) public class ActiveUserAspect { + + @Resource(name = "taskExecutor") + private TaskExecutor executor; @Resource private RedisManager redisManager; @@ -37,66 +36,55 @@ @Resource private UserSystemCouponService userSystemCouponService; + public static final String EDP = "execution(* com.yeshi.fanli.controller.client.*.*(..))"; @Around(EDP) public Object activeAround(ProceedingJoinPoint joinPoint) throws Throwable { - Object[] args = joinPoint.getArgs(); - if (!Constant.IS_OUTNET) { - return joinPoint.proceed(args); // 澶栫綉鐜 + Long uid = null; + + 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); } - - try { - - System.out.println("----------娲昏穬楠岃瘉---------------"); - - ServletRequestAttributes servletContainer = (ServletRequestAttributes) RequestContextHolder - .getRequestAttributes(); - - HttpServletRequest request = servletContainer.getRequest(); - - String strUid = request.getParameter("uid"); - if (strUid == null || strUid.trim().length() == 0) { - return joinPoint.proceed(args); - } - - Long uid = Long.parseLong(strUid); - - String key = "activeUid_" + uid; - - String cacheValue = redisManager.getCommonString(key); - if (cacheValue != null && cacheValue.trim().length() > 0) { - return joinPoint.proceed(args); - } - - // 鍔犲叆缂撳瓨 - redisManager.cacheCommonString("activeUid_" + uid, strUid, 60); - - AcceptData acceptData = null; - for (Object argsobj : args) { - if (argsobj instanceof AcceptData) { - acceptData = (AcceptData) argsobj; + + + final Long uuid = uid; + + executor.execute(new Runnable() { + @Override + public void run() { + + if (uuid == null) { + return; + } + + if (Constant.IS_OUTNET) { + String key = "activeUid_" + uuid; + // 缂撳瓨涓槸鍚﹀瓨鍦╱id + String cacheValue = redisManager.getCommonString(key); + if (cacheValue != null && cacheValue.trim().length() > 0) { + return; + } + // 鍔犲叆缂撳瓨 20鍒嗛挓 + redisManager.cacheCommonString(key, uuid.toString(), 60 * 20); + } + + // 鎺ユ敹鍒� + try { + userSystemCouponService.receivedCoupon(uuid); + } catch (Exception e) { + e.printStackTrace(); } } - - if (acceptData == null) { - return joinPoint.proceed(args); - } - - int platformType = 0; - String platform = acceptData.getPlatform(); - if ("android".equals(platform)) { - platformType = 1; - } else if ("ios".equals(platform)) { - platformType = 2; - } - userSystemCouponService.copyLotteryPrize(uid, platformType, acceptData.getDevice()); - } catch (Exception e) { - e.printStackTrace(); - } + }); - return joinPoint.proceed(args); + return joinPoint.proceed(joinPoint.getArgs()); } } -- Gitblit v1.8.0