商铺出售评估及房源接口新增

This commit is contained in:
2025-09-17 14:41:11 +08:00
parent 8ff5a7ca2c
commit 33281a1fa9
3 changed files with 275 additions and 1 deletions
@@ -1,5 +1,6 @@
package com.fangjia.core.util;
import org.apache.commons.lang.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -261,7 +262,9 @@ public class GeoUtils {
public static Map<String, String> parserByGaode(String city, String address) {
Map<String, String> params = new HashMap<String, String>();
params.put("city", city);
if(StringUtils.isNotBlank(city)){
params.put("city", city);
}
params.put("address", address);
String content;
@@ -0,0 +1,160 @@
package com.fangjia.open.controllers;
import com.fangjia.core.util.GeoUtils;
import com.fangjia.core.util.HttpRequest;
import com.fangjia.core.util.HttpRequestException;
import com.fangjia.open.interceptors.Authority;
import com.fangjia.open.interceptors.Role;
import com.fangjia.open.model.AddesssMatchModel;
import com.fangjia.open.model.BasicModel;
import com.fangjia.open.model.CommercialModel;
import com.fangjia.open.model.RestfulModelAndView;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 商业地产
*
* @since 2025/9/16
*/
@Authority(role = Role.USER)
public class CommercialController {
private static final List<String> GAODE_LEVEL = Arrays.asList("兴趣点", "门牌号", "单元号", "楼层", "房间", "门址", "住宅区","村庄");
public Object shopSellEvaluateAction(CommercialModel model) {
RestfulModelAndView mav = new RestfulModelAndView();
mav.setViewType("rest");
mav = checkParmas(model, mav);
if(mav.model()!=null){
return mav;
}
//加上高德获取经纬度 和 根据经纬度估值
Map<String, String> map = GeoUtils.parserByGaode(null, model.getAddress());
if (map != null && map.containsKey("level") && GAODE_LEVEL.contains(map.get("level"))
&& map.containsKey("lng") && map.containsKey("lat")) {
String location = map.get("lng") + "," + map.get("lat");
JSONObject json = locationEvaluateApi(location, String.valueOf(model.getSize()), String.valueOf(model.getEstateType()));
if (json != null) {
if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) {
HashMap<String, Long> resultMap = new HashMap<String, Long>();
resultMap.put("avgPrice", Long.valueOf(json.getString("unitPrice")));
resultMap.put("totalPrice", Long.valueOf(json.getString("totalPrice")));
mav.setModel(BasicModel.buildOKModel().setResult(resultMap));
} else {
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
}
} else {
mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中..."));
}
} else {
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
}
return mav;
}
public Object shopSellSampleAction(CommercialModel model) {
RestfulModelAndView mav = new RestfulModelAndView();
mav.setViewType("rest");
mav = checkParmas(model, mav);
if(mav.model()!=null){
return mav;
}
//加上高德获取经纬度 和 根据经纬度估值
Map<String, String> map = GeoUtils.parserByGaode(null, model.getAddress());
if (map != null && map.containsKey("level") && GAODE_LEVEL.contains(map.get("level"))
&& map.containsKey("lng") && map.containsKey("lat")) {
String location = map.get("lng") + "," + map.get("lat");
JSONObject json = locationEvaluateApi(location, String.valueOf(model.getSize()), String.valueOf(model.getEstateType()));
if (json != null) {
if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) {
String msg = json.getString("msg");
BasicModel basicModel = new BasicModel(200, "ok");
if (json.containsKey("case")) {
basicModel.setResult(json.get("case"));
}
mav.setModel(BasicModel.buildOKModel().setResult(basicModel));
}
} else {
mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中..."));
}
} else {
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持样本输出!"));
}
return mav;
}
private RestfulModelAndView checkParmas(CommercialModel model, RestfulModelAndView mav){
if (StringUtils.isBlank(model.getAddress()) || model.getSize()==null || model.getEstateType()==null ) {
mav.setModel(BasicModel.buildBadRequestModel("参数非法:地址,面积,商铺类型为必填项"));
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.getPassengerFlow() != null && (model.getPassengerFlow() <0 || model.getPassengerFlow() > 2)) {
mav.setModel(BasicModel.buildBadRequestModel("客流量取值非法,正确范围[0,2]"));
return mav;
}
if (model.getPassengerFlow() != null && (model.getLeaseStability() <0 || model.getLeaseStability() > 3)) {
mav.setModel(BasicModel.buildBadRequestModel("租约稳定性取值非法,正确范围[0,3]"));
return mav;
}
if (model.getSellType()!= null && (model.getSellType() <0 || model.getSellType() > 1)) {
mav.setModel(BasicModel.buildBadRequestModel("出售方式取值非法,正确范围[0,1]"));
return mav;
}
if (model.getEstateType()!= null && (model.getEstateType() <0 || model.getEstateType() > 7)) {
mav.setModel(BasicModel.buildBadRequestModel("商铺类型取值非法,正确范围[0,7]"));
return mav;
}
return mav;
}
private JSONObject locationEvaluateApi(String location, String area, String estateType){
//商铺类型---0:临街商铺 1:住宅底商 2:购物百货中心 3:写字楼商铺 4:档口摊位 5:市场类商铺 6:交通设施商铺 7:旅游商铺
HttpRequest request = new HttpRequest();
JSONObject json = null;
Map<String, String> params = new HashMap<String, String>();
params.put("location", location);
params.put("area", area);
params.put("estateType", estateType);
try {
json = request.getJsonContent("http://192.168.0.100:30020/avmWeb/shopSell", params, "UTF-8");
} catch (Exception e) {
try {
json = request.getJsonContent("http://192.168.0.100:30020/avmWeb/shopSell", params, "UTF-8");
} catch (Exception ex) {
ex.printStackTrace();
}
}
return json;
}
}
@@ -0,0 +1,111 @@
package com.fangjia.open.model;
import org.hibernate.validator.constraints.NotBlank;
public class CommercialModel extends FangjiaApiModel{
@NotBlank
private String address;
private Double size;
private String location;
private Integer floor;//所在楼层
private Integer maxFloor;//总楼层
private Integer passengerFlow;//客流量---0:高 1:中 2:低
private Integer LeaseStability;//租约稳定性---0:持续稳定出租 1:阶段性出租 2:偶尔出租 3:未出租
private Integer sellType;//出售/转让---0:出售 1:转让
private Integer decorationCost;//装修成本(单位:万元)
private Integer decorationYear;//装修年限(单位:年)
@NotBlank
private Integer estateType;//商铺类型---0:临街商铺 1:住宅底商 2:购物百货中心 3:写字楼商铺 4:档口摊位 5:市场类商铺 6:交通设施商铺 7:旅游商铺
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Double getSize() {
return size;
}
public void setSize(Double size) {
this.size = size;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public Integer getFloor() {
return floor;
}
public void setFloor(Integer floor) {
this.floor = floor;
}
public Integer getMaxFloor() {
return maxFloor;
}
public void setMaxFloor(Integer maxFloor) {
this.maxFloor = maxFloor;
}
public Integer getPassengerFlow() {
return passengerFlow;
}
public void setPassengerFlow(Integer passengerFlow) {
this.passengerFlow = passengerFlow;
}
public Integer getLeaseStability() {
return LeaseStability;
}
public void setLeaseStability(Integer leaseStability) {
LeaseStability = leaseStability;
}
public Integer getSellType() {
return sellType;
}
public void setSellType(Integer sellType) {
this.sellType = sellType;
}
public Integer getDecorationCost() {
return decorationCost;
}
public void setDecorationCost(Integer decorationCost) {
this.decorationCost = decorationCost;
}
public Integer getDecorationYear() {
return decorationYear;
}
public void setDecorationYear(Integer decorationYear) {
this.decorationYear = decorationYear;
}
public Integer getEstateType() {
return estateType;
}
public void setEstateType(Integer estateType) {
this.estateType = estateType;
}
}