package com.ichangzuo.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ichangzuo.core.security.util.SecurityUtils;
import com.ichangzuo.system.mapper.AccountMapper;
import com.ichangzuo.system.model.entity.Account;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> {
    public Account getCurrentAccount(){
        Long uid = SecurityUtils.getUserId();
        if(uid==null)
            return null;

        Account acc = getOne(new LambdaQueryWrapper<Account>()
                        .eq(Account::getUserId, uid));

        Integer vip = acc.getVipTime();
        if(vip>0 && (vip-System.currentTimeMillis()/1000)<0){
            acc.setVipTime(-2);
        }

        return acc;
    }
}
