package com.ssj.dao.weixin.problem.dao.impl;

import com.ssj.bean.sys.fx.domain.MerchantOut;
import com.ssj.dao.weixin.problem.dao.ProblemQueryDao;
import com.ssj.framework.core.persistence.PagingHibernateJdbcDao;
import com.ssj.framework.core.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Repository
public class ProblemQueryDaoImpl implements ProblemQueryDao{
	@Autowired
	private PagingHibernateJdbcDao dao;

	@Override
	public Page<Map<String, Object>> findForPage(
			Map<String, Object> searchParams, Pageable pageable) {
		 StringBuilder selSQL = new StringBuilder();
	        List<Object> queryParams = new ArrayList<Object>();
	        selSQL.append(" SELECT * FROM tb_lib_problem ");
	        selSQL.append(" WHERE 1=1");
	        if (searchParams.get("title") != null && !searchParams.get("title").equals("")) {
	        	selSQL.append("  and    title LIKE  CONCAT(CONCAT('%',?,'%'))  ");
	        	queryParams.add(searchParams.get("title"));
	        }
	        if (searchParams.get("type") != null && !searchParams.get("type").equals("")) {
	        	selSQL.append("  and    type LIKE  CONCAT(CONCAT('%',?,'%'))  ");
	        	queryParams.add(searchParams.get("type"));
	        }
	        if (searchParams.get("stat") != null && !searchParams.get("stat").equals("")) {
	        	selSQL.append("  and    stat LIKE  CONCAT(CONCAT('%',?,'%'))  ");
	        	queryParams.add(searchParams.get("stat"));
	        }
	        selSQL.append("  ORDER BY num");
	        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Page<Map<String, Object>> findForExpPage(
			Map<String, Object> searchParams, Pageable pageable) {
		 StringBuilder selSQL = new StringBuilder();
	        List<Object> queryParams = new ArrayList<Object>();
	        selSQL.append(" SELECT * FROM tb_experience ");
	        selSQL.append(" WHERE 1=1");
	        if (searchParams.get("name") != null && !searchParams.get("name").equals("")) {
	        	selSQL.append("  and    name LIKE  CONCAT(CONCAT('%',?,'%'))  ");
	        	queryParams.add(searchParams.get("name"));
	       }
	        if (searchParams.get("grade") != null && !searchParams.get("grade").equals("")) {
	        	selSQL.append("  and    grade LIKE  CONCAT(CONCAT('%',?,'%'))  ");
	        	queryParams.add(searchParams.get("grade"));
	       }
	        if (searchParams.get("type") != null && !searchParams.get("type").equals("")) {
	        	selSQL.append("  and    type LIKE  CONCAT(CONCAT('%',?,'%'))  ");
	        	queryParams.add(searchParams.get("type"));
	       }
	        if (searchParams.get("beginDate") != null && !searchParams.get("beginDate").equals("")) {
	        	selSQL.append(" and TO_DAYS(date_time) >=TO_DAYS(?) ");
	        	queryParams.add(searchParams.get("beginDate"));
	        }
	        if (searchParams.get("endDate") != null && !searchParams.get("endDate").equals("")) {
	        	selSQL.append(" and TO_DAYS(date_time) <=TO_DAYS(?) ");
	        	queryParams.add(searchParams.get("endDate"));
	        }
	        selSQL.append("  ORDER BY date_time desc ");
	        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public List<Map<String, Object>> getExpList(Map<String, Object> searchParams) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT name,grade,phone,type,course,DATE_FORMAT(date_time,'%Y-%m-%d %H:%i:%s')as sj,library,source, ");
        selSQL.append(" CASE  when type = 1 THEN '0元阅读' ");
        selSQL.append(" WHEN type = 2 THEN '0元试听课' END AS stat, ");
        selSQL.append(" CASE  when source = 1 THEN '官网' ");
        selSQL.append(" ELSE '微信' END AS ly ");
        selSQL.append(" FROM tb_experience ");
        selSQL.append(" WHERE 1=1");
        if (searchParams.get("name") != null && !searchParams.get("name").equals("")) {
        	selSQL.append("  and    name LIKE  CONCAT(CONCAT('%',?,'%'))  ");
        	queryParams.add(searchParams.get("name"));
       }
        if (searchParams.get("grade") != null && !searchParams.get("grade").equals("")) {
        	selSQL.append("  and    grade LIKE  CONCAT(CONCAT('%',?,'%'))  ");
        	queryParams.add(searchParams.get("grade"));
       }
        if (searchParams.get("type") != null && !searchParams.get("type").equals("")) {
        	selSQL.append("  and    type LIKE  CONCAT(CONCAT('%',?,'%'))  ");
        	queryParams.add(searchParams.get("type"));
       }
        if (searchParams.get("beginDate") != null && !searchParams.get("beginDate").equals("")) {
        	selSQL.append(" and TO_DAYS(date_time) >=TO_DAYS(?) ");
        	queryParams.add(searchParams.get("beginDate"));
        }
        if (searchParams.get("endDate") != null && !searchParams.get("endDate").equals("")) {
        	selSQL.append(" and TO_DAYS(date_time) <=TO_DAYS(?) ");
        	queryParams.add(searchParams.get("endDate"));
        }
        selSQL.append("  ORDER BY date_time desc ");
        return dao.findMap(selSQL.toString(), queryParams.toArray());
}

	@Override
	public Page<Map<String, Object>> findValidVipPage(
			Map<String, Object> searchParams, Pageable pageable) {
		 StringBuilder selSQL = new StringBuilder();
	        List<Object> queryParams = new ArrayList<Object>();
	        selSQL.append(" SELECT t.months, t.year_card,t.month_card,t.weekend_card,t.holiday,t.family,t.features, ");
	        selSQL.append(" t.taskyear_card,t.task_card,t.vip_total,t.half_card,j.league_name,case when t.type=1 then '截止到本月底' else '本月' END type ");
	        selSQL.append(" FROM tb_valid_vip t LEFT JOIN tb_lib_join j ON t.lib_id = j.id ");
	        
	        selSQL.append("  where   j.libtype=1  ");
	        
	        if (searchParams.get("orgCode") != null && !searchParams.get("orgCode").equals("")) {
	        	selSQL.append(" and  j.org_code in ( ");
	        	selSQL.append(searchParams.get("orgCode"));
	        	selSQL.append(" ) ");
	        }
	        
	        if (searchParams.get("months") != null && !searchParams.get("months").equals("")) {
	        	selSQL.append("  and    months LIKE  CONCAT(CONCAT('%',?,'%'))  ");
	        	queryParams.add(searchParams.get("months"));
	        }
	        if (searchParams.get("libId") != null && !searchParams.get("libId").equals("")) {
	        	selSQL.append(" and j.id = ? ");
	        	queryParams.add(searchParams.get("libId"));
	        }
	        if (searchParams.get("type") != null && !searchParams.get("type").equals("")) {
	        	selSQL.append(" and t.type = ? ");
	        	queryParams.add(searchParams.get("type"));
	        }
	        selSQL.append("  ORDER BY t.months ");
	        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public List<Map<String, Object>> getValidVipList(
			Map<String, Object> searchParams) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.months, t.year_card,t.month_card,t.weekend_card,t.holiday,t.family,t.features, ");
        selSQL.append(" t.taskyear_card,t.task_card,t.vip_total,t.half_card,j.league_name,case when t.type=1 then '截止到本月底' else '本月' END type ");
        selSQL.append(" FROM tb_valid_vip t LEFT JOIN tb_lib_join j ON t.lib_id = j.id ");
        selSQL.append("  where   j.libtype=1   ");
        
        if (searchParams.get("orgCode") != null && !searchParams.get("orgCode").equals("")) {
        	selSQL.append(" and  j.org_code in ( ");
        	selSQL.append(searchParams.get("orgCode"));
        	selSQL.append(" ) ");
        }
        
        if (searchParams.get("months") != null && !searchParams.get("months").equals("")) {
        	selSQL.append("  and    months LIKE  CONCAT(CONCAT('%',?,'%'))  ");
        	queryParams.add(searchParams.get("months"));
        }
        if (searchParams.get("libId") != null && !searchParams.get("libId").equals("")) {
        	selSQL.append(" and j.id = ? ");
        	queryParams.add(searchParams.get("libId"));
        }
        if (searchParams.get("type") != null && !searchParams.get("type").equals("")) {
        	selSQL.append(" and t.type = ? ");
        	queryParams.add(searchParams.get("type"));
        }
        selSQL.append("  ORDER BY t.months ");
        return dao.findMap(selSQL.toString(), queryParams.toArray());
}

	@Override
	public Page<Map<String, Object>> findCnAreaPage(
			Map<String, Object> searchParams, Pageable pageable) {
		 StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT a.*,b.name as area FROM sys_cn_area a");
		selSQL.append(" left join  sys_cn_area b on a.up_id=b.id and b.type=3");
		selSQL.append(" left join  sys_cn_area c on b.up_id=c.id and c.type=2");
		selSQL.append(" left join  sys_cn_area d on c.up_id=d.id and d.type=1");
		selSQL.append(" WHERE a.type='4' ");
		if (searchParams.get("name") != null && !searchParams.get("name").equals("")) {
			selSQL.append("  and    a.name LIKE  CONCAT(CONCAT('%',?,'%'))  ");
			queryParams.add(searchParams.get("name"));
		}
		if (searchParams.get("area") != null && !searchParams.get("area").equals("")) {
			selSQL.append("  and    a.up_id =?  ");
			queryParams.add(searchParams.get("area"));
		}else{
			if (searchParams.get("city") != null && !searchParams.get("city").equals("")) {
				selSQL.append("  and    b.up_id=? ");
				queryParams.add(searchParams.get("city"));
			}else{
				if (searchParams.get("province") != null && !searchParams.get("province").equals("")) {
					selSQL.append("  and    c.up_id =?  ");
					queryParams.add(searchParams.get("province"));
				}
			}
		}
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Page<Map<String, Object>> findRequestMethodLogPage(
			Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT	t.account_name,m.menu_name,t.method_url,t.org_code,t.create_time,IFNULL(j.league_name,'超级管理员')AS libname ");
        selSQL.append(" FROM request_method_log t LEFT JOIN sys_menu m ON t.method_url = m.menu_url ");
        selSQL.append(" LEFT JOIN tb_lib_join j on t.org_code=j.org_code ");
        selSQL.append(" where    m.type='2' ");
        
        if (searchParams.get("orgCode") != null && !searchParams.get("orgCode").equals("")) {
        	selSQL.append(" and  t.org_code in ( ");
        	selSQL.append(searchParams.get("orgCode"));
        	selSQL.append(" ) ");
        }
        
        if (searchParams.get("libId") != null && !searchParams.get("libId").equals("")) {
        	selSQL.append(" and j.id = ? ");
        	queryParams.add(searchParams.get("libId"));
        }
        selSQL.append("  ORDER BY t.create_time desc ");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
}

	@Override
	public Page<Map<String, Object>> findVipPage(
			Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT * FROM tb_lib_vip t WHERE t.user_id IS NOT NULL  ");
        if (searchParams.get("flow_id") != null && !searchParams.get("flow_id").equals("")) {
        	selSQL.append(" and t.flow_id = ? ");
        	queryParams.add(searchParams.get("flow_id"));
        }
        if (searchParams.get("child_name") != null && !searchParams.get("child_name").equals("")) {
        	selSQL.append(" and t.child_name LIKE  CONCAT(CONCAT('%',?,'%')) ");
        	queryParams.add(searchParams.get("child_name"));
        }
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
}

	@Override
	public Page<Map<String, Object>> findUpdateVipPage(
			Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT * FROM tb_lib_vip t WHERE t.user_id IS  NULL  ");
        if (searchParams.get("flow_id") != null && !searchParams.get("flow_id").equals("")) {
        	selSQL.append(" and t.flow_id = ? ");
        	queryParams.add(searchParams.get("flow_id"));
        }
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
}

	@Override
	public Page<Map<String, Object>> findBanbenDetailPage(Map<String, Object> params, Pageable initPage) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT * FROM sys_cn_school_detail ");
		selSQL.append(" WHERE 1=1");
		if (params.get("name") != null && !params.get("name").equals("")) {
			selSQL.append("  and    school_name LIKE  CONCAT(CONCAT('%',?,'%'))  ");
			queryParams.add(params.get("name"));
		}
		if (params.get("courseName") != null && !params.get("courseName").equals("")) {
			selSQL.append("  and    course_name =?  ");
			queryParams.add(params.get("courseName"));
		}
		if (params.get("grade") != null && !params.get("grade").equals("")) {
			selSQL.append("  and    grade =?  ");
			queryParams.add(params.get("grade"));
		}
		selSQL.append("  ORDER BY create_time desc ");
		return dao.findPage(selSQL.toString(), queryParams.toArray(), initPage);
	}

	@Override
	public List<Map<String, Object>> findCnAreaAll(Map<String, Object> searchParams) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT a.id,a.name,'学校' as type,a.py,case when a.is_hotcity=0 then '不是' else '是' end is_hotcity,a.school_address,a.school_lng,a.school_lat,b.name as area FROM sys_cn_area a");
		selSQL.append(" left join  sys_cn_area b on a.up_id=b.id and b.type=3");
		selSQL.append(" left join  sys_cn_area c on b.up_id=c.id and c.type=2");
		selSQL.append(" left join  sys_cn_area d on c.up_id=d.id and d.type=1");
		selSQL.append(" WHERE a.type='4' ");
		if (searchParams.get("name") != null && !searchParams.get("name").equals("")) {
			selSQL.append("  and    a.name LIKE  CONCAT(CONCAT('%',?,'%'))  ");
			queryParams.add(searchParams.get("name"));
		}
		if (searchParams.get("area") != null && !searchParams.get("area").equals("")) {
			selSQL.append("  and    a.up_id =?  ");
			queryParams.add(searchParams.get("area"));
		}else{
			if (searchParams.get("city") != null && !searchParams.get("city").equals("")) {
				selSQL.append("  and    b.up_id=? ");
				queryParams.add(searchParams.get("city"));
			}else{
				if (searchParams.get("province") != null && !searchParams.get("province").equals("")) {
					selSQL.append("  and    c.up_id =?  ");
					queryParams.add(searchParams.get("province"));
				}
			}
		}
		return dao.findMap(selSQL.toString(), queryParams.toArray());
	}

	@Override
	public Page<MerchantOut> findMerchantByPage(Map<String, Object> params, Pageable initPage) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT t11.*,t12.league_name from fx_merchant_area t ");
		selSQL.append(" left join fx_merchant t11 on t.merchant_id = t11.id \n");
		selSQL.append(" left join tb_lib_join t12 on t11.lib_id = t12.id \n");
		selSQL.append(" where t.cn_area_id = ? \n ");
		queryParams.add(params.get("schoolAreaId"));
		if(!StringUtil.isEmpty(params.get("LIKE_unitName"))){
			selSQL.append(" and t11.unit_name like concat('%',?,'%') \n ");
			queryParams.add(params.get("LIKE_unitName"));
		}

		if(!StringUtil.isEmpty(params.get("LIKE_posCode"))){
			selSQL.append(" and t11.pos_code like concat('%',?,'%') \n ");
			queryParams.add(params.get("LIKE_posCode"));
		}

		return dao.findPage(selSQL.toString(),queryParams.toArray(),initPage,MerchantOut.class);
	}

	@Override
	public Page<Map<String, Object>> findValidVip2Page(
			Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT a.league_name, a.lib_id,a.vip_total,b.family,a.year_card,a.halfyear_card,a.weekend_card,a.taskyear_card FROM  ");
        selSQL.append(" ( SELECT t.lib_id, COUNT(DISTINCT t.vip_id) AS vip_total,  ");
        selSQL.append(" sum( CASE WHEN t.species = 'S001' AND t.type = 'C003'  ");
        selSQL.append(" AND t.stat = '1' THEN 1 ELSE 0 END ) AS year_card,  ");
        selSQL.append(" sum( CASE WHEN t.species = 'S001' AND t.type = 'C002'  ");
        selSQL.append(" AND t.stat = '1' THEN 1 ELSE 0 END ) AS halfyear_card,  ");
        selSQL.append(" sum( CASE WHEN t.species = 'S003' AND t.type = 'C006'AND t.stat = '1' THEN  ");
        selSQL.append(" 1 ELSE 0 END ) AS taskyear_card,  ");
        selSQL.append(" sum( CASE WHEN t.species = 'S001'AND t.type = 'C007'AND t.stat = '1' THEN  ");
        selSQL.append(" 1 ELSE 0 END ) AS weekend_card ,j.league_name ");
        selSQL.append(" FROM tb_lib_vip_service t  ");
        selSQL.append(" LEFT JOIN tb_lib_join j on t.lib_id =j.id  ");
        selSQL.append(" WHERE t.stat = '1'  AND j.libtype <> '1'  ");
        if (searchParams.get("orgCode") != null && !searchParams.get("orgCode").equals("")) {
        	selSQL.append(" and  j.org_code in ( ");
        	selSQL.append(searchParams.get("orgCode"));
        	selSQL.append(" ) ");
        }
        if (searchParams.get("beginDate") != null && !searchParams.get("beginDate").equals("")) {
        	selSQL.append(" and TO_DAYS(t.start_time) >=TO_DAYS(?) ");
        	queryParams.add(searchParams.get("beginDate"));
        }
        if (searchParams.get("endDate") != null && !searchParams.get("endDate").equals("")) {
        	selSQL.append(" and TO_DAYS(t.start_time) <=TO_DAYS(?) ");
        	queryParams.add(searchParams.get("endDate"));
        }
        if (searchParams.get("libId") != null && !searchParams.get("libId").equals("")) {
        	selSQL.append(" and t.lib_id = ? ");
        	queryParams.add(searchParams.get("libId"));
        }
        selSQL.append(" GROUP BY t.lib_id ) AS a  ");
        selSQL.append(" LEFT JOIN (  ");
        selSQL.append(" SELECT count(DISTINCT v.user_id) AS family,  ");
        selSQL.append(" s.lib_id FROM tb_lib_vip_service s  ");
        selSQL.append(" LEFT JOIN tb_lib_vip v ON s.vip_id = v.id  ");
        selSQL.append(" LEFT JOIN tb_lib_join j on s.lib_id =j.id  ");
        selSQL.append(" WHERE s.stat = '1' AND j.libtype <> '1'  ");
        if (searchParams.get("orgCode") != null && !searchParams.get("orgCode").equals("")) {
        	selSQL.append(" and  j.org_code in ( ");
        	selSQL.append(searchParams.get("orgCode"));
        	selSQL.append(" ) ");
        }
        if (searchParams.get("beginDate") != null && !searchParams.get("beginDate").equals("")) {
        	selSQL.append(" and TO_DAYS(s.start_time) >=TO_DAYS(?) ");
        	queryParams.add(searchParams.get("beginDate"));
        }
        if (searchParams.get("endDate") != null && !searchParams.get("endDate").equals("")) {
        	selSQL.append(" and TO_DAYS(s.start_time) <=TO_DAYS(?) ");
        	queryParams.add(searchParams.get("endDate"));
        }
        if (searchParams.get("libId") != null && !searchParams.get("libId").equals("")) {
        	selSQL.append(" and s.lib_id = ? ");
        	queryParams.add(searchParams.get("libId"));
        }
        selSQL.append(" GROUP BY s.lib_id  ");
        selSQL.append(" ) b ON a.lib_id = b.lib_id  ");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
}

	@Override
	public List<Map<String, Object>> getValidVipList2(
			Map<String, Object> searchParams) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT a.league_name, a.lib_id,a.vip_total,b.family,a.year_card,a.weekend_card,a.taskyear_card FROM  ");
        selSQL.append(" ( SELECT t.lib_id, COUNT(DISTINCT t.vip_id) AS vip_total,  ");
        selSQL.append(" sum( CASE WHEN t.species = 'S001' AND t.type = 'C003'  ");
        selSQL.append(" AND t.stat = '1' THEN 1 ELSE 0 END ) AS year_card,  ");
        selSQL.append(" sum( CASE WHEN t.species = 'S003' AND t.type = 'C006'AND t.stat = '1' THEN  ");
        selSQL.append(" 1 ELSE 0 END ) AS taskyear_card,  ");
        selSQL.append(" sum( CASE WHEN t.species = 'S001'AND t.type = 'C007'AND t.stat = '1' THEN  ");
        selSQL.append(" 1 ELSE 0 END ) AS weekend_card ,j.league_name ");
        selSQL.append(" FROM tb_lib_vip_service t  ");
        selSQL.append(" LEFT JOIN tb_lib_join j on t.lib_id =j.id  ");
        selSQL.append(" WHERE t.stat = '1'  AND j.libtype <> '1'  ");
        if (searchParams.get("orgCode") != null && !searchParams.get("orgCode").equals("")) {
        	selSQL.append(" and  j.org_code in ( ");
        	selSQL.append(searchParams.get("orgCode"));
        	selSQL.append(" ) ");
        }
        if (searchParams.get("beginDate") != null && !searchParams.get("beginDate").equals("")) {
        	selSQL.append(" and TO_DAYS(t.start_time) >=TO_DAYS(?) ");
        	queryParams.add(searchParams.get("beginDate"));
        }
        if (searchParams.get("endDate") != null && !searchParams.get("endDate").equals("")) {
        	selSQL.append(" and TO_DAYS(t.start_time) <=TO_DAYS(?) ");
        	queryParams.add(searchParams.get("endDate"));
        }
        if (searchParams.get("libId") != null && !searchParams.get("libId").equals("")) {
        	selSQL.append(" and t.lib_id = ? ");
        	queryParams.add(searchParams.get("libId"));
        }
        selSQL.append(" GROUP BY t.lib_id ) AS a  ");
        selSQL.append(" LEFT JOIN (  ");
        selSQL.append(" SELECT count(DISTINCT v.user_id) AS family,  ");
        selSQL.append(" s.lib_id FROM tb_lib_vip_service s  ");
        selSQL.append(" LEFT JOIN tb_lib_vip v ON s.vip_id = v.id  ");
        selSQL.append(" LEFT JOIN tb_lib_join j on s.lib_id =j.id  ");
        selSQL.append(" WHERE s.stat = '1' AND j.libtype <> '1'  ");
        if (searchParams.get("orgCode") != null && !searchParams.get("orgCode").equals("")) {
        	selSQL.append(" and  j.org_code in ( ");
        	selSQL.append(searchParams.get("orgCode"));
        	selSQL.append(" ) ");
        }
        if (searchParams.get("beginDate") != null && !searchParams.get("beginDate").equals("")) {
        	selSQL.append(" and TO_DAYS(s.start_time) >=TO_DAYS(?) ");
        	queryParams.add(searchParams.get("beginDate"));
        }
        if (searchParams.get("endDate") != null && !searchParams.get("endDate").equals("")) {
        	selSQL.append(" and TO_DAYS(s.start_time) <=TO_DAYS(?) ");
        	queryParams.add(searchParams.get("endDate"));
        }
        if (searchParams.get("libId") != null && !searchParams.get("libId").equals("")) {
        	selSQL.append(" and s.lib_id = ? ");
        	queryParams.add(searchParams.get("libId"));
        }
        selSQL.append(" GROUP BY s.lib_id  ");
        selSQL.append(" ) b ON a.lib_id = b.lib_id  ");
        return dao.findMap(selSQL.toString(), queryParams.toArray());
}
}
