Enhance face embedding service notifications and error handling; add new shift date actions and improve UidService timeout

This commit is contained in:
2025-11-20 10:52:29 +03:30
parent 90d7de4901
commit 933dd3d937
4 changed files with 102 additions and 64 deletions

View File

@@ -21,14 +21,17 @@ public class FaceEmbeddingService : IFaceEmbeddingService
private readonly IHttpClientFactory _httpClientFactory;
private readonly ILogger<FaceEmbeddingService> _logger;
private readonly IFaceEmbeddingNotificationService _notificationService;
private readonly string _apiBaseUrl;
public FaceEmbeddingService(IHttpClientFactory httpClientFactory, ILogger<FaceEmbeddingService> logger)
public FaceEmbeddingService(IHttpClientFactory httpClientFactory, ILogger<FaceEmbeddingService> logger,
IFaceEmbeddingNotificationService notificationService = null)
{
_httpClientFactory = httpClientFactory;
_logger = logger;
_notificationService = notificationService;
_apiBaseUrl = "http://localhost:8000";
}
_notificationService = notificationService;
public async Task<OperationResult> GenerateEmbeddingsAsync(long employeeId, long workshopId,
string employeeFullName, string picture1Path, string picture2Path)
{
@@ -81,15 +84,21 @@ public class FaceEmbeddingService : IFaceEmbeddingService
_logger.LogInformation("Embeddings generated successfully for Employee {EmployeeId}, Workshop {WorkshopId}",
employeeId, workshopId);
return new OperationResult
{
IsSuccedded = true,
// ارسال اطلاع‌رسانی به سایر سیستم‌ها
if (_notificationService != null)
{
await _notificationService.NotifyEmbeddingCreatedAsync(workshopId, employeeId, employeeFullName);
}
return new OperationResult
{
IsSuccedded = true,
Message = "Embedding با موفقیت ایجاد شد"
};
}
else
{
var errorContent = await response.Content.ReadAsStringAsync();
_logger.LogError("Failed to generate embeddings. Status: {StatusCode}, Error: {Error}",
response.StatusCode, errorContent);
@@ -151,6 +160,13 @@ public class FaceEmbeddingService : IFaceEmbeddingService
if (response.IsSuccessStatusCode)
{
_logger.LogInformation("Embeddings generated successfully from streams for Employee {EmployeeId}", employeeId);
// ارسال اطلاع‌رسانی به سایر سیستم‌ها
if (_notificationService != null)
{
await _notificationService.NotifyEmbeddingCreatedAsync(workshopId, employeeId, employeeFullName);
}
return new OperationResult { IsSuccedded = true, Message = "Embedding با موفقیت ایجاد شد" };
}
else
@@ -160,13 +176,13 @@ public class FaceEmbeddingService : IFaceEmbeddingService
response.StatusCode, errorContent);
return new OperationResult
// ارسال اطلاع‌رسانی به سایر سیستم‌ها
if (_notificationService != null)
{
await _notificationService.NotifyEmbeddingCreatedAsync(workshopId, employeeId, employeeFullName);
}
IsSuccedded = false,
Message = $"خطا در تولید Embedding: {response.StatusCode}"
};
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error while generating embeddings from streams for Employee {EmployeeId}", employeeId);
return new OperationResult
@@ -200,6 +216,13 @@ public class FaceEmbeddingService : IFaceEmbeddingService
if (response.IsSuccessStatusCode)
{
_logger.LogInformation("Embedding refined successfully for Employee {EmployeeId}", employeeId);
// ارسال اطلاع‌رسانی به سایر سیستم‌ها
if (_notificationService != null)
{
await _notificationService.NotifyEmbeddingRefinedAsync(workshopId, employeeId);
}
return new OperationResult { IsSuccedded = true, Message = "Embedding بهبود یافت" };
}
else
@@ -216,13 +239,13 @@ public class FaceEmbeddingService : IFaceEmbeddingService
}
}
catch (Exception ex)
// ارسال اطلاع‌رسانی به سایر سیستم‌ها
if (_notificationService != null)
{
await _notificationService.NotifyEmbeddingRefinedAsync(workshopId, employeeId);
}
{
_logger.LogError(ex, "Error while refining embedding for Employee {EmployeeId}", employeeId);
return new OperationResult
{
IsSuccedded = false,
Message = "خطا در بهبود Embedding"
};
}
}
@@ -239,6 +262,13 @@ public class FaceEmbeddingService : IFaceEmbeddingService
if (response.IsSuccessStatusCode)
{
_logger.LogInformation("Embedding deleted successfully for Employee {EmployeeId}", employeeId);
// ارسال اطلاع‌رسانی به سایر سیستم‌ها
if (_notificationService != null)
{
await _notificationService.NotifyEmbeddingDeletedAsync(workshopId, employeeId);
}
return new OperationResult { IsSuccedded = true, Message = "Embedding حذف شد" };
}
else
@@ -262,13 +292,13 @@ public class FaceEmbeddingService : IFaceEmbeddingService
IsSuccedded = false,
Message = "خطا در حذف Embedding"
};
// ارسال اطلاع‌رسانی به سایر سیستم‌ها
if (_notificationService != null)
{
await _notificationService.NotifyEmbeddingDeletedAsync(workshopId, employeeId);
}
}
}
public async Task<OperationResult<FaceEmbeddingResponse>> GetEmbeddingAsync(long employeeId, long workshopId)
{
try
{
var httpClient = _httpClientFactory.CreateClient();
httpClient.BaseAddress = new Uri(_apiBaseUrl);
httpClient.Timeout = TimeSpan.FromSeconds(30);

View File

@@ -209,6 +209,11 @@ public class TemporaryClientRegistrationApplication : ITemporaryClientRegistrati
if (apiRespons.ResponseContext.Status.Code == 14)
throw new InternalServerException("سیستم احراز هویت در دسترس نمی باشد");
if (apiRespons.ResponseContext.Status.Code == 2)
{
throw new InternalServerException("سیستم احراز هویت در دسترس نمی باشد");
}
if (apiRespons.ResponseContext.Status.Code != 0)
return op.Failed($"{apiRespons.ResponseContext.Status.Message}");

View File

@@ -28,7 +28,8 @@ public class UidService : IUidService
{
_httpClient = new HttpClient()
{
BaseAddress = new Uri(BaseUrl)
BaseAddress = new Uri(BaseUrl),
Timeout = new TimeSpan(0, 0, 12)
};
_authorizedPersonApplication = authorizedPersonApplication;
_authorizedBankDetailsApplication = authorizedBankDetailsApplication;
@@ -63,6 +64,7 @@ public class UidService : IUidService
try
{
var requestResult = await _httpClient.PostAsync("inquiry/person/v2", contentType);
if (!requestResult.IsSuccessStatusCode)
return null;
var responseResult = await requestResult.Content.ReadFromJsonAsync<PersonalInfoResponse>();
@@ -79,7 +81,7 @@ public class UidService : IUidService
return responseResult;
}
catch
{
{
return new PersonalInfoResponse(new UidBasicInformation(),
new IdentificationInformation(default, default, default, default, default), new RegistrationStatus(),
new ResponseContext(new UidStatus(14, "")));

View File

@@ -130,7 +130,43 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
}
}
private async System.Threading.Tasks.Task CreateDadmehrWorkshopFaceEmbedding()
public IActionResult OnPostShiftDateNew()
{
var startRollCall = new DateTime(2025, 4, 21);
//var employees = _context.CustomizeWorkshopEmployeeSettings
// .Where(x => x.WorkshopShiftStatus == WorkshopShiftStatus.Rotating).Select(x => x.EmployeeId).ToList();
var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.EndDate != null).ToList();
var r1 = rollCalls.ToList();
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("endStep 1 ============");
SetBreakTime(r1);
ViewData["message"] = "تومام یک";
return Page();
}
public async Task<IActionResult> OnPostShiftDateNew2()
{
//var startRollCall = new DateTime(2025, 3, 21);
//var rollCalls = _context.RollCalls.Where(x => x.StartDate >= startRollCall && x.EndDate != null ).ToList();
//var r1 = rollCalls.Skip(10000).Take(10000).ToList();
//Console.ForegroundColor = ConsoleColor.DarkRed;
//Console.WriteLine("endStep 1 ============");
//SetRollCall(r1);
//await ChangeFridayWorkToWeeklyDayOfWeek();
//await SetPublicId();
await CreateDadmehrWorkshopFaceEmbedding();
ViewData["message"] = "تومام دو";
return Page();
}
private async System.Threading.Tasks.Task CreateDadmehrWorkshopFaceEmbedding()
{
var basePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "faces");
@@ -211,42 +247,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
}
}
}
public IActionResult OnPostShiftDateNew()
{
var startRollCall = new DateTime(2025, 4, 21);
//var employees = _context.CustomizeWorkshopEmployeeSettings
// .Where(x => x.WorkshopShiftStatus == WorkshopShiftStatus.Rotating).Select(x => x.EmployeeId).ToList();
var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall && x.EndDate != null).ToList();
var r1 = rollCalls.ToList();
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.WriteLine("endStep 1 ============");
SetBreakTime(r1);
ViewData["message"] = "تومام یک";
return Page();
}
public async Task<IActionResult> OnPostShiftDateNew2()
{
//var startRollCall = new DateTime(2025, 3, 21);
//var rollCalls = _context.RollCalls.Where(x => x.StartDate >= startRollCall && x.EndDate != null ).ToList();
//var r1 = rollCalls.Skip(10000).Take(10000).ToList();
//Console.ForegroundColor = ConsoleColor.DarkRed;
//Console.WriteLine("endStep 1 ============");
//SetRollCall(r1);
//await ChangeFridayWorkToWeeklyDayOfWeek();
//await SetPublicId();
await UpdateInstitutionContract();
ViewData["message"] = "تومام دو";
return Page();
}
public async Task<IActionResult> OnPostPaymentGateWay(CancellationToken cancellationToken)
{
var command = new CreatePaymentGatewayRequest()