package cn.hmsoft.frame.data.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.hmsoft.frame.data.model.FrameRes;
import cn.hmsoft.helper.StringHelper;
import cn.hmsoft.jdbc.core.PlatformDaoSupport;
import cn.hmsoft.jdbc.entity.Pager;
import cn.hmsoft.jdbc.entity.QueryOrder;

@Repository
public class FrameResDao extends PlatformDaoSupport<FrameRes>{


	public Pager pageRes(Integer start, Integer limit, String query, QueryOrder order) {
		String sql = "select * from frame_res where 1=1";
		if (StringHelper.isEmpty(query))
			return this.pageBySql(FrameRes.class, order, start, limit, sql);
		sql = sql + " and (res_name like ? or res_url like ? or res_desc like ?)";
		return this.pageBySql(FrameRes.class, order, start, limit, sql, "%" + query + "%", "%" + query + "%", "%" + query + "%");
	}
	
	public List<FrameRes> listRoleRes(int roleId) {
		if (roleId > 0) {
			String sql = "select r.* from frame_res r,frame_role_res rr where r.res_id=rr.res_id and rr.role_id=? order by r.res_level,r.res_order";
			return this.listBySql(sql, roleId);
		} else {
			String sql = "select * from frame_res r order by r.res_level,r.res_order";
			return this.listBySql(sql);
		}
	}
}
