package com.sonic.bear.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sonic.bear.dao.UserThirdDao;
import com.sonic.bear.domain.entity.UserThird;
import com.sonic.bear.enums.ThirdTypeEnum;
import com.sonic.bear.service.UserThirdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author code
 */
@Slf4j
@Service
public class UserThirdServiceImpl extends ServiceImpl<UserThirdDao, UserThird> implements UserThirdService {

    @Override
    public UserThird queryByOpenId(ThirdTypeEnum thirdType, String openId) {
        return getOne(Wrappers.<UserThird>lambdaQuery()
                .eq(UserThird::getThirdType, thirdType.name())
                .eq(UserThird::getOpenId, openId)
                .eq(UserThird::getIsDelete, false)
                .orderByDesc(UserThird::getId)
                .last("limit 1"));
    }
}
