如何维持轮循机制 [英] How to maintain a round robin approach
问题描述
我的数据库中存储了许多贷方.我应该说,借贷方的数量很少,因此我可以轻松地缓存数据,而不必进行查找.
I have a number of lenders stored in my database. I should say that there are only a small number of lenders so I can cache the data easily, without having to do lookups.
但是,当客户申请贷款时,我想按逻辑顺序每次都在不同的贷方上进行第一次查找.例如:
However, when a customer applies for a loan, I want to do my first lookup on a different lender each time but in a logical order. For instance:
贷方A贷方B贷方C
第一位客户再次查看贷方A,第二位客户B,第三位客户C,第四位客户A.
First customer views Lender A, second customer B, third customer C, fourth customer A again.
其背后的原因仅仅是将线索平均分配给贷方,并且如果每天重置计数器约一次,那就不是世界末日了.
The reason behind this is simply to distribute the leads amongst lenders evenly, and if the counter was reset once a day or so, it wouldn't be the end of the world.
很显然,我可以将此信息写入数据库-但是那太过分了吗?其他人需要实现类似的东西并想出一个更简单的解决方案吗?
Obviously, I could write this information to the database - but is that overkill? Anyone else needed to implement something similar and come up with a simpler solution?
任何建议表示赞赏.
推荐答案
如果存储了包含上次选择贷方的DateTime的额外列,则可以修改贷方选择查询以返回被选择时间最长的贷方前.即,例如: Lenders.OrderBy(x => x.LastSelected).First()
If you stored an extra column that contains the DateTime a lender was last selected, you can modify the lender selection query to return the lender that was selected the longest time ago. I.e., something like: Lenders.OrderBy(x => x.LastSelected).First()
当然,你也当选择一个贷款人必须写回数据库.除非您在一个SQL查询中完成了所有这些操作.像这样的东西(刚刚验证-很好):
Of course, you'll also have to write back to the database when a lender is selected. Unless you did all of this in one SQL query. Something like this works (edit: just verified - works well):
UPDATE MyTable
SET LastSelected = GetDate()
OUTPUT INSERTED.*
WHERE Id = (SELECT TOP (1) Id FROM MyTable ORDER BY LastSelected)
这篇关于如何维持轮循机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!