package cn.hmsoft.hmplatform.project.data.dao;

import org.springframework.stereotype.Repository;

import cn.hmsoft.helper.StringHelper;
import cn.hmsoft.hmplatform.project.data.model.PProject;
import cn.hmsoft.jdbc.core.PlatformDaoSupport;
import cn.hmsoft.jdbc.entity.Pager;
import cn.hmsoft.jdbc.entity.QueryOrder;

@Repository
public class PProjectDao extends PlatformDaoSupport<PProject> {

	public Pager pageProject(Integer school_id, Integer start, Integer limit, String query, 
			QueryOrder queryOrder) {
		StringBuilder sql = new StringBuilder();
		sql.append("select p.*,s.school_name,s.school_code from p_project p left join p_school s on p.school_id=s.school_id  ");
		sql.append("where 1=1 ");
		if (school_id != null) {
			sql.append(" and p.school_id=").append(school_id);
		}
		if (StringHelper.isEmpty(query)) {
			return this.pageMapBySql(queryOrder, start, limit, sql.toString());
		}
		sql.append(" and (s.school_code = ? or p.manager like ? or s.school_name like ?)");
		return this.pageMapBySql(queryOrder, start, limit, sql.toString(), query, "%" + query + "%", "%" + query + "%");
	}

}
