房源数据修改

This commit is contained in:
xuhe
2022-08-15 11:27:57 +08:00
parent 485cd44eeb
commit 105d71c782
8 changed files with 1007 additions and 28 deletions
@@ -3,6 +3,7 @@ package com.fangjia.bkoff.controllers;
import com.fangjia.bkoff.model.JsonModel;
import com.fangjia.bkoff.model.SeawaterModel;
import com.fangjia.core.RegionData;
import com.fangjia.dal.SeawaterQuery;
import com.fangjia.dal.common.DistrictKey;
import com.fangjia.dal.seawater.model.Seawater;
import com.fangjia.dal.seaweed.dao.DistrictDao;
@@ -13,6 +14,7 @@ import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
import org.sothis.core.util.Pager;
import org.sothis.web.mvc.annotation.Param;
import org.springframework.beans.BeanUtils;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
@@ -49,6 +51,8 @@ public class SeawaterController {
pager.setTotalRows(0);
}
}else {
SeawaterQuery query = new SeawaterQuery();
BeanUtils.copyProperties(model, query, new String[] {"sortField", "regionAlias", "districtAlias", "keys", "table"});
String sort = model.getSort();
String sortField = null;
boolean order = false;
@@ -62,6 +66,8 @@ public class SeawaterController {
if (sortField == null) {
sortField = "p_date";
}
query.setOrder(order);
query.setSortField(sortField);
List<String> regionAlias = null;
List<String> districtAlias = null;
@@ -80,9 +86,15 @@ public class SeawaterController {
regionAlias = RegionData.getRegionAlias(city, model.getRegion());
}
query.setDistrictAlias(districtAlias);
query.setRegionAlias(regionAlias);
query.setTable("seawater");
// pager.setTotalRows((int) seawaterService.findSeawatersCountFromEs(model.getCat(), city, model.getRegion(),model.getDistrictName(), districtAlias, regionAlias, model.getStartDate(), model.getEndDate(), model.getRoom(), model.getRootName(),"seawater"));
// List<Seawater> seawaterList = seawaterService.findSeawatersFromEs(model.getCat(), city, model.getRegion(),model.getDistrictName(), districtAlias, regionAlias, model.getStartDate(), model.getEndDate(), model.getRoom(), model.getRootName(), sortField, order, pager.getStartRow(), pager.getPageSize(), null,"seawater");
pager.setTotalRows((int)seawaterService.findSeawatersCountByQuery(query));
List<Seawater> seawaterList = seawaterService.findSeawatersByQuery(query);
pager.setTotalRows((int) seawaterService.findSeawatersCountFromEs(model.getCat(), city, model.getRegion(),model.getDistrictName(), districtAlias, regionAlias, model.getStartDate(), model.getEndDate(), model.getRoom(), model.getRootName(),"seawater"));
List<Seawater> seawaterList = seawaterService.findSeawatersFromEs(model.getCat(), city, model.getRegion(),model.getDistrictName(), districtAlias, regionAlias, model.getStartDate(), model.getEndDate(), model.getRoom(), model.getRootName(), sortField, order, pager.getStartRow(), pager.getPageSize(), null,"seawater");
Map<String, String> tagsMap = new HashMap<String, String>();
for(Seawater seawater : seawaterList) {
if(StringUtils.isBlank(seawater.getName())){
@@ -125,6 +137,58 @@ public class SeawaterController {
return ret;
}
/**
* 按条件批量删除数据(小区名称只匹配主名不匹配别名,查询时匹配别名)
* @param model
* @return
*/
public Object batchDeleteByParamsAction(SeawaterModel model) {
JsonModel ret = new JsonModel();
String city = model.getCityDisplay();
if(StringUtils.isBlank(model.getCat())) {
model.setCat("sell");
}
SeawaterQuery query = new SeawaterQuery();
BeanUtils.copyProperties(model, query, new String[] {"sortField", "regionAlias", "districtAlias", "keys", "table"});
List<String> regionAlias = null;
model.setDistrictName(model.getDistrictName().trim());
if(StringUtils.isNotBlank(model.getRegion())) {
regionAlias = RegionData.getRegionAlias(city, model.getRegion());
}
query.setRegionAlias(regionAlias);
query.setTable("seawater");
seawaterService.batchDeleteByParams(query);
return ret;
}
/**
* 按条件批量修改物业类型(小区名称只匹配主名不匹配别名,查询时匹配别名)
* @param model
* @return
*/
public Object batchUpdateEstateTypeAction(SeawaterModel model) {
JsonModel ret = new JsonModel();
String city = model.getCityDisplay();
if(StringUtils.isBlank(model.getCat())) {
model.setCat("sell");
}
SeawaterQuery query = new SeawaterQuery();
BeanUtils.copyProperties(model, query, new String[] {"sortField", "regionAlias", "districtAlias", "keys", "table"});
List<String> regionAlias = null;
model.setDistrictName(model.getDistrictName().trim());
if(StringUtils.isNotBlank(model.getRegion())) {
regionAlias = RegionData.getRegionAlias(city, model.getRegion());
}
query.setRegionAlias(regionAlias);
query.setTable("seawater");
seawaterService.batchUpdateEstateType(query);
return ret;
}
public void setSeawaterService(SeawaterService seawaterService) {
this.seawaterService = seawaterService;
}
@@ -35,12 +35,19 @@ public class SeawaterModel extends BaseModel {
private Seawater seawater;
private List<Seawater> seawaterList;
private Map<String, String> tagsMap;
private Integer order;
private Boolean order;
private Integer StartDate;
private Integer endDate;
private String sort;
private String url;
private String rootName;
private String estateType;
private Double startArea;
private Double endArea;
private Integer startPrice;
private Integer endPrice;
private Integer status;
private String editEstateType;
public String getId() {
return id;
}
@@ -156,10 +163,10 @@ public class SeawaterModel extends BaseModel {
public void setCityDisplay(String cityDisplay) {
this.cityDisplay = cityDisplay;
}
public Integer getOrder() {
public Boolean getOrder() {
return order;
}
public void setOrder(Integer order) {
public void setOrder(Boolean order) {
this.order = order;
}
@@ -220,4 +227,60 @@ public class SeawaterModel extends BaseModel {
public void setTagsMap(Map<String, String> tagsMap) {
this.tagsMap = tagsMap;
}
public String getEstateType() {
return estateType;
}
public void setEstateType(String estateType) {
this.estateType = estateType;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
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 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 String getEditEstateType() {
return editEstateType;
}
public void setEditEstateType(String editEstateType) {
this.editEstateType = editEstateType;
}
}
@@ -72,7 +72,9 @@
</select>
<label for="districtName">名称:</label>
<input type="text" name="districtName" id="districtName" class="input-medium" style="margin-top:9px;" value="${districtName!}" ></input>
<label for="cat">类型:</label>
<label for="estateType">物业类型:</label>
<input type="text" name="estateType" id="estateType" class="input-medium" style="margin-top:9px;" value="${estateType!}" ></input>
<label for="cat">类型:</label>
<select id="cat" name="cat" class="form-control" style="width: 110px;">
<option value="">不限</option>
<option <#if cat! == 'sell'>selected</#if> value="sell">二手房</option>
@@ -98,13 +100,29 @@
<option <#if room?? && room==9>selected="true"</#if> value="9">9室</option>
</select>
</span>
<label for="districtName">网站:</label>
<label for="status">状态:</label>
<select id="status" name="status" class="form-control" style="width: 80px;">
<option value="">不限</option>
<option <#if status?? && status==0>selected="true"</#if> value="0">正常</option>
<option <#if status?? && status==1>selected="true"</#if> value="1">已删除</option>
</select>
<label for="rootName">网站:</label>
<input type="text" name="rootName" id="rootName" class="input-medium" style="margin-top:9px;" value="${rootName!}" ></input>
<label for="startDate">时间:</label>
<input id="startDate" placeholder="开始时间" class="form-control" style="width:70px;" name="startDate" value="${startDate!}" onfocus="WdatePicker({dateFmt:'yyyyMMdd',maxDate:'#F{$dp.$D(\'endDate\')||\'%y-%M-%d\'}',minDate:'2007-1-1'})" />-
<input id="endDate" placeholder="结束时间" class="form-control" style="width:70px;" name="endDate" value="${endDate!}" onfocus="WdatePicker({dateFmt:'yyyyMMdd',maxDate:'%y-%M-%d',minDate:'#F{$dp.$D(\'startDate\')||\'2007-1-1\'}'})"/>
<label for="area">面积:</label>
<input class="form-control" style="width:50px;" name="startArea" id="startArea" value="${startArea!}"/>-
<input class="form-control" style="width:50px;" name="endArea" id="endArea" value="${endArea!}"/>
<label for="area">单价:</label>
<input class="form-control" style="width:50px;" name="startPrice" id="startPrice" value="${startPrice!}"/>-
<input class="form-control" style="width:50px;" name="endPrice" id="endPrice" value="${endPrice!}"/>
<input id="queryBtn" class ="btn btn-primary" type="submit" value="查询" />
<input class ="btn btn-primary" id="batchDeleteByParam" value="条件删除" style="width: 75px;"/>
<input class ="btn btn-primary" id="batchUpdateEstateType" value="批量修改物业类型" style="width: 120px;"/>
</form>
</td>
</tr>
@@ -142,6 +160,7 @@
<th style="width:70px;">朝向</th>
<th style="width:70px;">物业类型</th>
<th style="width:90px;">来源</th>
<th style="width:90px;">状态</th>
<th style="width:80px;">操作</th>
</tr>
<#if seawaterList??>
@@ -173,7 +192,7 @@
</#if>
</td>
<td>${it.area!'&nbsp;'}</td>
<td>${(it.totalPrice / it.area)?string('#')}</td>
<td>${it.avgPrice!'&nbsp;'}</td>
<td>${it.totalPrice!'&nbsp;'}</td>
<td>${it.pDate!}</td>
<td>${it.room!'-'}/${it.hall!'-'}/${it.toilet!'-'}</td>
@@ -189,6 +208,13 @@
--
</#if>
</td>
<td>
<#if it.status == 0>
正常
<#else>
已删除
</#if>
</td>
<td>
<a href="javascript:;" class="hrefClick" <#if it.name??>detail-name="${it.name}"</#if> <#if it.address??>detail-address="${it.address!}"</#if><#if it.mobile??>detail-mobile="${it.mobile}"</#if><#if it.category??>detail-category="${it.category}"</#if>>详情</a>
<a href="javascript:;" name="todelete" detail-id="${it.id!}">删除</a>
@@ -219,7 +245,26 @@
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true" aria-hidden="true">关闭</button>
</div>
</div>
</div>
<div id="estateTypeModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">修改物业类型</h3>
</div>
<form class="form-horizontal" id="editEstateTypeForm">
<div class="control-group" style="margin-top: 20px;">
<label class="control-label" for="cityPop">物业类型</label>
<div class="controls">
<input type="text" id="editEstateType" name="editEstateType" value=""/>
</div>
</div>
</form>
<div class="modal-footer">
<button class="btn btn-primary" id="editSubmit">修改</button>
<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
</div>
</div>
</body>
<script type="text/javascript" src="../js/jquery.editable.js?v=${version}"></script>
@@ -385,6 +430,106 @@
}
});
$("#batchDeleteByParam").click(function(){
if(confirm('确认要删除当前查询条件下的所有数据吗?')) {
var cityDisplay = $("input[name='cityDisplay']").val()
var region = $("select[name='region']").val()
var districtName = $("input[name='districtName']").val()
var estateType = $("input[name='estateType']").val()
var cat = $("select[name='cat']").val()
var status = $("select[name='status']").val()
var rootName = $("input[name='rootName']").val()
var startDate = $("input[name='startDate']").val()
var endDate = $("input[name='endDate']").val()
var startArea = $("input[name='startArea']").val()
var endArea = $("input[name='endArea']").val()
var startPrice = $("input[name='startPrice']").val()
var endPrice = $("input[name='endPrice']").val()
if(cityDisplay == "" || region == "" || districtName == ""){
alert("城市、区域、小区名称必填")
return false;
}
var data = {"cityDisplay": cityDisplay, "region": region, "districtName": districtName,
"estateType": estateType, "cat": cat, "status": status,
"rootName": rootName, "startDate": startDate, "endDate": endDate,
"startArea": startArea, "endArea": endArea, "startPrice": startPrice,
"endPrice": endPrice}
jQuery.ajax({
type: 'POST',
url: '../seawater/batchDeleteByParams',
data: data,
dataType: 'json',
timeout: 100000,
success: function(model) {
alert("批量删除操作成功");
location.reload();
},
error : function() {
}
});
}
});
$("#batchUpdateEstateType").click(function(){
$('#estateTypeModal').modal('show');
});
$("#editSubmit").click(function(){
var editEstateType = $("input[name='editEstateType']").val()
if(editEstateType == ""){
alert("物业类型必填")
return false;
}
if(confirm('确认要修改当前查询条件下的物业类型吗?')) {
var cityDisplay = $("input[name='cityDisplay']").val()
var region = $("select[name='region']").val()
var districtName = $("input[name='districtName']").val()
var estateType = $("input[name='estateType']").val()
var cat = $("select[name='cat']").val()
var status = $("select[name='status']").val()
var rootName = $("input[name='rootName']").val()
var startDate = $("input[name='startDate']").val()
var endDate = $("input[name='endDate']").val()
var startArea = $("input[name='startArea']").val()
var endArea = $("input[name='endArea']").val()
var startPrice = $("input[name='startPrice']").val()
var endPrice = $("input[name='endPrice']").val()
if(cityDisplay == "" || region == "" || districtName == ""){
alert("城市、区域、小区名称必填")
return false;
}
console.log(startArea)
console.log(endArea)
console.log(startPrice)
console.log(endPrice)
console.log(estateType)
if(startArea == "" && endArea == "" && startPrice == "" && endPrice == "" && estateType == ""){
alert("面积,价格,物业类型必须至少一项有值")
return false;
}
var data = {"cityDisplay": cityDisplay, "region": region, "districtName": districtName,
"estateType": estateType, "cat": cat, "status": status,
"rootName": rootName, "startDate": startDate, "endDate": endDate,
"startArea": startArea, "endArea": endArea, "startPrice": startPrice,
"endPrice": endPrice, "editEstateType": editEstateType}
jQuery.ajax({
type: 'POST',
url: '../seawater/batchUpdateEstateType',
data: data,
dataType: 'json',
timeout: 100000,
success: function(model) {
alert("批量修改操作成功");
location.reload();
},
error : function() {
alert("批量修改操作失败");
location.reload();
}
});
$('#estateTypeModal').modal('hide');
}
});
</script>
</html>
</#compress>
@@ -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);
}
@@ -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();
@@ -256,6 +334,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;
@@ -431,29 +512,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;
}
}
@@ -4,6 +4,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import com.fangjia.dal.SeawaterQuery;
import com.fangjia.dal.seawater.model.Seawater;
public interface SeawaterService {
@@ -37,9 +38,16 @@ public interface SeawaterService {
*/
void deleteByIds(String ids);
void batchDeleteByParams(SeawaterQuery query);
void batchUpdateEstateType(SeawaterQuery query);
@Deprecated
List<Seawater> findAllSeawater(String category, String city, String name, String region, Integer room, String root, String sort, Integer startDate, Integer endDate, int start, int limit, boolean order, String[] fields);
@Deprecated
int findAllSeawaterCount(String category, String city, String name, String region, Integer room, String root, Integer startDate, Integer endDate);
List<Seawater> findSeawatersByQuery(SeawaterQuery query);
long findSeawatersCountByQuery(SeawaterQuery query);
}
@@ -1,5 +1,6 @@
package com.fangjia.service.mongo.fangjia;
import com.fangjia.dal.SeawaterQuery;
import com.fangjia.dal.seawater.dao.SeawaterDao;
import com.fangjia.dal.seawater.model.Seawater;
import com.fangjia.datastore.driver.DSCollection;
@@ -191,6 +192,16 @@ public class SeawaterServiceImpl implements SeawaterService {
seawaterDao.deleteByIds(Arrays.asList(idArr));
}
@Override
public void batchDeleteByParams(SeawaterQuery query) {
seawaterDao.batchDeleteByParams(query);
}
@Override
public void batchUpdateEstateType(SeawaterQuery query) {
seawaterDao.batchUpdateEstateType(query);
}
public void setSeawaterDao(SeawaterDao seawaterDao) {
this.seawaterDao = seawaterDao;
}
@@ -237,7 +248,13 @@ public class SeawaterServiceImpl implements SeawaterService {
sort,order,start,limit,table);
}
@Override
public List<Seawater> findSeawatersByQuery(SeawaterQuery query){
return seawaterDao.findSeawatersByQuery(query);
}
@Override
public long findSeawatersCountByQuery(SeawaterQuery query){
return seawaterDao.findSeawatersCountByQuery(query);
}
}