出租增加排序

This commit is contained in:
2026-01-29 16:45:35 +08:00
parent 593a29d36e
commit 5e4b2e20da
@@ -122,9 +122,9 @@ public class CommercialController {
if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) { if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) {
if (json.containsKey("unitPrice") && json.containsKey("location")) { if (json.containsKey("unitPrice") && json.containsKey("location")) {
Integer unitPrice = null;
if(json.get("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); int minPrice = (int) (unitPrice - unitPrice * 0.1);
model.setMinPrice(minPrice); model.setMinPrice(minPrice);
@@ -142,7 +142,7 @@ public class CommercialController {
Double lng = locObj.getDouble("lon"); Double lng = locObj.getDouble("lon");
Double lat = locObj.getDouble("lat"); Double lat = locObj.getDouble("lat");
List<DealSample> houseSelf = dealSampleService.querySampleByLocation(lng, lat, model.getMinPrice(), model.getMaxPrice(), "shop_sell", 5); List<DealSample> houseSelf = dealSampleService.querySampleByLocation(lng, lat, model.getMinPrice(), model.getMaxPrice(), "shop_sell", 5);
List<BusinessCaseDto> dtos = createSample(houseSelf, "sell", ratio, lng, lat); List<BusinessCaseDto> dtos = createSample(houseSelf, "sell", ratio, lng, lat, unitPrice.doubleValue());
mav.setModel(BasicModel.buildOKModel().setResult(dtos)); mav.setModel(BasicModel.buildOKModel().setResult(dtos));
if(dtos!=null && dtos.size()<5){ if(dtos!=null && dtos.size()<5){
BasicModel.markNoDataRequest(); BasicModel.markNoDataRequest();
@@ -269,7 +269,7 @@ public class CommercialController {
} }
private List<BusinessCaseDto> createSample(List<DealSample> cases, String cat, Double ratio, Double lng, Double lat){ private List<BusinessCaseDto> createSample(List<DealSample> cases, String cat, Double ratio, Double lng, Double lat, final Double unitPrice){
if(cases != null && cases.size()>0){ if(cases != null && cases.size()>0){
List<BusinessCaseDto> dtos = new ArrayList<BusinessCaseDto>(); List<BusinessCaseDto> dtos = new ArrayList<BusinessCaseDto>();
for(DealSample sample : cases){ for(DealSample sample : cases){
@@ -315,6 +315,24 @@ public class CommercialController {
dtos.add(dto); dtos.add(dto);
} }
if(unitPrice!=null){
Collections.sort(dtos, new Comparator<BusinessCaseDto>() {
@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 dtos;
} }
return null; return null;
@@ -373,8 +391,9 @@ public class CommercialController {
Double minPrice = null; Double minPrice = null;
Double maxPrice = null; Double maxPrice = null;
Double unitPrice = null;
if(json.get("unitPrice") != null){ if(json.get("unitPrice") != null){
Double unitPrice = (Double) json.get("unitPrice"); unitPrice = (Double) json.get("unitPrice");
minPrice = unitPrice - unitPrice * 0.1; minPrice = unitPrice - unitPrice * 0.1;
maxPrice = unitPrice + unitPrice * 0.1; maxPrice = unitPrice + unitPrice * 0.1;
@@ -389,10 +408,12 @@ public class CommercialController {
JSONObject locObj = json.getJSONObject("location"); JSONObject locObj = json.getJSONObject("location");
Double lng = locObj.getDouble("lon"); Double lng = locObj.getDouble("lon");
Double lat = locObj.getDouble("lat"); Double lat = locObj.getDouble("lat");
List<DealSample> houseSelf = dealSampleService.querySampleByLocation(lng, lat, DataUtil.getDoubleRound(2, minPrice), DataUtil.getDoubleRound(2, maxPrice), "shop_rent", 5); List<DealSample> houseSelf = dealSampleService.querySampleByLocation(lng, lat, DataUtil.getDoubleRound(2, minPrice), DataUtil.getDoubleRound(2, maxPrice), "shop_rent", 30);
List<BusinessCaseDto> dtos = createSample(houseSelf, "rent", ratio, lng, lat); List<BusinessCaseDto> 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)); mav.setModel(BasicModel.buildOKModel().setResult(dtos));
if(dtos!=null && dtos.size()<5){ if(dtos!=null && dtos.size()<5){
BasicModel.markNoDataRequest(); BasicModel.markNoDataRequest();