Merge remote-tracking branch 'origin/master'
This commit is contained in:
+43
@@ -0,0 +1,43 @@
|
||||
package com.fangjia.service.datastore;
|
||||
|
||||
import com.fangjia.dal.mongo.model.Evaluation;
|
||||
import com.fangjia.dal.mongo.model.OfficeRentStat;
|
||||
import com.fangjia.dal.seaweed.model.District;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author shenjian
|
||||
* @since 2025/1/21
|
||||
*/
|
||||
public interface OfficeService {
|
||||
|
||||
|
||||
/**
|
||||
* 租金均价
|
||||
*
|
||||
* @param city
|
||||
* @param region
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return
|
||||
*/
|
||||
List<OfficeRentStat> findOfficeRentStat(final String city, final String region, final Integer startDate, final Integer endDate);
|
||||
|
||||
/**
|
||||
* 租金评估
|
||||
*
|
||||
* @param district
|
||||
* @param evaluation
|
||||
* @return
|
||||
*/
|
||||
Evaluation evaluateRent(District district, Evaluation evaluation);
|
||||
|
||||
/**
|
||||
* 租金地址维度评估
|
||||
*
|
||||
* @param evaluation
|
||||
* @return
|
||||
*/
|
||||
Evaluation addressEvaluateRent(Evaluation evaluation);
|
||||
}
|
||||
+348
@@ -0,0 +1,348 @@
|
||||
package com.fangjia.service.datastore;
|
||||
|
||||
import com.fangjia.core.util.CacheUtils;
|
||||
import com.fangjia.core.util.DataUtil;
|
||||
import com.fangjia.core.util.DateUtil;
|
||||
import com.fangjia.dal.QueryParam;
|
||||
import com.fangjia.dal.SeawaterQuery;
|
||||
import com.fangjia.dal.SortParam;
|
||||
import com.fangjia.dal.mongo.dao.office.OfficeRentStatDao;
|
||||
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.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;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 写字楼相关服务类
|
||||
*
|
||||
* @author shenjian
|
||||
* @since 2025/1/21
|
||||
*/
|
||||
public class OfficeServiceImpl implements OfficeService {
|
||||
|
||||
private OfficeRentStatDao officeRentStatDao;
|
||||
private SeawaterService seawaterService;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Evaluation evaluateRent(District district, Evaluation evaluation) {
|
||||
if (null == evaluation.getFloor() || 0 == evaluation.getFloor() || null == evaluation.getHeight() || 0 == evaluation.getHeight()) {
|
||||
evaluation.setFloor(null);
|
||||
evaluation.setHeight(null);
|
||||
}
|
||||
String city = district.getCity();
|
||||
String region = district.getRegion();
|
||||
String name = district.getName();
|
||||
List<String> alias = district.getAlias();
|
||||
Integer endDate = Integer.valueOf(DateUtil.formatByPattern(new Date(), "yyyyMMdd"));
|
||||
Integer startDate = Integer.valueOf(DateUtil.formatByPattern(DateUtil.addMonthToDate(new Date(), -12), "yyyyMMdd"));
|
||||
|
||||
SeawaterQuery query = new SeawaterQuery();
|
||||
query.setCat("office_rent");
|
||||
query.setCityDisplay(city);
|
||||
if (StringUtils.isNotBlank(region)) {
|
||||
query.setRegion(region);
|
||||
}
|
||||
query.setStartDate(startDate);
|
||||
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);
|
||||
}
|
||||
Pager pager = new Pager();
|
||||
pager.setStartRow(0);
|
||||
pager.setPageSize(100);
|
||||
query.setPager(pager);
|
||||
query.setTable("latest_seawater");
|
||||
List<Seawater> seawaters = seawaterService.findSeawatersByQuery(query);
|
||||
//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) {
|
||||
unitPrice = this.calcRent(seawaters, evaluation);
|
||||
} else if (StringUtils.isNotBlank(evaluation.getLocation())) {
|
||||
unitPrice = rentEvaluateByLocation(evaluation);
|
||||
}
|
||||
// 评估逻辑
|
||||
evaluation.setUnitPrice(unitPrice);
|
||||
return evaluation;
|
||||
}
|
||||
|
||||
// 所在楼层
|
||||
// 总楼层
|
||||
private static final Map<String, String> FITMENT_MAP = new HashMap<String, String>() {
|
||||
{
|
||||
put("1", "毛坯");
|
||||
put("2", "简装");
|
||||
put("3", "精装");
|
||||
put("4", "豪装");
|
||||
}
|
||||
};
|
||||
private static final Map<Integer, String> LEVEL_MAP = new HashMap<Integer, String>() {
|
||||
{
|
||||
put(1, "甲级");
|
||||
put(2, "乙级");
|
||||
put(3, "丙级");
|
||||
}
|
||||
};
|
||||
private static final Map<Integer, String> TYPE_MAP = new HashMap<Integer, String>() {
|
||||
{
|
||||
put(1, "标准写字楼");
|
||||
put(2, "创意园区");
|
||||
put(3, "商住两用");
|
||||
put(4, "综合体");
|
||||
}
|
||||
};
|
||||
public Double calcRent(List<Seawater> seawaters, Evaluation evaluation) {
|
||||
// 计算平均值
|
||||
Double sum = 0.0;
|
||||
Double size = 0.0;
|
||||
Double unitPrice = null;
|
||||
Double factor = 1.0;
|
||||
// 按写字楼类型过滤
|
||||
List<Seawater> filterWithType = new ArrayList<Seawater>();
|
||||
if (evaluation.getType() != null) {
|
||||
if (TYPE_MAP.get(evaluation.getFitment()) != null) {
|
||||
for (Seawater seawater : seawaters) {
|
||||
if (TYPE_MAP.get(evaluation.getType()).equals(seawater.getEstateType())) {
|
||||
filterWithType.add(seawater);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果样本数量大于5,则按装修过滤
|
||||
if (filterWithType.size() > 5) {
|
||||
seawaters = filterWithType;
|
||||
} else {
|
||||
// TODO 按照写字楼类型进行调整,1:标准写字楼;2:创意园区;3:商住两用;4:综合体
|
||||
// 拍脑袋
|
||||
if (evaluation.getType() == 1) {
|
||||
factor *= 1.0;
|
||||
} else if (evaluation.getType() == 2) {
|
||||
factor *= 0.98;
|
||||
} else if (evaluation.getType() == 3) {
|
||||
factor *= 0.97;
|
||||
} else if (evaluation.getType() == 4) {
|
||||
factor *= 0.96;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 按写字楼等级过滤
|
||||
List<Seawater> filterWithGrade = new ArrayList<Seawater>();
|
||||
if (evaluation.getLevel() != null) {
|
||||
if (LEVEL_MAP.get(evaluation.getFitment()) != null) {
|
||||
for (Seawater seawater : seawaters) {
|
||||
if (LEVEL_MAP.get(evaluation.getLevel()).equals(seawater.getLevel())) {
|
||||
filterWithGrade.add(seawater);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果样本数量大于5,则按装修过滤
|
||||
if (filterWithGrade.size() > 5) {
|
||||
seawaters = filterWithGrade;
|
||||
} else {
|
||||
// TODO 按照写字楼等级进行调整,1:甲级;2:乙级;3:丙级
|
||||
// 拍脑袋
|
||||
if (evaluation.getLevel() == 1) {
|
||||
factor *= 1.2;
|
||||
} else if (evaluation.getLevel() == 2) {
|
||||
factor *= 1.0;
|
||||
} else if (evaluation.getLevel() == 3) {
|
||||
factor *= 0.9;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 按楼层过滤
|
||||
List<Seawater> filterWithFloor = new ArrayList<Seawater>();
|
||||
if (evaluation.getFloor() != null && evaluation.getHeight() != null) {
|
||||
Double floorInfo = evaluation.getFloor() * 1.0 / evaluation.getHeight();
|
||||
String floorDesc = "中层";
|
||||
if (floorInfo <= 0.33) {
|
||||
floorDesc = "低层";
|
||||
} else if (floorInfo > 0.66) {
|
||||
floorDesc = "高层";
|
||||
}
|
||||
if (LEVEL_MAP.get(evaluation.getFitment()) != null) {
|
||||
for (Seawater seawater : seawaters) {
|
||||
if (seawater.getFloorInfo() != null && seawater.getFloorInfo().contains(floorDesc)) {
|
||||
filterWithFloor.add(seawater);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果样本数量大于5,则按装修过滤
|
||||
if (filterWithFloor.size() > 5) {
|
||||
seawaters = filterWithGrade;
|
||||
} else {
|
||||
// TODO 按照写字楼楼层进行调整,高层 中层 低层
|
||||
// 拍脑袋
|
||||
if (floorDesc.equals("高层")) {
|
||||
factor *= 1.2;
|
||||
} else if (floorDesc.equals("中层")) {
|
||||
factor *= 1.0;
|
||||
} else if (floorDesc.equals("低层")) {
|
||||
factor *= 0.9;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 按装修过滤
|
||||
List<Seawater> filterWithFitment = new ArrayList<Seawater>();
|
||||
|
||||
if (evaluation.getFitment() != null) {
|
||||
if (FITMENT_MAP.get(evaluation.getFitment()) != null) {
|
||||
for (Seawater seawater : seawaters) {
|
||||
if (FITMENT_MAP.get(evaluation.getFitment()).equals(seawater.getFitment())) {
|
||||
filterWithFitment.add(seawater);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果样本数量大于5,则按装修过滤
|
||||
if (filterWithFitment.size() > 5) {
|
||||
seawaters = filterWithFitment;
|
||||
} else {
|
||||
// TODO 按照装修系数进行调整,如1: 毛坯,2: 简装,3: 精装,4: 豪装
|
||||
// 拍脑袋
|
||||
if (evaluation.getFitment().equals(1)) {
|
||||
factor *= 0.8;
|
||||
} else if (evaluation.getFitment().equals(2)) {
|
||||
factor *= 1.0;
|
||||
} else if (evaluation.getFitment().equals(3)) {
|
||||
factor *= 1.2;
|
||||
} else if (evaluation.getFitment().equals(4)) {
|
||||
factor *= 1.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO 3.4免租期factor*调整因子:factory - 免租期/最低起租期
|
||||
// TODO 物业费因子
|
||||
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 * factor, 2);
|
||||
}
|
||||
return unitPrice ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Evaluation addressEvaluateRent(Evaluation evaluation) {
|
||||
if (null == evaluation.getFloor() || 0 == evaluation.getFloor() || null == evaluation.getHeight() || 0 == evaluation.getHeight()) {
|
||||
evaluation.setFloor(null);
|
||||
evaluation.setHeight(null);
|
||||
}
|
||||
// 评估逻辑
|
||||
String location = getLocation(evaluation.getCity(), evaluation.getAddress());
|
||||
evaluation.setLocation(location);
|
||||
Double unitPrice = rentEvaluateByLocation(evaluation);
|
||||
evaluation.setUnitPrice(unitPrice);
|
||||
return evaluation;
|
||||
}
|
||||
|
||||
private Double rentEvaluateByLocation(Evaluation evaluation) {
|
||||
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(10);
|
||||
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, evaluation);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
||||
public List<OfficeRentStat> findOfficeRentStat(final String city, final String region, final Integer startDate, final Integer endDate) {
|
||||
return CacheUtils.getValue(this.getClass(), "findOfficeRentStat", city + region + startDate + endDate,
|
||||
CacheUtils.CachePolicyEnum.MIDDLE, new Closure<List<OfficeRentStat>, String>() {
|
||||
public List<OfficeRentStat> execute(String input) {
|
||||
return doFindRegionBlockStat(city, region, startDate, endDate);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<OfficeRentStat> doFindRegionBlockStat(final String city, final String region, Integer startDate, Integer endDate) {
|
||||
if (startDate == null) {
|
||||
throw new IllegalArgumentException("开始日期不能为空");
|
||||
}
|
||||
if (endDate == null) {
|
||||
throw new IllegalArgumentException("结束日期不能为空");
|
||||
}
|
||||
|
||||
List<QueryParam> params = new ArrayList<QueryParam>();
|
||||
params.add(new QueryParam("city", city));
|
||||
params.add(new QueryParam("district", region));
|
||||
|
||||
if (startDate != null) {
|
||||
params.add(new QueryParam("date", QueryParam.GREATER_THAN_EQUAL_OPERATOR, startDate));
|
||||
}
|
||||
if (endDate != null) {
|
||||
params.add(new QueryParam("date", QueryParam.LESS_THAN_EQUAL_OPERATOR, endDate));
|
||||
}
|
||||
List<SortParam> sortParams = new ArrayList<SortParam>();
|
||||
sortParams.add(new SortParam("date", true));
|
||||
List<OfficeRentStat> regionStats = officeRentStatDao.findAllByParams(params, sortParams);
|
||||
return regionStats;
|
||||
}
|
||||
|
||||
public void setSeawaterService(SeawaterService seawaterService) {
|
||||
this.seawaterService = seawaterService;
|
||||
}
|
||||
|
||||
public void setOfficeRentStatDao(OfficeRentStatDao officeRentStatDao) {
|
||||
this.officeRentStatDao = officeRentStatDao;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user