ITrip项目(8)酒店后台查询

169 阅读1分钟

cityselect.js\color{green}{cityselect.js}

(function () {
    /*******************获取所有城市信息******************************************/
    /* 所有城市数据,可以按照格式自行添加(北京|beijing|bj),前16条为热门城市 */
    var cityids=[];
    var citynames=[];

    $.getJSON('http://localhost:9003/findAll_ItripAreaDic.do?t='+new Date().getTime(),function(cityAreaDiclist){
        //alert(cityAreaDiclist.length);
        //获取所有的城市id,给城市cityids数组赋值
        for (var n=0;n<cityAreaDiclist.length;n++){
            var cityAreaDic=cityAreaDiclist[n];
            cityids.push(cityAreaDic.id);
        }

        //获取所有的城市名称和拼音,给城市cityids数组赋值
        for (var m=0;m<cityAreaDiclist.length;m++){
            var cityAreaDic=cityAreaDiclist[m];
            //获取全拼
	        var qp=Pinyin.GetQP(cityAreaDic.name);
	        //alert(qp);
	        //获取简拼
	        var jp=Pinyin.GetJP(cityAreaDic.name);
			//alert(jp);


            citynames.push(cityAreaDic.name+'|'+qp+"|"+jp);
        }
        //alert(citynames.length);
        Vcity.allCity =citynames;
        //alert(Vcity.allCity);
        /* *
         * 格式化城市数组为对象oCity,按照a-h,i-p,q-z,hot热门城市分组:
         * {HOT:{hot:[]},ABCDEFGH:{a:[1,2,3],b:[1,2,3]},IJKLMNOP:{i:[1.2.3],j:[1,2,3]},QRSTUVWXYZ:{}}
         * */
        var citys = Vcity.allCity, match, letter,
            regEx = Vcity.regEx,
            reg2 = /^[a-b]$/i, reg3 = /^[c-d]$/i, reg4 = /^[e-g]$/i,reg5 = /^[h]$/i,reg6 = /^[j]$/i,reg7 = 
            /^[k-l]$/i,reg8 =  /^[m-p]$/i,reg9 =  /^[q-r]$/i,reg10 =  /^[s]$/i,reg11 =  /^[t]$/i,
            reg12 =  /^[w]$/i,reg13 =  /^[x]$/i,reg14 =  /^[y]$/i,reg15 =  /^[z]$/i;

        if (!Vcity.oCity) {
            Vcity.oCity = {hot:{},AB:{},CD:{},EFG:{},H:{},J:{},KL:{},MNP:{},QR:{},S:{},T:{},W:{},X:{},Y:{},Z:{}};


                /* 热门城市 前16条 */
                if(i<16){
                    if(!Vcity.oCity.hot['hot']) Vcity.oCity.hot['hot'] = [];
                    Vcity.oCity.hot['hot'].push(match[1]);
                }
                //alert(Vcity.oCity);
            }

        }

    });

2、在trvernlist.html\color{green}{trvernlist.html} 页面设置目的地字段名

<div class="search-title">
               目的地:<input id="tavernCitySelect1" value="北京市" placeholder="请选择目的地">
               入住: <input type="text" placeholder="2016-12-08"
                          onfocus="WdatePicker({doubleCalendar:true,dateFmt:'yyyy-MM-dd',position:{left:-48,top:17}})">
               退房:<input type="text" placeholder="2016-12-20"
                         onfocus="WdatePicker({doubleCalendar:true,dateFmt:'yyyy-MM-dd',position:{left:-130,top:17}})">
               关键词:<input id="seacherkeyword">
               <button id="btseacher" class="btn btn-default" style="font-size: 14px">搜索</button>
           </div>

3、在trvernlist.js\color{green}{trvernlist.js} 里编写点击搜索事件

/***********点击搜索的事件************/
$(function(){
	$("#btseacher").click(function(){
		var cityName=$("#tavernCitySelect1").val();
		var keyword=$("#seacherkeyword").val();
		//alert(cityName);
		//alert(keyword);
		jsondata={'redundantCityName':cityName,'hotelName':keyword};
		// $.post('http://localhost:9003/queryPageAll_Hotel.do',jsondata,function(map){
		//
		// });
		showAll(jsondata);
	});

3、更新HotelSolrBizImg.java里的方法

package com.zhaolong.biz.imp;
import ...

@Service
public class HotelSolrBizImg implements HotelSolrBiz {
   @Autowired
   private SolrClient solrClient;

   public SolrClient getSolrClient() {
   	return solrClient;
   }

   public void setSolrClient(SolrClient solrClient) {
   	this.solrClient = solrClient;
   }
   @Override
   public List<ItripHotelVO> queryPageAll(Integer page, Integer rows, ItripHotelVO hotelVO) {
   	System.out.println("hotelVO-->"+hotelVO);
   	//List<Hotel> hotelList=new ArrayList<Hotel>();
   	//创建Solr的查询对象
   	SolrQuery solrQuery=new SolrQuery();

   	solrQuery.set("q", "*:*");
   	String str="";
   	if(hotelVO!=null){
   		if(hotelVO.getRedundantCityName()!=null&&!hotelVO.getRedundantCityName().trim().equals("")){
   			str+="destination:"+hotelVO.getRedundantCityName();//按照目的地查询
   			//solrQuery.set("q","destination:"+hotelVO.getRedundantCityName());
   		}

   		if(hotelVO.getHotelName()!=null&&!hotelVO.getHotelName().trim().equals("")){
   			//solrQuery.add("keyword",hotelVO.getHotelName());
   			str+=" and "+"keyword:"+hotelVO.getHotelName();//按照关键字查询

   		}


   	}

   	if(str!=null&&!str.equals("")){
   		solrQuery.set("q",str);
   	}

   	//设置分页显示
   	solrQuery.setStart((page-1)*rows);//从第几条记录开始
   	solrQuery.setRows(rows);//每页显示的记录数
   	//设置排序
   	solrQuery.setSort("id", SolrQuery.ORDER.asc);//按照id升序排列
   	try {
   		//QueryResponse表示查询响应的结果集合
   		QueryResponse response=solrClient.query(solrQuery);//执行查询
   		List<ItripHotelVO> hotelList=response.getBeans(ItripHotelVO.class);
   		return hotelList;
   	} catch (SolrServerException e) {
   		e.printStackTrace();
   	} catch (IOException e) {
   		e.printStackTrace();
   	}

   	return null;
   }



   @Override
   public int findMaxPage(Integer rows, ItripHotelVO hotelVO) {
   	Long maxrow=0L;
   	int maxpage=1;
   	//创建Solr的查询对象
   	SolrQuery solrQuery=new SolrQuery();

   	solrQuery.set("q", "*:*");

   	String str="";
   	if(hotelVO!=null){
   		if(hotelVO.getRedundantCityName()!=null&&!hotelVO.getRedundantCityName().trim().equals("")){
   			str+="destination:"+hotelVO.getRedundantCityName();//按照目的地查询
   			//solrQuery.set("q","destination:"+hotelVO.getRedundantCityName());
   		}

   		if(hotelVO.getHotelName()!=null&&!hotelVO.getHotelName().trim().equals("")){
   			//solrQuery.add("keyword",hotelVO.getHotelName());
   			str+=" and "+"keyword:"+hotelVO.getHotelName();//按照关键字查询

   		}
   		//solrQuery.set("q",str);

   	}
   	if(str!=null&&!str.equals("")){
   		solrQuery.set("q",str);
   	}
   	try {
   		QueryResponse response=solrClient.query(solrQuery);
   		//通过solr文档对象获取找到的总记录数
   		maxrow=response.getResults().getNumFound();
   		System.out.println("maxrow-->"+maxrow);
   		//List<ItripHotelVO> hotelList=response.getBeans(ItripHotelVO.class);
   		//System.out.println("hotelList.size()-->"+hotelList.size());
   		//maxrow=(long)hotelList.size();//获取总记录数

   		if(maxrow>0){
   			maxpage=(int)(maxrow%rows==0?maxrow/rows:maxrow/rows+1);
   			return maxpage;
   		}

   	} catch (SolrServerException e) {
   		e.printStackTrace();
   	} catch (IOException e) {
   		e.printStackTrace();
   	}
   	System.out.println("maxpage--->"+maxpage);
   	return maxpage;
   }
}