package cn.hmsoft.skill.data.dao.std;

import org.springframework.stereotype.Repository;
import cn.hmsoft.helper.StringHelper;
import cn.hmsoft.jdbc.core.PlatformDaoSupport;
import cn.hmsoft.jdbc.entity.Pager;
import cn.hmsoft.jdbc.entity.QueryOrder;
import cn.hmsoft.skill.data.model.std.StdAdmission;


@Repository
public class StdAdmissionDao extends PlatformDaoSupport<StdAdmission> {


	public Pager pageStdAdmission(String region, String nation, String department, String major, String sex,
			String filing_unit, String graduation_type, String examination_type, String batch, String families,
			String planning_nature,String isReported, Integer school_id, Integer start, Integer limit, String query,
			QueryOrder queryOrder) {
		StringBuilder sql = new StringBuilder("select s.* from std_admission s");
		sql.append(" where school_id='").append(school_id).append("'");
		
		if (region != null && !"".equals(region)) {
			sql.append(" and s.region='").append(region).append("'");
		}
		if (nation != null && !"".equals(nation)) {
			sql.append(" and s.nation='").append(nation).append("'");
		}
		if (department != null  && !"".equals(department)) {
			sql.append(" and s.department='").append(department).append("'");
		}
		if (major != null  && !"".equals(major)) {
			sql.append(" and s.major='").append(major).append("'");
		}
		if (sex != null   && !"".equals(sex)) {
			sql.append(" and s.sex='").append(sex).append("'");
		}
		if (filing_unit != null   && !"".equals(filing_unit)) {
			sql.append(" and s.filing_unit='").append(filing_unit).append("'");
		}
		if (graduation_type != null   && !"".equals(graduation_type)) {
			sql.append(" and s.graduation_type='").append(graduation_type).append("'");
		}
		if (examination_type != null  && !"".equals(examination_type)) {
			sql.append(" and s.examination_type='").append(examination_type).append("'");
		}
		if (batch != null  && !"".equals(batch)) {
			sql.append(" and s.batch='").append(batch).append("'");
		}
		if (families != null && !"".equals(families)) {
			sql.append(" and s.families='").append(families).append("'");
		}
		if (planning_nature != null && !"".equals(planning_nature)) {
			sql.append(" and s.planning_nature='").append(planning_nature).append("'");
		}
		if (isReported != null && !"".equals(isReported)) {
			sql.append(" and s.isReported = '").append(isReported).append("'");
		}
		if (StringHelper.isEmpty(query)) {
			return this.pageMapBySql(queryOrder, start, limit, sql.toString());
		}
		sql.append(" and (s.region=? or s.nation=? or s.sex=? or s.department=? or s.stu_name = ? or s.major=?)");
		String vQuery = this.generateLikeParamter(query);
		return this.pageMapBySql(queryOrder, start, limit, sql.toString(), query, query, query, query,query, vQuery);
	}
	

	/**
	 * 查看对应年份数据是否导入数据库
	 * @param notification_number
	 * @return
	 */
	public StdAdmission findByYear(String notification_number) {
		String year = notification_number.substring(0,4);
		return this.findBySql("select * from std_admission where substring(notification_number,1,4)=?", year);
	}
}
