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

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

import com.jpsoft.shinestar.modules.base.entity.CompanyInfo;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.jpsoft.shinestar.modules.sys.dao.UserCompanyDAO;
import com.jpsoft.shinestar.modules.sys.entity.UserCompany;
import com.jpsoft.shinestar.modules.sys.service.UserCompanyService;
import com.github.pagehelper.Page;
import com.jpsoft.shinestar.modules.common.dto.Sort;
import com.github.pagehelper.PageHelper;

@Transactional
@Component(value="userCompanyService")
public class UserCompanyServiceImpl implements UserCompanyService {
	@Resource(name="userCompanyDAO")
	private UserCompanyDAO userCompanyDAO;

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

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

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

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

	@Override
	public boolean exist(String id) {
		// TODO Auto-generated method stub
		int count = userCompanyDAO.exist(id);
		
		return count > 0 ? true : false;
	}
	
	@Override
	public List<UserCompany> list() {
		// TODO Auto-generated method stub
		return userCompanyDAO.list();
	}
		
	@Override
	public Page<UserCompany> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
        Page<UserCompany> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
            userCompanyDAO.search(searchParams,sortList);
        });
        
        return page;
	}

	@Override
	public List<CompanyInfo> findByUserId(String userId) {
		return userCompanyDAO.findByUserId(userId);
	}

	@Override
	public int deleteByUserId(String userId){
		return userCompanyDAO.deleteByUserId(userId);
	}

	@Override
	public List<CompanyInfo> findByUserIdAndOutscourcer(String userId,Boolean isOutsourcer){
		return userCompanyDAO.findByUserIdAndOutscourcer(userId,isOutsourcer);
	}
}