From d46691356409bb1aebf7765f0f69e394ead2fc78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Tue, 21 Jan 2025 17:45:19 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=86=99=E5=AD=97?= =?UTF-8?q?=E6=A5=BC=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mongo/dao/office/OfficeRentStatDao.java | 13 ++ .../dao/office/OfficeRentStatDaoImpl.java | 23 ++++ .../dal/mongo/model/OfficeRentStat.java | 75 ++++++++++ .../open/controllers/OfficeController.java | 129 ++++++++++++++++++ .../service/datastore/OfficeService.java | 23 ++++ .../service/datastore/OfficeServiceImpl.java | 57 ++++++++ 6 files changed, 320 insertions(+) create mode 100644 projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/office/OfficeRentStatDao.java create mode 100644 projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/office/OfficeRentStatDaoImpl.java create mode 100644 projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/OfficeRentStat.java create mode 100644 projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java create mode 100644 projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeService.java create mode 100644 projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java diff --git a/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/office/OfficeRentStatDao.java b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/office/OfficeRentStatDao.java new file mode 100644 index 000000000..84bd6d813 --- /dev/null +++ b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/office/OfficeRentStatDao.java @@ -0,0 +1,13 @@ +package com.fangjia.dal.mongo.dao.office; + +import com.fangjia.dal.MongoDao; +import com.fangjia.dal.mongo.model.OfficeRentStat; +import com.fangjia.dal.mongo.model.RegionStat; + +import java.util.Date; +import java.util.List; + +public interface OfficeRentStatDao extends MongoDao { + + +} diff --git a/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/office/OfficeRentStatDaoImpl.java b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/office/OfficeRentStatDaoImpl.java new file mode 100644 index 000000000..7cbafebad --- /dev/null +++ b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/office/OfficeRentStatDaoImpl.java @@ -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 implements OfficeRentStatDao { + +} diff --git a/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/OfficeRentStat.java b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/OfficeRentStat.java new file mode 100644 index 000000000..900281731 --- /dev/null +++ b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/OfficeRentStat.java @@ -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; + } +} diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java new file mode 100644 index 000000000..0a9bd116c --- /dev/null +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java @@ -0,0 +1,129 @@ +package com.fangjia.open.controllers; + +import com.fangjia.core.RegionData; +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.OfficeRentStat; +import com.fangjia.open.HttpCode; +import com.fangjia.open.OpenHttpCodeEnum; +import com.fangjia.open.interceptors.Authority; +import com.fangjia.open.interceptors.Role; +import com.fangjia.open.model.BasicModel; +import com.fangjia.open.model.RestfulModelAndView; +import com.fangjia.service.datastore.OfficeService; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.sothis.web.mvc.annotation.Param; + +import java.util.List; + +/** + * @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; + + /** + * 城市出租均价 + * + * @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 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 (!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 regionStats = officeService.findOfficeRentStat(city, district, 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; + } + + public void setOfficeService(OfficeService officeService) { + this.officeService = officeService; + } +} diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeService.java b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeService.java new file mode 100644 index 000000000..5e18e3f6e --- /dev/null +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeService.java @@ -0,0 +1,23 @@ +package com.fangjia.service.datastore; + +import com.fangjia.dal.mongo.model.OfficeRentStat; + +import java.util.List; + +/** + * @author shenjian + * @since 2025/1/21 + */ +public interface OfficeService { + + + /** + * @param city + * @param region + * @param startDate + * @param endDate + * @return + */ + List findOfficeRentStat(final String city, final String region, final Integer startDate, final Integer endDate); + +} diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java new file mode 100644 index 000000000..104ef39d9 --- /dev/null +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java @@ -0,0 +1,57 @@ +package com.fangjia.service.datastore; + +import com.fangjia.core.util.CacheUtils; +import com.fangjia.dal.QueryParam; +import com.fangjia.dal.SortParam; +import com.fangjia.dal.mongo.dao.office.OfficeRentStatDao; +import com.fangjia.dal.mongo.model.OfficeRentStat; +import org.sothis.core.util.Closure; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author shenjian + * @since 2025/1/21 + */ +public class OfficeServiceImpl implements OfficeService { + + private OfficeRentStatDao officeRentStatDao; + + public List 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, String>() { + public List execute(String input) { + return doFindRegionBlockStat(city, region, startDate, endDate); + } + }); + } + + public List doFindRegionBlockStat(final String city, final String region, Integer startDate, Integer endDate) { + if (startDate == null) { + throw new IllegalArgumentException("开始日期不能为空"); + } + if (endDate == null) { + throw new IllegalArgumentException("结束日期不能为空"); + } + + List params = new ArrayList(); + 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 sortParams = new ArrayList(); + sortParams.add(new SortParam("date", true)); + List regionStats = officeRentStatDao.findAllByParams(params, sortParams); + return regionStats; + } + + public void setOfficeRentStatDao(OfficeRentStatDao officeRentStatDao) { + this.officeRentStatDao = officeRentStatDao; + } +} From 4e791bf94994c9543a9a607dadeb644ce8090c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Wed, 22 Jan 2025 09:52:34 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=86=99=E5=AD=97?= =?UTF-8?q?=E6=A5=BC=E4=BC=B0=E5=80=BC=E4=BC=B0=E5=80=BC=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mongo/dao/office/OfficeRentStatDao.java | 4 - .../fangjia/dal/mongo/model/Evaluation.java | 23 +- .../open/controllers/OfficeController.java | 386 +++++++++++++++++- .../com/fangjia/open/util/CommonUtils.java | 24 +- .../service/datastore/OfficeService.java | 20 + .../service/datastore/OfficeServiceImpl.java | 28 ++ 6 files changed, 466 insertions(+), 19 deletions(-) diff --git a/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/office/OfficeRentStatDao.java b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/office/OfficeRentStatDao.java index 84bd6d813..1a4066162 100644 --- a/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/office/OfficeRentStatDao.java +++ b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/office/OfficeRentStatDao.java @@ -2,10 +2,6 @@ package com.fangjia.dal.mongo.dao.office; import com.fangjia.dal.MongoDao; import com.fangjia.dal.mongo.model.OfficeRentStat; -import com.fangjia.dal.mongo.model.RegionStat; - -import java.util.Date; -import java.util.List; public interface OfficeRentStatDao extends MongoDao { diff --git a/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/Evaluation.java b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/Evaluation.java index 692beb580..7fe4170a1 100644 --- a/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/Evaluation.java +++ b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/Evaluation.java @@ -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,7 @@ public class Evaluation implements MongoEntity { //我查查状态字段 private int statusCha; + private Double unitPrice; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "_id") @@ -180,6 +174,7 @@ public class Evaluation implements MongoEntity { return totalPrice; } + public void setTotalPrice(Integer totalPrice) { this.totalPrice = totalPrice; } @@ -995,4 +990,12 @@ 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; + } } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java index 0a9bd116c..a3b62b926 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java @@ -1,23 +1,43 @@ 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 @@ -30,6 +50,12 @@ public class OfficeController { private OfficeService officeService; + private DistrictService districtService; + + private AddressMatchProxyService addressMatchProxyService; + + private OpenApiLogService openApiLogService; + /** * 城市出租均价 * @@ -89,6 +115,10 @@ public class OfficeController { 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)) { @@ -103,6 +133,11 @@ public class OfficeController { 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")); @@ -113,17 +148,364 @@ public class OfficeController { return mav; } - List regionStats = officeService.findOfficeRentStat(city, district, startDate, endDate); + List regionStats = officeService.findOfficeRentStat(city, region, startDate, endDate); if (CollectionUtils.isEmpty(regionStats)) { - mav.setModel(new HttpCode(OpenHttpCodeEnum.TARGET_DATA_NOT_EXIST, "该城市没有均价数据")); + 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 districtPriceMap = new HashMap(); + 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)); + Double cityPriceCredit = null; + + if (evaluation.getUnitPrice() != null && evaluation.getUnitPrice() != 0) { + Map districtPriceMap = new HashMap(); + 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.setCity(model.getCity()); + evaluation.setRegion(model.getRegion()); + evaluation.setDistrictName(model.getName()); + evaluation.setAddress(model.getAddress()); + evaluation.setDirection(DIRECTION.get(model.getDirection())); + evaluation.setFitment(EVALUATION_MODEL_FITMENT.get(FITMENT.get(StringUtils.isNotBlank(model.getDecoration()) ? + model.getDecoration() : model.getFitment()))); + 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 FACILITIES = new HashMap() { + { + 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; + } } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/util/CommonUtils.java b/projects/fangjia-open/src/main/java/com/fangjia/open/util/CommonUtils.java index f5b3497e9..f5c8ea110 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/util/CommonUtils.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/util/CommonUtils.java @@ -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 convertToMap(Object obj) { try { if (obj instanceof Map) { - return (Map)obj; + return (Map) obj; } Map returnMap = BeanUtils.describe(obj); returnMap.remove("class"); @@ -26,4 +29,19 @@ public class CommonUtils { } return new HashMap(); } + + 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; + } } diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeService.java b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeService.java index 5e18e3f6e..a3276a571 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeService.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeService.java @@ -1,6 +1,8 @@ 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; @@ -12,6 +14,8 @@ public interface OfficeService { /** + * 租金均价 + * * @param city * @param region * @param startDate @@ -20,4 +24,20 @@ public interface OfficeService { */ List 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); } diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java index 104ef39d9..0ef5351ae 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java @@ -4,13 +4,17 @@ import com.fangjia.core.util.CacheUtils; import com.fangjia.dal.QueryParam; 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.seaweed.model.District; import org.sothis.core.util.Closure; import java.util.ArrayList; import java.util.List; /** + * 写字楼相关服务类 + * * @author shenjian * @since 2025/1/21 */ @@ -18,6 +22,30 @@ public class OfficeServiceImpl implements OfficeService { private OfficeRentStatDao officeRentStatDao; + + + @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); + } + // 评估逻辑 + evaluation.setUnitPrice(3.04); + return evaluation; + } + + @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); + } + // 评估逻辑 + evaluation.setUnitPrice(3.05); + return evaluation; + } + public List 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, String>() { From b976e6f802c2c5e268b49b951906309552a6ff31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Wed, 22 Jan 2025 18:24:32 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=86=99=E5=AD=97?= =?UTF-8?q?=E6=A5=BC=E4=BC=B0=E5=80=BC=E4=BC=B0=E5=80=BC=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open/controllers/OfficeController.java | 1 - .../service/datastore/OfficeServiceImpl.java | 74 ++++++++++++++++++- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java index a3b62b926..510b7011f 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java @@ -300,7 +300,6 @@ public class OfficeController { model.setDistrictName(district.getName()); Evaluation evaluation = officeService.evaluateRent(district, buildEvaluation(model, request)); - Double cityPriceCredit = null; if (evaluation.getUnitPrice() != null && evaluation.getUnitPrice() != 0) { Map districtPriceMap = new HashMap(); diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java index 0ef5351ae..403123eec 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java @@ -1,15 +1,23 @@ 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 org.sothis.core.util.Closure; +import org.sothis.core.util.Pager; +import weiboclient4j.utils.StringUtils; import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -21,6 +29,7 @@ import java.util.List; public class OfficeServiceImpl implements OfficeService { private OfficeRentStatDao officeRentStatDao; + private SeawaterService seawaterService; @@ -30,8 +39,54 @@ public class OfficeServiceImpl implements OfficeService { evaluation.setFloor(null); evaluation.setHeight(null); } + String city = district.getCity(); + String region = district.getRegion(); + String name = district.getName(); + List 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 seawaters = seawaterService.findSeawatersByQuery(query); + //List seawaters = seawaterService.findSeawatersByQuery("office_rent", city, region, name, alias, startDate, endDate); + // 有样本 + Double unitPrice = null; + 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); + } + } else if (StringUtils.isNotBlank(evaluation.getLocation())) { + unitPrice = rentEvaluateByLocation(evaluation); + } // 评估逻辑 - evaluation.setUnitPrice(3.04); + evaluation.setUnitPrice(unitPrice); return evaluation; } @@ -42,10 +97,21 @@ public class OfficeServiceImpl implements OfficeService { evaluation.setHeight(null); } // 评估逻辑 - evaluation.setUnitPrice(3.05); + String location = getLocation(evaluation.getAddress()); + evaluation.setLocation(location); + Double unitPrice = rentEvaluateByLocation(evaluation); + evaluation.setUnitPrice(unitPrice); return evaluation; } + private Double rentEvaluateByLocation(Evaluation evaluation) { + return 3.04; + } + + private String getLocation(String address) { + return ""; + } + public List 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, String>() { @@ -79,6 +145,10 @@ public class OfficeServiceImpl implements OfficeService { return regionStats; } + public void setSeawaterService(SeawaterService seawaterService) { + this.seawaterService = seawaterService; + } + public void setOfficeRentStatDao(OfficeRentStatDao officeRentStatDao) { this.officeRentStatDao = officeRentStatDao; } From 5f4b4fc2d1d933ca91dee1c460b9d7320d9ad0fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Thu, 23 Jan 2025 11:44:37 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=BB=8F=E7=BA=AC?= =?UTF-8?q?=E5=BA=A6=E4=BC=B0=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/datastore/OfficeServiceImpl.java | 93 +++++++++++++++---- .../com/fangjia/service/util/GeoUtils.java | 59 ++++++++++++ .../fangjia/service/util/dto/GaodeDto.java | 39 ++++++++ 3 files changed, 172 insertions(+), 19 deletions(-) create mode 100644 projects/fangjia-service/src/main/java/com/fangjia/service/util/GeoUtils.java create mode 100644 projects/fangjia-service/src/main/java/com/fangjia/service/util/dto/GaodeDto.java diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java index 403123eec..70950f939 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java @@ -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 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 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 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 ""; } diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/util/GeoUtils.java b/projects/fangjia-service/src/main/java/com/fangjia/service/util/GeoUtils.java new file mode 100644 index 000000000..20846e7f4 --- /dev/null +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/util/GeoUtils.java @@ -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 params = new HashMap(); + 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; + } +} diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/util/dto/GaodeDto.java b/projects/fangjia-service/src/main/java/com/fangjia/service/util/dto/GaodeDto.java new file mode 100644 index 000000000..1fb150d78 --- /dev/null +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/util/dto/GaodeDto.java @@ -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; + } +} From 419603b0cc6fcd866745b9831a21882e6f6ac3dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Thu, 23 Jan 2025 14:10:00 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=B3=BB=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fangjia/dal/mongo/model/Evaluation.java | 56 +++++++ .../open/controllers/OfficeController.java | 6 +- .../open/model/PropertyEvaluationModel.java | 20 ++- .../service/datastore/OfficeServiceImpl.java | 156 +++++++++++++++++- 4 files changed, 225 insertions(+), 13 deletions(-) diff --git a/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/Evaluation.java b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/Evaluation.java index 7fe4170a1..7b21bbf0a 100644 --- a/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/Evaluation.java +++ b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/Evaluation.java @@ -122,6 +122,26 @@ 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") @@ -998,4 +1018,40 @@ public class Evaluation implements MongoEntity { 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; + } } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java index 510b7011f..c5d5b9f95 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java @@ -346,13 +346,15 @@ public class OfficeController { */ 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.setFitment(EVALUATION_MODEL_FITMENT.get(FITMENT.get(StringUtils.isNotBlank(model.getDecoration()) ? - model.getDecoration() : model.getFitment()))); evaluation.setNoise(NOISE.get(model.getNoise())); evaluation.setEstateType(PROPERTY_TYPES.get(model.getPropertyType())); evaluation.setSight(SIGHT.get(model.getView())); diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/model/PropertyEvaluationModel.java b/projects/fangjia-open/src/main/java/com/fangjia/open/model/PropertyEvaluationModel.java index 2abc1acf1..feb2119bd 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/model/PropertyEvaluationModel.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/model/PropertyEvaluationModel.java @@ -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; + } } diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java index 70950f939..e249b8eac 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java @@ -19,9 +19,7 @@ import org.sothis.core.util.CollectionUtils; import org.sothis.core.util.Pager; import weiboclient4j.utils.StringUtils; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; /** * 写字楼相关服务类 @@ -79,7 +77,7 @@ public class OfficeServiceImpl implements OfficeService { seawaters = seawaterService.findSeawatersByQuery(query); } if (seawaters.size() > 0) { - unitPrice = this.calcRent(seawaters); + unitPrice = this.calcRent(seawaters, evaluation); } else if (StringUtils.isNotBlank(evaluation.getLocation())) { unitPrice = rentEvaluateByLocation(evaluation); } @@ -88,11 +86,151 @@ public class OfficeServiceImpl implements OfficeService { return evaluation; } - public Double calcRent(List seawaters) { +// 所在楼层 +// 总楼层 + private static final Map FITMENT_MAP = new HashMap() { + { + put("1", "毛坯"); + put("2", "简装"); + put("3", "精装"); + put("4", "豪装"); + } + }; + private static final Map LEVEL_MAP = new HashMap() { + { + put(1, "甲级"); + put(2, "乙级"); + put(3, "丙级"); + } + }; + private static final Map TYPE_MAP = new HashMap() { + { + put(1, "标准写字楼"); + put(2, "创意园区"); + put(3, "商住两用"); + put(4, "综合体"); + } + }; + public Double calcRent(List seawaters, Evaluation evaluation) { // 计算平均值 Double sum = 0.0; Double size = 0.0; Double unitPrice = null; + Double factor = 1.0; + // 按写字楼类型过滤 + List filterWithType = new ArrayList(); + 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 filterWithGrade = new ArrayList(); + 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 filterWithFloor = new ArrayList(); + 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 filterWithFitment = new ArrayList(); + + 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(); @@ -100,9 +238,9 @@ public class OfficeServiceImpl implements OfficeService { } } if (size > 0) { - unitPrice = DataUtil.roundDouble(sum / size / 30, 2); + unitPrice = DataUtil.roundDouble(sum / size / 30 * factor, 2); } - return unitPrice; + return unitPrice ; } @Override @@ -142,7 +280,7 @@ public class OfficeServiceImpl implements OfficeService { query.setCityDisplay(evaluation.getCity()); Pager pager = new Pager(); pager.setStartRow(0); - pager.setPageSize(5); + pager.setPageSize(10); query.setPager(pager); query.setTable("latest_seawater"); seawaters = seawaterService.findSeawatersByQuery(query); @@ -153,7 +291,7 @@ public class OfficeServiceImpl implements OfficeService { seawaters = seawaterService.findSeawatersByQuery(query); } if (CollectionUtils.isNotEmpty(seawaters)) { - return calcRent(seawaters); + return calcRent(seawaters, evaluation); } } return null;