出租增加排序

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("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<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));
if(dtos!=null && dtos.size()<5){
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){
List<BusinessCaseDto> dtos = new ArrayList<BusinessCaseDto>();
for(DealSample sample : cases){
@@ -315,6 +315,24 @@ public class CommercialController {
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 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<DealSample> houseSelf = dealSampleService.querySampleByLocation(lng, lat, DataUtil.getDoubleRound(2, minPrice), DataUtil.getDoubleRound(2, maxPrice), "shop_rent", 5);
List<BusinessCaseDto> dtos = createSample(houseSelf, "rent", ratio, lng, lat);
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, 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();