This commit is contained in:
@@ -237,28 +237,26 @@ namespace Sockeye.Biz
|
|||||||
await Task.CompletedTask;
|
await Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
internal async Task<Subscription> SubscriptionGetForReportingAsync(SockType sType, long id)
|
|
||||||
{
|
|
||||||
|
|
||||||
//if it's the entire workorder just get, populate and return as normal
|
|
||||||
if (sType == SockType.Subscription)
|
|
||||||
return await GetAsync(id, false);
|
|
||||||
var subId = await ct.SubscriptionItem.AsNoTracking().Where(z => z.Id == id).Select(z => z.SubscriptionId).FirstOrDefaultAsync();
|
|
||||||
return await GetAsync(subId, false);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//REPORTING
|
//REPORTING
|
||||||
//
|
//
|
||||||
public async Task<JArray> GetReportData(DataListSelectedRequest dataListSelectedRequest, Guid jobId)
|
public async Task<JArray> GetReportData(DataListSelectedRequest dataListSelectedRequest, Guid jobId)
|
||||||
|
{
|
||||||
|
if (dataListSelectedRequest.SockType == SockType.Subscription)
|
||||||
|
return await GetSubscriptionsReportData(dataListSelectedRequest, jobId);
|
||||||
|
else
|
||||||
|
//subscription items
|
||||||
|
return await GetSubscriptionItemsReportData(dataListSelectedRequest, jobId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task<JArray> GetSubscriptionsReportData(DataListSelectedRequest dataListSelectedRequest, Guid jobId)
|
||||||
{
|
{
|
||||||
var idList = dataListSelectedRequest.SelectedRowIds;
|
var idList = dataListSelectedRequest.SelectedRowIds;
|
||||||
JArray ReportData = new JArray();
|
JArray ReportData = new JArray();
|
||||||
|
|
||||||
List<Subscription> batchResults = new List<Subscription>();
|
List<Subscription> batchResults = new List<Subscription>();
|
||||||
while (idList.Any())
|
while (idList.Any())
|
||||||
{
|
{
|
||||||
@@ -270,7 +268,8 @@ namespace Sockeye.Biz
|
|||||||
foreach (long batchId in batch)
|
foreach (long batchId in batch)
|
||||||
{
|
{
|
||||||
if (!ReportRenderManager.KeepGoing(jobId)) return null;
|
if (!ReportRenderManager.KeepGoing(jobId)) return null;
|
||||||
batchResults.Add(await SubscriptionGetForReportingAsync(dataListSelectedRequest.SockType, batchId));
|
//var subId = await ct.SubscriptionItem.AsNoTracking().Where(z => z.Id == id).Select(z => z.SubscriptionId).FirstOrDefaultAsync();
|
||||||
|
batchResults.Add(await GetAsync(batchId, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
//order the results back into original
|
//order the results back into original
|
||||||
@@ -287,8 +286,6 @@ namespace Sockeye.Biz
|
|||||||
{
|
{
|
||||||
if (!ReportRenderManager.KeepGoing(jobId)) return null;
|
if (!ReportRenderManager.KeepGoing(jobId)) return null;
|
||||||
var jo = JObject.FromObject(w);
|
var jo = JObject.FromObject(w);
|
||||||
if (!JsonUtil.JTokenIsNullOrEmpty(jo["CustomFields"]))
|
|
||||||
jo["CustomFields"] = JObject.Parse((string)jo["CustomFields"]);
|
|
||||||
ReportData.Add(jo);
|
ReportData.Add(jo);
|
||||||
}
|
}
|
||||||
orderedList = null;
|
orderedList = null;
|
||||||
@@ -296,6 +293,51 @@ namespace Sockeye.Biz
|
|||||||
vc.Clear();
|
vc.Clear();
|
||||||
return ReportData;
|
return ReportData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<JArray> GetSubscriptionItemsReportData(DataListSelectedRequest dataListSelectedRequest, Guid jobId)
|
||||||
|
{
|
||||||
|
var idList = dataListSelectedRequest.SelectedRowIds;
|
||||||
|
JArray ReportData = new JArray();
|
||||||
|
|
||||||
|
List<SubscriptionItem> batchResults = new List<SubscriptionItem>();
|
||||||
|
while (idList.Any())
|
||||||
|
{
|
||||||
|
if (!ReportRenderManager.KeepGoing(jobId)) return null;
|
||||||
|
|
||||||
|
var batch = idList.Take(IReportAbleObject.REPORT_DATA_BATCH_SIZE);
|
||||||
|
idList = idList.Skip(IReportAbleObject.REPORT_DATA_BATCH_SIZE).ToArray();
|
||||||
|
batchResults.Clear();
|
||||||
|
foreach (long batchId in batch)
|
||||||
|
{
|
||||||
|
if (!ReportRenderManager.KeepGoing(jobId)) return null;
|
||||||
|
//var subId = .Select(z => z.SubscriptionId).FirstOrDefaultAsync();
|
||||||
|
var subItem = await ct.SubscriptionItem.AsNoTracking().Where(z => z.Id == batchId).FirstOrDefaultAsync();
|
||||||
|
await PopulateItemVizFields(subItem, 0);
|
||||||
|
batchResults.Add(subItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
//order the results back into original
|
||||||
|
//What is happening here:
|
||||||
|
//for performance the query is batching a bunch at once by fetching a block of items from the sql server
|
||||||
|
//however it's returning in db order which is often not the order the id list is in
|
||||||
|
//so it needs to be sorted back into the same order as the ide list
|
||||||
|
//This would not be necessary if just fetching each one at a time individually (like in workorder get report data)
|
||||||
|
|
||||||
|
var orderedList = from id in batch join z in batchResults on id equals z.Id select z;
|
||||||
|
batchResults = null;
|
||||||
|
|
||||||
|
foreach (SubscriptionItem w in orderedList)
|
||||||
|
{
|
||||||
|
if (!ReportRenderManager.KeepGoing(jobId)) return null;
|
||||||
|
var jo = JObject.FromObject(w);
|
||||||
|
ReportData.Add(jo);
|
||||||
|
}
|
||||||
|
orderedList = null;
|
||||||
|
}
|
||||||
|
vc.Clear();
|
||||||
|
return ReportData;
|
||||||
|
}
|
||||||
|
|
||||||
private VizCache vc = new VizCache();
|
private VizCache vc = new VizCache();
|
||||||
|
|
||||||
|
|
||||||
@@ -310,20 +352,50 @@ namespace Sockeye.Biz
|
|||||||
|
|
||||||
foreach (var item in o.Items)//some subscriptions have a bunch of the same monthly or yearly raven user in them so this will save in that case
|
foreach (var item in o.Items)//some subscriptions have a bunch of the same monthly or yearly raven user in them so this will save in that case
|
||||||
{
|
{
|
||||||
if (!vc.Has("productname", item.ProductId))
|
await PopulateItemVizFields(item, o.CustomerId);
|
||||||
{
|
// if (!vc.Has("productname", item.ProductId))
|
||||||
var productInfo = await ct.Product.AsNoTracking().Where(x => x.Id == item.ProductId).FirstOrDefaultAsync();
|
// {
|
||||||
vc.Add(productInfo.Name, "productname", item.ProductId);
|
// var productInfo = await ct.Product.AsNoTracking().Where(x => x.Id == item.ProductId).FirstOrDefaultAsync();
|
||||||
vc.Add(productInfo.InitialPrice.ToString(), "productinitialprice", item.ProductId);
|
// vc.Add(productInfo.Name, "productname", item.ProductId);
|
||||||
vc.Add(productInfo.RenewPrice.ToString(), "productrenewprice", item.ProductId);
|
// vc.Add(productInfo.InitialPrice.ToString(), "productinitialprice", item.ProductId);
|
||||||
|
// vc.Add(productInfo.RenewPrice.ToString(), "productrenewprice", item.ProductId);
|
||||||
|
|
||||||
}
|
// }
|
||||||
item.ProductViz = vc.Get("productname", item.ProductId);
|
// item.ProductViz = vc.Get("productname", item.ProductId);
|
||||||
item.RenewPriceViz = vc.GetAsDecimal("productrenewprice", item.ProductId) ?? 0;
|
// item.RenewPriceViz = vc.GetAsDecimal("productrenewprice", item.ProductId) ?? 0;
|
||||||
item.InitialPriceViz = vc.GetAsDecimal("productinitialprice", item.ProductId) ?? 0;
|
// item.InitialPriceViz = vc.GetAsDecimal("productinitialprice", item.ProductId) ?? 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//populate viz fields from provided object
|
||||||
|
private async Task PopulateItemVizFields(SubscriptionItem o, long CustomerId)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (CustomerId == 0)
|
||||||
|
CustomerId = await ct.Subscription.Where(z => z.Id == o.SubscriptionId).Select(z => z.CustomerId).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
if (CustomerId != 0)
|
||||||
|
{
|
||||||
|
if (!vc.Has("customer", CustomerId))
|
||||||
|
{
|
||||||
|
vc.Add(await ct.Customer.AsNoTracking().Where(x => x.Id == CustomerId).Select(x => x.Name).FirstOrDefaultAsync(), "customer", CustomerId);
|
||||||
|
}
|
||||||
|
o.CustomerViz = vc.Get("customer", CustomerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!vc.Has("productname", o.ProductId))
|
||||||
|
{
|
||||||
|
var productInfo = await ct.Product.AsNoTracking().Where(x => x.Id == o.ProductId).FirstOrDefaultAsync();
|
||||||
|
vc.Add(productInfo.Name, "productname", o.ProductId);
|
||||||
|
vc.Add(productInfo.InitialPrice.ToString(), "productinitialprice", o.ProductId);
|
||||||
|
vc.Add(productInfo.RenewPrice.ToString(), "productrenewprice", o.ProductId);
|
||||||
|
}
|
||||||
|
o.ProductViz = vc.Get("productname", o.ProductId);
|
||||||
|
o.RenewPriceViz = vc.GetAsDecimal("productrenewprice", o.ProductId) ?? 0;
|
||||||
|
o.InitialPriceViz = vc.GetAsDecimal("productinitialprice", o.ProductId) ?? 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// IMPORT EXPORT
|
// IMPORT EXPORT
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ namespace Sockeye.Models
|
|||||||
[NotMapped]
|
[NotMapped]
|
||||||
public string ProductViz { get; set; }
|
public string ProductViz { get; set; }
|
||||||
|
|
||||||
|
[NotMapped]
|
||||||
|
public string CustomerViz { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public List<string> Tags { get; set; } = new List<string>();
|
public List<string> Tags { get; set; } = new List<string>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user