新增经纬度估值

This commit is contained in:
沈健
2025-01-23 11:44:37 +08:00
parent b976e6f802
commit 5f4b4fc2d1
3 changed files with 172 additions and 19 deletions
@@ -12,7 +12,10 @@ import com.fangjia.dal.mongo.model.OfficeRentStat;
import com.fangjia.dal.seawater.model.Seawater;
import com.fangjia.dal.seaweed.model.District;
import com.fangjia.service.mongo.fangjia.SeawaterService;
import com.fangjia.service.util.GeoUtils;
import com.fangjia.service.util.dto.GaodeDto;
import org.sothis.core.util.Closure;
import org.sothis.core.util.CollectionUtils;
import org.sothis.core.util.Pager;
import weiboclient4j.utils.StringUtils;
@@ -56,10 +59,10 @@ public class OfficeServiceImpl implements OfficeService {
query.setEndDate(endDate);
query.setDistrictName(name);
query.setDistrictAlias(alias);
// if (evaluation.getArea() != null && evaluation.getArea() != 0) {
// query.setStartArea(evaluation.getArea() * 0.9);
// query.setEndArea(evaluation.getArea() * 1.1);
// }
if (evaluation.getArea() != null && evaluation.getArea() != 0) {
query.setStartArea(evaluation.getArea() * 0.9);
query.setEndArea(evaluation.getArea() * 1.1);
}
Pager pager = new Pager();
pager.setStartRow(0);
pager.setPageSize(100);
@@ -69,19 +72,14 @@ public class OfficeServiceImpl implements OfficeService {
//List<Seawater> seawaters = seawaterService.findSeawatersByQuery("office_rent", city, region, name, alias, startDate, endDate);
// 有样本
Double unitPrice = null;
// 如果面积相近查不到,则不限制面积查询一次,如果还是没有查到,则返回null;
if (CollectionUtils.isEmpty(seawaters)) {
query.setStartArea(null);
query.setEndArea(null);
seawaters = seawaterService.findSeawatersByQuery(query);
}
if (seawaters.size() > 0) {
// 计算平均值
Double sum = 0.0;
Double size = 0.0;
for (Seawater seawater : seawaters) {
if (seawater.getTotalPrice() != null && seawater.getArea() != null && seawater.getTotalPrice() / seawater.getArea() / 30 > 0 && seawater.getTotalPrice() / seawater.getArea() / 30 < 30) {
sum += seawater.getTotalPrice();
size += seawater.getArea();
}
}
if (size > 0) {
unitPrice = DataUtil.roundDouble(sum / size / 30, 2);
}
unitPrice = this.calcRent(seawaters);
} else if (StringUtils.isNotBlank(evaluation.getLocation())) {
unitPrice = rentEvaluateByLocation(evaluation);
}
@@ -90,6 +88,23 @@ public class OfficeServiceImpl implements OfficeService {
return evaluation;
}
public Double calcRent(List<Seawater> seawaters) {
// 计算平均值
Double sum = 0.0;
Double size = 0.0;
Double unitPrice = null;
for (Seawater seawater : seawaters) {
if (seawater.getTotalPrice() != null && seawater.getArea() != null && seawater.getTotalPrice() / seawater.getArea() / 30 > 0 && seawater.getTotalPrice() / seawater.getArea() / 30 < 30) {
sum += seawater.getTotalPrice();
size += seawater.getArea();
}
}
if (size > 0) {
unitPrice = DataUtil.roundDouble(sum / size / 30, 2);
}
return unitPrice;
}
@Override
public Evaluation addressEvaluateRent(Evaluation evaluation) {
if (null == evaluation.getFloor() || 0 == evaluation.getFloor() || null == evaluation.getHeight() || 0 == evaluation.getHeight()) {
@@ -97,7 +112,7 @@ public class OfficeServiceImpl implements OfficeService {
evaluation.setHeight(null);
}
// 评估逻辑
String location = getLocation(evaluation.getAddress());
String location = getLocation(evaluation.getCity(), evaluation.getAddress());
evaluation.setLocation(location);
Double unitPrice = rentEvaluateByLocation(evaluation);
evaluation.setUnitPrice(unitPrice);
@@ -105,10 +120,50 @@ public class OfficeServiceImpl implements OfficeService {
}
private Double rentEvaluateByLocation(Evaluation evaluation) {
return 3.04;
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(1000);
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);
if (evaluation.getArea() != null && evaluation.getArea() != 0) {
query.setStartArea(evaluation.getArea() * 0.9);
query.setEndArea(evaluation.getArea() * 1.1);
}
query.setCityDisplay(evaluation.getCity());
Pager pager = new Pager();
pager.setStartRow(0);
pager.setPageSize(5);
query.setPager(pager);
query.setTable("latest_seawater");
seawaters = seawaterService.findSeawatersByQuery(query);
// 如果面积相近查不到,则不限制面积查询一次,如果还是没有查到,则返回null;
if (CollectionUtils.isEmpty(seawaters)) {
query.setStartArea(null);
query.setEndArea(null);
seawaters = seawaterService.findSeawatersByQuery(query);
}
if (CollectionUtils.isNotEmpty(seawaters)) {
return calcRent(seawaters);
}
}
return null;
}
private String getLocation(String address) {
private String getLocation(String city, String address) {
GaodeDto gaodeDto = GeoUtils.geo(city, address);
if (gaodeDto.getLng() != null && gaodeDto.getLat() != null) {
return gaodeDto.getLng() + "," + gaodeDto.getLat();
}
return "";
}
@@ -0,0 +1,59 @@
package com.fangjia.service.util;
import com.fangjia.core.util.HttpRequest;
import com.fangjia.service.util.dto.GaodeDto;
import groovy.util.logging.Slf4j;
import net.sf.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* 高德经纬度逆解析
*/
@Slf4j
public class GeoUtils {
private final static Logger LOGGER = LoggerFactory.getLogger(GeoUtils.class);
public static GaodeDto geo(String city, String address) {
GaodeDto gaodeDto = new GaodeDto();
Map<String, String> params = new HashMap<String, String>();
params.put("address", address);
params.put("key", "0cb105e7c10e9ae2b178e4744d62319a");
params.put("city", city);
params.put("batch", "true");
params.put("output", "json");
try {
net.sf.json.JSONObject response = new HttpRequest().getJsonContent("https://restapi.amap.com/v3/geocode/geo", params, "utf-8");
if ("10004".equals(response.getInt("infocode"))) {
LOGGER.error("高德服务单位时间内(1分钟)访问量超限, 睡眠1分钟");
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
Thread.sleep(60000);
response = new HttpRequest().getJsonContent("https://restapi.amap.com/v3/geocode/geo", params, "utf-8");
}
if ("OK".equals(response.getString("info"))) {
JSONArray geocodes = response.getJSONArray("geocodes");
if (geocodes.size() > 0) {
net.sf.json.JSONObject geocode = net.sf.json.JSONObject.fromObject(geocodes.get(0));
String level = geocode.getString("level");
if (!Arrays.asList("省", "市", "区县", "开发区", "乡镇").contains(level)) {
String location = geocode.getString("location");
Double lng = Double.valueOf(location.split(",")[0]);
Double lat = Double.valueOf(location.split(",")[1]);
gaodeDto.setLevel(level);
gaodeDto.setLng(lng);
gaodeDto.setLat(lat);
}
}
}
} catch (Exception e) {
LOGGER.error("地图辅助解析出错:" + city + " " + city);
}
return gaodeDto;
}
}
@@ -0,0 +1,39 @@
package com.fangjia.service.util.dto;
/**
* @author shenjian
* @since 2023/4/26
*/
public class GaodeDto {
private Double lng;
private Double lat;
private String level;
public Double getLng() {
return lng;
}
public void setLng(Double lng) {
this.lng = lng;
}
public Double getLat() {
return lat;
}
public void setLat(Double lat) {
this.lat = lat;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
}