Compare commits

...

3 Commits

7 changed files with 343 additions and 29 deletions

View File

@@ -66,4 +66,9 @@ public class File1 : EntityBase
Description = description;
Status = status;
}
public void ChangeStatus(int status)
{
Status = status;
}
}

View File

@@ -531,6 +531,11 @@ namespace Company.Domain.RollCallAgg
FridayWorkTimeSpan = CalculateFridayWorkDuration(StartDate.Value, EndDate.Value);
}
public void SetStartDate(DateTime start)
{
StartDate = start;
}
/// <summary>
/// جیزه
/// </summary>

View File

@@ -7,6 +7,7 @@ public class InstitutionContractExtensionCompleteRequest
public Guid TemporaryId { get; set; }
public bool IsInstallment { get; set; }
public long LawId { get; set; }
public bool CancelSendVerificationSms { get; set; }
}
public class InstitutionContractCreationCompleteRequest

View File

@@ -2269,7 +2269,8 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
extenstionTemp
);
var workshopIds = prevInstitutionContracts.WorkshopGroup?.CurrentWorkshops?.Select(x => x.WorkshopId.Value)??[];
var workshopIds = prevInstitutionContracts.WorkshopGroup?.CurrentWorkshops?.Select(x => x.WorkshopId.Value) ??
[];
var workshopsNotInInstitution = employerWorkshopIds.Where(x => !workshopIds.Contains(x)).ToList();
@@ -2317,7 +2318,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
WorkshopId = workshop?.id ?? 0,
RollCallInPerson = service.RollCallInPerson
};
}).ToList()??[];
}).ToList() ?? [];
var notIncludeWorskhopsLeftWork = await _context.LeftWorkList
.Where(x => workshopsNotInInstitution.Contains(x.WorkshopId) && x.StartWorkDate <= DateTime.Now &&
x.LeftWorkDate >= DateTime.Now)
@@ -2959,8 +2960,11 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
await SaveChangesAsync();
await _smsService.SendInstitutionCreationVerificationLink(contractingParty.Phone, contractingPartyFullName,
entity.PublicId, contractingParty.id, entity.id);
if (!request.CancelSendVerificationSms)
{
await _smsService.SendInstitutionCreationVerificationLink(contractingParty.Phone, contractingPartyFullName,
entity.PublicId, contractingParty.id, entity.id);
}
await SaveChangesAsync();
@@ -3363,10 +3367,10 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
institution.VerificationStatus == InstitutionContractVerificationStatus.PendingForVerify
? null
: institution.VerifierFullName,
VerifierPhoneNumber =
VerifierPhoneNumber =
institution.VerificationStatus == InstitutionContractVerificationStatus.PendingForVerify
? null
: institution.VerifierPhoneNumber,
? null
: institution.VerifierPhoneNumber,
VerifyCode = institution.VerificationStatus == InstitutionContractVerificationStatus.PendingForVerify
? null
: institution.VerifyCode,
@@ -4366,8 +4370,8 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
bool tempCreated = false;
if (creationTemp == null)
{
creationTemp = new InstitutionContractCreationTemp();
await _institutionContractCreationTemp.InsertOneAsync(creationTemp);
creationTemp = new InstitutionContractCreationTemp();
await _institutionContractCreationTemp.InsertOneAsync(creationTemp);
}
List<WorkshopTempViewModel> workshopDetails = [];
@@ -5109,9 +5113,11 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
await SaveChangesAsync();
await _smsService.SendInstitutionCreationVerificationLink(contractingParty.Phone, contractingPartyFullName,
entity.PublicId, contractingParty.id, entity.id);
if (!request.CancelSendVerificationSms)
{
await _smsService.SendInstitutionCreationVerificationLink(contractingParty.Phone, contractingPartyFullName,
entity.PublicId, contractingParty.id, entity.id);
}
await SaveChangesAsync();
await transaction.CommitAsync();

View File

@@ -95,7 +95,7 @@ public class FileUploadService : IFileUploadService
await _fileRepository.SaveChangesAsync();
// آپلود فایل به استوریج
var categoryFolder = GetCategoryFolderName(category);
var categoryFolder = category.ToString();
var uploadResult = await _fileStorageService.UploadAsync(
fileStream,
uploadedFile.UniqueFileName,
@@ -227,21 +227,5 @@ public class FileUploadService : IFileUploadService
return FileType.Document;
}
/// <summary>
/// دریافت نام پوشه بر اساس دسته‌بندی
/// </summary>
private string GetCategoryFolderName(FileCategory category)
{
return category switch
{
FileCategory.TaskChatMessage => "TaskChatMessage",
FileCategory.TaskAttachment => "TaskAttachment",
FileCategory.ProjectDocument => "ProjectDocument",
FileCategory.UserProfilePhoto => "UserProfilePhoto",
FileCategory.Report => "Report",
_ => "Other"
};
}
}

View File

@@ -0,0 +1,157 @@
@page
@model ServiceHost.Areas.AdminNew.Pages.Company.ExcelUpload.IndexModel
@{
ViewData["Title"] = "بارگذاری فایل اکسل";
}
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">بارگذاری و بررسی فایل اکسل</h3>
</div>
<div class="card-body">
<form method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="ExcelFile">انتخاب فایل اکسل (ستون B و C از ردیف 2 به بعد خوانده می‌شود):</label>
<input type="file" class="form-control" id="ExcelFile" name="ExcelFile" accept=".xlsx,.xls" required />
</div>
<button type="submit" asp-page-handler="UploadExcel" class="btn btn-primary">بارگذاری و پردازش</button>
</form>
@if (!string.IsNullOrEmpty(Model.Message))
{
<div class="alert alert-info mt-3" role="alert">
@Model.Message
</div>
}
</div>
</div>
</div>
</div>
@if (Model.HasProcessed)
{
<div class="row mt-4">
<!-- دسته اول: فایل‌هایی که در اکسل هستند -->
<div class="col-md-6">
<div class="card">
<div class="card-header bg-success text-white">
<h4 class="card-title mb-0">فایل‌های موجود در اکسل (@Model.FoundInExcel.Count مورد)</h4>
</div>
<div class="card-body" style="max-height: 600px; overflow-y: auto;">
@if (Model.FoundInExcel.Any())
{
<table class="table table-striped table-hover">
<thead>
<tr>
<th>ردیف</th>
<th>شناسه</th>
<th>شماره بایگانی</th>
<th>رده پرونده</th>
<th>وضعیت</th>
<th>عملیات</th>
</tr>
</thead>
<tbody>
@{
int index = 1;
}
@foreach (var item in Model.FoundInExcel)
{
<tr>
<td>@index</td>
<td>@item.ArchiveNo</td>
<td>@item.FileClass</td>
<td>@(item.Status == 2 ? "فعال" : "غیرفعال")</td>
<td>
<button class="btn btn-sm btn-primary">ویرایش</button>
</td>
</tr>
index++;
}
</tbody>
</table>
}
else
{
<p class="text-muted">هیچ موردی یافت نشد.</p>
}
</div>
</div>
</div>
<!-- دسته دوم: فایل‌هایی که در اکسل نیستند -->
<div class="col-md-6">
<div class="card">
<div class="card-header bg-warning text-dark">
<h4 class="card-title mb-0">فایل‌های غیرموجود در اکسل (@Model.NotFoundInExcel.Count مورد)</h4>
</div>
<div class="card-body" style="max-height: 600px; overflow-y: auto;">
@if (Model.NotFoundInExcel.Any())
{
<table class="table table-striped table-hover">
<thead>
<tr>
<th>ردیف</th>
<th>شناسه</th>
<th>شماره بایگانی</th>
<th>رده پرونده</th>
<th>وضعیت</th>
<th>عملیات</th>
</tr>
</thead>
<tbody>
@{
int index2 = 1;
}
@foreach (var item in Model.NotFoundInExcel)
{
<tr>
<td>@index2</td>
<td>@item.ArchiveNo</td>
<td>@item.FileClass</td>
<td>@(item.Status == 2 ? "فعال" : "غیرفعال")</td>
<td>
<button class="btn btn-sm btn-primary">ویرایش</button>
</td>
</tr>
index2++;
}
</tbody>
</table>
}
else
{
<p class="text-muted">هیچ موردی یافت نشد.</p>
}
</div>
</div>
</div>
</div>
}
</div>
<style>
.card {
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
border-radius: 8px;
}
.card-header {
border-radius: 8px 8px 0 0;
}
.table {
margin-bottom: 0;
}
.table thead th {
position: sticky;
top: 0;
background-color: #f8f9fa;
z-index: 10;
}
</style>

View File

@@ -0,0 +1,156 @@
using Company.Domain.File1;
using Company.Domain.RollCallAgg;
using Company.Domain.RollCallAgg.DomainService;
using CompanyManagment.EFCore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using OfficeOpenXml;
namespace ServiceHost.Areas.AdminNew.Pages.Company.ExcelUpload;
public class ExcelRowData
{
public string ColumnB { get; set; }
public string ColumnC { get; set; }
}
public class IndexModel : PageModel
{
private readonly CompanyContext _dbContext;
private readonly IRollCallDomainService _rollCallDomainService;
[BindProperty]
public IFormFile ExcelFile { get; set; }
public string Message { get; set; }
public List<File1> FoundInExcel { get; set; } = new List<File1>();
public List<File1> NotFoundInExcel { get; set; } = new List<File1>();
public List<ExcelRowData> ExcelData { get; set; } = new List<ExcelRowData>();
public bool HasProcessed { get; set; }
public IndexModel(CompanyContext dbContext, IRollCallDomainService rollCallDomainService)
{
_dbContext = dbContext;
_rollCallDomainService = rollCallDomainService;
}
public void OnGet()
{
}
public async Task<IActionResult> OnPostUploadExcel()
{
if (ExcelFile == null || ExcelFile.Length == 0)
{
Message = "لطفا یک فایل اکسل انتخاب کنید.";
return Page();
}
//await NewMethod();
// var rollcall = _dbContext.RollCalls.Where(x => x.id > 361628 && x.id < 362119).ToList();
//
// var diffTime = TimeSpan.FromHours(8) + TimeSpan.FromMinutes(30);
// var NoneRollCalls = rollcall
// .Where(x => x.RollCallModifyType == RollCallModifyType.None && x.EndDate == null).ToList();
// foreach (var noneRollCall in NoneRollCalls)
// {
// noneRollCall.SetStartDate(noneRollCall.StartDate!.Value.Add(diffTime));
// }
// var rollcallIds = NoneRollCalls.Select(x => x.id).ToList();
// var editedRollCall = rollcall.Where(x=>!rollcallIds.Contains(x.id) && x.RollCallModifyType != RollCallModifyType.EditByEmployer).ToList();
//
// foreach (var rollCall in editedRollCall)
// {
// rollCall.Edit(rollCall.StartDate.Value.Add(diffTime),
// rollCall.EndDate.Value.Add(diffTime),_rollCallDomainService);
// }
//
// await _dbContext.SaveChangesAsync();
return Page();
}
private async System.Threading.Tasks.Task NewMethod()
{
try
{
ExcelPackage.License.SetNonCommercialOrganization("Gozareshgir Noncommercial organization");
using (var stream = new MemoryStream())
{
await ExcelFile.CopyToAsync(stream);
stream.Position = 0;
using (var package = new ExcelPackage(stream))
{
var worksheet = package.Workbook.Worksheets[0];
int rowCount = worksheet.Dimension?.Rows ?? 0;
// خواندن مقادیر از ستون B و C از ردیف 2 به بعد
for (int row = 2; row <= rowCount; row++)
{
var columnB = worksheet.Cells[row, 2].Value?.ToString()?.Trim();
var columnC = worksheet.Cells[row, 3].Value?.ToString()?.Trim();
if (!string.IsNullOrWhiteSpace(columnB) || !string.IsNullOrWhiteSpace(columnC))
{
ExcelData.Add(new ExcelRowData
{
ColumnB = columnB ?? "",
ColumnC = columnC ?? ""
});
}
}
}
}
// ساخت HashSet برای سرچ سریع - هر جفت (B, C) رو با هم نگه داری
var excelPairs = new HashSet<(string B, string C)>(
ExcelData.Select(x => (
B: (x.ColumnB ?? "").Trim(),
C: (x.ColumnC ?? "").Trim()
)));
// دریافت تمام داده‌های موجود در دیتابیس
var allFiles = _dbContext.Files.ToList();
// دسته‌بندی: فایل‌هایی که در اکسل هستند و نیستند
foreach (var file in allFiles)
{
var fileB = file.ArchiveNo.ToString();
var fileC = (file.FileClass ?? "").Trim();
// بررسی آیا جفت (B, C) این فایل در اکسل وجود دارد
bool foundInExcel = excelPairs.Contains((fileB, fileC));
if (foundInExcel)
{
FoundInExcel.Add(file);
}
else
{
NotFoundInExcel.Add(file);
}
}
foreach (var file1 in FoundInExcel)
{
file1.ChangeStatus(2);
}
foreach (var file1 in NotFoundInExcel)
{
file1.ChangeStatus(1);
}
await _dbContext.SaveChangesAsync();
HasProcessed = true;
Message = $"پردازش با موفقیت انجام شد. تعداد ردیف‌های اکسل: {ExcelData.Count} | فایل‌های موجود در اکسل: {FoundInExcel.Count} | فایل‌های غیرموجود در اکسل: {NotFoundInExcel.Count}";
}
catch (Exception ex)
{
Message = $"خطا در پردازش فایل: {ex.Message}";
}
}
}