接口修改
This commit is contained in:
+2
@@ -523,6 +523,8 @@ public interface DistrictService extends ModeService<DistrictKey, DistrictBo> {
|
||||
|
||||
List<District> findNearestDistrict(District district, int radiusMeters, int limit);
|
||||
|
||||
List<District> findNearestDistrict(District district, int radiusMeters, String[] fields, int limit);
|
||||
|
||||
List<District> findNearestDistrict(String city, Double lng, Double lat, int radiusMeters, int limit);
|
||||
|
||||
int findPeopleDensity(District district);
|
||||
|
||||
+57
@@ -2292,6 +2292,22 @@ public class DistrictServiceImpl implements DistrictService {
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public List<District> findNearestDistrict(District district, int radiusMeters, String[] fields, int limit) {
|
||||
String cacheKey = district.getCity() + "#" + district.getRegion() + "#" + district.getName() + "#" + radiusMeters + "#" + limit;
|
||||
Object obj = CacheUtils.getValue(this.getClass(), cacheKey);
|
||||
if (obj != null) {
|
||||
return (List<District>) obj;
|
||||
}
|
||||
ArrayList<District> list = new ArrayList<District>();
|
||||
List<District> nlist = doFindNearestDistrict(district, radiusMeters, fields, limit);
|
||||
if (nlist.size() > 0) {
|
||||
list = (ArrayList<District>) nlist;
|
||||
}
|
||||
CacheUtils.putValue(CachePolicyEnum.LONG, this.getClass(), cacheKey, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<District> findNearestDistrict(String city, Double lng, Double lat, int radiusMeters, int limit) {
|
||||
|
||||
@@ -2416,6 +2432,47 @@ public class DistrictServiceImpl implements DistrictService {
|
||||
return new ArrayList<District>(ret);
|
||||
}
|
||||
|
||||
|
||||
public List<District> doFindNearestDistrict(District district, int radiusMeters, String[] fields, int limit) {
|
||||
if (district == null || district.getLat() == null || district.getLng() == null || district.getLat() <= 0
|
||||
|| district.getLng() <= 0) {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
List<QueryParam> params = new ArrayList<QueryParam>();
|
||||
params.add(new QueryParam("category", "district"));
|
||||
params.add(new QueryParam("city", district.getCity()));
|
||||
params.add(new QueryParam("visible", 0));
|
||||
SdQuery sdQuery = new SdQuery();
|
||||
sdQuery.setPoint((double) district.getLat() / 10000000000.0 + "," + (double) district.getLng() / 10000000000.0);
|
||||
sdQuery.setField("lat_lng");
|
||||
sdQuery.setDistance(String.valueOf((double) radiusMeters / 1000.0));
|
||||
params.add(new QueryParam(QueryParam.SD_PARAM_NAME, sdQuery));
|
||||
List<District> list = districtDao.findAllByParams(params, null, 0, limit * 2, fields);
|
||||
if (list.size() == 0) {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
List<District> ret = new ArrayList<District>();
|
||||
for (District d : list) {
|
||||
if (district.getName().equals(d.getName()) && district.getRegion().equals(d.getRegion())
|
||||
&& district.getCity().equals(d.getCity())) {
|
||||
continue;
|
||||
}
|
||||
if (d.getEstateType2() != null) {
|
||||
if (d.getEstateType2().indexOf(district.getEstateType2()) > -1) {
|
||||
ret.add(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ret.size() > limit) {
|
||||
ret = ret.subList(0, limit);
|
||||
}
|
||||
|
||||
return new ArrayList<District>(ret);
|
||||
}
|
||||
|
||||
Pattern PATT = Pattern.compile(".*(\\d{4})[年\\-].*");
|
||||
|
||||
private Integer parseStringToYear(String s) {
|
||||
|
||||
+9
@@ -15,6 +15,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.fangjia.dal.mongo.model.*;
|
||||
import com.fangjia.service.district.DistrictRoomSqmetreRentService;
|
||||
import com.fangjia.service.district.SqmetreRentService;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
@@ -89,6 +90,8 @@ public class EvaluationServiceImpl implements EvaluationService {
|
||||
private ApiUserCfgService apiUserCfgService;
|
||||
private SqmetreRentService sqmetreRentService;
|
||||
|
||||
private DistrictRoomSqmetreRentService districtRoomSqmetreRentService;
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(EvaluationServiceImpl.class);
|
||||
|
||||
public static final Map<String, List<Double>> CREDIT_RATE_MAP = new HashMap<String, List<Double>>();
|
||||
@@ -1031,6 +1034,8 @@ public class EvaluationServiceImpl implements EvaluationService {
|
||||
evaluation.setFloor(null);
|
||||
evaluation.setHeight(null);
|
||||
}
|
||||
|
||||
|
||||
SqmetreRent sqmetreRent = sqmetreRentService.findNearestSqmetreRent(district.getCity(), district.getRegion(), district.getName(), DateUtil.formatToYYYYMMDD(weekend), "district");
|
||||
if(sqmetreRent!=null){
|
||||
long totalPrice = evaluationRateService.evaluationRent(sqmetreRent.getAvgPrice(), evaluation);
|
||||
@@ -2014,4 +2019,8 @@ public class EvaluationServiceImpl implements EvaluationService {
|
||||
}
|
||||
return evaluationDao.findCountByParams(params);
|
||||
}
|
||||
|
||||
public void setDistrictRoomSqmetreRentService(DistrictRoomSqmetreRentService districtRoomSqmetreRentService) {
|
||||
this.districtRoomSqmetreRentService = districtRoomSqmetreRentService;
|
||||
}
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.fangjia.service.district;
|
||||
|
||||
import com.fangjia.dal.mongo.model.DistrictRoomSqmetreRent;
|
||||
import com.fangjia.dal.seaweed.model.District;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface DistrictRoomSqmetreRentService {
|
||||
|
||||
List<DistrictRoomSqmetreRent> findDistrictRoomSqmetreRents(District district, int periodCount, int houseType);
|
||||
|
||||
Map<String, Object> getRentTrends(String city, String region, String name, int room, int count);
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package com.fangjia.service.district;
|
||||
|
||||
import com.fangjia.core.util.CacheUtils;
|
||||
import com.fangjia.core.util.DateUtil;
|
||||
import com.fangjia.dal.QueryParam;
|
||||
import com.fangjia.dal.SortParam;
|
||||
import com.fangjia.dal.mongo.dao.DistrictRoomSqmetreRentDao;
|
||||
import com.fangjia.dal.mongo.model.DistrictRoomSqmetreRent;
|
||||
import com.fangjia.dal.mongo.model.DistrictStatRent;
|
||||
import com.fangjia.dal.seaweed.model.District;
|
||||
import com.fangjia.service.bo.DistrictStatRentBo;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class DistrictRoomSqmetreRentServiceImpl implements DistrictRoomSqmetreRentService{
|
||||
|
||||
private DistrictRoomSqmetreRentDao districtRoomSqmetreRentDao;
|
||||
|
||||
@Override
|
||||
public List<DistrictRoomSqmetreRent> findDistrictRoomSqmetreRents(District district, int periodCount, int houseType) {
|
||||
String cacheKey = district.getCity() + "_" + district.getRegion() + "_" + district.getName() + "_" + periodCount + "_" + houseType+"_room_rent";
|
||||
// Object obj = CacheUtils.getValue(this.getClass(), cacheKey);
|
||||
// if (obj != null) {
|
||||
// return (List<DistrictRoomSqmetreRent>) obj;
|
||||
// }
|
||||
List<DistrictRoomSqmetreRent> values = doFindLatestDistrictStatRent(district, periodCount, houseType);
|
||||
CacheUtils.putValue(CacheUtils.CachePolicyEnum.LONG, this.getClass(), cacheKey, new ArrayList<DistrictRoomSqmetreRent>(values));
|
||||
return values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getRentTrends(String city, String region, String name, int room, int count) {
|
||||
List<Date> dates = DateUtil.getLastDayBetweenDates(DateUtil.addMonthToDate(new Date(),count), new Date());
|
||||
|
||||
List<String> times = new ArrayList<String>();
|
||||
for(Date date : dates){
|
||||
times.add(org.apache.tools.ant.util.DateUtils.format(date, "yyyyMM"));
|
||||
}
|
||||
|
||||
// List<DistrictStatRentBo> districtRents = findDistrictStatRentsByParams(city, region, name, null, dates.get(0), dates.get(dates.size()-1), null, null, null, null, true);
|
||||
List<DistrictRoomSqmetreRent> districtRents = findRentTrends(city, region, name, room, count);
|
||||
Map<String, Map<String, Integer>> distMap = null;
|
||||
List<Integer> rooms = null;
|
||||
|
||||
if(null != districtRents){
|
||||
distMap = new HashMap<String, Map<String, Integer>>();
|
||||
rooms = new ArrayList<Integer>();
|
||||
for(DistrictRoomSqmetreRent rent : districtRents){
|
||||
|
||||
Map<String, Integer> priceMap = distMap.get(room);
|
||||
if(null == priceMap){
|
||||
priceMap = new HashMap<String, Integer>();
|
||||
distMap.put(String.valueOf(room), priceMap);
|
||||
}
|
||||
|
||||
priceMap.put(String.valueOf(rent.getsDate()), rent.getAvgPrice());
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> retMap = new HashMap<String, Object>();
|
||||
if(rooms != null){
|
||||
retMap.put("times", times);
|
||||
retMap.put("distMap", distMap);
|
||||
retMap.put("room", room);
|
||||
}
|
||||
return retMap;
|
||||
}
|
||||
|
||||
|
||||
private List<DistrictRoomSqmetreRent> findRentTrends(String city, String region, String name, int room, int count){
|
||||
String date = DateUtil.formatByPattern(DateUtil.addMonthToDate(new Date(), count), "yyyyMM");
|
||||
|
||||
List<QueryParam> params = new ArrayList<QueryParam>();
|
||||
params.add(new QueryParam("city", city));
|
||||
params.add(new QueryParam("region", region));
|
||||
params.add(new QueryParam("districtName", name));
|
||||
params.add(new QueryParam("houseType",room));
|
||||
params.add(new QueryParam("sDate", QueryParam.GREATER_THAN_EQUAL_OPERATOR, Integer.parseInt(date)));
|
||||
List<SortParam> sortParams = new ArrayList<SortParam>();
|
||||
sortParams.add(new SortParam("sDate", false));
|
||||
return districtRoomSqmetreRentDao.findAllByParams(params, sortParams, 0, count);
|
||||
}
|
||||
|
||||
|
||||
private List<DistrictRoomSqmetreRent> doFindLatestDistrictStatRent(District district, int periodCount, int houseType){
|
||||
|
||||
List<QueryParam> params = new ArrayList<QueryParam>();
|
||||
params.add(new QueryParam("city", district.getCity()));
|
||||
params.add(new QueryParam("region", district.getRegion()));
|
||||
params.add(new QueryParam("districtName", district.getName()));
|
||||
params.add(new QueryParam("houseType",houseType));
|
||||
// params.add(new QueryParam("sDate", QueryParam.GREATER_THAN_EQUAL_OPERATOR, calendar.getTime()));
|
||||
List<SortParam> sortParams = new ArrayList<SortParam>();
|
||||
sortParams.add(new SortParam("sDate", false));
|
||||
return districtRoomSqmetreRentDao.findAllByParams(params, sortParams, 0, periodCount);
|
||||
}
|
||||
|
||||
public void setDistrictRoomSqmetreRentDao(DistrictRoomSqmetreRentDao districtRoomSqmetreRentDao) {
|
||||
this.districtRoomSqmetreRentDao = districtRoomSqmetreRentDao;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.fangjia.service.district;
|
||||
|
||||
import com.fangjia.dal.mongo.model.RentDealPrice;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface RentDealPriceService {
|
||||
|
||||
List<RentDealPrice> getRentDealPrices(String city, String region, String districtName, int limit);
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.fangjia.service.district;
|
||||
|
||||
import com.fangjia.dal.MongoDaoImpl;
|
||||
import com.fangjia.dal.QueryParam;
|
||||
import com.fangjia.dal.SortParam;
|
||||
import com.fangjia.dal.mongo.dao.DistrictRoomSqmetreRentDao;
|
||||
import com.fangjia.dal.mongo.dao.RentDealPriceDao;
|
||||
import com.fangjia.dal.mongo.model.RegionStat;
|
||||
import com.fangjia.dal.mongo.model.RentDealPrice;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RentDealPriceServiceImpl extends MongoDaoImpl<RentDealPrice> implements RentDealPriceService{
|
||||
|
||||
private RentDealPriceDao dentDealPriceDao;
|
||||
|
||||
public void setDentDealPriceDao(RentDealPriceDao dentDealPriceDao) {
|
||||
this.dentDealPriceDao = dentDealPriceDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RentDealPrice> getRentDealPrices(String city, String region, String districtName, int limit) {
|
||||
|
||||
List<QueryParam> params = new ArrayList<QueryParam>();
|
||||
params.add(new QueryParam("city", city));
|
||||
if (StringUtils.isNotBlank(region)) {
|
||||
params.add(new QueryParam("region", region));
|
||||
} else {
|
||||
params.add(new QueryParam("region", null));
|
||||
}
|
||||
if (StringUtils.isNotBlank(districtName)) {
|
||||
params.add(new QueryParam("districtName", districtName));
|
||||
} else {
|
||||
params.add(new QueryParam("districtName", null));
|
||||
}
|
||||
|
||||
List<SortParam> sortParms = new ArrayList<SortParam>(1);
|
||||
sortParms.add(new SortParam("tradeDate", true));
|
||||
List<RentDealPrice> list = findAllByParams(params, sortParms, limit);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user