租金挂牌样本接口
This commit is contained in:
+155
-153
@@ -23,13 +23,13 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long findSeawatersCountFromEs(String category, String city, String region, String name, List<String> alias,
|
public long findSeawatersCountFromEs(String category, String city, String region, String name, List<String> alias,
|
||||||
List<String> regionAlias, Integer startDate, Integer endDate, Integer room, String root,String table) {
|
List<String> regionAlias, Integer startDate, Integer endDate, Integer room, String root, String table) {
|
||||||
int count = queryCount(null,category,city,region,name,alias,regionAlias,startDate,endDate,room,root,null,false,-1,-1,table);
|
int count = queryCount(null, category, city, region, name, alias, regionAlias, startDate, endDate, room, root, null, false, -1, -1, table);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Seawater findByIdFromEs(String id,String table) {
|
public Seawater findByIdFromEs(String id, String table) {
|
||||||
Seawater seawater = null;
|
Seawater seawater = null;
|
||||||
SeawaterQuery query = new SeawaterQuery();
|
SeawaterQuery query = new SeawaterQuery();
|
||||||
query.setId(id);
|
query.setId(id);
|
||||||
@@ -39,11 +39,11 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
pager.setPageSize(-1);
|
pager.setPageSize(-1);
|
||||||
query.setPager(pager);
|
query.setPager(pager);
|
||||||
List<JSONObject> jsonList = queryList(query);
|
List<JSONObject> jsonList = queryList(query);
|
||||||
if(jsonList == null){
|
if (jsonList == null) {
|
||||||
return null;
|
return null;
|
||||||
}else{
|
} else {
|
||||||
List<Seawater> seawaterList = wrapSeawater(jsonList);
|
List<Seawater> seawaterList = wrapSeawater(jsonList);
|
||||||
if(seawaterList.size() > 0){
|
if (seawaterList.size() > 0) {
|
||||||
seawater = seawaterList.get(0);
|
seawater = seawaterList.get(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
|
|
||||||
@Override
|
@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) {
|
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<Seawater> seawaterList = new ArrayList<Seawater>();
|
||||||
SeawaterQuery query = new SeawaterQuery();
|
SeawaterQuery query = new SeawaterQuery();
|
||||||
query.setCat(category);
|
query.setCat(category);
|
||||||
query.setCityDisplay(city);
|
query.setCityDisplay(city);
|
||||||
@@ -75,21 +75,21 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
query.setPager(pager);
|
query.setPager(pager);
|
||||||
query.setTable(table);
|
query.setTable(table);
|
||||||
List<JSONObject> jsonList = queryList(query);
|
List<JSONObject> jsonList = queryList(query);
|
||||||
if(jsonList == null){
|
if (jsonList == null) {
|
||||||
return null;
|
return null;
|
||||||
}else{
|
} else {
|
||||||
seawaterList = wrapSeawater(jsonList);
|
seawaterList = wrapSeawater(jsonList);
|
||||||
}
|
}
|
||||||
return seawaterList;
|
return seawaterList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Seawater> findSeawatersByQuery(SeawaterQuery query){
|
public List<Seawater> findSeawatersByQuery(SeawaterQuery query) {
|
||||||
List<Seawater> seawaterList;
|
List<Seawater> seawaterList;
|
||||||
List<JSONObject> jsonList = queryList(query);
|
List<JSONObject> jsonList = queryList(query);
|
||||||
if(jsonList == null){
|
if (jsonList == null) {
|
||||||
return null;
|
return null;
|
||||||
}else{
|
} else {
|
||||||
seawaterList = wrapSeawater(jsonList);
|
seawaterList = wrapSeawater(jsonList);
|
||||||
}
|
}
|
||||||
return seawaterList;
|
return seawaterList;
|
||||||
@@ -120,20 +120,20 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
query.put("bool", bool);
|
query.put("bool", bool);
|
||||||
reqBody.put("query", query);
|
reqBody.put("query", query);
|
||||||
Base64 token = new Base64();
|
Base64 token = new Base64();
|
||||||
String authenticationEncoding = token.encodeAsString(new String(""+ES_USER+":"+ES_PASSWORD+"").getBytes());
|
String authenticationEncoding = token.encodeAsString(new String("" + ES_USER + ":" + ES_PASSWORD + "").getBytes());
|
||||||
HttpRequest request = new HttpRequest();
|
HttpRequest request = new HttpRequest();
|
||||||
Map<String, String> headers = new HashMap<String, String>();
|
Map<String, String> headers = new HashMap<String, String>();
|
||||||
headers.put("Content-Type", "application/json");
|
headers.put("Content-Type", "application/json");
|
||||||
headers.put("Authorization", "Basic "+authenticationEncoding+"");
|
headers.put("Authorization", "Basic " + authenticationEncoding + "");
|
||||||
try {
|
try {
|
||||||
String response = request.postWithBody("http://es.fangjia.com:9200/latest_seawater/_search", reqBody, headers, "UTF-8");
|
String response = request.postWithBody("http://es.fangjia.com:9200/latest_seawater/_search", reqBody, headers, "UTF-8");
|
||||||
JSONObject json = JSONObject.fromObject(response);
|
JSONObject json = JSONObject.fromObject(response);
|
||||||
if(!json.containsKey("hits") || !json.getJSONObject("hits").containsKey("hits")){
|
if (!json.containsKey("hits") || !json.getJSONObject("hits").containsKey("hits")) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
JSONArray hits = json.getJSONObject("hits").getJSONArray("hits");
|
JSONArray hits = json.getJSONObject("hits").getJSONArray("hits");
|
||||||
List<JSONObject> results = new ArrayList<JSONObject>();
|
List<JSONObject> results = new ArrayList<JSONObject>();
|
||||||
for(int i=0 ;i < hits.size(); i++){
|
for (int i = 0; i < hits.size(); i++) {
|
||||||
JSONObject jsonObject = hits.getJSONObject(i);
|
JSONObject jsonObject = hits.getJSONObject(i);
|
||||||
results.add(jsonObject);
|
results.add(jsonObject);
|
||||||
}
|
}
|
||||||
@@ -208,7 +208,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
JSONObject reqBody = wrapQueryParams(query);
|
JSONObject reqBody = wrapQueryParams(query);
|
||||||
|
|
||||||
JSONObject script = new JSONObject();
|
JSONObject script = new JSONObject();
|
||||||
script.put("source", "ctx._source.estate_type="+"'"+query.getEditEstateType()+"'");
|
script.put("source", "ctx._source.estate_type=" + "'" + query.getEditEstateType() + "'");
|
||||||
script.put("lang", "painless");
|
script.put("lang", "painless");
|
||||||
reqBody.put("script", script);
|
reqBody.put("script", script);
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject addMatch(String name, String value){
|
private JSONObject addMatch(String name, String value) {
|
||||||
JSONObject term = new JSONObject();
|
JSONObject term = new JSONObject();
|
||||||
JSONObject match = new JSONObject();
|
JSONObject match = new JSONObject();
|
||||||
match.put(name, value);
|
match.put(name, value);
|
||||||
@@ -227,7 +227,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
return term;
|
return term;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject addTerms(String name, List<String> value){
|
private JSONObject addTerms(String name, List<String> value) {
|
||||||
JSONObject terms = new JSONObject();
|
JSONObject terms = new JSONObject();
|
||||||
JSONObject match = new JSONObject();
|
JSONObject match = new JSONObject();
|
||||||
match.put(name, value);
|
match.put(name, value);
|
||||||
@@ -235,7 +235,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
return terms;
|
return terms;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject addRange(String name, Number min, Number max){
|
private JSONObject addRange(String name, Number min, Number max) {
|
||||||
JSONObject term = new JSONObject();
|
JSONObject term = new JSONObject();
|
||||||
JSONObject range = new JSONObject();
|
JSONObject range = new JSONObject();
|
||||||
JSONObject rangeValue = new JSONObject();
|
JSONObject rangeValue = new JSONObject();
|
||||||
@@ -246,7 +246,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
return term;
|
return term;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject addRangeGte(String name, Number min){
|
private JSONObject addRangeGte(String name, Number min) {
|
||||||
JSONObject term = new JSONObject();
|
JSONObject term = new JSONObject();
|
||||||
JSONObject range = new JSONObject();
|
JSONObject range = new JSONObject();
|
||||||
JSONObject rangeValue = new JSONObject();
|
JSONObject rangeValue = new JSONObject();
|
||||||
@@ -257,9 +257,9 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<Seawater> wrapSeawater(List<JSONObject> jsonList){
|
private List<Seawater> wrapSeawater(List<JSONObject> jsonList) {
|
||||||
List<Seawater> seawaterList= new ArrayList<Seawater>();
|
List<Seawater> seawaterList = new ArrayList<Seawater>();
|
||||||
for(int i=0 ;i < jsonList.size(); i++){
|
for (int i = 0; i < jsonList.size(); i++) {
|
||||||
Seawater seawater = new Seawater();
|
Seawater seawater = new Seawater();
|
||||||
seawater.setId(jsonList.get(i).getString("_id"));
|
seawater.setId(jsonList.get(i).getString("_id"));
|
||||||
JSONObject source = jsonList.get(i).getJSONObject("_source");
|
JSONObject source = jsonList.get(i).getJSONObject("_source");
|
||||||
@@ -267,124 +267,124 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
seawater.setCity(source.getString("city"));
|
seawater.setCity(source.getString("city"));
|
||||||
seawater.setRegion(source.getString("region"));
|
seawater.setRegion(source.getString("region"));
|
||||||
seawater.setDistrictName(source.getString("district_name"));
|
seawater.setDistrictName(source.getString("district_name"));
|
||||||
if (source.containsKey("location")){
|
if (source.containsKey("location")) {
|
||||||
String location = source.getJSONObject("location").getString("lon") + "," + source.getJSONObject("location").getString("lat");
|
String location = source.getJSONObject("location").getString("lon") + "," + source.getJSONObject("location").getString("lat");
|
||||||
seawater.setLocation(location);
|
seawater.setLocation(location);
|
||||||
}
|
}
|
||||||
if(source.containsKey("address")){
|
if (source.containsKey("address")) {
|
||||||
seawater.setAddress(source.getString("address"));
|
seawater.setAddress(source.getString("address"));
|
||||||
}
|
}
|
||||||
if(source.containsKey("name")){
|
if (source.containsKey("name")) {
|
||||||
seawater.setName(source.getString("name"));
|
seawater.setName(source.getString("name"));
|
||||||
}
|
}
|
||||||
if(source.containsKey("direction")){
|
if (source.containsKey("direction")) {
|
||||||
seawater.setDirection(source.getString("direction"));
|
seawater.setDirection(source.getString("direction"));
|
||||||
}
|
}
|
||||||
if(source.containsKey("block")){
|
if (source.containsKey("block")) {
|
||||||
seawater.setBlock(source.getString("block"));
|
seawater.setBlock(source.getString("block"));
|
||||||
}
|
}
|
||||||
try{
|
try {
|
||||||
seawater.setTotalPrice(source.getInt("total_price"));
|
seawater.setTotalPrice(source.getInt("total_price"));
|
||||||
}catch(NumberFormatException e){
|
} catch (NumberFormatException e) {
|
||||||
seawater.setTotalPrice(0);
|
seawater.setTotalPrice(0);
|
||||||
}
|
}
|
||||||
try{
|
try {
|
||||||
seawater.setArea(source.getDouble("area"));
|
seawater.setArea(source.getDouble("area"));
|
||||||
}catch(NumberFormatException e){
|
} catch (NumberFormatException e) {
|
||||||
seawater.setArea(0d);
|
seawater.setArea(0d);
|
||||||
}
|
}
|
||||||
try{
|
try {
|
||||||
seawater.setHeight(source.getInt("height"));
|
seawater.setHeight(source.getInt("height"));
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
seawater.setHeight(0);
|
seawater.setHeight(0);
|
||||||
}
|
}
|
||||||
try{
|
try {
|
||||||
seawater.setFloor(source.getInt("floor"));
|
seawater.setFloor(source.getInt("floor"));
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
seawater.setFloor(0);
|
seawater.setFloor(0);
|
||||||
}
|
}
|
||||||
try{
|
try {
|
||||||
seawater.setFloorInfo(source.getString("floor_info"));
|
seawater.setFloorInfo(source.getString("floor_info"));
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
if(source.containsKey("fitment")){
|
if (source.containsKey("fitment")) {
|
||||||
seawater.setFitment(source.getString("fitment"));
|
seawater.setFitment(source.getString("fitment"));
|
||||||
}
|
}
|
||||||
try{
|
try {
|
||||||
seawater.setRoom(source.getInt("room"));
|
seawater.setRoom(source.getInt("room"));
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
seawater.setRoom(0);
|
seawater.setRoom(0);
|
||||||
}
|
}
|
||||||
try{
|
try {
|
||||||
seawater.setHall(source.getInt("hall"));
|
seawater.setHall(source.getInt("hall"));
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
seawater.setHall(0);
|
seawater.setHall(0);
|
||||||
}
|
}
|
||||||
try{
|
try {
|
||||||
seawater.setToilet(source.getInt("toilet"));
|
seawater.setToilet(source.getInt("toilet"));
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
seawater.setToilet(0);
|
seawater.setToilet(0);
|
||||||
}
|
}
|
||||||
try{
|
try {
|
||||||
seawater.setpDate(source.getInt("p_date"));
|
seawater.setpDate(source.getInt("p_date"));
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
seawater.setpDate(0);
|
seawater.setpDate(0);
|
||||||
}
|
}
|
||||||
if(source.containsKey("url")){
|
if (source.containsKey("url")) {
|
||||||
seawater.setUrl(source.getString("url"));
|
seawater.setUrl(source.getString("url"));
|
||||||
}
|
}
|
||||||
if(source.containsKey("avg_price")){
|
if (source.containsKey("avg_price")) {
|
||||||
seawater.setAvgPrice(source.getInt("avg_price"));
|
seawater.setAvgPrice(source.getInt("avg_price"));
|
||||||
}
|
}
|
||||||
if(source.containsKey("root")){
|
if (source.containsKey("root")) {
|
||||||
seawater.setRoot(source.getString("root"));
|
seawater.setRoot(source.getString("root"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(source.containsKey("estate_type")){
|
if (source.containsKey("estate_type")) {
|
||||||
seawater.setEstateType(source.getString("estate_type"));
|
seawater.setEstateType(source.getString("estate_type"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(source.containsKey("build_type")){
|
if (source.containsKey("build_type")) {
|
||||||
seawater.setBuildType(source.getString("build_type"));
|
seawater.setBuildType(source.getString("build_type"));
|
||||||
}
|
}
|
||||||
if(source.containsKey("status")){
|
if (source.containsKey("status")) {
|
||||||
seawater.setStatus(source.getInt("status"));
|
seawater.setStatus(source.getInt("status"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(source.containsKey("lift")){
|
if (source.containsKey("lift")) {
|
||||||
seawater.setLift(source.getInt("lift"));
|
seawater.setLift(source.getInt("lift"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(source.containsKey("lift_household")){
|
if (source.containsKey("lift_household")) {
|
||||||
seawater.setLiftHousehold(source.getInt("lift_household"));
|
seawater.setLiftHousehold(source.getInt("lift_household"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(source.containsKey("room_structure")){
|
if (source.containsKey("room_structure")) {
|
||||||
seawater.setRoomStructure(source.getString("room_structure"));
|
seawater.setRoomStructure(source.getString("room_structure"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(source.containsKey("trade_property")){
|
if (source.containsKey("trade_property")) {
|
||||||
seawater.setTradeProperty(source.getString("trade_property"));
|
seawater.setTradeProperty(source.getString("trade_property"));
|
||||||
}
|
}
|
||||||
if(source.containsKey("property_ownership")){
|
if (source.containsKey("property_ownership")) {
|
||||||
seawater.setPropertyOwnership(source.getString("property_ownership"));
|
seawater.setPropertyOwnership(source.getString("property_ownership"));
|
||||||
}
|
}
|
||||||
if(source.containsKey("housing_age")){
|
if (source.containsKey("housing_age")) {
|
||||||
seawater.setHousingAge(source.getString("housing_age"));
|
seawater.setHousingAge(source.getString("housing_age"));
|
||||||
}
|
}
|
||||||
if(source.containsKey("elevator")){
|
if (source.containsKey("elevator")) {
|
||||||
seawater.setElevator(source.getString("elevator"));
|
seawater.setElevator(source.getString("elevator"));
|
||||||
}
|
}
|
||||||
if(source.containsKey("level")){
|
if (source.containsKey("level")) {
|
||||||
seawater.setLevel(source.getString("level"));
|
seawater.setLevel(source.getString("level"));
|
||||||
}
|
}
|
||||||
if(source.containsKey("business_range")){
|
if (source.containsKey("business_range")) {
|
||||||
seawater.setBusinessRange(source.getString("business_range"));
|
seawater.setBusinessRange(source.getString("business_range"));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
seawater.setDistance((int)jsonList.get(i).getJSONArray("sort").getDouble(0));
|
seawater.setDistance((int) jsonList.get(i).getJSONArray("sort").getDouble(0));
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
seawater.setDistance(null);
|
seawater.setDistance(null);
|
||||||
}
|
}
|
||||||
seawaterList.add(seawater);
|
seawaterList.add(seawater);
|
||||||
@@ -392,22 +392,22 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
return seawaterList;
|
return seawaterList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject query(String id,String category, String city, String region, String name, List<String> alias,
|
private JSONObject query(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,
|
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){
|
Integer room, String root, String sort, boolean order, int start, int limit, String table) {
|
||||||
long time1 = System.currentTimeMillis();
|
long time1 = System.currentTimeMillis();
|
||||||
JSONObject reqBody = new JSONObject();
|
JSONObject reqBody = new JSONObject();
|
||||||
JSONObject q = new JSONObject();
|
JSONObject q = new JSONObject();
|
||||||
JSONObject query = new JSONObject();
|
JSONObject query = new JSONObject();
|
||||||
List<JSONObject> jsonList = new ArrayList<JSONObject>();
|
List<JSONObject> jsonList = new ArrayList<JSONObject>();
|
||||||
if(StringUtils.isNotBlank(id)) {
|
if (StringUtils.isNotBlank(id)) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("_id", id);
|
param.put("_id", id);
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
temp.put("term", param);
|
temp.put("term", param);
|
||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(category)) {
|
if (StringUtils.isNotBlank(category)) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("cat", category);
|
param.put("cat", category);
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
@@ -416,13 +416,13 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<String> namesList = new LinkedHashSet<String>();
|
Set<String> namesList = new LinkedHashSet<String>();
|
||||||
if(StringUtils.isNotBlank(name)) {
|
if (StringUtils.isNotBlank(name)) {
|
||||||
namesList.add(name);
|
namesList.add(name);
|
||||||
}
|
}
|
||||||
if (alias != null) {
|
if (alias != null) {
|
||||||
namesList.addAll(alias);
|
namesList.addAll(alias);
|
||||||
}
|
}
|
||||||
if(namesList != null && namesList.size() > 0){
|
if (namesList != null && namesList.size() > 0) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("district_name", namesList);
|
param.put("district_name", namesList);
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
@@ -431,13 +431,13 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<String> regionsList = new LinkedHashSet<String>();
|
Set<String> regionsList = new LinkedHashSet<String>();
|
||||||
if(StringUtils.isNotBlank(region)) {
|
if (StringUtils.isNotBlank(region)) {
|
||||||
regionsList.add(region);
|
regionsList.add(region);
|
||||||
}
|
}
|
||||||
if (regionAlias != null) {
|
if (regionAlias != null) {
|
||||||
regionsList.addAll(regionAlias);
|
regionsList.addAll(regionAlias);
|
||||||
}
|
}
|
||||||
if(regionsList != null && regionsList.size() > 0){
|
if (regionsList != null && regionsList.size() > 0) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("region", regionsList);
|
param.put("region", regionsList);
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
@@ -445,21 +445,21 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StringUtils.isNotBlank(city)){
|
if (StringUtils.isNotBlank(city)) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("city", city);
|
param.put("city", city);
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
temp.put("term", param);
|
temp.put("term", param);
|
||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
if(room != null) {
|
if (room != null) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("room", room);
|
param.put("room", room);
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
temp.put("term", param);
|
temp.put("term", param);
|
||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(root)) {
|
if (StringUtils.isNotBlank(root)) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("root", root);
|
param.put("root", root);
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
@@ -467,14 +467,14 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(startDate != null || endDate != null){
|
if (startDate != null || endDate != null) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
JSONObject temp2 = new JSONObject();
|
JSONObject temp2 = new JSONObject();
|
||||||
if(startDate != null){
|
if (startDate != null) {
|
||||||
temp2.put("gte", startDate);
|
temp2.put("gte", startDate);
|
||||||
}
|
}
|
||||||
if(endDate != null){
|
if (endDate != null) {
|
||||||
temp2.put("lte", endDate);
|
temp2.put("lte", endDate);
|
||||||
}
|
}
|
||||||
param.put("p_date", temp2);
|
param.put("p_date", temp2);
|
||||||
@@ -483,14 +483,14 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(startArea != null || endArea != null){
|
if (startArea != null || endArea != null) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
JSONObject temp2 = new JSONObject();
|
JSONObject temp2 = new JSONObject();
|
||||||
if(startArea != null){
|
if (startArea != null) {
|
||||||
temp2.put("gte", startArea);
|
temp2.put("gte", startArea);
|
||||||
}
|
}
|
||||||
if(endArea != null){
|
if (endArea != null) {
|
||||||
temp2.put("lte", endArea);
|
temp2.put("lte", endArea);
|
||||||
}
|
}
|
||||||
param.put("area", temp2);
|
param.put("area", temp2);
|
||||||
@@ -498,14 +498,14 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(startPrice != null || endPrice != null){
|
if (startPrice != null || endPrice != null) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
JSONObject temp2 = new JSONObject();
|
JSONObject temp2 = new JSONObject();
|
||||||
if(startPrice != null){
|
if (startPrice != null) {
|
||||||
temp2.put("gte", startPrice);
|
temp2.put("gte", startPrice);
|
||||||
}
|
}
|
||||||
if(endPrice != null){
|
if (endPrice != null) {
|
||||||
temp2.put("lte", endPrice);
|
temp2.put("lte", endPrice);
|
||||||
}
|
}
|
||||||
param.put("avg_price", temp2);
|
param.put("avg_price", temp2);
|
||||||
@@ -513,11 +513,11 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StringUtils.isNotBlank(sort)){
|
if (StringUtils.isNotBlank(sort)) {
|
||||||
JSONObject jsonOrder = new JSONObject();
|
JSONObject jsonOrder = new JSONObject();
|
||||||
if(order){
|
if (order) {
|
||||||
jsonOrder.put("order", "asc");
|
jsonOrder.put("order", "asc");
|
||||||
}else{
|
} else {
|
||||||
jsonOrder.put("order", "desc");
|
jsonOrder.put("order", "desc");
|
||||||
}
|
}
|
||||||
JSONObject jsonSort = new JSONObject();
|
JSONObject jsonSort = new JSONObject();
|
||||||
@@ -527,10 +527,10 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
reqBody.put("sort", sortJsonList);
|
reqBody.put("sort", sortJsonList);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(start >= 0){
|
if (start >= 0) {
|
||||||
reqBody.put("from", start);
|
reqBody.put("from", start);
|
||||||
}
|
}
|
||||||
if(limit >= 0){
|
if (limit >= 0) {
|
||||||
reqBody.put("size", limit);
|
reqBody.put("size", limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -546,16 +546,16 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
reqBody.put("query", q);
|
reqBody.put("query", q);
|
||||||
//用户名:密码
|
//用户名:密码
|
||||||
Base64 token = new Base64();
|
Base64 token = new Base64();
|
||||||
String authenticationEncoding = token.encodeAsString(new String(""+ES_USER+":"+ES_PASSWORD+"").getBytes());
|
String authenticationEncoding = token.encodeAsString(new String("" + ES_USER + ":" + ES_PASSWORD + "").getBytes());
|
||||||
HttpRequest request = new HttpRequest();
|
HttpRequest request = new HttpRequest();
|
||||||
Map<String, String> headers = new HashMap<String, String>();
|
Map<String, String> headers = new HashMap<String, String>();
|
||||||
headers.put("Content-Type", "application/json");
|
headers.put("Content-Type", "application/json");
|
||||||
headers.put("Authorization", "Basic "+authenticationEncoding+"");
|
headers.put("Authorization", "Basic " + authenticationEncoding + "");
|
||||||
try {
|
try {
|
||||||
String response = request.postWithBody("http://es.fangjia.com:9200/"+table+"/_search?rest_total_hits_as_int=true", reqBody, headers, "UTF-8");
|
String response = request.postWithBody("http://es.fangjia.com:9200/" + table + "/_search?rest_total_hits_as_int=true", reqBody, headers, "UTF-8");
|
||||||
JSONObject json = JSONObject.fromObject(response);
|
JSONObject json = JSONObject.fromObject(response);
|
||||||
long time2 = System.currentTimeMillis();
|
long time2 = System.currentTimeMillis();
|
||||||
System.out.println(time2-time1);
|
System.out.println(time2 - time1);
|
||||||
return json;
|
return json;
|
||||||
} catch (HttpRequestException e) {
|
} catch (HttpRequestException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -563,7 +563,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject query(SeawaterQuery query){
|
private JSONObject query(SeawaterQuery query) {
|
||||||
long time1 = System.currentTimeMillis();
|
long time1 = System.currentTimeMillis();
|
||||||
JSONObject reqBody = new JSONObject();
|
JSONObject reqBody = new JSONObject();
|
||||||
JSONObject q = new JSONObject();
|
JSONObject q = new JSONObject();
|
||||||
@@ -604,14 +604,14 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
sortJsonList.add(geoDistanceSort);
|
sortJsonList.add(geoDistanceSort);
|
||||||
reqBody.put("sort", sortJsonList);
|
reqBody.put("sort", sortJsonList);
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(query.getId())) {
|
if (StringUtils.isNotBlank(query.getId())) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("_id", query.getId());
|
param.put("_id", query.getId());
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
temp.put("term", param);
|
temp.put("term", param);
|
||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(query.getCat())) {
|
if (StringUtils.isNotBlank(query.getCat())) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("cat", query.getCat());
|
param.put("cat", query.getCat());
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
@@ -620,13 +620,13 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<String> namesList = new LinkedHashSet<String>();
|
Set<String> namesList = new LinkedHashSet<String>();
|
||||||
if(StringUtils.isNotBlank(query.getDistrictName())) {
|
if (StringUtils.isNotBlank(query.getDistrictName())) {
|
||||||
namesList.add(query.getDistrictName());
|
namesList.add(query.getDistrictName());
|
||||||
}
|
}
|
||||||
if (query.getDistrictAlias() != null) {
|
if (query.getDistrictAlias() != null) {
|
||||||
namesList.addAll(query.getDistrictAlias());
|
namesList.addAll(query.getDistrictAlias());
|
||||||
}
|
}
|
||||||
if(namesList != null && namesList.size() > 0){
|
if (namesList != null && namesList.size() > 0) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("district_name", namesList);
|
param.put("district_name", namesList);
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
@@ -635,13 +635,13 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<String> regionsList = new LinkedHashSet<String>();
|
Set<String> regionsList = new LinkedHashSet<String>();
|
||||||
if(StringUtils.isNotBlank(query.getRegion())) {
|
if (StringUtils.isNotBlank(query.getRegion())) {
|
||||||
regionsList.add(query.getRegion());
|
regionsList.add(query.getRegion());
|
||||||
}
|
}
|
||||||
if (query.getRegionAlias() != null) {
|
if (query.getRegionAlias() != null) {
|
||||||
regionsList.addAll(query.getRegionAlias());
|
regionsList.addAll(query.getRegionAlias());
|
||||||
}
|
}
|
||||||
if(regionsList != null && regionsList.size() > 0){
|
if (regionsList != null && regionsList.size() > 0) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("region", regionsList);
|
param.put("region", regionsList);
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
@@ -649,28 +649,28 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StringUtils.isNotBlank(query.getCityDisplay())){
|
if (StringUtils.isNotBlank(query.getCityDisplay())) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("city", query.getCityDisplay());
|
param.put("city", query.getCityDisplay());
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
temp.put("term", param);
|
temp.put("term", param);
|
||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(query.getEstateType())) {
|
if (StringUtils.isNotBlank(query.getEstateType())) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("estate_type", query.getEstateType());
|
param.put("estate_type", query.getEstateType());
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
temp.put("term", param);
|
temp.put("term", param);
|
||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
if(query.getRoom() != null) {
|
if (query.getRoom() != null) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("room", query.getRoom());
|
param.put("room", query.getRoom());
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
temp.put("term", param);
|
temp.put("term", param);
|
||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(query.getRootName())) {
|
if (StringUtils.isNotBlank(query.getRootName())) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("root", query.getRootName());
|
param.put("root", query.getRootName());
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
@@ -678,14 +678,14 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(query.getStartDate() != null || query.getEndDate() != null){
|
if (query.getStartDate() != null || query.getEndDate() != null) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
JSONObject temp2 = new JSONObject();
|
JSONObject temp2 = new JSONObject();
|
||||||
if(query.getStartDate() != null){
|
if (query.getStartDate() != null) {
|
||||||
temp2.put("gte", query.getStartDate());
|
temp2.put("gte", query.getStartDate());
|
||||||
}
|
}
|
||||||
if(query.getEndDate() != null){
|
if (query.getEndDate() != null) {
|
||||||
temp2.put("lte", query.getEndDate());
|
temp2.put("lte", query.getEndDate());
|
||||||
}
|
}
|
||||||
param.put("p_date", temp2);
|
param.put("p_date", temp2);
|
||||||
@@ -694,14 +694,14 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(query.getStartArea() != null || query.getEndArea() != null){
|
if (query.getStartArea() != null || query.getEndArea() != null) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
JSONObject temp2 = new JSONObject();
|
JSONObject temp2 = new JSONObject();
|
||||||
if(query.getStartArea() != null){
|
if (query.getStartArea() != null) {
|
||||||
temp2.put("gte", query.getStartArea());
|
temp2.put("gte", query.getStartArea());
|
||||||
}
|
}
|
||||||
if(query.getEndArea() != null){
|
if (query.getEndArea() != null) {
|
||||||
temp2.put("lte", query.getEndArea());
|
temp2.put("lte", query.getEndArea());
|
||||||
}
|
}
|
||||||
param.put("area", temp2);
|
param.put("area", temp2);
|
||||||
@@ -709,14 +709,14 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(query.getStartPrice() != null || query.getEndPrice() != null){
|
if (query.getStartPrice() != null || query.getEndPrice() != null) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
JSONObject temp2 = new JSONObject();
|
JSONObject temp2 = new JSONObject();
|
||||||
if(query.getStartPrice() != null){
|
if (query.getStartPrice() != null) {
|
||||||
temp2.put("gte", query.getStartPrice());
|
temp2.put("gte", query.getStartPrice());
|
||||||
}
|
}
|
||||||
if(query.getEndPrice() != null){
|
if (query.getEndPrice() != null) {
|
||||||
temp2.put("lte", query.getEndPrice());
|
temp2.put("lte", query.getEndPrice());
|
||||||
}
|
}
|
||||||
param.put("avg_price", temp2);
|
param.put("avg_price", temp2);
|
||||||
@@ -724,11 +724,11 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StringUtils.isNotBlank(query.getSortField())){
|
if (StringUtils.isNotBlank(query.getSortField())) {
|
||||||
JSONObject jsonOrder = new JSONObject();
|
JSONObject jsonOrder = new JSONObject();
|
||||||
if(query.getOrder()){
|
if (query.getOrder()) {
|
||||||
jsonOrder.put("order", "asc");
|
jsonOrder.put("order", "asc");
|
||||||
}else{
|
} else {
|
||||||
jsonOrder.put("order", "desc");
|
jsonOrder.put("order", "desc");
|
||||||
}
|
}
|
||||||
JSONObject jsonSort = new JSONObject();
|
JSONObject jsonSort = new JSONObject();
|
||||||
@@ -738,14 +738,14 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
reqBody.put("sort", sortJsonList);
|
reqBody.put("sort", sortJsonList);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(query.getPager().getStartRow() >= 0){
|
if (query.getPager().getStartRow() >= 0) {
|
||||||
reqBody.put("from", query.getPager().getStartRow());
|
reqBody.put("from", query.getPager().getStartRow());
|
||||||
}
|
}
|
||||||
if(query.getPager().getPageSize() >= 0){
|
if (query.getPager().getPageSize() >= 0) {
|
||||||
reqBody.put("size", query.getPager().getPageSize());
|
reqBody.put("size", query.getPager().getPageSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(query.getStatus() != null){
|
if (query.getStatus() != null) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("status", query.getStatus());
|
param.put("status", query.getStatus());
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
@@ -755,22 +755,24 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
|
|
||||||
queryJson.put("must", jsonList);
|
queryJson.put("must", jsonList);
|
||||||
ArrayList<JSONObject> filterList = new ArrayList<JSONObject>();
|
ArrayList<JSONObject> filterList = new ArrayList<JSONObject>();
|
||||||
|
if (filter.size() > 0) {
|
||||||
filterList.add(filter);
|
filterList.add(filter);
|
||||||
queryJson.put("filter", filterList);
|
queryJson.put("filter", filterList);
|
||||||
|
}
|
||||||
q.put("bool", queryJson);
|
q.put("bool", queryJson);
|
||||||
reqBody.put("query", q);
|
reqBody.put("query", q);
|
||||||
//用户名:密码
|
//用户名:密码
|
||||||
Base64 token = new Base64();
|
Base64 token = new Base64();
|
||||||
String authenticationEncoding = token.encodeAsString(new String(""+ES_USER+":"+ES_PASSWORD+"").getBytes());
|
String authenticationEncoding = token.encodeAsString(new String("" + ES_USER + ":" + ES_PASSWORD + "").getBytes());
|
||||||
HttpRequest request = new HttpRequest();
|
HttpRequest request = new HttpRequest();
|
||||||
Map<String, String> headers = new HashMap<String, String>();
|
Map<String, String> headers = new HashMap<String, String>();
|
||||||
headers.put("Content-Type", "application/json");
|
headers.put("Content-Type", "application/json");
|
||||||
headers.put("Authorization", "Basic "+authenticationEncoding+"");
|
headers.put("Authorization", "Basic " + authenticationEncoding + "");
|
||||||
try {
|
try {
|
||||||
String response = request.postWithBody("http://es.fangjia.com:9200/"+query.getTable()+"/_search?rest_total_hits_as_int=true", reqBody, headers, "UTF-8");
|
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);
|
JSONObject json = JSONObject.fromObject(response);
|
||||||
long time2 = System.currentTimeMillis();
|
long time2 = System.currentTimeMillis();
|
||||||
System.out.println(time2-time1);
|
System.out.println(time2 - time1);
|
||||||
return json;
|
return json;
|
||||||
} catch (HttpRequestException e) {
|
} catch (HttpRequestException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -793,22 +795,22 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
// return results;
|
// return results;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
private List<JSONObject> queryList(SeawaterQuery query){
|
private List<JSONObject> queryList(SeawaterQuery query) {
|
||||||
JSONObject json = query(query);
|
JSONObject json = query(query);
|
||||||
if(!json.containsKey("hits") || !json.getJSONObject("hits").containsKey("hits")){
|
if (!json.containsKey("hits") || !json.getJSONObject("hits").containsKey("hits")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
JSONArray hits = json.getJSONObject("hits").getJSONArray("hits");
|
JSONArray hits = json.getJSONObject("hits").getJSONArray("hits");
|
||||||
List<JSONObject> results = new ArrayList<JSONObject>();
|
List<JSONObject> results = new ArrayList<JSONObject>();
|
||||||
for(int i=0 ;i < hits.size(); i++){
|
for (int i = 0; i < hits.size(); i++) {
|
||||||
JSONObject jsonObject = hits.getJSONObject(i);
|
JSONObject jsonObject = hits.getJSONObject(i);
|
||||||
results.add(jsonObject);
|
results.add(jsonObject);
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int queryCount(String id,String category, String city, String region, String name, List<String> alias,
|
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){
|
List<String> regionAlias, Integer startDate, Integer endDate, Integer room, String root, String sort, boolean order, int start, int limit, String table) {
|
||||||
SeawaterQuery query = new SeawaterQuery();
|
SeawaterQuery query = new SeawaterQuery();
|
||||||
query.setCat(category);
|
query.setCat(category);
|
||||||
query.setCityDisplay(city);
|
query.setCityDisplay(city);
|
||||||
@@ -827,33 +829,33 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
query.setPager(pager);
|
query.setPager(pager);
|
||||||
query.setTable(table);
|
query.setTable(table);
|
||||||
JSONObject json = query(query);
|
JSONObject json = query(query);
|
||||||
if(!json.containsKey("hits") || !json.getJSONObject("hits").containsKey("total")){
|
if (!json.containsKey("hits") || !json.getJSONObject("hits").containsKey("total")) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return json.getJSONObject("hits").getInt("total");
|
return json.getJSONObject("hits").getInt("total");
|
||||||
}
|
}
|
||||||
|
|
||||||
private int queryCount(SeawaterQuery query){
|
private int queryCount(SeawaterQuery query) {
|
||||||
JSONObject json = query(query);
|
JSONObject json = query(query);
|
||||||
if(!json.containsKey("hits") || !json.getJSONObject("hits").containsKey("total")){
|
if (!json.containsKey("hits") || !json.getJSONObject("hits").containsKey("total")) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return json.getJSONObject("hits").getInt("total");
|
return json.getJSONObject("hits").getInt("total");
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject wrapQueryParams(SeawaterQuery query){
|
private JSONObject wrapQueryParams(SeawaterQuery query) {
|
||||||
JSONObject reqBody = new JSONObject();
|
JSONObject reqBody = new JSONObject();
|
||||||
JSONObject q = new JSONObject();
|
JSONObject q = new JSONObject();
|
||||||
JSONObject queryJson = new JSONObject();
|
JSONObject queryJson = new JSONObject();
|
||||||
List<JSONObject> jsonList = new ArrayList<JSONObject>();
|
List<JSONObject> jsonList = new ArrayList<JSONObject>();
|
||||||
if(StringUtils.isNotBlank(query.getId())) {
|
if (StringUtils.isNotBlank(query.getId())) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("_id", query.getId());
|
param.put("_id", query.getId());
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
temp.put("term", param);
|
temp.put("term", param);
|
||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(query.getCat())) {
|
if (StringUtils.isNotBlank(query.getCat())) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("cat", query.getCat());
|
param.put("cat", query.getCat());
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
@@ -862,10 +864,10 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<String> namesList = new LinkedHashSet<String>();
|
Set<String> namesList = new LinkedHashSet<String>();
|
||||||
if(StringUtils.isNotBlank(query.getDistrictName())) {
|
if (StringUtils.isNotBlank(query.getDistrictName())) {
|
||||||
namesList.add(query.getDistrictName());
|
namesList.add(query.getDistrictName());
|
||||||
}
|
}
|
||||||
if(namesList != null && namesList.size() > 0){
|
if (namesList != null && namesList.size() > 0) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("district_name", namesList);
|
param.put("district_name", namesList);
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
@@ -874,13 +876,13 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<String> regionsList = new LinkedHashSet<String>();
|
Set<String> regionsList = new LinkedHashSet<String>();
|
||||||
if(StringUtils.isNotBlank(query.getRegion())) {
|
if (StringUtils.isNotBlank(query.getRegion())) {
|
||||||
regionsList.add(query.getRegion());
|
regionsList.add(query.getRegion());
|
||||||
}
|
}
|
||||||
if (query.getRegionAlias() != null) {
|
if (query.getRegionAlias() != null) {
|
||||||
regionsList.addAll(query.getRegionAlias());
|
regionsList.addAll(query.getRegionAlias());
|
||||||
}
|
}
|
||||||
if(regionsList != null && regionsList.size() > 0){
|
if (regionsList != null && regionsList.size() > 0) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("region", regionsList);
|
param.put("region", regionsList);
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
@@ -888,28 +890,28 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(StringUtils.isNotBlank(query.getCityDisplay())){
|
if (StringUtils.isNotBlank(query.getCityDisplay())) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("city", query.getCityDisplay());
|
param.put("city", query.getCityDisplay());
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
temp.put("term", param);
|
temp.put("term", param);
|
||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(query.getEstateType())) {
|
if (StringUtils.isNotBlank(query.getEstateType())) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("estate_type", query.getEstateType());
|
param.put("estate_type", query.getEstateType());
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
temp.put("term", param);
|
temp.put("term", param);
|
||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
if(query.getRoom() != null) {
|
if (query.getRoom() != null) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("room", query.getRoom());
|
param.put("room", query.getRoom());
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
temp.put("term", param);
|
temp.put("term", param);
|
||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
if(StringUtils.isNotBlank(query.getRootName())) {
|
if (StringUtils.isNotBlank(query.getRootName())) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("root", query.getRootName());
|
param.put("root", query.getRootName());
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
@@ -917,14 +919,14 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(query.getStartDate() != null || query.getEndDate() != null){
|
if (query.getStartDate() != null || query.getEndDate() != null) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
JSONObject temp2 = new JSONObject();
|
JSONObject temp2 = new JSONObject();
|
||||||
if(query.getStartDate() != null){
|
if (query.getStartDate() != null) {
|
||||||
temp2.put("gte", query.getStartDate());
|
temp2.put("gte", query.getStartDate());
|
||||||
}
|
}
|
||||||
if(query.getEndDate() != null){
|
if (query.getEndDate() != null) {
|
||||||
temp2.put("lte", query.getEndDate());
|
temp2.put("lte", query.getEndDate());
|
||||||
}
|
}
|
||||||
param.put("p_date", temp2);
|
param.put("p_date", temp2);
|
||||||
@@ -933,14 +935,14 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(query.getStartArea() != null || query.getEndArea() != null){
|
if (query.getStartArea() != null || query.getEndArea() != null) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
JSONObject temp2 = new JSONObject();
|
JSONObject temp2 = new JSONObject();
|
||||||
if(query.getStartArea() != null){
|
if (query.getStartArea() != null) {
|
||||||
temp2.put("gte", query.getStartArea());
|
temp2.put("gte", query.getStartArea());
|
||||||
}
|
}
|
||||||
if(query.getEndArea() != null){
|
if (query.getEndArea() != null) {
|
||||||
temp2.put("lte", query.getEndArea());
|
temp2.put("lte", query.getEndArea());
|
||||||
}
|
}
|
||||||
param.put("area", temp2);
|
param.put("area", temp2);
|
||||||
@@ -948,14 +950,14 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(query.getStartPrice() != null || query.getEndPrice() != null){
|
if (query.getStartPrice() != null || query.getEndPrice() != null) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
JSONObject temp2 = new JSONObject();
|
JSONObject temp2 = new JSONObject();
|
||||||
if(query.getStartPrice() != null){
|
if (query.getStartPrice() != null) {
|
||||||
temp2.put("gte", query.getStartPrice());
|
temp2.put("gte", query.getStartPrice());
|
||||||
}
|
}
|
||||||
if(query.getEndPrice() != null){
|
if (query.getEndPrice() != null) {
|
||||||
temp2.put("lte", query.getEndPrice());
|
temp2.put("lte", query.getEndPrice());
|
||||||
}
|
}
|
||||||
param.put("avg_price", temp2);
|
param.put("avg_price", temp2);
|
||||||
@@ -963,7 +965,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
jsonList.add(temp);
|
jsonList.add(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(query.getStatus() != null){
|
if (query.getStatus() != null) {
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("status", query.getStatus());
|
param.put("status", query.getStatus());
|
||||||
JSONObject temp = new JSONObject();
|
JSONObject temp = new JSONObject();
|
||||||
|
|||||||
+2
-2
@@ -1150,11 +1150,11 @@ public class HouseController {
|
|||||||
public Object rentAction(final HouseSearchModel model) {
|
public Object rentAction(final HouseSearchModel model) {
|
||||||
RestfulModelAndView mav = new RestfulModelAndView();
|
RestfulModelAndView mav = new RestfulModelAndView();
|
||||||
mav.setViewType("rest");
|
mav.setViewType("rest");
|
||||||
if (model.getSize()<0) {
|
if (model.getSize()!= null && model.getSize()<0) {
|
||||||
mav.setModel(BasicModel.buildBadRequestModel("参数(size)有误"));
|
mav.setModel(BasicModel.buildBadRequestModel("参数(size)有误"));
|
||||||
return mav;
|
return mav;
|
||||||
}
|
}
|
||||||
if (StringUtils.isNotBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()) || StringUtils.isBlank(model.getName())) {
|
if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()) || StringUtils.isBlank(model.getName())) {
|
||||||
mav.setModel(BasicModel.buildBadRequestModel("城市(city),区域(district),小区名(name)为必填参数"));
|
mav.setModel(BasicModel.buildBadRequestModel("城市(city),区域(district),小区名(name)为必填参数"));
|
||||||
return mav;
|
return mav;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user