package com.qiankun.utils;

import com.qiankun.entity.Contacts;
import com.qiankun.entity.User;
import com.qiankun.vo.UserVo;
import org.springframework.beans.BeanUtils;

import java.util.Iterator;
import java.util.Set;

public class UserUtils {

    public static UserVo converToVo(User user){
        UserVo vo = null;
        if (user != null){
            vo = new UserVo();
            BeanUtils.copyProperties(user,vo);
            Set<Contacts> contacts = user.getContacts();
            if (contacts != null){
                Iterator<Contacts> its = contacts.iterator();
                Integer count = 0;
                while (its.hasNext()) {
                    Contacts c = its.next();
                    if (count == 0) {
                        vo.setContactsAddr1(c.getAddr());
                        vo.setContactsName1(c.getName());
                        vo.setContactsMobile1(c.getMobile());
                        vo.setContactsRelation1(c.getRelation());
                        vo.setContactsWeixin1(c.getWeixin());
                        vo.setContactsQQ1(c.getQq());
                        count ++;
                    } else {
                        vo.setContactsAddr2(c.getAddr());
                        vo.setContactsName2(c.getName());
                        vo.setContactsMobile2(c.getMobile());
                        vo.setContactsRelation2(c.getRelation());
                        vo.setContactsWeixin2(c.getWeixin());
                        vo.setContactsQQ2(c.getQq());
                    }


                }
            }

        }
        return vo;
    }
}
