6

我们有一个计费系统,我们可以在其中处理个人费用以及经常性费用(订阅)。

有两个 SQL 表:

StandardCharges
RecurringCharges

StandardCharges 表包含客户在当月购买的各个项目。

RecurringCharges 表包含按日期收费的经常性项目。当时间到来时,我们的系统会自动创建一个重复请求,该请求会在 StandardCharges 表中添加一行,并在 RecurringCharges 表中按日期将费用增加到下个月。

在每个月底,我们从 StandardCharges 表中获取每个客户的总值并创建发票。

是否有一种设计模式或另一种方式来做到这一点?这是正确的数据库设计吗?理想情况下,我想将所有费用保存在一张Charges表中并从那里管理经常性费用?

谢谢

4

2 回答 2

2

我怀疑你的设计确实是正确的。

在考虑现实世界中的数据时,将“可能的”交易(即尚未发生且可能无法实现的交易,可能是因为客户已超出其信用额度)与已承诺交易和实际交易混在一起是没有意义的.

将数据合并到单个表中也会使报告变得困难,因为您必须应用特殊的过滤条件并存储额外的元数据 - 例如 TransactionCompleted 和 TransactionIsFutureCharge。

如果我要提出一个建议,它会将 重命名StandardCharges为更接近它所拥有的数据CompletedTransactions的名称,RecurringTransactions例如PendingTransactions.

于 2012-07-20T08:05:07.467 回答
0

The current design seems reasonable to me. But if you want to merge the two tables, you could simply add a BIT column called IsRecurring or IsFuture or IsScheduled or whatever you want to use to designate the charges that would have otherwise gone in RecurringCharges. Then when your due date is hit for a recurring charge, you just insert into the same table instead of a different table. As for the invoice, you'd just add a condition to the query to filter out the charges that have the BIT column set.

于 2012-07-19T21:44:22.870 回答