优化商铺返回与写字楼一致

This commit is contained in:
沈健
2025-04-16 14:36:46 +08:00
parent c666be742e
commit e78f569e88
2 changed files with 44 additions and 55 deletions
@@ -13,6 +13,7 @@ import com.fangjia.dal.mongo.model.Evaluation;
import com.fangjia.dal.mongo.model.ShopRentStat; import com.fangjia.dal.mongo.model.ShopRentStat;
import com.fangjia.dal.mongo.model.ShopSellStat; import com.fangjia.dal.mongo.model.ShopSellStat;
import com.fangjia.dal.seawater.model.Seawater; import com.fangjia.dal.seawater.model.Seawater;
import com.fangjia.dal.seawater.model.SeawaterDto;
import com.fangjia.service.datastore.dto.ShopEvaluationDto; import com.fangjia.service.datastore.dto.ShopEvaluationDto;
import com.fangjia.service.mongo.fangjia.SeawaterService; import com.fangjia.service.mongo.fangjia.SeawaterService;
import com.fangjia.service.util.GeoUtils; import com.fangjia.service.util.GeoUtils;
@@ -204,53 +205,23 @@ public class AiShopServiceImpl implements AiShopService {
return getShopEvaluationDto(seawaters, evaluation, cat); return getShopEvaluationDto(seawaters, evaluation, cat);
} }
/** private static SeawaterDto getSeawaterDto(Seawater seawater, String cat) {
* 基准价*楼层系数*装修系数*朝向系数 SeawaterDto seawaterDto = new SeawaterDto();
* seawaterDto.setCity(seawater.getCity());
* @param seawaters seawaterDto.setDistrict(seawater.getRegion());
* @param evaluation seawaterDto.setName(seawater.getDistrictName());
* @return seawaterDto.setArea(seawater.getArea());
*/ seawaterDto.setFitment(seawater.getFitment());
private static ShopEvaluationDto getShopEvaluationDtoWithFactor(List<Seawater> seawaters, Evaluation evaluation) { if (cat != null && cat.contains("rent")) {
Double sum = 0.0; seawaterDto.setUnitPrice(seawater.getDayUnitPrice());
Double size = 0.0; } else {
seawaterDto.setUnitPrice(seawater.getAvgPrice().doubleValue());
String fitment = FITMENT_MAP.get(evaluation.getFitment());
String direction = DIRECTION_MAP.get(evaluation.getDirection());
for (Seawater seawater : seawaters) {
if (seawater.getTotalPrice() != null && seawater.getArea() != null && seawater.getTotalPrice() / seawater.getArea() / 30 > 0 && seawater.getTotalPrice() / seawater.getArea() / 30 < 30) {
Double price = Double.valueOf(seawater.getTotalPrice());
// 装修
if (seawater.getFitment() != null) {
try {
price = price / FITMENT_FACTOR.get(seawater.getFitment()) * FITMENT_FACTOR.get(fitment);
} catch (Exception ex) {
}
}
// 朝向
if (seawater.getDirection() != null) {
try {
price = price / DIRECTION_FACTOR.get(seawater.getDirection()) * DIRECTION_FACTOR.get(direction);
} catch (Exception ex) {
}
}
sum += price;
size += seawater.getArea();
}
} }
ShopEvaluationDto shopEvaluationDto = new ShopEvaluationDto(); seawaterDto.setEstateType(seawater.getEstateType());
if (size > 0) { seawaterDto.setBedKind(seawater.getLevel());
Double unitPrice = DataUtil.roundDouble(sum / size / 30, 2); seawaterDto.setPublishDate(String.valueOf(seawater.getpDate()));
shopEvaluationDto.setUnitPrice(unitPrice); seawaterDto.setFloorInfo(seawater.getFloorInfo());
shopEvaluationDto.setSeawater(seawaters); return seawaterDto;
shopEvaluationDto.setCity(evaluation.getCity());
shopEvaluationDto.setDistrict(evaluation.getRegion());
shopEvaluationDto.setName(evaluation.getDistrictName());
}
return shopEvaluationDto;
} }
/** /**
@@ -266,17 +237,20 @@ public class AiShopServiceImpl implements AiShopService {
ShopEvaluationDto shopEvaluationDto = new ShopEvaluationDto(); ShopEvaluationDto shopEvaluationDto = new ShopEvaluationDto();
List<SeawaterDto> seawaterList = new ArrayList<SeawaterDto>();
if ("shop_rent".equals(cat)) { if ("shop_rent".equals(cat)) {
for (Seawater seawater : seawaters) { for (Seawater seawater : seawaters) {
if (seawater.getTotalPrice() != null && seawater.getArea() != null && seawater.getTotalPrice() / seawater.getArea() / 30 > 0 && seawater.getTotalPrice() / seawater.getArea() / 30 < 30) { if (seawater.getTotalPrice() != null && seawater.getArea() != null && seawater.getTotalPrice() / seawater.getArea() / 30 > 0 && seawater.getTotalPrice() / seawater.getArea() / 30 < 30) {
sum += seawater.getTotalPrice(); sum += seawater.getTotalPrice();
size += seawater.getArea(); size += seawater.getArea();
} }
SeawaterDto seawaterDto = getSeawaterDto(seawater, cat);
seawaterList.add(seawaterDto);
} }
if (size > 0) { if (size > 0) {
Double unitPrice = DataUtil.roundDouble(sum / size / 30, 2); Double unitPrice = DataUtil.roundDouble(sum / size / 30, 2);
shopEvaluationDto.setUnitPrice(unitPrice); shopEvaluationDto.setUnitPrice(unitPrice);
shopEvaluationDto.setSeawater(seawaters); shopEvaluationDto.setSeawater(seawaterList);
shopEvaluationDto.setCity(evaluation.getCity()); shopEvaluationDto.setCity(evaluation.getCity());
shopEvaluationDto.setDistrict(evaluation.getRegion()); shopEvaluationDto.setDistrict(evaluation.getRegion());
shopEvaluationDto.setName(evaluation.getDistrictName()); shopEvaluationDto.setName(evaluation.getDistrictName());
@@ -287,11 +261,13 @@ public class AiShopServiceImpl implements AiShopService {
sum += seawater.getTotalPrice(); sum += seawater.getTotalPrice();
size += seawater.getArea(); size += seawater.getArea();
} }
SeawaterDto seawaterDto = getSeawaterDto(seawater, cat);
seawaterList.add(seawaterDto);
} }
if (size > 0) { if (size > 0) {
Double unitPrice = DataUtil.roundDouble(sum / size, 2); Double unitPrice = DataUtil.roundDouble(sum / size, 2);
shopEvaluationDto.setUnitPrice(unitPrice); shopEvaluationDto.setUnitPrice(unitPrice);
shopEvaluationDto.setSeawater(seawaters); shopEvaluationDto.setSeawater(seawaterList);
shopEvaluationDto.setCity(evaluation.getCity()); shopEvaluationDto.setCity(evaluation.getCity());
shopEvaluationDto.setDistrict(evaluation.getRegion()); shopEvaluationDto.setDistrict(evaluation.getRegion());
shopEvaluationDto.setName(evaluation.getDistrictName()); shopEvaluationDto.setName(evaluation.getDistrictName());
@@ -351,15 +327,24 @@ public class AiShopServiceImpl implements AiShopService {
query.setPager(pager); query.setPager(pager);
query.setTable("latest_seawater"); query.setTable("latest_seawater");
List<Seawater> shops = seawaterService.findSeawatersByQuery(query); List<Seawater> shops = seawaterService.findSeawatersByQuery(query);
List<SeawaterDto> seawaterDtoList = new ArrayList<SeawaterDto>();
if (CollectionUtils.isNotEmpty(shops)) { if (CollectionUtils.isNotEmpty(shops)) {
// 求均值 // 求均值
Double totalPrice = 0D; Double totalPrice = 0D;
int count = 0; int count = 0;
for (Seawater seawater : shops) { for (Seawater seawater : shops) {
if (seawater.getAvgPrice() != null) { if (seawater.getAvgPrice() != null) {
totalPrice += seawater.getAvgPrice(); totalPrice += seawater.getDayUnitPrice();
count += 1; count += 1;
} }
SeawaterDto seawaterDto = new SeawaterDto();
seawaterDto.setCity(seawater.getCity());
seawaterDto.setDistrict(seawater.getDistrict());
seawaterDto.setName(seawater.getName());
seawaterDto.setUnitPrice(seawater.getDayUnitPrice());
seawaterDto.setPublishDate(String.valueOf(seawater.getPublishDate()));
seawaterDto.setEstateType(seawater.getEstateType());
seawaterDtoList.add(seawaterDto);
} }
Double factor = 1.0; Double factor = 1.0;
if (evaluation.getFitment() != null) { if (evaluation.getFitment() != null) {
@@ -370,7 +355,7 @@ public class AiShopServiceImpl implements AiShopService {
} }
Double avgPrice = DataUtil.roundDouble(totalPrice / count * factor, 2); Double avgPrice = DataUtil.roundDouble(totalPrice / count * factor, 2);
shopEvaluationDto.setUnitPrice(avgPrice); shopEvaluationDto.setUnitPrice(avgPrice);
shopEvaluationDto.setSeawater(shops); shopEvaluationDto.setSeawater(seawaterDtoList);
shopEvaluationDto.setCity(evaluation.getCity()); shopEvaluationDto.setCity(evaluation.getCity());
shopEvaluationDto.setDistrict(evaluation.getRegion()); shopEvaluationDto.setDistrict(evaluation.getRegion());
shopEvaluationDto.setName(evaluation.getDistrictName()); shopEvaluationDto.setName(evaluation.getDistrictName());
@@ -401,6 +386,8 @@ public class AiShopServiceImpl implements AiShopService {
query.setPager(pager); query.setPager(pager);
query.setTable("latest_seawater"); query.setTable("latest_seawater");
List<Seawater> shops = seawaterService.findSeawatersByQuery(query); List<Seawater> shops = seawaterService.findSeawatersByQuery(query);
List<SeawaterDto> seawaterDtoList = new ArrayList<SeawaterDto>();
if (CollectionUtils.isNotEmpty(shops)) { if (CollectionUtils.isNotEmpty(shops)) {
// 求均值 // 求均值
Double totalPrice = 0D; Double totalPrice = 0D;
@@ -410,6 +397,8 @@ public class AiShopServiceImpl implements AiShopService {
totalPrice += seawater.getAvgPrice(); totalPrice += seawater.getAvgPrice();
count += 1; count += 1;
} }
SeawaterDto seawaterDto = getSeawaterDto(seawater, "shop_sell");
seawaterDtoList.add(seawaterDto);
} }
Double factor = 1.0; Double factor = 1.0;
if (evaluation.getFitment() != null) { if (evaluation.getFitment() != null) {
@@ -420,7 +409,7 @@ public class AiShopServiceImpl implements AiShopService {
} }
int avgPrice = (int) (totalPrice / count * factor); int avgPrice = (int) (totalPrice / count * factor);
shopEvaluationDto.setUnitPrice((double) avgPrice); shopEvaluationDto.setUnitPrice((double) avgPrice);
shopEvaluationDto.setSeawater(shops); shopEvaluationDto.setSeawater(seawaterDtoList);
shopEvaluationDto.setCity(evaluation.getCity()); shopEvaluationDto.setCity(evaluation.getCity());
shopEvaluationDto.setDistrict(evaluation.getRegion()); shopEvaluationDto.setDistrict(evaluation.getRegion());
shopEvaluationDto.setName(evaluation.getDistrictName()); shopEvaluationDto.setName(evaluation.getDistrictName());
@@ -1,7 +1,7 @@
package com.fangjia.service.datastore.dto; package com.fangjia.service.datastore.dto;
import com.fangjia.dal.mongo.model.Evaluation; import com.fangjia.dal.mongo.model.Evaluation;
import com.fangjia.dal.seawater.model.Seawater; import com.fangjia.dal.seawater.model.SeawaterDto;
import java.util.List; import java.util.List;
@@ -13,7 +13,7 @@ public class ShopEvaluationDto extends Evaluation {
private Double unitPrice; private Double unitPrice;
private List<Seawater> seawater; private List<SeawaterDto> seawater;
private String district; private String district;
@@ -28,11 +28,11 @@ public class ShopEvaluationDto extends Evaluation {
this.unitPrice = unitPrice; this.unitPrice = unitPrice;
} }
public List<Seawater> getSeawater() { public List<SeawaterDto> getSeawater() {
return seawater; return seawater;
} }
public void setSeawater(List<Seawater> seawater) { public void setSeawater(List<SeawaterDto> seawater) {
this.seawater = seawater; this.seawater = seawater;
} }