package com.goafanti.user.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.goafanti.common.dao.OrgHumanResourceMapper;
import com.goafanti.common.model.OrgHumanResource;
import com.goafanti.core.mybatis.BaseMybatisDao;
import com.goafanti.core.mybatis.page.Pagination;
import com.goafanti.user.service.OrgHumanResourceService;
@Service
public class OrgHumanResourceServiceImpl extends BaseMybatisDao<OrgHumanResourceMapper> implements OrgHumanResourceService{
	@Autowired
	private OrgHumanResourceMapper  orgHumanResourceMapper;
	
	@SuppressWarnings("unchecked")
	@Override
	public Pagination<OrgHumanResource> listOrgHumanResource(Integer year, Integer pageNo, Integer pageSize, String uid) {
		Map<String, Object> params = new HashMap<>();
		
		if (!StringUtils.isBlank(uid)){
			params.put("uid", uid);
		}
		
		if (null != year){
			params.put("year", year);
		}

		if (pageNo == null || pageNo < 0) {
			pageNo = 1;
		}

		if (pageSize == null || pageSize < 0) {
			pageSize = 10;
		}
		return  (Pagination<OrgHumanResource>)findPage("findOrgHumanResourceListByPage",
				"findOrgHumanResourceCount", params, pageNo, pageSize);
	}
	
	@Override
	public OrgHumanResource insert(OrgHumanResource orgHumanResource) {
		orgHumanResourceMapper.insert(orgHumanResource);
		return orgHumanResource;
	}

	@Override
	public int updateByPrimaryKeySelective(OrgHumanResource orgHumanResource) {
		return orgHumanResourceMapper.updateByPrimaryKeySelective(orgHumanResource);
	}

	@Override
	public int batchDeleteByPrimaryKey(List<String> id) {
		return orgHumanResourceMapper.batchDeleteByPrimaryKey(id);
	}

	@Override
	public OrgHumanResource selectOrgHumanResourceByUidAndYear(Integer year, String uid) {
		return orgHumanResourceMapper.selectOrgHumanResourceByUidAndYear(year, uid);
	}

	@Override
	public OrgHumanResource selectByPrimaryKey(String id) {
		return orgHumanResourceMapper.selectByPrimaryKey(id);
	}

}
