From 23b65cfbfe3f4b28703f3f9c471e94b7768b0a3d Mon Sep 17 00:00:00 2001 From: SamSys Date: Wed, 7 Jan 2026 16:59:21 +0330 Subject: [PATCH] GetSms Report Expand List --- .../SmsResult/Dto/SmsReportDto.cs | 43 +++++- .../Repository/SmsResultRepository.cs | 141 ++++++++++++++++++ 2 files changed, 183 insertions(+), 1 deletion(-) diff --git a/CompanyManagment.App.Contracts/SmsResult/Dto/SmsReportDto.cs b/CompanyManagment.App.Contracts/SmsResult/Dto/SmsReportDto.cs index 9158d59d..445ed2b0 100644 --- a/CompanyManagment.App.Contracts/SmsResult/Dto/SmsReportDto.cs +++ b/CompanyManagment.App.Contracts/SmsResult/Dto/SmsReportDto.cs @@ -1,4 +1,6 @@ -namespace CompanyManagment.App.Contracts.SmsResult.Dto; +using System; + +namespace CompanyManagment.App.Contracts.SmsResult.Dto; public class SmsReportDto { @@ -10,4 +12,43 @@ public class SmsReportDto } +public class SmsReportListDto +{ + /// + /// آی دی + /// + public long Id { get; set; } + /// + /// آی دی پیامک در sms.ir + /// + public int MessageId { get; set; } + + /// + /// وضعیت ارسال + /// + public string Status { get; set; } + + /// + /// نوع پیامک + /// + public string TypeOfSms { get; set; } + + /// + /// نام طرف حساب + /// + public string ContractingPartyName { get; set; } + + /// + /// شماره موبایل + /// + public string Mobile { get; set; } + + + /// + /// ساعت و دقیقه + /// + public string HourAndMinute { get; set; } +} + + diff --git a/CompanyManagment.EFCore/Repository/SmsResultRepository.cs b/CompanyManagment.EFCore/Repository/SmsResultRepository.cs index 943b32d1..326def5f 100644 --- a/CompanyManagment.EFCore/Repository/SmsResultRepository.cs +++ b/CompanyManagment.EFCore/Repository/SmsResultRepository.cs @@ -161,6 +161,147 @@ public class SmsResultRepository : RepositoryBase, ISmsResultRe } + public async Task> GetSmsReportExpandList(SmsReportSearchModel searchModel, string date) + { + if (date.TryToGeorgianDateTime(out var searchDate) == false) + return new List(); + var query = _context.SmsResults.Where(x => x.CreationDate == searchDate).Select(x => + new App.Contracts.SmsResult.SmsResultViewModel() + { + Id = x.id, + MessageId = x.MessageId, + Status = x.Status, + TypeOfSms = x.TypeOfSms, + ContractingPartyName = x.ContractingPartyName, + Mobile = x.Mobile, + ContractingPartyId = x.ContractingPatyId, + InstitutionContractId = x.InstitutionContractId, + CreationDate = x.CreationDate, + Hour = x.CreationDate.Hour > 9 ? $"{x.CreationDate.Hour}" : $"0{x.CreationDate.Hour}", + Minute = x.CreationDate.Minute > 9 ? $"{x.CreationDate.Minute}" : $"0{x.CreationDate.Minute}", + + }); + + if (searchModel.ContractingPatyId > 0) + { + query = query.Where(x => x.ContractingPartyId == searchModel.ContractingPatyId); + } + + if (!string.IsNullOrWhiteSpace(searchModel.Mobile)) + { + query = query.Where(x => x.Mobile.Contains(searchModel.Mobile)); + } + + if (searchModel.TypeOfSms != TypeOfSmsSetting.All && searchModel.TypeOfSms != TypeOfSmsSetting.Warning) + { + var typeOfSms = "All"; + switch (searchModel.TypeOfSms) + { + case TypeOfSmsSetting.InstitutionContractDebtReminder: + typeOfSms = "یادآور بدهی ماهانه"; + break; + case TypeOfSmsSetting.MonthlyInstitutionContract: + typeOfSms = "صورت حساب ماهانه"; + break; + case TypeOfSmsSetting.BlockContractingParty: + typeOfSms = "اعلام مسدودی طرف حساب"; + break; + case TypeOfSmsSetting.LegalAction: + typeOfSms = "اقدام قضایی"; + break; + case TypeOfSmsSetting.InstitutionContractConfirm: + typeOfSms = "یادآور تایید قرارداد مالی"; + break; + case TypeOfSmsSetting.SendInstitutionContractConfirmationCode: + typeOfSms = "کد تاییدیه قرارداد مالی"; + break; + case TypeOfSmsSetting.TaskReminder: + typeOfSms = "یادآور وظایف"; + break; + } + + query = query.Where(x => x.TypeOfSms == typeOfSms); + } + + if (searchModel.TypeOfSms == TypeOfSmsSetting.Warning) + { + query = query.Where(x => x.TypeOfSms.Contains("هشدار")); + } + + if (searchModel.SendStatus != SendStatus.All) + { + var status = "All"; + + switch (searchModel.SendStatus) + { + case SendStatus.Success: + status = "موفق"; + break; + case SendStatus.Failed: + status = "ناموفق"; + break; + + + } + + query = query.Where(x => x.Status == status); + + } + + #region searchByDate + + if (!string.IsNullOrWhiteSpace(searchModel.StartDateFa) && + !string.IsNullOrWhiteSpace(searchModel.EndDateFa)) + { + if (searchModel.StartDateFa.TryToGeorgianDateTime(out var startGr) == false || + searchModel.EndDateFa.TryToGeorgianDateTime(out var endGr) == false) + return new List(); + + query = query.Where(x => x.CreationDate.Date >= startGr.Date && x.CreationDate.Date <= endGr.Date); + + } + else + { + if (!string.IsNullOrWhiteSpace(searchModel.Year) && !string.IsNullOrWhiteSpace(searchModel.Month)) + { + var start = searchModel.Year + "/" + searchModel.Month + "/01"; + var end = start.FindeEndOfMonth(); + var startGr = start.ToGeorgianDateTime(); + var endGr = end.ToGeorgianDateTime(); + query = query.Where(x => x.CreationDate.Date >= startGr.Date && x.CreationDate.Date <= endGr.Date); + + + } + else if (!string.IsNullOrWhiteSpace(searchModel.Year) && string.IsNullOrWhiteSpace(searchModel.Month)) + { + var start = searchModel.Year + "/01/01"; + var findEndOfYear = searchModel.Year + "/12/01"; + var end = findEndOfYear.FindeEndOfMonth(); + var startGr = start.ToGeorgianDateTime(); + var endGr = end.ToGeorgianDateTime(); + query = query.Where(x => x.CreationDate.Date >= startGr.Date && x.CreationDate.Date <= endGr.Date); + + } + } + #endregion + var result = await query.OrderByDescending(x => x.CreationDate) + .ThenByDescending(x => x.CreationDate.Hour).ThenByDescending(x => x.CreationDate.Minute).Select(x => + new SmsReportListDto + { + Id = x.Id, + MessageId = x.MessageId, + Status = x.Status, + TypeOfSms = x.TypeOfSms, + ContractingPartyName = x.ContractingPartyName, + Mobile = x.Mobile, + HourAndMinute = $"{x.Hour}:{x.Minute}" + + }).ToListAsync(); + + return result; + + } + #endregion public List Search(SmsResultSearchModel searchModel)