BlueDeActiveAfterZeroDebt hangfire completed
This commit is contained in:
@@ -32,226 +32,245 @@ public class JobSchedulerRegistrator
|
|||||||
|
|
||||||
public void Register()
|
public void Register()
|
||||||
{
|
{
|
||||||
//_logger.LogInformation("hangfire Started");
|
_logger.LogInformation("hangfire Started");
|
||||||
//RecurringJob.AddOrUpdate(
|
RecurringJob.AddOrUpdate(
|
||||||
// "InstitutionContract.CreateFinancialTransaction",
|
"InstitutionContract.CreateFinancialTransaction",
|
||||||
// () => CreateFinancialTransaction(),
|
() => CreateFinancialTransaction(),
|
||||||
// "*/30 * * * *" // هر 30 دقیقه یکبار چک کن
|
"*/30 * * * *" // هر 30 دقیقه یکبار چک کن
|
||||||
//);
|
);
|
||||||
|
|
||||||
//RecurringJob.AddOrUpdate(
|
RecurringJob.AddOrUpdate(
|
||||||
// "InstitutionContract.SendMonthlySms",
|
"InstitutionContract.SendMonthlySms",
|
||||||
// () => SendFirstDayOfMonthSms(),
|
() => SendFirstDayOfMonthSms(),
|
||||||
// "*/20 * * * *" // هر 30 دقیقه یکبار چک کن
|
"*/20 * * * *" // هر 30 دقیقه یکبار چک کن
|
||||||
//);
|
);
|
||||||
|
|
||||||
//RecurringJob.AddOrUpdate(
|
RecurringJob.AddOrUpdate(
|
||||||
// "InstitutionContract.SendReminderSms",
|
"InstitutionContract.SendReminderSms",
|
||||||
// () => SendReminderSms(),
|
() => SendReminderSms(),
|
||||||
// "*/1 * * * *" // هر 1 دقیقه یکبار چک کن
|
"*/1 * * * *" // هر 1 دقیقه یکبار چک کن
|
||||||
//);
|
);
|
||||||
//RecurringJob.AddOrUpdate(
|
RecurringJob.AddOrUpdate(
|
||||||
// "InstitutionContract.SendBlockSms",
|
"InstitutionContract.SendBlockSms",
|
||||||
// () => SendBlockSms(),
|
() => SendBlockSms(),
|
||||||
// "*/1 * * * *" // هر 1 دقیقه یکبار چک کن
|
"*/1 * * * *" // هر 1 دقیقه یکبار چک کن
|
||||||
//);
|
);
|
||||||
//RecurringJob.AddOrUpdate(
|
RecurringJob.AddOrUpdate(
|
||||||
// "InstitutionContract.SendInstitutionContractConfirmSms",
|
"InstitutionContract.SendInstitutionContractConfirmSms",
|
||||||
// () => SendInstitutionContractConfirmSms(),
|
() => SendInstitutionContractConfirmSms(),
|
||||||
// "*/1 * * * *" // هر 1 دقیقه یکبار چک کن
|
"*/1 * * * *" // هر 1 دقیقه یکبار چک کن
|
||||||
//);
|
);
|
||||||
|
|
||||||
//RecurringJob.AddOrUpdate(
|
RecurringJob.AddOrUpdate(
|
||||||
// "InstitutionContract.SendWarningSms",
|
"InstitutionContract.SendWarningSms",
|
||||||
// () => SendWarningSms(),
|
() => SendWarningSms(),
|
||||||
// "*/1 * * * *" // هر 1 دقیقه یکبار چک کن
|
"*/1 * * * *" // هر 1 دقیقه یکبار چک کن
|
||||||
//);
|
);
|
||||||
|
|
||||||
//RecurringJob.AddOrUpdate(
|
RecurringJob.AddOrUpdate(
|
||||||
// "InstitutionContract.SendLegalActionSms",
|
"InstitutionContract.SendLegalActionSms",
|
||||||
// () => SendLegalActionSms(),
|
() => SendLegalActionSms(),
|
||||||
// "*/1 * * * *" // هر 1 دقیقه یکبار چک کن
|
"*/1 * * * *" // هر 1 دقیقه یکبار چک کن
|
||||||
//);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//RecurringJob.AddOrUpdate(
|
RecurringJob.AddOrUpdate(
|
||||||
// "InstitutionContract.Block",
|
"InstitutionContract.Block",
|
||||||
// () => Block(),
|
() => Block(),
|
||||||
// "*/30 * * * *" // هر 30 دقیقه یکبار چک کن
|
"*/30 * * * *" // هر 30 دقیقه یکبار چک کن
|
||||||
//);
|
);
|
||||||
|
|
||||||
//RecurringJob.AddOrUpdate(
|
RecurringJob.AddOrUpdate(
|
||||||
// "InstitutionContract.UnBlock",
|
"InstitutionContract.UnBlock",
|
||||||
// () => UnBlock(),
|
() => UnBlock(),
|
||||||
// "*/10 * * * *"
|
"*/10 * * * *"
|
||||||
//);
|
);
|
||||||
|
|
||||||
RecurringJob.AddOrUpdate(
|
RecurringJob.AddOrUpdate(
|
||||||
"InstitutionContract.DeActiveInstitutionEndOfContract",
|
"InstitutionContract.DeActiveInstitutionEndOfContract",
|
||||||
() => DeActiveInstitutionEndOfContract(),
|
() => DeActiveInstitutionEndOfContract(),
|
||||||
"*/30 * * * *"
|
"*/30 * * * *"
|
||||||
|
);
|
||||||
|
|
||||||
|
RecurringJob.AddOrUpdate(
|
||||||
|
"InstitutionContract.BlueDeActiveAfterZeroDebt",
|
||||||
|
() => BlueDeActiveAfterZeroDebt(),
|
||||||
|
"*/10 * * * *"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///// <summary>
|
/// <summary>
|
||||||
///// ایجاد سند بدهی ماهیانه برای قراداد مالی
|
/// ایجاد سند بدهی ماهیانه برای قراداد مالی
|
||||||
///// </summary>
|
/// </summary>
|
||||||
///// <returns></returns>
|
/// <returns></returns>
|
||||||
//[DisableConcurrentExecution(timeoutInSeconds: 1200)]
|
[DisableConcurrentExecution(timeoutInSeconds: 1200)]
|
||||||
//public async System.Threading.Tasks.Task CreateFinancialTransaction()
|
public async System.Threading.Tasks.Task CreateFinancialTransaction()
|
||||||
//{
|
{
|
||||||
// var now = DateTime.Now;
|
var now = DateTime.Now;
|
||||||
// var endOfMonth = now.ToFarsi().FindeEndOfMonth();
|
var endOfMonth = now.ToFarsi().FindeEndOfMonth();
|
||||||
// var endOfMonthGr = endOfMonth.ToGeorgianDateTime();
|
var endOfMonthGr = endOfMonth.ToGeorgianDateTime();
|
||||||
// _logger.LogInformation("CreateFinancialTransaction job run");
|
_logger.LogInformation("CreateFinancialTransaction job run");
|
||||||
// if (now.Date == endOfMonthGr.Date && now.Hour >= 2 && now.Hour < 4 &&
|
if (now.Date == endOfMonthGr.Date && now.Hour >= 2 && now.Hour < 4 &&
|
||||||
// now.Date != _lastRunCreateTransaction?.Date)
|
now.Date != _lastRunCreateTransaction?.Date)
|
||||||
// {
|
{
|
||||||
|
|
||||||
// var month = endOfMonth.Substring(5, 2);
|
var month = endOfMonth.Substring(5, 2);
|
||||||
// var year = endOfMonth.Substring(0, 4);
|
var year = endOfMonth.Substring(0, 4);
|
||||||
// var monthName = month.ToFarsiMonthByNumber();
|
var monthName = month.ToFarsiMonthByNumber();
|
||||||
// var description = $"{monthName} {year}";
|
var description = $"{monthName} {year}";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// var endnew = ($"{endOfMonth.Substring(0, 8)}01").FindeEndOfMonth();
|
var endnew = ($"{endOfMonth.Substring(0, 8)}01").FindeEndOfMonth();
|
||||||
|
|
||||||
// var endNewGr = endnew.ToGeorgianDateTime();
|
var endNewGr = endnew.ToGeorgianDateTime();
|
||||||
// var endNewFa = endNewGr.ToFarsi();
|
var endNewFa = endNewGr.ToFarsi();
|
||||||
|
|
||||||
// try
|
try
|
||||||
// {
|
{
|
||||||
// await _institutionContractRepository.CreateTransactionForInstitutionContracts(endNewGr, endNewFa, description);
|
await _institutionContractRepository.CreateTransactionForInstitutionContracts(endNewGr, endNewFa, description);
|
||||||
// _lastRunCreateTransaction = now;
|
_lastRunCreateTransaction = now;
|
||||||
// Console.WriteLine("CreateTransAction executed");
|
Console.WriteLine("CreateTransAction executed");
|
||||||
|
|
||||||
// }
|
}
|
||||||
// catch (Exception e)
|
catch (Exception e)
|
||||||
// {
|
{
|
||||||
// await _smsService.Alarm("09114221321", "خطا-ایجاد سند مالی");
|
await _smsService.Alarm("09114221321", "خطا-ایجاد سند مالی");
|
||||||
|
|
||||||
// }
|
}
|
||||||
|
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
|
||||||
///// <summary>
|
/// <summary>
|
||||||
///// ارسال پیامک صورت حساب ماهانه
|
/// ارسال پیامک صورت حساب ماهانه
|
||||||
///// </summary>
|
/// </summary>
|
||||||
///// <returns></returns>
|
/// <returns></returns>
|
||||||
//[DisableConcurrentExecution(timeoutInSeconds: 600)]
|
[DisableConcurrentExecution(timeoutInSeconds: 600)]
|
||||||
//public async System.Threading.Tasks.Task SendFirstDayOfMonthSms()
|
public async System.Threading.Tasks.Task SendFirstDayOfMonthSms()
|
||||||
//{
|
{
|
||||||
// //var now = new DateTime(2025,11,21, 10,30,0);
|
//var now = new DateTime(2025,11,21, 10,30,0);
|
||||||
// var now = DateTime.Now;
|
var now = DateTime.Now;
|
||||||
// var endOfMonth = now.ToFarsi().FindeEndOfMonth();
|
var endOfMonth = now.ToFarsi().FindeEndOfMonth();
|
||||||
// var endOfMonthGr = endOfMonth.ToGeorgianDateTime();
|
var endOfMonthGr = endOfMonth.ToGeorgianDateTime();
|
||||||
// _logger.LogInformation("SendFirstDayOfMonthSms job run");
|
_logger.LogInformation("SendFirstDayOfMonthSms job run");
|
||||||
// if (now.Date == endOfMonthGr.Date && now.Hour >= 10 && now.Hour < 11 &&
|
if (now.Date == endOfMonthGr.Date && now.Hour >= 10 && now.Hour < 11 &&
|
||||||
// now.Date != _lastRunSendMonthlySms?.Date)
|
now.Date != _lastRunSendMonthlySms?.Date)
|
||||||
// {
|
{
|
||||||
|
|
||||||
// try
|
try
|
||||||
// {
|
{
|
||||||
// await _institutionContractRepository.SendMonthlySms(now);
|
await _institutionContractSmsServiceRepository.SendMonthlySms(now);
|
||||||
// _lastRunSendMonthlySms = now;
|
_lastRunSendMonthlySms = now;
|
||||||
// Console.WriteLine("Send Monthly sms executed");
|
Console.WriteLine("Send Monthly sms executed");
|
||||||
|
|
||||||
// }
|
}
|
||||||
// catch (Exception e)
|
catch (Exception e)
|
||||||
// {
|
{
|
||||||
// //_smsService.Alarm("09114221321", "خطا-ایجاد سند مالی");
|
//_smsService.Alarm("09114221321", "خطا-ایجاد سند مالی");
|
||||||
|
|
||||||
// }
|
}
|
||||||
|
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
///// <summary>
|
/// <summary>
|
||||||
///// ارسال پیامک یاد آور بدهی
|
/// ارسال پیامک یاد آور بدهی
|
||||||
///// </summary>
|
/// </summary>
|
||||||
///// <returns></returns>
|
/// <returns></returns>
|
||||||
//[DisableConcurrentExecution(timeoutInSeconds: 1200)]
|
[DisableConcurrentExecution(timeoutInSeconds: 1200)]
|
||||||
//public async System.Threading.Tasks.Task SendReminderSms()
|
public async System.Threading.Tasks.Task SendReminderSms()
|
||||||
//{
|
{
|
||||||
// _logger.LogInformation("SendReminderSms job run");
|
_logger.LogInformation("SendReminderSms job run");
|
||||||
// await _institutionContractRepository.SendReminderSmsForBackgroundTask();
|
await _institutionContractSmsServiceRepository.SendReminderSmsForBackgroundTask();
|
||||||
//}
|
}
|
||||||
|
|
||||||
///// <summary>
|
/// <summary>
|
||||||
///// ارسال پیامک مسدودی
|
/// ارسال پیامک مسدودی
|
||||||
///// </summary>
|
/// </summary>
|
||||||
///// <returns></returns>
|
/// <returns></returns>
|
||||||
//[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
||||||
//public async System.Threading.Tasks.Task SendBlockSms()
|
public async System.Threading.Tasks.Task SendBlockSms()
|
||||||
//{
|
{
|
||||||
// _logger.LogInformation("SendBlockSms job run");
|
_logger.LogInformation("SendBlockSms job run");
|
||||||
// await _institutionContractSmsServiceRepository.SendBlockSmsForBackgroundTask();
|
await _institutionContractSmsServiceRepository.SendBlockSmsForBackgroundTask();
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
|
||||||
///// <summary>
|
/// <summary>
|
||||||
///// ارسال پیامک یادآور تایید قراداد مالی
|
/// ارسال پیامک یادآور تایید قراداد مالی
|
||||||
///// </summary>
|
/// </summary>
|
||||||
///// <returns></returns>
|
/// <returns></returns>
|
||||||
//[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
||||||
//public async System.Threading.Tasks.Task SendInstitutionContractConfirmSms()
|
public async System.Threading.Tasks.Task SendInstitutionContractConfirmSms()
|
||||||
//{
|
{
|
||||||
// _logger.LogInformation("SendInstitutionContractConfirmSms job run");
|
_logger.LogInformation("SendInstitutionContractConfirmSms job run");
|
||||||
// await _institutionContractRepository.SendInstitutionContractConfirmSmsTask();
|
await _institutionContractSmsServiceRepository.SendInstitutionContractConfirmSmsTask();
|
||||||
//}
|
}
|
||||||
|
|
||||||
///// <summary>
|
/// <summary>
|
||||||
///// ارسال پیامک هشدار
|
/// ارسال پیامک هشدار
|
||||||
///// </summary>
|
/// </summary>
|
||||||
///// <returns></returns>
|
/// <returns></returns>
|
||||||
//[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
||||||
//public async System.Threading.Tasks.Task SendWarningSms()
|
public async System.Threading.Tasks.Task SendWarningSms()
|
||||||
//{
|
{
|
||||||
// _logger.LogInformation("SendWarningSms job run");
|
_logger.LogInformation("SendWarningSms job run");
|
||||||
// await _institutionContractSmsServiceRepository.SendWarningOrLegalActionSmsTask(TypeOfSmsSetting.Warning);
|
await _institutionContractSmsServiceRepository.SendWarningOrLegalActionSmsTask(TypeOfSmsSetting.Warning);
|
||||||
//}
|
}
|
||||||
|
|
||||||
//[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
/// <summary>
|
||||||
//public async System.Threading.Tasks.Task SendLegalActionSms()
|
/// پیامک اقدام قضایی
|
||||||
//{
|
/// </summary>
|
||||||
// _logger.LogInformation("SendWarningSms job run");
|
/// <returns></returns>
|
||||||
// await _institutionContractSmsServiceRepository.SendWarningOrLegalActionSmsTask(TypeOfSmsSetting.LegalAction);
|
[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
||||||
//}
|
public async System.Threading.Tasks.Task SendLegalActionSms()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("SendWarningSms job run");
|
||||||
|
await _institutionContractSmsServiceRepository.SendWarningOrLegalActionSmsTask(TypeOfSmsSetting.LegalAction);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// بلاگ سازی
|
/// بلاگ سازی
|
||||||
/// </summary>
|
/// </summary>
|
||||||
///// <returns></returns>
|
/// <returns></returns>
|
||||||
//[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
||||||
//public async System.Threading.Tasks.Task Block()
|
public async System.Threading.Tasks.Task Block()
|
||||||
//{
|
{
|
||||||
// _logger.LogInformation("block job run");
|
_logger.LogInformation("block job run");
|
||||||
// var now = DateTime.Now;
|
var now = DateTime.Now;
|
||||||
// var executeDate = now.ToFarsi().Substring(8, 2);
|
var executeDate = now.ToFarsi().Substring(8, 2);
|
||||||
// if (executeDate == "20")
|
if (executeDate == "20")
|
||||||
// {
|
{
|
||||||
// if (now.Hour >= 9 && now.Hour < 10)
|
if (now.Hour >= 9 && now.Hour < 10)
|
||||||
// {
|
{
|
||||||
// await _institutionContractSmsServiceRepository.Block(now);
|
await _institutionContractSmsServiceRepository.Block(now);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
//[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
/// <summary>
|
||||||
//public async System.Threading.Tasks.Task UnBlock()
|
/// آنبلاک
|
||||||
//{
|
/// </summary>
|
||||||
// _logger.LogInformation("UnBlock job run");
|
/// <returns></returns>
|
||||||
|
[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
||||||
// await _institutionContractSmsServiceRepository.UnBlock();
|
public async System.Threading.Tasks.Task UnBlock()
|
||||||
|
{
|
||||||
//}
|
_logger.LogInformation("UnBlock job run");
|
||||||
|
|
||||||
|
await _institutionContractSmsServiceRepository.UnBlock();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// غیر فعال سازی قراداد های پایان یافته
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
||||||
public async System.Threading.Tasks.Task DeActiveInstitutionEndOfContract()
|
public async System.Threading.Tasks.Task DeActiveInstitutionEndOfContract()
|
||||||
{
|
{
|
||||||
@@ -266,9 +285,20 @@ public class JobSchedulerRegistrator
|
|||||||
{
|
{
|
||||||
await _institutionContractSmsServiceRepository.DeActiveInstitutionEndOfContract(now);
|
await _institutionContractSmsServiceRepository.DeActiveInstitutionEndOfContract(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// غیرفعال سازس قرارداد های آبی که بدهی ندارند
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[DisableConcurrentExecution(timeoutInSeconds: 800)]
|
||||||
|
public async System.Threading.Tasks.Task BlueDeActiveAfterZeroDebt()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("BlueDeActiveAfterZeroDebt job run");
|
||||||
|
await _institutionContractSmsServiceRepository.BlueDeActiveAfterZeroDebt();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -91,42 +91,7 @@ public interface IInstitutionContractRepository : IRepository<long, InstitutionC
|
|||||||
Task<List<InstitutionContractPrintViewModel>> PrintAllAsync(List<long> ids);
|
Task<List<InstitutionContractPrintViewModel>> PrintAllAsync(List<long> ids);
|
||||||
|
|
||||||
|
|
||||||
#region ReminderSMS
|
|
||||||
/// <summary>
|
|
||||||
/// دریافت لیست - ارسال پیامک
|
|
||||||
/// فراخوانی از سمت بک گراند سرویس
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<bool> SendReminderSmsForBackgroundTask();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// ارسال پیامک صورت حساب ماهانه
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="now"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task SendMonthlySms(DateTime now);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///دریافت لیست بدهکارن
|
|
||||||
/// جهت ارسال پیامک
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task<List<SmsListData>> GetSmsListData(DateTime checkDate, TypeOfSmsSetting typeOfSmsSetting);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// ارسال پیامک های یاد آور بدهی
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task SendReminderSmsToContractingParties(List<SmsListData> smsListData, string typeOfSms, string sendMessStart, string sendMessEnd);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// ارسال پیامک یادآور تایید قراداد مالی
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task SendInstitutionContractConfirmSmsTask();
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region CreateMontlyTransaction
|
#region CreateMontlyTransaction
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,16 @@ namespace Company.Domain.InstitutionContractAgg;
|
|||||||
|
|
||||||
public interface IInstitutionContractSmsServiceRepository : IRepository<long, InstitutionContract>
|
public interface IInstitutionContractSmsServiceRepository : IRepository<long, InstitutionContract>
|
||||||
{
|
{
|
||||||
|
#region reminderSMs
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ارسال پیامک یادآور تایید قراداد مالی
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task SendInstitutionContractConfirmSmsTask();
|
||||||
|
#endregion
|
||||||
|
|
||||||
//هشدار و اقدام قضایی
|
//هشدار و اقدام قضایی
|
||||||
#region WarningOrLegalActionSmsListData
|
#region WarningOrLegalActionSmsListData
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -35,7 +45,8 @@ public interface IInstitutionContractSmsServiceRepository : IRepository<long, In
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//بلاک - آنبلاک - پیامک بلاک
|
//بلاک - آنبلاک - پیامک بلاک -
|
||||||
|
// غیر فعال سازی قراداد های پایان یافته
|
||||||
#region Block
|
#region Block
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -91,5 +102,44 @@ public interface IInstitutionContractSmsServiceRepository : IRepository<long, In
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task DeActiveInstitutionEndOfContract(DateTime checkDate);
|
Task DeActiveInstitutionEndOfContract(DateTime checkDate);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// غیرفعال سازس قرارداد های آبی که بدهی ندارند
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task BlueDeActiveAfterZeroDebt();
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region ReminderSMS
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// دریافت لیست - ارسال پیامک
|
||||||
|
/// فراخوانی از سمت بک گراند سرویس
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<bool> SendReminderSmsForBackgroundTask();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ارسال پیامک صورت حساب ماهانه
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="now"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task SendMonthlySms(DateTime now);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///دریافت لیست بدهکارن
|
||||||
|
/// جهت ارسال پیامک
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<List<SmsListData>> GetSmsListData(DateTime checkDate, TypeOfSmsSetting typeOfSmsSetting);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ارسال پیامک های یاد آور بدهی
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task SendReminderSmsToContractingParties(List<SmsListData> smsListData, string typeOfSms, string sendMessStart, string sendMessEnd);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ public class SmsSettingApplication : ISmsSettingApplication
|
|||||||
|
|
||||||
public async Task<List<SmsListData>> GetSmsListData(TypeOfSmsSetting typeOfSmsSetting)
|
public async Task<List<SmsListData>> GetSmsListData(TypeOfSmsSetting typeOfSmsSetting)
|
||||||
{
|
{
|
||||||
return await _institutionContractRepository.GetSmsListData(DateTime.Now, typeOfSmsSetting);
|
return await _institutionContractSmsServiceRepository.GetSmsListData(DateTime.Now, typeOfSmsSetting);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<BlockSmsListData>> GetBlockSmsListData(TypeOfSmsSetting typeOfSmsSetting)
|
public async Task<List<BlockSmsListData>> GetBlockSmsListData(TypeOfSmsSetting typeOfSmsSetting)
|
||||||
@@ -137,7 +137,7 @@ public class SmsSettingApplication : ISmsSettingApplication
|
|||||||
|
|
||||||
if (command.Any())
|
if (command.Any())
|
||||||
{
|
{
|
||||||
await _institutionContractRepository.SendReminderSmsToContractingParties(command, typeOfSms, sendMessStart, sendMessEnd);
|
await _institutionContractSmsServiceRepository.SendReminderSmsToContractingParties(command, typeOfSms, sendMessStart, sendMessEnd);
|
||||||
return op.Succcedded();
|
return op.Succcedded();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -3562,623 +3562,10 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
//یادآور
|
|
||||||
#region DebtReminderSms
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// دریافت لیست - ارسال پیامک
|
|
||||||
/// فراخوانی از سمت بک گراند سرویس
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<bool> SendReminderSmsForBackgroundTask()
|
|
||||||
{
|
|
||||||
var now = DateTime.Now;
|
|
||||||
|
|
||||||
|
|
||||||
// تبدیل تاریخ میلادی به شمسی
|
|
||||||
var persianNow = now.ToFarsi();
|
|
||||||
var persianEndOfMonth = int.Parse(persianNow.FindeEndOfMonth().Substring(8, 2));
|
|
||||||
var dayOfMonth = int.Parse(persianNow.Substring(8, 2));
|
|
||||||
var hour = now.Hour;
|
|
||||||
var minute = now.Minute;
|
|
||||||
var checkAnyToExecute = false;
|
|
||||||
|
|
||||||
//اگر آخرین روز ماه باشد
|
|
||||||
//اگر روز مثلا عدد روز 31 بود ولی آخرین روز ماه 30 بود
|
|
||||||
if (dayOfMonth == persianEndOfMonth)
|
|
||||||
{
|
|
||||||
checkAnyToExecute = await _context.SmsSettings
|
|
||||||
.AnyAsync(x =>
|
|
||||||
x.DayOfMonth >= dayOfMonth &&
|
|
||||||
x.TimeOfDay.Hours == hour &&
|
|
||||||
x.TimeOfDay.Minutes == minute &&
|
|
||||||
x.TypeOfSmsSetting == TypeOfSmsSetting.InstitutionContractDebtReminder &&
|
|
||||||
x.IsActive
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
checkAnyToExecute = await _context.SmsSettings
|
|
||||||
.AnyAsync(x =>
|
|
||||||
x.DayOfMonth == dayOfMonth &&
|
|
||||||
x.TimeOfDay.Hours == hour &&
|
|
||||||
x.TimeOfDay.Minutes == minute &&
|
|
||||||
x.TypeOfSmsSetting == TypeOfSmsSetting.InstitutionContractDebtReminder &&
|
|
||||||
x.IsActive
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (checkAnyToExecute)
|
|
||||||
{
|
|
||||||
//اجرای تسک
|
|
||||||
_logger.LogInformation("اجرای تسک پیامک های یاد آور SendReminderSmsForBackgroundTask" + persianNow + " - " +
|
|
||||||
hour + ":" + minute);
|
|
||||||
//دریافت لیست بدهکاران
|
|
||||||
var smsListData = await GetSmsListData(now, TypeOfSmsSetting.InstitutionContractDebtReminder);
|
|
||||||
string typeOfSms = "یادآور بدهی ماهانه";
|
|
||||||
string sendMessStart = "شروع پیامک یادآور";
|
|
||||||
string sendMessEnd = "پایان پیامک یادآور";
|
|
||||||
//ارسال پیامک
|
|
||||||
await SendReminderSmsToContractingParties(smsListData, typeOfSms, sendMessStart, sendMessEnd);
|
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine("executed at : " + persianNow + " - " + hour + ":" + minute);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
//ماهانه
|
|
||||||
#region MonthlySms
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// ارسال پیامک صورت حساب ماهانه
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="now"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task SendMonthlySms(DateTime now)
|
|
||||||
{
|
|
||||||
//دریافت لیست بدهکاران
|
|
||||||
var smsListData = await GetSmsListData(now, TypeOfSmsSetting.MonthlyInstitutionContract);
|
|
||||||
|
|
||||||
string typeOfSms = "صورت حساب ماهانه";
|
|
||||||
string sendMessStart = "شروع پیامک ماهانه";
|
|
||||||
string sendMessEnd = "پایان پیامک ماهانه";
|
|
||||||
//ارسال پیامک
|
|
||||||
await SendReminderSmsToContractingParties(smsListData, typeOfSms, sendMessStart, sendMessEnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//دریافت لیست بدهکاران و ارسال پیامک
|
|
||||||
#region GetListAndSendSmsMethods
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///دریافت لیست بدهکارن
|
|
||||||
/// جهت ارسال پیامک
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<List<SmsListData>> GetSmsListData(DateTime checkDate, TypeOfSmsSetting typeOfSmsSetting)
|
|
||||||
{
|
|
||||||
var watch = new Stopwatch();
|
|
||||||
var smsList = new List<SmsListData>();
|
|
||||||
var currentMonthStart = ($"{(checkDate.ToFarsi()).Substring(0, 8)}01").ToGeorgianDateTime();
|
|
||||||
var previusMonthEnd = currentMonthStart.AddDays(-1);
|
|
||||||
var previusMonthStart = ($"{(previusMonthEnd.ToFarsi()).Substring(0, 8)}01").ToGeorgianDateTime();
|
|
||||||
|
|
||||||
watch.Start();
|
|
||||||
//دریافت اطلاعات بدهکارن و ساخت لیست پیامک
|
|
||||||
|
|
||||||
#region GetSmsListData
|
|
||||||
|
|
||||||
//var rollcallServiceList = _context.RollCallServices.Where(x => x.StartService.Date <= previusMonthStart.Date && x.EndService.Date >= previusMonthEnd.Date).ToList();
|
|
||||||
var institutionContracts = await _context.InstitutionContractSet.AsSplitQuery()
|
|
||||||
.Include(x => x.Installments)
|
|
||||||
.Select(x =>
|
|
||||||
new InstitutionContractViewModel
|
|
||||||
{
|
|
||||||
Id = x.id,
|
|
||||||
ContractingPartyId = x.ContractingPartyId,
|
|
||||||
ContractingPartyName = x.ContractingPartyName,
|
|
||||||
ContractStartGr = x.ContractStartGr,
|
|
||||||
ContractStartFa = x.ContractStartFa,
|
|
||||||
ContractEndGr = x.ContractEndGr,
|
|
||||||
ContractEndFa = x.ContractEndFa,
|
|
||||||
IsActiveString = x.IsActiveString,
|
|
||||||
ContractAmountDouble = x.ContractAmount,
|
|
||||||
OfficialCompany = x.OfficialCompany,
|
|
||||||
IsInstallment = x.IsInstallment,
|
|
||||||
VerificationStatus = x.VerificationStatus,
|
|
||||||
SigningType = x.SigningType,
|
|
||||||
InstallmentList = x.Installments
|
|
||||||
.Select(ins => new InstitutionContractInstallmentViewModel
|
|
||||||
{ AmountDouble = ins.Amount, InstallmentDateGr = ins.InstallmentDateGr })
|
|
||||||
.OrderBy(ins => ins.InstallmentDateGr).Skip(1).ToList(),
|
|
||||||
}).Where(x => x.ContractStartGr < checkDate && x.ContractEndGr >= checkDate &&
|
|
||||||
x.ContractAmountDouble > 0 && x.VerificationStatus != InstitutionContractVerificationStatus.PendingForVerify)
|
|
||||||
.GroupBy(x => x.ContractingPartyId).Select(x => x.First())
|
|
||||||
.ToListAsync();
|
|
||||||
// قرارداد هایی که بطور یکجا پرداخت شده اند
|
|
||||||
var paidInFull = institutionContracts.Where(x =>
|
|
||||||
x.SigningType != InstitutionContractSigningType.Legacy && x.IsInstallment == false && x.SigningType != null).ToList();
|
|
||||||
|
|
||||||
//حذف قراداد هایی که یکجا پرداخت شده اند از لیست ایجاد سند ماهانه
|
|
||||||
institutionContracts = institutionContracts.Except(paidInFull).ToList();
|
|
||||||
|
|
||||||
var contractingPartyList = await _context.PersonalContractingParties
|
|
||||||
.Where(x => institutionContracts.Select(ins => ins.ContractingPartyId).Contains(x.id)).ToListAsync();
|
|
||||||
|
|
||||||
var financialStatmentList = await _context.FinancialStatments.AsSplitQuery()
|
|
||||||
.Where(x => institutionContracts.Select(ins => ins.ContractingPartyId).Contains(x.ContractingPartyId))
|
|
||||||
.Include(x => x.FinancialTransactionList).Where(x => x.FinancialTransactionList.Count > 0).ToListAsync();
|
|
||||||
|
|
||||||
var phoneNumberList = await _context.InstitutionContractContactInfos
|
|
||||||
.Where(x => institutionContracts.Select(ins => ins.Id).Contains(x.InstitutionContractId))
|
|
||||||
.Where(x => x.SendSms && x.PhoneType == "شماره همراه" && !string.IsNullOrWhiteSpace(x.PhoneNumber) &&
|
|
||||||
x.PhoneNumber.Length == 11).ToListAsync();
|
|
||||||
|
|
||||||
Console.WriteLine("database query: " + watch.Elapsed);
|
|
||||||
watch.Stop();
|
|
||||||
watch.Start();
|
|
||||||
|
|
||||||
//var a = new FinancialInvoice(balance, item.ContractingPartyId, "");
|
|
||||||
//var b = new FinancialInvoiceItem("", balance, a.id, FinancialInvoiceItemType.PreviousDebt,
|
|
||||||
// 0);
|
|
||||||
//a.AddItem(b);
|
|
||||||
//_context.Add(a);
|
|
||||||
var oldInstitutionContract = institutionContracts.Where(x => x.IsInstallment == false).ToList();
|
|
||||||
var electronicInstitutionContract = institutionContracts.Where(x => x.IsInstallment == true).ToList();
|
|
||||||
foreach (var item in oldInstitutionContract)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var contractingParty = contractingPartyList.FirstOrDefault(x => x.id == item.ContractingPartyId);
|
|
||||||
//var isSend = sendedSms.Any(x => x.ContractingPatyId == contractingParty.Id);
|
|
||||||
if (!string.IsNullOrWhiteSpace(contractingParty.LName))
|
|
||||||
{
|
|
||||||
//Thread.Sleep(500);
|
|
||||||
var partyName = contractingParty.IsLegal == "حقیقی"
|
|
||||||
? $"{contractingParty.FName} {contractingParty.LName}"
|
|
||||||
: $"{contractingParty.LName}";
|
|
||||||
if (!string.IsNullOrWhiteSpace(contractingParty.SureName))
|
|
||||||
partyName = $"{partyName} ({contractingParty.SureName})";
|
|
||||||
|
|
||||||
if (partyName.Length > 25) partyName = $"{partyName.Substring(0, 25)}";
|
|
||||||
|
|
||||||
var isLegal = contractingParty.IsLegal == "حقوقی" ? true : false;
|
|
||||||
var isBlock = contractingParty.IsBlock == "true" ? true : false;
|
|
||||||
var isActive = contractingParty.IsActiveString == "true" ? true : false;
|
|
||||||
if (!string.IsNullOrWhiteSpace(contractingParty.IsActiveString) && isActive)
|
|
||||||
{
|
|
||||||
var hasFinancialStatement =
|
|
||||||
financialStatmentList.Any(x => x.ContractingPartyId == item.ContractingPartyId);
|
|
||||||
|
|
||||||
|
|
||||||
var hasPhonNumber = phoneNumberList.Any(x => x.InstitutionContractId == item.Id);
|
|
||||||
|
|
||||||
|
|
||||||
if (hasFinancialStatement && hasPhonNumber)
|
|
||||||
{
|
|
||||||
var phoneNumbers = phoneNumberList.Where(x => x.InstitutionContractId == item.Id)
|
|
||||||
.Select(x => new CreateContactInfo
|
|
||||||
{
|
|
||||||
PhoneType = x.PhoneType,
|
|
||||||
PhoneNumber = x.PhoneNumber,
|
|
||||||
|
|
||||||
InstitutionContractId = x.InstitutionContractId,
|
|
||||||
SendSms = x.SendSms
|
|
||||||
}).Where(x => x.PhoneNumber.Length == 11).ToList();
|
|
||||||
|
|
||||||
var transactions = financialStatmentList.FirstOrDefault(x =>
|
|
||||||
x.ContractingPartyId == item.ContractingPartyId);
|
|
||||||
|
|
||||||
var debtor = transactions.FinancialTransactionList.Sum(x => x.Deptor);
|
|
||||||
var creditor = transactions.FinancialTransactionList.Sum(x => x.Creditor);
|
|
||||||
|
|
||||||
|
|
||||||
var id = $"{item.ContractingPartyId}";
|
|
||||||
var aprove = $"{transactions.id}";
|
|
||||||
var balance = debtor - creditor;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (balance > 0) // اگر بدهکار بود
|
|
||||||
{
|
|
||||||
//var employers = _context.Employers.Where(x => x.ContractingPartyId == item.ContractingPartyId)
|
|
||||||
// .Select(x => x.id);
|
|
||||||
//var workshops = _context.WorkshopEmployers.Where(x => employers.Contains(x.EmployerId))
|
|
||||||
// .Select(x => x.WorkshopId).Distinct().ToList();
|
|
||||||
|
|
||||||
|
|
||||||
//var services =
|
|
||||||
// rollcallServiceList.Where(x => workshops.Contains(x.WorkshopId)).ToList();
|
|
||||||
|
|
||||||
//var hasRollCallService = services.Count > 0;
|
|
||||||
|
|
||||||
//موقت
|
|
||||||
var hasRollCallService = false;
|
|
||||||
|
|
||||||
//if (hasRollCallService)
|
|
||||||
//{
|
|
||||||
// var employees =
|
|
||||||
// _context.RollCallEmployees.Where(x => workshops.Contains(x.WorkshopId))
|
|
||||||
// .Select(x => x.id);
|
|
||||||
|
|
||||||
// var employeeCount = _context.RollCallEmployeesStatus
|
|
||||||
// .Where(x => employees.Contains(x.RollCallEmployeeId))
|
|
||||||
// .Count(x => x.EndDate.Date == activeStatusDate.Date);
|
|
||||||
|
|
||||||
// if (employeeCount == 0)
|
|
||||||
// hasRollCallService = false;
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (isLegal)
|
|
||||||
{
|
|
||||||
if (item.OfficialCompany == "Official") // حقوقی بدهکار رسمی
|
|
||||||
{
|
|
||||||
var balanceToMoney = balance.ToMoney();
|
|
||||||
|
|
||||||
foreach (var number in phoneNumbers)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
|
||||||
number.PhoneNumber.Length == 11)
|
|
||||||
{
|
|
||||||
|
|
||||||
var templateId = 161233;
|
|
||||||
if (typeOfSmsSetting ==
|
|
||||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
|
||||||
{
|
|
||||||
templateId = 394006;
|
|
||||||
}
|
|
||||||
|
|
||||||
smsList.Add(new SmsListData()
|
|
||||||
{
|
|
||||||
PhoneNumber = number.PhoneNumber,
|
|
||||||
TemplateId = templateId,
|
|
||||||
PartyName = partyName,
|
|
||||||
Amount = balanceToMoney,
|
|
||||||
ContractingPartyId = contractingParty.id,
|
|
||||||
AproveId = aprove,
|
|
||||||
TypeOfSmsMethod = "MonthlyBill",
|
|
||||||
Code1 = "",
|
|
||||||
Code2 = "",
|
|
||||||
InstitutionContractId = item.Id
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (item.OfficialCompany == "NotOfficial") // حقوقی بدهکار غیر رسمی
|
|
||||||
{
|
|
||||||
var balanceToMoney = balance.ToMoney();
|
|
||||||
foreach (var number in phoneNumbers)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
|
||||||
number.PhoneNumber.Length == 11)
|
|
||||||
{
|
|
||||||
|
|
||||||
var templateId = 347415;
|
|
||||||
if (typeOfSmsSetting ==
|
|
||||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
|
||||||
{
|
|
||||||
templateId = 679068;
|
|
||||||
}
|
|
||||||
|
|
||||||
smsList.Add(new SmsListData()
|
|
||||||
{
|
|
||||||
PhoneNumber = number.PhoneNumber,
|
|
||||||
TemplateId = templateId,
|
|
||||||
PartyName = partyName,
|
|
||||||
Amount = balanceToMoney,
|
|
||||||
ContractingPartyId = contractingParty.id,
|
|
||||||
AproveId = aprove,
|
|
||||||
TypeOfSmsMethod = "MonthlyBill",
|
|
||||||
Code1 = "",
|
|
||||||
Code2 = "",
|
|
||||||
InstitutionContractId = item.Id
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (item.OfficialCompany == "Official") // حقیقی بدهکار رسمی
|
|
||||||
{
|
|
||||||
var balanceToMoney = balance.ToMoney();
|
|
||||||
|
|
||||||
foreach (var number in phoneNumbers)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
|
||||||
number.PhoneNumber.Length == 11)
|
|
||||||
{
|
|
||||||
|
|
||||||
var templateId = 998180;
|
|
||||||
if (typeOfSmsSetting ==
|
|
||||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
|
||||||
{
|
|
||||||
templateId = 646040;
|
|
||||||
}
|
|
||||||
|
|
||||||
smsList.Add(new SmsListData()
|
|
||||||
{
|
|
||||||
PhoneNumber = number.PhoneNumber,
|
|
||||||
TemplateId = templateId,
|
|
||||||
PartyName = partyName,
|
|
||||||
Amount = balanceToMoney,
|
|
||||||
ContractingPartyId = contractingParty.id,
|
|
||||||
AproveId = aprove,
|
|
||||||
TypeOfSmsMethod = "MonthlyBill",
|
|
||||||
Code1 = "",
|
|
||||||
Code2 = "",
|
|
||||||
InstitutionContractId = item.Id
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (item.OfficialCompany == "NotOfficial") // حقیقی بدهکار غیر رسمی
|
|
||||||
{
|
|
||||||
var balanceToMoney = balance.ToMoney();
|
|
||||||
|
|
||||||
foreach (var number in phoneNumbers)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
|
||||||
number.PhoneNumber.Length == 11)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
var templateId = 810539;
|
|
||||||
if (typeOfSmsSetting ==
|
|
||||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
|
||||||
{
|
|
||||||
templateId = 566537;
|
|
||||||
}
|
|
||||||
|
|
||||||
smsList.Add(new SmsListData()
|
|
||||||
{
|
|
||||||
PhoneNumber = number.PhoneNumber,
|
|
||||||
TemplateId = templateId,
|
|
||||||
PartyName = partyName,
|
|
||||||
Amount = balanceToMoney,
|
|
||||||
ContractingPartyId = contractingParty.id,
|
|
||||||
AproveId = aprove,
|
|
||||||
TypeOfSmsMethod = "MonthlyBill",
|
|
||||||
Code1 = "",
|
|
||||||
Code2 = "",
|
|
||||||
InstitutionContractId = item.Id
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
phoneNumbers = new List<CreateContactInfo>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
string name = item.ContractingPartyName.Length > 18
|
|
||||||
? item.ContractingPartyName.Substring(0, 18)
|
|
||||||
: item.ContractingPartyName;
|
|
||||||
string errMess = $"{name}-خطا";
|
|
||||||
// _smsService.Alarm("09114221321", errMess);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var item in electronicInstitutionContract)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var contractingParty = contractingPartyList.FirstOrDefault(x => x.id == item.ContractingPartyId);
|
|
||||||
if (!string.IsNullOrWhiteSpace(contractingParty.LName))
|
|
||||||
{
|
|
||||||
var partyName = contractingParty.IsLegal == "حقیقی"
|
|
||||||
? $"{contractingParty.FName} {contractingParty.LName}"
|
|
||||||
: $"{contractingParty.LName}";
|
|
||||||
if (!string.IsNullOrWhiteSpace(contractingParty.SureName))
|
|
||||||
partyName = $"{partyName} ({contractingParty.SureName})";
|
|
||||||
|
|
||||||
if (partyName.Length > 25) partyName = $"{partyName.Substring(0, 25)}";
|
|
||||||
|
|
||||||
var isLegal = contractingParty.IsLegal == "حقوقی" ? true : false;
|
|
||||||
var isBlock = contractingParty.IsBlock == "true" ? true : false;
|
|
||||||
var isActive = contractingParty.IsActiveString == "true" ? true : false;
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(contractingParty.IsActiveString) && isActive)
|
|
||||||
{
|
|
||||||
var hasFinancialStatement =
|
|
||||||
financialStatmentList.Any(x => x.ContractingPartyId == item.ContractingPartyId);
|
|
||||||
|
|
||||||
|
|
||||||
var hasPhonNumber = phoneNumberList.Any(x => x.InstitutionContractId == item.Id);
|
|
||||||
|
|
||||||
if (hasFinancialStatement && hasPhonNumber)
|
|
||||||
{
|
|
||||||
var phoneNumbers = phoneNumberList.Where(x => x.InstitutionContractId == item.Id)
|
|
||||||
.Select(x => new CreateContactInfo
|
|
||||||
{
|
|
||||||
PhoneType = x.PhoneType,
|
|
||||||
PhoneNumber = x.PhoneNumber,
|
|
||||||
|
|
||||||
InstitutionContractId = x.InstitutionContractId,
|
|
||||||
SendSms = x.SendSms
|
|
||||||
}).Where(x => x.PhoneNumber.Length == 11).ToList();
|
|
||||||
|
|
||||||
var transactions = financialStatmentList.FirstOrDefault(x =>
|
|
||||||
x.ContractingPartyId == item.ContractingPartyId);
|
|
||||||
|
|
||||||
var debtor = transactions.FinancialTransactionList.Sum(x => x.Deptor);
|
|
||||||
var creditor = transactions.FinancialTransactionList.Sum(x => x.Creditor);
|
|
||||||
|
|
||||||
|
|
||||||
var id = $"{item.ContractingPartyId}";
|
|
||||||
var aprove = $"{transactions.id}";
|
|
||||||
var balance = debtor - creditor;
|
|
||||||
int templateId = 0;
|
|
||||||
//انتخاب قالب پیامک بر اساس حقیق/حقوقی
|
|
||||||
if (isLegal)
|
|
||||||
{
|
|
||||||
templateId = 789638;
|
|
||||||
if (typeOfSmsSetting ==
|
|
||||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
|
||||||
{
|
|
||||||
templateId = 983035;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
templateId = 768277;
|
|
||||||
if (typeOfSmsSetting ==
|
|
||||||
TypeOfSmsSetting.MonthlyInstitutionContract)
|
|
||||||
{
|
|
||||||
templateId = 479624;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (balance > 0) // اگر بدهکار بود
|
|
||||||
{
|
|
||||||
var balanceToMoney = balance.ToMoney();
|
|
||||||
|
|
||||||
foreach (var number in phoneNumbers)
|
|
||||||
{
|
|
||||||
string publicId = transactions.PublicIdStr;
|
|
||||||
string code1 = publicId.Substring(0, 25);
|
|
||||||
string code2 = publicId.Substring(25);
|
|
||||||
|
|
||||||
|
|
||||||
smsList.Add(new SmsListData()
|
|
||||||
{
|
|
||||||
PhoneNumber = number.PhoneNumber,
|
|
||||||
TemplateId = templateId,
|
|
||||||
PartyName = partyName,
|
|
||||||
Amount = balanceToMoney,
|
|
||||||
ContractingPartyId = contractingParty.id,
|
|
||||||
AproveId = aprove,
|
|
||||||
TypeOfSmsMethod = "MonthlyBillNew",
|
|
||||||
Code1 = code1,
|
|
||||||
Code2 = code2,
|
|
||||||
InstitutionContractId = item.Id
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
_logger.LogError($"ContractingPartyId : {item.ContractingPartyId} - ContractingPartyName : {item.ContractingPartyName} - InstitutionContractId : {item.Id} خطای دریافت لیست بدهکاران ");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
Console.WriteLine("SmsListData: " + watch.Elapsed);
|
|
||||||
return smsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// ارسال پیامک های یاد آور بدهی
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task SendReminderSmsToContractingParties(List<SmsListData> smsListData, string typeOfSms,
|
|
||||||
string sendMessStart, string sendMessEnd)
|
|
||||||
{
|
|
||||||
//ارسال پیامک با اساس لیست
|
|
||||||
|
|
||||||
#region SendSMSFromList
|
|
||||||
|
|
||||||
if (smsListData.Any())
|
|
||||||
{
|
|
||||||
//await _smsService.Alarm("09114221321", sendMessStart);
|
|
||||||
//Thread.Sleep(1000);
|
|
||||||
//await _smsService.Alarm("09111485044", sendMessStart);
|
|
||||||
//Thread.Sleep(1000);
|
|
||||||
|
|
||||||
int successProcess = 1;
|
|
||||||
int countList = smsListData.Count;
|
|
||||||
|
|
||||||
|
|
||||||
foreach (var item in smsListData)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (item.TypeOfSmsMethod == "MonthlyBill")
|
|
||||||
{
|
|
||||||
var res = await _smsService.MonthlyBill(item.PhoneNumber, item.TemplateId, item.PartyName,
|
|
||||||
item.Amount,
|
|
||||||
$"{item.ContractingPartyId}", item.AproveId);
|
|
||||||
|
|
||||||
if (res.isSucceded)
|
|
||||||
{
|
|
||||||
var createSmsResult = new Company.Domain.SmsResultAgg.SmsResult(res.messaeId,
|
|
||||||
res.message, typeOfSms, item.PartyName, item.PhoneNumber,
|
|
||||||
item.ContractingPartyId, item.InstitutionContractId);
|
|
||||||
|
|
||||||
await _smsResultRepository.CreateAsync(createSmsResult);
|
|
||||||
await _smsResultRepository.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var res = await _smsService.MonthlyBillNew(item.PhoneNumber, item.TemplateId, item.PartyName,
|
|
||||||
item.Amount, item.Code1, item.Code2);
|
|
||||||
if (res.isSucceded)
|
|
||||||
{
|
|
||||||
var createSmsResult = new Company.Domain.SmsResultAgg.SmsResult(res.messaeId,
|
|
||||||
res.message, typeOfSms, item.PartyName, item.PhoneNumber,
|
|
||||||
item.ContractingPartyId, item.InstitutionContractId);
|
|
||||||
|
|
||||||
await _smsResultRepository.CreateAsync(createSmsResult);
|
|
||||||
await _smsResultRepository.SaveChangesAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread.Sleep(600);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
string name = item.PartyName.Length > 18 ? item.PartyName.Substring(0, 18) : item.PartyName;
|
|
||||||
string errMess = $"{name}-خطا";
|
|
||||||
_logger.LogError(errMess);
|
|
||||||
await _smsService.Alarm("09114221321", errMess);
|
|
||||||
}
|
|
||||||
|
|
||||||
var percent = (successProcess / (double)countList) * 100;
|
|
||||||
await _hubContext.Clients.Group(SendSmsHub.GetGroupName(7))
|
|
||||||
.SendAsync("showStatus", (int)percent);
|
|
||||||
|
|
||||||
successProcess += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//await _smsService.Alarm("09114221321", sendMessEnd);
|
|
||||||
//Thread.Sleep(1000);
|
|
||||||
//await _smsService.Alarm("09111485044", sendMessEnd);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region PrivateMetods
|
#region PrivateMetods
|
||||||
|
|
||||||
@@ -4224,89 +3611,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region InstitutionContractConfirm
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// ارسال پیامک یادآور تایید قراداد مالی
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task SendInstitutionContractConfirmSmsTask()
|
|
||||||
{
|
|
||||||
var now = DateTime.Now;
|
|
||||||
|
|
||||||
|
|
||||||
// تبدیل تاریخ میلادی به شمسی
|
|
||||||
var persianNow = now.ToFarsi();
|
|
||||||
var persianEndOfMonth = int.Parse(persianNow.FindeEndOfMonth().Substring(8, 2));
|
|
||||||
var dayOfMonth = int.Parse(persianNow.Substring(8, 2));
|
|
||||||
var hour = now.Hour;
|
|
||||||
var minute = now.Minute;
|
|
||||||
var checkAnyToExecute = false;
|
|
||||||
|
|
||||||
//اگر آخرین روز ماه باشد
|
|
||||||
//اگر روز مثلا عدد روز 31 بود ولی آخرین روز ماه 30 بود
|
|
||||||
if (dayOfMonth == persianEndOfMonth)
|
|
||||||
{
|
|
||||||
checkAnyToExecute = await _context.SmsSettings
|
|
||||||
.AnyAsync(x =>
|
|
||||||
x.DayOfMonth >= dayOfMonth && /// اگر بزرگتر یا مساوی رو جاری بود
|
|
||||||
x.TimeOfDay.Hours == hour &&
|
|
||||||
x.TimeOfDay.Minutes == minute &&
|
|
||||||
x.TypeOfSmsSetting == TypeOfSmsSetting.InstitutionContractConfirm &&
|
|
||||||
x.IsActive
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
checkAnyToExecute = await _context.SmsSettings
|
|
||||||
.AnyAsync(x =>
|
|
||||||
x.DayOfMonth == dayOfMonth &&
|
|
||||||
x.TimeOfDay.Hours == hour &&
|
|
||||||
x.TimeOfDay.Minutes == minute &&
|
|
||||||
x.TypeOfSmsSetting == TypeOfSmsSetting.InstitutionContractConfirm &&
|
|
||||||
x.IsActive
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (checkAnyToExecute)
|
|
||||||
{
|
|
||||||
//اجرای تسک
|
|
||||||
_logger.LogInformation("اجرای تسک ارسال یاد آور تایید قراداد مالی SendInstitutionContractConfirmSms" +
|
|
||||||
persianNow + " - " + hour + ":" + minute);
|
|
||||||
//دریافت لیست قراداد های تایید نشده
|
|
||||||
var fromAmonthAgo = now.AddDays(-30);
|
|
||||||
var pendingContracts = await _context.InstitutionContractSet
|
|
||||||
.Where(x => x.CreationDate >= fromAmonthAgo && x.CreationDate.Date != now.Date &&
|
|
||||||
x.VerificationStatus == InstitutionContractVerificationStatus.PendingForVerify)
|
|
||||||
.Join(_context.PersonalContractingParties,
|
|
||||||
contract => contract.ContractingPartyId,
|
|
||||||
contractingParty => contractingParty.id,
|
|
||||||
(contract, contractingParty) => new { contract, contractingParty }).Select(x =>
|
|
||||||
new InstitutionCreationVerificationSmsDto
|
|
||||||
{
|
|
||||||
Number = x.contractingParty.Phone,
|
|
||||||
FullName = x.contractingParty.IsLegal == "حقیقی"
|
|
||||||
? $"{x.contractingParty.FName} {x.contractingParty.LName}"
|
|
||||||
: $"{x.contractingParty.LName}",
|
|
||||||
ContractingPartyId = x.contract.ContractingPartyId,
|
|
||||||
InstitutionContractId = x.contract.id,
|
|
||||||
InstitutionId = x.contract.PublicId,
|
|
||||||
}).ToListAsync();
|
|
||||||
|
|
||||||
string typeOfSms = "یادآور تایید قرارداد مالی";
|
|
||||||
foreach (var item in pendingContracts)
|
|
||||||
{
|
|
||||||
var sendResult = await _smsService.SendInstitutionCreationVerificationLink(item.Number, item.FullName,
|
|
||||||
item.InstitutionId, item.ContractingPartyId, item.InstitutionContractId, typeOfSms);
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("executed at : " + persianNow + " - " + hour + ":" + minute);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ using Microsoft.Extensions.Logging;
|
|||||||
using PersianTools.Core;
|
using PersianTools.Core;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -1418,6 +1419,59 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase<long, Inst
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
string name = item.ContractingPartyName.Length > 18
|
||||||
|
? item.ContractingPartyName.Substring(0, 18)
|
||||||
|
: item.ContractingPartyName;
|
||||||
|
string errMess = $"{name}-خطا";
|
||||||
|
await _smsService.Alarm("09114221321", errMess);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public async Task BlueDeActiveAfterZeroDebt()
|
||||||
|
{
|
||||||
|
var institutionContracts =await _context.InstitutionContractSet
|
||||||
|
.Where(x => x.IsActiveString == "blue").ToListAsync();
|
||||||
|
|
||||||
|
var financialStatmentList = await _context.FinancialStatments.AsSplitQuery()
|
||||||
|
.Where(x => institutionContracts.Select(ins => ins.ContractingPartyId).Contains(x.ContractingPartyId))
|
||||||
|
.Include(x => x.FinancialTransactionList).Where(x => x.FinancialTransactionList.Count > 0)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
foreach (var item in institutionContracts)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
var transactions =
|
||||||
|
financialStatmentList.FirstOrDefault(x => x.ContractingPartyId == item.ContractingPartyId);
|
||||||
|
|
||||||
|
if (transactions != null)
|
||||||
|
{
|
||||||
|
var debtor = transactions.FinancialTransactionList.Sum(x => x.Deptor);
|
||||||
|
var creditor = transactions.FinancialTransactionList.Sum(x => x.Creditor);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var balance = debtor - creditor;
|
||||||
|
|
||||||
|
|
||||||
|
if (balance <= 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
item.DeActive();
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -1431,7 +1485,693 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase<long, Inst
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
//ارسال پیامک یادآور تایید قرارداد مالی
|
||||||
|
#region InstitutionContractConfirm
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ارسال پیامک یادآور تایید قراداد مالی
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task SendInstitutionContractConfirmSmsTask()
|
||||||
|
{
|
||||||
|
var now = DateTime.Now;
|
||||||
|
|
||||||
|
|
||||||
|
// تبدیل تاریخ میلادی به شمسی
|
||||||
|
var persianNow = now.ToFarsi();
|
||||||
|
var persianEndOfMonth = int.Parse(persianNow.FindeEndOfMonth().Substring(8, 2));
|
||||||
|
var dayOfMonth = int.Parse(persianNow.Substring(8, 2));
|
||||||
|
var hour = now.Hour;
|
||||||
|
var minute = now.Minute;
|
||||||
|
var checkAnyToExecute = false;
|
||||||
|
|
||||||
|
//اگر آخرین روز ماه باشد
|
||||||
|
//اگر روز مثلا عدد روز 31 بود ولی آخرین روز ماه 30 بود
|
||||||
|
if (dayOfMonth == persianEndOfMonth)
|
||||||
|
{
|
||||||
|
checkAnyToExecute = await _context.SmsSettings
|
||||||
|
.AnyAsync(x =>
|
||||||
|
x.DayOfMonth >= dayOfMonth && /// اگر بزرگتر یا مساوی رو جاری بود
|
||||||
|
x.TimeOfDay.Hours == hour &&
|
||||||
|
x.TimeOfDay.Minutes == minute &&
|
||||||
|
x.TypeOfSmsSetting == TypeOfSmsSetting.InstitutionContractConfirm &&
|
||||||
|
x.IsActive
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
checkAnyToExecute = await _context.SmsSettings
|
||||||
|
.AnyAsync(x =>
|
||||||
|
x.DayOfMonth == dayOfMonth &&
|
||||||
|
x.TimeOfDay.Hours == hour &&
|
||||||
|
x.TimeOfDay.Minutes == minute &&
|
||||||
|
x.TypeOfSmsSetting == TypeOfSmsSetting.InstitutionContractConfirm &&
|
||||||
|
x.IsActive
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (checkAnyToExecute)
|
||||||
|
{
|
||||||
|
//اجرای تسک
|
||||||
|
_logger.LogInformation("اجرای تسک ارسال یاد آور تایید قراداد مالی SendInstitutionContractConfirmSms" +
|
||||||
|
persianNow + " - " + hour + ":" + minute);
|
||||||
|
//دریافت لیست قراداد های تایید نشده
|
||||||
|
var fromAmonthAgo = now.AddDays(-30);
|
||||||
|
var pendingContracts = await _context.InstitutionContractSet
|
||||||
|
.Where(x => x.CreationDate >= fromAmonthAgo && x.CreationDate.Date != now.Date &&
|
||||||
|
x.VerificationStatus == InstitutionContractVerificationStatus.PendingForVerify)
|
||||||
|
.Join(_context.PersonalContractingParties,
|
||||||
|
contract => contract.ContractingPartyId,
|
||||||
|
contractingParty => contractingParty.id,
|
||||||
|
(contract, contractingParty) => new { contract, contractingParty }).Select(x =>
|
||||||
|
new InstitutionCreationVerificationSmsDto
|
||||||
|
{
|
||||||
|
Number = x.contractingParty.Phone,
|
||||||
|
FullName = x.contractingParty.IsLegal == "حقیقی"
|
||||||
|
? $"{x.contractingParty.FName} {x.contractingParty.LName}"
|
||||||
|
: $"{x.contractingParty.LName}",
|
||||||
|
ContractingPartyId = x.contract.ContractingPartyId,
|
||||||
|
InstitutionContractId = x.contract.id,
|
||||||
|
InstitutionId = x.contract.PublicId,
|
||||||
|
}).ToListAsync();
|
||||||
|
|
||||||
|
string typeOfSms = "یادآور تایید قرارداد مالی";
|
||||||
|
foreach (var item in pendingContracts)
|
||||||
|
{
|
||||||
|
var sendResult = await _smsService.SendInstitutionCreationVerificationLink(item.Number, item.FullName,
|
||||||
|
item.InstitutionId, item.ContractingPartyId, item.InstitutionContractId, typeOfSms);
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("executed at : " + persianNow + " - " + hour + ":" + minute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ReminderSMS
|
||||||
|
/// <summary>
|
||||||
|
/// دریافت لیست - ارسال پیامک
|
||||||
|
/// فراخوانی از سمت بک گراند سرویس
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> SendReminderSmsForBackgroundTask()
|
||||||
|
{
|
||||||
|
var now = DateTime.Now;
|
||||||
|
|
||||||
|
|
||||||
|
// تبدیل تاریخ میلادی به شمسی
|
||||||
|
var persianNow = now.ToFarsi();
|
||||||
|
var persianEndOfMonth = int.Parse(persianNow.FindeEndOfMonth().Substring(8, 2));
|
||||||
|
var dayOfMonth = int.Parse(persianNow.Substring(8, 2));
|
||||||
|
var hour = now.Hour;
|
||||||
|
var minute = now.Minute;
|
||||||
|
var checkAnyToExecute = false;
|
||||||
|
|
||||||
|
//اگر آخرین روز ماه باشد
|
||||||
|
//اگر روز مثلا عدد روز 31 بود ولی آخرین روز ماه 30 بود
|
||||||
|
if (dayOfMonth == persianEndOfMonth)
|
||||||
|
{
|
||||||
|
checkAnyToExecute = await _context.SmsSettings
|
||||||
|
.AnyAsync(x =>
|
||||||
|
x.DayOfMonth >= dayOfMonth &&
|
||||||
|
x.TimeOfDay.Hours == hour &&
|
||||||
|
x.TimeOfDay.Minutes == minute &&
|
||||||
|
x.TypeOfSmsSetting == TypeOfSmsSetting.InstitutionContractDebtReminder &&
|
||||||
|
x.IsActive
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
checkAnyToExecute = await _context.SmsSettings
|
||||||
|
.AnyAsync(x =>
|
||||||
|
x.DayOfMonth == dayOfMonth &&
|
||||||
|
x.TimeOfDay.Hours == hour &&
|
||||||
|
x.TimeOfDay.Minutes == minute &&
|
||||||
|
x.TypeOfSmsSetting == TypeOfSmsSetting.InstitutionContractDebtReminder &&
|
||||||
|
x.IsActive
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (checkAnyToExecute)
|
||||||
|
{
|
||||||
|
//اجرای تسک
|
||||||
|
_logger.LogInformation("اجرای تسک پیامک های یاد آور SendReminderSmsForBackgroundTask" + persianNow + " - " +
|
||||||
|
hour + ":" + minute);
|
||||||
|
//دریافت لیست بدهکاران
|
||||||
|
var smsListData = await GetSmsListData(now, TypeOfSmsSetting.InstitutionContractDebtReminder);
|
||||||
|
string typeOfSms = "یادآور بدهی ماهانه";
|
||||||
|
string sendMessStart = "شروع پیامک یادآور";
|
||||||
|
string sendMessEnd = "پایان پیامک یادآور";
|
||||||
|
//ارسال پیامک
|
||||||
|
await SendReminderSmsToContractingParties(smsListData, typeOfSms, sendMessStart, sendMessEnd);
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine("executed at : " + persianNow + " - " + hour + ":" + minute);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ارسال پیامک صورت حساب ماهانه
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="now"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task SendMonthlySms(DateTime now)
|
||||||
|
{
|
||||||
|
//دریافت لیست بدهکاران
|
||||||
|
var smsListData = await GetSmsListData(now, TypeOfSmsSetting.MonthlyInstitutionContract);
|
||||||
|
|
||||||
|
string typeOfSms = "صورت حساب ماهانه";
|
||||||
|
string sendMessStart = "شروع پیامک ماهانه";
|
||||||
|
string sendMessEnd = "پایان پیامک ماهانه";
|
||||||
|
//ارسال پیامک
|
||||||
|
await SendReminderSmsToContractingParties(smsListData, typeOfSms, sendMessStart, sendMessEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///دریافت لیست بدهکارن
|
||||||
|
/// جهت ارسال پیامک
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<SmsListData>> GetSmsListData(DateTime checkDate, TypeOfSmsSetting typeOfSmsSetting)
|
||||||
|
{
|
||||||
|
var watch = new Stopwatch();
|
||||||
|
var smsList = new List<SmsListData>();
|
||||||
|
var currentMonthStart = ($"{(checkDate.ToFarsi()).Substring(0, 8)}01").ToGeorgianDateTime();
|
||||||
|
var previusMonthEnd = currentMonthStart.AddDays(-1);
|
||||||
|
var previusMonthStart = ($"{(previusMonthEnd.ToFarsi()).Substring(0, 8)}01").ToGeorgianDateTime();
|
||||||
|
|
||||||
|
watch.Start();
|
||||||
|
//دریافت اطلاعات بدهکارن و ساخت لیست پیامک
|
||||||
|
|
||||||
|
#region GetSmsListData
|
||||||
|
|
||||||
|
//var rollcallServiceList = _context.RollCallServices.Where(x => x.StartService.Date <= previusMonthStart.Date && x.EndService.Date >= previusMonthEnd.Date).ToList();
|
||||||
|
var institutionContracts = await _context.InstitutionContractSet.AsSplitQuery()
|
||||||
|
.Include(x => x.Installments)
|
||||||
|
.Select(x =>
|
||||||
|
new InstitutionContractViewModel
|
||||||
|
{
|
||||||
|
Id = x.id,
|
||||||
|
ContractingPartyId = x.ContractingPartyId,
|
||||||
|
ContractingPartyName = x.ContractingPartyName,
|
||||||
|
ContractStartGr = x.ContractStartGr,
|
||||||
|
ContractStartFa = x.ContractStartFa,
|
||||||
|
ContractEndGr = x.ContractEndGr,
|
||||||
|
ContractEndFa = x.ContractEndFa,
|
||||||
|
IsActiveString = x.IsActiveString,
|
||||||
|
ContractAmountDouble = x.ContractAmount,
|
||||||
|
OfficialCompany = x.OfficialCompany,
|
||||||
|
IsInstallment = x.IsInstallment,
|
||||||
|
VerificationStatus = x.VerificationStatus,
|
||||||
|
SigningType = x.SigningType,
|
||||||
|
InstallmentList = x.Installments
|
||||||
|
.Select(ins => new InstitutionContractInstallmentViewModel
|
||||||
|
{ AmountDouble = ins.Amount, InstallmentDateGr = ins.InstallmentDateGr })
|
||||||
|
.OrderBy(ins => ins.InstallmentDateGr).Skip(1).ToList(),
|
||||||
|
}).Where(x => x.ContractStartGr < checkDate && x.ContractEndGr >= checkDate &&
|
||||||
|
x.ContractAmountDouble > 0 && x.VerificationStatus != InstitutionContractVerificationStatus.PendingForVerify)
|
||||||
|
.GroupBy(x => x.ContractingPartyId).Select(x => x.First())
|
||||||
|
.ToListAsync();
|
||||||
|
// قرارداد هایی که بطور یکجا پرداخت شده اند
|
||||||
|
var paidInFull = institutionContracts.Where(x =>
|
||||||
|
x.SigningType != InstitutionContractSigningType.Legacy && x.IsInstallment == false && x.SigningType != null).ToList();
|
||||||
|
|
||||||
|
//حذف قراداد هایی که یکجا پرداخت شده اند از لیست ایجاد سند ماهانه
|
||||||
|
institutionContracts = institutionContracts.Except(paidInFull).ToList();
|
||||||
|
|
||||||
|
var contractingPartyList = await _context.PersonalContractingParties
|
||||||
|
.Where(x => institutionContracts.Select(ins => ins.ContractingPartyId).Contains(x.id)).ToListAsync();
|
||||||
|
|
||||||
|
var financialStatmentList = await _context.FinancialStatments.AsSplitQuery()
|
||||||
|
.Where(x => institutionContracts.Select(ins => ins.ContractingPartyId).Contains(x.ContractingPartyId))
|
||||||
|
.Include(x => x.FinancialTransactionList).Where(x => x.FinancialTransactionList.Count > 0).ToListAsync();
|
||||||
|
|
||||||
|
var phoneNumberList = await _context.InstitutionContractContactInfos
|
||||||
|
.Where(x => institutionContracts.Select(ins => ins.Id).Contains(x.InstitutionContractId))
|
||||||
|
.Where(x => x.SendSms && x.PhoneType == "شماره همراه" && !string.IsNullOrWhiteSpace(x.PhoneNumber) &&
|
||||||
|
x.PhoneNumber.Length == 11).ToListAsync();
|
||||||
|
|
||||||
|
Console.WriteLine("database query: " + watch.Elapsed);
|
||||||
|
watch.Stop();
|
||||||
|
watch.Start();
|
||||||
|
|
||||||
|
//var a = new FinancialInvoice(balance, item.ContractingPartyId, "");
|
||||||
|
//var b = new FinancialInvoiceItem("", balance, a.id, FinancialInvoiceItemType.PreviousDebt,
|
||||||
|
// 0);
|
||||||
|
//a.AddItem(b);
|
||||||
|
//_context.Add(a);
|
||||||
|
var oldInstitutionContract = institutionContracts.Where(x => x.IsInstallment == false).ToList();
|
||||||
|
var electronicInstitutionContract = institutionContracts.Where(x => x.IsInstallment == true).ToList();
|
||||||
|
foreach (var item in oldInstitutionContract)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var contractingParty = contractingPartyList.FirstOrDefault(x => x.id == item.ContractingPartyId);
|
||||||
|
//var isSend = sendedSms.Any(x => x.ContractingPatyId == contractingParty.Id);
|
||||||
|
if (!string.IsNullOrWhiteSpace(contractingParty.LName))
|
||||||
|
{
|
||||||
|
//Thread.Sleep(500);
|
||||||
|
var partyName = contractingParty.IsLegal == "حقیقی"
|
||||||
|
? $"{contractingParty.FName} {contractingParty.LName}"
|
||||||
|
: $"{contractingParty.LName}";
|
||||||
|
if (!string.IsNullOrWhiteSpace(contractingParty.SureName))
|
||||||
|
partyName = $"{partyName} ({contractingParty.SureName})";
|
||||||
|
|
||||||
|
if (partyName.Length > 25) partyName = $"{partyName.Substring(0, 25)}";
|
||||||
|
|
||||||
|
var isLegal = contractingParty.IsLegal == "حقوقی" ? true : false;
|
||||||
|
var isBlock = contractingParty.IsBlock == "true" ? true : false;
|
||||||
|
var isActive = contractingParty.IsActiveString == "true" ? true : false;
|
||||||
|
if (!string.IsNullOrWhiteSpace(contractingParty.IsActiveString) && isActive)
|
||||||
|
{
|
||||||
|
var hasFinancialStatement =
|
||||||
|
financialStatmentList.Any(x => x.ContractingPartyId == item.ContractingPartyId);
|
||||||
|
|
||||||
|
|
||||||
|
var hasPhonNumber = phoneNumberList.Any(x => x.InstitutionContractId == item.Id);
|
||||||
|
|
||||||
|
|
||||||
|
if (hasFinancialStatement && hasPhonNumber)
|
||||||
|
{
|
||||||
|
var phoneNumbers = phoneNumberList.Where(x => x.InstitutionContractId == item.Id)
|
||||||
|
.Select(x => new CreateContactInfo
|
||||||
|
{
|
||||||
|
PhoneType = x.PhoneType,
|
||||||
|
PhoneNumber = x.PhoneNumber,
|
||||||
|
|
||||||
|
InstitutionContractId = x.InstitutionContractId,
|
||||||
|
SendSms = x.SendSms
|
||||||
|
}).Where(x => x.PhoneNumber.Length == 11).ToList();
|
||||||
|
|
||||||
|
var transactions = financialStatmentList.FirstOrDefault(x =>
|
||||||
|
x.ContractingPartyId == item.ContractingPartyId);
|
||||||
|
|
||||||
|
var debtor = transactions.FinancialTransactionList.Sum(x => x.Deptor);
|
||||||
|
var creditor = transactions.FinancialTransactionList.Sum(x => x.Creditor);
|
||||||
|
|
||||||
|
|
||||||
|
var id = $"{item.ContractingPartyId}";
|
||||||
|
var aprove = $"{transactions.id}";
|
||||||
|
var balance = debtor - creditor;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (balance > 0) // اگر بدهکار بود
|
||||||
|
{
|
||||||
|
//var employers = _context.Employers.Where(x => x.ContractingPartyId == item.ContractingPartyId)
|
||||||
|
// .Select(x => x.id);
|
||||||
|
//var workshops = _context.WorkshopEmployers.Where(x => employers.Contains(x.EmployerId))
|
||||||
|
// .Select(x => x.WorkshopId).Distinct().ToList();
|
||||||
|
|
||||||
|
|
||||||
|
//var services =
|
||||||
|
// rollcallServiceList.Where(x => workshops.Contains(x.WorkshopId)).ToList();
|
||||||
|
|
||||||
|
//var hasRollCallService = services.Count > 0;
|
||||||
|
|
||||||
|
//موقت
|
||||||
|
var hasRollCallService = false;
|
||||||
|
|
||||||
|
//if (hasRollCallService)
|
||||||
|
//{
|
||||||
|
// var employees =
|
||||||
|
// _context.RollCallEmployees.Where(x => workshops.Contains(x.WorkshopId))
|
||||||
|
// .Select(x => x.id);
|
||||||
|
|
||||||
|
// var employeeCount = _context.RollCallEmployeesStatus
|
||||||
|
// .Where(x => employees.Contains(x.RollCallEmployeeId))
|
||||||
|
// .Count(x => x.EndDate.Date == activeStatusDate.Date);
|
||||||
|
|
||||||
|
// if (employeeCount == 0)
|
||||||
|
// hasRollCallService = false;
|
||||||
|
//}
|
||||||
|
|
||||||
|
if (isLegal)
|
||||||
|
{
|
||||||
|
if (item.OfficialCompany == "Official") // حقوقی بدهکار رسمی
|
||||||
|
{
|
||||||
|
var balanceToMoney = balance.ToMoney();
|
||||||
|
|
||||||
|
foreach (var number in phoneNumbers)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||||
|
number.PhoneNumber.Length == 11)
|
||||||
|
{
|
||||||
|
|
||||||
|
var templateId = 161233;
|
||||||
|
if (typeOfSmsSetting ==
|
||||||
|
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||||
|
{
|
||||||
|
templateId = 394006;
|
||||||
|
}
|
||||||
|
|
||||||
|
smsList.Add(new SmsListData()
|
||||||
|
{
|
||||||
|
PhoneNumber = number.PhoneNumber,
|
||||||
|
TemplateId = templateId,
|
||||||
|
PartyName = partyName,
|
||||||
|
Amount = balanceToMoney,
|
||||||
|
ContractingPartyId = contractingParty.id,
|
||||||
|
AproveId = aprove,
|
||||||
|
TypeOfSmsMethod = "MonthlyBill",
|
||||||
|
Code1 = "",
|
||||||
|
Code2 = "",
|
||||||
|
InstitutionContractId = item.Id
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (item.OfficialCompany == "NotOfficial") // حقوقی بدهکار غیر رسمی
|
||||||
|
{
|
||||||
|
var balanceToMoney = balance.ToMoney();
|
||||||
|
foreach (var number in phoneNumbers)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||||
|
number.PhoneNumber.Length == 11)
|
||||||
|
{
|
||||||
|
|
||||||
|
var templateId = 347415;
|
||||||
|
if (typeOfSmsSetting ==
|
||||||
|
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||||
|
{
|
||||||
|
templateId = 679068;
|
||||||
|
}
|
||||||
|
|
||||||
|
smsList.Add(new SmsListData()
|
||||||
|
{
|
||||||
|
PhoneNumber = number.PhoneNumber,
|
||||||
|
TemplateId = templateId,
|
||||||
|
PartyName = partyName,
|
||||||
|
Amount = balanceToMoney,
|
||||||
|
ContractingPartyId = contractingParty.id,
|
||||||
|
AproveId = aprove,
|
||||||
|
TypeOfSmsMethod = "MonthlyBill",
|
||||||
|
Code1 = "",
|
||||||
|
Code2 = "",
|
||||||
|
InstitutionContractId = item.Id
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (item.OfficialCompany == "Official") // حقیقی بدهکار رسمی
|
||||||
|
{
|
||||||
|
var balanceToMoney = balance.ToMoney();
|
||||||
|
|
||||||
|
foreach (var number in phoneNumbers)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||||
|
number.PhoneNumber.Length == 11)
|
||||||
|
{
|
||||||
|
|
||||||
|
var templateId = 998180;
|
||||||
|
if (typeOfSmsSetting ==
|
||||||
|
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||||
|
{
|
||||||
|
templateId = 646040;
|
||||||
|
}
|
||||||
|
|
||||||
|
smsList.Add(new SmsListData()
|
||||||
|
{
|
||||||
|
PhoneNumber = number.PhoneNumber,
|
||||||
|
TemplateId = templateId,
|
||||||
|
PartyName = partyName,
|
||||||
|
Amount = balanceToMoney,
|
||||||
|
ContractingPartyId = contractingParty.id,
|
||||||
|
AproveId = aprove,
|
||||||
|
TypeOfSmsMethod = "MonthlyBill",
|
||||||
|
Code1 = "",
|
||||||
|
Code2 = "",
|
||||||
|
InstitutionContractId = item.Id
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (item.OfficialCompany == "NotOfficial") // حقیقی بدهکار غیر رسمی
|
||||||
|
{
|
||||||
|
var balanceToMoney = balance.ToMoney();
|
||||||
|
|
||||||
|
foreach (var number in phoneNumbers)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||||
|
number.PhoneNumber.Length == 11)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
var templateId = 810539;
|
||||||
|
if (typeOfSmsSetting ==
|
||||||
|
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||||
|
{
|
||||||
|
templateId = 566537;
|
||||||
|
}
|
||||||
|
|
||||||
|
smsList.Add(new SmsListData()
|
||||||
|
{
|
||||||
|
PhoneNumber = number.PhoneNumber,
|
||||||
|
TemplateId = templateId,
|
||||||
|
PartyName = partyName,
|
||||||
|
Amount = balanceToMoney,
|
||||||
|
ContractingPartyId = contractingParty.id,
|
||||||
|
AproveId = aprove,
|
||||||
|
TypeOfSmsMethod = "MonthlyBill",
|
||||||
|
Code1 = "",
|
||||||
|
Code2 = "",
|
||||||
|
InstitutionContractId = item.Id
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
phoneNumbers = new List<CreateContactInfo>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
string name = item.ContractingPartyName.Length > 18
|
||||||
|
? item.ContractingPartyName.Substring(0, 18)
|
||||||
|
: item.ContractingPartyName;
|
||||||
|
string errMess = $"{name}-خطا";
|
||||||
|
// _smsService.Alarm("09114221321", errMess);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var item in electronicInstitutionContract)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var contractingParty = contractingPartyList.FirstOrDefault(x => x.id == item.ContractingPartyId);
|
||||||
|
if (!string.IsNullOrWhiteSpace(contractingParty.LName))
|
||||||
|
{
|
||||||
|
var partyName = contractingParty.IsLegal == "حقیقی"
|
||||||
|
? $"{contractingParty.FName} {contractingParty.LName}"
|
||||||
|
: $"{contractingParty.LName}";
|
||||||
|
if (!string.IsNullOrWhiteSpace(contractingParty.SureName))
|
||||||
|
partyName = $"{partyName} ({contractingParty.SureName})";
|
||||||
|
|
||||||
|
if (partyName.Length > 25) partyName = $"{partyName.Substring(0, 25)}";
|
||||||
|
|
||||||
|
var isLegal = contractingParty.IsLegal == "حقوقی" ? true : false;
|
||||||
|
var isBlock = contractingParty.IsBlock == "true" ? true : false;
|
||||||
|
var isActive = contractingParty.IsActiveString == "true" ? true : false;
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(contractingParty.IsActiveString) && isActive)
|
||||||
|
{
|
||||||
|
var hasFinancialStatement =
|
||||||
|
financialStatmentList.Any(x => x.ContractingPartyId == item.ContractingPartyId);
|
||||||
|
|
||||||
|
|
||||||
|
var hasPhonNumber = phoneNumberList.Any(x => x.InstitutionContractId == item.Id);
|
||||||
|
|
||||||
|
if (hasFinancialStatement && hasPhonNumber)
|
||||||
|
{
|
||||||
|
var phoneNumbers = phoneNumberList.Where(x => x.InstitutionContractId == item.Id)
|
||||||
|
.Select(x => new CreateContactInfo
|
||||||
|
{
|
||||||
|
PhoneType = x.PhoneType,
|
||||||
|
PhoneNumber = x.PhoneNumber,
|
||||||
|
|
||||||
|
InstitutionContractId = x.InstitutionContractId,
|
||||||
|
SendSms = x.SendSms
|
||||||
|
}).Where(x => x.PhoneNumber.Length == 11).ToList();
|
||||||
|
|
||||||
|
var transactions = financialStatmentList.FirstOrDefault(x =>
|
||||||
|
x.ContractingPartyId == item.ContractingPartyId);
|
||||||
|
|
||||||
|
var debtor = transactions.FinancialTransactionList.Sum(x => x.Deptor);
|
||||||
|
var creditor = transactions.FinancialTransactionList.Sum(x => x.Creditor);
|
||||||
|
|
||||||
|
|
||||||
|
var id = $"{item.ContractingPartyId}";
|
||||||
|
var aprove = $"{transactions.id}";
|
||||||
|
var balance = debtor - creditor;
|
||||||
|
int templateId = 0;
|
||||||
|
//انتخاب قالب پیامک بر اساس حقیق/حقوقی
|
||||||
|
if (isLegal)
|
||||||
|
{
|
||||||
|
templateId = 789638;
|
||||||
|
if (typeOfSmsSetting ==
|
||||||
|
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||||
|
{
|
||||||
|
templateId = 983035;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
templateId = 768277;
|
||||||
|
if (typeOfSmsSetting ==
|
||||||
|
TypeOfSmsSetting.MonthlyInstitutionContract)
|
||||||
|
{
|
||||||
|
templateId = 479624;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (balance > 0) // اگر بدهکار بود
|
||||||
|
{
|
||||||
|
var balanceToMoney = balance.ToMoney();
|
||||||
|
|
||||||
|
foreach (var number in phoneNumbers)
|
||||||
|
{
|
||||||
|
string publicId = transactions.PublicIdStr;
|
||||||
|
string code1 = publicId.Substring(0, 25);
|
||||||
|
string code2 = publicId.Substring(25);
|
||||||
|
|
||||||
|
|
||||||
|
smsList.Add(new SmsListData()
|
||||||
|
{
|
||||||
|
PhoneNumber = number.PhoneNumber,
|
||||||
|
TemplateId = templateId,
|
||||||
|
PartyName = partyName,
|
||||||
|
Amount = balanceToMoney,
|
||||||
|
ContractingPartyId = contractingParty.id,
|
||||||
|
AproveId = aprove,
|
||||||
|
TypeOfSmsMethod = "MonthlyBillNew",
|
||||||
|
Code1 = code1,
|
||||||
|
Code2 = code2,
|
||||||
|
InstitutionContractId = item.Id
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogError($"ContractingPartyId : {item.ContractingPartyId} - ContractingPartyName : {item.ContractingPartyName} - InstitutionContractId : {item.Id} خطای دریافت لیست بدهکاران ");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
Console.WriteLine("SmsListData: " + watch.Elapsed);
|
||||||
|
return smsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ارسال پیامک های یاد آور بدهی
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task SendReminderSmsToContractingParties(List<SmsListData> smsListData, string typeOfSms,
|
||||||
|
string sendMessStart, string sendMessEnd)
|
||||||
|
{
|
||||||
|
//ارسال پیامک با اساس لیست
|
||||||
|
|
||||||
|
#region SendSMSFromList
|
||||||
|
|
||||||
|
if (smsListData.Any())
|
||||||
|
{
|
||||||
|
//await _smsService.Alarm("09114221321", sendMessStart);
|
||||||
|
//Thread.Sleep(1000);
|
||||||
|
//await _smsService.Alarm("09111485044", sendMessStart);
|
||||||
|
//Thread.Sleep(1000);
|
||||||
|
|
||||||
|
int successProcess = 1;
|
||||||
|
int countList = smsListData.Count;
|
||||||
|
|
||||||
|
|
||||||
|
foreach (var item in smsListData)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (item.TypeOfSmsMethod == "MonthlyBill")
|
||||||
|
{
|
||||||
|
var res = await _smsService.MonthlyBill(item.PhoneNumber, item.TemplateId, item.PartyName,
|
||||||
|
item.Amount,
|
||||||
|
$"{item.ContractingPartyId}", item.AproveId);
|
||||||
|
|
||||||
|
if (res.isSucceded)
|
||||||
|
{
|
||||||
|
var createSmsResult = new Company.Domain.SmsResultAgg.SmsResult(res.messaeId,
|
||||||
|
res.message, typeOfSms, item.PartyName, item.PhoneNumber,
|
||||||
|
item.ContractingPartyId, item.InstitutionContractId);
|
||||||
|
|
||||||
|
await _smsResultRepository.CreateAsync(createSmsResult);
|
||||||
|
await _smsResultRepository.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var res = await _smsService.MonthlyBillNew(item.PhoneNumber, item.TemplateId, item.PartyName,
|
||||||
|
item.Amount, item.Code1, item.Code2);
|
||||||
|
if (res.isSucceded)
|
||||||
|
{
|
||||||
|
var createSmsResult = new Company.Domain.SmsResultAgg.SmsResult(res.messaeId,
|
||||||
|
res.message, typeOfSms, item.PartyName, item.PhoneNumber,
|
||||||
|
item.ContractingPartyId, item.InstitutionContractId);
|
||||||
|
|
||||||
|
await _smsResultRepository.CreateAsync(createSmsResult);
|
||||||
|
await _smsResultRepository.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread.Sleep(600);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
string name = item.PartyName.Length > 18 ? item.PartyName.Substring(0, 18) : item.PartyName;
|
||||||
|
string errMess = $"{name}-خطا";
|
||||||
|
_logger.LogError(errMess);
|
||||||
|
await _smsService.Alarm("09114221321", errMess);
|
||||||
|
}
|
||||||
|
|
||||||
|
var percent = (successProcess / (double)countList) * 100;
|
||||||
|
await _hubContext.Clients.Group(SendSmsHub.GetGroupName(7))
|
||||||
|
.SendAsync("showStatus", (int)percent);
|
||||||
|
|
||||||
|
successProcess += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//await _smsService.Alarm("09114221321", sendMessEnd);
|
||||||
|
//Thread.Sleep(1000);
|
||||||
|
//await _smsService.Alarm("09111485044", sendMessEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user