From 4de2e12ac5a4d70301bbe55b0edc222831204605 Mon Sep 17 00:00:00 2001 From: SamSys Date: Wed, 7 Jan 2026 18:38:12 +0330 Subject: [PATCH] AmaApiReport --- .../Application/Sms/ApiResultViewModel.cs | 14 +++ 0_Framework/Application/Sms/ISmsService.cs | 7 ++ .../SmsResultAgg/ISmsResultRepository.cs | 8 ++ .../SmsResult/ISmsResultApplication.cs | 8 ++ .../SmsResultApplication.cs | 5 + .../Repository/SmsResultRepository.cs | 96 +++++++------------ .../Services/SmsService.cs | 53 ++++++++-- .../Admin/Controllers/SmsReportController.cs | 39 +++++++- 8 files changed, 156 insertions(+), 74 deletions(-) diff --git a/0_Framework/Application/Sms/ApiResultViewModel.cs b/0_Framework/Application/Sms/ApiResultViewModel.cs index 0afaddc1..0d5c1ca1 100644 --- a/0_Framework/Application/Sms/ApiResultViewModel.cs +++ b/0_Framework/Application/Sms/ApiResultViewModel.cs @@ -17,4 +17,18 @@ public class ApiResultViewModel public string DeliveryUnixTime { get; set; } public string DeliveryColor { get; set; } public string FullName { get; set; } +} + + +public class ApiReportDto +{ + public int MessageId { get; set; } + + public long Mobile { get; set; } + + public string SendUnixTime { get; set; } + public string DeliveryState { get; set; } + public string DeliveryUnixTime { get; set; } + public string DeliveryColor { get; set; } + } \ No newline at end of file diff --git a/0_Framework/Application/Sms/ISmsService.cs b/0_Framework/Application/Sms/ISmsService.cs index 9590bf27..20e41608 100644 --- a/0_Framework/Application/Sms/ISmsService.cs +++ b/0_Framework/Application/Sms/ISmsService.cs @@ -19,6 +19,13 @@ public interface ISmsService bool SendAccountsInfo(string number,string fullName, string userName); Task GetByMessageId(int messId); Task> GetApiResult(string startDate, string endDate); + + #region ForApi + + Task> GetApiReport(string startDate, string endDate); + +#endregion + string DeliveryStatus(byte? dv); string DeliveryColorStatus(byte? dv); string UnixTimeStampToDateTime(int? unixTimeStamp); diff --git a/Company.Domain/SmsResultAgg/ISmsResultRepository.cs b/Company.Domain/SmsResultAgg/ISmsResultRepository.cs index 6a4ab25c..24ee411b 100644 --- a/Company.Domain/SmsResultAgg/ISmsResultRepository.cs +++ b/Company.Domain/SmsResultAgg/ISmsResultRepository.cs @@ -17,6 +17,14 @@ public interface ISmsResultRepository : IRepository /// Task> GetSmsReportList(SmsReportSearchModel searchModel); + /// + /// دریافت اکسپند لیست هر تاریخ + /// + /// + /// + /// + Task> GetSmsReportExpandList(SmsReportSearchModel searchModel, string date); + #endregion List Search(SmsResultSearchModel searchModel); } \ No newline at end of file diff --git a/CompanyManagment.App.Contracts/SmsResult/ISmsResultApplication.cs b/CompanyManagment.App.Contracts/SmsResult/ISmsResultApplication.cs index b3aee079..2c857396 100644 --- a/CompanyManagment.App.Contracts/SmsResult/ISmsResultApplication.cs +++ b/CompanyManagment.App.Contracts/SmsResult/ISmsResultApplication.cs @@ -19,6 +19,14 @@ public interface ISmsResultApplication /// Task> GetSmsReportList(SmsReportSearchModel searchModel); + /// + /// دریافت اکسپند لیست هر تاریخ + /// + /// + /// + /// + Task> GetSmsReportExpandList(SmsReportSearchModel searchModel, string date); + #endregion OperationResult Create(CreateSmsResult command); diff --git a/CompanyManagment.Application/SmsResultApplication.cs b/CompanyManagment.Application/SmsResultApplication.cs index 85ce62a6..2c94d837 100644 --- a/CompanyManagment.Application/SmsResultApplication.cs +++ b/CompanyManagment.Application/SmsResultApplication.cs @@ -25,6 +25,11 @@ public class SmsResultApplication : ISmsResultApplication return await _smsResultRepository.GetSmsReportList(searchModel); } + public async Task> GetSmsReportExpandList(SmsReportSearchModel searchModel, string date) + { + return await _smsResultRepository.GetSmsReportExpandList(searchModel, date); + } + #endregion diff --git a/CompanyManagment.EFCore/Repository/SmsResultRepository.cs b/CompanyManagment.EFCore/Repository/SmsResultRepository.cs index 326def5f..18ccbe1d 100644 --- a/CompanyManagment.EFCore/Repository/SmsResultRepository.cs +++ b/CompanyManagment.EFCore/Repository/SmsResultRepository.cs @@ -163,33 +163,39 @@ public class SmsResultRepository : RepositoryBase, ISmsResultRe public async Task> GetSmsReportExpandList(SmsReportSearchModel searchModel, string date) { + if(string.IsNullOrWhiteSpace(date)) + return new List(); + 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}", - }); + var query = await _context.SmsResults.Where(x => x.CreationDate.Date == searchDate.Date) + .Select(x => + new + { + x.id, + x.MessageId, + x.Status, + x.TypeOfSms, + x.ContractingPartyName, + x.Mobile, + x.ContractingPatyId, + x.InstitutionContractId, + x.CreationDate, + x.CreationDate.Hour, + x.CreationDate.Minute + + }).AsNoTracking() + .ToListAsync(); ; if (searchModel.ContractingPatyId > 0) { - query = query.Where(x => x.ContractingPartyId == searchModel.ContractingPatyId); + query = query.Where(x => x.ContractingPatyId == searchModel.ContractingPatyId).ToList(); } if (!string.IsNullOrWhiteSpace(searchModel.Mobile)) { - query = query.Where(x => x.Mobile.Contains(searchModel.Mobile)); + query = query.Where(x => x.Mobile.Contains(searchModel.Mobile)).ToList(); } if (searchModel.TypeOfSms != TypeOfSmsSetting.All && searchModel.TypeOfSms != TypeOfSmsSetting.Warning) @@ -220,12 +226,12 @@ public class SmsResultRepository : RepositoryBase, ISmsResultRe break; } - query = query.Where(x => x.TypeOfSms == typeOfSms); + query = query.Where(x => x.TypeOfSms == typeOfSms).ToList(); } if (searchModel.TypeOfSms == TypeOfSmsSetting.Warning) { - query = query.Where(x => x.TypeOfSms.Contains("هشدار")); + query = query.Where(x => x.TypeOfSms.Contains("هشدار")).ToList(); } if (searchModel.SendStatus != SendStatus.All) @@ -244,59 +250,25 @@ public class SmsResultRepository : RepositoryBase, ISmsResultRe } - query = query.Where(x => x.Status == status); + query = query.Where(x => x.Status == status).ToList(); } - #region searchByDate + if (query.Count == 0) + return new List(); - 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 + var result = query.OrderByDescending(x => x.CreationDate.Hour) + .ThenByDescending(x => x.CreationDate.Minute).Select(x => + new SmsReportListDto() { - Id = x.Id, + Id = x.id, MessageId = x.MessageId, Status = x.Status, TypeOfSms = x.TypeOfSms, ContractingPartyName = x.ContractingPartyName, Mobile = x.Mobile, - HourAndMinute = $"{x.Hour}:{x.Minute}" - - }).ToListAsync(); + HourAndMinute = x.CreationDate.TimeOfDay.ToString(@"hh\:mm"), + }).ToList(); return result; diff --git a/CompanyManagment.EFCore/Services/SmsService.cs b/CompanyManagment.EFCore/Services/SmsService.cs index 82cf6917..11ea7adb 100644 --- a/CompanyManagment.EFCore/Services/SmsService.cs +++ b/CompanyManagment.EFCore/Services/SmsService.cs @@ -207,16 +207,11 @@ public class SmsService : ISmsService } public async Task> GetApiResult(string startDate, string endDate) { - var st = new DateTime(2024, 6, 2); - var ed = new DateTime(2024, 7, 1); - if (!string.IsNullOrWhiteSpace(startDate) && startDate.Length == 10) - { - st = startDate.ToGeorgianDateTime(); - } - if (!string.IsNullOrWhiteSpace(endDate) && endDate.Length == 10) - { - ed = endDate.ToGeorgianDateTime(); - } + + + if(startDate.TryToGeorgianDateTime(out var st) == false || endDate.TryToGeorgianDateTime(out var ed) == false) + return new List(); + var res = new List(); Int32 unixTimestamp = (int)st.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; Int32 unixTimestamp2 = (int)ed.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; @@ -248,6 +243,44 @@ public class SmsService : ISmsService return res; } + public async Task> GetApiReport(string startDate, string endDate) + { + + + if (startDate.TryToGeorgianDateTime(out var st) == false || endDate.TryToGeorgianDateTime(out var ed) == false) + return new List(); + + var res = new List(); + Int32 unixTimestamp = (int)st.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; + Int32 unixTimestamp2 = (int)ed.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; + // int? fromDateUnixTime = null; // unix time - for instance: 1700598600 + //int? toDateUnixTime = null; // unix time - for instance: 1703190600 + int pageNumber = 2; + int pageSize = 100; // max: 100 + SmsIr smsIr = new SmsIr("Og5M562igmzJRhQPnq0GdtieYdLgtfikjzxOmeQBPxJjZtyge5Klc046Lfw1mxSa"); + var response = await smsIr.GetArchivedReportAsync(pageNumber, pageSize, unixTimestamp, unixTimestamp2); + + MessageReportResult[] messages = response.Data; + foreach (var message in messages) + { + var appendData = new ApiReportDto() + { + MessageId = message.MessageId, + + Mobile = message.Mobile, + + SendUnixTime = UnixTimeStampToDateTime(message.SendDateTime), + DeliveryState = DeliveryStatus(message.DeliveryState), + DeliveryUnixTime = UnixTimeStampToDateTime(message.DeliveryDateTime), + DeliveryColor = DeliveryColorStatus(message.DeliveryState), + }; + res.Add(appendData); + } + + + return res; + } + public string DeliveryStatus(byte? dv) { string mess = ""; diff --git a/ServiceHost/Areas/Admin/Controllers/SmsReportController.cs b/ServiceHost/Areas/Admin/Controllers/SmsReportController.cs index c3d42a97..254d5d05 100644 --- a/ServiceHost/Areas/Admin/Controllers/SmsReportController.cs +++ b/ServiceHost/Areas/Admin/Controllers/SmsReportController.cs @@ -1,4 +1,5 @@ -using CompanyManagment.App.Contracts.SmsResult; +using _0_Framework.Application.Sms; +using CompanyManagment.App.Contracts.SmsResult; using CompanyManagment.App.Contracts.SmsResult.Dto; using Microsoft.AspNetCore.Mvc; using ServiceHost.BaseControllers; @@ -8,12 +9,19 @@ namespace ServiceHost.Areas.Admin.Controllers; public class SmsReportController : AdminBaseController { private readonly ISmsResultApplication _smsResultApplication; + private readonly ISmsService _smsService; - public SmsReportController(ISmsResultApplication smsResultApplication) + public SmsReportController(ISmsResultApplication smsResultApplication, ISmsService smsService) { _smsResultApplication = smsResultApplication; + _smsService = smsService; } + /// + /// دریافت لیست پیامک ها + /// + /// + /// [HttpGet] public async Task> GetSmsReportList(SmsReportSearchModel searchModel) { @@ -21,4 +29,31 @@ public class SmsReportController : AdminBaseController var result =await _smsResultApplication.GetSmsReportList(searchModel); return result; } + + /// + /// دریافت اطلاعات هر تاریخ برای اکسپند + /// + /// + /// + /// + [HttpGet("GetExpandedList")] + public async Task> GetSmsReportExpandList(SmsReportSearchModel searchModel, string date) + { + var result =await _smsResultApplication.GetSmsReportExpandList(searchModel, date); + return result; + } + + /// + /// گزارش ای پی آی + /// + /// + /// + /// + [HttpGet("GetApiReport")] + public async Task> GetApiReport(string startDate, string endDate) + { + var result =await _smsService.GetApiReport(startDate, endDate); + return result; + } + } \ No newline at end of file