新增商铺相关接口

This commit is contained in:
沈健
2025-04-14 16:05:41 +08:00
parent bc13222a54
commit 1c61cc3b76
3 changed files with 648 additions and 41 deletions
@@ -17,7 +17,6 @@ import com.fangjia.service.datastore.dto.ShopEvaluationDto;
import com.fangjia.service.mongo.fangjia.SeawaterService;
import com.fangjia.service.util.GeoUtils;
import com.fangjia.service.util.dto.GaodeDto;
import com.mongodb.BasicDBObject;
import org.apache.commons.collections.CollectionUtils;
import org.sothis.core.util.Closure;
import org.sothis.core.util.Pager;
@@ -322,8 +321,13 @@ public class AiShopServiceImpl implements AiShopService {
}
@Override
public List<ShopSellStat> findShopSellStat(String city, String region, String name, String cat, Integer startDate, Integer endDate) {
return Collections.emptyList();
public List<ShopSellStat> findShopSellStat(final String city, final String region, final String name, final String cat, final Integer startDate, final Integer endDate) {
return CacheUtils.getValue(this.getClass(), "findShopRentStat", city + region + name + startDate + endDate,
CacheUtils.CachePolicyEnum.MIDDLE, new Closure<List<ShopSellStat>, String>() {
public List<ShopSellStat> execute(String input) {
return doFindShopSellStat(city, region, name, cat, startDate, endDate);
}
});
}
private ShopEvaluationDto rentEvaluateByLocation(Evaluation evaluation) {
@@ -382,40 +386,28 @@ public class AiShopServiceImpl implements AiShopService {
shopEvaluationDto.setLocation(evaluation.getLocation());
Double lng = Double.valueOf(evaluation.getLocation().split(",")[0]);
Double lat = Double.valueOf(evaluation.getLocation().split(",")[1]);
// 查询附近5个写字楼基准价
BasicDBObject geo = new BasicDBObject();
BasicDBObject nearQuery = new BasicDBObject();
nearQuery.append("$geometry", new BasicDBObject("type", "Point").append("coordinates", new double[]{lng, lat}));
nearQuery.append("$maxDistance", 3000);
geo.append("$near", nearQuery);
List<QueryParam> params = new ArrayList<QueryParam>(5);
params.add(new QueryParam("cat", "shop"));
params.add(new QueryParam("location", geo));
String date = DateUtil.formatByPattern(DateUtil.addMonthToDate(new Date(), -2), "yyyyMM");
params.add(new QueryParam("date", Integer.parseInt(date)));
// 按日期降序排序,取最新的数据,可能上月还未更新,则取上上个月的数据
List<SortParam> sortParams = new ArrayList<SortParam>();
sortParams.add(new SortParam("date", false));
List<ShopSellStat> infos = shopSellStatDao.findAllByParams(params, sortParams, 5);
if (CollectionUtils.isEmpty(infos)) {
// 去掉类型,重新查找
params = new ArrayList<QueryParam>(5);
params.add(new QueryParam("cat", "shop"));
params.add(new QueryParam("location", geo));
params.add(new QueryParam("date", Integer.parseInt(date)));
infos = shopSellStatDao.findAllByParams(params, sortParams);
}
if (CollectionUtils.isNotEmpty(infos)) {
SeawaterQuery query = new SeawaterQuery();
query.setLat(lat);
query.setLng(lng);
query.setCat("shop_sell");
query.setRadius(1000);
// 查询近一年样本
query.setStartDate(Integer.parseInt(DateUtil.formatByPattern(DateUtil.addMonthToDate(new Date(), -12), "yyyyMMdd")));
query.setEndDate(Integer.parseInt(DateUtil.formatByPattern(new Date(), "yyyyMMdd")));
query.setCityDisplay(evaluation.getCity());
Pager pager = new Pager();
pager.setStartRow(0);
pager.setPageSize(5);
query.setPager(pager);
query.setTable("latest_seawater");
List<Seawater> shops = seawaterService.findSeawatersByQuery(query);
if (CollectionUtils.isNotEmpty(shops)) {
// 求均值
Double totalPrice = 0D;
int count = 0;
for (ShopSellStat shopSellStat : infos) {
if (shopSellStat.getAvgPrice() != null) {
totalPrice += shopSellStat.getAvgPrice();
for (Seawater seawater : shops) {
if (seawater.getAvgPrice() != null) {
totalPrice += seawater.getAvgPrice();
count += 1;
}
}
@@ -426,8 +418,9 @@ public class AiShopServiceImpl implements AiShopService {
if (evaluation.getDirection() != null) {
factor *= DIRECTION_FACTOR.get(DIRECTION_MAP.get(evaluation.getDirection()));
}
Double avgPrice = DataUtil.roundDouble(totalPrice / count * factor, 2);
shopEvaluationDto.setUnitPrice(avgPrice);
int avgPrice = (int) (totalPrice / count * factor);
shopEvaluationDto.setUnitPrice((double) avgPrice);
shopEvaluationDto.setSeawater(shops);
shopEvaluationDto.setCity(evaluation.getCity());
shopEvaluationDto.setDistrict(evaluation.getRegion());
shopEvaluationDto.setName(evaluation.getDistrictName());
@@ -454,12 +447,12 @@ public class AiShopServiceImpl implements AiShopService {
return CacheUtils.getValue(this.getClass(), "findShopRentStat", city + region + name + startDate + endDate,
CacheUtils.CachePolicyEnum.MIDDLE, new Closure<List<ShopRentStat>, String>() {
public List<ShopRentStat> execute(String input) {
return doFindRegionBlockStat(city, region, name, cat, startDate, endDate);
return doFindShopRentStat(city, region, name, cat, startDate, endDate);
}
});
}
public List<ShopRentStat> doFindRegionBlockStat(final String city, final String region, final String name, final String cat, Integer startDate, Integer endDate) {
public List<ShopRentStat> doFindShopRentStat(final String city, final String region, final String name, final String cat, Integer startDate, Integer endDate) {
if (startDate == null) {
throw new IllegalArgumentException("开始日期不能为空");
}