package com.goafanti.user.service.impl;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.goafanti.common.dao.OrganizationContactBookMapper;
import com.goafanti.common.model.OrganizationContactBook;
import com.goafanti.user.bo.UserContactBo;
import com.goafanti.user.service.UserContactService;

@Service
public class UserContactServiceImpl implements UserContactService {
	
	@Autowired
	private OrganizationContactBookMapper organizationContactBookMapper;
	
	@Override
	public List<UserContactBo> selectContactByUid(String uid) {
		// TODO Auto-generated method stub
		return organizationContactBookMapper.selectContactByUid(uid);
	}

	@Override
	public boolean checkUserContact(String uid,String mobile) {
		// TODO Auto-generated method stub
		return organizationContactBookMapper.checkContacts(uid, mobile, null)>0;
	}

	@Override
	public int insertSelective(UserContactBo bo) {
		OrganizationContactBook book = new OrganizationContactBook();
		if(bo != null){
			BeanUtils.copyProperties(bo, book);
			book.setId(UUID.randomUUID().toString());
			return organizationContactBookMapper.insertSelective(book);
		}
		return 0;
	}

	@Override
	public int updateByPrimaryKeySelective(UserContactBo bo) {
		OrganizationContactBook book = new OrganizationContactBook();
		if(bo != null){
			BeanUtils.copyProperties(bo, book);
			return organizationContactBookMapper.updateByPrimaryKeySelective(book);
		}
		return 0;
	}

	@Override
	public int deleteUserContact(String id) {
		return organizationContactBookMapper.deleteByPrimaryKey(id);
	}
	
}
