Untitled

mail@pastecode.io avatar
unknown
plain_text
4 months ago
4.1 kB
5
Indexable
public List<CompareMMObligation> CompareMMObligationData()
{
    context.CompareMMObligations.RemoveRange(context.CompareMMObligations.Where(t => t.CompareMMObligationInit.CompareDate == Today));
    context.SaveChanges();

    var result = new List<CompareMMObligation>();

    var spopDatas = GetSPOPMMObligation();

    var extDatas = GetExtMMObligation();

    //var spopOnly = extData.Where(t => !spopData.Any(s => s.InternalData.Board == t.ExternalData.Board));

    var extOnly = extDatas.Where(t => !spopDatas.Any(s => s.InternalData.MMGroup == t.ExternalData.MMGroup && s.InternalData.Security!="-" && s.InternalData.Security == t.ExternalData.Security));

    foreach (var item in spopDatas)
    {

        bool isSame = true;

        var extData = extDatas.FirstOrDefault(t => t.ExternalData.MMGroup == item.InternalData.MMGroup && item.InternalData.Security!=null  && item.InternalData.Security == t.ExternalData.Security);
        
        if (extData?.ExternalData?.MMGroup == "LPAR" || item.InternalData.MMGroup == "LPAR")
        {

        }
        
        if (extData != null)
        {
            isSame = extData.ExternalData.MMGroup == item.InternalData.MMGroup && item.InternalData.MMGroup != null;
            isSame = isSame && extData.ExternalData.Security == item.InternalData.Security && item.InternalData.Security!= null;
            isSame = isSame && extData.ExternalData.Instrument== item.InternalData.Instrument && item.InternalData.Instrument != null;
            isSame = isSame && extData.ExternalData.Board == item.InternalData.Board && item.InternalData.Board != null;
            isSame = isSame && extData.ExternalData.Depth== item.InternalData.Depth && item.InternalData.Depth != null;
            isSame = isSame && extData.ExternalData.EnableTakenOut == item.InternalData.EnableTakenOut && item.InternalData.EnableTakenOut != null;
            //isSame = isSame && extData.ExternalData.Status == item.InternalData.Status && item.InternalData.Status != null;
        }
        else
        {
            isSame = false;
        }

        //if (!isSame)
        //{

        var newDiff = new CompareMMObligation();
        newDiff.Init();
        newDiff.SetCreated();
        newDiff.InternalData = item.InternalData;
        newDiff.ExternalData = extData?.ExternalData ?? new CompareMMObligationExternalData();
        newDiff.IsSame = isSame;
        if (!isSame)
        {
            newDiff.DifferentColumn = DiffColumnMMObligationData(newDiff);
        }
        newDiff.InternalData.Init();
        newDiff.InternalData.SetCreated();
        newDiff.ExternalData.Init();
        newDiff.ExternalData.SetCreated();

        result.Add(newDiff);

        //}

    }

    foreach (var extdata in extOnly)
    {

        var newDiff = new CompareMMObligation();
        newDiff.Init();
        newDiff.SetCreated();
        newDiff.InternalData = new CompareMMObligationInternalData();
        newDiff.ExternalData = extdata.ExternalData;
        newDiff.IsSame = false;
        newDiff.DifferentColumn = DiffColumnMMObligationData(newDiff);
        newDiff.InternalData.Init();
        newDiff.InternalData.SetCreated();
        newDiff.ExternalData.Init();
        newDiff.ExternalData.SetCreated();

        result.Add(newDiff);

    }


    var init = context.CompareMMObligationInits
        .Include("Result")
        .Include("Result.InternalData")
        .Include("Result.ExternalData")
        .FirstOrDefault(t => t.CompareDate== Today);

    if (init == null)
    {

        init = new CompareMMObligationInit();
        init.Init();
        init.SetCreated();
        init.CompareDate = Today;
        init.Result = result;

        context.CompareMMObligationInits.Add(init);

    }
    else
    {

        init.SetUpdated();
        init.CompareDate = Today;

        context.CompareMMObligations.RemoveRange(init.Result.ToList());

        init.Result = result;
    }

    context.SaveChanges();

    return result;
}
Leave a Comment