/house/around接口
This commit is contained in:
@@ -6,6 +6,7 @@ import javax.persistence.*;
|
|||||||
|
|
||||||
import com.fangjia.dal.DatastoreCategory;
|
import com.fangjia.dal.DatastoreCategory;
|
||||||
import com.fangjia.dal.SeawaterEntity;
|
import com.fangjia.dal.SeawaterEntity;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "fangjia.seawater")
|
@Table(name = "fangjia.seawater")
|
||||||
@@ -35,9 +36,11 @@ public class Seawater implements SeawaterEntity {
|
|||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String category;
|
private String category;
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
|
||||||
private int status;
|
private int status;
|
||||||
private String city;
|
private String city;
|
||||||
private String region;
|
private String region;
|
||||||
|
private String district;
|
||||||
private String districtName;
|
private String districtName;
|
||||||
private String address;
|
private String address;
|
||||||
private Date modificationDate;
|
private Date modificationDate;
|
||||||
@@ -46,8 +49,10 @@ public class Seawater implements SeawaterEntity {
|
|||||||
private String block;
|
private String block;
|
||||||
private Integer totalPrice;
|
private Integer totalPrice;
|
||||||
private Double area;
|
private Double area;
|
||||||
|
private Double size;
|
||||||
private Integer height;
|
private Integer height;
|
||||||
private Integer floor;
|
private Integer floor;
|
||||||
|
private Integer maxFloor;
|
||||||
private String floorInfo;
|
private String floorInfo;
|
||||||
private String fitment;
|
private String fitment;
|
||||||
private Integer room;
|
private Integer room;
|
||||||
@@ -55,10 +60,13 @@ public class Seawater implements SeawaterEntity {
|
|||||||
private Integer toilet;
|
private Integer toilet;
|
||||||
private String mobile;
|
private String mobile;
|
||||||
private Integer pDate;
|
private Integer pDate;
|
||||||
|
|
||||||
|
private String publishDate;
|
||||||
private Integer userId;
|
private Integer userId;
|
||||||
private String url;
|
private String url;
|
||||||
private String root;
|
private String root;
|
||||||
private Integer avgPrice;
|
private Integer avgPrice;
|
||||||
|
private Integer unitPrice;
|
||||||
private String purpose;
|
private String purpose;
|
||||||
private String estateType;
|
private String estateType;
|
||||||
private String buildType;
|
private String buildType;
|
||||||
@@ -70,6 +78,8 @@ public class Seawater implements SeawaterEntity {
|
|||||||
private String housingAge; //房屋年限 满二年
|
private String housingAge; //房屋年限 满二年
|
||||||
private String elevator; //配备电梯 有/无
|
private String elevator; //配备电梯 有/无
|
||||||
|
|
||||||
|
private String decoration;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "_id")
|
@Column(name = "_id")
|
||||||
public String getId() {
|
public String getId() {
|
||||||
@@ -395,4 +405,52 @@ public class Seawater implements SeawaterEntity {
|
|||||||
public void setElevator(String elevator) {
|
public void setElevator(String elevator) {
|
||||||
this.elevator = elevator;
|
this.elevator = elevator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDistrict() {
|
||||||
|
return district;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDistrict(String district) {
|
||||||
|
this.district = district;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSize(Double size) {
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMaxFloor() {
|
||||||
|
return maxFloor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxFloor(Integer maxFloor) {
|
||||||
|
this.maxFloor = maxFloor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getUnitPrice() {
|
||||||
|
return unitPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUnitPrice(Integer unitPrice) {
|
||||||
|
this.unitPrice = unitPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublishDate() {
|
||||||
|
return publishDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublishDate(String publishDate) {
|
||||||
|
this.publishDate = publishDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDecoration() {
|
||||||
|
return decoration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDecoration(String decoration) {
|
||||||
|
this.decoration = decoration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ public class Seaweed implements SeaweedEntity {
|
|||||||
private List<String> alias;
|
private List<String> alias;
|
||||||
private List<String> addrAlias;
|
private List<String> addrAlias;
|
||||||
|
|
||||||
|
private double score;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
@Column(name = "_id")
|
@Column(name = "_id")
|
||||||
@@ -134,4 +136,13 @@ public class Seaweed implements SeaweedEntity {
|
|||||||
public void setEstateType2(String estateType2) {
|
public void setEstateType2(String estateType2) {
|
||||||
this.estateType2 = estateType2;
|
this.estateType2 = estateType2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
public double getScore() {
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScore(double score) {
|
||||||
|
this.score = score;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+124
-10
@@ -14,6 +14,7 @@ import com.fangjia.dal.mongo.model.StatsIndex;
|
|||||||
import com.fangjia.dal.seawater.dao.SeawaterDao;
|
import com.fangjia.dal.seawater.dao.SeawaterDao;
|
||||||
import com.fangjia.dal.seawater.model.Seawater;
|
import com.fangjia.dal.seawater.model.Seawater;
|
||||||
import com.fangjia.dal.seaweed.model.District;
|
import com.fangjia.dal.seaweed.model.District;
|
||||||
|
import com.fangjia.dal.seaweed.model.Seaweed;
|
||||||
import com.fangjia.dal.sql.model.ApiUser;
|
import com.fangjia.dal.sql.model.ApiUser;
|
||||||
import com.fangjia.datastore.driver.FacetResult;
|
import com.fangjia.datastore.driver.FacetResult;
|
||||||
import com.fangjia.open.FangjiaApiUtil;
|
import com.fangjia.open.FangjiaApiUtil;
|
||||||
@@ -38,10 +39,7 @@ import com.fangjia.service.bo.Collateral;
|
|||||||
import com.fangjia.service.bo.DistrictStatBo;
|
import com.fangjia.service.bo.DistrictStatBo;
|
||||||
import com.fangjia.service.bo.Sample;
|
import com.fangjia.service.bo.Sample;
|
||||||
import com.fangjia.service.bo.ShopSample;
|
import com.fangjia.service.bo.ShopSample;
|
||||||
import com.fangjia.service.datastore.CzbankSampleService;
|
import com.fangjia.service.datastore.*;
|
||||||
import com.fangjia.service.datastore.DistrictService;
|
|
||||||
import com.fangjia.service.datastore.HouseService;
|
|
||||||
import com.fangjia.service.datastore.NoHouseDistrictService;
|
|
||||||
import com.fangjia.service.datastore.bean.CollateralSampleQueryBean;
|
import com.fangjia.service.datastore.bean.CollateralSampleQueryBean;
|
||||||
import com.fangjia.service.datastore.bean.ShopCollateralSampleQueryBean;
|
import com.fangjia.service.datastore.bean.ShopCollateralSampleQueryBean;
|
||||||
import com.fangjia.service.district.DistrictFacilitysService;
|
import com.fangjia.service.district.DistrictFacilitysService;
|
||||||
@@ -70,6 +68,7 @@ import java.io.IOException;
|
|||||||
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;
|
||||||
|
|
||||||
@Authority(role = Role.USER)
|
@Authority(role = Role.USER)
|
||||||
public class HouseController {
|
public class HouseController {
|
||||||
|
|
||||||
@@ -98,6 +97,8 @@ public class HouseController {
|
|||||||
|
|
||||||
private SeawaterService seawaterService;
|
private SeawaterService seawaterService;
|
||||||
private SeawaterDao seawaterDao;
|
private SeawaterDao seawaterDao;
|
||||||
|
|
||||||
|
private SeaweedService seaweedService;
|
||||||
private List<String> PROPERTY_TYPE_CODE_LIST = Arrays.asList("01", "02");
|
private List<String> PROPERTY_TYPE_CODE_LIST = Arrays.asList("01", "02");
|
||||||
|
|
||||||
|
|
||||||
@@ -149,8 +150,6 @@ public class HouseController {
|
|||||||
"address", "publishDate", "url"};
|
"address", "publishDate", "url"};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Object publishAction(@Valid HousePublishModel model) {
|
public Object publishAction(@Valid HousePublishModel model) {
|
||||||
|
|
||||||
RestfulModelAndView mav = new RestfulModelAndView();
|
RestfulModelAndView mav = new RestfulModelAndView();
|
||||||
@@ -256,7 +255,9 @@ public class HouseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**商铺相似房源接口*/
|
/**
|
||||||
|
* 商铺相似房源接口
|
||||||
|
*/
|
||||||
@Authority(role = Role.USER)
|
@Authority(role = Role.USER)
|
||||||
public Object shopSimilarAction(@Valid ShopCollateralSampleQuery query) {
|
public Object shopSimilarAction(@Valid ShopCollateralSampleQuery query) {
|
||||||
RestfulModelAndView mav = new RestfulModelAndView();
|
RestfulModelAndView mav = new RestfulModelAndView();
|
||||||
@@ -568,7 +569,6 @@ public class HouseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Object arroundlistAction(final HouseSearchModel model) {
|
public Object arroundlistAction(final HouseSearchModel model) {
|
||||||
RestfulModelAndView mav = new RestfulModelAndView();
|
RestfulModelAndView mav = new RestfulModelAndView();
|
||||||
mav.setViewType("rest");
|
mav.setViewType("rest");
|
||||||
@@ -696,6 +696,7 @@ public class HouseController {
|
|||||||
|
|
||||||
|
|
||||||
public static final int VALUE_SKIP = 100;
|
public static final int VALUE_SKIP = 100;
|
||||||
|
|
||||||
private double[] compareTotalPrice(String city, int totalPrice) {
|
private double[] compareTotalPrice(String city, int totalPrice) {
|
||||||
if (StringUtils.isBlank(city) || totalPrice <= 1000) {
|
if (StringUtils.isBlank(city) || totalPrice <= 1000) {
|
||||||
return null;
|
return null;
|
||||||
@@ -889,6 +890,118 @@ public class HouseController {
|
|||||||
return mav;
|
return mav;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Authority(role = Role.USER)
|
||||||
|
public Object aroundAction(final HouseSearchModel model) {
|
||||||
|
RestfulModelAndView mav = new RestfulModelAndView();
|
||||||
|
mav.setViewType("rest");
|
||||||
|
if (StringUtils.isBlank(model.getLocation())) {
|
||||||
|
mav.setModel(BasicModel.buildBadRequestModel("location(经纬度)不能为空"));
|
||||||
|
return mav;
|
||||||
|
}
|
||||||
|
model.setLocation(model.getLocation().replace(",", ","));
|
||||||
|
if (StringUtils.isBlank(model.getLocation()) || !model.getLocation().contains(",")) {
|
||||||
|
mav.setModel(BasicModel.buildBadRequestModel("location(经纬度)不能为空或格式错误"));
|
||||||
|
return mav;
|
||||||
|
}
|
||||||
|
String[] locationStr = model.getLocation().split(",");
|
||||||
|
Double lng = Double.valueOf(locationStr[0]);
|
||||||
|
Double lat = Double.valueOf(locationStr[1]);
|
||||||
|
if ("2".equals(model.getLocationType())) {
|
||||||
|
Map<String, Double> gcj02Location = GeoUtils.bd09ToGcj02(lat, lng);
|
||||||
|
lng = gcj02Location.get("lng");
|
||||||
|
lat = gcj02Location.get("lat");
|
||||||
|
}
|
||||||
|
if (lng < 70 || lng > 140 || lat < 0 || lat > 55) {
|
||||||
|
mav.setModel(BasicModel.buildBadRequestModel("非中国经纬度"));
|
||||||
|
return mav;
|
||||||
|
}
|
||||||
|
String category = "district";
|
||||||
|
if ("1".equals(model.getPropertyType())) {
|
||||||
|
category = "office";
|
||||||
|
} else if ("2".equals(model.getPropertyType())) {
|
||||||
|
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";
|
||||||
|
if ("1".equals(model.getHouseType())) {
|
||||||
|
if ("0".equals(model.getPropertyType())) {
|
||||||
|
cat = "rent";
|
||||||
|
}
|
||||||
|
if ("1".equals(model.getPropertyType())) {
|
||||||
|
cat = "office_rent";
|
||||||
|
}
|
||||||
|
if ("2".equals(model.getPropertyType())) {
|
||||||
|
cat = "shop_rent";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ("1".equals(model.getPropertyType())) {
|
||||||
|
cat = "office_sell";
|
||||||
|
}
|
||||||
|
if ("2".equals(model.getPropertyType())) {
|
||||||
|
cat = "shop_sell";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<Seawater> houses;
|
||||||
|
List<Seawater> houseList = new ArrayList<Seawater>();
|
||||||
|
for (Seaweed seaweed : seaweedList) {
|
||||||
|
|
||||||
|
if (model.getSize() != null && model.getSize() != 0) {
|
||||||
|
Double size = model.getSize();
|
||||||
|
houses = seawaterDao.findSeawatersFromEs(cat, seaweed.getCity(), seaweed.getRegion(), seaweed.getName(), seaweed.getAlias(), null,
|
||||||
|
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) {
|
||||||
|
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.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);
|
||||||
|
}
|
||||||
|
if (houseList.size() > 4) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
houseList.add(seawater);
|
||||||
|
}
|
||||||
|
if (houseList.size() > 4) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BasicModel basicModel = new BasicModel(200, "ok");
|
||||||
|
// 组装数据
|
||||||
|
basicModel.setResult(houseList);
|
||||||
|
mav.setModel(basicModel);
|
||||||
|
mav.setViewType("rest");
|
||||||
|
return mav;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Object caseAction(@Valid SampleQuery sampleQuery) {
|
public Object caseAction(@Valid SampleQuery sampleQuery) {
|
||||||
|
|
||||||
@@ -935,8 +1048,6 @@ public class HouseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private List<HousePojo> fillDistrictInfoForHouse(FacetQueryResult<com.fangjia.service.bo.HouseBo> houseList, Date endDate,
|
private List<HousePojo> fillDistrictInfoForHouse(FacetQueryResult<com.fangjia.service.bo.HouseBo> houseList, Date endDate,
|
||||||
District district, boolean showDetail, boolean matchModel) {
|
District district, boolean showDetail, boolean matchModel) {
|
||||||
FacetQueryResult<HousePojo> list = new FacetQueryResult<HousePojo>();
|
FacetQueryResult<HousePojo> list = new FacetQueryResult<HousePojo>();
|
||||||
@@ -1701,4 +1812,7 @@ public class HouseController {
|
|||||||
this.fangjiaOfficialAreaService = fangjiaOfficialAreaService;
|
this.fangjiaOfficialAreaService = fangjiaOfficialAreaService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSeaweedService(SeaweedService seaweedService) {
|
||||||
|
this.seaweedService = seaweedService;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,16 @@ public class HouseSearchModel extends SearchModel {
|
|||||||
private String unitNo;
|
private String unitNo;
|
||||||
private Double size;
|
private Double size;
|
||||||
private Boolean showDetail;
|
private Boolean showDetail;
|
||||||
|
|
||||||
|
private String city;
|
||||||
|
|
||||||
|
private String location;
|
||||||
|
|
||||||
|
private String locationType;
|
||||||
|
|
||||||
|
private String propertyType;
|
||||||
|
|
||||||
|
private String houseType;
|
||||||
@Override
|
@Override
|
||||||
public QueryBean getQueryBean() {
|
public QueryBean getQueryBean() {
|
||||||
HouseQueryBean queryBean = new HouseQueryBean();
|
HouseQueryBean queryBean = new HouseQueryBean();
|
||||||
@@ -125,4 +135,46 @@ public class HouseSearchModel extends SearchModel {
|
|||||||
public void setId(String id) {
|
public void setId(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCity() {
|
||||||
|
return city;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCity(String city) {
|
||||||
|
this.city = city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(String location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocationType() {
|
||||||
|
return locationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocationType(String locationType) {
|
||||||
|
this.locationType = locationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPropertyType() {
|
||||||
|
return propertyType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPropertyType(String propertyType) {
|
||||||
|
this.propertyType = propertyType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHouseType() {
|
||||||
|
return houseType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHouseType(String houseType) {
|
||||||
|
this.houseType = houseType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-1
@@ -1535,15 +1535,23 @@ public class DistrictServiceImpl implements DistrictService {
|
|||||||
|
|
||||||
List<District> ret = new ArrayList<District>();
|
List<District> ret = new ArrayList<District>();
|
||||||
for (District d : districts) {
|
for (District d : districts) {
|
||||||
if (null == d.getLat2() || null == d.getLng2()) {
|
if (d.getLat2() == null || d.getLng2() == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
double dis = GeoUtils.calculateDistance(lng, lat, d.getLng() / 10000000000.0, d.getLat() / 10000000000.0);
|
double dis = GeoUtils.calculateDistance(lng, lat, d.getLng() / 10000000000.0, d.getLat() / 10000000000.0);
|
||||||
if (dis <= radius) {
|
if (dis <= radius) {
|
||||||
|
d.setScore(dis); // Assuming District has a `distance` field to store the calculated distance.
|
||||||
ret.add(d);
|
ret.add(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Collections.sort(ret, new Comparator<District>() {
|
||||||
|
@Override
|
||||||
|
public int compare(District d1, District d2) {
|
||||||
|
return Double.compare(d1.getScore(), d2.getScore());
|
||||||
|
}
|
||||||
|
});
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package com.fangjia.service.datastore;
|
||||||
|
|
||||||
|
import com.fangjia.dal.QueryParam;
|
||||||
|
import com.fangjia.dal.common.DistrictKey;
|
||||||
|
import com.fangjia.dal.seaweed.model.Seaweed;
|
||||||
|
import com.fangjia.dal.seaweed.model.Shop;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface SeaweedService {
|
||||||
|
List<Seaweed> findSeaweedByLocation(double lat, double lng, double radius,String cat,int limit);
|
||||||
|
List<Seaweed> findSeaweedByLocation(double lat, double lng, double radius,String cat);
|
||||||
|
}
|
||||||
+102
@@ -0,0 +1,102 @@
|
|||||||
|
package com.fangjia.service.datastore;
|
||||||
|
|
||||||
|
import com.fangjia.core.util.CacheUtils;
|
||||||
|
import com.fangjia.core.util.CacheUtils.CachePolicyEnum;
|
||||||
|
import com.fangjia.core.util.GeoUtils;
|
||||||
|
import com.fangjia.dal.QueryParam;
|
||||||
|
import com.fangjia.dal.common.DistrictKey;
|
||||||
|
import com.fangjia.dal.seaweed.dao.SeaweedDao;
|
||||||
|
import com.fangjia.dal.seaweed.dao.ShopDao;
|
||||||
|
import com.fangjia.dal.seaweed.model.District;
|
||||||
|
import com.fangjia.dal.seaweed.model.Seaweed;
|
||||||
|
import com.fangjia.dal.seaweed.model.Shop;
|
||||||
|
import com.fangjia.service.index.BoostQueryPolicy;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.sothis.core.util.Closure;
|
||||||
|
import org.sothis.core.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class SeaweedServiceImpl implements SeaweedService {
|
||||||
|
private SeaweedDao seaweedDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Seaweed> findSeaweedByLocation(double lat, double lng, double radius,String cat,int limit) {
|
||||||
|
double[] latlngs = GeoUtils.getAround(lat, lng, radius);
|
||||||
|
List<QueryParam> params = new ArrayList<QueryParam>();
|
||||||
|
params.add(new QueryParam("category", cat));
|
||||||
|
params.add(new QueryParam("status", 0));
|
||||||
|
params.add(new QueryParam("lat", QueryParam.GREATER_THAN_EQUAL_OPERATOR, latlngs[0] * 10000000000d));
|
||||||
|
params.add(new QueryParam("lat", QueryParam.LESS_THAN_EQUAL_OPERATOR, latlngs[1] * 10000000000d));
|
||||||
|
params.add(new QueryParam("lng", QueryParam.GREATER_THAN_EQUAL_OPERATOR, latlngs[2] * 10000000000d));
|
||||||
|
params.add(new QueryParam("lng", QueryParam.LESS_THAN_EQUAL_OPERATOR, latlngs[3] * 10000000000d));
|
||||||
|
|
||||||
|
List<Seaweed> seaweeds = seaweedDao.findAllByParams(params,limit);
|
||||||
|
if (CollectionUtils.isEmpty(seaweeds)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Seaweed> ret = new ArrayList<Seaweed>();
|
||||||
|
for (Seaweed d : seaweeds) {
|
||||||
|
if (d.getLat() == null || d.getLng() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
double dis = GeoUtils.calculateDistance(lng, lat, d.getLng() / 10000000000.0, d.getLat() / 10000000000.0);
|
||||||
|
if (dis <= radius) {
|
||||||
|
d.setScore(dis); // Assuming District has a `distance` field to store the calculated distance.
|
||||||
|
ret.add(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(ret, new Comparator<Seaweed>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Seaweed d1, Seaweed d2) {
|
||||||
|
return Double.compare(d1.getScore(), d2.getScore());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Seaweed> findSeaweedByLocation(double lat, double lng, double radius, String cat) {
|
||||||
|
double[] latlngs = GeoUtils.getAround(lat, lng, radius);
|
||||||
|
List<QueryParam> params = new ArrayList<QueryParam>();
|
||||||
|
params.add(new QueryParam("category", cat));
|
||||||
|
params.add(new QueryParam("status", 0));
|
||||||
|
params.add(new QueryParam("lat", QueryParam.GREATER_THAN_EQUAL_OPERATOR, latlngs[0] * 10000000000d));
|
||||||
|
params.add(new QueryParam("lat", QueryParam.LESS_THAN_EQUAL_OPERATOR, latlngs[1] * 10000000000d));
|
||||||
|
params.add(new QueryParam("lng", QueryParam.GREATER_THAN_EQUAL_OPERATOR, latlngs[2] * 10000000000d));
|
||||||
|
params.add(new QueryParam("lng", QueryParam.LESS_THAN_EQUAL_OPERATOR, latlngs[3] * 10000000000d));
|
||||||
|
|
||||||
|
List<Seaweed> seaweeds = seaweedDao.findAllByParams(params);
|
||||||
|
if (CollectionUtils.isEmpty(seaweeds)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Seaweed> ret = new ArrayList<Seaweed>();
|
||||||
|
for (Seaweed d : seaweeds) {
|
||||||
|
if (d.getLat() == null || d.getLng() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
double dis = GeoUtils.calculateDistance(lng, lat, d.getLng() / 10000000000.0, d.getLat() / 10000000000.0);
|
||||||
|
if (dis <= radius) {
|
||||||
|
d.setScore(dis); // Assuming District has a `distance` field to store the calculated distance.
|
||||||
|
ret.add(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(ret, new Comparator<Seaweed>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Seaweed d1, Seaweed d2) {
|
||||||
|
return Double.compare(d1.getScore(), d2.getScore());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeaweedDao(SeaweedDao seaweedDao) {
|
||||||
|
this.seaweedDao = seaweedDao;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user