feature: job exporting (resolves #155)

This commit is contained in:
Gary Sharp
2024-12-12 16:02:12 +11:00
parent 90c709c4c1
commit a6b9cd1af2
55 changed files with 3197 additions and 412 deletions
+17 -9
View File
@@ -107,11 +107,12 @@ namespace Disco.Services.Authorization
{ "Job.Actions.ConvertHWarToHNWar", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.ConvertHWarToHNWar, (c, v) => c.Job.Actions.ConvertHWarToHNWar = v, "Convert HWar Jobs To HNWar", "Can convert warranty jobs to non-warranty jobs", false) },
{ "Job.Actions.Create", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.Create, (c, v) => c.Job.Actions.Create = v, "Create Jobs", "Can create jobs", false) },
{ "Job.Actions.Delete", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.Delete, (c, v) => c.Job.Actions.Delete = v, "Delete Jobs", "Can delete jobs", false) },
{ "Job.Actions.Export", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.Export, (c, v) => c.Job.Actions.Export = v, "Export Jobs", "Can export jobs in a bulk format", false) },
{ "Job.Actions.ForceClose", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.ForceClose, (c, v) => c.Job.Actions.ForceClose = v, "Force Close Jobs", "Can force close jobs", false) },
{ "Job.Actions.GenerateDocuments", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.GenerateDocuments, (c, v) => c.Job.Actions.GenerateDocuments = v, "Generate Documents", "Can generate documents for jobs", false) },
{ "Job.Actions.LogInsurance", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.LogInsurance, (c, v) => c.Job.Actions.LogInsurance = v, "Log Insurance", "Can log insurance for non-warranty jobs", false) },
{ "Job.Actions.LogRepair", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.LogRepair, (c, v) => c.Job.Actions.LogRepair = v, "Log Repair", "Can log repair for non-warranty jobs", false) },
{ "Job.Actions.LogWarranty", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.LogWarranty, (c, v) => c.Job.Actions.LogWarranty = v, "Log Warranty", "Can log warranty for jobs", false) },
{ "Job.Actions.LogInsurance", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.LogInsurance, (c, v) => c.Job.Actions.LogInsurance = v, "Lodge Insurance", "Can lodge insurance for non-warranty jobs", false) },
{ "Job.Actions.LogRepair", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.LogRepair, (c, v) => c.Job.Actions.LogRepair = v, "Lodge Repair", "Can lodge repair for non-warranty jobs", false) },
{ "Job.Actions.LogWarranty", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.LogWarranty, (c, v) => c.Job.Actions.LogWarranty = v, "Lodge Warranty", "Can lodge warranty for jobs", false) },
{ "Job.Actions.RemoveAnyAttachments", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.RemoveAnyAttachments, (c, v) => c.Job.Actions.RemoveAnyAttachments = v, "Remove Any Attachments", "Can remove any attachments from jobs", false) },
{ "Job.Actions.RemoveAnyLogs", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.RemoveAnyLogs, (c, v) => c.Job.Actions.RemoveAnyLogs = v, "Remove Any Logs", "Can remove any job logs", false) },
{ "Job.Actions.RemoveAnyQueues", new Tuple<Func<RoleClaims, bool>, Action<RoleClaims, bool>, string, string, bool>(c => c.Job.Actions.RemoveAnyQueues, (c, v) => c.Job.Actions.RemoveAnyQueues = v, "Remove from Any Queues", "Can remove from any job queues", false) },
@@ -336,6 +337,7 @@ namespace Disco.Services.Authorization
new ClaimNavigatorItem("Job.Actions.ConvertHWarToHNWar", false),
new ClaimNavigatorItem("Job.Actions.Create", false),
new ClaimNavigatorItem("Job.Actions.Delete", false),
new ClaimNavigatorItem("Job.Actions.Export", false),
new ClaimNavigatorItem("Job.Actions.ForceClose", false),
new ClaimNavigatorItem("Job.Actions.GenerateDocuments", false),
new ClaimNavigatorItem("Job.Actions.LogInsurance", false),
@@ -647,6 +649,7 @@ namespace Disco.Services.Authorization
c.Job.Actions.ConvertHWarToHNWar = true;
c.Job.Actions.Create = true;
c.Job.Actions.Delete = true;
c.Job.Actions.Export = true;
c.Job.Actions.ForceClose = true;
c.Job.Actions.GenerateDocuments = true;
c.Job.Actions.LogInsurance = true;
@@ -1334,6 +1337,11 @@ namespace Disco.Services.Authorization
/// </summary>
public const string Delete = "Job.Actions.Delete";
/// <summary>Export Jobs
/// <para>Can export jobs in a bulk format</para>
/// </summary>
public const string Export = "Job.Actions.Export";
/// <summary>Force Close Jobs
/// <para>Can force close jobs</para>
/// </summary>
@@ -1344,18 +1352,18 @@ namespace Disco.Services.Authorization
/// </summary>
public const string GenerateDocuments = "Job.Actions.GenerateDocuments";
/// <summary>Log Insurance
/// <para>Can log insurance for non-warranty jobs</para>
/// <summary>Lodge Insurance
/// <para>Can lodge insurance for non-warranty jobs</para>
/// </summary>
public const string LogInsurance = "Job.Actions.LogInsurance";
/// <summary>Log Repair
/// <para>Can log repair for non-warranty jobs</para>
/// <summary>Lodge Repair
/// <para>Can lodge repair for non-warranty jobs</para>
/// </summary>
public const string LogRepair = "Job.Actions.LogRepair";
/// <summary>Log Warranty
/// <para>Can log warranty for jobs</para>
/// <summary>Lodge Warranty
/// <para>Can lodge warranty for jobs</para>
/// </summary>
public const string LogWarranty = "Job.Actions.LogWarranty";
+1 -1
View File
@@ -7,7 +7,7 @@
<#@ assembly name="VSLangProj" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="System.Xml.Linq" #>
<#@ assembly name="C:\Windows\Microsoft.NET\Framework\v4.0.30319\CustomMarshalers.dll" #>
<#@ assembly name="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\CustomMarshalers.dll" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
@@ -52,5 +52,7 @@
[ClaimDetails("Update Sub Types", "Can update sub types for jobs")]
public bool UpdateSubTypes { get; set; }
[ClaimDetails("Export Jobs", "Can export jobs in a bulk format")]
public bool Export { get; set; }
}
}
+2
View File
@@ -381,6 +381,8 @@
<Compile Include="Interop\VicEduDept\VicSmart.cs" />
<Compile Include="Interop\DiscoServices\UpdateQuery.cs" />
<Compile Include="Interop\DiscoServices\UpdateQueryTask.cs" />
<Compile Include="Jobs\Exporting\JobExport.cs" />
<Compile Include="Jobs\Exporting\JobExportTask.cs" />
<Compile Include="Jobs\JobActionExtensions.cs" />
<Compile Include="Jobs\JobExtensions.cs" />
<Compile Include="Jobs\JobFlagExtensions.cs" />
@@ -15,6 +15,9 @@ namespace Disco.Services
{
public static ExportResult WriteExport<T>(IExportOptions options, IScheduledTaskStatus status, List<ExportFieldMetadata<T>> metadata, List<T> records) where T : IExportRecord
{
if (records.Count == 0)
return new ExportResult();
var filenameWithoutExtension = $"{options.FilenamePrefix}-{status.StartedTimestamp.Value:yyyyMMdd-HHmmss}";
MemoryStream stream;
string filename;
+402
View File
@@ -0,0 +1,402 @@
using Disco.Data.Repository;
using Disco.Models.Exporting;
using Disco.Models.Repository;
using Disco.Models.Services.Exporting;
using Disco.Models.Services.Jobs.Exporting;
using Disco.Services.Jobs.JobQueues;
using Disco.Services.Plugins.Features.DetailsProvider;
using Disco.Services.Tasks;
using Disco.Services.Users;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Linq;
namespace Disco.Services.Jobs.Exporting
{
using Metadata = ExportFieldMetadata<JobExportRecord>;
public static class JobExport
{
public static ExportResult GenerateExport(DiscoDataContext database, Func<IQueryable<Job>, IQueryable<Job>> filter, JobExportOptions options, IScheduledTaskStatus taskStatus)
{
database.Configuration.LazyLoadingEnabled = false;
database.Configuration.ProxyCreationEnabled = false;
var jobQuery = (IQueryable<Job>)database.Jobs;
if (filter != null)
jobQuery = filter(jobQuery);
// Update Users
if (options.UserDisplayName ||
options.UserSurname ||
options.UserGivenName ||
options.UserPhoneNumber ||
options.UserEmailAddress)
{
taskStatus.UpdateStatus(5, "Refreshing user details from Active Directory");
var userIds = jobQuery.Where(d => d.UserId != null).Select(d => d.UserId).Distinct().ToList();
foreach (var userId in userIds)
{
try
{
UserService.GetUser(userId, database);
}
catch (Exception) { } // Ignore Errors
}
}
// Update Last Network Logon Date
if (options.DeviceLastNetworkLogon)
{
taskStatus.UpdateStatus(15, "Refreshing device last network logon dates from Active Directory");
try
{
Interop.ActiveDirectory.ADNetworkLogonDatesUpdateTask.UpdateLastNetworkLogonDates(database, ScheduledTaskMockStatus.Create("UpdateLastNetworkLogonDates"));
database.SaveChanges();
}
catch (Exception) { } // Ignore Errors
}
taskStatus.UpdateStatus(25, "Extracting records from the database");
var records = BuildRecords(jobQuery).ToList();
records.ForEach(r =>
{
if (options.JobStatus)
{
r.JobStatus = JobExtensions.CalculateStatusId(
r.Job.ClosedDate,
r.Job.JobTypeId,
r.JobMetaWarranty?.ExternalLoggedDate,
r.JobMetaWarranty?.ExternalCompletedDate,
r.JobMetaNonWarranty?.RepairerLoggedDate,
r.JobMetaNonWarranty?.RepairerCompletedDate,
r.JobMetaNonWarranty?.AccountingChargeRequiredDate,
r.JobMetaNonWarranty?.AccountingChargeAddedDate,
r.JobMetaNonWarranty?.AccountingChargePaidDate,
r.JobMetaNonWarranty?.IsInsuranceClaim,
r.JobMetaInsurance?.ClaimFormSentDate,
r.Job.WaitingForUserAction,
r.Job.DeviceReadyForReturn,
r.Job.DeviceReturnedDate);
}
if (options.UserDetailCustom && r.User != null)
{
var detailsService = new DetailsProviderService(database);
r.UserCustomDetails = detailsService.GetDetails(r.User);
}
});
taskStatus.UpdateStatus(70, "Building metadata");
var metadata = options.BuildMetadata(records);
if (metadata.Count == 0)
throw new ArgumentException("At least one export field must be specified", "Options");
taskStatus.UpdateStatus(80, $"Formatting {records.Count} records for export");
return ExportHelpers.WriteExport(options, taskStatus, metadata, records);
}
public static ExportResult GenerateExport(DiscoDataContext database, JobExportOptions options, IScheduledTaskStatus taskStatus)
{
Func<IQueryable<Job>, IQueryable<Job>> filter = q =>
{
var r = q.Where(j => j.OpenedDate >= options.FilterStartDate);
if (options.FilterEndDate.HasValue)
r = r.Where(j => j.OpenedDate <= options.FilterEndDate);
if (options.FilterJobTypeId != null)
r = r.Where(j => j.JobTypeId == options.FilterJobTypeId);
if (options.FilterJobSubTypeIds?.Any() ?? false)
r = r.Where(j => j.JobSubTypes.Any(st => options.FilterJobSubTypeIds.Contains(st.Id)));
if (options.FilterJobQueueId.HasValue)
r = r.Where(j => j.JobQueues.Any(jq => !jq.RemovedDate.HasValue && jq.JobQueueId == options.FilterJobQueueId));
if (options.FilterJobStatusId != null)
{
if (options.FilterJobStatusId != Job.JobStatusIds.Closed)
r = r.Where(j => j.ClosedDate == null);
switch (options.FilterJobStatusId)
{
case Job.JobStatusIds.Open:
// already filtered
break;
case Job.JobStatusIds.AwaitingAccountingPayment:
r = r.Where(j => j.JobTypeId == JobType.JobTypeIds.HNWar && j.JobMetaNonWarranty.AccountingChargeAddedDate != null && j.JobMetaNonWarranty.AccountingChargePaidDate == null);
break;
case Job.JobStatusIds.AwaitingAccountingCharge:
r = r.Where(j => j.JobTypeId == JobType.JobTypeIds.HNWar && j.JobMetaNonWarranty.AccountingChargeRequiredDate == null && (j.JobMetaNonWarranty.AccountingChargePaidDate != null || j.JobMetaNonWarranty.AccountingChargeAddedDate != null));
break;
case Job.JobStatusIds.AwaitingDeviceReturn:
r = r.Where(j => j.DeviceReadyForReturn != null && j.DeviceReturnedDate == null);
break;
case Job.JobStatusIds.AwaitingInsuranceProcessing:
r = r.Where(j => j.JobTypeId == JobType.JobTypeIds.HNWar && j.JobMetaNonWarranty.IsInsuranceClaim && j.JobMetaInsurance.ClaimFormSentDate == null);
break;
case Job.JobStatusIds.AwaitingRepairs:
r = r.Where(j => j.JobTypeId == JobType.JobTypeIds.HNWar && j.JobMetaNonWarranty.RepairerLoggedDate != null && j.JobMetaNonWarranty.RepairerCompletedDate == null);
break;
case Job.JobStatusIds.AwaitingUserAction:
r = r.Where(j => j.WaitingForUserAction != null);
break;
case Job.JobStatusIds.AwaitingWarrantyRepair:
r = r.Where(j => j.JobTypeId == JobType.JobTypeIds.HWar && j.JobMetaWarranty.ExternalLoggedDate != null && j.JobMetaWarranty.ExternalCompletedDate == null);
break;
case Job.JobStatusIds.Closed:
r = r.Where(j => j.ClosedDate != null);
break;
default:
throw new ArgumentException($"Unknown Job Status Id: {options.FilterJobStatusId}", nameof(options.FilterJobStatusId));
}
}
return r;
};
return GenerateExport(database, filter, options, taskStatus);
}
public static ExportResult GenerateExport(DiscoDataContext database, JobExportOptions options)
{
return GenerateExport(database, options, ScheduledTaskMockStatus.Create("Job Export"));
}
private static IEnumerable<JobExportRecord> BuildRecords(IQueryable<Job> jobs)
{
return jobs.Select(j => new JobExportRecord()
{
Job = j,
JobTypeDescription = j.JobType.Description,
JobSubTypeDescriptions = j.JobSubTypes.Select(st => st.Description),
LogCount = j.JobLogs.Count(),
FirstLog = j.JobLogs.OrderBy(l => l.Id).FirstOrDefault(),
LastLog = j.JobLogs.OrderByDescending(l => l.Id).FirstOrDefault(),
AttachmentsCount = j.JobAttachments.Count(),
QueueCount = j.JobQueues.Count(),
QueueActiveCount = j.JobQueues.Count(q => !q.RemovedDate.HasValue),
QueueLatestActive = j.JobQueues.Where(q => !q.RemovedDate.HasValue).OrderByDescending(q => q.Id).FirstOrDefault(),
JobMetaWarranty = j.JobMetaWarranty,
JobMetaNonWarranty = j.JobMetaNonWarranty,
JobMetaInsurance = j.JobMetaInsurance,
User = j.User,
Device = j.Device,
DeviceModelId = j.Device.DeviceModelId,
DeviceModelDescription = j.Device.DeviceModel.Description,
DeviceModelManufacturer = j.Device.DeviceModel.Manufacturer,
DeviceModelModel = j.Device.DeviceModel.Model,
DeviceModelType = j.Device.DeviceModel.ModelType,
DeviceBatchId = j.Device.DeviceBatchId,
DeviceBatchName = j.Device.DeviceBatch.Name,
DeviceBatchPurchaseDate = j.Device.DeviceBatch.PurchaseDate,
DeviceBatchSupplier = j.Device.DeviceBatch.Supplier,
DeviceBatchUnitCost = j.Device.DeviceBatch.UnitCost,
DeviceBatchWarrantyValidUntilDate = j.Device.DeviceBatch.WarrantyValidUntil,
DeviceBatchInsuredDate = j.Device.DeviceBatch.InsuredDate,
DeviceBatchInsuranceSupplier = j.Device.DeviceBatch.InsuranceSupplier,
DeviceBatchInsuredUntilDate = j.Device.DeviceBatch.InsuredUntil,
DeviceProfileId = j.Device.DeviceProfileId,
DeviceProfileName = j.Device.DeviceProfile.Name,
DeviceProfileShortName = j.Device.DeviceProfile.ShortName,
});
}
private static List<Metadata> BuildMetadata(this JobExportOptions options, List<JobExportRecord> records)
{
IEnumerable<string> userDetailCustomKeys = null;
if (options.UserDetailCustom)
userDetailCustomKeys = records.Where(r => r.UserCustomDetails != null).SelectMany(r => r.UserCustomDetails.Keys).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
var allAccessors = BuildRecordAccessors(userDetailCustomKeys);
return typeof(JobExportOptions).GetProperties()
.Where(p => p.PropertyType == typeof(bool))
.Select(p => new
{
property = p,
details = (DisplayAttribute)p.GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault()
})
.Where(p => p.details != null && (bool)p.property.GetValue(options))
.SelectMany(p =>
{
var fieldMetadata = allAccessors[p.property.Name];
fieldMetadata.ForEach(f =>
{
if (f.ColumnName == null)
f.ColumnName = (p.details.ShortName == "Job" || p.details.ShortName == "Job Details") ? p.details.Name : $"{p.details.ShortName} {p.details.Name}";
});
return fieldMetadata;
}).ToList();
}
private static Dictionary<string, List<Metadata>> BuildRecordAccessors(IEnumerable<string> userDetailCustomKeys)
{
const string DateFormat = "yyyy-MM-dd";
const string DateTimeFormat = DateFormat + " HH:mm:ss";
Func<object, string> csvStringEncoded = (o) => o == null ? null : $"\"{((string)o).Replace("\"", "\"\"")}\"";
Func<object, string> csvToStringEncoded = (o) => o == null ? null : o.ToString();
Func<object, string> csvCurrencyEncoded = (o) => ((decimal?)o).HasValue ? ((decimal?)o).Value.ToString("C") : null;
Func<object, string> csvDateEncoded = (o) => ((DateTime)o).ToString(DateFormat);
Func<object, string> csvDateTimeEncoded = (o) => ((DateTime)o).ToString(DateTimeFormat);
Func<object, string> csvNullableDateEncoded = (o) => ((DateTime?)o).HasValue ? csvDateEncoded(o) : null;
Func<object, string> csvNullableDateTimeEncoded = (o) => ((DateTime?)o).HasValue ? csvDateTimeEncoded(o) : null;
var metadata = new Dictionary<string, List<Metadata>>();
// Job
metadata.Add(nameof(JobExportOptions.JobId), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobId), typeof(int), r => r.Job.Id, csvToStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobStatus), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobStatus), typeof(string), r => Job.JobStatusIds.StatusDescriptions.TryGetValue(r.JobStatus, out var status) ? status : "Unknown", csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobType), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobType), typeof(string), r => r.JobTypeDescription, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobSubTypes), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobSubTypes), typeof(string), r => string.Join(", ", r.JobSubTypeDescriptions), csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobOpenedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobOpenedDate), typeof(DateTime), r => r.Job.OpenedDate, csvDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobOpenedUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobOpenedUser), typeof(string), r => r.Job.OpenedTechUserId, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobExpectedClosedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobExpectedClosedDate), typeof(DateTime), r => r.Job.ExpectedClosedDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobClosedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobClosedDate), typeof(DateTime), r => r.Job.ClosedDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobClosedUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobClosedUser), typeof(string), r => r.Job.ClosedTechUserId, csvStringEncoded) });
// Job Details
metadata.Add(nameof(JobExportOptions.JobDeviceHeldDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobDeviceHeldDate), typeof(DateTime), r => r.Job.DeviceHeld, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobDeviceHeldUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobDeviceHeldUser), typeof(string), r => r.Job.DeviceHeldTechUserId, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobDeviceHeldLocation), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobDeviceHeldLocation), typeof(string), r => r.Job.DeviceHeldLocation, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobDeviceReadyForReturnDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobDeviceReadyForReturnDate), typeof(DateTime), r => r.Job.DeviceReadyForReturn, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobDeviceReadyForReturnUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobDeviceReadyForReturnUser), typeof(string), r => r.Job.DeviceReadyForReturnTechUserId, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobDeviceReturnedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobDeviceReturnedDate), typeof(DateTime), r => r.Job.DeviceReturnedDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobDeviceReturnedUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobDeviceReturnedUser), typeof(string), r => r.Job.DeviceReturnedTechUserId, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobWaitingForUserActionDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobWaitingForUserActionDate), typeof(DateTime), r => r.Job.WaitingForUserAction, csvNullableDateTimeEncoded) });
// Job Logs
metadata.Add(nameof(JobExportOptions.LogCount), new List<Metadata>() { new Metadata(nameof(JobExportOptions.LogCount), typeof(int), r => r.LogCount, csvToStringEncoded) });
metadata.Add(nameof(JobExportOptions.LogFirstDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.LogFirstDate), typeof(DateTime), r => r.FirstLog?.Timestamp, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.LogFirstUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.LogFirstUser), typeof(string), r => r.FirstLog?.TechUserId, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.LogFirstContent), new List<Metadata>() { new Metadata(nameof(JobExportOptions.LogFirstContent), typeof(string), r => r.FirstLog?.Comments, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.LogLastDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.LogLastDate), typeof(DateTime), r => r.LastLog?.Timestamp, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.LogLastUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.LogLastUser), typeof(string), r => r.LastLog?.TechUserId, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.LogLastContent), new List<Metadata>() { new Metadata(nameof(JobExportOptions.LogLastContent), typeof(string), r => r.LastLog?.Comments, csvStringEncoded) });
// Attachments
metadata.Add(nameof(JobExportOptions.AttachmentsCount), new List<Metadata>() { new Metadata(nameof(JobExportOptions.AttachmentsCount), typeof(int), r => r.AttachmentsCount, csvToStringEncoded) });
// Job Queues
metadata.Add(nameof(JobExportOptions.JobQueueCount), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobQueueCount), typeof(int), r => r.QueueCount, csvToStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobQueueActiveCount), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobQueueActiveCount), typeof(int), r => r.QueueActiveCount, csvToStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobQueueActiveLatest), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobQueueActiveLatest), typeof(DateTime), r => r.QueueLatestActive?.JobQueueId == null ? null : JobQueueService.GetQueue(r.QueueLatestActive.JobQueueId).JobQueue.Name, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobQueueActiveLatestAddedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobQueueActiveLatestAddedDate), typeof(DateTime), r => r.QueueLatestActive?.AddedDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobQueueActiveLatestAddedUser), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobQueueActiveLatestAddedUser), typeof(string), r => r.QueueLatestActive?.AddedUserId, csvStringEncoded) });
// Warranty
metadata.Add(nameof(JobExportOptions.JobWarrantyExternalName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobWarrantyExternalName), typeof(string), r => r.JobMetaWarranty?.ExternalName, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobWarrantyExternalReference), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobWarrantyExternalReference), typeof(string), r => r.JobMetaWarranty?.ExternalReference, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobWarrantyExternalLoggedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobWarrantyExternalLoggedDate), typeof(DateTime), r => r.JobMetaWarranty?.ExternalLoggedDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobWarrantyExternalCompletedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobWarrantyExternalCompletedDate), typeof(DateTime), r => r.JobMetaWarranty?.ExternalCompletedDate, csvNullableDateTimeEncoded) });
// Non-Warranty
metadata.Add(nameof(JobExportOptions.JobNonWarrantyAccountingChargeRequiredDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyAccountingChargeRequiredDate), typeof(DateTime), r => r.JobMetaNonWarranty?.AccountingChargeRequiredDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobNonWarrantyAccountingChargeAddedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyAccountingChargeAddedDate), typeof(DateTime), r => r.JobMetaNonWarranty?.AccountingChargeAddedDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobNonWarrantyAccountingChargePaidDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyAccountingChargePaidDate), typeof(DateTime), r => r.JobMetaNonWarranty?.AccountingChargePaidDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobNonWarrantyPurchaseOrderRaisedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyPurchaseOrderRaisedDate), typeof(DateTime), r => r.JobMetaNonWarranty?.PurchaseOrderRaisedDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobNonWarrantyPurchaseOrderReference), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyPurchaseOrderReference), typeof(string), r => r.JobMetaNonWarranty?.PurchaseOrderReference, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobNonWarrantyPurchaseOrderSentDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyPurchaseOrderSentDate), typeof(DateTime), r => r.JobMetaNonWarranty?.PurchaseOrderSentDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobNonWarrantyInvoiceReceivedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyInvoiceReceivedDate), typeof(DateTime), r => r.JobMetaNonWarranty?.InvoiceReceivedDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobNonWarrantyRepairerName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyRepairerName), typeof(string), r => r.JobMetaNonWarranty?.RepairerName, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobNonWarrantyRepairerLoggedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyRepairerLoggedDate), typeof(DateTime), r => r.JobMetaNonWarranty?.RepairerLoggedDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobNonWarrantyRepairerReference), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyRepairerReference), typeof(string), r => r.JobMetaNonWarranty?.RepairerReference, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobNonWarrantyRepairerCompletedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobNonWarrantyRepairerCompletedDate), typeof(DateTime), r => r.JobMetaNonWarranty?.RepairerCompletedDate, csvNullableDateTimeEncoded) });
// Insurance
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceLossOrDamageDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceLossOrDamageDate), typeof(DateTime), r => r.JobMetaInsurance?.LossOrDamageDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceEventLocation), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceEventLocation), typeof(string), r => r.JobMetaInsurance?.EventLocation, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceDescription), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceDescription), typeof(string), r => r.JobMetaInsurance?.Description, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceThirdPartyCausedName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceThirdPartyCausedName), typeof(string), r => r.JobMetaInsurance?.ThirdPartyCausedName, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceThirdPartyCausedWhy), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceThirdPartyCausedWhy), typeof(string), r => r.JobMetaInsurance?.ThirdPartyCausedWhy, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceWitnessesNamesAddresses), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceWitnessesNamesAddresses), typeof(string), r => r.JobMetaInsurance?.WitnessesNamesAddresses, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceBurglaryTheftMethodOfEntry), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceBurglaryTheftMethodOfEntry), typeof(string), r => r.JobMetaInsurance?.BurglaryTheftMethodOfEntry, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsurancePropertyLastSeenDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsurancePropertyLastSeenDate), typeof(DateTime), r => r.JobMetaInsurance?.PropertyLastSeenDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsurancePoliceNotifiedStation), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsurancePoliceNotifiedStation), typeof(string), r => r.JobMetaInsurance?.PoliceNotifiedStation, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsurancePoliceNotifiedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsurancePoliceNotifiedDate), typeof(DateTime), r => r.JobMetaInsurance?.PoliceNotifiedDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsurancePoliceNotifiedCrimeReportNo), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsurancePoliceNotifiedCrimeReportNo), typeof(string), r => r.JobMetaInsurance?.PoliceNotifiedCrimeReportNo, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceRecoverReduceAction), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceRecoverReduceAction), typeof(string), r => r.JobMetaInsurance?.RecoverReduceAction, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceOtherInterestedParties), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceOtherInterestedParties), typeof(string), r => r.JobMetaInsurance?.OtherInterestedParties, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceDateOfPurchase), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceDateOfPurchase), typeof(DateTime), r => r.JobMetaInsurance?.DateOfPurchase, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceClaimFormSentDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceClaimFormSentDate), typeof(DateTime), r => r.JobMetaInsurance?.ClaimFormSentDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceInsurer), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceInsurer), typeof(string), r => r.JobMetaInsurance?.Insurer, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.JobMetaInsuranceInsurerReference), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobMetaInsuranceInsurerReference), typeof(string), r => r.JobMetaInsurance?.InsurerReference, csvStringEncoded) });
// User Management
metadata.Add(nameof(JobExportOptions.JobUserManagementFlags), new List<Metadata>() { new Metadata(nameof(JobExportOptions.JobUserManagementFlags), typeof(string), r => r.Job.Flags, csvToStringEncoded) });
// User
metadata.Add(nameof(JobExportOptions.UserId), new List<Metadata>() { new Metadata(nameof(JobExportOptions.UserId), typeof(string), r => r.User?.UserId, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.UserDisplayName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.UserDisplayName), typeof(string), r => r.User?.DisplayName, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.UserSurname), new List<Metadata>() { new Metadata(nameof(JobExportOptions.UserSurname), typeof(string), r => r.User?.Surname, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.UserGivenName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.UserGivenName), typeof(string), r => r.User?.GivenName, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.UserPhoneNumber), new List<Metadata>() { new Metadata(nameof(JobExportOptions.UserPhoneNumber), typeof(string), r => r.User?.PhoneNumber, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.UserEmailAddress), new List<Metadata>() { new Metadata(nameof(JobExportOptions.UserEmailAddress), typeof(string), r => r.User?.EmailAddress, csvStringEncoded) });
if (userDetailCustomKeys != null)
{
var assignedUserDetailCustomFields = new List<Metadata>();
foreach (var detailKey in userDetailCustomKeys.OrderBy(k => k, StringComparer.OrdinalIgnoreCase))
{
var key = detailKey;
assignedUserDetailCustomFields.Add(new Metadata(detailKey, detailKey, typeof(string), r => r.UserCustomDetails != null && r.UserCustomDetails.TryGetValue(key, out var value) ? value : null, csvStringEncoded));
}
metadata.Add(nameof(JobExportOptions.UserDetailCustom), assignedUserDetailCustomFields);
}
// Device
metadata.Add(nameof(JobExportOptions.DeviceSerialNumber), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceSerialNumber), typeof(string), r => r.Device?.SerialNumber, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceAssetNumber), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceAssetNumber), typeof(string), r => r.Device?.AssetNumber, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceLocation), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceLocation), typeof(string), r => r.Device?.Location, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceComputerName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceComputerName), typeof(string), r => r.Device?.DeviceDomainId, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceLastNetworkLogon), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceLastNetworkLogon), typeof(DateTime), r => r.Device?.LastNetworkLogonDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceCreatedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceCreatedDate), typeof(DateTime), r => r.Device?.CreatedDate, csvDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceFirstEnrolledDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceFirstEnrolledDate), typeof(DateTime), r => r.Device?.EnrolledDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceLastEnrolledDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceLastEnrolledDate), typeof(DateTime), r => r.Device?.LastEnrolDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceAllowUnauthenticatedEnrol), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceAllowUnauthenticatedEnrol), typeof(bool), r => r.Device?.AllowUnauthenticatedEnrol, csvToStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceDecommissionedDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceDecommissionedDate), typeof(DateTime), r => r.Device?.DecommissionedDate, csvNullableDateTimeEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceDecommissionedReason), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceDecommissionedReason), typeof(string), r => r.Device?.DecommissionReason, csvToStringEncoded) });
// Model
metadata.Add(nameof(JobExportOptions.DeviceModelId), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceModelId), typeof(int), r => r.DeviceModelId, csvToStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceModelDescription), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceModelDescription), typeof(string), r => r.DeviceModelDescription, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceModelManufacturer), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceModelManufacturer), typeof(string), r => r.DeviceModelManufacturer, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceModelModel), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceModelModel), typeof(string), r => r.DeviceModelModel, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceModelType), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceModelType), typeof(string), r => r.DeviceModelType, csvStringEncoded) });
// Batch
metadata.Add(nameof(JobExportOptions.DeviceBatchId), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchId), typeof(int), r => r.DeviceBatchId, csvToStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceBatchName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchName), typeof(string), r => r.DeviceBatchName, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceBatchPurchaseDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchPurchaseDate), typeof(DateTime), r => r.DeviceBatchPurchaseDate, csvNullableDateEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceBatchSupplier), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchSupplier), typeof(string), r => r.DeviceBatchSupplier, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceBatchUnitCost), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchUnitCost), typeof(decimal), r => r.DeviceBatchUnitCost, csvCurrencyEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceBatchWarrantyValidUntilDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchWarrantyValidUntilDate), typeof(DateTime), r => r.DeviceBatchWarrantyValidUntilDate, csvNullableDateEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceBatchInsuredDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchInsuredDate), typeof(DateTime), r => r.DeviceBatchInsuredDate, csvNullableDateEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceBatchInsuranceSupplier), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchInsuranceSupplier), typeof(string), r => r.DeviceBatchInsuranceSupplier, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceBatchInsuredUntilDate), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceBatchInsuredUntilDate), typeof(DateTime), r => r.DeviceBatchInsuredUntilDate, csvNullableDateEncoded) });
// Profile
metadata.Add(nameof(JobExportOptions.DeviceProfileId), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceProfileId), typeof(int), r => r.DeviceProfileId, csvToStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceProfileName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceProfileName), typeof(string), r => r.DeviceProfileName, csvStringEncoded) });
metadata.Add(nameof(JobExportOptions.DeviceProfileShortName), new List<Metadata>() { new Metadata(nameof(JobExportOptions.DeviceProfileShortName), typeof(string), r => r.DeviceProfileShortName, csvStringEncoded) });
return metadata;
}
}
}
@@ -0,0 +1,44 @@
using Disco.Data.Repository;
using Disco.Models.Services.Jobs.Exporting;
using Disco.Services.Exporting;
using Disco.Services.Tasks;
using Quartz;
namespace Disco.Services.Jobs.Exporting
{
public class JobExportTask : ScheduledTask
{
private const string JobDataMapContext = "Context";
public override string TaskName { get { return "Export Jobs"; } }
public override bool SingleInstanceTask { get { return false; } }
public override bool CancelInitiallySupported { get { return false; } }
public static ExportTaskContext<JobExportOptions> ScheduleNow(JobExportOptions Options)
{
// Build Context
var context = new ExportTaskContext<JobExportOptions>(Options);
// Build Data Map
var task = new JobExportTask();
JobDataMap taskData = new JobDataMap() { { JobDataMapContext, context} };
// Schedule Task
context.TaskStatus = task.ScheduleTask(taskData);
return context;
}
protected override void ExecuteTask()
{
var context = (ExportTaskContext<JobExportOptions>)ExecutionContext.JobDetail.JobDataMap[JobDataMapContext];
Status.UpdateStatus(10, "Exporting Job Records", "Starting...");
using (DiscoDataContext Database = new DiscoDataContext())
{
context.Result = JobExport.GenerateExport(Database, context.Options, Status);
}
}
}
}
+83 -78
View File
@@ -81,116 +81,121 @@ namespace Disco.Services
return i;
}
public static string JobStatusDescription(string StatusId, Job j = null)
{
switch (StatusId)
{
case Job.JobStatusIds.Open:
return "Open";
case Job.JobStatusIds.Closed:
return "Closed";
case Job.JobStatusIds.AwaitingWarrantyRepair:
if (j == null)
return "Awaiting Warranty Repair";
else
if (j.DeviceHeld.HasValue)
return string.Format("Awaiting Warranty Repair ({0})", j.JobMetaWarranty.ExternalName);
else
return string.Format("Awaiting Warranty Repair - Not Held ({0})", j.JobMetaWarranty.ExternalName);
case Job.JobStatusIds.AwaitingRepairs:
if (j == null)
return "Awaiting Repairs";
else
if (j.DeviceHeld.HasValue)
return string.Format("Awaiting Repairs ({0})", j.JobMetaNonWarranty.RepairerName);
else
return string.Format("Awaiting Repairs - Not Held ({0})", j.JobMetaNonWarranty.RepairerName);
case Job.JobStatusIds.AwaitingDeviceReturn:
return "Awaiting Device Return";
case Job.JobStatusIds.AwaitingUserAction:
return "Awaiting User Action";
case Job.JobStatusIds.AwaitingAccountingPayment:
return "Awaiting Accounting Payment";
case Job.JobStatusIds.AwaitingAccountingCharge:
return "Awaiting Accounting Charge";
case Job.JobStatusIds.AwaitingInsuranceProcessing:
return "Awaiting Insurance Processing";
default:
return "Unknown";
}
}
public static string JobStatusDescription(string StatusId, Job j)
=> JobStatusDescription(StatusId, j?.DeviceHeld, j?.JobMetaWarranty?.ExternalName, j?.JobMetaNonWarranty?.RepairerName);
public static string JobStatusDescription(string StatusId, JobTableStatusItemModel j)
=> JobStatusDescription(StatusId, j?.DeviceHeld, j?.JobMetaWarranty_ExternalName, j?.JobMetaNonWarranty_RepairerName);
public static string JobStatusDescription(string StatusId, JobTableStatusItemModel j = null)
public static string JobStatusDescription(string statusId, DateTime? deviceHeld = null, string warrantyExternalName = null, string nonWarrantyRepairerName = null)
{
switch (StatusId)
if (!Job.JobStatusIds.StatusDescriptions.TryGetValue(statusId, out var statusDescription))
return "Unknown";
switch (statusId)
{
case Job.JobStatusIds.Open:
return "Open";
case Job.JobStatusIds.Closed:
return "Closed";
case Job.JobStatusIds.AwaitingWarrantyRepair:
if (j == null)
return "Awaiting Warranty Repair";
var warrantyName = string.Empty;
if (!string.IsNullOrWhiteSpace(warrantyExternalName))
warrantyName = $" ({warrantyExternalName})";
if (deviceHeld.HasValue)
return statusDescription + warrantyName;
else
if (j.DeviceHeld.HasValue)
return string.Format("Awaiting Warranty Repair ({0})", j.JobMetaWarranty_ExternalName);
else
return string.Format("Awaiting Warranty Repair - Not Held ({0})", j.JobMetaWarranty_ExternalName);
return $"{statusDescription} - Not Held{warrantyExternalName}";
case Job.JobStatusIds.AwaitingRepairs:
if (j == null)
return "Awaiting Repairs";
var repairerName = string.Empty;
if (!string.IsNullOrWhiteSpace(nonWarrantyRepairerName))
repairerName = $" ({nonWarrantyRepairerName})";
if (deviceHeld.HasValue)
return statusDescription + repairerName;
else
if (j.DeviceHeld.HasValue)
return string.Format("Awaiting Repairs ({0})", j.JobMetaNonWarranty_RepairerName);
else
return string.Format("Awaiting Repairs - Not Held ({0})", j.JobMetaNonWarranty_RepairerName);
case Job.JobStatusIds.AwaitingDeviceReturn:
return "Awaiting Device Return";
case Job.JobStatusIds.AwaitingUserAction:
return "Awaiting User Action";
case Job.JobStatusIds.AwaitingAccountingPayment:
return "Awaiting Accounting Payment";
case Job.JobStatusIds.AwaitingAccountingCharge:
return "Awaiting Accounting Charge";
case Job.JobStatusIds.AwaitingInsuranceProcessing:
return "Awaiting Insurance Processing";
return $"{statusDescription} - Not Held{repairerName}";
default:
return "Unknown";
return statusDescription;
}
}
public static string CalculateStatusId(this Job j)
{
return j.ToJobTableStatusItemModel().CalculateStatusId();
return CalculateStatusId(
j.ClosedDate,
j.JobTypeId,
j.JobMetaWarranty?.ExternalLoggedDate,
j.JobMetaWarranty?.ExternalCompletedDate,
j.JobMetaNonWarranty?.RepairerLoggedDate,
j.JobMetaNonWarranty?.RepairerCompletedDate,
j.JobMetaNonWarranty?.AccountingChargeRequiredDate,
j.JobMetaNonWarranty?.AccountingChargeAddedDate,
j.JobMetaNonWarranty?.AccountingChargePaidDate,
j.JobMetaNonWarranty?.IsInsuranceClaim,
j.JobMetaInsurance?.ClaimFormSentDate,
j.WaitingForUserAction,
j.DeviceReadyForReturn,
j.DeviceReturnedDate);
}
public static string CalculateStatusId(this JobTableStatusItemModel j)
{
if (j.ClosedDate.HasValue)
return CalculateStatusId(
j.ClosedDate,
j.JobTypeId,
j.JobMetaWarranty_ExternalLoggedDate,
j.JobMetaWarranty_ExternalCompletedDate,
j.JobMetaNonWarranty_RepairerLoggedDate,
j.JobMetaNonWarranty_RepairerCompletedDate,
j.JobMetaNonWarranty_AccountingChargeRequiredDate,
j.JobMetaNonWarranty_AccountingChargeAddedDate,
j.JobMetaNonWarranty_AccountingChargePaidDate,
j.JobMetaNonWarranty_IsInsuranceClaim,
j.JobMetaInsurance_ClaimFormSentDate,
j.WaitingForUserAction,
j.DeviceReadyForReturn,
j.DeviceReturnedDate);
}
public static string CalculateStatusId(
DateTime? closedDate,
string jobTypeId,
DateTime? warrantyExternallyLoggedDate,
DateTime? warrantyExternallyCompletedDate,
DateTime? nonWarrantyRepairerLoggedDate,
DateTime? nonWarrantyRepairerCompletedDate,
DateTime? nonWarrantyAccountingChargeRequiredDate,
DateTime? nonWarrantyAccountintChargeAddedDate,
DateTime? nonWarrantyAccountintChargePaidDate,
bool? nonWarrantyIsInsuranceClaim,
DateTime? insuranceClaimFormSentDate,
DateTime? waitingForUserActionDate,
DateTime? deviceReadyForReturnDate,
DateTime? deviceReturnedDate)
{
if (closedDate.HasValue)
return Job.JobStatusIds.Closed;
if (j.JobTypeId == JobType.JobTypeIds.HWar)
if (jobTypeId == JobType.JobTypeIds.HWar)
{
if (j.JobMetaWarranty_ExternalLoggedDate.HasValue && !j.JobMetaWarranty_ExternalCompletedDate.HasValue)
if (warrantyExternallyLoggedDate.HasValue && !warrantyExternallyCompletedDate.HasValue)
return Job.JobStatusIds.AwaitingWarrantyRepair; // Job Logged - but not marked as completed
}
if (j.JobTypeId == JobType.JobTypeIds.HNWar)
if (jobTypeId == JobType.JobTypeIds.HNWar)
{
if (j.JobMetaNonWarranty_RepairerLoggedDate.HasValue && !j.JobMetaNonWarranty_RepairerCompletedDate.HasValue)
if (nonWarrantyRepairerLoggedDate.HasValue && !nonWarrantyRepairerCompletedDate.HasValue)
return Job.JobStatusIds.AwaitingRepairs; // Repairs logged - but not complete
if (j.JobMetaNonWarranty_AccountingChargeAddedDate.HasValue && !j.JobMetaNonWarranty_AccountingChargePaidDate.HasValue)
if (nonWarrantyAccountintChargeAddedDate.HasValue && !nonWarrantyAccountintChargePaidDate.HasValue)
return Job.JobStatusIds.AwaitingAccountingPayment; // Accounting Charge Added, but not paid
if (j.JobMetaNonWarranty_AccountingChargeRequiredDate.HasValue && (!j.JobMetaNonWarranty_AccountingChargePaidDate.HasValue || !j.JobMetaNonWarranty_AccountingChargeAddedDate.HasValue))
if (nonWarrantyAccountingChargeRequiredDate.HasValue && (!nonWarrantyAccountintChargePaidDate.HasValue || !nonWarrantyAccountintChargeAddedDate.HasValue))
return Job.JobStatusIds.AwaitingAccountingCharge; // Accounting Charge Required, but not added or paid
if (j.JobMetaNonWarranty_RepairerLoggedDate.HasValue && j.JobMetaNonWarranty_IsInsuranceClaim.Value && !j.JobMetaInsurance_ClaimFormSentDate.HasValue)
if (nonWarrantyRepairerLoggedDate.HasValue && nonWarrantyIsInsuranceClaim.GetValueOrDefault() && !insuranceClaimFormSentDate.HasValue)
return Job.JobStatusIds.AwaitingInsuranceProcessing; // Is insurance claim, but no Claim Form Sent
}
if (j.WaitingForUserAction.HasValue)
if (waitingForUserActionDate.HasValue)
return Job.JobStatusIds.AwaitingUserAction; // Awaiting for User
if (j.DeviceReadyForReturn.HasValue && !j.DeviceReturnedDate.HasValue)
if (deviceReadyForReturnDate.HasValue && !deviceReturnedDate.HasValue)
return Job.JobStatusIds.AwaitingDeviceReturn; // Device not returned to User
return Job.JobStatusIds.Open;
@@ -1,7 +1,7 @@
using Disco.Data.Repository;
using Disco.Data.Repository.Monitor;
using Disco.Models.Repository;
using Disco.Models.Services.Job.Statistics;
using Disco.Models.Services.Jobs.Statistics;
using Disco.Services.Tasks;
using Quartz;
using System;