package cn.com.ty.lift.system.user.service.impl;

import cn.com.ty.lift.common.utils.ProjectUtils;
import cn.com.ty.lift.system.user.dao.entity.UserInfo;
import cn.com.ty.lift.system.user.dao.mapper.UserInfoMapper;
import cn.com.ty.lift.system.user.service.IUserInfoService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author huangyuan
 * @date 2019-11-29
 * @description 用户信息
 */
@Service
public class UserInfoService extends ServiceImpl<UserInfoMapper, UserInfo> implements IUserInfoService {


    @Override
    public UserInfo getByUserId(Long userId) {
        return this.getById(userId);
    }

    @Override
    public boolean updateUserInfo(UserInfo userInfo) {
        return this.update(userInfo, new UpdateWrapper<UserInfo>()
        .eq("user_id", userInfo.getUserId())
        );
    }

    @Override
    public Map<Long, UserInfo> userIdToInfo(List<Long> userIdList) {
        if(userIdList != null && userIdList.size() > 0){
            List<UserInfo> userInfoList = (List<UserInfo>)this.listByIds(userIdList);
            Map<Long, UserInfo> userIdToInfo = ProjectUtils.attrToObjMap(userInfoList, "userId", null);
            return userIdToInfo;
        }
        return null;
    }
}
