feat: add EmployeeFaceEmbedding integration to CameraController and application logic
This commit is contained in:
@@ -2,12 +2,13 @@ using System.Collections.Generic;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.EmployeeFaceEmbedding;
|
||||
|
||||
public class CreateEmployeeFaceEmbedding
|
||||
public class EmployeeFaceEmbeddingDto
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string EmployeeFullName { get; set; }
|
||||
public long EmployeeId { get; set; }
|
||||
public long WorkshopId { get; set; }
|
||||
public List<double> Embeddings { get; set; }
|
||||
public EmployeeFaceEmbeddingMetadataViewModel Metadata { get; set; }
|
||||
public EmployeeFaceEmbeddingMetadataDto Metadata { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.EmployeeFaceEmbedding;
|
||||
|
||||
public class EmployeeFaceEmbeddingMetadataDto
|
||||
{
|
||||
public double AvgEyeDistanceNormalized { get; set; }
|
||||
public double AvgEyeToFaceRatio { get; set; }
|
||||
public double AvgFaceAspectRatio { get; set; }
|
||||
public double AvgDetectionConfidence { get; set; }
|
||||
public EmployeeFaceEmbeddingKeypointsDto AvgKeypointsNormalized { get; set; }
|
||||
public List<ImageMetadataDto> PerImageMetadata { get; set; }
|
||||
}
|
||||
|
||||
public class EmployeeFaceEmbeddingKeypointsDto
|
||||
{
|
||||
public double[] LeftEye { get; set; }
|
||||
public double[] RightEye { get; set; }
|
||||
public double[] Nose { get; set; }
|
||||
public double[] MouthLeft { get; set; }
|
||||
public double[] MouthRight { get; set; }
|
||||
}
|
||||
|
||||
public class ImageMetadataDto
|
||||
{
|
||||
public double FaceAspectRatio { get; set; }
|
||||
public double EyeDistanceNormalized { get; set; }
|
||||
public double EyeToFaceRatio { get; set; }
|
||||
public double DetectionConfidence { get; set; }
|
||||
public EmployeeFaceEmbeddingKeypointsDto KeypointsNormalized { get; set; }
|
||||
}
|
||||
|
||||
public class EmbeddingHistoryItemDto
|
||||
{
|
||||
public List<double> Embedding { get; set; }
|
||||
public DateTime Timestamp { get; set; }
|
||||
public double Confidence { get; set; }
|
||||
public double RefinementPercentage { get; set; }
|
||||
}
|
||||
|
||||
public class MetadataHistoryItemDto
|
||||
{
|
||||
public EmployeeFaceEmbeddingMetadataDto Metadata { get; set; }
|
||||
public DateTime Timestamp { get; set; }
|
||||
public double Confidence { get; set; }
|
||||
public double RefinementPercentage { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.EmployeeFaceEmbedding;
|
||||
|
||||
public class EmployeeFaceEmbeddingViewModel
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string EmployeeFullName { get; set; }
|
||||
public long EmployeeId { get; set; }
|
||||
public long WorkshopId { get; set; }
|
||||
public List<double> Embeddings { get; set; }
|
||||
public EmployeeFaceEmbeddingMetadataViewModel Metadata { get; set; }
|
||||
public List<EmbeddingHistoryItemViewModel> EmbeddingHistory { get; set; }
|
||||
public List<MetadataHistoryItemViewModel> MetadataHistory { get; set; }
|
||||
public DateTime CreatedAt { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
}
|
||||
|
||||
public class EmployeeFaceEmbeddingMetadataViewModel
|
||||
{
|
||||
public double AvgEyeDistanceNormalized { get; set; }
|
||||
public double AvgEyeToFaceRatio { get; set; }
|
||||
public double AvgFaceAspectRatio { get; set; }
|
||||
public double AvgDetectionConfidence { get; set; }
|
||||
public EmployeeFaceEmbeddingKeypointsViewModel AvgKeypointsNormalized { get; set; }
|
||||
public List<ImageMetadataViewModel> PerImageMetadata { get; set; }
|
||||
}
|
||||
|
||||
public class EmployeeFaceEmbeddingKeypointsViewModel
|
||||
{
|
||||
public double[] LeftEye { get; set; }
|
||||
public double[] RightEye { get; set; }
|
||||
public double[] Nose { get; set; }
|
||||
public double[] MouthLeft { get; set; }
|
||||
public double[] MouthRight { get; set; }
|
||||
}
|
||||
|
||||
public class ImageMetadataViewModel
|
||||
{
|
||||
public double FaceAspectRatio { get; set; }
|
||||
public double EyeDistanceNormalized { get; set; }
|
||||
public double EyeToFaceRatio { get; set; }
|
||||
public double DetectionConfidence { get; set; }
|
||||
public EmployeeFaceEmbeddingKeypointsViewModel KeypointsNormalized { get; set; }
|
||||
}
|
||||
|
||||
public class EmbeddingHistoryItemViewModel
|
||||
{
|
||||
public List<double> Embedding { get; set; }
|
||||
public DateTime Timestamp { get; set; }
|
||||
public double Confidence { get; set; }
|
||||
public double RefinementPercentage { get; set; }
|
||||
}
|
||||
|
||||
public class MetadataHistoryItemViewModel
|
||||
{
|
||||
public EmployeeFaceEmbeddingMetadataViewModel Metadata { get; set; }
|
||||
public DateTime Timestamp { get; set; }
|
||||
public double Confidence { get; set; }
|
||||
public double RefinementPercentage { get; set; }
|
||||
}
|
||||
|
||||
@@ -4,65 +4,40 @@ using System.Threading.Tasks;
|
||||
namespace CompanyManagment.App.Contracts.EmployeeFaceEmbedding;
|
||||
|
||||
/// <summary>
|
||||
/// رابط اپلیکیشن Embedding چهره کارکنان
|
||||
/// مدیریت عملیات مربوط به ذخیره و مدیریت embedding های چهره کارکنان
|
||||
/// سرویس مدیریت Embedding چهره کارکنان
|
||||
/// این سرویس فقط برای دریافت و ارسال داده است و هیچ command-driven نیست
|
||||
/// </summary>
|
||||
public interface IEmployeeFaceEmbeddingApplication
|
||||
{
|
||||
/// <summary>
|
||||
/// ایجاد embedding جدید برای کارمند
|
||||
/// دریافت embedding بر اساس شناسه
|
||||
/// </summary>
|
||||
/// <param name="command">اطلاعات embedding</param>
|
||||
/// <returns>شناسه embedding ایجاد شده</returns>
|
||||
Task<string> CreateAsync(CreateEmployeeFaceEmbedding command);
|
||||
|
||||
/// <summary>
|
||||
/// بهروزرسانی embedding کارمند
|
||||
/// </summary>
|
||||
/// <param name="command">اطلاعات جدید embedding</param>
|
||||
/// <returns>نتیجه عملیات</returns>
|
||||
Task UpdateEmbeddingAsync(UpdateEmployeeFaceEmbedding command);
|
||||
|
||||
/// <summary>
|
||||
/// بهروزرسانی metadata کارمند
|
||||
/// </summary>
|
||||
/// <param name="command">اطلاعات جدید metadata</param>
|
||||
/// <returns>نتیجه عملیات</returns>
|
||||
Task UpdateMetadataAsync(UpdateEmployeeFaceEmbeddingMetadata command);
|
||||
|
||||
/// <summary>
|
||||
/// بهروزرسانی اطلاعات کارمند
|
||||
/// </summary>
|
||||
/// <param name="command">اطلاعات جدید کارمند</param>
|
||||
/// <returns>نتیجه عملیات</returns>
|
||||
Task UpdateEmployeeInfoAsync(UpdateEmployeeInfo command);
|
||||
Task<EmployeeFaceEmbeddingDto> GetByIdAsync(string id);
|
||||
|
||||
/// <summary>
|
||||
/// دریافت embedding بر اساس شناسه کارمند
|
||||
/// </summary>
|
||||
/// <param name="employeeId">شناسه کارمند</param>
|
||||
/// <returns>اطلاعات embedding</returns>
|
||||
Task<EmployeeFaceEmbeddingViewModel> GetByEmployeeIdAsync(long employeeId);
|
||||
Task<EmployeeFaceEmbeddingDto> GetByEmployeeIdAsync(long employeeId);
|
||||
|
||||
/// <summary>
|
||||
/// دریافت لیست embeddings بر اساس شناسه کارگاه
|
||||
/// </summary>
|
||||
/// <param name="workshopId">شناسه کارگاه</param>
|
||||
/// <returns>لیست embeddings</returns>
|
||||
Task<List<EmployeeFaceEmbeddingViewModel>> GetByWorkshopIdAsync(long workshopId);
|
||||
Task<List<EmployeeFaceEmbeddingDto>> GetByWorkshopIdAsync(long workshopId);
|
||||
|
||||
/// <summary>
|
||||
/// دریافت لیست embeddings بر اساس لیست شناسه کارگاهها
|
||||
/// </summary>
|
||||
/// <param name="workshopIds">لیست شناسه کارگاهها</param>
|
||||
/// <returns>لیست embeddings</returns>
|
||||
Task<List<EmployeeFaceEmbeddingViewModel>> GetByWorkshopIdsAsync(List<long> workshopIds);
|
||||
Task<List<EmployeeFaceEmbeddingDto>> GetByWorkshopIdsAsync(List<long> workshopIds);
|
||||
|
||||
/// <summary>
|
||||
/// حذف embedding کارمند
|
||||
/// ذخیره یا بهروزرسانی embedding
|
||||
/// اگر Id وجود داشته باشد، بهروزرسانی میشود، در غیر این صورت ایجاد میشود
|
||||
/// </summary>
|
||||
Task<string> SaveAsync(EmployeeFaceEmbeddingDto dto);
|
||||
|
||||
/// <summary>
|
||||
/// حذف embedding
|
||||
/// </summary>
|
||||
/// <param name="id">شناسه embedding</param>
|
||||
/// <returns>نتیجه عملیات</returns>
|
||||
Task DeleteAsync(string id);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CompanyManagment.App.Contracts.EmployeeFaceEmbedding;
|
||||
|
||||
public class UpdateEmployeeFaceEmbedding
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public List<double> Embeddings { get; set; }
|
||||
public double Confidence { get; set; }
|
||||
public double RefinementPercentage { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace CompanyManagment.App.Contracts.EmployeeFaceEmbedding;
|
||||
|
||||
public class UpdateEmployeeFaceEmbeddingMetadata
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public EmployeeFaceEmbeddingMetadataViewModel Metadata { get; set; }
|
||||
public double Confidence { get; set; }
|
||||
public double RefinementPercentage { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace CompanyManagment.App.Contracts.EmployeeFaceEmbedding;
|
||||
|
||||
public class UpdateEmployeeInfo
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string EmployeeFullName { get; set; }
|
||||
public long WorkshopId { get; set; }
|
||||
}
|
||||
|
||||
@@ -16,91 +16,61 @@ public class EmployeeFaceEmbeddingApplication : IEmployeeFaceEmbeddingApplicatio
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
public async Task<string> CreateAsync(CreateEmployeeFaceEmbedding command)
|
||||
public async Task<EmployeeFaceEmbeddingDto> GetByIdAsync(string id)
|
||||
{
|
||||
var metadata = MapMetadataFromViewModel(command.Metadata);
|
||||
|
||||
var employeeFaceEmbedding = new EmployeeFaceEmbedding(
|
||||
command.EmployeeFullName,
|
||||
command.EmployeeId,
|
||||
command.WorkshopId,
|
||||
command.Embeddings,
|
||||
metadata
|
||||
);
|
||||
|
||||
await _repository.CreateAsync(employeeFaceEmbedding);
|
||||
|
||||
return employeeFaceEmbedding.Id;
|
||||
var entity = await _repository.GetByIdAsync(id);
|
||||
return entity == null ? null : MapToDto(entity);
|
||||
}
|
||||
|
||||
public async Task UpdateEmbeddingAsync(UpdateEmployeeFaceEmbedding command)
|
||||
public async Task<EmployeeFaceEmbeddingDto> GetByEmployeeIdAsync(long employeeId)
|
||||
{
|
||||
var employeeFaceEmbedding = await _repository.GetByIdAsync(command.Id);
|
||||
|
||||
if (employeeFaceEmbedding == null)
|
||||
throw new Exception($"EmployeeFaceEmbedding با شناسه {command.Id} یافت نشد");
|
||||
|
||||
employeeFaceEmbedding.UpdateEmbedding(
|
||||
command.Embeddings,
|
||||
command.Confidence,
|
||||
command.RefinementPercentage
|
||||
);
|
||||
|
||||
await _repository.UpdateAsync(employeeFaceEmbedding);
|
||||
var entity = await _repository.GetByEmployeeIdAsync(employeeId);
|
||||
return entity == null ? null : MapToDto(entity);
|
||||
}
|
||||
|
||||
public async Task UpdateMetadataAsync(UpdateEmployeeFaceEmbeddingMetadata command)
|
||||
public async Task<List<EmployeeFaceEmbeddingDto>> GetByWorkshopIdAsync(long workshopId)
|
||||
{
|
||||
var employeeFaceEmbedding = await _repository.GetByIdAsync(command.Id);
|
||||
|
||||
if (employeeFaceEmbedding == null)
|
||||
throw new Exception($"EmployeeFaceEmbedding با شناسه {command.Id} یافت نشد");
|
||||
|
||||
var metadata = MapMetadataFromViewModel(command.Metadata);
|
||||
|
||||
employeeFaceEmbedding.UpdateMetadata(
|
||||
metadata,
|
||||
command.Confidence,
|
||||
command.RefinementPercentage
|
||||
);
|
||||
|
||||
await _repository.UpdateAsync(employeeFaceEmbedding);
|
||||
var entities = await _repository.GetByWorkshopIdAsync(workshopId);
|
||||
return entities.Select(MapToDto).ToList();
|
||||
}
|
||||
|
||||
public async Task UpdateEmployeeInfoAsync(UpdateEmployeeInfo command)
|
||||
public async Task<List<EmployeeFaceEmbeddingDto>> GetByWorkshopIdsAsync(List<long> workshopIds)
|
||||
{
|
||||
var employeeFaceEmbedding = await _repository.GetByIdAsync(command.Id);
|
||||
|
||||
if (employeeFaceEmbedding == null)
|
||||
throw new Exception($"EmployeeFaceEmbedding با شناسه {command.Id} یافت نشد");
|
||||
|
||||
employeeFaceEmbedding.UpdateEmployeeInfo(
|
||||
command.EmployeeFullName,
|
||||
command.WorkshopId
|
||||
);
|
||||
|
||||
await _repository.UpdateAsync(employeeFaceEmbedding);
|
||||
var entities = await _repository.GetByWorkshopIdsAsync(workshopIds);
|
||||
return entities.Select(MapToDto).ToList();
|
||||
}
|
||||
|
||||
public async Task<EmployeeFaceEmbeddingViewModel> GetByEmployeeIdAsync(long employeeId)
|
||||
public async Task<string> SaveAsync(EmployeeFaceEmbeddingDto dto)
|
||||
{
|
||||
var employeeFaceEmbedding = await _repository.GetByEmployeeIdAsync(employeeId);
|
||||
|
||||
return employeeFaceEmbedding == null ? null : MapToViewModel(employeeFaceEmbedding);
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(dto.Id))
|
||||
{
|
||||
// ایجاد جدید
|
||||
var metadata = MapMetadataFromDto(dto.Metadata);
|
||||
var entity = new EmployeeFaceEmbedding(
|
||||
dto.EmployeeFullName,
|
||||
dto.EmployeeId,
|
||||
dto.WorkshopId,
|
||||
dto.Embeddings,
|
||||
metadata
|
||||
);
|
||||
|
||||
public async Task<List<EmployeeFaceEmbeddingViewModel>> GetByWorkshopIdAsync(long workshopId)
|
||||
{
|
||||
var employeeFaceEmbeddings = await _repository.GetByWorkshopIdAsync(workshopId);
|
||||
|
||||
return employeeFaceEmbeddings.Select(MapToViewModel).ToList();
|
||||
}
|
||||
await _repository.CreateAsync(entity);
|
||||
return entity.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
// بهروزرسانی
|
||||
var entity = await _repository.GetByIdAsync(dto.Id);
|
||||
if (entity == null)
|
||||
throw new Exception($"EmployeeFaceEmbedding با شناسه {dto.Id} یافت نشد");
|
||||
|
||||
public async Task<List<EmployeeFaceEmbeddingViewModel>> GetByWorkshopIdsAsync(List<long> workshopIds)
|
||||
{
|
||||
var employeeFaceEmbeddings = await _repository.GetByWorkshopIdsAsync(workshopIds);
|
||||
|
||||
return employeeFaceEmbeddings.Select(MapToViewModel).ToList();
|
||||
entity.UpdateEmployeeInfo(dto.EmployeeFullName, dto.WorkshopId);
|
||||
entity.UpdateEmbedding(dto.Embeddings, 0, 0);
|
||||
entity.UpdateMetadata(MapMetadataFromDto(dto.Metadata), 0, 0);
|
||||
|
||||
await _repository.UpdateAsync(entity);
|
||||
return entity.Id;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(string id)
|
||||
@@ -110,62 +80,46 @@ public class EmployeeFaceEmbeddingApplication : IEmployeeFaceEmbeddingApplicatio
|
||||
|
||||
#region Mapping Methods
|
||||
|
||||
private EmployeeFaceEmbeddingViewModel MapToViewModel(EmployeeFaceEmbedding entity)
|
||||
private EmployeeFaceEmbeddingDto MapToDto(EmployeeFaceEmbedding entity)
|
||||
{
|
||||
return new EmployeeFaceEmbeddingViewModel
|
||||
return new EmployeeFaceEmbeddingDto
|
||||
{
|
||||
Id = entity.Id,
|
||||
EmployeeFullName = entity.EmployeeFullName,
|
||||
EmployeeId = entity.EmployeeId,
|
||||
WorkshopId = entity.WorkshopId,
|
||||
Embeddings = entity.Embeddings,
|
||||
Metadata = MapMetadataToViewModel(entity.Metadata),
|
||||
EmbeddingHistory = entity.EmbeddingHistory?.Select(x => new EmbeddingHistoryItemViewModel
|
||||
{
|
||||
Embedding = x.Embedding,
|
||||
Timestamp = x.Timestamp,
|
||||
Confidence = x.Confidence,
|
||||
RefinementPercentage = x.RefinementPercentage
|
||||
}).ToList(),
|
||||
MetadataHistory = entity.MetadataHistory?.Select(x => new MetadataHistoryItemViewModel
|
||||
{
|
||||
Metadata = MapMetadataToViewModel(x.Metadata),
|
||||
Timestamp = x.Timestamp,
|
||||
Confidence = x.Confidence,
|
||||
RefinementPercentage = x.RefinementPercentage
|
||||
}).ToList(),
|
||||
CreatedAt = entity.CreatedAt,
|
||||
UpdatedAt = entity.UpdatedAt
|
||||
Metadata = MapMetadataToDto(entity.Metadata)
|
||||
};
|
||||
}
|
||||
|
||||
private EmployeeFaceEmbeddingMetadataViewModel MapMetadataToViewModel(EmployeeFaceEmbeddingMetadata metadata)
|
||||
private EmployeeFaceEmbeddingMetadataDto MapMetadataToDto(EmployeeFaceEmbeddingMetadata metadata)
|
||||
{
|
||||
if (metadata == null) return null;
|
||||
|
||||
return new EmployeeFaceEmbeddingMetadataViewModel
|
||||
return new EmployeeFaceEmbeddingMetadataDto
|
||||
{
|
||||
AvgEyeDistanceNormalized = metadata.AvgEyeDistanceNormalized,
|
||||
AvgEyeToFaceRatio = metadata.AvgEyeToFaceRatio,
|
||||
AvgFaceAspectRatio = metadata.AvgFaceAspectRatio,
|
||||
AvgDetectionConfidence = metadata.AvgDetectionConfidence,
|
||||
AvgKeypointsNormalized = MapKeypointsToViewModel(metadata.AvgKeypointsNormalized),
|
||||
PerImageMetadata = metadata.PerImageMetadata?.Select(x => new ImageMetadataViewModel
|
||||
AvgKeypointsNormalized = MapKeypointsToDto(metadata.AvgKeypointsNormalized),
|
||||
PerImageMetadata = metadata.PerImageMetadata?.Select(x => new ImageMetadataDto
|
||||
{
|
||||
FaceAspectRatio = x.FaceAspectRatio,
|
||||
EyeDistanceNormalized = x.EyeDistanceNormalized,
|
||||
EyeToFaceRatio = x.EyeToFaceRatio,
|
||||
DetectionConfidence = x.DetectionConfidence,
|
||||
KeypointsNormalized = MapKeypointsToViewModel(x.KeypointsNormalized)
|
||||
KeypointsNormalized = MapKeypointsToDto(x.KeypointsNormalized)
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
private EmployeeFaceEmbeddingKeypointsViewModel MapKeypointsToViewModel(EmployeeFaceEmbeddingKeypoints keypoints)
|
||||
private EmployeeFaceEmbeddingKeypointsDto MapKeypointsToDto(EmployeeFaceEmbeddingKeypoints keypoints)
|
||||
{
|
||||
if (keypoints == null) return null;
|
||||
|
||||
return new EmployeeFaceEmbeddingKeypointsViewModel
|
||||
return new EmployeeFaceEmbeddingKeypointsDto
|
||||
{
|
||||
LeftEye = keypoints.LeftEye,
|
||||
RightEye = keypoints.RightEye,
|
||||
@@ -175,39 +129,39 @@ public class EmployeeFaceEmbeddingApplication : IEmployeeFaceEmbeddingApplicatio
|
||||
};
|
||||
}
|
||||
|
||||
private EmployeeFaceEmbeddingMetadata MapMetadataFromViewModel(EmployeeFaceEmbeddingMetadataViewModel viewModel)
|
||||
private EmployeeFaceEmbeddingMetadata MapMetadataFromDto(EmployeeFaceEmbeddingMetadataDto dto)
|
||||
{
|
||||
if (viewModel == null) return null;
|
||||
if (dto == null) return null;
|
||||
|
||||
return new EmployeeFaceEmbeddingMetadata
|
||||
{
|
||||
AvgEyeDistanceNormalized = viewModel.AvgEyeDistanceNormalized,
|
||||
AvgEyeToFaceRatio = viewModel.AvgEyeToFaceRatio,
|
||||
AvgFaceAspectRatio = viewModel.AvgFaceAspectRatio,
|
||||
AvgDetectionConfidence = viewModel.AvgDetectionConfidence,
|
||||
AvgKeypointsNormalized = MapKeypointsFromViewModel(viewModel.AvgKeypointsNormalized),
|
||||
PerImageMetadata = viewModel.PerImageMetadata?.Select(x => new ImageMetadata
|
||||
AvgEyeDistanceNormalized = dto.AvgEyeDistanceNormalized,
|
||||
AvgEyeToFaceRatio = dto.AvgEyeToFaceRatio,
|
||||
AvgFaceAspectRatio = dto.AvgFaceAspectRatio,
|
||||
AvgDetectionConfidence = dto.AvgDetectionConfidence,
|
||||
AvgKeypointsNormalized = MapKeypointsFromDto(dto.AvgKeypointsNormalized),
|
||||
PerImageMetadata = dto.PerImageMetadata?.Select(x => new ImageMetadata
|
||||
{
|
||||
FaceAspectRatio = x.FaceAspectRatio,
|
||||
EyeDistanceNormalized = x.EyeDistanceNormalized,
|
||||
EyeToFaceRatio = x.EyeToFaceRatio,
|
||||
DetectionConfidence = x.DetectionConfidence,
|
||||
KeypointsNormalized = MapKeypointsFromViewModel(x.KeypointsNormalized)
|
||||
KeypointsNormalized = MapKeypointsFromDto(x.KeypointsNormalized)
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
private EmployeeFaceEmbeddingKeypoints MapKeypointsFromViewModel(EmployeeFaceEmbeddingKeypointsViewModel viewModel)
|
||||
private EmployeeFaceEmbeddingKeypoints MapKeypointsFromDto(EmployeeFaceEmbeddingKeypointsDto dto)
|
||||
{
|
||||
if (viewModel == null) return null;
|
||||
if (dto == null) return null;
|
||||
|
||||
return new EmployeeFaceEmbeddingKeypoints
|
||||
{
|
||||
LeftEye = viewModel.LeftEye,
|
||||
RightEye = viewModel.RightEye,
|
||||
Nose = viewModel.Nose,
|
||||
MouthLeft = viewModel.MouthLeft,
|
||||
MouthRight = viewModel.MouthRight
|
||||
LeftEye = dto.LeftEye,
|
||||
RightEye = dto.RightEye,
|
||||
Nose = dto.Nose,
|
||||
MouthLeft = dto.MouthLeft,
|
||||
MouthRight = dto.MouthRight
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -220,9 +220,12 @@ using CompanyManagment.App.Contracts.PaymentInstrument;
|
||||
using CompanyManagment.App.Contracts.PaymentTransaction;
|
||||
using CompanyManagment.App.Contracts.AuthorizedPerson;
|
||||
using Company.Domain.AuthorizedPersonAgg;
|
||||
using Company.Domain.EmployeeFaceEmbeddingAgg;
|
||||
using Company.Domain.InstitutionContractExtensionTempAgg;
|
||||
using Company.Domain.LawAgg;
|
||||
using CompanyManagement.Infrastructure.Mongo.EmployeeFaceEmbeddingRepo;
|
||||
using CompanyManagement.Infrastructure.Mongo.InstitutionContractInsertTempRepo;
|
||||
using CompanyManagment.App.Contracts.EmployeeFaceEmbedding;
|
||||
using CompanyManagment.App.Contracts.Law;
|
||||
using CompanyManagment.EFCore.Repository;
|
||||
|
||||
@@ -479,6 +482,10 @@ public class PersonalBootstrapper
|
||||
|
||||
services
|
||||
.AddTransient<IInstitutionContractExtenstionTempRepository, InstitutionContractExtenstionTempRepository>();
|
||||
|
||||
services.AddTransient<IEmployeeFaceEmbeddingRepository, EmployeeFaceEmbeddingRepository>();
|
||||
services.AddTransient<IEmployeeFaceEmbeddingApplication, EmployeeFaceEmbeddingApplication>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Pooya
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
|
||||
}
|
||||
|
||||
|
||||
public IActionResult OnPostShiftDate()
|
||||
public async Task<IActionResult> OnPostShiftDate()
|
||||
{
|
||||
//var startRollCall = new DateTime(2025, 2, 19);
|
||||
//var rollCalls = _context.RollCalls.Where(x => x.ShiftDate >= startRollCall);
|
||||
@@ -73,12 +73,41 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk
|
||||
//var notEndedRollCalls = rollCalls.Where(x => x.EndDate == null).ToList();
|
||||
//RefactorAllTheRollCallsOnEsfand(endedRollCalls, notEndedRollCalls);
|
||||
//CreateRewardForKebabMahdi().GetAwaiter().GetResult();
|
||||
SetEntityIdForCheckoutValues();
|
||||
SetEntityIdForCheckoutValuesTemp();
|
||||
// SetEntityIdForCheckoutValues();
|
||||
// SetEntityIdForCheckoutValuesTemp();
|
||||
await CreateDadmehrWorkshopFaceEmbedding();
|
||||
ViewData["message"] = "ایجاد شد";
|
||||
return Page();
|
||||
}
|
||||
|
||||
private async System.Threading.Tasks.Task CreateDadmehrWorkshopFaceEmbedding()
|
||||
{
|
||||
|
||||
// ایجاد HttpClient
|
||||
var client = new HttpClient();
|
||||
|
||||
using var formData = new MultipartFormDataContent();
|
||||
formData.Add(new StringContent("123"), "employee_id");
|
||||
formData.Add(new StringContent("456"), "workshop_id");
|
||||
formData.Add(new StringContent("نام کامل کارمند"), "employee_full_name");
|
||||
|
||||
// ارسال درخواست GET
|
||||
var response = await client.PostAsync("http://127.0.0.1:8000/embeddings",
|
||||
formData
|
||||
);
|
||||
|
||||
// یا ارسال درخواست POST با داده JSON
|
||||
// var response = await client.PostAsJsonAsync("https://your-api-url.com/endpoint", new { key = "value" });
|
||||
|
||||
// بررسی وضعیت پاسخ
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var result = await response.Content.ReadAsStringAsync();
|
||||
// یا برای خواندن JSON: var result = await response.Content.ReadFromJsonAsync<YourType>();
|
||||
Console.WriteLine(result);
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult OnPostShiftDateNew()
|
||||
{
|
||||
var startRollCall = new DateTime(2025, 4, 21);
|
||||
|
||||
@@ -13,11 +13,12 @@ using CompanyManagment.App.Contracts.RollCall;
|
||||
using CompanyManagment.App.Contracts.RollCallEmployee;
|
||||
using CompanyManagment.App.Contracts.RollCallService;
|
||||
using CompanyManagment.App.Contracts.Employee;
|
||||
using CompanyManagment.App.Contracts.EmployeeFaceEmbedding;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace ServiceHost.Areas.Camera.Controllers;
|
||||
|
||||
public class CameraController:CameraBaseController
|
||||
public class CameraController : CameraBaseController
|
||||
{
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
private readonly IConfiguration _configuration;
|
||||
@@ -30,6 +31,7 @@ public class CameraController:CameraBaseController
|
||||
private readonly IAccountApplication _accountApplication;
|
||||
private readonly IPasswordHasher _passwordHasher;
|
||||
private readonly ICameraAccountApplication _cameraAccountApplication;
|
||||
private readonly IEmployeeFaceEmbeddingApplication _employeeFaceEmbeddingApplication;
|
||||
|
||||
public CameraController(IWebHostEnvironment webHostEnvironment,
|
||||
IConfiguration configuration,
|
||||
@@ -41,7 +43,8 @@ public class CameraController:CameraBaseController
|
||||
IPersonnelCodeApplication personnelCodeApplication,
|
||||
IAccountApplication accountApplication,
|
||||
IPasswordHasher passwordHasher,
|
||||
ICameraAccountApplication cameraAccountApplication)
|
||||
ICameraAccountApplication cameraAccountApplication,
|
||||
IEmployeeFaceEmbeddingApplication employeeFaceEmbeddingApplication)
|
||||
{
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
_configuration = configuration;
|
||||
@@ -54,55 +57,33 @@ public class CameraController:CameraBaseController
|
||||
_accountApplication = accountApplication;
|
||||
_passwordHasher = passwordHasher;
|
||||
_cameraAccountApplication = cameraAccountApplication;
|
||||
_employeeFaceEmbeddingApplication = employeeFaceEmbeddingApplication;
|
||||
}
|
||||
|
||||
[HttpPost("login")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult CameraLogin([FromBody]CameraLoginRequest request)
|
||||
public IActionResult CameraLogin([FromBody] CameraLoginRequest request)
|
||||
{
|
||||
_accountApplication.CameraLogin(request);
|
||||
return Ok();
|
||||
_accountApplication.CameraLogin(request);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("embedding")]
|
||||
|
||||
[HttpPost("embedding")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult WorkshopEmbedding(long? workshopId = null)
|
||||
public async Task<ActionResult<List<EmployeeFaceEmbeddingDto>>> WorkshopEmbedding([FromBody] long[] workshopIds)
|
||||
{
|
||||
if (!User.Identity?.IsAuthenticated??false)
|
||||
if (!User.Identity?.IsAuthenticated ?? false)
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
try
|
||||
{
|
||||
var filePath = Path.Combine(
|
||||
_webHostEnvironment.WebRootPath,
|
||||
"embeddings.json");
|
||||
|
||||
if (!System.IO.File.Exists(filePath))
|
||||
{
|
||||
return NotFound(new
|
||||
{
|
||||
isSuccess = false,
|
||||
message = "embedding.json not found",
|
||||
path = filePath
|
||||
});
|
||||
}
|
||||
|
||||
var json = System.IO.File.ReadAllText(filePath);
|
||||
return Content(json, "application/json");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return StatusCode(500, new
|
||||
{
|
||||
isSuccess = false,
|
||||
message = "خطا در خواندن فایل embedding.json",
|
||||
error = ex.Message
|
||||
});
|
||||
}
|
||||
var data = await _employeeFaceEmbeddingApplication
|
||||
.GetByWorkshopIdsAsync(workshopIds.ToList());
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("SendPersonelCodeToGetEmployeeId")]
|
||||
public IActionResult SendPersonelCodeToGetEmployeeId(long personelCode, long workshopId)
|
||||
{
|
||||
@@ -124,7 +105,6 @@ public class CameraController:CameraBaseController
|
||||
{
|
||||
isSuccess = false,
|
||||
message = "پرسنل مورد نظر غیر فعال است",
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -150,7 +130,6 @@ public class CameraController:CameraBaseController
|
||||
isSuccess = true,
|
||||
message = "",
|
||||
personId = $"{employeeId}",
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -165,9 +144,7 @@ public class CameraController:CameraBaseController
|
||||
{
|
||||
employeeName = employeeFullName,
|
||||
flag = flagId
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("Out")]
|
||||
@@ -199,7 +176,6 @@ public class CameraController:CameraBaseController
|
||||
WorkshopId = workshopId,
|
||||
EmployeeId = employeeId,
|
||||
StartDate = now,
|
||||
|
||||
};
|
||||
var res = _rollCallApplication.Create(command);
|
||||
if (res.IsSuccedded)
|
||||
@@ -216,13 +192,13 @@ public class CameraController:CameraBaseController
|
||||
isSuccess = false,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("ShowPicture")]
|
||||
public IActionResult ShowPicture(int index, long workshopId, long label)
|
||||
{
|
||||
var filePath = Path.Combine(_webHostEnvironment.ContentRootPath, "Faces", workshopId.ToString(), label.ToString(), $"{index}.jpg");
|
||||
var filePath = Path.Combine(_webHostEnvironment.ContentRootPath, "Faces", workshopId.ToString(),
|
||||
label.ToString(), $"{index}.jpg");
|
||||
|
||||
if (!System.IO.File.Exists(filePath))
|
||||
{
|
||||
@@ -272,7 +248,6 @@ public class CameraController:CameraBaseController
|
||||
return new JsonResult(new
|
||||
{
|
||||
isSuccess = true,
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -281,7 +256,6 @@ public class CameraController:CameraBaseController
|
||||
isSuccess = false,
|
||||
errorMessage = "گذرواژه اشتباه است",
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("Logout")]
|
||||
@@ -290,5 +264,4 @@ public class CameraController:CameraBaseController
|
||||
_accountApplication.Logout();
|
||||
return new JsonResult(new { isSuccess = true });
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user