diff --git a/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/bkoff/DealSampleDao.java b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/bkoff/DealSampleDao.java new file mode 100644 index 000000000..825e58d15 --- /dev/null +++ b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/bkoff/DealSampleDao.java @@ -0,0 +1,8 @@ +package com.fangjia.dal.mongo.dao.bkoff; + + +import com.fangjia.dal.MongoDao; +import com.fangjia.dal.mongo.model.bkoff.DealSample; + +public interface DealSampleDao extends MongoDao { +} diff --git a/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/bkoff/DealSampleDaoImpl.java b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/bkoff/DealSampleDaoImpl.java new file mode 100644 index 000000000..3013c3cf5 --- /dev/null +++ b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/dao/bkoff/DealSampleDaoImpl.java @@ -0,0 +1,9 @@ +package com.fangjia.dal.mongo.dao.bkoff; + +import com.fangjia.dal.MongoDaoImpl; +import com.fangjia.dal.mongo.model.bkoff.DealSample; + + +public class DealSampleDaoImpl extends MongoDaoImpl implements DealSampleDao{ + +} diff --git a/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/bkoff/DealSample.java b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/bkoff/DealSample.java new file mode 100644 index 000000000..463b47bcd --- /dev/null +++ b/projects/fangjia-dal/src/main/java/com/fangjia/dal/mongo/model/bkoff/DealSample.java @@ -0,0 +1,194 @@ +package com.fangjia.dal.mongo.model.bkoff; + +import com.fangjia.dal.MongoEntity; + +import javax.persistence.*; +import java.util.Date; + +@Entity +@Table(name = "business.deal_sample") +public class DealSample implements MongoEntity { + private String id; + private String city; + private String district; + private String name; + private Number unitPrice; + private Integer totalPrice; + private Double size; + private String type; + private Integer floor; + private Date caseDate; + private String decoration; + private String direction;//朝向 + private Integer maxFloor; + private Integer room; + private Integer hall; + private Integer yearmonth; + private String cat; + private Object location; + + @Column(name = "city") + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + @Column(name = "district") + public String getDistrict() { + return district; + } + + public void setDistrict(String district) { + this.district = district; + } + + @Column(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Column(name = "unitPrice") + public Number getUnitPrice() { + return unitPrice; + } + + public void setUnitPrice(Number unitPrice) { + this.unitPrice = unitPrice; + } + + @Column(name = "totalPrice") + public Integer getTotalPrice() { + return totalPrice; + } + + public void setTotalPrice(Integer totalPrice) { + this.totalPrice = totalPrice; + } + + @Column(name = "size") + public Double getSize() { + return size; + } + + public void setSize(Double size) { + this.size = size; + } + + @Column(name = "type") + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Column(name = "floor") + public Integer getFloor() { + return floor; + } + + public void setFloor(Integer floor) { + this.floor = floor; + } + + @Column(name = "caseDate") + public Date getCaseDate() { + return caseDate; + } + + public void setCaseDate(Date caseDate) { + this.caseDate = caseDate; + } + + @Column(name = "decoration") + public String getDecoration() { + return decoration; + } + + public void setDecoration(String decoration) { + this.decoration = decoration; + } + + @Column(name = "direction") + public String getDirection() { + return direction; + } + + public void setDirection(String direction) { + this.direction = direction; + } + + @Column(name = "maxFloor") + public Integer getMaxFloor() { + return maxFloor; + } + + public void setMaxFloor(Integer maxFloor) { + this.maxFloor = maxFloor; + } + + @Column(name = "room") + public Integer getRoom() { + return room; + } + + public void setRoom(Integer room) { + this.room = room; + } + + @Column(name = "hall") + public Integer getHall() { + return hall; + } + + public void setHall(Integer hall) { + this.hall = hall; + } + + @Column(name = "yearmonth") + public Integer getYearmonth() { + return yearmonth; + } + + public void setYearmonth(Integer yearmonth) { + this.yearmonth = yearmonth; + } + + @Column(name = "cat") + public String getCat() { + return cat; + } + + public void setCat(String cat) { + this.cat = cat; + } + + @Column(name = "location") + public Object getLocation() { + return location; + } + + public void setLocation(Object location) { + this.location = location; + } + + @Id + @GeneratedValue + @Column(name = "_id", unique = true, nullable = false) + public String getId() { + return id; + } + + @Override + public void setId(String id) { + this.id = id; + } +} diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/CommercialController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/CommercialController.java index db77ba917..715bf5ae8 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/CommercialController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/CommercialController.java @@ -1,7 +1,9 @@ package com.fangjia.open.controllers; import com.fangjia.core.util.*; +import com.fangjia.dal.mongo.fangjia.model.ServerArea; import com.fangjia.dal.mongo.model.ApiUserCfg; +import com.fangjia.dal.mongo.model.bkoff.DealSample; import com.fangjia.open.dto.BusinessCaseDto; import com.fangjia.open.interceptors.AuthenticationBean; import com.fangjia.open.interceptors.Authority; @@ -11,6 +13,8 @@ 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 com.fangjia.service.mongo.fangjia.DealSampleService; +import com.fangjia.service.mongo.fangjia.ServerAreaService; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; @@ -30,6 +34,7 @@ public class CommercialController { private static final List GAODE_LEVEL = Arrays.asList("兴趣点", "门牌号", "单元号", "楼层", "房间", "门址", "住宅区","村庄"); private ApiUserCfgService apiUserCfgService; + private DealSampleService dealSampleService; public Object shopSellEvaluateAction(CommercialModel model, HttpServletRequest request) { @@ -40,6 +45,7 @@ public class CommercialController { return mav; } + Double ratio = getUserPriceRatio(request); JSONObject json = locationEvaluateApi(model, AvmUrls.SHOPSELL_EVALUATE); if (json != null) { if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) { @@ -51,7 +57,7 @@ public class CommercialController { resultMap.put("totalPrice", totalPrice); if (model.getShowSample()!=null && model.getShowSample()==1 && json.containsKey("case")) { - List dtos = createBusiness((JSONArray) json.get("case"), "sell"); + List dtos = createBusiness((JSONArray) json.get("case"), "sell", ratio); resultMap.put("result", dtos); } @@ -66,7 +72,7 @@ public class CommercialController { return mav; } - public Object shopSellSampleAction(CommercialModel model) { + public Object shopSellSampleAction(CommercialModel model, HttpServletRequest request) { RestfulModelAndView mav = new RestfulModelAndView(); mav.setViewType("rest"); @@ -74,14 +80,15 @@ public class CommercialController { if(mav.model()!=null){ return mav; } + Double ratio = getUserPriceRatio(request); JSONObject json = locationEvaluateApi(model, AvmUrls.SHOPSELL_EVALUATE); if (json != null) { + if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) { - List> list = new ArrayList>(); if (json.containsKey("case")) { - List dtos = createBusiness((JSONArray) json.get("case"), "sell"); + List dtos = createBusiness((JSONArray) json.get("case"), "sell", ratio); mav.setModel(BasicModel.buildOKModel().setResult(dtos)); - if(dtos.size()<5){ + if(dtos!=null && dtos.size()<5){ BasicModel.markNoDataRequest(); } } @@ -95,6 +102,69 @@ public class CommercialController { return mav; } + /** + * 湖北征信定制接口 + * @param model + * @param request + * @return + */ + public Object shopSellCaseAction(CommercialModel model, HttpServletRequest request) { + + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + mav = checkParmas(model, mav); + if(mav.model()!=null){ + return mav; + } + Double ratio = getUserPriceRatio(request); + JSONObject json = locationEvaluateApi(model, AvmUrls.SHOPSELL_EVALUATE); + if (json != null) { + + if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) { + if (json.containsKey("unitPrice") && json.containsKey("location")) { + Double unitPrice = null; + if(json.get("unitPrice") != null){ + unitPrice = Double.valueOf(json.getInt("unitPrice")); + if(ratio!=null){ + unitPrice = unitPrice * ratio; + } + int minPrice = (int) (unitPrice - unitPrice * 0.1); + model.setMinPrice(minPrice); + + int maxPrice = (int) (unitPrice + unitPrice * 0.1); + model.setMaxPrice(maxPrice); + }else{ + if(model.getMinPrice() != null && model.getMinPrice()>0){ + model.setMinPrice(model.getMinPrice()); + } + if(model.getMaxPrice() != null && model.getMaxPrice()>0){ + model.setMaxPrice(model.getMaxPrice()); + } + } + JSONObject locObj = json.getJSONObject("location"); + Double lng = locObj.getDouble("lon"); + Double lat = locObj.getDouble("lat"); + List houseSelf = dealSampleService.querySampleByLocation(json.getString("city"), lng, lat, model.getMinPrice(), model.getMaxPrice(), "shop_sell", 30); + List dtos = createSample(houseSelf, "sell", ratio, lng, lat, unitPrice.doubleValue()); + + if(dtos!=null && dtos.size()>5){ + dtos = dtos.subList(0,5); + } + mav.setModel(BasicModel.buildOKModel().setResult(dtos)); + if(dtos!=null && dtos.size()<5){ + BasicModel.markNoDataRequest(); + } + + } + } else{ + mav.setModel(BasicModel.buildOKModel().setResult(null)); + } + } else { + mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); + } + + return mav; + } /** * 商铺出租 @@ -110,6 +180,7 @@ public class CommercialController { return mav; } + Double ratio = getUserPriceRatio(request); JSONObject json = locationEvaluateApi(model, AvmUrls.SHOPRENT_EVALUATE); if (json != null) { if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) { @@ -122,7 +193,7 @@ public class CommercialController { if (model.getShowSample()!=null && model.getShowSample()==1 && json.containsKey("case")) { - List dtos = createBusiness((JSONArray) json.get("case"), "rent"); + List dtos = createBusiness((JSONArray) json.get("case"), "rent", ratio); resultMap.put("result", dtos); } @@ -154,29 +225,44 @@ public class CommercialController { return totalPrice; } - private List createBusiness(JSONArray cases, String cat){ + private List createBusiness(JSONArray cases, String cat, Double ratio){ if(cases != null && cases.size()>0){ List dtos = new ArrayList(); for(int i=0 ;i < cases.size(); i++){ JSONObject jsonObject = cases.getJSONObject(i); BusinessCaseDto dto = new BusinessCaseDto(); + dto.setId(jsonObject.getString("id")); dto.setCity(jsonObject.getString("city")); dto.setDistrict(jsonObject.getString("district")); dto.setName(jsonObject.getString("name")); dto.setLocation(jsonObject.getString("location")); - if(cat.equals("rent")){ - Double dayPrice = jsonObject.getInt("totalPrice")/(jsonObject.getDouble("size")*30); - dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + + if(ratio != null){ + Integer totalPrice = new BigDecimal(jsonObject.getInt("totalPrice")* ratio).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(); + if(cat.equals("rent")){ + Double dayPrice = totalPrice/(jsonObject.getDouble("size")*30); + dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + }else{ + Integer avgPrie = (int)(totalPrice/jsonObject.getDouble("size")); + dto.setUnitPrice(avgPrie); + } + dto.setTotalPrice(totalPrice); }else{ - dto.setUnitPrice(jsonObject.getInt("unitPrice")); + if(cat.equals("rent")){ + Double dayPrice = jsonObject.getInt("totalPrice")/(jsonObject.getDouble("size")*30); + dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + }else{ + dto.setUnitPrice(jsonObject.getInt("unitPrice")); + } + dto.setTotalPrice(jsonObject.getInt("totalPrice")); } - dto.setTotalPrice(jsonObject.getInt("totalPrice")); + dto.setDistance(jsonObject.getInt("distance")); dto.setSize(jsonObject.getDouble("size")); if(jsonObject.containsKey("type")){ - dto.setType(jsonObject.getString("type")); + dto.setEstateType(jsonObject.getString("type")); } if(jsonObject.containsKey("floor")){ dto.setFloor(jsonObject.getInt("floor")); @@ -191,7 +277,77 @@ public class CommercialController { } - public Object shopRentSampleAction(CommercialModel model) { + private List createSample(List cases, String cat, Double ratio, Double lng, Double lat, final Double unitPrice){ + if(cases != null && cases.size()>0){ + List dtos = new ArrayList(); + for(DealSample sample : cases){ + BusinessCaseDto dto = new BusinessCaseDto(); + dto.setId(sample.getId()); + dto.setCity(sample.getCity()); + dto.setDistrict(sample.getDistrict()); + dto.setName(sample.getName()); +// dto.setLocation(sample.getString("location")); + +// if(ratio != null){ +// Integer totalPrice = (int)(sample.getTotalPrice().intValue() * ratio); +// if(cat.equals("rent")){ +// Double dayPrice = totalPrice/(sample.getSize()*30); +// dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); +// }else{ +// Integer avgPrice = BigDecimal.valueOf(totalPrice/sample.getSize()).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(); +// dto.setUnitPrice(avgPrice); +// } +// dto.setTotalPrice(totalPrice); +// }else{ + if(cat.equals("rent")){ + Double dayPrice = sample.getTotalPrice()/(sample.getSize()*30); + dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + }else{ + dto.setUnitPrice(sample.getUnitPrice()); + } + dto.setTotalPrice(sample.getTotalPrice()); +// } + dto.setSize(sample.getSize()); + if(StringUtils.isNotBlank(sample.getType())){ + dto.setEstateType(sample.getType()); + } + if(sample.getFloor()!=null){ + dto.setFloor(sample.getFloor()); + } + + dto.setCaseDate(DateUtil.formatByPattern(sample.getCaseDate(),"yyyy-MM-dd")); + + Map locationMap = (Map) sample.getLocation(); + double distance = GeoUtils.calculateDistance(locationMap.get("lon"), locationMap.get("lat"), lng, lat); + dto.setDistance((int)distance); + + dtos.add(dto); + } + + if(unitPrice!=null){ + Collections.sort(dtos, new Comparator() { + @Override + public int compare(BusinessCaseDto dto1, BusinessCaseDto dto2) { + double diff1 = Math.abs(dto1.getUnitPrice().doubleValue() - unitPrice); + double diff2 = Math.abs(dto2.getUnitPrice().doubleValue() - unitPrice); + + if (diff1 < diff2) { + return -1; + } else if (diff1 > diff2) { + return 1; + } else { + return 0; + } + } + }); + } + return dtos; + } + return null; + } + + + public Object shopRentSampleAction(CommercialModel model, HttpServletRequest request) { RestfulModelAndView mav = new RestfulModelAndView(); mav.setViewType("rest"); @@ -199,14 +355,14 @@ public class CommercialController { if(mav.model()!=null){ return mav; } + Double ratio = getUserPriceRatio(request); JSONObject json = locationEvaluateApi(model, AvmUrls.SHOPRENT_EVALUATE); if (json != null) { if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) { - List> list = new ArrayList>(); if (json.containsKey("case")) { - List dtos = createBusiness((JSONArray) json.get("case"), "rent"); + List dtos = createBusiness((JSONArray) json.get("case"), "rent", ratio); mav.setModel(BasicModel.buildOKModel().setResult(dtos)); - if(dtos.size()<5){ + if(dtos!=null && dtos.size()<5){ BasicModel.markNoDataRequest(); } } @@ -221,6 +377,71 @@ public class CommercialController { } + /** + * 湖北征信定制出租案例接口 + * @param model + * @param request + * @return + */ + public Object shopRentCaseAction(CommercialModel model, HttpServletRequest request) { + + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + mav = checkParmas(model, mav); + if(mav.model()!=null){ + return mav; + } + Double ratio = getUserPriceRatio(request); + JSONObject json = locationEvaluateApi(model, AvmUrls.SHOPRENT_EVALUATE); + if (json != null) { + if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) { + if (json.containsKey("unitPrice") && json.containsKey("location")) { + + Double minPrice = null; + Double maxPrice = null; + Double unitPrice = null; + if(json.get("unitPrice") != null){ + unitPrice = (Double) json.get("unitPrice"); + if(ratio!=null){ + unitPrice = unitPrice * ratio; + } + minPrice = unitPrice - unitPrice * 0.1; + maxPrice = unitPrice + unitPrice * 0.1; + + }else{ + if(model.getMinPrice() != null && model.getMinPrice()>0){ + minPrice = model.getMinPrice().doubleValue(); + } + if(model.getMaxPrice() != null && model.getMaxPrice()>0){ + minPrice = model.getMaxPrice().doubleValue(); + } + } + JSONObject locObj = json.getJSONObject("location"); + Double lng = locObj.getDouble("lon"); + Double lat = locObj.getDouble("lat"); + List houseSelf = dealSampleService.querySampleByLocation(json.getString("city"), lng, lat, DataUtil.getDoubleRound(2, minPrice), DataUtil.getDoubleRound(2, maxPrice), "shop_rent", 30); + + List dtos = createSample(houseSelf, "rent", ratio, lng, lat, unitPrice); + + if(dtos!=null && dtos.size()>5){ + dtos = dtos.subList(0,5); + } + mav.setModel(BasicModel.buildOKModel().setResult(dtos)); + if(dtos!=null && dtos.size()<5){ + BasicModel.markNoDataRequest(); + } + } + }else{ + mav.setModel(BasicModel.buildOKModel().setResult(null)); + } + } else { + mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中...")); + } + + return mav; + } + + private RestfulModelAndView checkParmas(CommercialModel model, RestfulModelAndView mav){ if (StringUtils.isBlank(model.getAddress()) && StringUtils.isBlank(model.getLocation())) { @@ -334,7 +555,26 @@ public class CommercialController { return json; } + private Double getUserPriceRatio(HttpServletRequest request){ + Double ratio = null; + 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(); + ratio = rate; + } + } + return ratio; + } + public void setApiUserCfgService(ApiUserCfgService apiUserCfgService) { this.apiUserCfgService = apiUserCfgService; } + + public void setDealSampleService(DealSampleService dealSampleService) { + this.dealSampleService = dealSampleService; + } } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java index 10f8faba0..c9c6ffba1 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeController.java @@ -7,6 +7,7 @@ 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.mongo.model.bkoff.DealSample; import com.fangjia.dal.seawater.model.SeawaterDto; import com.fangjia.dal.seaweed.model.District; import com.fangjia.open.HttpCode; @@ -27,12 +28,15 @@ import com.fangjia.service.datastore.FieldFilterService; import com.fangjia.service.datastore.OfficeService; import com.fangjia.service.datastore.OpenApiLogService; import com.fangjia.service.datastore.dto.OfficeEvaluationDto; +import com.fangjia.service.mongo.fangjia.DealSampleService; +import com.fangjia.service.mongo.fangjia.ServerAreaService; import net.sf.json.JSONObject; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.bson.types.ObjectId; import org.slf4j.Logger; +import org.sothis.core.util.Pager; import org.sothis.web.mvc.ActionContext; import org.sothis.web.mvc.annotation.Param; @@ -63,6 +67,8 @@ public class OfficeController { private AddressParser addressParser; private FieldFilterService fieldFilterService; private ApiUserCfgService apiUserCfgService; + private ServerAreaService serverAreaService; + private DealSampleService dealSampleService; /** * 城市出租均价 @@ -727,6 +733,7 @@ public class OfficeController { } /* 先到CPDB库中查找写字楼 */ District district = null; + Double ratio = getUserPriceRatio(request); if(StringUtils.isNotBlank(model.getDistrict()) && StringUtils.isNotBlank(model.getName())) { district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), "office"); @@ -766,6 +773,13 @@ public class OfficeController { return mav; } + if(district.getCity()!=null){ + ServerArea serverArea = serverAreaService.findByDisplay(district.getCity()); + if(serverArea!=null && serverArea.getNewCityGrade()>=3000){ + mav.setModel(BasicModel.buildServerErrorModel().setMsg("当前仅支持一、二线城市,暂不支持您选择的城市")); + return mav; + } + } model.setRegion(district.getRegion()); model.setDistrictName(district.getName()); @@ -774,18 +788,141 @@ public class OfficeController { if (evaluation.getUnitPrice() != null && evaluation.getUnitPrice() != 0) { Map districtPriceMap = new HashMap(); - List createBusiness = createBusiness(evaluation.getSeawater(), "office_rent", district); + List createBusiness = createBusiness(evaluation.getSeawater(), "office_rent", district, ratio); mav.setModel(BasicModel.buildOKModel().setResult(createBusiness)); - if(createBusiness.size()<5){ + if(createBusiness!=null && createBusiness.size()<5){ BasicModel.markNoDataRequest(); } return mav; } - mav.setModel(BasicModel.buildOKModel().markNoData()); +// mav.setModel(BasicModel.buildOKModel().markNoData()); return mav; } + public Object rentSampleAction(PropertyEvaluationModel model, HttpServletRequest request) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + + if (StringUtils.isBlank(model.getCity()) || model.getSize()<=0) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,面积为必填项")); + return mav; + } + + if (StringUtils.isBlank(model.getName()) && StringUtils.isBlank(model.getAddress()) ) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:名称或地址至少填一个")); + return mav; + } + /* 先到CPDB库中查找写字楼 */ + District district = null; + Double ratio = getUserPriceRatio(request); + + if(StringUtils.isNotBlank(model.getDistrict()) && StringUtils.isNotBlank(model.getName())) { + district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), "office"); + } + + 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(), "office", false); + }else if(StringUtils.isNotBlank(model.getName())){ + resultObject = addressMatchProxyService.newMatch(model.getCity(), model.getName(), "office", false); + } + if(resultObject != null){ + String id = (String) resultObject.get("id"); + district = districtService.findById(id); + } + } + + 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; + } + + if(district.getCity()!=null){ + ServerArea serverArea = serverAreaService.findByDisplay(district.getCity()); + if(serverArea!=null && serverArea.getNewCityGrade()>=3000){ + mav.setModel(BasicModel.buildServerErrorModel().setMsg("当前仅支持一、二线城市,暂不支持您选择的城市")); + return mav; + } + } + + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + + OfficeEvaluationDto evaluation = officeService.evaluateRent(district, buildEvaluation(model, request)); + Double minPrice = null; + Double maxPrice = null; + if (evaluation.getUnitPrice() != null && evaluation.getUnitPrice() != 0) { + + Pager pager = new Pager(); + pager.setStartRow(0); + if (model.getPageSize() != null) { + if(model.getPageSize() <=50){ + pager.setPageSize(model.getPageSize()); + }else{ + pager.setPageSize(50); + } + } else { + pager.setPageSize(30); + } + + Double unitPrice = null; + if(model.getMinPrice() == null){ + unitPrice = evaluation.getUnitPrice(); + if(ratio != null){ + unitPrice = unitPrice * ratio; + } + if(evaluation != null) { + minPrice = evaluation.getUnitPrice() - evaluation.getUnitPrice() * 0.1; + maxPrice = evaluation.getUnitPrice() + evaluation.getUnitPrice().intValue() * 0.1; + } + }else{ + if(model.getMinPrice() != null && model.getMinPrice()>0){ + minPrice = model.getMinPrice().doubleValue(); + } + if(model.getMaxPrice() != null && model.getMaxPrice()>0){ + maxPrice = model.getMaxPrice().doubleValue(); + } + } + + Double lng = district.getLng()/10000000000.0; + Double lat = district.getLat()/10000000000.0; + List houseSelf = dealSampleService.querySampleByLocation(district.getCity(), lng, lat, DataUtil.getDoubleRound(2, minPrice), DataUtil.getDoubleRound(2, maxPrice), "office_rent", pager.getPageSize()); + List createBusiness = createSample(houseSelf, "office_rent", district, ratio, lng, lat, unitPrice); + + if(createBusiness!=null && createBusiness.size()>5){ + createBusiness = createBusiness.subList(0,5); + } + mav.setModel(BasicModel.buildOKModel().setResult(createBusiness)); + if(createBusiness!=null && createBusiness.size()<5){ + BasicModel.markNoDataRequest(); + } + return mav; + } +// mav.setModel(BasicModel.buildOKModel().markNoData()); + return mav; + } + + + + private Integer getFloor(String roomNumber) { if (StringUtils.isNotBlank(roomNumber) && DataUtil.isNumber(roomNumber)) { if (roomNumber.length() == 3) { @@ -799,6 +936,23 @@ public class OfficeController { return null; } + + private Double getUserPriceRatio(HttpServletRequest request){ + Double ratio = null; + 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(); + ratio = rate; + } + } + return ratio; + } + + /** * 通过EvaluationModel组装Evaluation实体 * @@ -967,25 +1121,40 @@ public class OfficeController { } }; - private List createBusiness(List seawaterDtos, String cat, District district){ + private List createBusiness(List seawaterDtos, String cat, District district, Double ratio){ if(seawaterDtos != null && seawaterDtos.size()>0){ List dtos = new ArrayList(); for(SeawaterDto house : seawaterDtos){ BusinessCaseDto dto = new BusinessCaseDto(); + dto.setId(house.getId()); dto.setCity(house.getCity()); dto.setDistrict(house.getDistrict()); dto.setName(house.getName()); dto.setLocation(house.getLocation()); - if(cat.equals("office_rent")){ - Double dayPrice = house.getTotalPrice()/(house.getArea()*30); - dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + if(ratio != null) { + Integer totalPrice = (int) (house.getTotalPrice() * ratio); + if(cat.equals("office_rent")){ + Double dayPrice = totalPrice/(house.getArea()*30); + dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + }else{ + Integer avgPrie = (int)(totalPrice/house.getArea()); + dto.setUnitPrice(avgPrie); + } + dto.setTotalPrice(totalPrice); }else{ - dto.setUnitPrice(house.getUnitPrice()); + if(cat.equals("office_rent")){ + Double dayPrice = house.getTotalPrice()/(house.getArea()*30); + dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + }else{ + dto.setUnitPrice(house.getUnitPrice()); + } + dto.setTotalPrice(house.getTotalPrice()); } + if(StringUtils.isNotBlank(house.getEstateType())){ - dto.setType(house.getEstateType()); + dto.setEstateType(house.getEstateType()); } - dto.setTotalPrice(house.getTotalPrice()); + if(StringUtils.isNotBlank(house.getLocation()) && district.getLat()!=null){ String[] arrs = house.getLocation().split(","); double distance = GeoUtils.calculateDistance(district.getLng()/10000000000.0, district.getLat()/10000000000.0, Double.valueOf(arrs[0]), Double.valueOf(arrs[1])); @@ -1007,6 +1176,73 @@ public class OfficeController { } return null; } + private List createSample(List seawaterDtos, String cat, District district, Double ratio, Double lng, Double lat, final Double unitPrice){ + if(seawaterDtos != null && seawaterDtos.size()>0){ + List dtos = new ArrayList(); + for(DealSample house : seawaterDtos){ + BusinessCaseDto dto = new BusinessCaseDto(); + dto.setId(house.getId()); + dto.setCity(house.getCity()); + dto.setDistrict(house.getDistrict()); + dto.setName(house.getName()); + +// if(ratio != null){ +// Integer totalPrice = (int) (house.getTotalPrice()*ratio); +// if(cat.equals("office_rent")){ +// Double dayPrice = totalPrice/(house.getSize()*30); +// dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); +// }else{ +// Integer avgPrie = (int)(totalPrice/house.getSize()); +// dto.setUnitPrice(avgPrie); +// } +// dto.setTotalPrice(totalPrice); +// }else{ + if(cat.equals("office_rent")){ + Double dayPrice = house.getTotalPrice()/(house.getSize()*30); + dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + }else{ + dto.setUnitPrice(house.getUnitPrice()); + } + dto.setTotalPrice(house.getTotalPrice()); + +// } + + if(StringUtils.isNotBlank(house.getType())){ + dto.setEstateType(house.getType()); + } + + Map locationMap = (Map) house.getLocation(); + double distance = GeoUtils.calculateDistance(locationMap.get("lon"), locationMap.get("lat"), lng, lat); + dto.setDistance((int)distance); + + dto.setSize(house.getSize()); + dto.setCaseDate(DateUtil.formatByPattern(house.getCaseDate(),"yyyy-MM-dd")); + + dtos.add(dto); + } + + if(unitPrice!=null){ + Collections.sort(dtos, new Comparator() { + @Override + public int compare(BusinessCaseDto dto1, BusinessCaseDto dto2) { + double diff1 = Math.abs(dto1.getUnitPrice().doubleValue() - unitPrice); + double diff2 = Math.abs(dto2.getUnitPrice().doubleValue() - unitPrice); + + if (diff1 < diff2) { + return -1; + } else if (diff1 > diff2) { + return 1; + } else { + return 0; + } + } + }); + } + + return dtos; + } + return null; + } public void setOpenApiLogService(OpenApiLogService openApiLogService) { this.openApiLogService = openApiLogService; @@ -1035,4 +1271,12 @@ public class OfficeController { public void setApiUserCfgService(ApiUserCfgService apiUserCfgService) { this.apiUserCfgService = apiUserCfgService; } + + public void setServerAreaService(ServerAreaService serverAreaService) { + this.serverAreaService = serverAreaService; + } + + public void setDealSampleService(DealSampleService dealSampleService) { + this.dealSampleService = dealSampleService; + } } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeSellController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeSellController.java index 8a6d00e14..4ee9677f9 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeSellController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/OfficeSellController.java @@ -1,15 +1,14 @@ package com.fangjia.open.controllers; import com.fangjia.core.RegionData; -import com.fangjia.core.util.AnalyticsUtil; -import com.fangjia.core.util.DataUtil; -import com.fangjia.core.util.GeoUtils; -import com.fangjia.core.util.LoggerFactory; +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.OfficeSellStat; +import com.fangjia.dal.mongo.model.SqmetreRent; +import com.fangjia.dal.mongo.model.bkoff.DealSample; import com.fangjia.dal.seawater.model.SeawaterDto; import com.fangjia.dal.seaweed.model.District; import com.fangjia.open.HttpCode; @@ -28,12 +27,15 @@ import com.fangjia.service.datastore.DistrictService; import com.fangjia.service.datastore.OfficeService; import com.fangjia.service.datastore.OpenApiLogService; import com.fangjia.service.datastore.dto.OfficeEvaluationDto; +import com.fangjia.service.mongo.fangjia.DealSampleService; +import com.fangjia.service.mongo.fangjia.ServerAreaService; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; +import org.sothis.core.util.Pager; import org.sothis.web.mvc.ActionContext; import org.sothis.web.mvc.annotation.Param; @@ -57,6 +59,8 @@ public class OfficeSellController { private OpenApiLogService openApiLogService; private AddressMatchProxyService addressMatchProxyService; private ApiUserCfgService apiUserCfgService; + private ServerAreaService serverAreaService; + private DealSampleService dealSampleService; /** * 写字楼城市出售均价 * @@ -284,6 +288,15 @@ public class OfficeSellController { return mav; } + if(district.getCity()!=null){ + ServerArea serverArea = serverAreaService.findByDisplay(district.getCity()); + if(serverArea!=null && serverArea.getNewCityGrade()>=3000){ + mav.setModel(BasicModel.buildServerErrorModel().setMsg("当前仅支持一、二线城市,暂不支持您选择的城市")); + return mav; + } + } + + if (model.getFloor() == null) { JSONObject structureOb = addressMatchProxyService.addressStructure(district.getCity(), model.getAddress()); if (structureOb != null) { @@ -440,6 +453,7 @@ public class OfficeSellController { return mav; } + Double ratio = getUserPriceRatio(request); /* 先到CPDB库中查找写字楼 */ District district = null; @@ -485,24 +499,167 @@ public class OfficeSellController { mav.setModel(BasicModel.buildBadRequestModel("所在楼层不能大于总楼层")); return mav; } + + if(district.getCity()!=null){ + ServerArea serverArea = serverAreaService.findByDisplay(district.getCity()); + if(serverArea!=null && serverArea.getNewCityGrade()>=3000){ + mav.setModel(BasicModel.buildServerErrorModel().setMsg("当前仅支持一、二线城市,暂不支持您选择的城市")); + return mav; + } + } + model.setRegion(district.getRegion()); model.setDistrictName(district.getName()); OfficeEvaluationDto evaluation = officeService.evaluateSell(district, buildEvaluation(model, request)); if (evaluation.getUnitPrice() != null && evaluation.getUnitPrice() != 0) { Map districtPriceMap = new HashMap(); - List createBusiness = createBusiness(evaluation.getSeawater(), "office_sell", district); + List createBusiness = createBusiness(evaluation.getSeawater(), "office_sell", district, ratio); // districtPriceMap.put("result", createBusiness); mav.setModel(BasicModel.buildOKModel().setResult(createBusiness)); - if(createBusiness.size()<5){ + if(createBusiness !=null && createBusiness.size()<5){ BasicModel.markNoDataRequest(); } return mav; } - mav.setModel(BasicModel.buildOKModel().markNoData()); +// mav.setModel(BasicModel.buildOKModel().markNoData()); return mav; } + /** + * 湖北征信定制写字楼案例接口 + * @param model + * @param request + * @return + */ + public Object sellSampleAction(PropertyEvaluationModel model, HttpServletRequest request) { + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + + if (StringUtils.isBlank(model.getCity()) || model.getSize()<=0) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,面积为必填项")); + return mav; + } + + if (StringUtils.isBlank(model.getName()) && StringUtils.isBlank(model.getAddress()) ) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:名称或地址至少填一个")); + return mav; + } + + Double ratio = getUserPriceRatio(request); + /* 先到CPDB库中查找写字楼 */ + District district = null; + + if(StringUtils.isNotBlank(model.getDistrict()) && StringUtils.isNotBlank(model.getName())) { + district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), "office"); + } + if (district == null) { + if (StringUtils.isNotBlank(model.getDistrict()) && (model.getDistrict().contains("市辖区") || model.getDistrict().contains(model.getCity()))) { + district = districtService.findByNameAndAlias(model.getCity(), null, model.getName(), "office"); + } + + } + + 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(), "office", false); + }else if(StringUtils.isNotBlank(model.getName())){ + resultObject = addressMatchProxyService.newMatch(model.getCity(), model.getName(), "office", false); + } + if(resultObject != null){ + String id = (String) resultObject.get("id"); + district = districtService.findById(id); + } + } + + 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; + } + + if(district.getCity()!=null){ + ServerArea serverArea = serverAreaService.findByDisplay(district.getCity()); + if(serverArea!=null && serverArea.getNewCityGrade()>=3000){ + mav.setModel(BasicModel.buildServerErrorModel().setMsg("当前仅支持一、二线城市,暂不支持您选择的城市")); + return mav; + } + } + + model.setRegion(district.getRegion()); + model.setDistrictName(district.getName()); + OfficeEvaluationDto evaluation = officeService.evaluateSell(district, buildEvaluation(model, request)); + if (evaluation.getUnitPrice() != null && evaluation.getUnitPrice() != 0) { + + Pager pager = new Pager(); + pager.setStartRow(0); + if (model.getPageSize() != null) { + if(model.getPageSize() <=50){ + pager.setPageSize(model.getPageSize()); + }else{ + pager.setPageSize(50); + } + } else { + pager.setPageSize(30); + } + + Double unitPrice = null; + if(model.getMinPrice() == null){ + if(evaluation != null) { + unitPrice = evaluation.getUnitPrice(); + if(ratio != null){ + unitPrice = unitPrice * ratio; + } + int minPrice = (int) (evaluation.getUnitPrice().intValue() - evaluation.getUnitPrice() * 0.1); + model.setMinPrice(minPrice); + + int maxPrice = (int) (evaluation.getUnitPrice() + evaluation.getUnitPrice().intValue() * 0.1); + model.setMaxPrice(maxPrice); + } + }else{ + if(model.getMinPrice() != null && model.getMinPrice()>0){ + model.setMinPrice(model.getMinPrice()); + } + if(model.getMaxPrice() != null && model.getMaxPrice()>0){ + model.setMaxPrice(model.getMaxPrice()); + } + } + + Double lng = district.getLng()/10000000000.0; + Double lat = district.getLat()/10000000000.0; + List houseSelf = dealSampleService.querySampleByLocation(district.getCity(), lng, lat, model.getMinPrice(), model.getMaxPrice(), "office_sell", pager.getPageSize()); + List createBusiness = createSample(houseSelf, "office_sell", district, ratio, lng, lat, unitPrice); + + if(createBusiness!=null && createBusiness.size()>5){ + createBusiness = createBusiness.subList(0,5); + } + mav.setModel(BasicModel.buildOKModel().setResult(createBusiness)); + if(createBusiness !=null && createBusiness.size()<5){ + BasicModel.markNoDataRequest(); + } + return mav; + } +// mav.setModel(BasicModel.buildOKModel().markNoData()); + return mav; + } + + + private Integer getFloor(String roomNumber) { if (StringUtils.isNotBlank(roomNumber) && DataUtil.isNumber(roomNumber)) { if (roomNumber.length() == 3) { @@ -673,25 +830,41 @@ public class OfficeSellController { } - private List createBusiness(List seawaterDtos, String cat, District district){ + private List createBusiness(List seawaterDtos, String cat, District district, Double ratio){ if(seawaterDtos != null && seawaterDtos.size()>0){ List dtos = new ArrayList(); for(SeawaterDto house : seawaterDtos){ BusinessCaseDto dto = new BusinessCaseDto(); + dto.setId(house.getId()); dto.setCity(house.getCity()); dto.setDistrict(house.getDistrict()); dto.setName(house.getName()); dto.setLocation(house.getLocation()); - if(cat.equals("office_rent")){ - Double dayPrice = house.getTotalPrice()/(house.getUnitPrice()*30); - dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + if(ratio != null){ + Integer totalPrice = (int) (house.getTotalPrice()*ratio); + if(cat.equals("office_rent")){ + Double dayPrice = totalPrice/(house.getArea()*30); + dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + }else{ + Integer avgPrie = (int)(totalPrice/house.getArea()); + dto.setUnitPrice(avgPrie); + } + dto.setTotalPrice(totalPrice); }else{ - dto.setUnitPrice(house.getUnitPrice()); + if(cat.equals("office_rent")){ + Double dayPrice = house.getTotalPrice()/(house.getArea()*30); + dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + }else{ + dto.setUnitPrice(house.getUnitPrice()); + } + dto.setTotalPrice(house.getTotalPrice()); + } + if(StringUtils.isNotBlank(house.getEstateType())){ - dto.setType(house.getEstateType()); + dto.setEstateType(house.getEstateType()); } - dto.setTotalPrice(house.getTotalPrice()); + if(StringUtils.isNotBlank(house.getLocation()) && district.getLat()!=null){ String[] arrs = house.getLocation().split(","); double distance = GeoUtils.calculateDistance(district.getLng()/10000000000.0, district.getLat()/10000000000.0, Double.valueOf(arrs[0]), Double.valueOf(arrs[1])); @@ -714,6 +887,89 @@ public class OfficeSellController { return null; } + + private List createSample(List seawaterDtos, String cat, District district, Double ratio, Double lng, Double lat, final Double unitPrice){ + if(seawaterDtos != null && seawaterDtos.size()>0){ + List dtos = new ArrayList(); + for(DealSample house : seawaterDtos){ + BusinessCaseDto dto = new BusinessCaseDto(); + dto.setId(house.getId()); + dto.setCity(house.getCity()); + dto.setDistrict(house.getDistrict()); + dto.setName(house.getName()); + +// if(ratio != null){ +// Integer totalPrice = (int) (house.getTotalPrice()*ratio); +// if(cat.equals("office_rent")){ +// Double dayPrice = totalPrice/(house.getSize()*30); +// dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); +// }else{ +// Integer avgPrie = BigDecimal.valueOf(totalPrice/house.getSize()).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(); +// dto.setUnitPrice(avgPrie); +// } +// dto.setTotalPrice(totalPrice); +// }else{ + if(cat.equals("office_rent")){ + Double dayPrice = house.getTotalPrice()/(house.getSize()*30); + dto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + }else{ + dto.setUnitPrice(house.getUnitPrice()); + } + dto.setTotalPrice(house.getTotalPrice()); + +// } + + if(StringUtils.isNotBlank(house.getType())){ + dto.setEstateType(house.getType()); + } + + Map locationMap = (Map) house.getLocation(); + double distance = GeoUtils.calculateDistance(locationMap.get("lon"), locationMap.get("lat"), lng, lat); + dto.setDistance((int)distance); + + dto.setSize(house.getSize()); + dto.setCaseDate(DateUtil.formatByPattern(house.getCaseDate(),"yyyy-MM-dd")); + dtos.add(dto); + } + + if(unitPrice!=null){ + Collections.sort(dtos, new Comparator() { + @Override + public int compare(BusinessCaseDto dto1, BusinessCaseDto dto2) { + double diff1 = Math.abs(dto1.getUnitPrice().doubleValue() - unitPrice); + double diff2 = Math.abs(dto2.getUnitPrice().doubleValue() - unitPrice); + + if (diff1 < diff2) { + return -1; + } else if (diff1 > diff2) { + return 1; + } else { + return 0; + } + } + }); + } + return dtos; + } + return null; + } + + + private Double getUserPriceRatio(HttpServletRequest request){ + Double ratio = null; + 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(); + ratio = rate; + } + } + return ratio; + } + public void setOfficeService(OfficeService officeService) { this.officeService = officeService; } @@ -733,4 +989,12 @@ public class OfficeSellController { public void setApiUserCfgService(ApiUserCfgService apiUserCfgService) { this.apiUserCfgService = apiUserCfgService; } + + public void setServerAreaService(ServerAreaService serverAreaService) { + this.serverAreaService = serverAreaService; + } + + public void setDealSampleService(DealSampleService dealSampleService) { + this.dealSampleService = dealSampleService; + } } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java index fd2a50b93..6dd826a9e 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/PropertyController.java @@ -25,6 +25,8 @@ import com.fangjia.core.util.*; import com.fangjia.dal.*; import com.fangjia.dal.mongo.dao.AliasFangDao; import com.fangjia.dal.mongo.model.*; +import com.fangjia.dal.mongo.model.bkoff.*; +import com.fangjia.dal.mongo.model.bkoff.HouseLoudong; import com.fangjia.dal.mongo.open.model.CommunityBasePrice; import com.fangjia.dal.mongo.open.model.CommunityPoi; import com.fangjia.dal.mongo.open.model.EvaluateRatio; @@ -66,10 +68,6 @@ import com.fangjia.dal.common.DistrictKey; import com.fangjia.dal.common.ServerAreaData; import com.fangjia.dal.datastore.model.House; import com.fangjia.dal.mongo.fangjia.model.ServerArea; -import com.fangjia.dal.mongo.model.bkoff.DealPrice; -import com.fangjia.dal.mongo.model.bkoff.HouseAuction; -import com.fangjia.dal.mongo.model.bkoff.HouseLoudong; -import com.fangjia.dal.mongo.model.bkoff.Loudong; import com.fangjia.dal.mongo.open.model.ApiUserAuthority; import com.fangjia.dal.seaweed.model.District; import com.fangjia.dal.sql.model.ApiUser; @@ -179,6 +177,7 @@ public class PropertyController { private CommunityBasePriceService communityBasePriceService; private EvaluateFactorService evaluateFactorService; + private FileDao fileDao = FileDao.getInstance(); private static final int DEFAULT_PAGE_SIZE = 20; private static final int DEFAULT_HOUSE_COUNT = 5; @@ -195,6 +194,7 @@ public class PropertyController { private RentDealPriceService rentDealPriceService; private EvaluateRatioService evaluateRatioService; private AliasFangService aliasFangService; + private DealSampleService dealSampleService; private static final int EVALUATE_SHOW_DETAIL = 1; private static final Map PROPERTY_TYPES = new HashMap() { @@ -1667,10 +1667,18 @@ public class PropertyController { public Object addressEvaluateAction(PropertyEvaluationModel model, HttpServletRequest request) throws IllegalAccessException { RestfulModelAndView mav = new RestfulModelAndView(); mav.setViewType("rest"); - if (StringUtils.isBlank(model.getCity()) || StringUtils.isBlank(model.getAddress()) || model.getSize() <= 0) { - mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,地址,面积(size)为必填项")); + + if (StringUtils.isBlank(model.getCity()) || model.getSize() <= 0) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市,面积(size)为必填项")); return mav; } + + if (StringUtils.isBlank(model.getAddress()) && StringUtils.isBlank(model.getName())) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:地址或名称不为空")); + return mav; + } + + if (model.getDistrict() != null) { //区域编码转房价网区域 FangjiaOfficialAreaMap fangjiaOfficialAreaMap = fangjiaOfficialAreaService.convertOfficialCodeToFangjia(model.getDistrict()); @@ -1679,45 +1687,72 @@ public class PropertyController { } } + District district = null; + + if(StringUtils.isNotBlank(model.getDistrict()) && StringUtils.isNotBlank(model.getName())){ + district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(),"district"); + } + boolean villaFlag = DataUtil.isVilla(model.getSize(), model.getName(), model.getHeight(), model.getRoom()); - District district = null; - Map params = new HashMap(); - 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 map = (Map) 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"); - } + if(district == null){ + Map params = new HashMap(); + params.put("city", model.getCity()); + if (StringUtils.isNotBlank(model.getDistrict())) { + params.put("suggestDistrict", model.getDistrict()); + } + if(StringUtils.isNotBlank(model.getAddress())){ + params.put("address", model.getAddress()); + }else{ + if (StringUtils.isNotBlank(model.getName())) { + params.put("address", model.getName()); + } + } + 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 map = (Map) 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"); + } + + } } } } + if (district == null) { //使用新匹配再配一遍,不加类型,有结果,类型为district则走小区估值,其它类型也走经纬度估值 - JSONObject resultObject = addressMatchProxyService.newMatch(model.getCity(), model.getAddress(), null, false); + JSONObject resultObject = null; + if(StringUtils.isNotBlank(model.getAddress())){ + resultObject = addressMatchProxyService.newMatch(model.getCity(), model.getAddress(), null, false); + }else{ + if(StringUtils.isNotBlank(model.getName())){ + String addr = model.getName(); + if(StringUtils.isNotBlank(model.getDistrict())){ + addr = model.getDistrict() + addr; + } + resultObject = addressMatchProxyService.newMatch(model.getCity(), addr, 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"); @@ -1744,8 +1779,10 @@ 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 resultMap = new HashMap(); - resultMap.put("avgPrice", Long.valueOf(json.getString("unitPrice"))); - resultMap.put("totalPrice", Long.valueOf(json.getString("totalPrice"))); + Long totalPrice = getRatioPrice(request, Long.valueOf(json.getString("totalPrice"))); + + resultMap.put("avgPrice", new BigDecimal(totalPrice/model.getSize()).setScale(0, BigDecimal.ROUND_HALF_UP).longValue()); + resultMap.put("totalPrice", totalPrice); mav.setModel(BasicModel.buildOKModel().setResult(resultMap)); } else { mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!")); @@ -1770,6 +1807,41 @@ public class PropertyController { } + + 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 Double getUserPriceRatio(HttpServletRequest request){ + Double ratio = null; + 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(); + ratio = rate; + } + } + return ratio; + } + + public Object evaluate2Action(PropertyEvaluationModel model, HttpServletRequest request) throws NumberFormatException, IllegalAccessException { RestfulModelAndView mav = new RestfulModelAndView(); @@ -6007,47 +6079,6 @@ public class PropertyController { } District district = null; - if(StringUtils.isNotBlank(model.getCity()) && StringUtils.isNotBlank(model.getDistrict()) && StringUtils.isNotBlank(model.getName())){ - /* 先到CPDB库中查找小区 */ - district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(), - "district"); - } - boolean villaFlag = DataUtil.isVilla(model.getSize(), model.getName(), model.getHeight(), model.getRoom()); - -// Map params = new HashMap(); -// 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 map = (Map) 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")){ @@ -6059,6 +6090,10 @@ public class PropertyController { } } + if(StringUtils.isNotBlank(model.getDistrict()) && StringUtils.isNotBlank(model.getName())){ + district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(),"district"); + } + if (district == null && (StringUtils.isNotBlank(model.getName()) || StringUtils.isNotBlank(model.getAddress()))) { JSONObject resultObject = null; if(StringUtils.isNotBlank(model.getAddress())){ @@ -6077,16 +6112,10 @@ public class PropertyController { 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){ + mav.setModel(BasicModel.buildOKModel().setMsg("暂时不支持该小区的租金估价").markNoData()); + return mav; + } if(district != null){ model.setRegion(district.getRegion()); @@ -6175,6 +6204,7 @@ public class PropertyController { return mav; } + District district = null; String estateType = null; if(StringUtils.isNotBlank(model.getPropertyType())){ if(model.getPropertyType().equals("0")){ @@ -6186,14 +6216,8 @@ public class PropertyController { } } - District district = null; - if(StringUtils.isNotBlank(model.getDistrict()) && StringUtils.isNotBlank(model.getName())){ - if(StringUtils.isNotBlank(model.getEstateType()) && model.getEstateType().equals("别墅") && !model.getName().contains("别墅")){ - district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName()+"别墅","district"); - }else{ - district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(),"district"); - } + district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(),"district"); } if (district == null && (StringUtils.isNotBlank(model.getName()) || StringUtils.isNotBlank(model.getAddress()))) { @@ -6243,6 +6267,7 @@ public class PropertyController { model.setRadius(1000); } + Double ratio = getUserPriceRatio(request); if(district != null){ if(model.getMinPrice() == null){ @@ -6255,10 +6280,10 @@ public class PropertyController { model.setMaxPrice(maxPrice); } }else{ - if(model.getMinPrice() != null && model.getMinPrice()>0){ + if(model.getMinPrice() != null ){ model.setMinPrice(model.getMinPrice()); } - if(model.getMaxPrice() != null && model.getMaxPrice()>0){ + if(model.getMaxPrice() != null ){ model.setMaxPrice(model.getMaxPrice()); } } @@ -6280,7 +6305,7 @@ public class PropertyController { //查自身样本 List houseSelf = houseService.findSelfHouseByParams(district, "sell", Integer.parseInt(startDate), Integer.parseInt(endDate), model.getMinPrice(), model.getMaxPrice(), estateType, pager); if(houseSelf!=null && houseSelf.size()>0){ - caseDtos = createHouseCase(caseDtos, houseSelf, model.getShowSource()); + caseDtos = createHouseCase(caseDtos, houseSelf, model.getShowSource(), ratio); for(HouseCaseDto house : caseDtos){ house.setDistance(0); } @@ -6299,7 +6324,7 @@ public class PropertyController { newDist.setEstateType2(estateType); houseSelf = houseService.findSelfHouseByParams(newDist, "sell", Integer.parseInt(startDate), Integer.parseInt(endDate), model.getMinPrice(), model.getMaxPrice(), estateType, pager); if(houseSelf!=null && houseSelf.size()>0){ - caseDtos = createHouseCase(caseDtos, houseSelf, model.getShowSource()); + caseDtos = createHouseCase(caseDtos, houseSelf, model.getShowSource(), ratio); if(caseDtos.size() == pager.getPageSize()){ caseDtos = caseDtos.subList(0, caseDtos.size()-1); mav.setModel(BasicModel.buildOKModel().setResult(caseDtos)); @@ -6316,7 +6341,7 @@ public class PropertyController { newDist.setEstateType2(estateType); houseSelf = houseService.findSelfHouseByParams(newDist, "sell", Integer.parseInt(startDate), Integer.parseInt(endDate), model.getMinPrice(), model.getMaxPrice(), null, pager); if(houseSelf!=null && houseSelf.size()>0){ - caseDtos = createHouseCase(caseDtos, houseSelf, model.getShowSource()); + caseDtos = createHouseCase(caseDtos, houseSelf, model.getShowSource(), ratio); if(caseDtos.size() == pager.getPageSize()){ caseDtos = caseDtos.subList(0, caseDtos.size()-1); mav.setModel(BasicModel.buildOKModel().setResult(caseDtos)); @@ -6381,20 +6406,26 @@ public class PropertyController { houseAround = houseService.findArroundHouseByParams("sell", lng, lat, Integer.parseInt(startDate), Integer.parseInt(endDate), model.getMinPrice(), model.getMaxPrice(), estateType, pager, model.getRadius()); } if(houseAround != null && houseAround.size()>0){ - caseDtos = createHouseCase(caseDtos, houseAround, model.getShowSource()); + caseDtos = createHouseCase(caseDtos, houseAround, model.getShowSource(), ratio); } } if(caseDtos.size()>pager.getPageSize()){ caseDtos = caseDtos.subList(0, caseDtos.size()-1); } mav.setModel(BasicModel.buildOKModel().setResult(caseDtos)); - if(caseDtos.size()<5){ + if(caseDtos!=null && caseDtos.size()<5){ BasicModel.markNoDataRequest(); } return mav; } + /** + * 公用案例接口 + * @param model + * @param request + * @return + */ public Object rentCaseAction(PropertyEvaluationModel model, HttpServletRequest request){ RestfulModelAndView mav = new RestfulModelAndView(); mav.setViewType("rest"); @@ -6471,6 +6502,7 @@ public class PropertyController { model.setRadius(1000); } + Double ratio = getUserPriceRatio(request); if(district != null){ if(model.getMinPrice() == null){ @@ -6492,12 +6524,11 @@ public class PropertyController { } } - if(caseDtos.size() < pager.getPageSize()){ //查自身样本 List houseSelf = houseService.findSelfHouseByParams(district, "rent", Integer.parseInt(startDate), Integer.parseInt(endDate), model.getMinPrice(), model.getMaxPrice(), estateType, pager); if(houseSelf!=null && houseSelf.size()>0){ - caseDtos = createHouseCase(caseDtos, houseSelf, model.getShowSource()); + caseDtos = createHouseCase(caseDtos, houseSelf, model.getShowSource(), ratio); for(HouseCaseDto house : caseDtos){ house.setDistance(0); } @@ -6516,7 +6547,7 @@ public class PropertyController { newDist.setEstateType2(estateType); houseSelf = houseService.findSelfHouseByParams(newDist, "rent", Integer.parseInt(startDate), Integer.parseInt(endDate), model.getMinPrice(), model.getMaxPrice(), estateType, pager); if(houseSelf!=null && houseSelf.size()>0){ - caseDtos = createHouseCase(caseDtos, houseSelf, model.getShowSource()); + caseDtos = createHouseCase(caseDtos, houseSelf, model.getShowSource(), ratio); if(caseDtos.size() == pager.getPageSize()){ caseDtos = caseDtos.subList(0, caseDtos.size()-1); mav.setModel(BasicModel.buildOKModel().setResult(caseDtos)); @@ -6535,7 +6566,7 @@ public class PropertyController { newDist.setEstateType2(estateType); houseSelf = houseService.findSelfHouseByParams(newDist, "rent", Integer.parseInt(startDate), Integer.parseInt(endDate), model.getMinPrice(), model.getMaxPrice(), null, pager); if(houseSelf!=null && houseSelf.size()>0){ - caseDtos = createHouseCase(caseDtos, houseSelf, model.getShowSource()); + caseDtos = createHouseCase(caseDtos, houseSelf, model.getShowSource(), ratio); if(caseDtos.size() == pager.getPageSize()){ caseDtos = caseDtos.subList(0, caseDtos.size()-1); mav.setModel(BasicModel.buildOKModel().setResult(caseDtos)); @@ -6577,14 +6608,252 @@ public class PropertyController { houseAround = houseService.findArroundHouseByParams("rent", lng, lat, Integer.parseInt(startDate), Integer.parseInt(endDate), model.getMinPrice(), model.getMaxPrice(), estateType, pager, model.getRadius()); } if(houseAround != null && houseAround.size()>0){ - caseDtos = createHouseCase(caseDtos, houseAround, model.getShowSource()); + caseDtos = createHouseCase(caseDtos, houseAround, model.getShowSource(), ratio); } } if(caseDtos.size()>pager.getPageSize()){ caseDtos = caseDtos.subList(0, caseDtos.size()-1); } mav.setModel(BasicModel.buildOKModel().setResult(caseDtos)); - if(caseDtos.size()<5){ + if(caseDtos!=null && caseDtos.size()<5){ + BasicModel.markNoDataRequest(); + } + return mav; + } + + /** + * 湖北征信定制接口 + * @param model + * @param request + * @return + */ + public Object rentSampleAction(PropertyEvaluationModel model, HttpServletRequest request){ + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + + if (StringUtils.isBlank(model.getCity())) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市为必填项")); + return mav; + } + + if (StringUtils.isBlank(model.getName()) && StringUtils.isBlank(model.getAddress()) ) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:名称或地址至少填一个")); + return mav; + } + + District district = null; + 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(StringUtils.isNotBlank(model.getDistrict()) && StringUtils.isNotBlank(model.getName())){ + district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(),"district"); + } + + 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 && StringUtils.isBlank(model.getLocation())){ + mav.setModel(BasicModel.buildOKModel().setResult(null)); + return mav; + } + + + List caseDtos = new ArrayList(); + + Pager pager = new Pager(); + pager.setStartRow(0); + if (model.getPageSize() != null) { + if(model.getPageSize() <=50){ + pager.setPageSize(model.getPageSize()); + }else{ + pager.setPageSize(50); + } + } else { + pager.setPageSize(30); + } + Double ratio = getUserPriceRatio(request); + Double minPrice = null; + Double maxPrice = null; + Double avgPrice = null; + if(district != null){ + if(model.getMinPrice() == null){ + SqmetreRent rent = sqmetreRentService.findNearestSqmetreRent(district.getCity(), district.getRegion(), district.getName(), "district"); + + if(rent != null) { + avgPrice = Double.valueOf(DataUtil.getRound(2, rent.getAvgPrice().intValue()/30)); + if(ratio!=null){ + avgPrice = avgPrice * ratio; + } + minPrice = avgPrice - avgPrice * 0.1; + maxPrice = avgPrice + avgPrice * 0.1; + } + }else{ + if(model.getMinPrice() != null){ + minPrice = Double.valueOf(model.getMinPrice()); + } + if(model.getMaxPrice() != null){ + maxPrice = Double.valueOf(model.getMaxPrice()); + } + } + + if(caseDtos.size() < pager.getPageSize()){ + List houseSelf = dealSampleService.querySampleByLocation(district.getCity(),district.getLng()/10000000000.0, district.getLat()/10000000000.0, minPrice, maxPrice, "rent", pager.getPageSize()); + if(houseSelf!=null && houseSelf.size()>0){ + caseDtos = createHouseSample(caseDtos, houseSelf, model.getShowSource(), ratio, district.getLng()/10000000000.0, district.getLat()/10000000000.0, avgPrice); + } + } + } + + if(caseDtos!=null && caseDtos.size()>5){ + caseDtos = caseDtos.subList(0,5); + } + mav.setModel(BasicModel.buildOKModel().setResult(caseDtos)); + if(caseDtos!=null && caseDtos.size()<5){ + BasicModel.markNoDataRequest(); + } + return mav; + } + + + + /** + * 湖北征信定制接口 + * @param model + * @param request + * @return + */ + public Object sellSampleAction(PropertyEvaluationModel model, HttpServletRequest request){ + RestfulModelAndView mav = new RestfulModelAndView(); + mav.setViewType("rest"); + + if (StringUtils.isBlank(model.getCity())) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:城市为必填项")); + return mav; + } + + if (StringUtils.isBlank(model.getName()) && StringUtils.isBlank(model.getAddress()) ) { + mav.setModel(BasicModel.buildBadRequestModel("参数非法:名称或地址至少填一个")); + return mav; + } + + District district = null; + 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(StringUtils.isNotBlank(model.getDistrict()) && StringUtils.isNotBlank(model.getName())){ + district = districtService.findByNameAndAlias(model.getCity(), model.getDistrict(), model.getName(),"district"); + } + + 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 && StringUtils.isBlank(model.getLocation())){ + mav.setModel(BasicModel.buildOKModel().setResult(null)); + return mav; + } + + + List caseDtos = new ArrayList(); + + Pager pager = new Pager(); + pager.setStartRow(0); + if (model.getPageSize() != null) { + if(model.getPageSize() <=50){ + pager.setPageSize(model.getPageSize()); + }else{ + pager.setPageSize(50); + } + } else { + pager.setPageSize(30); + } + Double ratio = getUserPriceRatio(request); + Integer minPrice = null; + Integer maxPrice = null; + Double avgPrice = null; + if(district != null){ + if(model.getMinPrice() == null){ + DistrictStatBo statBo = districtStatService.findCurrentDistrictStat(new DistrictKey(district.getCity(), district.getRegion(), district.getName())); + if(statBo != null) { + + if(StringUtils.isNotBlank(district.getEstateType2()) && district.getEstateType2().equals("别墅")){ + avgPrice = Double.valueOf(statBo.getVillaDistrictStat().getAvg_price_2b()); + }else{ + avgPrice = Double.valueOf(statBo.getDistrictStat().getAvg_price_2b()); + } + if(ratio != null){ + avgPrice = avgPrice * ratio; + } + minPrice = (int)(avgPrice - avgPrice * 0.1); + maxPrice = (int)(avgPrice + avgPrice * 0.1); + } + }else{ + if(model.getMinPrice() != null){ + minPrice = model.getMinPrice(); + } + if(model.getMaxPrice() != null){ + maxPrice = model.getMaxPrice(); + } + } + + if(caseDtos.size() < pager.getPageSize()){ + List houseSelf = dealSampleService.querySampleByLocation(district.getCity(), district.getLng()/10000000000.0, district.getLat()/10000000000.0, minPrice, maxPrice, "sell", pager.getPageSize()); + if(houseSelf!=null && houseSelf.size()>0){ + caseDtos = createHouseSample(caseDtos, houseSelf, model.getShowSource(), ratio, district.getLng()/10000000000.0, district.getLat()/10000000000.0, avgPrice); + } + } + } + + if(caseDtos!=null && caseDtos.size()>5){ + caseDtos = caseDtos.subList(0,5); + } + mav.setModel(BasicModel.buildOKModel().setResult(caseDtos)); + if(caseDtos!=null && caseDtos.size()<5){ BasicModel.markNoDataRequest(); } return mav; @@ -6627,8 +6896,94 @@ public class PropertyController { return null; } + private List createHouseSample(List caseDtos, List houses, Integer showSource, Double ratio, Double lng, Double lat,final Double unitPrice){ + if (houses != null && !houses.isEmpty()) { + Set seenIds = new HashSet(); + Iterator iterator = houses.iterator(); + while (iterator.hasNext()) { + DealSample s = iterator.next(); + if (!seenIds.add(s.getId())) { + // 如果已经存在,则从列表中移除 + iterator.remove(); + } + } - private List createHouseCase(List caseDtos, List houses, Integer showSource){ + List ids = new ArrayList(); + for(HouseCaseDto dto : caseDtos){ + ids.add(dto.getId()); + } + for (DealSample house : houses) { + if(!ids.contains(house.getId())){ + HouseCaseDto caseDto = new HouseCaseDto(); + caseDto.setId(house.getId()); + caseDto.setCity(house.getCity()); + caseDto.setDistrict(house.getDistrict()); + caseDto.setName(house.getName()); + caseDto.setSize(house.getSize() == null || house.getSize() == 0 ? null : house.getSize()); + + if(house.getTotalPrice()!=null){ +// if(ratio!=null){ +// Integer totalPrice = new BigDecimal(house.getTotalPrice() * ratio).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(); +// caseDto.setTotalPrice(totalPrice); +// if(house.getCat().equals("sell")){ +// caseDto.setUnitPrice(new BigDecimal(totalPrice/house.getSize()).setScale(0, BigDecimal.ROUND_HALF_UP).intValue()); +// }else if(house.getCat().equals("rent")){ +//// Double dayPrice = house.getTotalPrice()/(30*house.getArea()); +// Double dayPrice = totalPrice/(30*house.getSize()); +// caseDto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); +// } +// }else{ + caseDto.setTotalPrice(house.getTotalPrice() == null || house.getTotalPrice() == 0 ? null : house.getTotalPrice()); + if(house.getCat().equals("sell")){ + caseDto.setUnitPrice(house.getUnitPrice()); + }else if(house.getCat().equals("rent")){ + Double dayPrice = house.getTotalPrice()/(30*house.getSize()); + caseDto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + } +// } + } + caseDto.setDirection(house.getDirection()); + caseDto.setDecoration(house.getDecoration()); + caseDto.setFloor(house.getFloor() == null || house.getFloor() == 0 ? null : house.getFloor()); + caseDto.setMaxFloor(house.getMaxFloor()); + caseDto.setRoom(house.getRoom() == null || house.getRoom() == 0 ? null : house.getRoom().toString()); + caseDto.setHall(house.getHall() == null || house.getHall() == 0 ? null : house.getHall().toString()); + + caseDto.setCaseDate(DateUtil.formatByPattern(house.getCaseDate(),"yyyy-MM-dd")); + + Map locationMap = (Map) house.getLocation(); + double distance = GeoUtils.calculateDistance(locationMap.get("lon"), locationMap.get("lat"), lng, lat); + caseDto.setDistance((int)distance); + if(showSource!=null && showSource==1){ + caseDto.setSource("成交"); + } + caseDtos.add(caseDto); + } + } + if(unitPrice!=null){ + Collections.sort(caseDtos, new Comparator() { + @Override + public int compare(HouseCaseDto dto1, HouseCaseDto dto2) { + double diff1 = Math.abs(dto1.getUnitPrice().doubleValue() - unitPrice); + double diff2 = Math.abs(dto2.getUnitPrice().doubleValue() - unitPrice); + + if (diff1 < diff2) { + return -1; + } else if (diff1 > diff2) { + return 1; + } else { + return 0; + } + } + }); + } + + } + return caseDtos; + } + + + private List createHouseCase(List caseDtos, List houses, Integer showSource, Double ratio){ if (houses != null && !houses.isEmpty()) { Set seenIds = new HashSet(); Iterator iterator = houses.iterator(); @@ -6652,13 +7007,28 @@ public class PropertyController { caseDto.setDistrict(house.getRegion()); caseDto.setName(house.getDistrictName()); caseDto.setSize(house.getArea() == null || house.getArea() == 0 ? null : house.getArea()); - if(house.getCategory().equals("sell")){ - caseDto.setUnitPrice(house.getAvgPrice() == null || house.getAvgPrice() == 0 ? null : house.getAvgPrice()); - }else if(house.getCategory().equals("rent")){ - Double dayPrice = house.getTotalPrice()/(30*house.getArea()); - caseDto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + + if(house.getTotalPrice()!=null){ + if(ratio!=null){ + Integer totalPrice = new BigDecimal(house.getTotalPrice() * ratio).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(); + caseDto.setTotalPrice(totalPrice); + if(house.getCategory().equals("sell")){ + caseDto.setUnitPrice(new BigDecimal(totalPrice/house.getArea()).setScale(0, BigDecimal.ROUND_HALF_UP).intValue()); + }else if(house.getCategory().equals("rent")){ +// Double dayPrice = house.getTotalPrice()/(30*house.getArea()); + Double dayPrice = totalPrice/(30*house.getArea()); + caseDto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + } + }else{ + caseDto.setTotalPrice(house.getTotalPrice() == null || house.getTotalPrice() == 0 ? null : house.getTotalPrice()); + if(house.getCategory().equals("sell")){ + caseDto.setUnitPrice(house.getAvgPrice() == null || house.getAvgPrice() == 0 ? null : house.getAvgPrice()); + }else if(house.getCategory().equals("rent")){ + Double dayPrice = house.getTotalPrice()/(30*house.getArea()); + caseDto.setUnitPrice(DataUtil.getDoubleRound(2, dayPrice)); + } + } } - caseDto.setTotalPrice(house.getTotalPrice() == null || house.getTotalPrice() == 0 ? null : house.getTotalPrice()); caseDto.setDirection(house.getDirection()); caseDto.setDecoration(house.getFitment()); caseDto.setFloor(house.getFloor() == null || house.getFloor() == 0 ? null : house.getFloor()); @@ -6894,4 +7264,8 @@ public class PropertyController { public void setAliasFangService(AliasFangService aliasFangService) { this.aliasFangService = aliasFangService; } + + public void setDealSampleService(DealSampleService dealSampleService) { + this.dealSampleService = dealSampleService; + } } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/dto/BusinessCaseDto.java b/projects/fangjia-open/src/main/java/com/fangjia/open/dto/BusinessCaseDto.java index 246449c3c..b0fd56b1a 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/dto/BusinessCaseDto.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/dto/BusinessCaseDto.java @@ -12,7 +12,7 @@ public class BusinessCaseDto { private Integer totalPrice;//总价(单位:元) private Integer floor;//所在楼层 private String caseDate;//案例时间(如: 2013-07-12) - private String type;//类型 + private String estateType;//类型 public String getId() { return id; @@ -102,11 +102,11 @@ public class BusinessCaseDto { this.caseDate = caseDate; } - public String getType() { - return type; + public String getEstateType() { + return estateType; } - public void setType(String type) { - this.type = type; + public void setEstateType(String estateType) { + this.estateType = estateType; } } diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/model/CommercialModel.java b/projects/fangjia-open/src/main/java/com/fangjia/open/model/CommercialModel.java index a136e8ef0..60da71c02 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/model/CommercialModel.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/model/CommercialModel.java @@ -23,6 +23,10 @@ public class CommercialModel extends FangjiaApiModel{ private Integer showSample;//是否显示样本 1:显示 + + private Integer maxPrice; + private Integer minPrice; + public String getAddress() { return address; } @@ -118,4 +122,20 @@ public class CommercialModel extends FangjiaApiModel{ public void setShowSample(Integer showSample) { this.showSample = showSample; } + + public Integer getMaxPrice() { + return maxPrice; + } + + public void setMaxPrice(Integer maxPrice) { + this.maxPrice = maxPrice; + } + + public Integer getMinPrice() { + return minPrice; + } + + public void setMinPrice(Integer minPrice) { + this.minPrice = minPrice; + } } diff --git a/projects/fangjia-open/src/main/resources/urlrewrite2.0.xml b/projects/fangjia-open/src/main/resources/urlrewrite2.0.xml index 52f11e6e6..26873f5f1 100644 --- a/projects/fangjia-open/src/main/resources/urlrewrite2.0.xml +++ b/projects/fangjia-open/src/main/resources/urlrewrite2.0.xml @@ -61,6 +61,12 @@ + + + /sellSample + + + @@ -75,6 +81,13 @@ + + + /sellSample + + + + /rentEvaluate @@ -87,5 +100,12 @@ + + + + /rentSample + + + \ No newline at end of file diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java index a2d523b7c..a10b567c2 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/OfficeServiceImpl.java @@ -207,7 +207,7 @@ public class OfficeServiceImpl implements OfficeService { sortParams.add(new SortParam("date", false)); // 第二步:基准价*楼层系数*装修系数*朝向系数 - OfficeRentStat officeRentStat = officeRentStatDao.findFirstByParams(params); + OfficeRentStat officeRentStat = officeRentStatDao.findFirstByParams(params, sortParams); // if(officeRentStat == null){ // // 获取上个月yyyyMM日期 // String date = DateUtil.formatByPattern(DateUtil.addMonthToDate(new Date(), -1), "yyyyMM"); diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/mongo/fangjia/DealSampleService.java b/projects/fangjia-service/src/main/java/com/fangjia/service/mongo/fangjia/DealSampleService.java new file mode 100644 index 000000000..a701db466 --- /dev/null +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/mongo/fangjia/DealSampleService.java @@ -0,0 +1,10 @@ +package com.fangjia.service.mongo.fangjia; + +import com.fangjia.dal.mongo.model.bkoff.DealSample; +import scala.math.Numeric; + +import java.util.List; + +public interface DealSampleService { + List querySampleByLocation(String city, Double lng, Double lat, Number minPrice, Number maxPrice, String cat, int pageSize); +} diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/mongo/fangjia/DealSampleServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/mongo/fangjia/DealSampleServiceImpl.java new file mode 100644 index 000000000..1e125a65d --- /dev/null +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/mongo/fangjia/DealSampleServiceImpl.java @@ -0,0 +1,63 @@ +package com.fangjia.service.mongo.fangjia; + +import com.fangjia.core.util.DateUtil; +import com.fangjia.dal.QueryParam; +import com.fangjia.dal.SortParam; +import com.fangjia.dal.mongo.dao.bkoff.DealSampleDao; +import com.fangjia.dal.mongo.model.OfficeRentStat; +import com.fangjia.dal.mongo.model.bkoff.DealSample; +import com.mongodb.BasicDBObject; +import org.apache.commons.lang.StringUtils; +import scala.math.Numeric; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class DealSampleServiceImpl implements DealSampleService{ + + private DealSampleDao dealSampleDao; + + public DealSampleDao getDealSampleDao() { + return dealSampleDao; + } + + public void setDealSampleDao(DealSampleDao dealSampleDao) { + this.dealSampleDao = dealSampleDao; + } + + @Override + public List querySampleByLocation(String city, Double lng, Double lat, Number minPrice, Number maxPrice, String cat, int pageSize) { + if(lng!=null && lat!=null){ + List params = new ArrayList(); + BasicDBObject geo = new BasicDBObject(); + BasicDBObject nearQuery = new BasicDBObject(); +// nearQuery.append("$geometry", new double[]{lng, lat}); + nearQuery.append("$geometry", new BasicDBObject("type", "Point").append("coordinates", new double[]{lng, lat})); + nearQuery.append("$maxDistance", 3000); + geo.append("$near", nearQuery); + + params.add(new QueryParam("city", city)); + params.add(new QueryParam("cat", cat)); + params.add(new QueryParam("location", geo)); + + Date date = DateUtil.truncateDay(DateUtil.addMonthToDate(new Date(), -12)); + params.add(new QueryParam("caseDate", QueryParam.GREATER_THAN_EQUAL_OPERATOR, date)); + + if(minPrice != null){ + params.add(new QueryParam("unitPrice", QueryParam.GREATER_THAN_EQUAL_OPERATOR, minPrice)); + } + if(maxPrice != null){ + params.add(new QueryParam("unitPrice", QueryParam.LESS_THAN_EQUAL_OPERATOR, maxPrice)); + } + + // 按日期降序排序,取最新的数据,可能上月还未更新,则取上上个月的数据 +// List sortParams = new ArrayList(); +// sortParams.add(new SortParam("caseDate", false)); + + List samples = dealSampleDao.findAllByParams(params, pageSize); + return samples; + } + return null; + } +}