Merge remote-tracking branch 'origin/master'

This commit is contained in:
majintao
2025-03-07 17:40:13 +08:00
4 changed files with 87 additions and 32 deletions
@@ -1,6 +1,7 @@
package com.fangjia.dal.mongo.model;
import com.fangjia.dal.MongoEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
@@ -16,6 +17,8 @@ public class OfficeRentStat implements MongoEntity {
private Integer date;
private Double avgPrice;
private String name;
@JsonIgnore
private Object location;
@Id
@GeneratedValue
@@ -81,4 +84,13 @@ public class OfficeRentStat implements MongoEntity {
public void setName(String name) {
this.name = name;
}
@Column(name = "location")
public Object getLocation() {
return location;
}
public void setLocation(Object location) {
this.location = location;
}
}
@@ -281,8 +281,8 @@ public class OfficeController {
districtPriceMap.put("city", evaluation.getCity());
districtPriceMap.put("district", evaluation.getRegion());
districtPriceMap.put("name", evaluation.getName());
districtPriceMap.put("unitPrice", evaluation.getUnitPrice());
districtPriceMap.put("samples", evaluation.getSeawater());
districtPriceMap.put("refOffices", evaluation.getOffice());
mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap));
try {
@@ -524,6 +524,7 @@ public class OfficeController {
districtPriceMap.put("name", district.getName());
districtPriceMap.put("unitPrice", evaluation.getUnitPrice());
districtPriceMap.put("samples", evaluation.getSeawater());
districtPriceMap.put("refOffices", evaluation.getOffice());
mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap));
try {
@@ -15,8 +15,9 @@ import com.fangjia.service.datastore.dto.OfficeEvaluationDto;
import com.fangjia.service.mongo.fangjia.SeawaterService;
import com.fangjia.service.util.GeoUtils;
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.CollectionUtils;
import org.sothis.core.util.Pager;
import weiboclient4j.utils.StringUtils;
@@ -353,47 +354,78 @@ public class OfficeServiceImpl implements OfficeService {
// 评估逻辑
String location = getLocation(evaluation.getCity(), evaluation.getAddress());
evaluation.setLocation(location);
OfficeEvaluationDto officeEvaluationDto = rentEvaluateByLocation(evaluation);
return officeEvaluationDto;
return rentEvaluateByLocation(evaluation);
}
private OfficeEvaluationDto rentEvaluateByLocation(Evaluation evaluation) {
OfficeEvaluationDto officeEvaluationDto = new OfficeEvaluationDto();
if (StringUtils.isNotBlank(evaluation.getLocation())) {
Double lng = Double.valueOf(evaluation.getLocation().split(",")[0]);
Double lat = Double.valueOf(evaluation.getLocation().split(",")[1]);
// 查询Seawater样本
List<Seawater> seawaters;
SeawaterQuery query = new SeawaterQuery();
query.setLat(lat);
query.setLng(lng);
query.setCat("office_rent");
query.setRadius(3000);
// 查询附近5个写字楼基准价
BasicDBObject geo = new BasicDBObject();
BasicDBObject nearQuery = new BasicDBObject();
nearQuery.append("$geometry", new BasicDBObject("type", "Point").append("coordinates", new double[]{lng, lat}));
nearQuery.append("$maxDistance", 3000);
geo.append("$near", nearQuery);
Integer endDate = Integer.valueOf(DateUtil.formatByPattern(new Date(), "yyyyMMdd"));
Integer startDate = Integer.valueOf(DateUtil.formatByPattern(DateUtil.addMonthToDate(new Date(), -12), "yyyyMMdd"));
query.setStartDate(startDate);
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);
List<QueryParam> params = new ArrayList<QueryParam>(5);
if (TYPE_MAP.get(evaluation.getType()) != null) {
params.add(new QueryParam("estate_type2", TYPE_MAP.get(evaluation.getType())));
}
if (CollectionUtils.isNotEmpty(seawaters)) {
return getOfficeEvaluationDtoWithFactor(seawaters, evaluation);
if (LEVEL_MAP.get(evaluation.getLevel()) != null) {
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) {
@@ -1,6 +1,7 @@
package com.fangjia.service.datastore.dto;
import com.fangjia.dal.mongo.model.Evaluation;
import com.fangjia.dal.mongo.model.OfficeRentStat;
import com.fangjia.dal.seawater.model.Seawater;
import java.util.List;
@@ -14,6 +15,7 @@ public class OfficeEvaluationDto extends Evaluation {
private Double unitPrice;
private List<Seawater> seawater;
private List<OfficeRentStat> office;
private String district;
private String name;
@@ -49,4 +51,12 @@ public class OfficeEvaluationDto extends Evaluation {
public void setName(String name) {
this.name = name;
}
public List<OfficeRentStat> getOffice() {
return office;
}
public void setOffice(List<OfficeRentStat> office) {
this.office = office;
}
}