LoginHistoryAspect.java 2.95 KB
package com.lhcredit.framework.aspectj;//package com.lhcredit.framework.aspectj;
//
//import com.lhcredit.framework.aspectj.lang.annotation.LoginHistoryArr;
//import com.lhcredit.framework.web.domain.AjaxResult;
//import com.lhcredit.framework.web.domain.TokenEntity;
//import com.lhcredit.framework.web.service.TokenManager;
//import com.lhcredit.project.business.loginHistory.domain.LoginHistory;
//import com.lhcredit.project.business.loginHistory.service.ILoginHistoryService;
//import com.lhcredit.project.front.frontUser.domain.FrontUser;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.Signature;
//import org.aspectj.lang.annotation.After;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.lang.reflect.Method;
//import java.util.Date;
//
//@Aspect
//@Component
//public class LoginHistoryAspect {
//    @Autowired
//    private ILoginHistoryService loginHistoryService;
//    @Autowired
//    private TokenManager tokenManager;
//
//    // 配置织入点
//    @Pointcut("@annotation(com.lhcredit.framework.aspectj.lang.annotation.LoginHistoryArr)")
//    public void LoginPointCut() {
//
//    }
//
//    @Around("LoginPointCut()")
//    public Object d(ProceedingJoinPoint point) throws Throwable {
//        AjaxResult res=new AjaxResult(AjaxResult.Type.ERROR,"登录失败");
//        try {
//             res =(AjaxResult)point.proceed();
//            int code = (int)res.get("code");
//            if(2000 == code){
//                FrontUser user = (FrontUser)res.get("data");
//                LoginHistory loginHistory = new LoginHistory();
//                if (null != user) {
//                    loginHistory.setUserId(user.getUserId());
//                    loginHistory.setStatus("0");
//                    loginHistory.setDelFlag("0");
//                    loginHistory.setLastLoginTime((new Date()));
//                    loginHistory.setUpdateTime(new Date());
//                    loginHistory.setCreateTime(new Date());
//                    loginHistoryService.insertLoginHistory(loginHistory);
//                }
//            }
//        } catch (Throwable throwable) {
//            throwable.printStackTrace();
//        }
//
//        return res;
//    }
//
//
//
//    /**
//     * 是否存在注解,如果存在就获取
//     */
//    private LoginHistoryArr getAnnotationLog(JoinPoint joinPoint) {
//        Signature signature = joinPoint.getSignature();
//        MethodSignature methodSignature = (MethodSignature) signature;
//        Method method = methodSignature.getMethod();
//
//        if (method != null) {
//            return method.getAnnotation(LoginHistoryArr.class);
//        }
//        return null;
//    }
//
//}