Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.fangjia.dal.mongo.model;
|
package com.fangjia.dal.mongo.model;
|
||||||
|
|
||||||
import com.fangjia.dal.MongoEntity;
|
import com.fangjia.dal.MongoEntity;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
|
||||||
@@ -16,6 +17,8 @@ public class OfficeRentStat implements MongoEntity {
|
|||||||
private Integer date;
|
private Integer date;
|
||||||
private Double avgPrice;
|
private Double avgPrice;
|
||||||
private String name;
|
private String name;
|
||||||
|
@JsonIgnore
|
||||||
|
private Object location;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
@@ -81,4 +84,13 @@ public class OfficeRentStat implements MongoEntity {
|
|||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Column(name = "location")
|
||||||
|
public Object getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(Object location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -281,8 +281,8 @@ public class OfficeController {
|
|||||||
districtPriceMap.put("city", evaluation.getCity());
|
districtPriceMap.put("city", evaluation.getCity());
|
||||||
districtPriceMap.put("district", evaluation.getRegion());
|
districtPriceMap.put("district", evaluation.getRegion());
|
||||||
districtPriceMap.put("name", evaluation.getName());
|
districtPriceMap.put("name", evaluation.getName());
|
||||||
districtPriceMap.put("unitPrice", evaluation.getUnitPrice());
|
|
||||||
districtPriceMap.put("samples", evaluation.getSeawater());
|
districtPriceMap.put("samples", evaluation.getSeawater());
|
||||||
|
districtPriceMap.put("refOffices", evaluation.getOffice());
|
||||||
|
|
||||||
mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap));
|
mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap));
|
||||||
try {
|
try {
|
||||||
@@ -524,6 +524,7 @@ public class OfficeController {
|
|||||||
districtPriceMap.put("name", district.getName());
|
districtPriceMap.put("name", district.getName());
|
||||||
districtPriceMap.put("unitPrice", evaluation.getUnitPrice());
|
districtPriceMap.put("unitPrice", evaluation.getUnitPrice());
|
||||||
districtPriceMap.put("samples", evaluation.getSeawater());
|
districtPriceMap.put("samples", evaluation.getSeawater());
|
||||||
|
districtPriceMap.put("refOffices", evaluation.getOffice());
|
||||||
|
|
||||||
mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap));
|
mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap));
|
||||||
try {
|
try {
|
||||||
|
|||||||
+63
-31
@@ -15,8 +15,9 @@ import com.fangjia.service.datastore.dto.OfficeEvaluationDto;
|
|||||||
import com.fangjia.service.mongo.fangjia.SeawaterService;
|
import com.fangjia.service.mongo.fangjia.SeawaterService;
|
||||||
import com.fangjia.service.util.GeoUtils;
|
import com.fangjia.service.util.GeoUtils;
|
||||||
import com.fangjia.service.util.dto.GaodeDto;
|
import com.fangjia.service.util.dto.GaodeDto;
|
||||||
|
import com.mongodb.BasicDBObject;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.sothis.core.util.Closure;
|
import org.sothis.core.util.Closure;
|
||||||
import org.sothis.core.util.CollectionUtils;
|
|
||||||
import org.sothis.core.util.Pager;
|
import org.sothis.core.util.Pager;
|
||||||
import weiboclient4j.utils.StringUtils;
|
import weiboclient4j.utils.StringUtils;
|
||||||
|
|
||||||
@@ -353,47 +354,78 @@ public class OfficeServiceImpl implements OfficeService {
|
|||||||
// 评估逻辑
|
// 评估逻辑
|
||||||
String location = getLocation(evaluation.getCity(), evaluation.getAddress());
|
String location = getLocation(evaluation.getCity(), evaluation.getAddress());
|
||||||
evaluation.setLocation(location);
|
evaluation.setLocation(location);
|
||||||
OfficeEvaluationDto officeEvaluationDto = rentEvaluateByLocation(evaluation);
|
|
||||||
|
|
||||||
return officeEvaluationDto;
|
return rentEvaluateByLocation(evaluation);
|
||||||
}
|
}
|
||||||
|
|
||||||
private OfficeEvaluationDto rentEvaluateByLocation(Evaluation evaluation) {
|
private OfficeEvaluationDto rentEvaluateByLocation(Evaluation evaluation) {
|
||||||
|
OfficeEvaluationDto officeEvaluationDto = new OfficeEvaluationDto();
|
||||||
if (StringUtils.isNotBlank(evaluation.getLocation())) {
|
if (StringUtils.isNotBlank(evaluation.getLocation())) {
|
||||||
Double lng = Double.valueOf(evaluation.getLocation().split(",")[0]);
|
Double lng = Double.valueOf(evaluation.getLocation().split(",")[0]);
|
||||||
Double lat = Double.valueOf(evaluation.getLocation().split(",")[1]);
|
Double lat = Double.valueOf(evaluation.getLocation().split(",")[1]);
|
||||||
// 查询Seawater样本
|
// 查询附近5个写字楼基准价
|
||||||
List<Seawater> seawaters;
|
BasicDBObject geo = new BasicDBObject();
|
||||||
SeawaterQuery query = new SeawaterQuery();
|
BasicDBObject nearQuery = new BasicDBObject();
|
||||||
query.setLat(lat);
|
nearQuery.append("$geometry", new BasicDBObject("type", "Point").append("coordinates", new double[]{lng, lat}));
|
||||||
query.setLng(lng);
|
nearQuery.append("$maxDistance", 3000);
|
||||||
query.setCat("office_rent");
|
geo.append("$near", nearQuery);
|
||||||
query.setRadius(3000);
|
|
||||||
|
|
||||||
Integer endDate = Integer.valueOf(DateUtil.formatByPattern(new Date(), "yyyyMMdd"));
|
List<QueryParam> params = new ArrayList<QueryParam>(5);
|
||||||
Integer startDate = Integer.valueOf(DateUtil.formatByPattern(DateUtil.addMonthToDate(new Date(), -12), "yyyyMMdd"));
|
if (TYPE_MAP.get(evaluation.getType()) != null) {
|
||||||
query.setStartDate(startDate);
|
params.add(new QueryParam("estate_type2", TYPE_MAP.get(evaluation.getType())));
|
||||||
query.setEndDate(endDate);
|
|
||||||
query.setEstateType(TYPE_MAP.get(evaluation.getType()));
|
|
||||||
query.setLevel(LEVEL_MAP.get(evaluation.getLevel()));
|
|
||||||
query.setCityDisplay(evaluation.getCity());
|
|
||||||
Pager pager = new Pager();
|
|
||||||
pager.setStartRow(0);
|
|
||||||
pager.setPageSize(10);
|
|
||||||
query.setPager(pager);
|
|
||||||
query.setTable("latest_seawater");
|
|
||||||
seawaters = seawaterService.findSeawatersByQuery(query);
|
|
||||||
// 如果同等级同类型没有查到,则放开
|
|
||||||
if (CollectionUtils.isEmpty(seawaters)) {
|
|
||||||
query.setEstateType(null);
|
|
||||||
query.setLevel(null);
|
|
||||||
seawaters = seawaterService.findSeawatersByQuery(query);
|
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(seawaters)) {
|
if (LEVEL_MAP.get(evaluation.getLevel()) != null) {
|
||||||
return getOfficeEvaluationDtoWithFactor(seawaters, evaluation);
|
params.add(new QueryParam("bed_kind", LEVEL_MAP.get(evaluation.getLevel())));
|
||||||
|
}
|
||||||
|
params.add(new QueryParam("cat", "office"));
|
||||||
|
params.add(new QueryParam("location", geo));
|
||||||
|
|
||||||
|
String date = DateUtil.formatByPattern(DateUtil.addMonthToDate(new Date(), -2), "yyyyMM");
|
||||||
|
params.add(new QueryParam("date", Integer.parseInt(date)));
|
||||||
|
|
||||||
|
// 按日期降序排序,取最新的数据,可能上月还未更新,则取上上个月的数据
|
||||||
|
List<SortParam> sortParams = new ArrayList<SortParam>();
|
||||||
|
sortParams.add(new SortParam("date", false));
|
||||||
|
|
||||||
|
List<OfficeRentStat> infos = officeRentStatDao.findAllByParams(params, sortParams, 5);
|
||||||
|
if (CollectionUtils.isEmpty(infos)) {
|
||||||
|
// 去掉类型,重新查找
|
||||||
|
params = new ArrayList<QueryParam>(5);
|
||||||
|
params.add(new QueryParam("cat", "office"));
|
||||||
|
params.add(new QueryParam("location", geo));
|
||||||
|
params.add(new QueryParam("date", Integer.parseInt(date)));
|
||||||
|
infos = officeRentStatDao.findAllByParams(params, sortParams);
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isNotEmpty(infos)) {
|
||||||
|
// 求均值
|
||||||
|
Double totalPrice = 0D;
|
||||||
|
int count = 0;
|
||||||
|
for (OfficeRentStat officeRentStat : infos) {
|
||||||
|
if (officeRentStat.getAvgPrice() != null) {
|
||||||
|
totalPrice += officeRentStat.getAvgPrice();
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Double factor = 1.0;
|
||||||
|
if (evaluation.getFitment() != null) {
|
||||||
|
factor *= FITMENT_FACTOR.get(FITMENT_MAP.get(evaluation.getFitment()));
|
||||||
|
}
|
||||||
|
if (evaluation.getFloorDesc() != null) {
|
||||||
|
factor *= FLOOR_FACTOR.get(evaluation.getFloorDesc());
|
||||||
|
}
|
||||||
|
if (evaluation.getDirection() != null) {
|
||||||
|
factor *= DIRECTION_FACTOR.get(DIRECTION_MAP.get(evaluation.getDirection()));
|
||||||
|
}
|
||||||
|
Double avgPrice = DataUtil.roundDouble(totalPrice / count * factor, 2);
|
||||||
|
officeEvaluationDto.setUnitPrice(avgPrice);
|
||||||
|
officeEvaluationDto.setOffice(infos);
|
||||||
|
officeEvaluationDto.setCity(evaluation.getCity());
|
||||||
|
officeEvaluationDto.setDistrict(evaluation.getRegion());
|
||||||
|
officeEvaluationDto.setName(evaluation.getDistrictName());
|
||||||
|
return officeEvaluationDto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return officeEvaluationDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLocation(String city, String address) {
|
private String getLocation(String city, String address) {
|
||||||
|
|||||||
+10
@@ -1,6 +1,7 @@
|
|||||||
package com.fangjia.service.datastore.dto;
|
package com.fangjia.service.datastore.dto;
|
||||||
|
|
||||||
import com.fangjia.dal.mongo.model.Evaluation;
|
import com.fangjia.dal.mongo.model.Evaluation;
|
||||||
|
import com.fangjia.dal.mongo.model.OfficeRentStat;
|
||||||
import com.fangjia.dal.seawater.model.Seawater;
|
import com.fangjia.dal.seawater.model.Seawater;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -14,6 +15,7 @@ public class OfficeEvaluationDto extends Evaluation {
|
|||||||
private Double unitPrice;
|
private Double unitPrice;
|
||||||
|
|
||||||
private List<Seawater> seawater;
|
private List<Seawater> seawater;
|
||||||
|
private List<OfficeRentStat> office;
|
||||||
|
|
||||||
private String district;
|
private String district;
|
||||||
private String name;
|
private String name;
|
||||||
@@ -49,4 +51,12 @@ public class OfficeEvaluationDto extends Evaluation {
|
|||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<OfficeRentStat> getOffice() {
|
||||||
|
return office;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOffice(List<OfficeRentStat> office) {
|
||||||
|
this.office = office;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user