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.OrgFinanceService;
import com.goafanti.common.dao.OrgFinanceMapper;
import com.goafanti.common.model.OrgFinance;
import com.goafanti.core.mybatis.BaseMybatisDao;
import com.goafanti.core.mybatis.page.Pagination;
@Service
public class OrgFinanceServiceImpl  extends BaseMybatisDao<OrgFinanceMapper> implements OrgFinanceService {
	@Autowired
	private OrgFinanceMapper orgFinanceMapper;


	@Override
	public OrgFinance insert(OrgFinance orgFinance) {
		orgFinanceMapper.insert(orgFinance);
		return orgFinance;
	}

	@Override
	public int updateByPrimaryKeySelective(OrgFinance orgFinance) {
		return orgFinanceMapper.updateByPrimaryKeySelective(orgFinance);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Pagination<OrgFinance> listFinance(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<OrgFinance>)findPage("findOrgFinanceListByPage",
				"findOrgFinanceCount", params, pageNo, pageSize);
	}

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

	@Override
	public OrgFinance selectFinanceByUidAndYear(String uid, Integer year) {
		return orgFinanceMapper.selectFinanceByUidAndYear(uid, year);
	}

	@Override
	public OrgFinance selectByPrimaryKey(String id) {
		return orgFinanceMapper.selectByPrimaryKey(id);
	}
	
}
