/house/around 完善
This commit is contained in:
+20
-10
@@ -15,11 +15,11 @@ import net.sf.json.JSONObject;
|
||||
import org.sothis.core.util.Pager;
|
||||
|
||||
public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> implements SeawaterDao {
|
||||
|
||||
|
||||
|
||||
|
||||
private static final String ES_USER = "developer";
|
||||
private static final String ES_PASSWORD = "5e8edd851d2fdfbd7415232c67367cc3";
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public long findSeawatersCountFromEs(String category, String city, String region, String name, List<String> alias,
|
||||
@@ -267,6 +267,10 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
seawater.setCity(source.getString("city"));
|
||||
seawater.setRegion(source.getString("region"));
|
||||
seawater.setDistrictName(source.getString("district_name"));
|
||||
if (source.containsKey("location")){
|
||||
String location = source.getJSONObject("location").getString("lon") + "," + source.getJSONObject("location").getString("lat");
|
||||
seawater.setLocation(location);
|
||||
}
|
||||
if(source.containsKey("address")){
|
||||
seawater.setAddress(source.getString("address"));
|
||||
}
|
||||
@@ -372,11 +376,16 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
if(source.containsKey("elevator")){
|
||||
seawater.setElevator(source.getString("elevator"));
|
||||
}
|
||||
try {
|
||||
seawater.setDistance((int)jsonList.get(i).getJSONArray("sort").getDouble(0));
|
||||
}catch (Exception e){
|
||||
seawater.setDistance(null);
|
||||
}
|
||||
seawaterList.add(seawater);
|
||||
}
|
||||
return seawaterList;
|
||||
}
|
||||
|
||||
|
||||
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,
|
||||
Integer room, String root,String sort, boolean order, int start, int limit,String table){
|
||||
@@ -399,7 +408,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
|
||||
Set<String> namesList = new LinkedHashSet<String>();
|
||||
if(StringUtils.isNotBlank(name)) {
|
||||
namesList.add(name);
|
||||
@@ -414,7 +423,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
temp.put("terms", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
|
||||
Set<String> regionsList = new LinkedHashSet<String>();
|
||||
if(StringUtils.isNotBlank(region)) {
|
||||
regionsList.add(region);
|
||||
@@ -429,7 +438,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
temp.put("terms", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
|
||||
if(StringUtils.isNotBlank(city)){
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("city", city);
|
||||
@@ -451,7 +460,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
temp.put("term", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
|
||||
if(startDate != null || endDate != null){
|
||||
JSONObject param = new JSONObject();
|
||||
JSONObject temp = new JSONObject();
|
||||
@@ -497,7 +506,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
temp.put("range", param);
|
||||
jsonList.add(temp);
|
||||
}
|
||||
|
||||
|
||||
if(StringUtils.isNotBlank(sort)){
|
||||
JSONObject jsonOrder = new JSONObject();
|
||||
if(order){
|
||||
@@ -511,7 +520,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
sortJsonList.add(jsonSort);
|
||||
reqBody.put("sort", sortJsonList);
|
||||
}
|
||||
|
||||
|
||||
if(start >= 0){
|
||||
reqBody.put("from", start);
|
||||
}
|
||||
@@ -557,6 +566,7 @@ public class SeawaterDaoImpl extends com.fangjia.dal.SeawaterDaoImpl<Seawater> i
|
||||
Double lat = query.getLat();
|
||||
Double lng = query.getLng();
|
||||
Integer radius = query.getRadius();
|
||||
// 添加地理位置过滤器和排序
|
||||
if (lat != null && lng != null && radius != null) {
|
||||
// 1. 设置地理位置参数
|
||||
JSONObject geoDistanceParam = new JSONObject();
|
||||
|
||||
@@ -80,6 +80,10 @@ public class Seawater implements SeawaterEntity {
|
||||
|
||||
private String decoration;
|
||||
|
||||
private Integer distance;
|
||||
|
||||
private String location;
|
||||
|
||||
@Id
|
||||
@Column(name = "_id")
|
||||
public String getId() {
|
||||
@@ -453,4 +457,20 @@ public class Seawater implements SeawaterEntity {
|
||||
public void setDecoration(String decoration) {
|
||||
this.decoration = decoration;
|
||||
}
|
||||
|
||||
public Integer getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public void setDistance(Integer distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
|
||||
+49
-20
@@ -897,8 +897,22 @@ public class HouseController {
|
||||
|
||||
@Authority(role = Role.USER)
|
||||
public Object aroundAction(final HouseSearchModel model) {
|
||||
List<String> type3 = Arrays.asList("1", "2", "0");
|
||||
List<String> type2 = Arrays.asList("1", "0");
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isNotBlank(model.getLocationType()) && !type3.contains(model.getLocationType())){
|
||||
mav.setModel(BasicModel.buildBadRequestModel("参数(locationType)有误"));
|
||||
return mav;
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getPropertyType()) && !type3.contains(model.getPropertyType())){
|
||||
mav.setModel(BasicModel.buildBadRequestModel("参数(propertyType)有误"));
|
||||
return mav;
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getHouseType()) && !type2.contains(model.getHouseType())){
|
||||
mav.setModel(BasicModel.buildBadRequestModel("参数(houseType)有误"));
|
||||
return mav;
|
||||
}
|
||||
// 获取当前日期
|
||||
Calendar today = Calendar.getInstance();
|
||||
|
||||
@@ -925,8 +939,17 @@ public class HouseController {
|
||||
return mav;
|
||||
}
|
||||
String[] locationStr = model.getLocation().split(",");
|
||||
String numberPattern = "-?\\d+(\\.\\d+)?"; // 匹配整数或浮点数
|
||||
for (String loc : locationStr) {
|
||||
if (!loc.trim().matches(numberPattern)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("location(经纬度)格式错误"));
|
||||
return mav;
|
||||
}
|
||||
}
|
||||
Double lng = Double.valueOf(locationStr[0]);
|
||||
Double lat = Double.valueOf(locationStr[1]);
|
||||
|
||||
// if (model.getSize())
|
||||
if ("2".equals(model.getLocationType())) {
|
||||
Map<String, Double> gcj02Location = GeoUtils.bd09ToGcj02(lat, lng);
|
||||
lng = gcj02Location.get("lng");
|
||||
@@ -985,19 +1008,20 @@ public class HouseController {
|
||||
if (houses != null && !houses.isEmpty()) {
|
||||
for (Seawater house : houses) {
|
||||
Seawater seawater = new Seawater();
|
||||
seawater.setId(house.getId());
|
||||
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.setSize(house.getArea() == 0 ? null : house.getArea());
|
||||
seawater.setUnitPrice(house.getAvgPrice() == 0 ? null : house.getAvgPrice());
|
||||
seawater.setTotalPrice(house.getTotalPrice() == 0 ? null : 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.setFloor(house.getFloor() == 0 ? null : house.getFloor());
|
||||
seawater.setMaxFloor(house.getHeight() == 0 ? null : house.getMaxFloor());
|
||||
seawater.setRoom(house.getRoom() == 0 ? null : house.getRoom());
|
||||
seawater.setHall(house.getHall() == 0 ? null : house.getHall());
|
||||
seawater.setToilet(house.getToilet() == 0 ? null : house.getToilet());
|
||||
seawater.setDecoration(house.getFitment());
|
||||
if (house.getpDate() != null && house.getpDate() > 10000000) {
|
||||
String numberStr = String.valueOf(house.getpDate());
|
||||
@@ -1008,6 +1032,8 @@ public class HouseController {
|
||||
String formattedDate = year + "-" + month + "-" + day;
|
||||
seawater.setPublishDate(formattedDate);
|
||||
}
|
||||
seawater.setDistance(house.getDistance());
|
||||
seawater.setLocation(house.getLocation());
|
||||
houseList.add(seawater);
|
||||
}
|
||||
}
|
||||
@@ -1016,25 +1042,28 @@ public class HouseController {
|
||||
if (nearestHasHouseByLocation != null && !nearestHasHouseByLocation.isEmpty()) {
|
||||
for (House house : nearestHasHouseByLocation) {
|
||||
Seawater seawater = new Seawater();
|
||||
seawater.setId(house.getId());
|
||||
seawater.setCity(house.getCity());
|
||||
seawater.setDistrict(house.getRegion());
|
||||
seawater.setAddress(house.getAddress());
|
||||
seawater.setName(house.getDistrictName());
|
||||
seawater.setSize(house.getArea());
|
||||
if (house.getAvgPrice() != null) {
|
||||
seawater.setSize(house.getArea() == 0 ? null : house.getArea());
|
||||
seawater.setUnitPrice(house.getAvgPrice() == 0 || house.getAvgPrice() == null ? null : house.getAvgPrice());
|
||||
seawater.setTotalPrice(house.getTotalPrice() == 0 ? null : house.getTotalPrice());
|
||||
seawater.setDirection(house.getDirection());
|
||||
seawater.setFloor(house.getFloor() == 0 ? null : house.getFloor());
|
||||
seawater.setMaxFloor(house.getHeight() == 0 ? null : house.getHeight());
|
||||
seawater.setRoom(house.getRoom() == 0 ? null : house.getRoom());
|
||||
seawater.setHall(house.getHall() == 0 ? null : house.getHall());
|
||||
seawater.setToilet(house.getToilet() == 0 ? null : house.getToilet());
|
||||
if (house.getAvgPrice() != null && house.getAvgPrice() != 0) {
|
||||
seawater.setUnitPrice(house.getAvgPrice());
|
||||
}else {
|
||||
if (house.getTotalPrice() != null &&house.getTotalPrice()>0 && house.getArea()!=null && house.getArea()>0){
|
||||
seawater.setUnitPrice((int) (house.getTotalPrice() / house.getArea()));
|
||||
} else {
|
||||
if (house.getTotalPrice() != null && house.getTotalPrice() > 0 && house.getArea() != null && house.getArea() > 0) {
|
||||
int price = (int) (house.getTotalPrice() / house.getArea());
|
||||
seawater.setUnitPrice(price == 0 ? null : price);
|
||||
}
|
||||
}
|
||||
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");
|
||||
|
||||
+1
-1
@@ -841,7 +841,7 @@ public class RentHouseServiceImpl implements RentHouseService {
|
||||
// sdQuery.setDistance(String.valueOf(radiusMeters));
|
||||
params.add(new QueryParam(QueryParam.SD_PARAM_NAME, sdQuery));
|
||||
List<SortParam> sortParams = Arrays.asList(new SortParam("latLng", true));
|
||||
List<House> list = houseDao.findAllByParams(params, null, 0, limit);
|
||||
List<House> list = houseDao.findAllByParams(params, sortParams, 0, limit);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user