/house/around接口
This commit is contained in:
+9
-1
@@ -1535,15 +1535,23 @@ public class DistrictServiceImpl implements DistrictService {
|
||||
|
||||
List<District> ret = new ArrayList<District>();
|
||||
for (District d : districts) {
|
||||
if (null == d.getLat2() || null == d.getLng2()) {
|
||||
if (d.getLat2() == null || d.getLng2() == 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<District>() {
|
||||
@Override
|
||||
public int compare(District d1, District d2) {
|
||||
return Double.compare(d1.getScore(), d2.getScore());
|
||||
}
|
||||
});
|
||||
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