Tradeline считается дубликатом, если он имеет:
- Один и тот же номер счета, тип счета, дату и не вручную
- Последняя отчетная дата
- Если отчетная дата совпадает, сравните (30,60,90) поля и выберите торговую линию, которая имеет более высокое значение в ЛЮБОМ из трех вышеуказанных атрибутов.
public IEnumerable DedupeTradeline(IEnumerable tradelines)
{
//split tradeline into manual and non-manual
var tradelineDictionary = tradelines.GroupBy(x => x.Source == "MAN").ToDictionary(x => x.Key, x => x.ToList());
//create list of non-manual tradeline for dedupe logic
var nonManualTradelines = tradelineDictionary.Where(x => x.Key == false).Select(x => x.Value).FirstOrDefault();
var manualTradelines = tradelineDictionary.Where(x => x.Key).Select(x => x.Value).FirstOrDefault();
//check if same reported date is present for dedupe tradelines
var duplicate = nonManualTradelines?.GroupBy(x => new
{
x.ReportedDate,
x.Account,
x.AcctType,
x.Date
}).Any(g => g.Count() > 1);
IEnumerable dedupe;
if (duplicate != null && (bool) !duplicate)
{
//logic for dedupe tradeline if no same reported date
dedupe = nonManualTradelines.GroupBy(x => new
{
x.Account,
x.AcctType,
x.Date
})
//in case of duplicate tradelines select one with the latest date reported
.Select(x => x.OrderByDescending(o => o.ReportedDate).First());
}
else
{
//logic for dedupe tradeline if same reported date
dedupe = nonManualTradelines?.GroupBy(x => new
{
x.ReportedDate,
x.Account,
x.AcctType,
x.Date
})
.Select();
// Stuck here not sure what to do
}
//append manual tradeline to the output of dedupe tradelines
var response = manualTradelines != null ? (dedupe).Union(manualTradelines) : dedupe;
return response;
}
Класс Tradeline:
public class Tradeline
{
public string Account { get; set; }
public string AcctType { get; set; }
public string Late30 { get; set; }
public string Late60 { get; set; }
public string Late90 { get; set; }
public string Date { get; set; }
public string ReportedDate { get; set; }
public string Source { get; set; }
}
Подробнее здесь: https://stackoverflow.com/questions/565 ... using-linq
Мобильная версия