initial source commit
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Disco.Models.BI.Job;
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.BI.Extensions;
|
||||
|
||||
namespace Disco.BI.JobBI
|
||||
{
|
||||
public static class Searching
|
||||
{
|
||||
public static JobTableModel Search(DiscoDataContext dbContext, string Term, int? LimitCount = null, bool IncludeJobStatus = true, bool SearchDetails = false)
|
||||
{
|
||||
int termInt = default(int);
|
||||
|
||||
IQueryable<Job> query = default(IQueryable<Job>);
|
||||
|
||||
if (int.TryParse(Term, out termInt))
|
||||
{
|
||||
// Term is a Number (int)
|
||||
if (SearchDetails)
|
||||
{
|
||||
query = BuildJobTableModel(dbContext).Where(j =>
|
||||
j.Id == termInt ||
|
||||
j.DeviceHeldLocation.Contains(Term) ||
|
||||
j.Device.SerialNumber.Contains(Term) ||
|
||||
j.Device.AssetNumber.Contains(Term) ||
|
||||
j.User.Id == Term ||
|
||||
j.User.Surname.Contains(Term) ||
|
||||
j.User.GivenName.Contains(Term) ||
|
||||
j.User.DisplayName.Contains(Term) ||
|
||||
j.JobLogs.Any(jl => jl.Comments.Contains(Term)) ||
|
||||
j.JobAttachments.Any(ja => ja.Comments.Contains(Term)));
|
||||
}
|
||||
else
|
||||
{
|
||||
query = BuildJobTableModel(dbContext).Where(j =>
|
||||
j.Id == termInt ||
|
||||
j.DeviceHeldLocation.Contains(Term) ||
|
||||
j.Device.SerialNumber.Contains(Term) ||
|
||||
j.Device.AssetNumber.Contains(Term) ||
|
||||
j.User.Id == Term ||
|
||||
j.User.Surname.Contains(Term) ||
|
||||
j.User.GivenName.Contains(Term) ||
|
||||
j.User.DisplayName.Contains(Term));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SearchDetails)
|
||||
{
|
||||
query = BuildJobTableModel(dbContext).Where(j =>
|
||||
j.DeviceHeldLocation.Contains(Term) ||
|
||||
j.Device.SerialNumber.Contains(Term) ||
|
||||
j.Device.AssetNumber.Contains(Term) ||
|
||||
j.User.Id == Term ||
|
||||
j.User.Surname.Contains(Term) ||
|
||||
j.User.GivenName.Contains(Term) ||
|
||||
j.User.DisplayName.Contains(Term) ||
|
||||
j.JobLogs.Any(jl => jl.Comments.Contains(Term)) ||
|
||||
j.JobAttachments.Any(ja => ja.Comments.Contains(Term)));
|
||||
}
|
||||
else
|
||||
{
|
||||
query = BuildJobTableModel(dbContext).Where(j =>
|
||||
j.DeviceHeldLocation.Contains(Term) ||
|
||||
j.Device.SerialNumber.Contains(Term) ||
|
||||
j.Device.AssetNumber.Contains(Term) ||
|
||||
j.User.Id == Term ||
|
||||
j.User.Surname.Contains(Term) ||
|
||||
j.User.GivenName.Contains(Term) ||
|
||||
j.User.DisplayName.Contains(Term));
|
||||
}
|
||||
}
|
||||
|
||||
if (LimitCount.HasValue)
|
||||
query = query.Take(LimitCount.Value);
|
||||
|
||||
JobTableModel model = new JobTableModel() { ShowStatus = IncludeJobStatus };
|
||||
model.Fill(dbContext, query);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public static IQueryable<Job> BuildJobTableModel(DiscoDataContext dbContext)
|
||||
{
|
||||
return dbContext.Jobs.Include("JobType").Include("Device").Include("User").Include("OpenedTechUser");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Quartz;
|
||||
using Disco.Models.BI.Job.Statistics;
|
||||
using Disco.Data.Repository;
|
||||
using Quartz.Impl;
|
||||
using Disco.Services.Tasks;
|
||||
|
||||
namespace Disco.BI.JobBI.Statistics
|
||||
{
|
||||
public class DailyOpenedClosed : ScheduledTask
|
||||
{
|
||||
|
||||
private static List<DailyOpenedClosedItem> _data;
|
||||
private static object _dataLock = new object();
|
||||
|
||||
|
||||
public override string TaskName { get { return "Job Statistics - Daily Opened/Closed Task"; } }
|
||||
public override bool SingleInstanceTask { get { return true; } }
|
||||
public override bool CancelInitiallySupported { get { return false; } }
|
||||
|
||||
public override void InitalizeScheduledTask(DiscoDataContext dbContext)
|
||||
{
|
||||
// Trigger Daily @ 12:29am
|
||||
TriggerBuilder triggerBuilder = TriggerBuilder.Create().WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(0, 29));
|
||||
|
||||
this.ScheduleTask(triggerBuilder);
|
||||
}
|
||||
protected override void ExecuteTask()
|
||||
{
|
||||
using (var dbContext = new DiscoDataContext())
|
||||
{
|
||||
UpdateDataHistory(dbContext, true);
|
||||
}
|
||||
}
|
||||
|
||||
//public void InitalizeScheduledTask(DiscoDataContext dbContext, IScheduler Scheduler)
|
||||
//{
|
||||
// // Run @ 12:29am
|
||||
// IJobDetail jobDetail = new JobDetailImpl("JobStatisticsDailyOpenedClosed", typeof(DailyOpenedClosed));
|
||||
// ITrigger trigger = TriggerBuilder.Create().
|
||||
// WithIdentity("JobStatisticsDailyOpenedClosedTrigger").
|
||||
// StartNow().
|
||||
// WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(0, 29)).
|
||||
// Build();
|
||||
// Scheduler.ScheduleJob(jobDetail, trigger);
|
||||
//}
|
||||
|
||||
//public void Execute(IJobExecutionContext context)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// using (var dbContext = new DiscoDataContext())
|
||||
// {
|
||||
// UpdateDataHistory(dbContext, true);
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Logging.SystemLog.LogException("Disco.BI.JobBI.Statistics.DailyOpenedClosed", ex);
|
||||
// }
|
||||
//}
|
||||
|
||||
private static void UpdateDataHistory(DiscoDataContext dbContext, bool Refresh = false)
|
||||
{
|
||||
DateTime historyEnd = DateTime.Now.AddDays(-1).Date;
|
||||
|
||||
if (Refresh || _data == null || _data.Count == 0 || _data.Last().Timestamp < historyEnd)
|
||||
{
|
||||
lock (_dataLock)
|
||||
{
|
||||
if (Refresh || _data == null || _data.Count == 0 || _data.Last().Timestamp < historyEnd)
|
||||
{
|
||||
DateTime historyStart = DateTime.Now.AddDays(-28).Date;
|
||||
|
||||
// Initialize Memory Store
|
||||
List<DailyOpenedClosedItem> resultData;
|
||||
if (Refresh || _data == null)
|
||||
resultData = new List<DailyOpenedClosedItem>();
|
||||
else
|
||||
resultData = _data;
|
||||
|
||||
// Remove Old Data
|
||||
while (resultData.Count > 0 && resultData[0].Timestamp < historyStart)
|
||||
resultData.RemoveAt(0);
|
||||
|
||||
// Calculate Update Scope
|
||||
DateTime processDate = historyStart;
|
||||
if (resultData.Count > 0)
|
||||
processDate = resultData.Last().Timestamp.AddDays(-1);
|
||||
|
||||
// Cache Data
|
||||
while (processDate <= historyEnd)
|
||||
{
|
||||
resultData.Add(Data(dbContext, processDate));
|
||||
processDate = processDate.AddDays(1);
|
||||
}
|
||||
|
||||
_data = resultData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static DailyOpenedClosedItem Data(DiscoDataContext dbContext, DateTime ProcessDate)
|
||||
{
|
||||
DateTime processDateStart = ProcessDate;
|
||||
DateTime processDateEnd = ProcessDate.AddDays(1);
|
||||
|
||||
int totalJobs = dbContext.Jobs.Where(j => j.OpenedDate < processDateEnd && (!j.ClosedDate.HasValue || j.ClosedDate > processDateEnd)).Count();
|
||||
int openedJobs = dbContext.Jobs.Where(j => j.OpenedDate > processDateStart && j.OpenedDate < processDateEnd).Count();
|
||||
int closedJobs = dbContext.Jobs.Where(j => j.ClosedDate > processDateStart && j.ClosedDate < processDateEnd).Count();
|
||||
|
||||
return new DailyOpenedClosedItem()
|
||||
{
|
||||
Timestamp = ProcessDate,
|
||||
TotalJobs = totalJobs,
|
||||
OpenedJobs = openedJobs,
|
||||
ClosedJobs = closedJobs
|
||||
};
|
||||
}
|
||||
|
||||
public static List<DailyOpenedClosedItem> Data(DiscoDataContext dbContext, bool FilterUnimportantWeekends = false)
|
||||
{
|
||||
List<DailyOpenedClosedItem> resultData;
|
||||
|
||||
UpdateDataHistory(dbContext);
|
||||
|
||||
if (FilterUnimportantWeekends)
|
||||
resultData = _data.Where(i => (i.Timestamp.DayOfWeek != DayOfWeek.Saturday && i.Timestamp.DayOfWeek != DayOfWeek.Sunday) ||
|
||||
(i.OpenedJobs > 0 || i.ClosedJobs > 0)).ToList();
|
||||
else
|
||||
resultData = _data.ToList();
|
||||
|
||||
resultData.Add(Data(dbContext, DateTime.Today));
|
||||
|
||||
return resultData;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.BI.Job;
|
||||
|
||||
namespace Disco.BI.JobBI
|
||||
{
|
||||
public static class Utilities
|
||||
{
|
||||
public static Job Create(DiscoDataContext dbContext, Device device, User user, JobType type, List<JobSubType> subTypes, User initialTech)
|
||||
{
|
||||
Job j = new Job()
|
||||
{
|
||||
JobType = type,
|
||||
OpenedTechUserId = initialTech.Id,
|
||||
OpenedTechUser = initialTech,
|
||||
OpenedDate = DateTime.Now
|
||||
};
|
||||
|
||||
// Device
|
||||
if (device != null)
|
||||
{
|
||||
j.Device = device;
|
||||
j.DeviceSerialNumber = device.SerialNumber;
|
||||
}
|
||||
|
||||
// User
|
||||
if (user != null)
|
||||
{
|
||||
j.User = user;
|
||||
j.UserId = user.Id;
|
||||
}
|
||||
|
||||
// Sub Types
|
||||
List<JobSubType> jobSubTypes = subTypes.ToList();
|
||||
j.JobSubTypes = jobSubTypes;
|
||||
|
||||
dbContext.Jobs.Add(j);
|
||||
|
||||
switch (type.Id)
|
||||
{
|
||||
case JobType.JobTypeIds.HWar:
|
||||
dbContext.JobMetaWarranties.Add(new JobMetaWarranty() { Job = j });
|
||||
break;
|
||||
case JobType.JobTypeIds.HNWar:
|
||||
dbContext.JobMetaNonWarranties.Add(new JobMetaNonWarranty() { Job = j });
|
||||
if (device != null)
|
||||
{
|
||||
// Add Job Components
|
||||
var components = dbContext.DeviceComponents.Include("JobSubTypes").Where(c => !c.DeviceModelId.HasValue || c.DeviceModelId == j.Device.DeviceModelId);
|
||||
var addedComponents = new List<DeviceComponent>();
|
||||
foreach (var c in components)
|
||||
{
|
||||
if (c.JobSubTypes.Count == 0)
|
||||
{ // No Filter
|
||||
addedComponents.Add(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var st in c.JobSubTypes)
|
||||
{
|
||||
foreach (var jst in jobSubTypes)
|
||||
{
|
||||
if (st.JobTypeId == jst.JobTypeId && st.Id == jst.Id)
|
||||
{
|
||||
addedComponents.Add(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (addedComponents.Contains(c))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var c in addedComponents)
|
||||
dbContext.JobComponents.Add(new JobComponent()
|
||||
{
|
||||
Job = j,
|
||||
TechUserId = initialTech.Id,
|
||||
Cost = c.Cost,
|
||||
Description = c.Description
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
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, JobTableModel.JobTableItemModelIncludeStatus 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";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user