diff --git a/Service/ServiceUtils/AiContextLoader.cs b/Service/ServiceUtils/AiContextLoader.cs index b409ad7ac..795867965 100644 --- a/Service/ServiceUtils/AiContextLoader.cs +++ b/Service/ServiceUtils/AiContextLoader.cs @@ -15,6 +15,7 @@ using AICore.Context.Core; using DevExpress.DataAccess.Native.Sql; using BS.Shared.Exceptions; using BS.Shared.DataContracts.Feature.AI; +using System.Security.Cryptography; namespace BeWo.Service.ServiceUtils { @@ -108,19 +109,26 @@ namespace BeWo.Service.ServiceUtils private static IContextSummary loadServiceRecordDocumentationContext(Dictionary context_reference, string doku_text, int? sample_count = null) { var customer = loadCompactCustomerDC(context_reference); - var serviceRecords = loadServiceRecordDCs(context_reference, sample_count); var supportConcept = loadSupportConceptDC(context_reference); var costBearer = supportConcept.CostBearerList.First(x => x.CostBearerOid == context_reference[TableID.CostBearer][0]); + var costBearer2SupportConcept = costBearer.CostBearer2SupportConceptOid; + + var serviceRecords = loadServiceRecordsByExplicitReference(customer.CustomerOid, costBearer2SupportConcept, sample_count); return AiContextSummaryFactory.CreateServiceRecordDocumentationFunction(serviceRecords, customer, costBearer, supportConcept, doku_text); } - private static bool oidsContainsOid(long[] oids, long oid) + private static IEnumerable loadServiceRecordsByExplicitReference(long customer, long cb2sc, int? sample_count = null) { - if (oids == null || oids.Length == 0) - return false; + if (sample_count is null || sample_count == 0) + return null; - return oids.Contains(oid); + var dcs = new OperationsServiceImp().GetCustomerServiceRecordsCompact(customer, cb2sc, null); + + if(sample_count == -1) + return dcs; + + return dcs.Take(sample_count.Value); } private static CompactCustomerDC loadCompactCustomerDC(Dictionary context_reference)