From ad046713b50b188d4543ab80d1752f2457ec0378 Mon Sep 17 00:00:00 2001 From: gaojuan Date: Wed, 26 Apr 2023 18:18:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=88=E5=8E=BB=E6=8E=89=E6=9D=83=E9=99=90?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=EF=BC=8C=E6=B1=9F=E5=8D=97=E8=A1=8C=E6=88=BF?= =?UTF-8?q?=E6=BA=90=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open/controllers/HouseController.java | 4 +- .../open/controllers/JnBankController.java | 2 +- .../datastore/CzbankSampleServiceImpl.java | 115 ++++++++++++++++-- 3 files changed, 109 insertions(+), 12 deletions(-) diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/HouseController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/HouseController.java index 1efa12d0f..5f2fddf88 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/HouseController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/HouseController.java @@ -208,7 +208,7 @@ public class HouseController { } - @Authority(role = Role.USER) + @Authority(role = Role.NONE) public Object similarAction(@Valid CollateralSampleQuery collateralSampleQuery){ RestfulModelAndView mav = new RestfulModelAndView(); @@ -253,7 +253,7 @@ public class HouseController { /**商铺相似房源接口*/ - @Authority(role = Role.USER) + @Authority(role = Role.NONE) public Object shopSimilarAction(@Valid ShopCollateralSampleQuery query){ RestfulModelAndView mav = new RestfulModelAndView(); ShopCollateralSampleQueryBean queryBean = new ShopCollateralSampleQueryBean(); diff --git a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/JnBankController.java b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/JnBankController.java index 2c7a22187..998b4664e 100644 --- a/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/JnBankController.java +++ b/projects/fangjia-open/src/main/java/com/fangjia/open/controllers/JnBankController.java @@ -39,7 +39,7 @@ public class JnBankController { private static final Pattern STAGE_PATTERN = Pattern.compile(".*[\\w东南北中西甲乙丙丁一二三四五六七八九十百千\\d]+(期|区)$"); - @Authority(role = Role.USER) + @Authority(role = Role.NONE) public Object searchAction(@Valid JNBankSearchModel model){ RestfulModelAndView mav = new RestfulModelAndView(); diff --git a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/CzbankSampleServiceImpl.java b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/CzbankSampleServiceImpl.java index 604d35021..52cea9435 100644 --- a/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/CzbankSampleServiceImpl.java +++ b/projects/fangjia-service/src/main/java/com/fangjia/service/datastore/CzbankSampleServiceImpl.java @@ -1,9 +1,6 @@ package com.fangjia.service.datastore; -import com.fangjia.core.util.BeanUtils; -import com.fangjia.core.util.DataUtil; -import com.fangjia.core.util.DateUtil; -import com.fangjia.core.util.HouseValidator; +import com.fangjia.core.util.*; import com.fangjia.dal.QueryParam; import com.fangjia.dal.SortParam; import com.fangjia.dal.SrQuery; @@ -51,7 +48,7 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ private static String[] HOUSE_FIELDS = new String[]{"city", "region", "districtName", "totalPrice", "avgPrice", "area", "fitment", "direction", "floor", "height", "publishDate", "address", "estateType"}; - + public static String[] TAGS =new String[]{"独栋", "联排", "叠加", "双拼", "花园面积", "泳池", "别墅", "带花园", "洋房", "叠拼", "独院", "联体", "微墅", "大平墅"}; private DealPriceDao dealPriceDao; private HouseDao houseDao; @@ -191,7 +188,8 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ } List querySamples= new ArrayList(); List samples = findSampleByDistrict(district.getCity(), district.getRegion(), district.getName(), district.getAlias(), district.getMasterDistrictNname(), district.getEstateType2(),queryBean.getPropertyTypeCode(), queryBean.getUpdateDate(), districtStat); - scoreForSample(samples, target); +// scoreForSample(samples, target); + sortForSample(samples, target); for(SampleWrapper sample : samples){ sample.setProperty(queryBean.getProperty()); } @@ -205,7 +203,8 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ for(SampleWrapper sample : nearlySample){ sample.setProperty(d); } - scoreForSample(nearlySample, target); +// scoreForSample(nearlySample, target); + sortForSample(samples, target); querySamples.addAll(nearlySample); if(querySamples.size() > max){ break; @@ -481,6 +480,56 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ return samples; } + + private List sortForSample(List samples, final SampleWrapper targetSample){ + + if(samples.isEmpty()){ + return samples; + } +// if(samples!=null && samples.size() < max){ +// return samples; +// } + Collections.sort(samples, new Comparator() { + public int compare(SampleWrapper o1, SampleWrapper o2) { + Double d1 = Math.abs(o1.getStrctureArea() - targetSample.getStrctureArea()); + Double d2 = Math.abs(o2.getStrctureArea() - targetSample.getStrctureArea()); +// return (int) (d1 - d2); + return d1.compareTo(d2); + } + }); + + List prices = new ArrayList(); + for(SampleWrapper sample : samples){ + if(!prices.contains(sample.getUnitPrice())){ + prices.add(sample.getUnitPrice()); + if(prices.size()>=10){ + break; + } + } + } + final Integer midPrice = (int)median(prices); + Collections.sort(samples, new Comparator() { + public int compare(SampleWrapper o1, SampleWrapper o2) { + Integer d1 = Math.abs(o1.getUnitPrice() - midPrice); + Integer d2 = Math.abs(o2.getUnitPrice() - midPrice); + return d1.compareTo(d2); + } + }); + return samples; + } + + private static double median(List total) { + double j = 0; + Collections.sort(total); + int size = total.size(); + if(size % 2 == 1){ + j = total.get((size-1)/2); + }else { + j = (total.get(size/2-1) + total.get(size/2) + 0.0)/2; + } + return j; + } + /** * 查找小区样本 * @param city @@ -514,8 +563,8 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ houseQuery.add(new QueryParam("region", region )); if(districtStat != null && districtStat.getAvgPrice() > 0){ int avgPrice = districtStat.getAvgPrice(); - houseQuery.add(new QueryParam("avgPrice", QueryParam.GREATER_THAN_EQUAL_OPERATOR, (int)(avgPrice * 0.85 ))); - houseQuery.add(new QueryParam("avgPrice", QueryParam.LESS_THAN_EQUAL_OPERATOR, (int)(avgPrice * 1.15 ))); + houseQuery.add(new QueryParam("avgPrice", QueryParam.GREATER_THAN_EQUAL_OPERATOR, (int)(avgPrice * 0.5 )));//0.85 + houseQuery.add(new QueryParam("avgPrice", QueryParam.LESS_THAN_EQUAL_OPERATOR, (int)(avgPrice * 1.5 )));//1.15 } BooleanQuery nameQuery = new BooleanQuery(); int c = 0; @@ -548,6 +597,21 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ int maxFloor = 0; boolean allSampleHasHeight = true; for(House house : houses){ + if(StringUtils.isNotBlank(estateType) && estateType.equals("01")){//01:普通住宅 02:别墅 + if(StringUtils.isNotBlank(house.getEstateType()) && house.getEstateType().contains("别墅")){ + continue; + } + if(isVilla(house.getArea(), house.getName(), house.getHeight(), house.getRoom())){ + continue; + } + }else if(StringUtils.isNotBlank(estateType) && estateType.equals("02")){ + if(house.getHeight()!=null && house.getHeight()>=10){ + continue; + } + if(house.getFloor()!=null && house.getFloor()>=10){ + continue; + } + } SampleWrapper sample = convertHouse2Sample(house); if(isAvailableSample(sample)){ @@ -859,6 +923,39 @@ public class CzbankSampleServiceImpl implements CzbankSampleService{ return null; } + /** + * 是否是别墅 + * @return + */ + public boolean isVilla(Double area, String name, Integer height, Integer room) { + if (area == null) { + return false; + } + if (area >= 150 && StringUtils.indexOfAny(name, TAGS) > -1) { + return true; + } + + boolean ret = false; + if (height != null && room != null) { + if (height <= 3) { + if (area > 200 && room >= 5) { + ret = true; + } + } + } else if (height == null && room != null) { + if (area > 360 && room >= 6) { + ret = true; + } + } else if (height == null && room == null) { + if (area > 500) { + ret = true; + } + } + + return ret; + } + + public void setDealPriceDao(DealPriceDao dealPriceDao) { this.dealPriceDao = dealPriceDao; }