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

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jpsoft.shinestar.modules.base.dao.PersonCompanyDAO;
import com.jpsoft.shinestar.modules.base.entity.PersonCompany;
import com.jpsoft.shinestar.modules.base.service.PersonCompanyService;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Transactional
@Component(value="personCompanyService")
public class PersonCompanyServiceImpl implements PersonCompanyService {
	@Resource(name="personCompanyDAO")
	private PersonCompanyDAO personCompanyDAO;

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

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

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

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

    @Override
    public int deleteByPersonId(Long personId){
        return personCompanyDAO.deleteByPersonId(personId);
    }

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = personCompanyDAO.exist(id);
		
		return count > 0 ? true : false;
	}

	@Override
	public List<PersonCompany> findByPersonId(Long personId){
		return personCompanyDAO.findByPersonId(personId);
	}
	
	@Override
	public List<PersonCompany> list() {
		// TODO Auto-generated method stub
		return personCompanyDAO.list();
	}
		
	@Override
	public Page<PersonCompany> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
        Page<PersonCompany> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            personCompanyDAO.search(searchParams,sortList);
        });
        
        return page;
	}
}