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.EmployeeInfoDAO;
import com.jpsoft.shinestar.modules.base.entity.EmployeeInfo;
import com.jpsoft.shinestar.modules.base.service.EmployeeInfoService;
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="employeeInfoService")
public class EmployeeInfoServiceImpl implements EmployeeInfoService {
	@Resource(name="employeeInfoDAO")
	private EmployeeInfoDAO employeeInfoDAO;

	@Override
	public EmployeeInfo get(Long id) {
		// TODO Auto-generated method stub
		return employeeInfoDAO.get(id);
	}

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

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

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

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

	@Override
	public List<EmployeeInfo> findByArray(String[] arr) {
		return employeeInfoDAO.findByArray(arr);
	}

	@Override
	public EmployeeInfo findByOpenId(String openId) {
		return employeeInfoDAO.findByOpenId(openId);
	}
}