package com.microservices.wiki.service.sys.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.microservices.wiki.domain.sys.Token;
import com.microservices.wiki.mapper.sys.TokenMapper;
import com.microservices.wiki.service.sys.TokenService;
import org.springframework.stereotype.Service;

@Service
public class TokenServiceImpl extends ServiceImpl<TokenMapper, Token> implements TokenService {

    @Override
    public Token getToken(String action, String key) {
        QueryWrapper wrapper = new QueryWrapper<Token>();
        wrapper.eq("action", action);
        wrapper.eq("value", key);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public Token getTokenByUser(int userId, String action) {
        QueryWrapper wrapper = new QueryWrapper<Token>();
        wrapper.eq("action", action);
        wrapper.eq("user_id", userId);
        return baseMapper.selectOne(wrapper);
    }

    @Override
    public int updateByPrimaryKey(Token record) {
        return baseMapper.updateByPrimaryKey(record);
    }


}
