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

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.school.SchoolReg;

@Repository
public class SchoolRegDao extends PlatformDaoSupport<SchoolReg> {

	/***********************
	 * 考点分页查询
	 */
	public Pager pageSchoolReg(Integer school_id, Integer start, Integer limit, String query, QueryOrder order) {
		StringBuilder sql = new StringBuilder("select ag.*,aspect_total from school_reg ag ");
		sql.append(" left join (select school_id,count(1) aspect_total from school_aspect group by school_id) ap on ap.school_id=ag.school_id");
		sql.append(" where ag.school_id=").append(school_id);
		if (StringHelper.isEmpty(query)) {
			return this.pageMapBySql(order, start, limit, sql.toString());
		}
		sql.append(" and (school_code = ? or school_name like ?)");
		return this.pageMapBySql(order, start, limit, sql.toString(), query, "%" + query + "%");
	}
	
	/***********************
	 * 考点分页查询
	 */
	public Pager pageAllSchoolReg(Integer start, Integer limit, QueryOrder order) {
		StringBuilder sql = new StringBuilder("select ag.*,aspect_total from school_reg ag ");
		sql.append(" left join (select school_id,count(1) aspect_total from school_aspect group by school_id) ap on ap.school_id=ag.school_id");
		return this.pageMapBySql(order, start, limit, sql.toString());
	}
}
