package com.ssj.dao.sys.award.dao.impl;

import com.ssj.bean.award.dto.VipIntegralDto;
import com.ssj.dao.sys.award.dao.AwardQueryDao;
import com.ssj.framework.core.persistence.PagingHibernateJdbcDao;
import org.apache.commons.lang3.StringUtils;
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 AwardQueryDaoImpl implements AwardQueryDao {
	
	
	@Autowired
	private PagingHibernateJdbcDao dao;

	/**
	 * 
	 * 新版抽奖活动 
	 * 2020年5月27日10:28:11
	 * 
	 */
	
	@Override
	public Page<Map<String, Object>> findAwardMaterialBylist(Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT * from tb_award_material t WHERE t.status=1  ");
        if (searchParams.get("name") != null && !searchParams.get("name").equals("")) {
        	selSQL.append(" and  t.`name` LIKE  CONCAT(CONCAT('%',?,'%')) ");
        	queryParams.add(searchParams.get("name"));
        }
        if (searchParams.get("level") != null && !searchParams.get("level").equals("")) {
        	selSQL.append(" and  t.`level`=? ");
        	queryParams.add(searchParams.get("level"));
        }
        selSQL.append(" ORDER BY t.create_time desc ");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	
	@Override
	public Page<Map<String, Object>> findAwardActivityBylist(Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.*,m.unit_name,am1.`name` as level1_material_name,am2.`name` as level2_material_name,am3.`name` as level3_material_name from tb_award_activity t  ");
        selSQL.append(" LEFT JOIN fx_merchant m ON t.merchant_id=m.id ");
        selSQL.append(" LEFT JOIN tb_award_material am1 ON t.level1_material_id=am1.id ");
        selSQL.append(" LEFT JOIN tb_award_material am2 ON t.level2_material_id=am2.id ");
        selSQL.append(" LEFT JOIN tb_award_material am3 ON t.level3_material_id=am3.id ");
        selSQL.append("  WHERE 1=1  ");
        if (searchParams.get("status") != null && !searchParams.get("status").equals("")) {
        	String[] inList=searchParams.get("status").toString().split(";");
			selSQL.append(" AND  t.`status` IN  ('").append(String.join("','",inList)).append("')");
        }
        if (searchParams.get("merchantId") != null && !searchParams.get("merchantId").equals("")) {
        	String[] inList=searchParams.get("merchantId").toString().split(";");
			selSQL.append(" AND  t.`merchant_id` IN  ('").append(String.join("','",inList)).append("')");
        }
        if (searchParams.get("title") != null && !searchParams.get("title").equals("")) {
        	selSQL.append(" AND  t.`title` LIKE  CONCAT(CONCAT('%',?,'%')) ");
        	queryParams.add(searchParams.get("title"));
        }
        
        if (searchParams.get("startTime") != null && !searchParams.get("startTime").equals("")) {
        	selSQL.append(" AND  t.`create_time` >= ? ");
        	queryParams.add(searchParams.get("startTime"));
        }
        
        if (searchParams.get("endTime") != null && !searchParams.get("endTime").equals("")) {
        	selSQL.append(" AND  t.`create_time`<= ? ");
        	queryParams.add(searchParams.get("endTime"));
        }

        selSQL.append(" ORDER BY t.create_time desc ");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}


	@Override
	public Page<Map<String, Object>> findAwardGrantBylist(Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT * from (  ");
        
//	        selSQL.append(" SELECT t.*,fm.unit_name as fm_unit_name,tm.unit_name as tm_unit_name,am1.`name` as level1_material_name,am2.`name` as level2_material_name,am3.`name` as level3_material_name ,'1' as type  ");
//	        selSQL.append(" from tb_award_grant t   ");
//	        selSQL.append(" LEFT JOIN fx_merchant fm ON t.from_merchant_id=fm.id  ");
//	        selSQL.append("	LEFT JOIN fx_merchant tm ON t.to_merchant_id=tm.id ");
//	        selSQL.append(" LEFT JOIN tb_award_material am1 ON t.level1_material_id=am1.id ");
//	        selSQL.append(" LEFT JOIN tb_award_material am2 ON t.level2_material_id=am2.id ");
//	        selSQL.append(" LEFT JOIN tb_award_material am3 ON t.level3_material_id=am3.id ");
//	        selSQL.append("	WHERE 1=1 ");
//	        if (searchParams.get("merchantId") != null && !searchParams.get("merchantId").equals("")) {
//	        	String[] inList=searchParams.get("merchantId").toString().split(";");
//				selSQL.append(" AND t.from_merchant_id IN  ('").append(String.join("','",inList)).append("')");
//	        }
	        
//	        selSQL.append("	UNION ");
//	        
	        selSQL.append("	SELECT t.*,fm.unit_name as fm_unit_name,tm.port_num as tm_port_num,tm.unit_name as tm_unit_name,am1.`name` as level1_material_name,am2.`name` as level2_material_name,am3.`name` as level3_material_name ,'2' as type ");
	        selSQL.append("	from tb_award_grant t  ");
	        selSQL.append("	LEFT JOIN fx_merchant fm ON t.from_merchant_id=fm.id ");
	        selSQL.append("	LEFT JOIN fx_merchant tm ON t.to_merchant_id=tm.id ");
	        selSQL.append(" LEFT JOIN tb_award_material am1 ON t.level1_material_id=am1.id ");
	        selSQL.append(" LEFT JOIN tb_award_material am2 ON t.level2_material_id=am2.id ");
	        selSQL.append(" LEFT JOIN tb_award_material am3 ON t.level3_material_id=am3.id ");
	        selSQL.append("	WHERE 1=1 ");
	        if (searchParams.get("merchantId") != null && !searchParams.get("merchantId").equals("")) {
	        	String[] inList=searchParams.get("merchantId").toString().split(";");
				selSQL.append(" AND t.to_merchant_id IN  ('").append(String.join("','",inList)).append("')");
	        }

	        if (searchParams.get("status") != null && !searchParams.get("status").equals("")) {
	        	selSQL.append(" AND t.`status`=? ");
	        	queryParams.add(searchParams.get("status"));
	        }
	        
	        if (searchParams.get("ems") != null && searchParams.get("ems").equals("1")) {
	        	selSQL.append(" AND t.`ems_time` is not null ");
	        }
	        
	        if (searchParams.get("ems") != null && searchParams.get("ems").equals("2")) {
	        	selSQL.append(" AND t.`ems_time` is null ");
	        }
	        
	        if (searchParams.get("dingNumber") != null && !searchParams.get("dingNumber").equals("")) {
	        	selSQL.append(" AND t.`ding_number`  LIKE  CONCAT(CONCAT('%',?,'%')) ");
	        	queryParams.add(searchParams.get("dingNumber"));
	        }
	        
	        if (searchParams.get("emsNumber") != null && !searchParams.get("emsNumber").equals("")) {
	        	selSQL.append(" AND t.`ems_number`  LIKE  CONCAT(CONCAT('%',?,'%')) ");
	        	queryParams.add(searchParams.get("emsNumber"));
	        }
	        
	        if (searchParams.get("remarks") != null && !searchParams.get("remarks").equals("")) {
	        	selSQL.append(" AND t.`remarks`  LIKE  CONCAT(CONCAT('%',?,'%')) ");
	        	queryParams.add(searchParams.get("remarks"));
	        }
	        
	        if (searchParams.get("startTime") != null && !searchParams.get("startTime").equals("")) {
	        	selSQL.append(" AND TO_DAYS(t.`create_time`)<=TO_DAYS(?) ");
	        	queryParams.add(searchParams.get("startTime"));
	        }
	        if (searchParams.get("endTime") != null && !searchParams.get("endTime").equals("")) {
	        	selSQL.append(" AND TO_DAYS(t.`create_time`)<=TO_DAYS(?) ");
	        	queryParams.add(searchParams.get("endTime"));
	        }
	        
        selSQL.append("	) as tmp ORDER BY tmp.create_time desc ");
        
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	
	@Override
	public Page<Map<String, Object>> findAwardConsumeBylist(Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.*,fm.unit_name as fm_unit_name ,tm.unit_name as tm_unit_name,m.`name` as material_name,m.`level` as material_level   FROM `tb_award_consume` t   ");
        selSQL.append(" LEFT JOIN fx_merchant fm ON t.from_merchant_id=fm.id ");
        selSQL.append(" LEFT JOIN fx_merchant tm ON t.to_merchant_id=tm.id ");
        selSQL.append(" LEFT JOIN tb_award_material m ON t.award_material_id=m.id ");
        selSQL.append(" WHERE 1=1 ");
        
        if (searchParams.get("type") != null && !searchParams.get("type").equals("")) {
        	selSQL.append(" AND t.`type`=? ");
        	queryParams.add(searchParams.get("type"));
        }
        
        
        
        if (searchParams.get("type") != null && (searchParams.get("type").equals("2"))) {
        	
	        if (searchParams.get("merchantId") != null && !searchParams.get("merchantId").equals("")) {
	        	String[] inList=searchParams.get("merchantId").toString().split(";");
	        	selSQL.append(" AND ( ");
				selSQL.append(" 	t.`to_merchant_id` IN  ('").append(String.join("','",inList)).append("')");
				
				if (searchParams.get("isSSJ") != null && searchParams.get("isSSJ").equals("1")) {
					selSQL.append(" OR  t.`type`=6 ");
				}
				selSQL.append(" ) ");
	        }
	        
        }else {
        	
        	 if (searchParams.get("merchantId") != null && !searchParams.get("merchantId").equals("")) {
 	        	String[] inList=searchParams.get("merchantId").toString().split(";");
 	        	selSQL.append(" AND ( ");
 				selSQL.append(" 	t.`from_merchant_id` IN  ('").append(String.join("','",inList)).append("')");
 				
 				if (searchParams.get("isSSJ") != null && searchParams.get("isSSJ").equals("1")) {
 					selSQL.append(" OR  t.`type`=6 ");
 				}
 				selSQL.append(" ) ");
 	        }
        	 
        }
        
        
        
        
        if (searchParams.get("name") != null && !searchParams.get("name").equals("")) {
        	selSQL.append(" AND m.`name` LIKE  CONCAT(CONCAT('%',?,'%')) ");
        	queryParams.add(searchParams.get("name"));
        }
        if (searchParams.get("awardMaterialId") != null && !searchParams.get("awardMaterialId").equals("")) {
        	selSQL.append(" AND t.`award_material_id`=? ");
        	queryParams.add(searchParams.get("awardMaterialId"));
        }
     
        if (searchParams.get("startTime") != null && !searchParams.get("startTime").equals("")) {
        	selSQL.append(" AND TO_DAYS(t.`create_time`)<=TO_DAYS(?) ");
        	queryParams.add(searchParams.get("startTime"));
        }
        if (searchParams.get("endTime") != null && !searchParams.get("endTime").equals("")) {
        	selSQL.append(" AND TO_DAYS(t.`create_time`)<=TO_DAYS(?) ");
        	queryParams.add(searchParams.get("endTime"));
        }
        
        selSQL.append(" ORDER BY t.create_time desc ");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}


	@Override
	public Page<Map<String, Object>> findAwardConsumeByAwardMaterial(Map<String, Object> searchParams,Pageable pageable) {
		
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        
        selSQL.append("	SELECT t.*,fm.unit_name as fm_unit_name,tm.unit_name as tm_unit_name,am1.`name` as level1_material_name,am2.`name` as level2_material_name,am3.`name` as level3_material_name");
        if (searchParams.get("awardMaterialId") != null && !searchParams.get("awardMaterialId").equals("")) {
        	selSQL.append(",IF(t.level1_material_id=?,1,0) as type_1 ");
        	selSQL.append(",IF(t.level2_material_id=?,1,0)as type_2 ");
            selSQL.append(",IF(t.level3_material_id=?,1,0) as type_3 ");
            
            queryParams.add(searchParams.get("awardMaterialId"));
        	queryParams.add(searchParams.get("awardMaterialId"));
        	queryParams.add(searchParams.get("awardMaterialId"));
        }
        selSQL.append("	from tb_award_grant t  ");
        selSQL.append("	LEFT JOIN fx_merchant fm ON t.from_merchant_id=fm.id ");
        selSQL.append("	LEFT JOIN fx_merchant tm ON t.to_merchant_id=tm.id ");
        selSQL.append(" LEFT JOIN tb_award_material am1 ON t.level1_material_id=am1.id ");
        selSQL.append(" LEFT JOIN tb_award_material am2 ON t.level2_material_id=am2.id ");
        selSQL.append(" LEFT JOIN tb_award_material am3 ON t.level3_material_id=am3.id ");
        selSQL.append("	WHERE 1=1 ");
        if (searchParams.get("status") != null && !searchParams.get("status").equals("")) {
        	String[] inList=searchParams.get("status").toString().split(";");
			selSQL.append(" AND  t.`status` IN  ('").append(String.join("','",inList)).append("')");
        }
        if (searchParams.get("merchantId") != null && !searchParams.get("merchantId").equals("")) {
        	String[] inList=searchParams.get("merchantId").toString().split(";");
			selSQL.append(" AND t.to_merchant_id IN  ('").append(String.join("','",inList)).append("')");
        }
        
        if (searchParams.get("awardMaterialId") != null && !searchParams.get("awardMaterialId").equals("")) {
        	selSQL.append(" AND ( t.`level1_material_id`=? or t.`level2_material_id`=? or t.`level3_material_id`=? ) ");
        	queryParams.add(searchParams.get("awardMaterialId"));
        	queryParams.add(searchParams.get("awardMaterialId"));
        	queryParams.add(searchParams.get("awardMaterialId"));
        }
        if (searchParams.get("startTime") != null && !searchParams.get("startTime").equals("")) {
        	selSQL.append(" AND  TO_DAYS(t.`create_time`) >= TO_DAYS(?) ");
        	queryParams.add(searchParams.get("startTime"));
        }
        if (searchParams.get("endTime") != null && !searchParams.get("endTime").equals("")) {
        	selSQL.append(" AND  TO_DAYS(t.`create_time`) <= TO_DAYS(?) ");
        	queryParams.add(searchParams.get("endTime"));
        }
        selSQL.append("	 ORDER BY t.create_time desc ");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}


	@Override
	public Page<Map<String, Object>> findAwardSncodeBylist(Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.*,a.title,fm.unit_name,m.`name`,m.`level`,v.parent_name,v.child_name from tb_award_sncode t   ");
        selSQL.append("	LEFT JOIN tb_award_activity a ON t.award_activity_id=a.id ");
        selSQL.append(" LEFT JOIN fx_merchant fm ON fm.id=a.merchant_id ");
        selSQL.append(" LEFT JOIN tb_award_material m ON t.award_material_id=m.id ");
        selSQL.append(" LEFT JOIN tb_lib_vip v ON t.vip_id=v.id ");
        selSQL.append(" WHERE t.`status`!=4 ");
        if (searchParams.get("awardActivityId") != null && !searchParams.get("awardActivityId").equals("")) {
        	selSQL.append(" AND  t.`award_activity_id`=? ");
        	queryParams.add(searchParams.get("awardActivityId"));
        }
        if (searchParams.get("awardMaterialId") != null && !searchParams.get("awardMaterialId").equals("")) {
        	selSQL.append(" AND  t.`award_material_id`=? ");
        	queryParams.add(searchParams.get("awardMaterialId"));
        }
        if (searchParams.get("merchantId") != null && !searchParams.get("merchantId").equals("")) {
        	String[] inList=searchParams.get("merchantId").toString().split(";");
			selSQL.append(" AND a.merchant_id IN  ('").append(String.join("','",inList)).append("')");
        }
        if (searchParams.get("snCode") != null && !searchParams.get("snCode").equals("")) {
        	selSQL.append(" AND  t.`sn_code`=? ");
        	queryParams.add(searchParams.get("snCode"));
        }
        if (searchParams.get("name") != null && !searchParams.get("name").equals("")) {
        	selSQL.append(" AND  v.`child_name` LIKE  CONCAT(CONCAT('%',?,'%')) ");
        	queryParams.add(searchParams.get("name"));
        }
        if (searchParams.get("level") != null && !searchParams.get("level").equals("")) {
        	selSQL.append(" AND  m.`level`=? ");
        	queryParams.add(searchParams.get("level"));
        }
        
        if (searchParams.get("status") != null && !searchParams.get("status").equals("")) {
        	selSQL.append(" AND  m.`status`=? ");
        	queryParams.add(searchParams.get("status"));
        }
        if (searchParams.get("startTime") != null && !searchParams.get("startTime").equals("")) {
        	selSQL.append(" AND  TO_DAYS(t.`update_time`) >= TO_DAYS(?) ");
        	queryParams.add(searchParams.get("startTime"));
        }
        if (searchParams.get("endTime") != null && !searchParams.get("endTime").equals("")) {
        	selSQL.append(" AND  TO_DAYS(t.`update_time`) <= TO_DAYS(?) ");
        	queryParams.add(searchParams.get("endTime"));
        }
        selSQL.append(" ORDER BY t.update_time DESC ");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}


	@Override
	public Page<Map<String, Object>> findAwardStockBylist(Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.*,m.unit_name,a.`name`,a.`level`,a.exchange_integral,a.img from tb_award_stock t  ");
        selSQL.append(" LEFT JOIN fx_merchant m ON t.merchant_id=m.id ");
        selSQL.append(" LEFT JOIN tb_award_material a ON t.award_material_id=a.id ");
        selSQL.append(" where 1=1 ");
        if (searchParams.get("merchantId") != null && !searchParams.get("merchantId").equals("")) {
        	String[] inList=searchParams.get("merchantId").toString().split(";");
			selSQL.append(" AND t.merchant_id IN  ('").append(String.join("','",inList)).append("')");
        }
        if (searchParams.get("level") != null && !searchParams.get("level").equals("")) {
			selSQL.append(" AND a.`level`=? ");
			queryParams.add(searchParams.get("level"));
        }
        if (searchParams.get("name") != null && !searchParams.get("name").equals("")) {
			selSQL.append(" AND a.`name` LIKE  CONCAT(CONCAT('%',?,'%')) ");
			queryParams.add(searchParams.get("name"));
        }
        selSQL.append(" ORDER BY a.`level` ASC ");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}


	@Override
	public Page<Map<String, Object>> findAwardSncodeByVipList(Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append(" SELECT t.*,j.league_name,j.league_address,am.`name`,am.img,am.`level` from tb_award_sncode t   ");
        selSQL.append(" LEFT JOIN tb_award_material am ON t.award_material_id=am.id ");
        selSQL.append(" LEFT JOIN tb_award_activity a ON t.award_activity_id=a.id ");
        selSQL.append(" LEFT JOIN fx_merchant m ON m.id=a.merchant_id ");
        selSQL.append(" LEFT JOIN tb_lib_join j ON t.lib_id=j.id ");
        selSQL.append(" where 1=1 ");
        if (searchParams.get("vipId") != null && !searchParams.get("vipId").equals("")) {
			selSQL.append(" AND t.`vip_id`=? ");
			queryParams.add(searchParams.get("vipId"));
        }
        selSQL.append(" ORDER BY t.draw_time desc ");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}

	@Override
	public Page<VipIntegralDto> userIntegralList(Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
		List<Object> queryParams = new ArrayList<Object>();
		selSQL.append(" SELECT t.title,t.type,t.integral,DATE_FORMAT(t.create_time,'%Y.%m.%d %H:%i') as create_time from scon_integral_detail t   ");
		selSQL.append(" where  t.`vip_id`=?  order by t.create_time desc ");
		queryParams.add(searchParams.get("vipId"));
		return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable,VipIntegralDto.class);
	}

	@Override
	public List<Map<String, Object>> getAwardActivityMapByMerchantId(String merchantId, Integer status) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append("  SELECT t.*,  ");
        selSQL.append("  m1.`name` as level1_material_name ,m1.img as level1_material_img,m1.`level` as level1_material_level,m1.exchange_integral as level1_material_exchange_integral,m1.price as level1_material_price,    ");
        selSQL.append("  m2.`name` as level2_material_name ,m2.img as level2_material_img,m2.`level` as level2_material_level,m2.exchange_integral as level2_material_exchange_integral,m2.price as level2_material_price,    ");
        selSQL.append("  m3.`name` as level3_material_name ,m3.img as level3_material_img,m1.`level` as level3_material_level,m3.exchange_integral as level3_material_exchange_integral,m3.price as level3_material_price  ");
        selSQL.append(" from tb_award_activity t  ");
        selSQL.append("  LEFT JOIN tb_award_material m1 ON t.level1_material_id=m1.id ");
        selSQL.append("  LEFT JOIN tb_award_material m2 ON t.level2_material_id=m2.id  ");
        selSQL.append("  LEFT JOIN tb_award_material m3 ON t.level3_material_id=m3.id  ");
        selSQL.append(" WHERE  1=1  ");
        if (StringUtils.isNotEmpty(merchantId)) {
        	selSQL.append(" AND t.merchant_id=?  ");
        	queryParams.add(merchantId);
        }
        if (status!=null) {
        	selSQL.append(" AND t.status=?  ");
        	queryParams.add(status);
        }
        selSQL.append(" LIMIT 1  ");
    	return dao.findMap(selSQL.toString(), queryParams.toArray());
	}


	@Override
	public Page<Map<String, Object>> findAwardActivityLogBylist(Map<String, Object> searchParams, Pageable pageable) {
		StringBuilder selSQL = new StringBuilder();
        List<Object> queryParams = new ArrayList<Object>();
        selSQL.append("  SELECT t.*,a.title,m.`name`,m.`level`,u.wx_name,u.photo,v.parent_name,v.child_name,s.`status` as sstatus from tb_award_activity_log t   ");
        selSQL.append("  LEFT JOIN tb_award_activity a on t.award_activity_id=a.id ");
        selSQL.append("  LEFT JOIN tb_award_material m ON t.award_material_id=m.id ");
        selSQL.append("  LEFT JOIN tb_user u ON t.user_id=u.id ");
        selSQL.append("  LEFT JOIN tb_lib_vip v ON t.vip_id=v.id ");
        selSQL.append("  LEFT JOIN tb_award_sncode s ON t.sn_code=s.sn_code ");
        selSQL.append(" WHERE  1=1  ");
        if (searchParams.get("id") != null && !searchParams.get("id").equals("")) {
   			selSQL.append(" AND t.award_activity_id=? ");
   			queryParams.add(searchParams.get("id"));
        }
        if (searchParams.get("name") != null && !searchParams.get("name").equals("")) {
        	selSQL.append(" AND ( ");
			selSQL.append("    v.parent_name LIKE CONCAT(CONCAT('%',?,'%')) ");
			selSQL.append(" OR v.child_name LIKE  CONCAT(CONCAT('%',?,'%'))");
			selSQL.append(" ) ");
			queryParams.add(searchParams.get("name"));
			queryParams.add(searchParams.get("name"));
	    }
        
        if (searchParams.get("level") != null && !searchParams.get("level").equals("")) {
			selSQL.append(" AND m.`level`=? ");
			queryParams.add(searchParams.get("level"));
        }
        
        if (searchParams.get("sncode") != null && !searchParams.get("sncode").equals("")) {
 			selSQL.append(" AND t.`sncode`=? ");
 			queryParams.add(searchParams.get("sncode"));
         }
        
        if (searchParams.get("startTime") != null && !searchParams.get("startTime").equals("")) {
        	selSQL.append(" AND  TO_DAYS(t.`create_time`) >= TO_DAYS(?) ");
        	queryParams.add(searchParams.get("startTime"));
        }
        if (searchParams.get("endTime") != null && !searchParams.get("endTime").equals("")) {
        	selSQL.append(" AND  TO_DAYS(t.`create_time`) <= TO_DAYS(?) ");
        	queryParams.add(searchParams.get("endTime"));
        }
        selSQL.append(" ORDER BY t.create_time desc ");
        return dao.findPage(selSQL.toString(), queryParams.toArray(), pageable);
	}


}
