Created approval reminder worker
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user