This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Bogus" Version="31.0.3" />
|
||||
<PackageReference Include="BouncyCastle.NetCore" Version="1.8.6" />
|
||||
<PackageReference Include="CsvHelper" Version="15.0.8" />
|
||||
<PackageReference Include="ChoETL.JSON.NETStandard" Version="1.2.1.2" />
|
||||
<PackageReference Include="Enums.NET" Version="3.0.3" />
|
||||
<PackageReference Include="jose-jwt" Version="2.5.0" />
|
||||
<PackageReference Include="MailKit" Version="2.9.0" />
|
||||
|
||||
@@ -14,6 +14,7 @@ using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using ChoETL;
|
||||
|
||||
namespace AyaNova.Api.Controllers
|
||||
{
|
||||
@@ -80,27 +81,31 @@ namespace AyaNova.Api.Controllers
|
||||
log.LogDebug($"Instantiating biz object handler for {dataListSelection.ObjectType}");
|
||||
var biz = BizObjectFactory.GetBizObject(dataListSelection.ObjectType, ct);
|
||||
log.LogDebug($"Fetching data for {dataListSelection.SelectedRowIds.Length} {dataListSelection.ObjectType} items");
|
||||
var TheData = await ((IExportAbleObject)biz).GetExportData(dataListSelection.SelectedRowIds);
|
||||
// var TheData = await ((IExportAbleObject)biz).GetJSONExportData(dataListSelection.SelectedRowIds);
|
||||
|
||||
string baseFileName = FileUtil.StringToSafeFileName($"{dataListSelection.ObjectType.ToString().ToLowerInvariant()}-{FileUtil.GetSafeDateFileName()}");
|
||||
string baseFileName = FileUtil.StringToSafeFileName($"{dataListSelection.ObjectType.ToString().ToLowerInvariant()}-{format}-{FileUtil.GetSafeDateFileName()}");
|
||||
|
||||
// string outputRandomFileNameNoExtension = StringUtil.ReplaceLastOccurrence(FileUtil.NewRandomFileName, ".", "");
|
||||
string outputSourceFileName = baseFileName + "." + format;
|
||||
string outputSourceFullPath = System.IO.Path.Combine(FileUtil.TemporaryFilesFolder, outputSourceFileName);
|
||||
string outputZipFullpath = System.IO.Path.Combine(FileUtil.TemporaryFilesFolder, baseFileName + ".zip");
|
||||
// string outputFullPathSourceFile=outputFullPathNoExtension
|
||||
// string outputFullpathZipFile=outputFullPathNoExtension + ".zip";
|
||||
log.LogDebug($"Calling render export data to file");
|
||||
|
||||
log.LogDebug($"Calling render export data to file {outputZipFullpath}");
|
||||
switch (format)
|
||||
{
|
||||
case "csv":
|
||||
throw new System.NotImplementedException("CSV export not implemented yet");
|
||||
case "csv":
|
||||
using (var w = new ChoCSVWriter(outputSourceFullPath).WithFirstLineHeader())
|
||||
{
|
||||
var dat = await ((IExportAbleObject)biz).GetExportData(dataListSelection.SelectedRowIds);
|
||||
w.Write(ToDynamicList(dat));
|
||||
}
|
||||
break;
|
||||
case "json":
|
||||
using (StreamWriter file = System.IO.File.CreateText(outputSourceFullPath))
|
||||
using (JsonTextWriter writer = new JsonTextWriter(file))
|
||||
{
|
||||
TheData.WriteTo(writer);
|
||||
var dat = await ((IExportAbleObject)biz).GetExportData(dataListSelection.SelectedRowIds);
|
||||
dat.WriteTo(writer);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -118,6 +123,18 @@ namespace AyaNova.Api.Controllers
|
||||
|
||||
}
|
||||
|
||||
public static IList<dynamic> ToDynamicList(JArray data)
|
||||
{
|
||||
var dynamicData = new List<dynamic>();
|
||||
var expConverter = new Newtonsoft.Json.Converters.ExpandoObjectConverter();
|
||||
|
||||
foreach (var dataItem in data)
|
||||
{
|
||||
dynamic obj = JsonConvert.DeserializeObject<System.Dynamic.ExpandoObject>(dataItem.ToString(), expConverter);
|
||||
dynamicData.Add(obj);
|
||||
}
|
||||
return dynamicData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download a rendered Export
|
||||
|
||||
@@ -321,6 +321,37 @@ namespace AyaNova.Biz
|
||||
return await GetReportData(idList);
|
||||
}
|
||||
|
||||
|
||||
// public async Task<object[]> GetObjectArrayExportData(long[] idList)
|
||||
// {
|
||||
// //NOTE: Report widget is a superset of biz object widget
|
||||
// //Biz objects will add and needed linked records here as extra fields with the data included
|
||||
// //for example instead of a userid only there will be username added to the record
|
||||
// //so the report designer can just select it as a field, no need to query seperately for it etc
|
||||
// //REMEMBER: there is a name display format system and it should honour that so that the report
|
||||
// //displays a user the same as it would display in the UI in an input form, no surprises
|
||||
|
||||
// List<Widget> wList = new List<Widget>();
|
||||
// while (idList.Any())
|
||||
// {
|
||||
// var batch = idList.Take(IReportAbleObject.REPORT_DATA_BATCH_SIZE);
|
||||
// idList = idList.Skip(IReportAbleObject.REPORT_DATA_BATCH_SIZE).ToArray();
|
||||
// //query for this batch, comes back in db natural order unfortunately
|
||||
// var batchResults = await ct.Widget.Where(z => batch.Contains(z.Id)).ToArrayAsync();
|
||||
// //order the results back into original
|
||||
// var orderedList = from id in batch join z in batchResults on id equals z.Id select z;
|
||||
|
||||
// wList.AddRange(orderedList);
|
||||
// // foreach (Widget w in orderedList)
|
||||
// // {
|
||||
// // var jo = JObject.FromObject(w);
|
||||
// // jo["CustomFields"] = JObject.Parse((string)jo["CustomFields"]);
|
||||
// // ReportData.Add(jo);
|
||||
// // }
|
||||
// }
|
||||
// return wList.ToArray();
|
||||
// }
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//JOB / OPERATIONS
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user