优化接口

This commit is contained in:
沈健
2024-11-07 11:24:17 +08:00
parent 1e024b5996
commit e2d942c8cc
@@ -42,6 +42,7 @@ import org.slf4j.Logger;
import org.sothis.web.mvc.ActionContext; import org.sothis.web.mvc.ActionContext;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.ParseException; import java.text.ParseException;
import java.util.*; import java.util.*;
@@ -218,6 +219,11 @@ public class ComprehensiveQueryController {
mav.setModel(BasicModel.buildBadRequestModel("地址(address),面积(size)为必填字段")); mav.setModel(BasicModel.buildBadRequestModel("地址(address),面积(size)为必填字段"));
return mav; return mav;
} }
// 不支持车位等估价
if (model.getAddress().contains("车位")) {
mav.setModel(BasicModel.buildBadRequestModel("非住宅无法估值"));
return mav;
}
String cityStr = model.getCity(); String cityStr = model.getCity();
if (StringUtils.isNotBlank(cityStr) && cityStr.matches("\\d+")) { if (StringUtils.isNotBlank(cityStr) && cityStr.matches("\\d+")) {
@@ -247,35 +253,36 @@ public class ComprehensiveQueryController {
} catch (HttpRequestException e) { } catch (HttpRequestException e) {
} }
if (matchResponse == null || !matchResponse.containsKey("result") || !matchResponse.getJSONObject("result").containsKey("id")) { // 去掉经纬度解析
//加上高德获取经纬度 和 根据经纬度估值 // if (matchResponse == null || !matchResponse.containsKey("result") || !matchResponse.getJSONObject("result").containsKey("id")) {
Map<String, String> map = GeoUtils.parserByGaode(model.getCity(), model.getAddress()); // //加上高德获取经纬度 和 根据经纬度估值
if (map.containsKey("level") && GAODE_LEVEL.contains(map.get("level")) // Map<String, String> map = GeoUtils.parserByGaode(model.getCity(), model.getAddress());
&& map.containsKey("lng") && map.containsKey("lat")) { // if (map.containsKey("level") && GAODE_LEVEL.contains(map.get("level"))
String location = map.get("lng") + "," + map.get("lat"); // && map.containsKey("lng") && map.containsKey("lat")) {
JSONObject jsonResult = null; // String location = map.get("lng") + "," + map.get("lat");
Map<String, String> param = new HashMap<String, String>(); // JSONObject jsonResult = null;
param.put("location", location); // Map<String, String> param = new HashMap<String, String>();
param.put("area", String.valueOf(model.getSize())); // param.put("location", location);
try { // param.put("area", String.valueOf(model.getSize()));
jsonResult = httpRequest.getJsonContent("http://192.168.0.100:30020/avmWeb/avmAnn", param, "UTF-8"); // try {
if (jsonResult.containsKey("msg") && "成功".equals(jsonResult.getString("msg"))) { // jsonResult = httpRequest.getJsonContent("http://192.168.0.100:30020/avmWeb/avmAnn", param, "UTF-8");
HashMap<String, Object> resultMap = new HashMap<String, Object>(); // if (jsonResult.containsKey("msg") && "成功".equals(jsonResult.getString("msg"))) {
resultMap.put("avgPrice", jsonResult.getString("unitPrice")); // HashMap<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("totalPrice", jsonResult.getString("totalPrice")); // resultMap.put("avgPrice", jsonResult.getString("unitPrice"));
houseValueInformation.setAddressValue(resultMap); // resultMap.put("totalPrice", jsonResult.getString("totalPrice"));
mav.setModel(BasicModel.buildOKModel().setResult(houseValueInformation)); // houseValueInformation.setAddressValue(resultMap);
} else { // mav.setModel(BasicModel.buildOKModel().setResult(houseValueInformation));
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!")); // } else {
} // mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
} catch (HttpRequestException e) { // }
throw new RuntimeException(e); // } catch (HttpRequestException e) {
} // throw new RuntimeException(e);
} else { // }
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!")); // } else {
} // mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
return mav; // }
} // return mav;
// }
String id = matchResponse.getJSONObject("result").getString("id"); String id = matchResponse.getJSONObject("result").getString("id");
District district = districtService.findById(id); District district = districtService.findById(id);
if (district == null) { if (district == null) {
@@ -305,6 +312,13 @@ public class ComprehensiveQueryController {
} }
} }
// 价格下调10%
if (dto.getAvgPrice() != null) {
int avgPrice = new BigDecimal(dto.getAvgPrice()).multiply(new BigDecimal(0.9)).intValue();
dto.setAvgPrice(avgPrice);
}
// 非住宅无法估值
// 保存小区均价的返回结果 // 保存小区均价的返回结果
houseValueInformation.setCommunityAvgPrice(dto); houseValueInformation.setCommunityAvgPrice(dto);
@@ -328,6 +342,13 @@ public class ComprehensiveQueryController {
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
} }
// 价格下调10%
Map<String, Object> addressValue = houseValueInformation.getAddressValue();
if (addressValue != null && addressValue.get("totalPrice") != null && addressValue.get("avgPrice") != null) {
int evaluatePrice = new BigDecimal((Integer) addressValue.get("avgPrice")).multiply(new BigDecimal(0.9)).intValue();
addressValue.put("avgPrice", evaluatePrice);
addressValue.put("totalPrice", new BigDecimal(evaluatePrice * model.getSize()).intValue());
}
// houseValueInformation.setAddressValue(modelAndView); // houseValueInformation.setAddressValue(modelAndView);
//房源样本 //房源样本