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.OrgStandardService;
import com.goafanti.common.dao.OrgStandardMapper;
import com.goafanti.common.model.OrgStandard;
import com.goafanti.core.mybatis.BaseMybatisDao;
import com.goafanti.core.mybatis.page.Pagination;

@Service
public class OrgStandardServiceImpl extends BaseMybatisDao<OrgStandardMapper> implements OrgStandardService {
	@Autowired
	private OrgStandardMapper orgStandardMapper;

	@Override
	public OrgStandard insert(OrgStandard orgStandard) {
		orgStandardMapper.insert(orgStandard);
		return orgStandard;
	}

	@Override
	public int updateByPrimaryKeySelective(OrgStandard orgStandard) {
		return orgStandardMapper.updateByPrimaryKeySelective(orgStandard);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Pagination<OrgStandard> listOrgStandard(Integer year, String standardName, String standardNumber, Integer standardLevel,
			Integer participateWay, Integer pageNo, Integer pageSize, String uid) {
		Map<String, Object> params = new HashMap<>();
		
		if (null != year){
			params.put("year", year);
		}
		
		if (!StringUtils.isBlank(uid)){
			params.put("uid", uid);
		}
		
		if (!StringUtils.isBlank(standardName)){
			params.put("standardName", standardName);
		}
		
		if (!StringUtils.isBlank(standardNumber)){
			params.put("standardNumber", standardNumber);
		}
		
		if (null != standardLevel){
			params.put("standardLevel", standardLevel);
		}
		
		if (null != participateWay){
			params.put("participateWay", participateWay);
		}
		
		if (pageNo == null || pageNo < 0) {
			pageNo = 1;
		}

		if (pageSize == null || pageSize < 0) {
			pageSize = 10;
		}
		return (Pagination<OrgStandard>) findPage("findOrgStandardListByPage", "findOrgStandardCount", params, pageNo,
				pageSize);
	}

	@Override
	public int delete(String id) {
		return orgStandardMapper.deleteByPrimaryKey(id);
	}

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

	@Override
	public OrgStandard selectByPrimaryKey(String id) {
		return orgStandardMapper.selectByPrimaryKey(id);
	}
}
