DeActiveInstitutionEndOfContract hangfire completed
This commit is contained in:
@@ -75,16 +75,22 @@ public class JobSchedulerRegistrator
|
||||
|
||||
|
||||
|
||||
RecurringJob.AddOrUpdate(
|
||||
"InstitutionContract.Block",
|
||||
() => Block(),
|
||||
"*/30 * * * *" // هر 30 دقیقه یکبار چک کن
|
||||
);
|
||||
//RecurringJob.AddOrUpdate(
|
||||
// "InstitutionContract.Block",
|
||||
// () => Block(),
|
||||
// "*/30 * * * *" // هر 30 دقیقه یکبار چک کن
|
||||
//);
|
||||
|
||||
//RecurringJob.AddOrUpdate(
|
||||
// "InstitutionContract.UnBlock",
|
||||
// () => UnBlock(),
|
||||
// "*/10 * * * *"
|
||||
//);
|
||||
|
||||
RecurringJob.AddOrUpdate(
|
||||
"InstitutionContract.UnBlock",
|
||||
() => UnBlock(),
|
||||
"*/10 * * * *"
|
||||
"InstitutionContract.DeActiveInstitutionEndOfContract",
|
||||
() => DeActiveInstitutionEndOfContract(),
|
||||
"*/30 * * * *"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -220,29 +226,48 @@ public class JobSchedulerRegistrator
|
||||
/// <summary>
|
||||
/// بلاگ سازی
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
///// <returns></returns>
|
||||
//[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
||||
//public async System.Threading.Tasks.Task Block()
|
||||
//{
|
||||
// _logger.LogInformation("block job run");
|
||||
// var now = DateTime.Now;
|
||||
// var executeDate = now.ToFarsi().Substring(8, 2);
|
||||
// if (executeDate == "20")
|
||||
// {
|
||||
// if (now.Hour >= 9 && now.Hour < 10)
|
||||
// {
|
||||
// await _institutionContractSmsServiceRepository.Block(now);
|
||||
// }
|
||||
|
||||
// }
|
||||
//}
|
||||
|
||||
//[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
||||
//public async System.Threading.Tasks.Task UnBlock()
|
||||
//{
|
||||
// _logger.LogInformation("UnBlock job run");
|
||||
|
||||
// await _institutionContractSmsServiceRepository.UnBlock();
|
||||
|
||||
//}
|
||||
|
||||
[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
||||
public async System.Threading.Tasks.Task Block()
|
||||
public async System.Threading.Tasks.Task DeActiveInstitutionEndOfContract()
|
||||
{
|
||||
_logger.LogInformation("block job run");
|
||||
_logger.LogInformation("DeActiveInstitutionEndOfContract job run");
|
||||
|
||||
|
||||
var now = DateTime.Now;
|
||||
var executeDate = now.ToFarsi().Substring(8, 2);
|
||||
if (executeDate == "20")
|
||||
if (executeDate == "01")
|
||||
{
|
||||
if (now.Hour >= 9 && now.Hour < 10)
|
||||
{
|
||||
await _institutionContractSmsServiceRepository.Block(now);
|
||||
await _institutionContractSmsServiceRepository.DeActiveInstitutionEndOfContract(now);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[DisableConcurrentExecution(timeoutInSeconds: 100)]
|
||||
public async System.Threading.Tasks.Task UnBlock()
|
||||
{
|
||||
_logger.LogInformation("UnBlock job run");
|
||||
|
||||
await _institutionContractSmsServiceRepository.UnBlock();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -83,5 +83,13 @@ public interface IInstitutionContractSmsServiceRepository : IRepository<long, In
|
||||
/// <returns></returns>
|
||||
Task UnBlock();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// غیر فعالسازی قرارداد های پایان یافته
|
||||
/// </summary>
|
||||
/// <param name="checkDate"></param>
|
||||
/// <returns></returns>
|
||||
Task DeActiveInstitutionEndOfContract(DateTime checkDate);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -2,12 +2,13 @@
|
||||
using _0_Framework.Application.Enums;
|
||||
using _0_Framework.Application.Sms;
|
||||
using _0_Framework.InfraStructure;
|
||||
|
||||
using Company.Domain.ContarctingPartyAgg;
|
||||
using Company.Domain.InstitutionContractAgg;
|
||||
using Company.Domain.SmsResultAgg;
|
||||
using CompanyManagment.App.Contracts.Hubs;
|
||||
using CompanyManagment.App.Contracts.InstitutionContract;
|
||||
using CompanyManagment.App.Contracts.InstitutionContractContactinfo;
|
||||
using CompanyManagment.EFCore.Migrations;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -18,7 +19,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Company.Domain.ContarctingPartyAgg;
|
||||
|
||||
namespace CompanyManagment.EFCore.Repository;
|
||||
|
||||
@@ -30,6 +30,7 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase<long, Inst
|
||||
private readonly ISmsResultRepository _smsResultRepository;
|
||||
private readonly IHubContext<SendSmsHub> _hubContext;
|
||||
private readonly IPersonalContractingPartyRepository _personalContractingPartyRepository;
|
||||
|
||||
public InstitutionContractSmsServiceRepository(CompanyContext context, ISmsService smsService, ILogger<InstitutionContractSmsServiceRepository> logger, ISmsResultRepository smsResultRepository, IHubContext<SendSmsHub> hubContext, IPersonalContractingPartyRepository personalContractingPartyRepository) : base(context)
|
||||
{
|
||||
_context = context;
|
||||
@@ -1324,7 +1325,114 @@ public class InstitutionContractSmsServiceRepository : RepositoryBase<long, Inst
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
public async Task DeActiveInstitutionEndOfContract(DateTime checkDate)
|
||||
{
|
||||
var institutionContracts = await _context.InstitutionContractSet
|
||||
.Where(x => (x.IsActiveString == "true" || x.IsActiveString == "blue") && (x.ContractEndGr.Date < checkDate.Date && x.VerificationStatus != InstitutionContractVerificationStatus.PendingForVerify))
|
||||
.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(),
|
||||
}).ToListAsync();
|
||||
|
||||
// قرارداد هایی که بطور یکجا پرداخت شده اند
|
||||
var paidInFull = institutionContracts.Where(x =>
|
||||
x.SigningType != InstitutionContractSigningType.Legacy && x.IsInstallment == false && x.SigningType != null).ToList();
|
||||
|
||||
//حذف قراداد هایی که یکجا پرداخت شده اند از لیست ایجاد سند ماهانه
|
||||
institutionContracts = institutionContracts.Except(paidInFull).ToList();
|
||||
|
||||
|
||||
|
||||
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 currentActiveContracts = await _context.InstitutionContractSet.Where(x =>
|
||||
x.ContractEndGr.Date > checkDate.Date && x.IsActiveString == "true" &&
|
||||
x.VerificationStatus != InstitutionContractVerificationStatus.PendingForVerify).ToListAsync();
|
||||
|
||||
|
||||
|
||||
var institutionContractIds = institutionContracts.Select(x => x.Id).ToList();
|
||||
var queryableContracts =await _context.InstitutionContractSet.Where(x => institutionContractIds.Contains(x.id)).ToListAsync();
|
||||
foreach (var item in institutionContracts)
|
||||
{
|
||||
try
|
||||
{
|
||||
var existContractAfterThis = currentActiveContracts.Any(x =>
|
||||
x.ContractingPartyId == item.ContractingPartyId);
|
||||
var transactions =
|
||||
financialStatmentList.FirstOrDefault(x => x.ContractingPartyId == item.ContractingPartyId);
|
||||
var contract = queryableContracts.FirstOrDefault(x => x.id == item.Id);
|
||||
if (transactions != null && contract != null)
|
||||
{
|
||||
var debtor = transactions.FinancialTransactionList.Sum(x => x.Deptor);
|
||||
var creditor = transactions.FinancialTransactionList.Sum(x => x.Creditor);
|
||||
|
||||
|
||||
|
||||
var balance = debtor - creditor;
|
||||
|
||||
|
||||
if (balance > 0)
|
||||
{
|
||||
if (existContractAfterThis) // اگر بعد از این قراداد مالی قراردادی داشت حتی اگر بدهکار بود فقط غیرفعالش کن
|
||||
contract.DeActive();
|
||||
else // اگر نداشت غیر فعال آبیش کن
|
||||
contract.DeActiveBlue();
|
||||
|
||||
}
|
||||
else // اگر بدهکار نبود چه بعدش قرارداد مالی داشت چه نداشت غیرفعال کن
|
||||
{
|
||||
contract.DeActive();
|
||||
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
if (!existContractAfterThis) // اگر بعد از این قراداد مالی قرادادی نداشت همه وابستگی ها را غیر فعال کن
|
||||
{
|
||||
await _personalContractingPartyRepository.DeActiveAllAsync(item.ContractingPartyId);
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
string name = item.ContractingPartyName.Length > 18
|
||||
? item.ContractingPartyName.Substring(0, 18)
|
||||
: item.ContractingPartyName;
|
||||
string errMess = $"{name}-خطا";
|
||||
await _smsService.Alarm("09114221321", errMess);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user