package cn.hmsoft.frame.data.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import cn.hmsoft.frame.data.model.FrameReport;
import cn.hmsoft.frame.data.model.FrameReportDetail;
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 FrameReportDao extends PlatformDaoSupport<FrameReport> {

	public Pager pageReport(Integer start, Integer limit, String query, QueryOrder order) {
		String sql = "select f.*,res.res_name from frame_report f left join frame_res res on res.res_id=f.res_id where 1=1";
		if (StringHelper.isEmpty(query))
			return this.pageMapBySql(order, start, limit, sql);
		sql = sql + " and (report_name like ? )";
		return this.pageMapBySql(order, start, limit, sql, "%" + query + "%");
	}

	public List<FrameReportDetail> listDetail(String report_name) {
		String sql = "select * from frame_report_detail where report_name=? order by field_order";
		return this.listBySql(FrameReportDetail.class, sql, report_name);
	}
	
	public void deleteDetail(String report_name) {
		String sql = "delete from frame_report_detail where report_name=? ";
		this.updateBySql(sql, report_name);
	}

}
