Merge branch 'feature_master_xh_standard' into 'master'
房源数据修改 See merge request !370
This commit is contained in:
@@ -0,0 +1,242 @@
|
||||
package com.fangjia.dal;
|
||||
import org.sothis.core.util.Pager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SeawaterQuery {
|
||||
|
||||
private String id;
|
||||
private String cat;
|
||||
private String region;
|
||||
private String districtName;
|
||||
private String cityDisplay;
|
||||
private Integer room;
|
||||
private String direction;
|
||||
private String fitment;
|
||||
private String sort;
|
||||
private Boolean order;
|
||||
private Integer StartDate;
|
||||
private Integer endDate;
|
||||
private String estateType;
|
||||
private Double startArea;
|
||||
private Double endArea;
|
||||
private Integer startPrice;
|
||||
private Integer endPrice;
|
||||
private Integer status;
|
||||
private String rootName;
|
||||
private String sortField;
|
||||
private List<String> regionAlias;
|
||||
private List<String> districtAlias;
|
||||
private String[] keys;
|
||||
private String table;
|
||||
private Pager pager;
|
||||
private String editEstateType;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getCat() {
|
||||
return cat;
|
||||
}
|
||||
|
||||
public void setCat(String cat) {
|
||||
this.cat = cat;
|
||||
}
|
||||
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setRegion(String region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public String getDistrictName() {
|
||||
return districtName;
|
||||
}
|
||||
|
||||
public void setDistrictName(String districtName) {
|
||||
this.districtName = districtName;
|
||||
}
|
||||
|
||||
public Integer getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
public void setRoom(Integer room) {
|
||||
this.room = room;
|
||||
}
|
||||
|
||||
public String getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection(String direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
public String getFitment() {
|
||||
return fitment;
|
||||
}
|
||||
|
||||
public void setFitment(String fitment) {
|
||||
this.fitment = fitment;
|
||||
}
|
||||
|
||||
public Boolean getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(Boolean order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public Integer getStartDate() {
|
||||
return StartDate;
|
||||
}
|
||||
|
||||
public void setStartDate(Integer startDate) {
|
||||
StartDate = startDate;
|
||||
}
|
||||
|
||||
public Integer getEndDate() {
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public void setEndDate(Integer endDate) {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public String getEstateType() {
|
||||
return estateType;
|
||||
}
|
||||
|
||||
public void setEstateType(String estateType) {
|
||||
this.estateType = estateType;
|
||||
}
|
||||
|
||||
public Integer getStartPrice() {
|
||||
return startPrice;
|
||||
}
|
||||
|
||||
public void setStartPrice(Integer startPrice) {
|
||||
this.startPrice = startPrice;
|
||||
}
|
||||
|
||||
public Integer getEndPrice() {
|
||||
return endPrice;
|
||||
}
|
||||
|
||||
public void setEndPrice(Integer endPrice) {
|
||||
this.endPrice = endPrice;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Integer status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getSortField() {
|
||||
return sortField;
|
||||
}
|
||||
|
||||
public void setSortField(String sortField) {
|
||||
this.sortField = sortField;
|
||||
}
|
||||
|
||||
public List<String> getRegionAlias() {
|
||||
return regionAlias;
|
||||
}
|
||||
|
||||
public void setRegionAlias(List<String> regionAlias) {
|
||||
this.regionAlias = regionAlias;
|
||||
}
|
||||
|
||||
public List<String> getDistrictAlias() {
|
||||
return districtAlias;
|
||||
}
|
||||
|
||||
public void setDistrictAlias(List<String> districtAlias) {
|
||||
this.districtAlias = districtAlias;
|
||||
}
|
||||
|
||||
public String[] getKeys() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
public void setKeys(String[] keys) {
|
||||
this.keys = keys;
|
||||
}
|
||||
|
||||
public String getTable() {
|
||||
return table;
|
||||
}
|
||||
|
||||
public void setTable(String table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
public String getRootName() {
|
||||
return rootName;
|
||||
}
|
||||
|
||||
public void setRootName(String rootName) {
|
||||
this.rootName = rootName;
|
||||
}
|
||||
|
||||
public Double getStartArea() {
|
||||
return startArea;
|
||||
}
|
||||
|
||||
public void setStartArea(Double startArea) {
|
||||
this.startArea = startArea;
|
||||
}
|
||||
|
||||
public Double getEndArea() {
|
||||
return endArea;
|
||||
}
|
||||
|
||||
public void setEndArea(Double endArea) {
|
||||
this.endArea = endArea;
|
||||
}
|
||||
|
||||
public Pager getPager() {
|
||||
return pager;
|
||||
}
|
||||
|
||||
public void setPager(Pager pager) {
|
||||
this.pager = pager;
|
||||
}
|
||||
|
||||
public String getSort() {
|
||||
return sort;
|
||||
}
|
||||
|
||||
public void setSort(String sort) {
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
public String getCityDisplay() {
|
||||
return cityDisplay;
|
||||
}
|
||||
|
||||
public void setCityDisplay(String cityDisplay) {
|
||||
this.cityDisplay = cityDisplay;
|
||||
}
|
||||
|
||||
public String getEditEstateType() {
|
||||
return editEstateType;
|
||||
}
|
||||
|
||||
public void setEditEstateType(String editEstateType) {
|
||||
this.editEstateType = editEstateType;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.fangjia.dal.seawater.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fangjia.dal.SeawaterQuery;
|
||||
import com.fangjia.dal.seawater.model.Seawater;
|
||||
|
||||
/**
|
||||
@@ -18,4 +19,12 @@ public interface SeawaterDao extends com.fangjia.dal.SeawaterDao<Seawater> {
|
||||
Double startArea, Double endArea, Integer startPrice, Integer endPrice, Integer room, String root, String sort, boolean order, int start, int limit , String table);
|
||||
|
||||
List<Seawater> findHouses(String city, String region, List<String> alias, Integer minPrice, Integer maxPrice, Integer limit);
|
||||
|
||||
List<Seawater> findSeawatersByQuery(SeawaterQuery query);
|
||||
|
||||
long findSeawatersCountByQuery(SeawaterQuery query);
|
||||
|
||||
void batchDeleteByParams(SeawaterQuery query);
|
||||
|
||||
void batchUpdateEstateType(SeawaterQuery query);
|
||||
}
|
||||
|
||||
+447
-16
@@ -2,6 +2,7 @@ package com.fangjia.dal.seawater.dao;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.fangjia.dal.SeawaterQuery;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
@@ -29,7 +30,12 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
@Override
|
||||
public Seawater findByIdFromEs(String id,String table) {
|
||||
Seawater seawater = null;
|
||||
List<JSONObject> jsonList = queryList(id,null,null,null,null,null,null,null,null, null, null, null, null, null,null,null,false,-1,-1,table);
|
||||
SeawaterQuery query = new SeawaterQuery();
|
||||
query.setId(id);
|
||||
query.setTable(table);
|
||||
query.getPager().setStartRow(-1);
|
||||
query.getPager().setPageSize(-1);
|
||||
List<JSONObject> jsonList = queryList(query);
|
||||
if(jsonList == null){
|
||||
return null;
|
||||
}else{
|
||||
@@ -44,7 +50,26 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
@Override
|
||||
public List<Seawater> findSeawatersFromEs(String category, String city, String region, String name, List<String> alias, List<String> regionAlias, Integer startDate, Integer endDate, Double startArea, Double endArea, Integer startPrice, Integer endPrice, Integer room, String root, String sort, boolean order, int start, int limit, String table) {
|
||||
List<Seawater> seawaterList= new ArrayList<Seawater>();
|
||||
List<JSONObject> jsonList = queryList(null,category,city,region,name,alias,regionAlias,startDate,endDate, startArea, endArea, startPrice, endPrice, room,root,sort,order,start,limit,table);
|
||||
SeawaterQuery query = new SeawaterQuery();
|
||||
query.setCat(category);
|
||||
query.setCityDisplay(city);
|
||||
query.setRegion(region);
|
||||
query.setDistrictName(name);
|
||||
query.setDistrictAlias(alias);
|
||||
query.setRegionAlias(regionAlias);
|
||||
query.setStartDate(startDate);
|
||||
query.setEndDate(endDate);
|
||||
query.setStartArea(startArea);
|
||||
query.setEndArea(endArea);
|
||||
query.setStartPrice(startPrice);
|
||||
query.setEndPrice(endPrice);
|
||||
query.setRoom(room);
|
||||
query.setRootName(root);
|
||||
query.setOrder(order);
|
||||
query.getPager().setStartRow(-1);
|
||||
query.getPager().setPageSize(-1);
|
||||
query.setTable(table);
|
||||
List<JSONObject> jsonList = queryList(query);
|
||||
if(jsonList == null){
|
||||
return null;
|
||||
}else{
|
||||
@@ -53,6 +78,23 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
return seawaterList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Seawater> findSeawatersByQuery(SeawaterQuery query){
|
||||
List<Seawater> seawaterList= new ArrayList<Seawater>();
|
||||
List<JSONObject> jsonList = queryList(query);
|
||||
if(jsonList == null){
|
||||
return null;
|
||||
}else{
|
||||
seawaterList = wrapSeawater(jsonList);
|
||||
}
|
||||
return seawaterList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long findSeawatersCountByQuery(SeawaterQuery query) {
|
||||
int count = queryCount(query);
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Seawater> findHouses(String city, String region, List<String> alias, Integer minPrice, Integer maxPrice, Integer limit) {
|
||||
@@ -136,6 +178,42 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchDeleteByParams(SeawaterQuery query) {
|
||||
HttpRequest request = new HttpRequest();
|
||||
|
||||
JSONObject reqBody = wrapQueryParams(query);
|
||||
|
||||
JSONObject script = new JSONObject();
|
||||
script.put("source", "ctx._source.status=1");
|
||||
script.put("lang", "painless");
|
||||
reqBody.put("script", script);
|
||||
|
||||
try {
|
||||
request.postWithBody("http://es.fangjia.com:9200/seawater/_update_by_query", reqBody, this.buildHeader(), "UTF-8");
|
||||
} catch (HttpRequestException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchUpdateEstateType(SeawaterQuery query) {
|
||||
HttpRequest request = new HttpRequest();
|
||||
|
||||
JSONObject reqBody = wrapQueryParams(query);
|
||||
|
||||
JSONObject script = new JSONObject();
|
||||
script.put("source", "ctx._source.estate_type="+"'"+query.getEditEstateType()+"'");
|
||||
script.put("lang", "painless");
|
||||
reqBody.put("script", script);
|
||||
|
||||
try {
|
||||
request.postWithBody("http://es.fangjia.com:9200/seawater/_update_by_query", reqBody, this.buildHeader(), "UTF-8");
|
||||
} catch (HttpRequestException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private JSONObject addMatch(String name, String value){
|
||||
JSONObject term = new JSONObject();
|
||||
JSONObject match = new JSONObject();
|
||||
@@ -261,6 +339,9 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
if(source.containsKey("build_type")){
|
||||
seawater.setBuildType(source.getString("build_type"));
|
||||
}
|
||||
if(source.containsKey("status")){
|
||||
seawater.setStatus(source.getInt("status"));
|
||||
}
|
||||
seawaterList.add(seawater);
|
||||
}
|
||||
return seawaterList;
|
||||
@@ -436,29 +517,379 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<JSONObject> queryList(String id,String category, String city, String region, String name, List<String> alias,
|
||||
List<String> regionAlias, Integer startDate, Integer endDate, Double startArea, Double endArea, Integer startPrice, Integer endPrice, Integer room, String root,String sort, boolean order, int start, int limit,String table){
|
||||
JSONObject json = query(id,category,city,region,name,alias,regionAlias,startDate,endDate, startArea, endArea, startPrice, endPrice, room,root,sort,order,start,limit,table);
|
||||
|
||||
private JSONObject query(SeawaterQuery query){
|
||||
long time1 = System.currentTimeMillis();
|
||||
JSONObject reqBody = new JSONObject();
|
||||
JSONObject q = new JSONObject();
|
||||
JSONObject queryJson = new JSONObject();
|
||||
List<JSONObject> jsonList = new ArrayList<JSONObject>();
|
||||
if(StringUtils.isNotBlank(query.getId())) {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("_id", query.getId());
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
if(StringUtils.isNotBlank(query.getCat())) {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("cat", query.getCat());
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
Set<String> namesList = new LinkedHashSet<String>();
|
||||
if(StringUtils.isNotBlank(query.getDistrictName())) {
|
||||
namesList.add(query.getDistrictName());
|
||||
}
|
||||
if (query.getDistrictAlias() != null) {
|
||||
namesList.addAll(query.getDistrictAlias());
|
||||
}
|
||||
if(namesList != null && namesList.size() > 0){
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("district_name", namesList);
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("terms", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
Set<String> regionsList = new LinkedHashSet<String>();
|
||||
if(StringUtils.isNotBlank(query.getRegion())) {
|
||||
regionsList.add(query.getRegion());
|
||||
}
|
||||
if (query.getRegionAlias() != null) {
|
||||
regionsList.addAll(query.getRegionAlias());
|
||||
}
|
||||
if(regionsList != null && regionsList.size() > 0){
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("region", regionsList);
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("terms", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
if(StringUtils.isNotBlank(query.getCityDisplay())){
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("city", query.getCityDisplay());
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
if(StringUtils.isNotBlank(query.getEstateType())) {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("estate_type", query.getEstateType());
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
if(query.getRoom() != null) {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("room", query.getRoom());
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
if(StringUtils.isNotBlank(query.getRootName())) {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("root", query.getRootName());
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
if(query.getStartDate() != null || query.getEndDate() != null){
|
||||
JSONObject param = new JSONObject();
|
||||
JSONObject temp = new JSONObject();
|
||||
JSONObject temp2 = new JSONObject();
|
||||
if(query.getStartDate() != null){
|
||||
temp2.put("gte", query.getStartDate());
|
||||
}
|
||||
if(query.getEndDate() != null){
|
||||
temp2.put("lte", query.getEndDate());
|
||||
}
|
||||
param.put("p_date", temp2);
|
||||
temp.put("range", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
|
||||
if(query.getStartArea() != null || query.getEndArea() != null){
|
||||
JSONObject param = new JSONObject();
|
||||
JSONObject temp = new JSONObject();
|
||||
JSONObject temp2 = new JSONObject();
|
||||
if(query.getStartArea() != null){
|
||||
temp2.put("gte", query.getStartArea());
|
||||
}
|
||||
if(query.getEndArea() != null){
|
||||
temp2.put("lte", query.getEndArea());
|
||||
}
|
||||
param.put("area", temp2);
|
||||
temp.put("range", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
if(query.getStartPrice() != null || query.getEndPrice() != null){
|
||||
JSONObject param = new JSONObject();
|
||||
JSONObject temp = new JSONObject();
|
||||
JSONObject temp2 = new JSONObject();
|
||||
if(query.getStartPrice() != null){
|
||||
temp2.put("gte", query.getStartPrice());
|
||||
}
|
||||
if(query.getEndPrice() != null){
|
||||
temp2.put("lte", query.getEndPrice());
|
||||
}
|
||||
param.put("avg_price", temp2);
|
||||
temp.put("range", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
if(StringUtils.isNotBlank(query.getSort())){
|
||||
JSONObject jsonOrder = new JSONObject();
|
||||
if(query.getOrder()){
|
||||
jsonOrder.put("order", "asc");
|
||||
}else{
|
||||
jsonOrder.put("order", "desc");
|
||||
}
|
||||
JSONObject jsonSort = new JSONObject();
|
||||
jsonSort.put(query.getOrder(), jsonOrder);
|
||||
List<JSONObject> sortJsonList = new ArrayList<JSONObject>();
|
||||
sortJsonList.add(jsonSort);
|
||||
reqBody.put("sort", sortJsonList);
|
||||
}
|
||||
|
||||
if(query.getPager().getStartRow() >= 0){
|
||||
reqBody.put("from", query.getPager().getStartRow());
|
||||
}
|
||||
if(query.getPager().getPageSize() >= 0){
|
||||
reqBody.put("size", query.getPager().getPageSize());
|
||||
}
|
||||
|
||||
if(query.getStatus() != null){
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("status", query.getStatus());
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
queryJson.put("must", jsonList);
|
||||
q.put("bool", queryJson);
|
||||
reqBody.put("query", q);
|
||||
//用户名:密码
|
||||
Base64 token = new Base64();
|
||||
String authenticationEncoding = token.encodeAsString(new String(""+ES_USER+":"+ES_PASSWORD+"").getBytes());
|
||||
HttpRequest request = new HttpRequest();
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
headers.put("Content-Type", "application/json");
|
||||
headers.put("Authorization", "Basic "+authenticationEncoding+"");
|
||||
try {
|
||||
String response = request.postWithBody("http://es.fangjia.com:9200/"+query.getTable()+"/_search?rest_total_hits_as_int=true", reqBody, headers, "UTF-8");
|
||||
JSONObject json = JSONObject.fromObject(response);
|
||||
long time2 = System.currentTimeMillis();
|
||||
System.out.println(time2-time1);
|
||||
return json;
|
||||
} catch (HttpRequestException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// private List<JSONObject> queryList(String id,String category, String city, String region, String name, List<String> alias,
|
||||
// List<String> regionAlias, Integer startDate, Integer endDate, Double startArea, Double endArea, Integer startPrice, Integer endPrice, Integer room, String root,String sort, boolean order, int start, int limit,String table){
|
||||
// JSONObject json = query(id,category,city,region,name,alias,regionAlias,startDate,endDate, startArea, endArea, startPrice, endPrice, room,root,sort,order,start,limit,table);
|
||||
// if(!json.containsKey("hits") || !json.getJSONObject("hits").containsKey("hits")){
|
||||
// return null;
|
||||
// }
|
||||
// JSONArray hits = json.getJSONObject("hits").getJSONArray("hits");
|
||||
// List<JSONObject> results = new ArrayList<JSONObject>();
|
||||
// for(int i=0 ;i < hits.size(); i++){
|
||||
// JSONObject jsonObject = hits.getJSONObject(i);
|
||||
// results.add(jsonObject);
|
||||
// }
|
||||
// return results;
|
||||
// }
|
||||
|
||||
private List<JSONObject> queryList(SeawaterQuery query){
|
||||
JSONObject json = query(query);
|
||||
if(!json.containsKey("hits") || !json.getJSONObject("hits").containsKey("hits")){
|
||||
return null;
|
||||
}
|
||||
JSONArray hits = json.getJSONObject("hits").getJSONArray("hits");
|
||||
List<JSONObject> results = new ArrayList<JSONObject>();
|
||||
for(int i=0 ;i < hits.size(); i++){
|
||||
JSONObject jsonObject = hits.getJSONObject(i);
|
||||
results.add(jsonObject);
|
||||
}
|
||||
return results;
|
||||
return null;
|
||||
}
|
||||
JSONArray hits = json.getJSONObject("hits").getJSONArray("hits");
|
||||
List<JSONObject> results = new ArrayList<JSONObject>();
|
||||
for(int i=0 ;i < hits.size(); i++){
|
||||
JSONObject jsonObject = hits.getJSONObject(i);
|
||||
results.add(jsonObject);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private int queryCount(String id,String category, String city, String region, String name, List<String> alias,
|
||||
List<String> regionAlias, Integer startDate, Integer endDate, Integer room, String root,String sort, boolean order, int start, int limit,String table){
|
||||
JSONObject json = query(id,category,city,region,name,alias,regionAlias,startDate,endDate,null, null, null, null, room,root,sort,order,start,limit,table);
|
||||
SeawaterQuery query = new SeawaterQuery();
|
||||
query.setCat(category);
|
||||
query.setCityDisplay(city);
|
||||
query.setRegion(region);
|
||||
query.setDistrictName(name);
|
||||
query.setDistrictAlias(alias);
|
||||
query.setRegionAlias(regionAlias);
|
||||
query.setStartDate(startDate);
|
||||
query.setEndDate(endDate);
|
||||
query.setRoom(room);
|
||||
query.setRootName(root);
|
||||
query.setOrder(order);
|
||||
query.getPager().setStartRow(-1);
|
||||
query.getPager().setPageSize(-1);
|
||||
query.setTable(table);
|
||||
JSONObject json = query(query);
|
||||
if(!json.containsKey("hits") || !json.getJSONObject("hits").containsKey("total")){
|
||||
return 0;
|
||||
}
|
||||
return json.getJSONObject("hits").getInt("total");
|
||||
}
|
||||
|
||||
private int queryCount(SeawaterQuery query){
|
||||
JSONObject json = query(query);
|
||||
if(!json.containsKey("hits") || !json.getJSONObject("hits").containsKey("total")){
|
||||
return 0;
|
||||
}
|
||||
return json.getJSONObject("hits").getInt("total");
|
||||
}
|
||||
|
||||
private JSONObject wrapQueryParams(SeawaterQuery query){
|
||||
JSONObject reqBody = new JSONObject();
|
||||
JSONObject q = new JSONObject();
|
||||
JSONObject queryJson = new JSONObject();
|
||||
List<JSONObject> jsonList = new ArrayList<JSONObject>();
|
||||
if(StringUtils.isNotBlank(query.getId())) {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("_id", query.getId());
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
if(StringUtils.isNotBlank(query.getCat())) {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("cat", query.getCat());
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
Set<String> namesList = new LinkedHashSet<String>();
|
||||
if(StringUtils.isNotBlank(query.getDistrictName())) {
|
||||
namesList.add(query.getDistrictName());
|
||||
}
|
||||
if(namesList != null && namesList.size() > 0){
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("district_name", namesList);
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("terms", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
Set<String> regionsList = new LinkedHashSet<String>();
|
||||
if(StringUtils.isNotBlank(query.getRegion())) {
|
||||
regionsList.add(query.getRegion());
|
||||
}
|
||||
if (query.getRegionAlias() != null) {
|
||||
regionsList.addAll(query.getRegionAlias());
|
||||
}
|
||||
if(regionsList != null && regionsList.size() > 0){
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("region", regionsList);
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("terms", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
if(StringUtils.isNotBlank(query.getCityDisplay())){
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("city", query.getCityDisplay());
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
if(StringUtils.isNotBlank(query.getEstateType())) {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("estate_type", query.getEstateType());
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
if(query.getRoom() != null) {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("room", query.getRoom());
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
if(StringUtils.isNotBlank(query.getRootName())) {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("root", query.getRootName());
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
if(query.getStartDate() != null || query.getEndDate() != null){
|
||||
JSONObject param = new JSONObject();
|
||||
JSONObject temp = new JSONObject();
|
||||
JSONObject temp2 = new JSONObject();
|
||||
if(query.getStartDate() != null){
|
||||
temp2.put("gte", query.getStartDate());
|
||||
}
|
||||
if(query.getEndDate() != null){
|
||||
temp2.put("lte", query.getEndDate());
|
||||
}
|
||||
param.put("p_date", temp2);
|
||||
temp.put("range", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
|
||||
if(query.getStartArea() != null || query.getEndArea() != null){
|
||||
JSONObject param = new JSONObject();
|
||||
JSONObject temp = new JSONObject();
|
||||
JSONObject temp2 = new JSONObject();
|
||||
if(query.getStartArea() != null){
|
||||
temp2.put("gte", query.getStartArea());
|
||||
}
|
||||
if(query.getEndArea() != null){
|
||||
temp2.put("lte", query.getEndArea());
|
||||
}
|
||||
param.put("area", temp2);
|
||||
temp.put("range", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
if(query.getStartPrice() != null || query.getEndPrice() != null){
|
||||
JSONObject param = new JSONObject();
|
||||
JSONObject temp = new JSONObject();
|
||||
JSONObject temp2 = new JSONObject();
|
||||
if(query.getStartPrice() != null){
|
||||
temp2.put("gte", query.getStartPrice());
|
||||
}
|
||||
if(query.getEndPrice() != null){
|
||||
temp2.put("lte", query.getEndPrice());
|
||||
}
|
||||
param.put("avg_price", temp2);
|
||||
temp.put("range", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
if(query.getStatus() != null){
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("status", query.getStatus());
|
||||
JSONObject temp = new JSONObject();
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
queryJson.put("must", jsonList);
|
||||
q.put("bool", queryJson);
|
||||
reqBody.put("query", q);
|
||||
return reqBody;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user