package com.bjsxt.aop;

import com.bjsxt.mapper.LogsMapper;
import com.bjsxt.pojo.Logs;
import com.bjsxt.pojo.Users;
import com.bjsxt.pojo.UsersExt;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Aspect
@Component
public class UsersLoginAop {

    @Autowired
    private LogsMapper logsMapper;

    @Pointcut("execution(* com.bjsxt.service.UsersService.usersLogin(..))")
    public void myPointcut(){

    }

    @AfterReturning("myPointcut()")
    public void usersLoginLog(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        UsersExt users = (UsersExt) args[0];
        Logs logs = new Logs();
        logs.setLogtime(new Date());
        logs.setUsername(users.getUsername());
        logs.setIp(users.getIp());
        this.logsMapper.insertSelective(logs);

    }



}
