| | |
| | | package com.yeshi.fanli.aspect;
|
| | |
|
| | | import java.io.IOException;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | |
|
| | |
| | | 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;
|
| | |
|
| | | /**
|
| | | * 活跃用户处理
|
| | |
| | | //@Aspect
|
| | | //@Order(6)
|
| | | public class ActiveUserAspect {
|
| | | |
| | | @Resource(name = "taskExecutor")
|
| | | private TaskExecutor executor;
|
| | |
|
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | |
| | | @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); // 外网环境
|
| | | }
|
| | |
|
| | | 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;
|
| | | ServletRequestAttributes servletContainer = (ServletRequestAttributes) RequestContextHolder
|
| | | .getRequestAttributes();
|
| | | |
| | | final Object[] args = joinPoint.getArgs();
|
| | | |
| | | final HttpServletRequest request = servletContainer.getRequest();
|
| | | |
| | | executor.execute(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | |
| | | AcceptData acceptData = null;
|
| | | for (Object argsobj : args) {
|
| | | if (argsobj instanceof AcceptData) {
|
| | | acceptData = (AcceptData) argsobj;
|
| | | }
|
| | | }
|
| | | |
| | | // 自动领取券-系统发放
|
| | | receivedPushCoupon(acceptData, request);
|
| | | }
|
| | |
|
| | | 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);
|
| | | }
|
| | |
|
| | | |
| | | |
| | | /**
|
| | | * 使用中 自动领取系统推送券
|
| | | * @param acceptData
|
| | | * @param request
|
| | | */
|
| | | public void receivedPushCoupon(AcceptData acceptData, HttpServletRequest request) {
|
| | |
|
| | | if (acceptData == null) {
|
| | | return;
|
| | | }
|
| | | |
| | | String strUid = request.getParameter("uid");
|
| | | if (strUid == null || strUid.trim().length() == 0) {
|
| | | return;
|
| | | }
|
| | |
|
| | | try {
|
| | | Long uid = Long.parseLong(strUid);
|
| | |
|
| | | // 缓存中是否存在uid
|
| | | String key = "activeUid_" + uid;
|
| | | String cacheValue = redisManager.getCommonString(key);
|
| | | if (cacheValue != null && cacheValue.trim().length() > 0) {
|
| | | return;
|
| | | }
|
| | |
|
| | | // 加入缓存 20分钟
|
| | | redisManager.cacheCommonString("activeUid_" + uid, strUid, 60 * 20);
|
| | |
|
| | | // 接收券
|
| | | userSystemCouponService.receivedCoupon(uid);
|
| | | |
| | | } catch (Exception e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | | }
|
| | | |
| | | |
| | | }
|