package com.goafanti.cognizance.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.cognizance.service.OrgRatepayService;
import com.goafanti.common.dao.OrgRatepayMapper;
import com.goafanti.common.model.OrgRatepay;
import com.goafanti.core.mybatis.BaseMybatisDao;
import com.goafanti.core.mybatis.page.Pagination;
@Service
public class OrgRatepayServiceImpl extends BaseMybatisDao<OrgRatepayMapper> implements OrgRatepayService {
	@Autowired
	private OrgRatepayMapper orgRatepayMapper;
	

	@Override
	public OrgRatepay insert(OrgRatepay orgRatepay) {
		orgRatepayMapper.insert(orgRatepay);
		return orgRatepay;
	}

	@Override
	public int updateByPrimaryKeySelective(OrgRatepay orgRatepay) {
		return orgRatepayMapper.updateByPrimaryKeySelective(orgRatepay);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Pagination<OrgRatepay> listOrgRatepay(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<OrgRatepay>)findPage("findOrgRatepayListByPage",
				"findOrgRatepayCount", params, pageNo, pageSize);
	}

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

	@Override
	public OrgRatepay selectRatepayByUidAndYear(String uid, Integer year) {
		return orgRatepayMapper.selectRatepayByUidAndYear(uid, year);
	}

	@Override
	public OrgRatepay selectByPrimaryKey(String id) {
		return orgRatepayMapper.selectByPrimaryKey(id);
	}

}
