/house/around接口
This commit is contained in:
@@ -32,6 +32,12 @@ public class SeawaterQuery {
|
|||||||
private Pager pager;
|
private Pager pager;
|
||||||
private String editEstateType;
|
private String editEstateType;
|
||||||
|
|
||||||
|
private Double lat;
|
||||||
|
|
||||||
|
private Double lng;
|
||||||
|
|
||||||
|
private Integer radius;
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@@ -239,4 +245,28 @@ public class SeawaterQuery {
|
|||||||
public void setEditEstateType(String editEstateType) {
|
public void setEditEstateType(String editEstateType) {
|
||||||
this.editEstateType = editEstateType;
|
this.editEstateType = editEstateType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Double getLat() {
|
||||||
|
return lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLat(Double lat) {
|
||||||
|
this.lat = lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getLng() {
|
||||||
|
return lng;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLng(Double lng) {
|
||||||
|
this.lng = lng;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getRadius() {
|
||||||
|
return radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRadius(Integer radius) {
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -554,6 +554,37 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
|||||||
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>();
|
||||||
|
Double lat = query.getLat();
|
||||||
|
Double lng = query.getLng();
|
||||||
|
Integer radius = query.getRadius();
|
||||||
|
if (lat != null && lng != null && radius != null) {
|
||||||
|
// 1. 设置地理位置参数
|
||||||
|
JSONObject geoDistanceParam = new JSONObject();
|
||||||
|
geoDistanceParam.put("lat", lat);
|
||||||
|
geoDistanceParam.put("lon", lng);
|
||||||
|
|
||||||
|
// 2. 设置 geo_distance 过滤器,限制结果在指定的半径范围内
|
||||||
|
JSONObject geoDistanceFilter = new JSONObject();
|
||||||
|
JSONObject geoDistance = new JSONObject();
|
||||||
|
geoDistance.put("distance", radius + "m"); // 半径设置为 3000km
|
||||||
|
geoDistance.put("location", geoDistanceParam); // 使用给定的经纬度
|
||||||
|
geoDistanceFilter.put("geo_distance", geoDistance);
|
||||||
|
|
||||||
|
// 3. 构建查询体
|
||||||
|
reqBody.put("query", new JSONObject().put("filter", geoDistanceFilter));
|
||||||
|
// 4. 添加按距离排序的部分
|
||||||
|
JSONObject geoDistanceSort = new JSONObject();
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("order", "asc");
|
||||||
|
jsonObject.put("location", geoDistanceParam);
|
||||||
|
jsonObject.put("unit", "m");
|
||||||
|
jsonObject.put("distance_type", "arc");
|
||||||
|
geoDistanceSort.put("_geo_distance", jsonObject);
|
||||||
|
// 5. 将排序部分添加到请求体
|
||||||
|
List<JSONObject> sortJsonList = new ArrayList<JSONObject>();
|
||||||
|
sortJsonList.add(geoDistanceSort);
|
||||||
|
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());
|
||||||
|
|||||||
+105
-51
@@ -4,6 +4,7 @@ import com.fangjia.core.util.*;
|
|||||||
import com.fangjia.dal.FacetQuery;
|
import com.fangjia.dal.FacetQuery;
|
||||||
import com.fangjia.dal.FacetQueryResult;
|
import com.fangjia.dal.FacetQueryResult;
|
||||||
import com.fangjia.dal.QueryParam;
|
import com.fangjia.dal.QueryParam;
|
||||||
|
import com.fangjia.dal.SeawaterQuery;
|
||||||
import com.fangjia.dal.common.DistrictKey;
|
import com.fangjia.dal.common.DistrictKey;
|
||||||
import com.fangjia.dal.common.ServerAreaData;
|
import com.fangjia.dal.common.ServerAreaData;
|
||||||
import com.fangjia.dal.datastore.model.House;
|
import com.fangjia.dal.datastore.model.House;
|
||||||
@@ -61,10 +62,12 @@ import net.sf.json.JSONObject;
|
|||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
import org.sothis.core.util.Closure;
|
import org.sothis.core.util.Closure;
|
||||||
|
import org.sothis.core.util.Pager;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -894,6 +897,22 @@ public class HouseController {
|
|||||||
public Object aroundAction(final HouseSearchModel model) {
|
public Object aroundAction(final HouseSearchModel model) {
|
||||||
RestfulModelAndView mav = new RestfulModelAndView();
|
RestfulModelAndView mav = new RestfulModelAndView();
|
||||||
mav.setViewType("rest");
|
mav.setViewType("rest");
|
||||||
|
// 获取当前日期
|
||||||
|
Calendar today = Calendar.getInstance();
|
||||||
|
|
||||||
|
// 复制一份当前日期,用于计算半年前的日期
|
||||||
|
Calendar sixMonthsAgo = (Calendar) today.clone();
|
||||||
|
|
||||||
|
// 减去 6 个月
|
||||||
|
sixMonthsAgo.add(Calendar.MONTH, -6);
|
||||||
|
|
||||||
|
// 格式化日期为 yyyyMMdd
|
||||||
|
int todayInt = formatDate(today);
|
||||||
|
int sixMonthsAgoInt = formatDate(sixMonthsAgo);
|
||||||
|
model.setStartTime(sixMonthsAgoInt);
|
||||||
|
model.setEndTime(todayInt);
|
||||||
|
// 默认3000M内
|
||||||
|
model.setRadius(3000);
|
||||||
if (StringUtils.isBlank(model.getLocation())) {
|
if (StringUtils.isBlank(model.getLocation())) {
|
||||||
mav.setModel(BasicModel.buildBadRequestModel("location(经纬度)不能为空"));
|
mav.setModel(BasicModel.buildBadRequestModel("location(经纬度)不能为空"));
|
||||||
return mav;
|
return mav;
|
||||||
@@ -922,21 +941,14 @@ public class HouseController {
|
|||||||
category = "shop";
|
category = "shop";
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Seaweed> seaweedList = seaweedService.findSeaweedByLocation(lat, lng, 3000, category);
|
|
||||||
if (seaweedList == null || seaweedList.isEmpty()) {
|
|
||||||
mav.setModel(BasicModel.buildBadRequestModel("没有找到相关的楼盘"));
|
|
||||||
return mav;
|
|
||||||
}
|
|
||||||
String cat = "sell";
|
String cat = "sell";
|
||||||
if ("1".equals(model.getHouseType())) {
|
if ("1".equals(model.getHouseType())) {
|
||||||
if ("0".equals(model.getPropertyType())) {
|
|
||||||
cat = "rent";
|
|
||||||
}
|
|
||||||
if ("1".equals(model.getPropertyType())) {
|
if ("1".equals(model.getPropertyType())) {
|
||||||
cat = "office_rent";
|
cat = "office_rent";
|
||||||
}
|
} else if ("2".equals(model.getPropertyType())) {
|
||||||
if ("2".equals(model.getPropertyType())) {
|
|
||||||
cat = "shop_rent";
|
cat = "shop_rent";
|
||||||
|
} else {
|
||||||
|
cat = "rent";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ("1".equals(model.getPropertyType())) {
|
if ("1".equals(model.getPropertyType())) {
|
||||||
@@ -946,54 +958,86 @@ public class HouseController {
|
|||||||
cat = "shop_sell";
|
cat = "shop_sell";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<Seawater> houses;
|
List<Seawater> houses = null;
|
||||||
List<Seawater> houseList = new ArrayList<Seawater>();
|
List<Seawater> houseList = new ArrayList<Seawater>();
|
||||||
for (Seaweed seaweed : seaweedList) {
|
if (cat.contains("_")) {
|
||||||
|
// 商铺,写字楼有经纬度,直接查
|
||||||
|
SeawaterQuery query = new SeawaterQuery();
|
||||||
|
query.setLat(lat);
|
||||||
|
query.setLng(lng);
|
||||||
|
query.setCat(cat);
|
||||||
|
query.setRadius(model.getRadius());
|
||||||
|
query.setStartDate(model.getStartTime());
|
||||||
|
query.setEndDate(model.getEndTime());
|
||||||
if (model.getSize() != null && model.getSize() != 0) {
|
if (model.getSize() != null && model.getSize() != 0) {
|
||||||
Double size = model.getSize();
|
query.setStartArea(model.getSize() * 0.9);
|
||||||
houses = seawaterDao.findSeawatersFromEs(cat, seaweed.getCity(), seaweed.getRegion(), seaweed.getName(), seaweed.getAlias(), null,
|
query.setEndArea(model.getSize() * 1.1);
|
||||||
model.getStartTime(), model.getEndTime(), 0.9 * size, 1.1 * size, null, null, null, null,
|
|
||||||
"p_date", false, 0, 5, "latest_seawater");
|
|
||||||
} else {
|
|
||||||
houses = seawaterDao.findSeawatersFromEs(cat, seaweed.getCity(), seaweed.getRegion(), seaweed.getName(), seaweed.getAlias(), null,
|
|
||||||
model.getStartTime(), model.getEndTime(), null, null, null, null, null, null,
|
|
||||||
"p_date", false, 0, 5, "latest_seawater");
|
|
||||||
}
|
}
|
||||||
for (Seawater house : houses) {
|
query.setCityDisplay(model.getCity());
|
||||||
Seawater seawater = new Seawater();
|
Pager pager = new Pager();
|
||||||
seawater.setCity(house.getCity());
|
pager.setStartRow(0);
|
||||||
seawater.setDistrict(house.getRegion());
|
pager.setPageSize(5);
|
||||||
seawater.setAddress(house.getAddress());
|
query.setPager(pager);
|
||||||
seawater.setName(house.getDistrictName());
|
query.setTable("latest_seawater");
|
||||||
seawater.setSize(house.getArea());
|
houses = seawaterDao.findSeawatersByQuery(query);
|
||||||
seawater.setUnitPrice(house.getAvgPrice());
|
if (houses != null && !houses.isEmpty()) {
|
||||||
seawater.setTotalPrice(house.getTotalPrice());
|
for (Seawater house : houses) {
|
||||||
seawater.setDirection(house.getDirection());
|
Seawater seawater = new Seawater();
|
||||||
seawater.setFloor(house.getFloor());
|
seawater.setCity(house.getCity());
|
||||||
seawater.setMaxFloor(house.getHeight());
|
seawater.setDistrict(house.getRegion());
|
||||||
seawater.setRoom(house.getRoom());
|
seawater.setAddress(house.getAddress());
|
||||||
seawater.setHall(house.getHall());
|
seawater.setName(house.getDistrictName());
|
||||||
seawater.setToilet(house.getToilet());
|
seawater.setSize(house.getArea());
|
||||||
seawater.setDecoration(house.getFitment());
|
seawater.setUnitPrice(house.getAvgPrice());
|
||||||
if (house.getpDate() != null && house.getpDate() > 10000000) {
|
seawater.setTotalPrice(house.getTotalPrice());
|
||||||
String numberStr = String.valueOf(house.getpDate());
|
seawater.setDirection(house.getDirection());
|
||||||
// 拆分字符串并格式化
|
seawater.setFloor(house.getFloor());
|
||||||
String year = numberStr.substring(0, 4); // 前四位是年份
|
seawater.setMaxFloor(house.getHeight());
|
||||||
String month = numberStr.substring(4, 6); // 中间两位是月份
|
seawater.setRoom(house.getRoom());
|
||||||
String day = numberStr.substring(6, 8); // 最后两位是日期
|
seawater.setHall(house.getHall());
|
||||||
String formattedDate = year + "-" + month + "-" + day;
|
seawater.setToilet(house.getToilet());
|
||||||
seawater.setPublishDate(formattedDate);
|
seawater.setDecoration(house.getFitment());
|
||||||
|
if (house.getpDate() != null && house.getpDate() > 10000000) {
|
||||||
|
String numberStr = String.valueOf(house.getpDate());
|
||||||
|
// 拆分字符串并格式化
|
||||||
|
String year = numberStr.substring(0, 4); // 前四位是年份
|
||||||
|
String month = numberStr.substring(4, 6); // 中间两位是月份
|
||||||
|
String day = numberStr.substring(6, 8); // 最后两位是日期
|
||||||
|
String formattedDate = year + "-" + month + "-" + day;
|
||||||
|
seawater.setPublishDate(formattedDate);
|
||||||
|
}
|
||||||
|
houseList.add(seawater);
|
||||||
}
|
}
|
||||||
if (houseList.size() > 4) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
houseList.add(seawater);
|
|
||||||
}
|
}
|
||||||
if (houseList.size() > 4) {
|
} else {
|
||||||
break;
|
List<House> nearestHasHouseByLocation = houseService.findNearestHasHouseByLocation(model.getCity(), lat, lng, cat, model.getRadius(), 5);
|
||||||
|
if (nearestHasHouseByLocation != null && !nearestHasHouseByLocation.isEmpty()) {
|
||||||
|
for (House house : nearestHasHouseByLocation) {
|
||||||
|
Seawater seawater = new Seawater();
|
||||||
|
seawater.setCity(house.getCity());
|
||||||
|
seawater.setDistrict(house.getRegion());
|
||||||
|
seawater.setAddress(house.getAddress());
|
||||||
|
seawater.setName(house.getDistrictName());
|
||||||
|
seawater.setSize(house.getArea());
|
||||||
|
seawater.setUnitPrice(house.getAvgPrice());
|
||||||
|
seawater.setTotalPrice(house.getTotalPrice());
|
||||||
|
seawater.setDirection(house.getDirection());
|
||||||
|
seawater.setFloor(house.getFloor());
|
||||||
|
seawater.setMaxFloor(house.getHeight());
|
||||||
|
seawater.setRoom(house.getRoom());
|
||||||
|
seawater.setHall(house.getHall());
|
||||||
|
seawater.setToilet(house.getToilet());
|
||||||
|
seawater.setDecoration(house.getFitment());
|
||||||
|
if (house.getPublishDate() != null) {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
seawater.setPublishDate(sdf.format(house.getPublishDate()));
|
||||||
|
}
|
||||||
|
houseList.add(seawater);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BasicModel basicModel = new BasicModel(200, "ok");
|
BasicModel basicModel = new BasicModel(200, "ok");
|
||||||
// 组装数据
|
// 组装数据
|
||||||
basicModel.setResult(houseList);
|
basicModel.setResult(houseList);
|
||||||
@@ -1002,6 +1046,16 @@ public class HouseController {
|
|||||||
return mav;
|
return mav;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 格式化日期为 yyyyMMdd
|
||||||
|
private static int formatDate(Calendar calendar) {
|
||||||
|
int year = calendar.get(Calendar.YEAR);
|
||||||
|
int month = calendar.get(Calendar.MONTH) + 1; // 月份是从 0 开始的
|
||||||
|
int day = calendar.get(Calendar.DAY_OF_MONTH);
|
||||||
|
|
||||||
|
// 返回格式化后的整数
|
||||||
|
return year * 10000 + month * 100 + day;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Object caseAction(@Valid SampleQuery sampleQuery) {
|
public Object caseAction(@Valid SampleQuery sampleQuery) {
|
||||||
|
|
||||||
|
|||||||
+9
-9
@@ -992,7 +992,7 @@ public class DistrictServiceImpl implements DistrictService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据QueryBean查询符合条件的小区数量
|
* 根据QueryBean查询符合条件的小区数量
|
||||||
*
|
*
|
||||||
* @param districtQueryBean
|
* @param districtQueryBean
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -1067,7 +1067,7 @@ public class DistrictServiceImpl implements DistrictService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param keyList
|
* @param keyList
|
||||||
* List<DistrictKey>
|
* List<DistrictKey>
|
||||||
* @param isNewDistrict
|
* @param isNewDistrict
|
||||||
@@ -1098,7 +1098,7 @@ public class DistrictServiceImpl implements DistrictService {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param districtKey
|
* @param districtKey
|
||||||
* DistrictKey
|
* DistrictKey
|
||||||
* @param isNewDistrict
|
* @param isNewDistrict
|
||||||
@@ -1171,7 +1171,7 @@ public class DistrictServiceImpl implements DistrictService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找小区
|
* 查找小区
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private District doFindDistrict(DistrictKey key, String cat) {
|
private District doFindDistrict(DistrictKey key, String cat) {
|
||||||
@@ -1203,7 +1203,7 @@ public class DistrictServiceImpl implements DistrictService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找小区
|
* 查找小区
|
||||||
*
|
*
|
||||||
* @param key
|
* @param key
|
||||||
* DistrictKey
|
* DistrictKey
|
||||||
* @param isNewDistrict
|
* @param isNewDistrict
|
||||||
@@ -1252,7 +1252,7 @@ public class DistrictServiceImpl implements DistrictService {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see com.fangjia.service.datastore.DistrictService#processDistrictInfo(java
|
* @see com.fangjia.service.datastore.DistrictService#processDistrictInfo(java
|
||||||
* .util.List, java.lang.String)
|
* .util.List, java.lang.String)
|
||||||
*/
|
*/
|
||||||
@@ -2226,13 +2226,13 @@ public class DistrictServiceImpl implements DistrictService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找周边最相似的楼盘
|
* 查找周边最相似的楼盘
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* 相似条件
|
* 相似条件
|
||||||
* |建筑类型(estate_type2)相同或包含
|
* |建筑类型(estate_type2)相同或包含
|
||||||
* |建筑年代最多差5年
|
* |建筑年代最多差5年
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param district
|
* @param district
|
||||||
* @param radiusMeters
|
* @param radiusMeters
|
||||||
* @param limit
|
* @param limit
|
||||||
@@ -2431,7 +2431,7 @@ public class DistrictServiceImpl implements DistrictService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 查找最近的楼盘
|
* 查找最近的楼盘
|
||||||
*
|
*
|
||||||
* @param district
|
* @param district
|
||||||
* @param radiusMeters
|
* @param radiusMeters
|
||||||
* @param limit
|
* @param limit
|
||||||
|
|||||||
@@ -469,4 +469,6 @@ public interface HouseService extends ModeService<String, HouseBo> {
|
|||||||
long findHouseByYearMonth(String city, String region, String districtName, int yearMonth);
|
long findHouseByYearMonth(String city, String region, String districtName, int yearMonth);
|
||||||
|
|
||||||
HashMap<String, Object> findHouseStat(District districtKey, Integer avgPrice);
|
HashMap<String, Object> findHouseStat(District districtKey, Integer avgPrice);
|
||||||
|
|
||||||
|
List<House> findNearestHasHouseByLocation(String city, Double lat,Double lng,String cat, int radiusMeters, int limit);
|
||||||
}
|
}
|
||||||
|
|||||||
+20
@@ -2612,5 +2612,25 @@ public class HouseServiceImpl implements HouseService {
|
|||||||
CacheUtils.putValue(CacheUtils.CachePolicyEnum.MIDDLE, HouseServiceImpl.class, key, value);
|
CacheUtils.putValue(CacheUtils.CachePolicyEnum.MIDDLE, HouseServiceImpl.class, key, value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public List<House> findNearestHasHouseByLocation(String city,Double lat, Double lng, String cat,int radiusMeters, int limit) {
|
||||||
|
if (lat == null || lng == null || lat <= 0 ||lng <= 0) {
|
||||||
|
return Collections.EMPTY_LIST;
|
||||||
|
}
|
||||||
|
List<QueryParam> params = new ArrayList<QueryParam>();
|
||||||
|
// params.add(new QueryParam("cat", cat));
|
||||||
|
if (StringUtils.isNotBlank(city)){
|
||||||
|
params.add(new QueryParam("city", city));
|
||||||
|
}
|
||||||
|
SdQuery sdQuery = new SdQuery();
|
||||||
|
sdQuery.setPoint(lat + "," + lng);
|
||||||
|
sdQuery.setField("lat_lng");
|
||||||
|
// sdQuery.setDistance(String.valueOf((double) radiusMeters / 1000.0));
|
||||||
|
sdQuery.setDistance(String.valueOf(radiusMeters));
|
||||||
|
params.add(new QueryParam(QueryParam.SD_PARAM_NAME, sdQuery));
|
||||||
|
// List<SortParam> sortParams = Arrays.asList(new SortParam("distance", true));
|
||||||
|
List<House> list = houseDao.findAllByParams(params, null, 0, limit);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user