package com.ningdatech.carapi.sys.convert;

import cn.hutool.core.collection.CollUtil;
import com.ningdatech.carapi.sys.entity.Company;
import com.ningdatech.carapi.sys.entity.dto.UserQueryDTO;
import com.ningdatech.carapi.sys.entity.vo.UserInfoVO;
import com.ningdatech.carapi.user.entity.NdUserInfo;

import java.util.List;
import java.util.Objects;

/**
 * @Classname UserCompanyConverter
 * @Description
 * @Date 2022/10/9 10:30
 * @Created by PoffyZhang
 */
public class UserCompanyConverter {

    public static UserInfoVO convert(UserInfoVO user, List<Company> companies) {
        if(Objects.isNull(user) || Objects.isNull(user.getId())){
            return user;
        }
        if(CollUtil.isNotEmpty(companies)){
            companies.forEach(company -> {
                if(user.getCompanyId().equals(company.getId())){
                    user.setCompanyName(company.getName());
                }
            });
        }
        return user;
    }

    public static UserQueryDTO convert(UserQueryDTO user, List<Company> companies) {
        if(Objects.isNull(user) || Objects.isNull(user.getId())){
            return user;
        }
        if(CollUtil.isNotEmpty(companies)){
            companies.forEach(company -> {
                if(user.getCompanyId().equals(company.getId())){
                    user.setCompanyName(company.getName());
                }
            });
        }
        return user;
    }
}
