Created approval reminder worker
This commit is contained in:
65
FabApprovalWorkerService/Services/ApprovalService.cs
Normal file
65
FabApprovalWorkerService/Services/ApprovalService.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
public interface IApprovalService {
|
||||
Task<IEnumerable<Approval>> GetActiveApprovalsWithNotificationOlderThanFiveDays();
|
||||
Task UpdateApproval(Approval approval);
|
||||
}
|
||||
|
||||
public class ApprovalService : IApprovalService {
|
||||
private readonly ILogger<ApprovalService> _logger;
|
||||
private readonly IDalService _dalService;
|
||||
|
||||
public ApprovalService(ILogger<ApprovalService> logger, IDalService dalService) {
|
||||
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
|
||||
_dalService = dalService ?? throw new ArgumentNullException("IDalService not injected");
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Approval>> GetActiveApprovalsWithNotificationOlderThanFiveDays() {
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to get active approvals with notifications older than five days");
|
||||
|
||||
StringBuilder queryBuilder = new();
|
||||
queryBuilder.Append("select * from Approval where ");
|
||||
queryBuilder.Append($"(CompletedDate is null or CompletedDate >= '{DateTimeUtilities.MAX_DT.ToString("yyyy-MM-dd HH:mm")}') and ");
|
||||
queryBuilder.Append($"(NotifyDate is null or NotifyDate < '{DateTimeOffset.Now.AddDays(-5).ToString("yyyy-MM-dd HH:mm")}')");
|
||||
|
||||
IEnumerable<Approval> approvals = await _dalService.QueryAsync<Approval>(queryBuilder.ToString());
|
||||
|
||||
return approvals;
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to get active approvals with notifications older than five days, because {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateApproval(Approval approval) {
|
||||
try {
|
||||
_logger.LogInformation("Attempting to update an approval");
|
||||
|
||||
if (approval is null) throw new ArgumentNullException("Approval cannot be null");
|
||||
|
||||
StringBuilder queryBuilder = new();
|
||||
queryBuilder.Append($"update Approval set IssueID={approval.IssueID}, RoleName='{approval.RoleName}', ");
|
||||
queryBuilder.Append($"SubRole='{approval.SubRole}', UserID={approval.UserID}, SubRoleID={approval.SubRoleID}, ");
|
||||
queryBuilder.Append($"ItemStatus={Convert.ToInt32(approval.ItemStatus)}, Step={approval.Step}, ");
|
||||
queryBuilder.Append($"NotifyDate='{approval.NotifyDate.ToString("yyyy-MM-dd HH:mm:ss")}', ");
|
||||
queryBuilder.Append($"AssignedDate='{approval.AssignedDate.ToString("yyyy-MM-dd HH:mm:ss")}', ");
|
||||
queryBuilder.Append($"CompletedDate='{approval.CompletedDate.ToString("yyyy-MM-dd HH:mm:ss")}', ");
|
||||
queryBuilder.Append($"Comments='{approval.Comments.Replace("'", "''")}', ");
|
||||
queryBuilder.Append($"TaskID={approval.TaskID} ");
|
||||
queryBuilder.Append($"where ApprovalID={approval.ApprovalID};");
|
||||
|
||||
int rowsUpdated = await _dalService.ExecuteAsync(queryBuilder.ToString());
|
||||
|
||||
if (rowsUpdated <= 0) throw new Exception("Unable to update approval in database");
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Approval update failed, because {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
|
||||
using System.Text;
|
||||
|
||||
@ -7,6 +8,8 @@ namespace FabApprovalWorkerService.Services;
|
||||
public interface ICorrectiveActionService {
|
||||
Task<IEnumerable<CorrectiveAction>> GetCorrectiveActionsWithFollowUpInFiveDays();
|
||||
Task CreateCorrectiveActionFollowUpApproval(int caNo, int qaId);
|
||||
Task<bool> CANumberIsActive(int number);
|
||||
Task<CorrectiveAction> GetCorrectiveActionById(int id);
|
||||
}
|
||||
|
||||
public class CorrectiveActionService : ICorrectiveActionService {
|
||||
@ -64,4 +67,43 @@ public class CorrectiveActionService : ICorrectiveActionService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> CANumberIsActive(int number) {
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to determine if {number} is an active CA#");
|
||||
|
||||
if (number <= 0) return false;
|
||||
|
||||
StringBuilder queryBuilder = new();
|
||||
queryBuilder.Append($"select count(CANo) as count from _8DCorrectiveAction ");
|
||||
queryBuilder.Append($"where CANo={number} and ");
|
||||
queryBuilder.Append($"(ClosedDate is null or ClosedDate >= '{DateTimeUtilities.MAX_DT.ToString("yyyy-MM-dd HH:mm")}')");
|
||||
|
||||
int rowsReturned = (await _dalService.QueryAsync<int>(queryBuilder.ToString())).FirstOrDefault();
|
||||
|
||||
return rowsReturned > 0;
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to determine if {number} is an active CA#, because {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<CorrectiveAction> GetCorrectiveActionById(int id) {
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to get CA# {id}");
|
||||
|
||||
if (id <= 0) throw new ArgumentException($"{id} is not a valid CA#");
|
||||
|
||||
string sql = $"select * from _8DCorrectiveAction where CANo={id}";
|
||||
|
||||
CorrectiveAction? ca = (await _dalService.QueryAsync<CorrectiveAction>(sql)).FirstOrDefault();
|
||||
|
||||
if (ca is null) throw new Exception($"no CA found with CA# {id}");
|
||||
|
||||
return ca;
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to get CA# {id}, because {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,10 +21,6 @@ public class DbConnectionService : IDbConnectionService {
|
||||
}
|
||||
|
||||
public IDbConnection GetConnection() {
|
||||
if (_envName.ToLower().Equals("development")) {
|
||||
return new SqliteConnection(_dbConnectionString);
|
||||
} else {
|
||||
return new SqlConnection(_dbConnectionString);
|
||||
}
|
||||
return new SqlConnection(_dbConnectionString);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
|
||||
using System.Text;
|
||||
|
||||
@ -10,6 +11,7 @@ public interface IECNService {
|
||||
Task<IEnumerable<string>> GetTECNNotificationUserEmails();
|
||||
Task<ECN> GetEcnByNumber(int ecnNumber);
|
||||
bool EcnIsExpired(ECN ecn);
|
||||
Task<bool> ECNNumberIsActive(int number);
|
||||
}
|
||||
|
||||
public class ECNService : IECNService {
|
||||
@ -163,4 +165,23 @@ public class ECNService : IECNService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> ECNNumberIsActive(int number) {
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to determine if {number} is a valid ECN#");
|
||||
|
||||
if (number <= 0) return false;
|
||||
|
||||
StringBuilder queryBuilder = new();
|
||||
queryBuilder.Append($"select count(ECNNumber) as count from ECN where ECNNumber={number} and ");
|
||||
queryBuilder.Append($"(CloseDate is null or CloseDate >= '{DateTimeUtilities.MAX_DT.ToString("yyyy-MM-dd HH:mm")}')");
|
||||
|
||||
int rowsReturned = (await _dalService.QueryAsync<int>(queryBuilder.ToString())).FirstOrDefault();
|
||||
|
||||
return rowsReturned > 0;
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to determine if {number} is a valid ECN#, because {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
59
FabApprovalWorkerService/Services/MRBService.cs
Normal file
59
FabApprovalWorkerService/Services/MRBService.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
public interface IMRBService {
|
||||
Task<bool> MRBNumberIsActive(int number);
|
||||
Task<MRB> GetMRBById(int id);
|
||||
}
|
||||
|
||||
public class MRBService : IMRBService {
|
||||
private readonly ILogger<MRBService> _logger;
|
||||
private readonly IDalService _dalService;
|
||||
|
||||
public MRBService(ILogger<MRBService> logger, IDalService dalService) {
|
||||
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
|
||||
_dalService = dalService ?? throw new ArgumentNullException("IDalService not injected");
|
||||
}
|
||||
|
||||
public async Task<bool> MRBNumberIsActive(int number) {
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to determine if {number} is an active MRB#");
|
||||
|
||||
if (number <= 0) return false;
|
||||
|
||||
StringBuilder queryBuilder = new();
|
||||
queryBuilder.Append($"select count(MRBNumber) as count from MRB where MRBNumber={number} and ");
|
||||
queryBuilder.Append($"(CloseDate is null or CloseDate >= '{DateTimeUtilities.MAX_DT.ToString("yyyy-MM-dd HH:mm")}')");
|
||||
|
||||
int rowsReturned = (await _dalService.QueryAsync<int>(queryBuilder.ToString())).FirstOrDefault();
|
||||
|
||||
return rowsReturned > 0;
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to determine if {number} is an active MRB#, because {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<MRB> GetMRBById(int id) {
|
||||
try {
|
||||
_logger.LogInformation("Attempting to get an MRB by ID");
|
||||
|
||||
if (id < 0) throw new ArgumentException("Invalid MRB number");
|
||||
|
||||
string sql = $"select * from MRB where MRBNumber={id}";
|
||||
|
||||
MRB? mrb = (await _dalService.QueryAsync<MRB>(sql)).FirstOrDefault();
|
||||
|
||||
if (mrb is null) throw new Exception($"Unable to get MRB {id}");
|
||||
|
||||
return mrb;
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to get MRB# {id}, because {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
60
FabApprovalWorkerService/Services/PCRBService.cs
Normal file
60
FabApprovalWorkerService/Services/PCRBService.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Utilities;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
public interface IPCRBService {
|
||||
Task<bool> PCRBNumberIsActive(int number);
|
||||
public Task<PCRB> GetPCRBByPlanNumber(int planNumber);
|
||||
}
|
||||
|
||||
public class PCRBService : IPCRBService {
|
||||
private readonly ILogger<PCRBService> _logger;
|
||||
private readonly IDalService _dalService;
|
||||
|
||||
public PCRBService(ILogger<PCRBService> logger, IDalService dalService) {
|
||||
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
|
||||
_dalService = dalService ?? throw new ArgumentNullException("IDalService not injected");
|
||||
}
|
||||
|
||||
public async Task<bool> PCRBNumberIsActive(int number) {
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to determine if {number} is an active PCRB#");
|
||||
|
||||
if (number <= 0) return false;
|
||||
|
||||
StringBuilder queryBuilder = new();
|
||||
queryBuilder.Append("select count(PlanNumber) as count from CCChangeControl ");
|
||||
queryBuilder.Append($"where PlanNumber={number} and ");
|
||||
queryBuilder.Append($"(ClosedDate is null or ClosedDate >= '{DateTimeUtilities.MAX_DT.ToString("yyyy-MM-dd HH:mm")}')");
|
||||
|
||||
int rowsReturned = (await _dalService.QueryAsync<int>(queryBuilder.ToString())).FirstOrDefault();
|
||||
|
||||
return rowsReturned > 0;
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to determine if {number} is an active PCRB#, because {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<PCRB> GetPCRBByPlanNumber(int planNumber) {
|
||||
try {
|
||||
_logger.LogInformation("Attempting to get a PCRB by plan#");
|
||||
|
||||
if (planNumber <= 0) throw new ArgumentException($"{planNumber} is not a valid PCRB#");
|
||||
|
||||
string sql = $"select * from CCChangeControl where PlanNumber={planNumber}";
|
||||
|
||||
PCRB? pcrb = (await _dalService.QueryAsync<PCRB>(sql)).FirstOrDefault();
|
||||
|
||||
if (pcrb is null) throw new Exception($"unable to find PCRB {planNumber}");
|
||||
|
||||
return pcrb;
|
||||
} catch (Exception ex) {
|
||||
_logger.LogError($"Unable to get PCRB# {planNumber}, because {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
@ -66,6 +66,7 @@ public class SmtpService : ISmtpService {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_logger.LogInformation("Not sending email per configuration");
|
||||
messageWasSent = true;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
|
Reference in New Issue
Block a user