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 190a1eea4..96ac55875 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 @@ -122,9 +122,9 @@ public class CommercialController { if (json.containsKey("msg") && "³É¹¦".equals(json.getString("msg"))) { if (json.containsKey("unitPrice") && json.containsKey("location")) { - + Integer unitPrice = null; if(json.get("unitPrice") != null){ - int unitPrice = (Integer) json.get("unitPrice"); + unitPrice = (Integer) json.get("unitPrice"); int minPrice = (int) (unitPrice - unitPrice * 0.1); model.setMinPrice(minPrice); @@ -142,7 +142,7 @@ public class CommercialController { Double lng = locObj.getDouble("lon"); Double lat = locObj.getDouble("lat"); List houseSelf = dealSampleService.querySampleByLocation(lng, lat, model.getMinPrice(), model.getMaxPrice(), "shop_sell", 5); - List dtos = createSample(houseSelf, "sell", ratio, lng, lat); + List dtos = createSample(houseSelf, "sell", ratio, lng, lat, unitPrice.doubleValue()); mav.setModel(BasicModel.buildOKModel().setResult(dtos)); if(dtos!=null && dtos.size()<5){ BasicModel.markNoDataRequest(); @@ -269,7 +269,7 @@ public class CommercialController { } - private List createSample(List cases, String cat, Double ratio, Double lng, Double lat){ + 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){ @@ -315,6 +315,24 @@ public class CommercialController { 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; @@ -373,8 +391,9 @@ public class CommercialController { Double minPrice = null; Double maxPrice = null; + Double unitPrice = null; if(json.get("unitPrice") != null){ - Double unitPrice = (Double) json.get("unitPrice"); + unitPrice = (Double) json.get("unitPrice"); minPrice = unitPrice - unitPrice * 0.1; maxPrice = unitPrice + unitPrice * 0.1; @@ -389,10 +408,12 @@ public class CommercialController { JSONObject locObj = json.getJSONObject("location"); Double lng = locObj.getDouble("lon"); Double lat = locObj.getDouble("lat"); - List houseSelf = dealSampleService.querySampleByLocation(lng, lat, DataUtil.getDoubleRound(2, minPrice), DataUtil.getDoubleRound(2, maxPrice), "shop_rent", 5); - List dtos = createSample(houseSelf, "rent", ratio, lng, lat); - + List houseSelf = dealSampleService.querySampleByLocation(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();