我正在为租赁公寓的公司创建系统。所有定价设置都基于某些时段。例如,在分类“少年工作室”公寓有价格时期:基于期间的价格计算算法
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个可能的记录,所以动态计算这可能会导致性能问题。
UPDATE
下面是一些代码,以与一个公寓类为一个建设周期:
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,货币,价值 经过这些步骤后,我有一个类别的独特价格列表。然后,我需要计算在这些独特价格周期中每个预订有多少天,然后乘以它,也许是整数+乘以税,然后求和以得到预订的最终价格。现在重新运行这些步骤可以说500次(多个建筑物中的多个类别)。
虽然没有明确说明,我们可以假设每个公寓的周期不重叠,它们的联合覆盖了从负无穷到正无穷的时间跨度? – Codor
@Codor是每个公寓的每个价格期间都是独一无二的。所以对于每一天只有一个有效的价格,但对于整个客户预订有多个可能的价格。 – jgr