Merge remote-tracking branch 'origin/master'
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
||||
package com.fangjia.dal.mongo.dao.office;
|
||||
|
||||
import com.fangjia.dal.MongoDao;
|
||||
import com.fangjia.dal.mongo.model.OfficeRentStat;
|
||||
|
||||
public interface OfficeRentStatDao extends MongoDao<OfficeRentStat> {
|
||||
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.fangjia.dal.mongo.dao.office;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fangjia.dal.mongo.dao.RegionStatDao;
|
||||
import com.fangjia.dal.mongo.model.OfficeRentStat;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.fangjia.core.util.DateUtil;
|
||||
import com.fangjia.dal.MongoDaoImpl;
|
||||
import com.fangjia.dal.QueryParam;
|
||||
import com.fangjia.dal.SortParam;
|
||||
import com.fangjia.dal.mongo.model.RegionStat;
|
||||
|
||||
public class OfficeRentStatDaoImpl extends MongoDaoImpl<OfficeRentStat> implements OfficeRentStatDao {
|
||||
|
||||
}
|
||||
@@ -1,17 +1,10 @@
|
||||
package com.fangjia.dal.mongo.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import com.fangjia.dal.MongoEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
@Table(name = "fangjia.evaluation")
|
||||
public class Evaluation implements MongoEntity {
|
||||
@@ -128,6 +121,27 @@ public class Evaluation implements MongoEntity {
|
||||
//我查查状态字段
|
||||
private int statusCha;
|
||||
|
||||
private Double unitPrice;
|
||||
|
||||
/**
|
||||
* 写字楼类型:1:标准写字楼;2:创意园区;3:商住两用;4:综合体
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 写字楼等级 1:甲级;2:乙级;3:丙级
|
||||
*/
|
||||
private Integer level;
|
||||
|
||||
/**
|
||||
* 免租期(月)
|
||||
*/
|
||||
private Integer rentFreePeriod;
|
||||
|
||||
/**
|
||||
* 物业费(元/m?/月)
|
||||
*/
|
||||
private Double propertyManagementFee;
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "_id")
|
||||
@@ -180,6 +194,7 @@ public class Evaluation implements MongoEntity {
|
||||
return totalPrice;
|
||||
}
|
||||
|
||||
|
||||
public void setTotalPrice(Integer totalPrice) {
|
||||
this.totalPrice = totalPrice;
|
||||
}
|
||||
@@ -995,4 +1010,48 @@ public class Evaluation implements MongoEntity {
|
||||
this.statusCha = statusCha;
|
||||
}
|
||||
|
||||
@Column(name = "unit_price")
|
||||
public Double getUnitPrice() {
|
||||
return unitPrice;
|
||||
}
|
||||
|
||||
public void setUnitPrice(Double unitPrice) {
|
||||
this.unitPrice = unitPrice;
|
||||
}
|
||||
|
||||
@Column(name = "type")
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Column(name = "level")
|
||||
public Integer getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(Integer level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Column(name = "rent_free_period")
|
||||
public Integer getRentFreePeriod() {
|
||||
return rentFreePeriod;
|
||||
}
|
||||
|
||||
public void setRentFreePeriod(Integer rentFreePeriod) {
|
||||
this.rentFreePeriod = rentFreePeriod;
|
||||
}
|
||||
|
||||
@Column(name = "property_management_fee")
|
||||
public Double getPropertyManagementFee() {
|
||||
return propertyManagementFee;
|
||||
}
|
||||
|
||||
public void setPropertyManagementFee(Double propertyManagementFee) {
|
||||
this.propertyManagementFee = propertyManagementFee;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.fangjia.dal.mongo.model;
|
||||
|
||||
import com.fangjia.dal.MongoEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
@Table(name = "fangjia_stat.office_rent_stat")
|
||||
public class OfficeRentStat implements MongoEntity {
|
||||
private static final long serialVersionUID = 4425229045088250573L;
|
||||
|
||||
private String id;
|
||||
private String cat;
|
||||
private String city;
|
||||
private String district;
|
||||
private Integer date;
|
||||
private Double avgPrice;
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "_id", unique = true, nullable = false)
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(name = "cat")
|
||||
public String getCat() {
|
||||
return cat;
|
||||
}
|
||||
|
||||
public void setCat(String cat) {
|
||||
this.cat = cat;
|
||||
}
|
||||
|
||||
@Column(name = "city")
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
@Column(name = "district")
|
||||
public String getDistrict() {
|
||||
return district;
|
||||
}
|
||||
|
||||
public void setDistrict(String district) {
|
||||
this.district = district;
|
||||
}
|
||||
|
||||
@Column(name = "date")
|
||||
public Integer getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Integer date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
@Column(name = "avg_price")
|
||||
public Double getAvgPrice() {
|
||||
return avgPrice;
|
||||
}
|
||||
|
||||
public void setAvgPrice(Double avgPrice) {
|
||||
this.avgPrice = avgPrice;
|
||||
}
|
||||
}
|
||||
+512
@@ -0,0 +1,512 @@
|
||||
package com.fangjia.open.controllers;
|
||||
|
||||
import com.fangjia.core.RegionData;
|
||||
import com.fangjia.core.util.AnalyticsUtil;
|
||||
import com.fangjia.core.util.DataUtil;
|
||||
import com.fangjia.core.util.LoggerFactory;
|
||||
import com.fangjia.dal.common.ServerAreaData;
|
||||
import com.fangjia.dal.mongo.fangjia.model.ServerArea;
|
||||
import com.fangjia.dal.mongo.model.Evaluation;
|
||||
import com.fangjia.dal.mongo.model.OfficeRentStat;
|
||||
import com.fangjia.dal.seaweed.model.District;
|
||||
import com.fangjia.open.HttpCode;
|
||||
import com.fangjia.open.OpenHttpCodeEnum;
|
||||
import com.fangjia.open.interceptors.AuthenticationBean;
|
||||
import com.fangjia.open.interceptors.Authority;
|
||||
import com.fangjia.open.interceptors.Role;
|
||||
import com.fangjia.open.model.BasicModel;
|
||||
import com.fangjia.open.model.PropertyEvaluationModel;
|
||||
import com.fangjia.open.model.RestfulModelAndView;
|
||||
import com.fangjia.open.util.CommonUtils;
|
||||
import com.fangjia.service.api.AddressMatchProxyService;
|
||||
import com.fangjia.service.datastore.DistrictService;
|
||||
import com.fangjia.service.datastore.OfficeService;
|
||||
import com.fangjia.service.datastore.OpenApiLogService;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.sothis.web.mvc.ActionContext;
|
||||
import org.sothis.web.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.fangjia.open.util.CommonUtils.convertToString;
|
||||
import static com.fangjia.open.util.EvaluationFactorUtil.*;
|
||||
|
||||
/**
|
||||
* @author shenjian
|
||||
* @since 2025/1/21
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public class OfficeController {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PropertyController.class);
|
||||
|
||||
private OfficeService officeService;
|
||||
|
||||
private DistrictService districtService;
|
||||
|
||||
private AddressMatchProxyService addressMatchProxyService;
|
||||
|
||||
private OpenApiLogService openApiLogService;
|
||||
|
||||
/**
|
||||
* 城市出租均价
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Object cityRentAction(@Param(name = "city") String city, @Param(name = "startDate") Integer startDate, @Param(name = "endDate") Integer endDate) {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isBlank(city)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city不能为null"));
|
||||
return mav;
|
||||
}
|
||||
if (!RegionData.isCity(city)) {
|
||||
String formatCity = RegionData.formatCity(city);
|
||||
if (StringUtils.isNotBlank(formatCity)) {
|
||||
city = formatCity;
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city非法"));
|
||||
return mav;
|
||||
}
|
||||
}
|
||||
ServerArea serverArea = ServerAreaData.getServerAreaByCity(city);
|
||||
if (null == serverArea) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city非法"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
if (startDate == null || endDate == null) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("startDate或endDate不能为null"));
|
||||
return mav;
|
||||
}
|
||||
if (startDate > endDate) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("startDate不能大于endDate"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
List<OfficeRentStat> regionStats = officeService.findOfficeRentStat(city, null, startDate, endDate);
|
||||
|
||||
if (CollectionUtils.isEmpty(regionStats)) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "该城市没有均价数据"));
|
||||
return mav;
|
||||
}
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(regionStats));
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
* 区域出租均价
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Object districtRentAction(@Param(name = "city") String city, @Param(name = "district") String district,
|
||||
@Param(name = "startDate") Integer startDate, @Param(name = "endDate") Integer endDate) {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isBlank(city)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city不能为null"));
|
||||
return mav;
|
||||
}
|
||||
if (StringUtils.isBlank(district)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("district不能为null"));
|
||||
return mav;
|
||||
}
|
||||
if (!RegionData.isCity(city)) {
|
||||
String formatCity = RegionData.formatCity(city);
|
||||
if (StringUtils.isNotBlank(formatCity)) {
|
||||
city = formatCity;
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city非法"));
|
||||
return mav;
|
||||
}
|
||||
}
|
||||
ServerArea serverArea = ServerAreaData.getServerAreaByCity(city);
|
||||
if (null == serverArea) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city非法"));
|
||||
return mav;
|
||||
}
|
||||
String region = RegionData.formatRegion(city, district);
|
||||
if (!RegionData.isRegion(city, region)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("没有找你输入的区域"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
if (startDate == null || endDate == null) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("startDate或endDate不能为null"));
|
||||
return mav;
|
||||
}
|
||||
if (startDate > endDate) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("startDate不能大于endDate"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
List<OfficeRentStat> regionStats = officeService.findOfficeRentStat(city, region, startDate, endDate);
|
||||
|
||||
if (CollectionUtils.isEmpty(regionStats)) {
|
||||
mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "该区域没有均价数据"));
|
||||
return mav;
|
||||
}
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(regionStats));
|
||||
return mav;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写字楼楼租金地址估值
|
||||
*
|
||||
* @param model
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public Object addressEvaluateRentAction(PropertyEvaluationModel model, HttpServletRequest request) {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getAddress()) || model.getSize() <= 0) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,地址,面积(size)为必填项"));
|
||||
return mav;
|
||||
}
|
||||
if (model.getCity().endsWith("市")) {
|
||||
model.setCity(model.getCity().replaceAll("市$", ""));
|
||||
}
|
||||
|
||||
if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法"));
|
||||
return mav;
|
||||
}
|
||||
if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)"));
|
||||
return mav;
|
||||
}
|
||||
if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
if (model.getFloor() == null) {
|
||||
JSONObject structureOb = addressMatchProxyService.addressStructure(model.getCity(), model.getAddress());
|
||||
if (structureOb != null) {
|
||||
if (structureOb.containsKey("buildingNumber")) {
|
||||
model.setBuildingNumber(structureOb.getString("buildingNumber"));
|
||||
}
|
||||
|
||||
if (structureOb.containsKey("roomNumber")) {
|
||||
String roomNumber = structureOb.getString("roomNumber");
|
||||
model.setFloor(getFloor(roomNumber));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Evaluation evaluation = officeService.addressEvaluateRent(buildEvaluation(model, request));
|
||||
|
||||
if (evaluation.getUnitPrice() != null && evaluation.getUnitPrice() != 0) {
|
||||
Map<String, Object> districtPriceMap = new HashMap<String, Object>();
|
||||
districtPriceMap.put("unitPrice", evaluation.getUnitPrice());
|
||||
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap));
|
||||
try {
|
||||
if (StringUtils.isNotBlank(evaluation.getFromUserId()) && !evaluation.getFromUserId().equals("1007497")) {
|
||||
openApiLogService.saveLog(CommonUtils.convertToMap(model), districtPriceMap, evaluation, "/office/addressEvaluateRent");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return mav;
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该地址写字楼的评估").markNoData());
|
||||
return mav;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 写字楼租金评估
|
||||
*
|
||||
* @param model
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public Object evaluateRentAction(PropertyEvaluationModel model, HttpServletRequest request) {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName())
|
||||
|| StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0 || model.getCity().contains("全国")
|
||||
|| model.getDistrict().contains("全国")) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,写字楼名,面积(size)为必填项"));
|
||||
return mav;
|
||||
}
|
||||
if (model.getCity().endsWith("市")) {
|
||||
model.setCity(model.getCity().replaceAll("市$", ""));
|
||||
}
|
||||
/* 先到CPDB库中查找写字楼 */
|
||||
District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), "office");
|
||||
if (district == null) {
|
||||
if (model.getDistrict().contains("市辖区") || model.getDistrict().contains(model.getCity())) {
|
||||
district = districtService.findByNameAndAlias(model.getCity(), null, model.getName(), "district");
|
||||
}
|
||||
if (district == null) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("该写字楼不存在"));
|
||||
return mav;
|
||||
}
|
||||
}
|
||||
model.setName(district.getName());
|
||||
|
||||
if (model.getCarportPrice() != null && (model.getCarportPrice() < 0 || model.getCarportPrice() > 1000000)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("carportPrice(车位)取值不合法"));
|
||||
return mav;
|
||||
}
|
||||
if (model.getMaxFloor() != null && (model.getMaxFloor() <= 0 || model.getMaxFloor() > 59)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("maxFloor取值非法,正确范围[1,60)"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
if (model.getFloor() != null && (model.getFloor() <= 0 || model.getFloor() > 59)) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("floor取值非法,正确范围[1,60)"));
|
||||
return mav;
|
||||
}
|
||||
if (model.getMaxFloor() != null && model.getFloor() != null && model.getFloor() > model.getMaxFloor()) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
if (model.getFloor() == null) {
|
||||
JSONObject structureOb = addressMatchProxyService.addressStructure(district.getCity(), model.getAddress());
|
||||
if (structureOb != null) {
|
||||
if (structureOb.containsKey("buildingNumber")) {
|
||||
model.setBuildingNumber(structureOb.getString("buildingNumber"));
|
||||
}
|
||||
|
||||
if (structureOb.containsKey("roomNumber")) {
|
||||
String roomNumber = structureOb.getString("roomNumber");
|
||||
model.setFloor(getFloor(roomNumber));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
model.setRegion(district.getRegion());
|
||||
model.setDistrictName(district.getName());
|
||||
|
||||
Evaluation evaluation = officeService.evaluateRent(district, buildEvaluation(model, request));
|
||||
|
||||
if (evaluation.getUnitPrice() != null && evaluation.getUnitPrice() != 0) {
|
||||
Map<String, Object> districtPriceMap = new HashMap<String, Object>();
|
||||
districtPriceMap.put("city", district.getCity());
|
||||
districtPriceMap.put("district", district.getRegion());
|
||||
districtPriceMap.put("name", district.getName());
|
||||
districtPriceMap.put("unitPrice", evaluation.getUnitPrice());
|
||||
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap));
|
||||
try {
|
||||
if (StringUtils.isNotBlank(evaluation.getFromUserId()) && !evaluation.getFromUserId().equals("1007497")) {
|
||||
openApiLogService.saveLog(CommonUtils.convertToMap(model), districtPriceMap, evaluation, "/office/evaluateRent");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return mav;
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该写字楼的评估").markNoData());
|
||||
return mav;
|
||||
}
|
||||
}
|
||||
|
||||
private Integer getFloor(String roomNumber) {
|
||||
if (StringUtils.isNotBlank(roomNumber) && DataUtil.isNumber(roomNumber)) {
|
||||
if (roomNumber.length() == 3) {
|
||||
return Integer.valueOf(roomNumber.substring(0, 1));
|
||||
} else if (roomNumber.length() == 4) {
|
||||
return Integer.valueOf(roomNumber.substring(0, 2));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过EvaluationModel组装Evaluation实体
|
||||
*
|
||||
* @param model
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private Evaluation buildEvaluation(PropertyEvaluationModel model, HttpServletRequest request) {
|
||||
Evaluation evaluation = new Evaluation();
|
||||
evaluation.setLevel(model.getLevel());
|
||||
evaluation.setFitment(model.getFitment());
|
||||
evaluation.setType(model.getType());
|
||||
|
||||
evaluation.setCity(model.getCity());
|
||||
evaluation.setRegion(model.getRegion());
|
||||
evaluation.setDistrictName(model.getName());
|
||||
evaluation.setAddress(model.getAddress());
|
||||
evaluation.setDirection(DIRECTION.get(model.getDirection()));
|
||||
evaluation.setNoise(NOISE.get(model.getNoise()));
|
||||
evaluation.setEstateType(PROPERTY_TYPES.get(model.getPropertyType()));
|
||||
evaluation.setSight(SIGHT.get(model.getView()));
|
||||
evaluation.setAtticArea(model.getAtticSize());
|
||||
evaluation.setTerraceArea(model.getOuterSize());
|
||||
evaluation.setBasementArea(model.getBasementSize());
|
||||
evaluation.setGardenArea(model.getGardenSize());
|
||||
String worryFacility = model.getNegativeFactor();
|
||||
evaluation.setWorryFacility(NEGATIVE_FACTOR.get(worryFacility));
|
||||
evaluation.setCreationDate(new Date());
|
||||
evaluation.setModificationDate(new Date());
|
||||
evaluation.setClientNo(model.getClientNo());
|
||||
if (0 != model.getAge()) {
|
||||
evaluation.setAge(model.getAge());
|
||||
}
|
||||
evaluation.setArea(model.getSize());
|
||||
if (ArrayUtils.isNotEmpty(model.getBuildQuality())) {
|
||||
evaluation.setBuildQuality(convertToString(model.getBuildQuality()));
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getBuildType())) {
|
||||
evaluation.setBuildType(model.getBuildType());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getCarport())) {
|
||||
evaluation.setCarport(model.getCarport());
|
||||
}
|
||||
if (model.getDecorationAge() >= 1 && model.getDecorationAge() <= 5) {
|
||||
evaluation.setFitmentAge(model.getDecorationAge());
|
||||
}
|
||||
evaluation.setCarportPrice(model.getCarportPrice());
|
||||
evaluation.setCity(model.getCity());
|
||||
evaluation.setDistrictName(model.getName());
|
||||
if (model.getDecorationCost() != null && model.getDecorationCost() > 0) {
|
||||
evaluation.setFitmentCharge(model.getDecorationCost());
|
||||
}
|
||||
if (0 != model.getHall()) {
|
||||
evaluation.setHall(model.getHall());
|
||||
}
|
||||
if (null != model.getFloor()) {
|
||||
evaluation.setFloor(model.getFloor());
|
||||
}
|
||||
if (model.getMaxFloor() != null && 0 != model.getMaxFloor()) {
|
||||
evaluation.setHeight(model.getMaxFloor());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getBuildingNumber())) {
|
||||
evaluation.setHouseNum(model.getBuildingNumber());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getHouseProperty())) {
|
||||
evaluation.setHouseProperty(model.getHouseProperty());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getInsidepos())) {
|
||||
evaluation.setInsidepos(model.getInsidepos());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getLightingVentilation())) {
|
||||
evaluation.setLightingVentilation(model.getLightingVentilation());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(model.getOtherFactor())) {
|
||||
evaluation.setOtherFactor(model.getOtherFactor());
|
||||
}
|
||||
evaluation.setRegion(model.getDistrict());
|
||||
if (null != model.getRoom()) {
|
||||
evaluation.setRoom(model.getRoom());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getRoomNumber())) {
|
||||
evaluation.setRoomNum(model.getRoomNumber());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getSideset())) {
|
||||
evaluation.setSideset(model.getSideset());
|
||||
}
|
||||
if (0 != model.getToilet()) {
|
||||
evaluation.setToilet(model.getToilet());
|
||||
}
|
||||
if (model.getFacilities() != null) {
|
||||
String facilities = model.getFacilities();
|
||||
String[] fs = facilities.split(",");
|
||||
for (int i = 0; i < fs.length; i++) {
|
||||
fs[i] = FACILITIES.get(fs[i]);
|
||||
}
|
||||
evaluation.setFacilities(convertToString(fs));
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(model.getFacade())) {
|
||||
evaluation.setFacade(model.getFacade());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getTraffice())) {
|
||||
evaluation.setTraffice(model.getTraffice());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getShape())) {
|
||||
evaluation.setShape(model.getShape());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getObstacle())) {
|
||||
evaluation.setObstacle(model.getObstacle());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getIndustry())) {
|
||||
evaluation.setIndustry(model.getIndustry());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getSupportDevice())) {
|
||||
evaluation.setSupportDevice(model.getSupportDevice());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getLeftPosition())) {
|
||||
evaluation.setLeftPosition(model.getLeftPosition());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getShopType())) {
|
||||
evaluation.setShopType(model.getShopType());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getShopUnique())) {
|
||||
evaluation.setShopUnique(model.getShopUnique());
|
||||
}
|
||||
if (StringUtils.isNotBlank(model.getLocation())) {
|
||||
evaluation.setLocation(model.getLocation());
|
||||
}
|
||||
if (model.isNewDistrict()) {
|
||||
evaluation.setNewDistrict(model.isNewDistrict());
|
||||
}
|
||||
String ip = AnalyticsUtil.getIpAddress(ActionContext.getContext().getRequest());
|
||||
evaluation.setIp(ip);
|
||||
AuthenticationBean authenticationBean = (AuthenticationBean) request
|
||||
.getAttribute(AuthenticationBean.ATTR_AUTHENTICATION_BEAN);
|
||||
if (authenticationBean != null && authenticationBean.apiUser != null) {
|
||||
evaluation.setFromUserId(String.valueOf(authenticationBean.apiUser.getId()));
|
||||
}
|
||||
evaluation.setSource("api_office_evaluateRent");
|
||||
return evaluation;
|
||||
}
|
||||
|
||||
private static final Map<String, String> FACILITIES = new HashMap<String, String>() {
|
||||
{
|
||||
put("0", "健身房");
|
||||
put("1", "游泳池");
|
||||
put("2", "会所");
|
||||
put("3", "网球场");
|
||||
put("4", "球场");
|
||||
put("5", "棋牌室");
|
||||
put("6", "停车场");
|
||||
put("7", "图书馆");
|
||||
put("8", "活动中心");
|
||||
}
|
||||
};
|
||||
|
||||
public void setOpenApiLogService(OpenApiLogService openApiLogService) {
|
||||
this.openApiLogService = openApiLogService;
|
||||
}
|
||||
|
||||
public void setOfficeService(OfficeService officeService) {
|
||||
this.officeService = officeService;
|
||||
}
|
||||
|
||||
public void setDistrictService(DistrictService districtService) {
|
||||
this.districtService = districtService;
|
||||
}
|
||||
|
||||
public void setAddressMatchProxyService(AddressMatchProxyService addressMatchProxyService) {
|
||||
this.addressMatchProxyService = addressMatchProxyService;
|
||||
}
|
||||
}
|
||||
+18
-2
@@ -1,7 +1,5 @@
|
||||
package com.fangjia.open.model;
|
||||
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import java.util.Date;
|
||||
|
||||
public class PropertyEvaluationModel extends FangjiaApiModel {
|
||||
@@ -291,6 +289,8 @@ public class PropertyEvaluationModel extends FangjiaApiModel {
|
||||
|
||||
private Integer avgPrice;
|
||||
|
||||
private Integer level;
|
||||
private Integer type;
|
||||
|
||||
public void setDecorationAge(int decorationAge) {
|
||||
this.decorationAge = decorationAge;
|
||||
@@ -926,4 +926,20 @@ public class PropertyEvaluationModel extends FangjiaApiModel {
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(Integer level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
package com.fangjia.open.util;
|
||||
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
//¹«ÓÃ
|
||||
public class CommonUtils {
|
||||
|
||||
|
||||
//¶ÔÏóתmap
|
||||
public static Map<String, Object> convertToMap(Object obj) {
|
||||
try {
|
||||
if (obj instanceof Map) {
|
||||
return (Map)obj;
|
||||
return (Map) obj;
|
||||
}
|
||||
Map<String, Object> returnMap = BeanUtils.describe(obj);
|
||||
returnMap.remove("class");
|
||||
@@ -26,4 +29,19 @@ public class CommonUtils {
|
||||
}
|
||||
return new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
public static String convertToString(String[] strs) {
|
||||
if (ArrayUtils.isNotEmpty(strs)) {
|
||||
StringBuffer ret = new StringBuffer();
|
||||
for (String str : strs) {
|
||||
if (StringUtils.isEmpty(ret.toString())) {
|
||||
ret.append(str);
|
||||
} else {
|
||||
ret.append(",").append(str);
|
||||
}
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+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