package com.ningdatech.pmapi.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ningdatech.pmapi.user.entity.UserInfo;
import com.ningdatech.pmapi.user.mapper.NdUserInfoMapper;
import com.ningdatech.pmapi.user.service.IUserInfoService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Lierbao
 * @since 2023-02-01
 */
@Service
@RequiredArgsConstructor
public class UserInfoServiceImpl extends ServiceImpl<NdUserInfoMapper, UserInfo> implements IUserInfoService {

    @Override
    public UserInfo getUserInfoByPhoneNo(String phoneNo) {
        if (StringUtils.isEmpty(phoneNo)) {
            return null;
        }
        LambdaQueryWrapper<UserInfo> query = Wrappers.lambdaQuery(UserInfo.class)
                .eq(UserInfo::getMobile, phoneNo);
        return getOne(query);
    }

    @Override
    public UserInfo getUserInfoByEmployeeCode(String employeeCode) {
        LambdaQueryWrapper<UserInfo> query = Wrappers.lambdaQuery(UserInfo.class)
                .eq(UserInfo::getEmployeeCode, employeeCode);
        return getOne(query);
    }

    @Override
    public List<UserInfo> getUserInfoByEmployeeCodes(Collection<String> employeeCodes) {
        LambdaQueryWrapper<UserInfo> query = Wrappers.lambdaQuery(UserInfo.class)
                .in(UserInfo::getEmployeeCode, employeeCodes);
        return list(query);
    }
}
