添加平米租金接口
This commit is contained in:
+9
-8
@@ -1069,7 +1069,7 @@ public class PropertyController {
|
||||
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("È«¹ú")) {
|
||||
|| model.getDistrict().contains("È«¹ú")) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项"));
|
||||
return mav;
|
||||
}
|
||||
@@ -1659,8 +1659,8 @@ public class PropertyController {
|
||||
json = httpRequest.getJsonContent("http://192.168.0.100:30020/avmWeb/avmAnn", param, "UTF-8");
|
||||
if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) {
|
||||
HashMap<String, String> resultMap = new HashMap<String, String>();
|
||||
resultMap.put("avgPrice",json.getString("unitPrice"));
|
||||
resultMap.put("totalPrice",json.getString("totalPrice"));
|
||||
resultMap.put("avgPrice", json.getString("unitPrice"));
|
||||
resultMap.put("totalPrice", json.getString("totalPrice"));
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(resultMap));
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
|
||||
@@ -2527,20 +2527,21 @@ public class PropertyController {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("参数缺失:cat(租金类型)是必须参数"));
|
||||
return mav;
|
||||
}
|
||||
if ("city".equals(model.getCity()) && StringUtils.isBlank(model.getCity())) {
|
||||
if ("city".equals(model.getCat()) && StringUtils.isBlank(model.getCity())) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("城市平米租金,city(城市)是必须参数"));
|
||||
return mav;
|
||||
}
|
||||
if ("region".equals(model.getCity()) && (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()))) {
|
||||
if ("region".equals(model.getCat()) && (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()))) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("区域平米租金,city(城市),district(区域)是必须参数"));
|
||||
return mav;
|
||||
}
|
||||
if ("district".equals(model.getCity()) && (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()) || StringUtils.isBlank(model.getName()))) {
|
||||
if ("district".equals(model.getCat()) && (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict()) || StringUtils.isBlank(model.getName()))) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("小区平米租金,city(城市),district(区域),name(小区名)是必须参数"));
|
||||
return mav;
|
||||
}
|
||||
District district = null;
|
||||
if ("district".equals(model.getCat())) {
|
||||
District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(),
|
||||
district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(),
|
||||
"district");
|
||||
if (null == district) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("小区不存在"));
|
||||
@@ -2556,7 +2557,7 @@ public class PropertyController {
|
||||
}
|
||||
Date startDate = DateUtil.add(new Date(), Calendar.MONTH, -model.getPeriodCount());
|
||||
|
||||
List<SqmetreRent> sqmetreRents = sqmetreRentService.findSqmetreRents(RegionData.formatCity(model.getCity()), RegionData.formatRegion(model.getCity(), model.getDistrict()), model.getName(), model.getCat(), startDate, null);
|
||||
List<SqmetreRent> sqmetreRents = sqmetreRentService.findSqmetreRents(RegionData.formatCity(model.getCity()), RegionData.formatRegion(model.getCity(), model.getDistrict()), district.getName(), model.getCat(), startDate, null);
|
||||
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(model.getPeriodCount());
|
||||
|
||||
for (SqmetreRent sqmetreRent : sqmetreRents) {
|
||||
|
||||
+267
@@ -0,0 +1,267 @@
|
||||
package com.fangjia.open.controllers;
|
||||
|
||||
import com.fangjia.core.RegionData;
|
||||
import com.fangjia.core.util.DateUtil;
|
||||
import com.fangjia.dal.mongo.model.SqmetreRent;
|
||||
import com.fangjia.dal.seaweed.model.District;
|
||||
import com.fangjia.open.interceptors.Authority;
|
||||
import com.fangjia.open.interceptors.Role;
|
||||
import com.fangjia.open.model.AvgPriceQueryModel;
|
||||
import com.fangjia.open.model.BasicModel;
|
||||
import com.fangjia.open.model.RestfulModelAndView;
|
||||
import com.fangjia.service.datastore.DistrictService;
|
||||
import com.fangjia.service.district.SqmetreRentService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 平米租金
|
||||
*/
|
||||
@Authority(role = Role.USER)
|
||||
public class SqmetreRentController {
|
||||
|
||||
private SqmetreRentService sqmetreRentService;
|
||||
private DistrictService districtService;
|
||||
|
||||
|
||||
/**
|
||||
* 城市平米租金
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
public Object cityAction(AvgPriceQueryModel model) {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
model.setCat("city");
|
||||
|
||||
// 校验城市参数
|
||||
if (StringUtils.isBlank(model.getCity())) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city(城市)是必须参数"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
// 设置默认 periodCount 并校验范围
|
||||
if (model.getPeriodCount() == null) {
|
||||
model.setPeriodCount(1);
|
||||
}
|
||||
if (model.getPeriodCount() < 1 || model.getPeriodCount() > 156) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("periodCount值不合法,取值范围是:[1-156]"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
// 计算起始日期
|
||||
Date startDate = DateUtil.add(new Date(), Calendar.MONTH, -(model.getPeriodCount() + 1));
|
||||
|
||||
// 查询平米租金数据
|
||||
List<SqmetreRent> sqmetreRents = sqmetreRentService.findSqmetreRents(
|
||||
RegionData.formatCity(model.getCity()),
|
||||
RegionData.formatRegion(model.getCity(), model.getDistrict()),
|
||||
model.getName(),
|
||||
model.getCat(),
|
||||
startDate,
|
||||
null
|
||||
);
|
||||
|
||||
// 准备结果列表
|
||||
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(model.getPeriodCount());
|
||||
Double lastMonthRent = null;
|
||||
|
||||
// 遍历并填充结果
|
||||
if (sqmetreRents != null && !sqmetreRents.isEmpty()) {
|
||||
for (SqmetreRent sqmetreRent : sqmetreRents) {
|
||||
Map<String, Object> item = new LinkedHashMap<String, Object>();
|
||||
item.put("city", sqmetreRent.getCity());
|
||||
Integer currentRent = (sqmetreRent.getAvgPrice() != null) ? sqmetreRent.getAvgPrice().intValue() : 0;
|
||||
item.put("rent", currentRent);
|
||||
item.put("date", sqmetreRent.getWeekend() != null ? DateUtil.formatByPattern(sqmetreRent.getWeekend(), "yyyy-MM") : "未知日期");
|
||||
|
||||
// 计算月涨幅
|
||||
if (lastMonthRent != null && lastMonthRent != 0) {
|
||||
double changePercent = ((double) currentRent - lastMonthRent) / lastMonthRent;
|
||||
item.put("changePercent", Double.valueOf(String.format("%.2f", changePercent)));
|
||||
} else {
|
||||
item.put("changePercent", null);
|
||||
}
|
||||
|
||||
lastMonthRent = (double) currentRent;
|
||||
result.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// 设置返回结果,防止 subList 越界
|
||||
if (result.size() > 1) {
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(result.subList(1, result.size())));
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(null));
|
||||
}
|
||||
return mav;
|
||||
}
|
||||
/**
|
||||
* 区域平米租金
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
public Object districtAction(AvgPriceQueryModel model) {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
model.setCat("region");
|
||||
|
||||
// 校验城市参数
|
||||
if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getDistrict())) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city(城市),district(区域)是必须参数"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
// 设置默认 periodCount 并校验范围
|
||||
if (model.getPeriodCount() == null) {
|
||||
model.setPeriodCount(1);
|
||||
}
|
||||
if (model.getPeriodCount() < 1 || model.getPeriodCount() > 156) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("periodCount值不合法,取值范围是:[1-156]"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
// 计算起始日期
|
||||
Date startDate = DateUtil.add(new Date(), Calendar.MONTH, -(model.getPeriodCount() + 1));
|
||||
|
||||
// 查询平米租金数据
|
||||
List<SqmetreRent> sqmetreRents = sqmetreRentService.findSqmetreRents(
|
||||
RegionData.formatCity(model.getCity()),
|
||||
RegionData.formatRegion(model.getCity(), model.getDistrict()),
|
||||
model.getName(),
|
||||
model.getCat(),
|
||||
startDate,
|
||||
null
|
||||
);
|
||||
|
||||
// 准备结果列表
|
||||
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(model.getPeriodCount());
|
||||
Double lastMonthRent = null;
|
||||
|
||||
// 遍历并填充结果
|
||||
if (sqmetreRents != null && !sqmetreRents.isEmpty()) {
|
||||
for (SqmetreRent sqmetreRent : sqmetreRents) {
|
||||
Map<String, Object> item = new LinkedHashMap<String, Object>();
|
||||
item.put("city", sqmetreRent.getCity());
|
||||
item.put("district", sqmetreRent.getRegion());
|
||||
Integer currentRent = (sqmetreRent.getAvgPrice() != null) ? sqmetreRent.getAvgPrice().intValue() : 0;
|
||||
item.put("rent", currentRent);
|
||||
item.put("date", sqmetreRent.getWeekend() != null ? DateUtil.formatByPattern(sqmetreRent.getWeekend(), "yyyy-MM") : "未知日期");
|
||||
|
||||
// 计算月涨幅
|
||||
if (lastMonthRent != null && lastMonthRent != 0) {
|
||||
double changePercent = ((double) currentRent - lastMonthRent) / lastMonthRent;
|
||||
item.put("changePercent", Double.valueOf(String.format("%.2f", changePercent)));
|
||||
} else {
|
||||
item.put("changePercent", null);
|
||||
}
|
||||
|
||||
lastMonthRent = (double) currentRent;
|
||||
result.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// 设置返回结果,防止 subList 越界
|
||||
if (result.size() > 1) {
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(result.subList(1, result.size())));
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(null));
|
||||
}
|
||||
return mav;
|
||||
}
|
||||
/**
|
||||
* 小区平米租金
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
public Object propertyAction(AvgPriceQueryModel model) {
|
||||
RestfulModelAndView mav = new RestfulModelAndView();
|
||||
mav.setViewType("rest");
|
||||
model.setCat("district");
|
||||
|
||||
// 校验城市参数
|
||||
if (StringUtils.isBlank(model.getCity())) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("city(城市),district(区域),name(小区名)是必须参数"));
|
||||
return mav;
|
||||
}
|
||||
District district = null;
|
||||
if ("district".equals(model.getCat())) {
|
||||
district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(),
|
||||
"district");
|
||||
if (null == district) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("该小区不存在"));
|
||||
return mav;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置默认 periodCount 并校验范围
|
||||
if (model.getPeriodCount() == null) {
|
||||
model.setPeriodCount(1);
|
||||
}
|
||||
if (model.getPeriodCount() < 1 || model.getPeriodCount() > 156) {
|
||||
mav.setModel(BasicModel.buildBadRequestModel("periodCount值不合法,取值范围是:[1-156]"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
// 计算起始日期
|
||||
Date startDate = DateUtil.add(new Date(), Calendar.MONTH, -(model.getPeriodCount() + 1));
|
||||
|
||||
// 查询平米租金数据
|
||||
List<SqmetreRent> sqmetreRents = sqmetreRentService.findSqmetreRents(
|
||||
RegionData.formatCity(model.getCity()),
|
||||
RegionData.formatRegion(model.getCity(), model.getDistrict()),
|
||||
district.getName(),
|
||||
model.getCat(),
|
||||
startDate,
|
||||
null
|
||||
);
|
||||
|
||||
// 准备结果列表
|
||||
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(model.getPeriodCount());
|
||||
Double lastMonthRent = null;
|
||||
|
||||
// 遍历并填充结果
|
||||
if (sqmetreRents != null && !sqmetreRents.isEmpty()) {
|
||||
for (SqmetreRent sqmetreRent : sqmetreRents) {
|
||||
Map<String, Object> item = new LinkedHashMap<String, Object>();
|
||||
item.put("city", sqmetreRent.getCity());
|
||||
item.put("district", sqmetreRent.getRegion());
|
||||
item.put("name", sqmetreRent.getDistrictName());
|
||||
Integer currentRent = (sqmetreRent.getAvgPrice() != null) ? sqmetreRent.getAvgPrice().intValue() : 0;
|
||||
item.put("rent", currentRent);
|
||||
item.put("date", sqmetreRent.getWeekend() != null ? DateUtil.formatByPattern(sqmetreRent.getWeekend(), "yyyy-MM") : "未知日期");
|
||||
|
||||
// 计算月涨幅
|
||||
if (lastMonthRent != null && lastMonthRent != 0) {
|
||||
double changePercent = ((double) currentRent - lastMonthRent) / lastMonthRent;
|
||||
item.put("changePercent", Double.valueOf(String.format("%.2f", changePercent)));
|
||||
} else {
|
||||
item.put("changePercent", null);
|
||||
}
|
||||
|
||||
lastMonthRent = (double) currentRent;
|
||||
result.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// 设置返回结果,防止 subList 越界
|
||||
if (result.size() > 1) {
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(result.subList(1, result.size())));
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildOKModel().setResult(null));
|
||||
}
|
||||
return mav;
|
||||
}
|
||||
|
||||
public void setSqmetreRentService(SqmetreRentService sqmetreRentService) {
|
||||
this.sqmetreRentService = sqmetreRentService;
|
||||
}
|
||||
|
||||
public void setDistrictService(DistrictService districtService) {
|
||||
this.districtService = districtService;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user