评估方法http请求

This commit is contained in:
沈健
2021-05-08 13:46:19 +08:00
parent 87d2deb228
commit 8cb7bd7812
@@ -9,13 +9,11 @@ import com.fangjia.dal.mongo.model.Evaluation;
import com.fangjia.dal.mongo.model.RentDealPrice;
import com.fangjia.dal.seawater.model.Seawater;
import com.fangjia.dal.seaweed.model.District;
import com.fangjia.open.APIConstant;
import com.fangjia.open.compatible.model.JsonModel;
import com.fangjia.open.controllers.PropertyController;
import com.fangjia.open.dto.DistrictHouseDtao;
import com.fangjia.open.interceptors.AuthenticationBean;
import com.fangjia.open.model.BaseModel;
import com.fangjia.open.model.BasicModel;
import com.fangjia.open.model.RestfulModelAndView;
import com.fangjia.open.model.weixin.EvaluationModel;
import com.fangjia.open.model.weixin.PropertyEvaluationModel;
import com.fangjia.open.util.LineChartsUtils;
@@ -51,6 +49,7 @@ import org.xhtmlrenderer.pdf.ITextRenderer;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.util.*;
@@ -89,92 +88,25 @@ public class CcbRentController {
}
public Object evaluateRentAction(com.fangjia.open.model.PropertyEvaluationModel model, HttpServletRequest request)throws NumberFormatException, IllegalAccessException {
RestfulModelAndView mav = new RestfulModelAndView();
mav.setViewType("rest");
if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getName())
|| StringUtils.isBlank(model.getDistrict()) || model.getSize() <= 0) {
mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,区域,小区名,面积(size)为必填项"));
return mav;
}
if (model.getCity().endsWith("市")) {
model.setCity(model.getCity().replaceAll("市$", ""));
}
if (StringUtils.isNotBlank(request.getParameter("calDate"))) {
Date calDate = null;
try {
calDate = org.apache.commons.lang.time.DateUtils.parseDate(request.getParameter("calDate"), new String[] { "yyyy-MM-dd" });
} catch (ParseException e) {
String result = null;
HttpRequest httpRequest = new HttpRequest();
try {
Map<String, String> headers = new HashMap<String, String>();
}
if (calDate == null) {
mav.setModel(BasicModel.buildBadRequestModel("calDate:数据类型不合法"));
return mav;
} else {
model.setCalDate(calDate);
}
}
/* 先到CPDB库中查找小区 */
District district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(),
"district");
if (district == null) {
mav.setModel(BasicModel.buildBadRequestModel("该小区不存在"));
return mav;
}
model.setName(district.getName());
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;
}
model.setRegion(district.getRegion());
model.setDistrictName(district.getName());
if (StringUtils.isBlank(model.getPropertyType())) {
if (district.getEstateType2() != null && district.getEstateType2().contains("别墅")) {
model.setPropertyType("1");
}
}
if (model.getCalDate() != null) {
if (new Date().before(model.getCalDate())) {
model.setCalDate(DateUtil.getFirstDayOfWeek(new Date()));
} else {
model.setCalDate(DateUtil.getFirstDayOfWeek(model.getCalDate()));
}
} else {
model.setCalDate(DateUtil.getFirstDayOfWeek(new Date()));
}
Evaluation evaluation = buildEvaluation(model, request);
evaluation.setSource("api_property_evaluate_rent");
evaluation = evaluationService.evaluateRent(district, evaluation, model.getCalDate());
if (evaluation.getTotalPrice() != null && evaluation.getTotalPrice() != 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("address", district.getAddress());
districtPriceMap.put("totalPrice", evaluation.getTotalPrice());
districtPriceMap.put("cal_date", model.getCalDate());
mav.setModel(BasicModel.buildOKModel().setResult(districtPriceMap));
return mav;
} else {
mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的租金估价").markNoData());
return mav;
final String path = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
String url = path + "/property/evaluateRent?token=" + APIConstant.SUPER_USER_TOKEN + "&__refresh_cache=1";
Map<String, String> params = new HashMap<String, String>();
params = org.apache.commons.beanutils.BeanUtils.describe(model);
//params.put("request", JsonUtils.httpParameterToJSONObject(request));
result = httpRequest.post(url, params, headers,"UTF-8");
} catch (HttpRequestException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return result;
}
public Object downloadPageAction(PropertyEvaluationModel result, HttpServletRequest request, @Param(name = "city") String city, @Param(name = "district") String districtStr,