加入价格系统

This commit is contained in:
2026-01-14 18:39:39 +08:00
parent 39ff1bca75
commit 3be9803dba
5 changed files with 187 additions and 46 deletions
@@ -1,17 +1,22 @@
package com.fangjia.open.controllers;
import com.fangjia.core.util.*;
import com.fangjia.dal.mongo.model.ApiUserCfg;
import com.fangjia.open.dto.BusinessCaseDto;
import com.fangjia.open.interceptors.AuthenticationBean;
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 com.fangjia.service.api.ApiUserCfgService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;
/**
@@ -24,7 +29,9 @@ public class CommercialController {
private static final List<String> GAODE_LEVEL = Arrays.asList("兴趣点", "门牌号", "单元号", "楼层", "房间", "门址", "住宅区","村庄");
public Object shopSellEvaluateAction(CommercialModel model) {
private ApiUserCfgService apiUserCfgService;
public Object shopSellEvaluateAction(CommercialModel model, HttpServletRequest request) {
RestfulModelAndView mav = new RestfulModelAndView();
mav.setViewType("rest");
@@ -37,8 +44,11 @@ public class CommercialController {
if (json != null) {
if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) {
HashMap<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("unitPrice", Long.valueOf(json.getString("unitPrice")));
resultMap.put("totalPrice", Long.valueOf(json.getString("totalPrice")));
long totalPrice = getRatioPrice(request, Long.valueOf(json.getString("totalPrice")));
resultMap.put("unitPrice", new BigDecimal(totalPrice/model.getSize()).setScale(0, BigDecimal.ROUND_HALF_UP).intValue());
resultMap.put("totalPrice", totalPrice);
if (model.getShowSample()!=null && model.getShowSample()==1 && json.containsKey("case")) {
List<BusinessCaseDto> dtos = createBusiness((JSONArray) json.get("case"), "sell");
@@ -71,6 +81,9 @@ public class CommercialController {
if (json.containsKey("case")) {
List<BusinessCaseDto> dtos = createBusiness((JSONArray) json.get("case"), "sell");
mav.setModel(BasicModel.buildOKModel().setResult(dtos));
if(dtos.size()<5){
BasicModel.markNoDataRequest();
}
}
}else{
mav.setModel(BasicModel.buildServerErrorModel().setMsg(json.getString("msg")));
@@ -88,7 +101,7 @@ public class CommercialController {
* @param model
* @return
*/
public Object shopRentEvaluateAction(CommercialModel model) {
public Object shopRentEvaluateAction(CommercialModel model, HttpServletRequest request) {
RestfulModelAndView mav = new RestfulModelAndView();
mav.setViewType("rest");
@@ -101,8 +114,12 @@ public class CommercialController {
if (json != null) {
if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) {
HashMap<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("unitPrice", Double.valueOf(json.getString("unitPrice")));
resultMap.put("totalPrice", Long.valueOf(json.getString("totalPrice")));
long totalPrice = getRatioPrice(request, Long.valueOf(json.getString("totalPrice")));
resultMap.put("unitPrice", new BigDecimal(totalPrice/(30*model.getSize())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
resultMap.put("totalPrice", totalPrice);
if (model.getShowSample()!=null && model.getShowSample()==1 && json.containsKey("case")) {
List<BusinessCaseDto> dtos = createBusiness((JSONArray) json.get("case"), "rent");
@@ -120,6 +137,23 @@ public class CommercialController {
return mav;
}
private Long getRatioPrice(HttpServletRequest request, Long totalPrice){
AuthenticationBean authenticationBean = (AuthenticationBean) request
.getAttribute(AuthenticationBean.ATTR_AUTHENTICATION_BEAN);
if (authenticationBean != null && authenticationBean.apiUser != null) {
String userId = String.valueOf(authenticationBean.apiUser.getId());
ApiUserCfg apiUserCfg = apiUserCfgService.findByUserId(Long.valueOf(userId), ApiUserCfg.ApiUserCfgKey.EVALUATE_RATE);
if(apiUserCfg != null && apiUserCfg.getCfgValue() != null && apiUserCfg.getCfgValue() instanceof Double){
Double rate = (Double)apiUserCfg.getCfgValue();
if(rate != 0){
totalPrice = (long)(totalPrice * rate);
}
}
}
return totalPrice;
}
private List<BusinessCaseDto> createBusiness(JSONArray cases, String cat){
if(cases != null && cases.size()>0){
List<BusinessCaseDto> dtos = new ArrayList<BusinessCaseDto>();
@@ -172,6 +206,9 @@ public class CommercialController {
if (json.containsKey("case")) {
List<BusinessCaseDto> dtos = createBusiness((JSONArray) json.get("case"), "rent");
mav.setModel(BasicModel.buildOKModel().setResult(dtos));
if(dtos.size()<5){
BasicModel.markNoDataRequest();
}
}
} else {
mav.setModel(BasicModel.buildServerErrorModel().setMsg(json.getString("msg")));
@@ -296,4 +333,8 @@ public class CommercialController {
}
return json;
}
public void setApiUserCfgService(ApiUserCfgService apiUserCfgService) {
this.apiUserCfgService = apiUserCfgService;
}
}
@@ -4,6 +4,7 @@ import com.fangjia.core.RegionData;
import com.fangjia.core.util.*;
import com.fangjia.dal.common.ServerAreaData;
import com.fangjia.dal.mongo.fangjia.model.ServerArea;
import com.fangjia.dal.mongo.model.ApiUserCfg;
import com.fangjia.dal.mongo.model.Evaluation;
import com.fangjia.dal.mongo.model.OfficeRentStat;
import com.fangjia.dal.seawater.model.SeawaterDto;
@@ -20,6 +21,7 @@ import com.fangjia.open.util.CommonUtils;
import com.fangjia.open.util.FangJiaTongUrl;
import com.fangjia.service.address.AddressParser;
import com.fangjia.service.api.AddressMatchProxyService;
import com.fangjia.service.api.ApiUserCfgService;
import com.fangjia.service.datastore.DistrictService;
import com.fangjia.service.datastore.FieldFilterService;
import com.fangjia.service.datastore.OfficeService;
@@ -35,6 +37,7 @@ import org.sothis.web.mvc.ActionContext;
import org.sothis.web.mvc.annotation.Param;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;
import static com.fangjia.open.util.CommonUtils.convertToString;
@@ -59,6 +62,7 @@ public class OfficeController {
private AddressParser addressParser;
private FieldFilterService fieldFilterService;
private ApiUserCfgService apiUserCfgService;
/**
* 城市出租均价
@@ -530,8 +534,24 @@ public class OfficeController {
districtPriceMap.put("city", district.getCity());
districtPriceMap.put("district", district.getRegion());
districtPriceMap.put("name", district.getName());
districtPriceMap.put("unitPrice", evaluation.getUnitPrice());
Long totalPrice = (long) (evaluation.getUnitPrice() * model.getSize() * 30);
BigDecimal avgPrice = BigDecimal.valueOf(evaluation.getUnitPrice());
AuthenticationBean authenticationBean = (AuthenticationBean) request
.getAttribute(AuthenticationBean.ATTR_AUTHENTICATION_BEAN);
if (authenticationBean != null && authenticationBean.apiUser != null) {
String userId = String.valueOf(authenticationBean.apiUser.getId());
ApiUserCfg apiUserCfg = apiUserCfgService.findByUserId(Long.valueOf(userId), ApiUserCfg.ApiUserCfgKey.EVALUATE_RATE);
if(apiUserCfg != null && apiUserCfg.getCfgValue() != null && apiUserCfg.getCfgValue() instanceof Double){
Double rate = (Double)apiUserCfg.getCfgValue();
if(rate != 0){
totalPrice = (long)(totalPrice * rate);
avgPrice = BigDecimal.valueOf(totalPrice/(30*model.getSize())).setScale(2, BigDecimal.ROUND_HALF_UP);
}
}
}
districtPriceMap.put("unitPrice", avgPrice);
districtPriceMap.put("totalPrice", totalPrice);
if(model.getShow()!=null && model.getShow()==1) {
districtPriceMap.put("result", evaluation.getSeawater());
@@ -756,6 +776,9 @@ public class OfficeController {
Map<String, Object> districtPriceMap = new HashMap<String, Object>();
List<BusinessCaseDto> createBusiness = createBusiness(evaluation.getSeawater(), "office_rent", district);
mav.setModel(BasicModel.buildOKModel().setResult(createBusiness));
if(createBusiness.size()<5){
BasicModel.markNoDataRequest();
}
return mav;
}
mav.setModel(BasicModel.buildOKModel().markNoData());
@@ -1008,4 +1031,8 @@ public class OfficeController {
public void setFieldFilterService(FieldFilterService fieldFilterService) {
this.fieldFilterService = fieldFilterService;
}
public void setApiUserCfgService(ApiUserCfgService apiUserCfgService) {
this.apiUserCfgService = apiUserCfgService;
}
}
@@ -7,6 +7,7 @@ import com.fangjia.core.util.GeoUtils;
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.ApiUserCfg;
import com.fangjia.dal.mongo.model.Evaluation;
import com.fangjia.dal.mongo.model.OfficeSellStat;
import com.fangjia.dal.seawater.model.SeawaterDto;
@@ -22,6 +23,7 @@ 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.api.ApiUserCfgService;
import com.fangjia.service.datastore.DistrictService;
import com.fangjia.service.datastore.OfficeService;
import com.fangjia.service.datastore.OpenApiLogService;
@@ -36,6 +38,7 @@ import org.sothis.web.mvc.ActionContext;
import org.sothis.web.mvc.annotation.Param;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;
import static com.fangjia.open.util.CommonUtils.convertToString;
@@ -53,7 +56,7 @@ public class OfficeSellController {
private DistrictService districtService;
private OpenApiLogService openApiLogService;
private AddressMatchProxyService addressMatchProxyService;
private ApiUserCfgService apiUserCfgService;
/**
* 写字楼城市出售均价
*
@@ -305,9 +308,26 @@ public class OfficeSellController {
districtPriceMap.put("city", district.getCity());
districtPriceMap.put("district", district.getRegion());
districtPriceMap.put("name", district.getName());
districtPriceMap.put("unitPrice", evaluation.getUnitPrice());
Long totalPrice = (long) (evaluation.getUnitPrice() * model.getSize());
AuthenticationBean authenticationBean = (AuthenticationBean) request
.getAttribute(AuthenticationBean.ATTR_AUTHENTICATION_BEAN);
if (authenticationBean != null && authenticationBean.apiUser != null) {
evaluation.setFromUserId(String.valueOf(authenticationBean.apiUser.getId()));
}
if(null!= evaluation && StringUtils.isNotBlank(evaluation.getFromUserId())){
ApiUserCfg apiUserCfg = apiUserCfgService.findByUserId(Long.valueOf(evaluation.getFromUserId()), ApiUserCfg.ApiUserCfgKey.EVALUATE_RATE);
if(apiUserCfg != null && apiUserCfg.getCfgValue() != null && apiUserCfg.getCfgValue() instanceof Double){
Double rate = (Double)apiUserCfg.getCfgValue();
if(rate != 0){
totalPrice = (long)(totalPrice * rate);
}
}
}
districtPriceMap.put("totalPrice", totalPrice);
districtPriceMap.put("unitPrice", new BigDecimal(totalPrice/model.getSize()).setScale(0, BigDecimal.ROUND_HALF_UP).intValue());
if(model.getShow()!=null && model.getShow()==1){
districtPriceMap.put("result", evaluation.getSeawater());
}
@@ -473,6 +493,9 @@ public class OfficeSellController {
List<BusinessCaseDto> createBusiness = createBusiness(evaluation.getSeawater(), "office_sell", district);
// districtPriceMap.put("result", createBusiness);
mav.setModel(BasicModel.buildOKModel().setResult(createBusiness));
if(createBusiness.size()<5){
BasicModel.markNoDataRequest();
}
return mav;
}
mav.setModel(BasicModel.buildOKModel().markNoData());
@@ -706,4 +729,8 @@ public class OfficeSellController {
public void setAddressMatchProxyService(AddressMatchProxyService addressMatchProxyService) {
this.addressMatchProxyService = addressMatchProxyService;
}
public void setApiUserCfgService(ApiUserCfgService apiUserCfgService) {
this.apiUserCfgService = apiUserCfgService;
}
}
@@ -6014,49 +6014,79 @@ public class PropertyController {
}
boolean villaFlag = DataUtil.isVilla(model.getSize(), model.getName(), model.getHeight(), model.getRoom());
Map<String, Object> params = new HashMap<String, Object>();
params.put("city", model.getCity());
if (StringUtils.isNotBlank(model.getDistrict())) {
params.put("suggestDistrict", model.getDistrict());
}
params.put("address", model.getAddress());
if (StringUtils.isNotBlank(model.getName())) {
params.put("suggestName", model.getName());
}
params.put("category", "district");
params.put("propertyType", model.getPropertyType());
String result = addressMatchProxyService.parser(params);
if (result != null) {
JSONObject json = JSONObject.fromObject(result);
if (json.getInt("code") == 200) {
Map<String, Object> map = (Map<String, Object>) json.get("result");
if ((Integer) map.get("precise") >= 0) {
String propertyType = (String) map.get("propertyType");
// 优先使用客户的物业类型,即使面积很大也不进行别墅推断 20241111
String userPropertyTypeParam = model.getPropertyType();
if (StringUtils.isNotBlank(userPropertyTypeParam) && ("0,2".contains(userPropertyTypeParam))) {
villaFlag = false;
}
if (villaFlag && StringUtils.isNotBlank(propertyType) && !propertyType.equals("别墅")) {
district = districtService.findByNameAndAlias((String) map.get("city"), (String) map.get("district"), (String) map.get("name") + "别墅", "district");
}
if (null == district) {
district = districtService.findByNameAndAlias((String) map.get("city"), (String) map.get("district"), (String) map.get("name"), "district");
}
// Map<String, Object> params = new HashMap<String, Object>();
// params.put("city", model.getCity());
// if (StringUtils.isNotBlank(model.getDistrict())) {
// params.put("suggestDistrict", model.getDistrict());
// }
// params.put("address", model.getAddress());
// if (StringUtils.isNotBlank(model.getName())) {
// params.put("suggestName", model.getName());
// }
// params.put("category", "district");
// params.put("propertyType", model.getPropertyType());
// String result = addressMatchProxyService.parser(params);
// if (result != null) {
// JSONObject json = JSONObject.fromObject(result);
// if (json.getInt("code") == 200) {
// Map<String, Object> map = (Map<String, Object>) json.get("result");
// if ((Integer) map.get("precise") >= 0) {
// String propertyType = (String) map.get("propertyType");
// // 优先使用客户的物业类型,即使面积很大也不进行别墅推断 20241111
// String userPropertyTypeParam = model.getPropertyType();
// if (StringUtils.isNotBlank(userPropertyTypeParam) && ("0,2".contains(userPropertyTypeParam))) {
// villaFlag = false;
// }
// if (villaFlag && StringUtils.isNotBlank(propertyType) && !propertyType.equals("别墅")) {
// district = districtService.findByNameAndAlias((String) map.get("city"), (String) map.get("district"), (String) map.get("name") + "别墅", "district");
// }
// if (null == district) {
// district = districtService.findByNameAndAlias((String) map.get("city"), (String) map.get("district"), (String) map.get("name"), "district");
// }
//
// }
// }
// }
}
String estateType = null;
if(StringUtils.isNotBlank(model.getPropertyType())){
if(model.getPropertyType().equals("0")){
estateType = "普通住宅";
}else if(model.getPropertyType().equals("1")){
estateType = "别墅";
}else if(model.getPropertyType().equals("2")){
estateType = "商住";
}
}
if (district == null) {
//使用新匹配再配一遍,不加类型,有结果,类型为district则走小区估值,其它类型也走经纬度估值
JSONObject resultObject = addressMatchProxyService.newMatch(model.getCity(), model.getAddress(), null, false);
if (resultObject != null && resultObject.containsKey("category") && resultObject.get("category")!=null) {
if(resultObject.containsKey("id") && resultObject.get("category").equals("district")){
String id = (String) resultObject.get("id");
district = districtService.findById(id);
if (district == null && (StringUtils.isNotBlank(model.getName()) || StringUtils.isNotBlank(model.getAddress()))) {
JSONObject resultObject = null;
if(StringUtils.isNotBlank(model.getAddress())){
resultObject = addressMatchProxyService.newMatch(model.getCity(), model.getAddress(), "property", false);
}else if(StringUtils.isNotBlank(model.getName())){
if(estateType !=null && estateType.equals("别墅") && !model.getName().contains("别墅")){
resultObject = addressMatchProxyService.newMatch(model.getCity(), model.getName()+"别墅", "property", false);
}else{
resultObject = addressMatchProxyService.newMatch(model.getCity(), model.getName(), "property", false);
}
}
if(resultObject != null){
String id = (String) resultObject.get("id");
district = districtService.findById(id);
}
}
// if (district == null) {
// //使用新匹配再配一遍,不加类型,有结果,类型为district则走小区估值,其它类型也走经纬度估值
// JSONObject resultObject = addressMatchProxyService.newMatch(model.getCity(), model.getAddress(), null, false);
// if (resultObject != null && resultObject.containsKey("category") && resultObject.get("category")!=null) {
// if(resultObject.containsKey("id") && resultObject.get("category").equals("district")){
// String id = (String) resultObject.get("id");
// district = districtService.findById(id);
// }
// }
// }
if(district != null){
model.setRegion(district.getRegion());
@@ -6358,6 +6388,9 @@ public class PropertyController {
caseDtos = caseDtos.subList(0, caseDtos.size()-1);
}
mav.setModel(BasicModel.buildOKModel().setResult(caseDtos));
if(caseDtos.size()<5){
BasicModel.markNoDataRequest();
}
return mav;
}
@@ -6551,6 +6584,9 @@ public class PropertyController {
caseDtos = caseDtos.subList(0, caseDtos.size()-1);
}
mav.setModel(BasicModel.buildOKModel().setResult(caseDtos));
if(caseDtos.size()<5){
BasicModel.markNoDataRequest();
}
return mav;
}
@@ -1044,7 +1044,17 @@ public class EvaluationServiceImpl implements EvaluationService {
if(sqmetreRent!=null){
long totalPrice = evaluationRateService.evaluationRent(sqmetreRent.getAvgPrice().intValue(), evaluation);
if(null!= evaluation && StringUtils.isNotBlank(evaluation.getFromUserId())){
ApiUserCfg apiUserCfg = apiUserCfgService.findByUserId(Long.valueOf(evaluation.getFromUserId()), ApiUserCfg.ApiUserCfgKey.EVALUATE_RATE);
if(apiUserCfg != null && apiUserCfg.getCfgValue() != null && apiUserCfg.getCfgValue() instanceof Double){
Double rate = (Double)apiUserCfg.getCfgValue();
if(rate != 0){
totalPrice = (long)(totalPrice * rate);
}
}
}
evaluation.setTotalPrice(((Number) (totalPrice)).intValue());
// evaluation.setAvgPrice(((Number) (totalPrice / evaluation.getArea())).intValue());
evaluation.setEvaluateWay(sqmetreRent.getValueType());
evaluation.setCredit(sqmetreRent.getCredit());