package cn.hmsoft.frame.data.dao;

import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import cn.hmsoft.frame.data.model.FrameDept;
import cn.hmsoft.jdbc.core.PlatformDaoSupport;
import cn.hmsoft.jdbc.entity.Pager;
import cn.hmsoft.jdbc.entity.QueryOrder;

@Repository
public class FrameDeptDao extends PlatformDaoSupport<FrameDept> {
	public Pager pageDept(Integer start, Integer limit, String query, QueryOrder order) {
		final StringBuilder sql = new StringBuilder();
		sql.append("select a.*,optr.optr_count from frame_dept a ");
		sql.append(
				"left join (select optr_dept,count(1) optr_count from frame_optr group by optr_dept) optr on a.dept_id=optr.optr_dept ");
		if (StringUtils.isEmpty(query)) {
			return this.pageBySql(order, start, limit, sql.toString());
		}
		sql.append(" where dept_name like ?");
		return super.pageBySql(order, start, limit, sql.toString(), "%" + query + "%");
	}
}
