【发布时间】:2017-05-30 09:30:22
【问题描述】:
我正在为一家出租公寓的公司创建系统。所有定价设置均基于某些时期。例如,“初级工作室”类别中的公寓有价格周期:
30.05.2016 - 31.01.2017: 3000 EUR
01.02.2017 - Infinity: 4000 EUR
还有其他时期,例如:税费、季节性价格(加/减某个百分比值)以及基于其他时期的费用。所以价格可能经常变化,例如:
31.05.2016 - 30.06.2016 (3500EUR because of some seasonal price period)
01.07-31.08.2016 (5000EUR other seasonal price period)
01.09.2016 - 31.01.2017 (3000 EUR)
01.02.2017 - 4000 EUR.
此外,如果有人想租一套公寓,例如少于 15 天,则需要支付额外费用,比如说 15% - 所有这些都是动态设置的。
现在问题出在我们的页面上,我们应该让用户根据价格找到公寓。例如,一些用户只想找到价格在 3000 到 4000 欧元之间的公寓并租用 6 个月的公寓。正如我所说,价格在这些期间可能会发生 5 次变化,因此我正在计算平均价格。
你知道如何实现这个算法来合并所有指定的时期吗?我们假设可能有 500 条可能的记录,因此动态计算可能会导致性能问题。
更新
下面是一些代码,用于获取与一栋建筑物的一种公寓类别相关的时间段:
private RentPriceAggregatedPeriodsDto prepareRentPriceAggregator(Long buildingId, Long categoryId, LocalDate dateFrom, LocalDate dateTo, Integer duration) {
List<CategoryPricePeriod> pricePeriods = categoryPricePeriodRepository.findCategoryPricePeriods(buildingId, categoryId, dateFrom, dateTo);
List<SeasonalPricePeriod> seasonalPricePeriods = seasonalPricePeriodRepository.findSeasonalPricePeriods(buildingId, categoryId, dateFrom, dateTo);
List<LastMinuteRatePeriod> lastMinuteRatePeriods = lastMinuteRatePeriodRepository.findLastMinuteRatePeriods(buildingId, categoryId, dateFrom, dateTo);
List<TaxesDefinitionPeriodDto> taxesDefinition = taxesDefinitionService.findTaxPeriodsForBuildingAndCategory(buildingId, categoryId, TaxTypeCode.VAT,
dateFrom, dateTo);
Optional<SurchargePolicy> surcharge = surchargePolicyRepository.findForDurationAndRentalObjectCategoryIds(categoryId, buildingId, duration);
return new RentPriceAggregatedPeriodsDto(pricePeriods, seasonalPricePeriods, lastMinuteRatePeriods, taxesDefinition, surcharge);
}
根据所有这些时期,我准备了独特的价格时期列表:dateFrom, dateTo, currency, value。在这些步骤之后,我有一个类别的唯一价格列表。然后我需要计算每个唯一价格期间的预订天数并将其相乘,可能是四舍五入 + 乘以税款,然后将其相加得出最终的预订价格。现在重新运行这些步骤,比如说,500 次(多个建筑物中的多个类别)。
【问题讨论】:
-
虽然没有明确说明,但我们可以假设每个公寓的时期不重叠,并且它们的并集涵盖了从负无穷到正无穷的时间跨度吗?
-
@Codor 是的,每间公寓的每个价格周期都是独一无二的。因此,每天只有一个有效价格,但对于整个客户的预订,则有多个可能的价格。
标签: algorithm