package com.jpsoft.shinestar.modules.base.service.impl;

import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.jpsoft.shinestar.modules.base.dao.CompanyContactsDAO;
import com.jpsoft.shinestar.modules.base.entity.CompanyContacts;
import com.jpsoft.shinestar.modules.base.service.CompanyContactsService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="companyContactsService")
public class CompanyContactsServiceImpl implements CompanyContactsService {
	@Resource(name="companyContactsDAO")
	private CompanyContactsDAO companyContactsDAO;

	@Override
	public CompanyContacts get(String id) {
		// TODO Auto-generated method stub
		return companyContactsDAO.get(id);
	}

	@Override
	public int insert(CompanyContacts model) {
		// TODO Auto-generated method stub
		//model.setId(UUID.randomUUID().toString());

		return companyContactsDAO.insert(model);
	}

	@Override
	public int update(CompanyContacts model) {
		// TODO Auto-generated method stub
		return companyContactsDAO.update(model);
	}

	@Override
	public int delete(String id) {
		// TODO Auto-generated method stub
		return companyContactsDAO.delete(id);
	}

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = companyContactsDAO.exist(id);

		return count > 0 ? true : false;
	}

	@Override
	public List<CompanyContacts> list() {
		// TODO Auto-generated method stub
		return companyContactsDAO.list();
	}

	@Override
	public Page<CompanyContacts> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
        Page<CompanyContacts> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            companyContactsDAO.search(searchParams,sortList);
        });

        return page;
	}

	@Override
	public List<CompanyContacts> findByCompanyId(String companyId) {
		return companyContactsDAO.findByCompanyId(companyId);
	}
}