diff --git a/0_Framework/InfraStructure/FaceEmbeddingService.cs b/0_Framework/InfraStructure/FaceEmbeddingService.cs index 50465e5e..0b709ed5 100644 --- a/0_Framework/InfraStructure/FaceEmbeddingService.cs +++ b/0_Framework/InfraStructure/FaceEmbeddingService.cs @@ -21,14 +21,17 @@ public class FaceEmbeddingService : IFaceEmbeddingService private readonly IHttpClientFactory _httpClientFactory; private readonly ILogger _logger; private readonly IFaceEmbeddingNotificationService _notificationService; + private readonly string _apiBaseUrl; - public FaceEmbeddingService(IHttpClientFactory httpClientFactory, ILogger logger) public FaceEmbeddingService(IHttpClientFactory httpClientFactory, ILogger logger, IFaceEmbeddingNotificationService notificationService = null) + { + _httpClientFactory = httpClientFactory; _logger = logger; + _notificationService = notificationService; _apiBaseUrl = "http://localhost:8000"; } - _notificationService = notificationService; + public async Task 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> GetEmbeddingAsync(long employeeId, long workshopId) + { + try + { var httpClient = _httpClientFactory.CreateClient(); httpClient.BaseAddress = new Uri(_apiBaseUrl); httpClient.Timeout = TimeSpan.FromSeconds(30); diff --git a/CompanyManagment.Application/TemporaryClientRegistrationApplication.cs b/CompanyManagment.Application/TemporaryClientRegistrationApplication.cs index fb81f9d6..868c8835 100644 --- a/CompanyManagment.Application/TemporaryClientRegistrationApplication.cs +++ b/CompanyManagment.Application/TemporaryClientRegistrationApplication.cs @@ -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}"); diff --git a/CompanyManagment.EFCore/Services/UidService.cs b/CompanyManagment.EFCore/Services/UidService.cs index ec721347..c48d754d 100644 --- a/CompanyManagment.EFCore/Services/UidService.cs +++ b/CompanyManagment.EFCore/Services/UidService.cs @@ -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(); @@ -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, ""))); diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs index 64530132..f4b1e222 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs @@ -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 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 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 OnPostPaymentGateWay(CancellationToken cancellationToken) { var command = new CreatePaymentGatewayRequest()