package com.ningdatech.kqapi.user.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ningdatech.kqapi.user.model.entity.UserInfo;
import com.ningdatech.kqapi.user.model.enumerization.AccountStatus;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

/**
 * <p>
 * 服务类
 * </p>
 *
 * @author Liuxinxin
 * @since 2022-11-23
 */
public interface IUserInfoService extends IService<UserInfo> {

    default String getRealName(Long userId) {
        LambdaQueryWrapper<UserInfo> query = Wrappers.lambdaQuery(UserInfo.class)
                .select(UserInfo::getRealName)
                .eq(UserInfo::getId, userId);
        return Optional.ofNullable(getOne(query))
                .flatMap(w -> Optional.of(w.getRealName()))
                .orElse(null);
    }

    default List<UserInfo> list(Collection<Long> userIds, AccountStatus accountStatus) {
        LambdaQueryWrapper<UserInfo> uQuery = Wrappers.lambdaQuery(UserInfo.class)
                .in(UserInfo::getId, userIds)
                .eq(UserInfo::getAccountStatus, accountStatus);
        return list(uQuery);
    }

}
