CreateTransaction completed
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
|
||||
using _0_Framework.Application;
|
||||
using Company.Domain.ContarctingPartyAgg;
|
||||
using Company.Domain.InstitutionContractAgg;
|
||||
using Hangfire;
|
||||
@@ -10,7 +11,7 @@ public class JobSchedulerRegistrator
|
||||
private readonly IBackgroundJobClient _backgroundJobClient;
|
||||
private readonly SmsReminder _smsReminder;
|
||||
private readonly IInstitutionContractRepository _institutionContractRepository;
|
||||
private static DateTime? _lastRunDebtReminder;
|
||||
private static DateTime? _lastRunCreateTransaction;
|
||||
|
||||
|
||||
public JobSchedulerRegistrator(SmsReminder smsReminder, IBackgroundJobClient backgroundJobClient, IInstitutionContractRepository institutionContractRepository)
|
||||
@@ -24,14 +25,56 @@ public class JobSchedulerRegistrator
|
||||
{
|
||||
|
||||
|
||||
//RecurringJob.AddOrUpdate(
|
||||
// "InstitutionContract.ReminderDebtSMS",
|
||||
// () => _institutionContractRepository.SendReminderSmsForBackgroundTask(),
|
||||
// "*/1 * * * *" // هر 1 دقیقه یکبار چک کن
|
||||
//);
|
||||
|
||||
RecurringJob.AddOrUpdate(
|
||||
"InstitutionContract.ReminderDebtSMS",
|
||||
() => _institutionContractRepository.SendReminderSmsForBackgroundTask(),
|
||||
"*/1 * * * *" // هر 1 دقیقه یکبار چک کن
|
||||
"InstitutionContract.CreateTransaction",
|
||||
() => CreateFinancialTransaction(),
|
||||
"*/1 * * * *" // هر 30 دقیقه یکبار چک کن
|
||||
);
|
||||
}
|
||||
|
||||
public void CreateFinancialTransaction()
|
||||
{
|
||||
var now = new DateTime(2025,11,21, 2, 0, 0);
|
||||
var endOfMonth = now.ToFarsi().FindeEndOfMonth();
|
||||
var endOfMonthGr = endOfMonth.ToGeorgianDateTime();
|
||||
|
||||
if (now.Date == endOfMonthGr.Date && now.Hour >= 2 && now.Hour < 4 &&
|
||||
now.Date != _lastRunCreateTransaction?.Date)
|
||||
{
|
||||
|
||||
var month = endOfMonth.Substring(5, 2);
|
||||
var year = endOfMonth.Substring(0, 4);
|
||||
var monthName = month.ToFarsiMonthByNumber();
|
||||
var description = $"{monthName} {year}";
|
||||
|
||||
|
||||
|
||||
var endnew = ($"{endOfMonth.Substring(0, 8)}01").FindeEndOfMonth();
|
||||
|
||||
var endNewGr = endnew.ToGeorgianDateTime();
|
||||
var endNewFa = endNewGr.ToFarsi();
|
||||
|
||||
try
|
||||
{
|
||||
_backgroundJobClient.Enqueue(() => _institutionContractRepository.CreateTransaction(endNewGr, endNewFa, description));
|
||||
_lastRunCreateTransaction = now;
|
||||
Console.WriteLine("CreateTransAction executed");
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//_smsService.Alarm("09114221321", "خطا-ایجاد سند مالی");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user