package cn.com.ctop.common.module.service.impl;

import cn.com.ctop.common.module.entity.CtopCorpWexinUser;
import cn.com.ctop.common.module.mapper.CtopCorpWexinUserMapper;
import cn.com.ctop.common.module.service.ICtopCorpWexinUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

/**
 * 企业微信用户表
 *
 * @author jeecg-boot
 * @version V1.0
 * @date 2019-12-08
 */
@Service
@Primary
public class CtopCorpWexinUserServiceImpl extends ServiceImpl<CtopCorpWexinUserMapper, CtopCorpWexinUser> implements ICtopCorpWexinUserService {

    @Autowired
    CtopCorpWexinUserMapper ctopCorpWexinUserMapper;

    @Override
    public String getEmailByUserId(String userId) {
        return ctopCorpWexinUserMapper.queryEmailByUserId(userId);
    }

    @Override
    public CtopCorpWexinUser getInfoByUserId(String userId) {
        QueryWrapper<CtopCorpWexinUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("wexin_id", userId);
        queryWrapper.orderByDesc("create_time");
        queryWrapper.last("limit 1");
        return this.getOne(queryWrapper);
    }
}
