fix file alerts

This commit is contained in:
MahanCh
2025-04-16 14:50:53 +03:30
parent e625ed9a6e
commit 535e3943eb
7 changed files with 183 additions and 41 deletions

View File

@@ -1680,6 +1680,10 @@ public static class Tools
}
#endregion
#region Pooya
@@ -1899,15 +1903,18 @@ public static class Tools
public static int GetWorkingDaysDifference(DateTime? fromDate, DateTime? toDate)
{
//var workingDays = PersianDateExtensions.GetWorkingDays(new PersianDateTime(fromDate.ToFarsi()), new PersianDateTime(toDate.ToFarsi()), true);
var workingDays = PersianDateExtensions.GetWorkingDays((DateTime)fromDate, (DateTime)toDate, true);
if (fromDate > toDate)
workingDays *= -1;
return workingDays;
}
#endregion
}

View File

@@ -11,5 +11,5 @@ public interface IFileAlertRepository : IRepository<long, FileAlert>
FileAlertViewModel GetDetails(long id);
void Remove(long id);
List<EditFileAlert> Search(FileAlertSearchModel searchModel);
Task<List<FileAlertViewModel>> GetFileAlerts();
Task<List<FileAlertViewModel>> GetFileAlerts(FileAlertSearchModel searchModel);
}

View File

@@ -14,5 +14,5 @@ public interface IFileAlertApplication
List<EditFileAlert> Search(FileAlertSearchModel searchModel);
List<FileAlertViewModel> GetFilesAlerts(List<FileViewModel> files);
int getMaximumAdditionalDeadlineTimes(int additionalDeadline);
Task<List<FileAlertViewModel>> GetFileAlerts();
Task<List<FileAlertViewModel>> GetFileAlerts(FileAlertSearchModel searchModel);
}

View File

@@ -179,8 +179,8 @@ public class FileAlertApplication : IFileAlertApplication
return 0;
}
public async Task<List<FileAlertViewModel>> GetFileAlerts()
public async Task<List<FileAlertViewModel>> GetFileAlerts(FileAlertSearchModel searchModel)
{
return await _fileAlertRepository.GetFileAlerts();
return await _fileAlertRepository.GetFileAlerts(searchModel);
}
}

View File

@@ -21,13 +21,42 @@ public class PetitionApplication : IPetitionApplication
var petitionIssuanceDate = new DateTime?();
var notificationPetitionDate = new DateTime?();
if (!string.IsNullOrWhiteSpace(command.PetitionNo) ||
!string.IsNullOrWhiteSpace(command.NotificationPetitionDate) ||
!string.IsNullOrWhiteSpace(command.PetitionIssuanceDate) ||
!string.IsNullOrWhiteSpace(command.TotalPenalty))
{
if (string.IsNullOrWhiteSpace(command.PetitionNo))
{
return operation.Failed("لطفا شماره دادنامه خودرا وارد کنید");
}
if (string.IsNullOrWhiteSpace(command.NotificationPetitionDate))
{
return operation.Failed("لطفا تاریخ ابلاغ دادنامه را وارد کنید");
}
if (string.IsNullOrWhiteSpace(command.PetitionIssuanceDate))
{
return operation.Failed("لطفا تاریخ صدور دادنامه را وارد کنید");
}
if (string.IsNullOrWhiteSpace(command.TotalPenalty))
{
return operation.Failed("لطفا جمع نهایی دادنامه را وارد کنید");
}
}
if (command.PetitionIssuanceDate != null)
petitionIssuanceDate = command.PetitionIssuanceDate.ToGeorgianDateTime();
if (command.NotificationPetitionDate != null)
notificationPetitionDate = command.NotificationPetitionDate.ToGeorgianDateTime();
//TODO if
//if(_BoardRepository.Exists(x=>x.Branch == command.Branch))
// operation.Failed("fail message")
@@ -37,7 +66,7 @@ public class PetitionApplication : IPetitionApplication
_petitionRepository.Create(petition);
_petitionRepository.SaveChanges();
return operation.Succcedded(petition.id);
}
@@ -49,6 +78,33 @@ public class PetitionApplication : IPetitionApplication
var petitionIssuanceDate = new DateTime?();
var notificationPetitionDate = new DateTime?();
if (!string.IsNullOrWhiteSpace(command.PetitionNo) ||
!string.IsNullOrWhiteSpace(command.NotificationPetitionDate) ||
!string.IsNullOrWhiteSpace(command.PetitionIssuanceDate) ||
!string.IsNullOrWhiteSpace(command.TotalPenalty))
{
if (string.IsNullOrWhiteSpace(command.PetitionNo))
{
return operation.Failed("لطفا شماره دادنامه خودرا وارد کنید");
}
if (string.IsNullOrWhiteSpace(command.NotificationPetitionDate))
{
return operation.Failed("لطفا تاریخ ابلاغ دادنامه را وارد کنید");
}
if (string.IsNullOrWhiteSpace(command.PetitionIssuanceDate))
{
return operation.Failed("لطفا تاریخ صدور دادنامه را وارد کنید");
}
if (string.IsNullOrWhiteSpace(command.TotalPenalty))
{
return operation.Failed("لطفا جمع نهایی دادنامه را وارد کنید");
}
}
if (command.PetitionIssuanceDate != null)
petitionIssuanceDate = command.PetitionIssuanceDate.ToGeorgianDateTime();
@@ -71,7 +127,7 @@ public class PetitionApplication : IPetitionApplication
{
return _petitionRepository.GetDetails(id);
}
public EditPetition GetDetails(long fileId, int boardTypeId)
{
return _petitionRepository.GetDetails(fileId, boardTypeId);

View File

@@ -65,21 +65,14 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
}
#region Mahan
public async Task<List<FileAlertViewModel>> GetFileAlerts()
public async Task<List<FileAlertViewModel>> GetFileAlerts(FileAlertSearchModel searchModel)
{
var today = DateTime.Today;
var fileAlertsVM = new List<FileAlertViewModel>();
var fileStates = await _context.FileStates.Include(x => x.FileTiming).Select(x => new
{
Id = x.id,
x.FileTiming_Id,
x.State,
x.Title,
x.FileTiming.Deadline
}).ToListAsync();
var files = await _context.Files.Where(x => x.Status == FileEnums.ACTIVE)
var filesQuery = _context.Files.Where(x => x.Status == FileEnums.ACTIVE)
.Include(x => x.BoardsList).ThenInclude(x => x.ProceedingSessionsList)
.Include(x => x.PetitionsList)
.Where(file =>
@@ -97,14 +90,29 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
a.BoardType_Id == 2 && a.DisputeResolutionPetitionDate != new DateTime() &&
a.ProceedingSessionsList.Count == 0))
|| (file.PetitionsList.Any(x => x.BoardType_Id == 2) == false)
).ToListAsync();
);
if (!string.IsNullOrWhiteSpace(searchModel.ArchiveNo))
{
var archiveNo = Convert.ToInt64(searchModel.ArchiveNo);
filesQuery = filesQuery.Where(x => x.ArchiveNo == archiveNo);
}
if (!string.IsNullOrWhiteSpace(searchModel.FileClass))
{
filesQuery = filesQuery.Where(x => x.FileClass == searchModel.FileClass);
}
if (searchModel.UserId > 0)
{
filesQuery = filesQuery.Where(x =>
(x.Client == 1 && x.Reqester == searchModel.UserId) ||
(x.Client == 2 && x.Summoned == searchModel.UserId));
}
var files = await filesQuery.ToListAsync();
var fileWithState = files.Select(x =>
{
if (x.id == 74)
{
}
var state = GetFileState(x);
return new
{
@@ -112,15 +120,43 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
State = state,
StateDate = GetFileStateDate(x, state)
};
}).Where(x => x.StateDate > today).ToList();
}).ToList();
if (searchModel.FileState_Id>0)
{
fileWithState =fileWithState.Where(x => x.State == searchModel.FileState_Id).ToList();
}
fileWithState = fileWithState.Where(x => x.StateDate < today).ToList();
var requesterIds = fileWithState.Select(x => x.File.Reqester);
var summonedIds = fileWithState.Select(x => x.File.Summoned);
var requesterEmployees = await _context.Employees.Where(x => requesterIds.Contains(x.id)).ToListAsync();
var summonedEmployers = await _context.Employers.Where(x => summonedIds.Contains(x.id)).ToListAsync();
var fileStates = await _context.FileStates.Include(x => x.FileTiming).Select(x => new
{
Id = x.id,
x.FileTiming_Id,
x.State,
x.Title,
x.FileTiming.Deadline
}).ToListAsync();
foreach (var file in fileWithState)
{
if (file.File.FileAlertsList.Count == 0)
var clientFullName = file.File.Client == 1
? requesterEmployees.FirstOrDefault(x => x.id == file.File.Reqester)?.FullName
: summonedEmployers.FirstOrDefault(x => x.id == file.File.Summoned)?.FullName ?? "-";
var oppositePersonFullName = file.File.Client == 2
? requesterEmployees.FirstOrDefault(x => x.id == file.File.Reqester)?.FullName
: summonedEmployers.FirstOrDefault(x => x.id == file.File.Summoned)?.FullName ?? "-";
if (file.File.FileAlertsList == null || file.File.FileAlertsList.Count == 0)
{
var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.Where(x => x.State == file.State).FirstOrDefault().Deadline);
var workingDaysDifference = Tools.GetWorkingDaysDifference(today, dueDate);
var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.FirstOrDefault(x => x.State == file.State).Deadline);
var workingDaysDifference = GetDaysWorkingDays(today, dueDate.Value);
if (workingDaysDifference <= 1)
{
@@ -142,7 +178,14 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
Id = fileAlertEntity.id,
FileState_Id = fileAlertEntity.FileState_Id,
File_Id = fileAlertEntity.File_Id,
IsExpired = false
IsExpired = false,
File = new CreateFile()
{
FileClass = file.File.FileClass,
ArchiveNo = file.File.ArchiveNo,
ClientFullName = clientFullName,
OppositePersonFullName = oppositePersonFullName,
}
};
if (workingDaysDifference < 0)
fileAlert.IsExpired = true;
@@ -153,8 +196,8 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
else if (file.File.FileAlertsList.Count == 1)
{
var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.Where(x => x.State == file.State).FirstOrDefault().Deadline);
var workingDaysDifference = Tools.GetWorkingDaysDifference(today, dueDate);
var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.FirstOrDefault(x => x.State == file.State).Deadline);
var workingDaysDifference = GetDaysWorkingDays(today, dueDate.Value);
if (workingDaysDifference <= 1)
{
@@ -174,7 +217,14 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
Id = fileAlertEntity.id,
FileState_Id = fileAlertEntity.FileState_Id,
File_Id = fileAlertEntity.File_Id,
IsExpired = false
IsExpired = false,
File = new CreateFile()
{
FileClass = file.File.FileClass,
ArchiveNo = file.File.ArchiveNo,
ClientFullName = clientFullName,
OppositePersonFullName = oppositePersonFullName,
}
};
if (workingDaysDifference < 0)
fileAlert.IsExpired = true;
@@ -186,8 +236,8 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
else
{
var totalAdditionalDeadline = file.File.FileAlertsList.Sum(x => x.AdditionalDeadline);
var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.Where(x => x.State == file.State).FirstOrDefault().Deadline) + TimeSpan.FromDays(totalAdditionalDeadline);
var workingDaysDifference = Tools.GetWorkingDaysDifference(today, dueDate);
var dueDate = file.StateDate + TimeSpan.FromDays(fileStates.FirstOrDefault(x => x.State == file.State).Deadline) + TimeSpan.FromDays(totalAdditionalDeadline);
var workingDaysDifference = GetDaysWorkingDays(today, dueDate.Value); ;
if (workingDaysDifference <= 1)
{
@@ -208,7 +258,14 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
Id = fileAlertEntity.id,
FileState_Id = fileAlertEntity.FileState_Id,
File_Id = fileAlertEntity.File_Id,
IsExpired = false
IsExpired = false,
File = new CreateFile()
{
FileClass = file.File.FileClass,
ArchiveNo = file.File.ArchiveNo,
ClientFullName = clientFullName,
OppositePersonFullName = oppositePersonFullName,
}
};
if (workingDaysDifference < 0)
fileAlert.IsExpired = true;
@@ -218,7 +275,6 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
}
}
return fileAlertsVM;
}
public int GetFileState(File1 file)
@@ -297,6 +353,30 @@ public class FileAlertRepository : RepositoryBase<long, FileAlert>, IFileAlertRe
return null;
}
}
#endregion
#endregion
public int GetDaysWorkingDays(DateTime startDate, DateTime endDate)
{
int sign = startDate <= endDate ? 1 : -1;
DateTime from = startDate <= endDate ? startDate : endDate;
DateTime to = startDate <= endDate ? endDate : startDate;
int totalDays = (to - from).Days + 1;
int fullWeeks = totalDays / 7;
int remainingDays = totalDays % 7;
int fridays = fullWeeks;
for (int i = 0; i < remainingDays; i++)
{
var currentDay = from.AddDays(i);
if (currentDay.DayOfWeek == DayOfWeek.Friday)
fridays++;
}
var holidays = _context.HolidayItems.Count(x => x.Holidaydate >= from && x.Holidaydate <= to);
return (totalDays - fridays - holidays) * sign;
}
}

View File

@@ -35,11 +35,10 @@ public class AlertsModel : PageModel
var files = _fileApplication.Search(new FileSearchModel
{ ArchiveNo = searchModel.ArchiveNo, FileClass = searchModel.FileClass, Status = FileEnums.ACTIVE });
viewModels = _fileAlertApplication.GetFilesAlerts(files.Where(x=>x.Id == 74).ToList());
viewModels =await _fileAlertApplication.GetFileAlerts();
viewModels =await _fileAlertApplication.GetFileAlerts(searchModel);
if (searchModel.FileState_Id != 0)
viewModels = viewModels.Where(x => x.FileState_Id == searchModel.FileState_Id).ToList();
//if (searchModel.FileState_Id != 0)
// viewModels = viewModels.Where(x => x.FileState_Id == searchModel.FileState_Id).ToList();
var filesId = viewModels.Select(y => y.File_Id).ToList();
@@ -76,7 +75,7 @@ public class AlertsModel : PageModel
.Select(x => new Users { Id = x.Id, FullName = x.FullName }).ToList());
this.searchModel.FileStatesList =
_fileStateApplication.Search(new FileStateSearchModel()).OrderBy(x => x.Id).ToList();
}
}
}
public JsonResult OnPostSetAdditionalDeadline(EditFileAlert fileAlert)