Created CA follow up worker
This commit is contained in:
67
FabApprovalWorkerService/Services/CorrectiveActionService.cs
Normal file
67
FabApprovalWorkerService/Services/CorrectiveActionService.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using FabApprovalWorkerService.Models;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace FabApprovalWorkerService.Services;
|
||||
|
||||
public interface ICorrectiveActionService {
|
||||
Task<IEnumerable<CorrectiveAction>> GetCorrectiveActionsWithFollowUpInFiveDays();
|
||||
Task CreateCorrectiveActionFollowUpApproval(int caNo, int qaId);
|
||||
}
|
||||
|
||||
public class CorrectiveActionService : ICorrectiveActionService {
|
||||
private readonly ILogger<CorrectiveActionService> _logger;
|
||||
private readonly IDalService _dalService;
|
||||
|
||||
public CorrectiveActionService(ILogger<CorrectiveActionService> logger, IDalService dalService) {
|
||||
_logger = logger ?? throw new ArgumentNullException("ILogger not injected");
|
||||
_dalService = dalService ?? throw new ArgumentNullException("IDalService not injected");
|
||||
}
|
||||
|
||||
public async Task CreateCorrectiveActionFollowUpApproval(int caNo, int qaId) {
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to create a follow up approval for CA {caNo} by QA {qaId}");
|
||||
|
||||
if (caNo <= 0) throw new ArgumentException($"{caNo} is not a valid CA number");
|
||||
if (qaId <= 0) throw new ArgumentException($"{qaId} is not a valid User Id");
|
||||
|
||||
string today = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
|
||||
StringBuilder queryBuilder = new();
|
||||
queryBuilder.Append("insert into Approval (IssueID, RoleName, SubRole, UserID, SubRoleID, ItemStatus, Step, ");
|
||||
queryBuilder.Append("AssignedDate, NotifyDate,RoleAssignedDate, ApprovalType, DocumentTypeID) ");
|
||||
queryBuilder.Append($"values ({caNo}, '8DQAFollowUp', '8DQAFollowUp', {qaId}, 335, 0, 2, ");
|
||||
queryBuilder.Append($"{today}, {today}, {today}, 1, 9);");
|
||||
|
||||
await _dalService.ExecuteAsync(queryBuilder.ToString());
|
||||
} catch (Exception ex) {
|
||||
StringBuilder errMsgBuilder = new();
|
||||
errMsgBuilder.Append($"An exception occurred when attempting to create a follow up approval for CA {caNo} by QA {qaId}. ");
|
||||
errMsgBuilder.Append($"Exception: {ex.Message}");
|
||||
_logger.LogError(errMsgBuilder.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CorrectiveAction>> GetCorrectiveActionsWithFollowUpInFiveDays() {
|
||||
try {
|
||||
_logger.LogInformation("Attempting to get all CAs needing follow up in five days");
|
||||
|
||||
DateTime fiveDaysFromToday = DateTime.Now.Date.AddDays(5);
|
||||
DateTime sixDaysFromToday = DateTime.Now.Date.AddDays(6);
|
||||
|
||||
StringBuilder queryBuilder = new();
|
||||
queryBuilder.Append("select * from _8DCorrectiveAction where ApprovalStatus = 1 and FollowUpDate is not null ");
|
||||
queryBuilder.Append($"and FollowUpDate < '{sixDaysFromToday.ToString("yyyy-MM-dd HH:mm:ss")}' ");
|
||||
queryBuilder.Append($"and FollowUpDate >= '{fiveDaysFromToday.ToString("yyyy-MM-dd HH:mm:ss")}';");
|
||||
|
||||
return (await _dalService.QueryAsync<CorrectiveAction>(queryBuilder.ToString())).ToList();
|
||||
} catch (Exception ex) {
|
||||
StringBuilder errMsgBuilder = new();
|
||||
errMsgBuilder.Append($"An exception occurred when attempting to get all CAs needing follow up in five days. ");
|
||||
errMsgBuilder.Append($"Exception: {ex.Message}");
|
||||
_logger.LogError(errMsgBuilder.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,9 +6,10 @@ namespace FabApprovalWorkerService.Services;
|
||||
|
||||
public interface IECNService {
|
||||
Task<IEnumerable<ECN>> GetExpiringTECNs();
|
||||
Task<IEnumerable<ECN>> GetExpiredTECNs();
|
||||
Task<IEnumerable<ECN>> GetExpiredTECNsInPastDay();
|
||||
Task<IEnumerable<string>> GetTECNNotificationUserEmails();
|
||||
Task<ECN> GetEcnByNumber(int ecnNumber);
|
||||
bool EcnIsExpired(ECN ecn);
|
||||
}
|
||||
|
||||
public class ECNService : IECNService {
|
||||
@ -20,6 +21,31 @@ public class ECNService : IECNService {
|
||||
_dalService = dalService ?? throw new ArgumentNullException("IDalService not injected");
|
||||
}
|
||||
|
||||
public bool EcnIsExpired(ECN ecn) {
|
||||
try {
|
||||
_logger.LogInformation("Attempting to determine if ECN is expired");
|
||||
|
||||
if (ecn is null) throw new ArgumentNullException("ECN cannot be null");
|
||||
|
||||
if (!ecn.IsTECN) return false;
|
||||
if (ecn.CloseDate <= DateTime.Now) return false;
|
||||
|
||||
DateTime tomorrow = DateTime.Now.Date.AddDays(1);
|
||||
|
||||
bool isExpired = (ecn.ExpirationDate < tomorrow) && (ecn.ExtensionDate < tomorrow);
|
||||
|
||||
_logger.LogInformation($"ECN {ecn.ECNNumber} expired: {isExpired}");
|
||||
|
||||
return isExpired;
|
||||
} catch (Exception ex) {
|
||||
StringBuilder errMsgBuilder = new();
|
||||
errMsgBuilder.Append($"An exception occurred when attempting to determine if ECN is expired. ");
|
||||
errMsgBuilder.Append($"Exception: {ex.Message}");
|
||||
_logger.LogError(errMsgBuilder.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ECN> GetEcnByNumber(int ecnNumber) {
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to get ECN {ecnNumber}");
|
||||
@ -42,7 +68,7 @@ public class ECNService : IECNService {
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ECN>> GetExpiredTECNs() {
|
||||
public async Task<IEnumerable<ECN>> GetExpiredTECNsInPastDay() {
|
||||
try {
|
||||
_logger.LogInformation("Attempting to get all TECNs expired in the last day");
|
||||
|
||||
|
@ -29,7 +29,7 @@ public class SmtpService : ISmtpService {
|
||||
string subject,
|
||||
string body) {
|
||||
if (recipients.IsNullOrEmpty()) throw new ArgumentNullException("recipients cannot be null or empty!");
|
||||
if (ccRecipients.IsNullOrEmpty()) throw new ArgumentNullException("ccRecipients cannot be null or empty!");
|
||||
if (ccRecipients is null) throw new ArgumentNullException("ccRecipients cannot be null!");
|
||||
if (subject.IsNullOrEmpty()) throw new ArgumentNullException("subject cannot be null or empty!");
|
||||
if (body.IsNullOrEmpty()) throw new ArgumentNullException("body cannot be null or empty!");
|
||||
|
||||
|
@ -7,12 +7,14 @@ namespace FabApprovalWorkerService.Services;
|
||||
public interface ITrainingService {
|
||||
Task<IEnumerable<int>> GetTrainingIdsForECN(int ecnNumber);
|
||||
Task MarkTrainingAsComplete(int trainingId);
|
||||
Task DeleteTrainingAssignment(int trainingId);
|
||||
Task DeleteTrainingAssignmentsByTrainingId(int trainingId);
|
||||
Task DeleteTrainingAssignmentById(int trainingAssignmentId);
|
||||
Task<IEnumerable<int>> GetTrainingAssignmentIdsForTraining(int trainingId);
|
||||
Task DeleteDocAssignment(int trainingAssignmentId);
|
||||
Task<IEnumerable<TrainingAssignment>> GetActiveTrainingAssignments();
|
||||
Task UpdateTrainingAssignmentLastNotification(int trainingAssignmentId);
|
||||
Task<int> GetEcnNumberByTrainingId(int trainingId);
|
||||
Task<IEnumerable<int>> GetTrainingAssignmentIdsByUserId(int userId);
|
||||
}
|
||||
|
||||
public class TrainingService : ITrainingService {
|
||||
@ -47,22 +49,44 @@ public class TrainingService : ITrainingService {
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteTrainingAssignment(int trainingId) {
|
||||
public async Task DeleteTrainingAssignmentsByTrainingId(int trainingId) {
|
||||
if (trainingId <= 0) throw new ArgumentException($"Invalid training id: {trainingId}");
|
||||
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to delete training assignment {trainingId}");
|
||||
_logger.LogInformation($"Attempting to delete training assignments for training ID {trainingId}");
|
||||
|
||||
StringBuilder queryBuilder = new();
|
||||
queryBuilder.Append($"update TrainingAssignments set Deleted = 1, ");
|
||||
queryBuilder.Append($"DeletedDate = '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}' ");
|
||||
queryBuilder.Append($"where TrainingID = {trainingId} and status = 0;");
|
||||
|
||||
await _dalService.ExecuteAsync(queryBuilder.ToString());
|
||||
} catch (Exception ex) {
|
||||
StringBuilder errMsgBuilder = new();
|
||||
errMsgBuilder.Append($"An exception occurred when attempting to delete training assignments ");
|
||||
errMsgBuilder.Append($"for training id {trainingId}. Exception: {ex.Message}");
|
||||
_logger.LogError(errMsgBuilder.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteTrainingAssignmentById(int trainingAssignmentId) {
|
||||
if (trainingAssignmentId <= 0)
|
||||
throw new ArgumentException($"Invalid training assignment id: {trainingAssignmentId}");
|
||||
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to delete training assignment {trainingAssignmentId}");
|
||||
|
||||
StringBuilder queryBuilder = new();
|
||||
queryBuilder.Append($"update TrainingAssignments set Deleted = 1, ");
|
||||
queryBuilder.Append($"DeletedDate = '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}' ");
|
||||
queryBuilder.Append($"where ID = {trainingAssignmentId};");
|
||||
|
||||
await _dalService.ExecuteAsync(queryBuilder.ToString());
|
||||
} catch (Exception ex) {
|
||||
StringBuilder errMsgBuilder = new();
|
||||
errMsgBuilder.Append($"An exception occurred when attempting to delete training assignment ");
|
||||
errMsgBuilder.Append($"{trainingId}. Exception: {ex.Message}");
|
||||
errMsgBuilder.Append($"{trainingAssignmentId}. Exception: {ex.Message}");
|
||||
_logger.LogError(errMsgBuilder.ToString());
|
||||
throw;
|
||||
}
|
||||
@ -151,7 +175,7 @@ public class TrainingService : ITrainingService {
|
||||
throw new ArgumentException($"{trainingAssignmentId} is not a valid training assignment Id");
|
||||
|
||||
StringBuilder queryBuilder = new();
|
||||
queryBuilder.Append($"update TrainingAssignments set LastNotification = {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
|
||||
queryBuilder.Append($"update TrainingAssignments set LastNotification = '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}'");
|
||||
queryBuilder.Append($"where ID = {trainingAssignmentId};");
|
||||
|
||||
await _dalService.ExecuteAsync(queryBuilder.ToString());
|
||||
@ -186,4 +210,22 @@ public class TrainingService : ITrainingService {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<int>> GetTrainingAssignmentIdsByUserId(int userId) {
|
||||
try {
|
||||
_logger.LogInformation($"Attempting to get all training assignment Ids for user {userId}");
|
||||
|
||||
if (userId <= 0) throw new ArgumentException($"{userId} is not a valid User ID");
|
||||
|
||||
string sql = $"select ID from TrainingAssignments where UserID = {userId};";
|
||||
|
||||
return (await _dalService.QueryAsync<int>(sql)).ToList();
|
||||
} catch (Exception ex) {
|
||||
StringBuilder errMsgBuilder = new();
|
||||
errMsgBuilder.Append($"An exception occurred when attempting to get all training assignment Ids for user {userId}. ");
|
||||
errMsgBuilder.Append($"Exception: {ex.Message}");
|
||||
_logger.LogError(errMsgBuilder.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user