Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -3561,7 +3561,7 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
public async Task<bool> SendReminderSmsForBackgroundTask()
|
||||
{
|
||||
var now = DateTime.Now;
|
||||
_logger.LogInformation("================>> SendReminderSmsForBackgroundTask job run");
|
||||
|
||||
|
||||
// تبدیل تاریخ میلادی به شمسی
|
||||
var persianNow = now.ToFarsi();
|
||||
@@ -6333,6 +6333,269 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///دریافت لیست پیامک قرادا های آبی بدهکار
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<SmsListData>> GetBlueSmsListData()
|
||||
{
|
||||
|
||||
var institutionContracts = await _context.InstitutionContractSet.AsQueryable().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,
|
||||
}).Where(x => x.IsActiveString == "blue" &&
|
||||
x.ContractAmountDouble > 0).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();
|
||||
var legalActionSentSms =await _context.SmsResults
|
||||
.Where(x => x.TypeOfSms == "اقدام قضایی").ToListAsync();
|
||||
var warningSentSms = await _context.SmsResults.Where(x => x.TypeOfSms.Contains("هشدار")).ToListAsync();
|
||||
|
||||
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 = GetDetails(item.ContractingPartyId);
|
||||
bool hasLegalActionSentSms = legalActionSentSms.Any(x => x.InstitutionContractId == item.Id);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(contractingParty.LName) && !hasLegalActionSentSms)
|
||||
{
|
||||
//Thread.Sleep(500);
|
||||
var partyName = contractingParty.LName;
|
||||
|
||||
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))
|
||||
{
|
||||
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.FinancialTransactionViewModels.Sum(x => x.Deptor);
|
||||
var creditor = transactions.FinancialTransactionViewModels.Sum(x => x.Creditor);
|
||||
|
||||
|
||||
var id = $"{item.ContractingPartyId}";
|
||||
var aprove = $"{transactions.Id}";
|
||||
var balance = debtor - creditor;
|
||||
|
||||
if (balance > 0) // اگر بدهکار بود
|
||||
{
|
||||
|
||||
if (isLegal)
|
||||
{
|
||||
if (item.OfficialCompany == "Official") // حقوقی بدهکار رسمی
|
||||
{
|
||||
var balanceToMoney = balance.ToMoney();
|
||||
|
||||
foreach (var number in phoneNumbers)
|
||||
{
|
||||
|
||||
var isLastAlarmSend = _context.SmsResults.Any(x => (
|
||||
x.ContractingPatyId == contractingParty.Id &&
|
||||
x.Mobile == number.PhoneNumber) && (x.TypeOfSms == "اقدام قضایی" || x.TypeOfSms == "هشدار دوم"));
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11 && !isSend && !isLastAlarmSend)
|
||||
{
|
||||
|
||||
var smsResult = _smsService.MonthlyBill(number.PhoneNumber, 608443,
|
||||
partyName,
|
||||
balanceToMoney, id, aprove);
|
||||
Thread.Sleep(1000);
|
||||
if (smsResult.IsSuccedded)
|
||||
{
|
||||
var createSmsResult = new SmsResult(smsResult.MessageId,
|
||||
smsResult.Message, typeOfSms, partyName, number.PhoneNumber,
|
||||
item.ContractingPartyId, item.Id);
|
||||
_smsResultRepository.Create(createSmsResult);
|
||||
_smsResultRepository.SaveChanges();
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
else if (item.OfficialCompany == "NotOfficial") // حقوقی بدهکار غیر رسمی
|
||||
{
|
||||
var balanceToMoney = balance.ToMoney();
|
||||
foreach (var number in phoneNumbers)
|
||||
{
|
||||
var isSend = _context.SmsResults.Any(x =>
|
||||
x.ContractingPatyId == contractingParty.Id &&
|
||||
x.Mobile == number.PhoneNumber && x.TypeOfSms == typeOfSms);
|
||||
var isLastAlarmSend = _context.SmsResults.Any(x => (
|
||||
x.ContractingPatyId == contractingParty.Id &&
|
||||
x.Mobile == number.PhoneNumber) && (x.TypeOfSms == "اقدام قضایی" || x.TypeOfSms == "هشدار دوم"));
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11 && !isSend && !isLastAlarmSend)
|
||||
{
|
||||
|
||||
var smsResult = _smsService.MonthlyBill(number.PhoneNumber, 351691,
|
||||
partyName,
|
||||
balanceToMoney, id, aprove);
|
||||
Thread.Sleep(1000);
|
||||
if (smsResult.IsSuccedded)
|
||||
{
|
||||
var createSmsResult = new SmsResult(smsResult.MessageId,
|
||||
smsResult.Message, typeOfSms, partyName, number.PhoneNumber,
|
||||
item.ContractingPartyId, item.Id);
|
||||
_smsResultRepository.Create(createSmsResult);
|
||||
_smsResultRepository.SaveChanges();
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.OfficialCompany == "Official") // حقیقی بدهکار رسمی
|
||||
{
|
||||
var balanceToMoney = balance.ToMoney();
|
||||
|
||||
foreach (var number in phoneNumbers)
|
||||
{
|
||||
var isSend = _context.SmsResults.Any(x =>
|
||||
x.ContractingPatyId == contractingParty.Id &&
|
||||
x.Mobile == number.PhoneNumber && x.TypeOfSms == typeOfSms);
|
||||
var isLastAlarmSend = _context.SmsResults.Any(x => (
|
||||
x.ContractingPatyId == contractingParty.Id &&
|
||||
x.Mobile == number.PhoneNumber) && (x.TypeOfSms == "اقدام قضایی" || x.TypeOfSms == "هشدار دوم"));
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11 && !isSend && !isLastAlarmSend)
|
||||
{
|
||||
|
||||
var smsResult = _smsService.MonthlyBill(number.PhoneNumber, 190430,
|
||||
partyName,
|
||||
balanceToMoney, id, aprove);
|
||||
Thread.Sleep(1000);
|
||||
if (smsResult.IsSuccedded)
|
||||
{
|
||||
var createSmsResult = new SmsResult(smsResult.MessageId,
|
||||
smsResult.Message, typeOfSms, partyName, number.PhoneNumber,
|
||||
item.ContractingPartyId, item.Id);
|
||||
_smsResultRepository.Create(createSmsResult);
|
||||
_smsResultRepository.SaveChanges();
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (item.OfficialCompany == "NotOfficial") // حقیقی بدهکار غیر رسمی
|
||||
{
|
||||
var balanceToMoney = balance.ToMoney();
|
||||
|
||||
foreach (var number in phoneNumbers)
|
||||
{
|
||||
var isSend = _context.SmsResults.Any(x =>
|
||||
x.ContractingPatyId == contractingParty.Id &&
|
||||
x.Mobile == number.PhoneNumber && x.TypeOfSms == typeOfSms);
|
||||
var isLastAlarmSend = _context.SmsResults.Any(x => (
|
||||
x.ContractingPatyId == contractingParty.Id &&
|
||||
x.Mobile == number.PhoneNumber) && (x.TypeOfSms == "اقدام قضایی" || x.TypeOfSms == "هشدار دوم"));
|
||||
if (!string.IsNullOrWhiteSpace(number.PhoneNumber) &&
|
||||
number.PhoneNumber.Length == 11 && !isSend && !isLastAlarmSend)
|
||||
{
|
||||
var smsResult = _smsService.MonthlyBill(number.PhoneNumber, 412829,
|
||||
partyName,
|
||||
balanceToMoney, id, aprove);
|
||||
Thread.Sleep(1000);
|
||||
if (smsResult.IsSuccedded)
|
||||
{
|
||||
var createSmsResult = new SmsResult(smsResult.MessageId,
|
||||
smsResult.Message, typeOfSms, partyName, number.PhoneNumber,
|
||||
item.ContractingPartyId, item.Id);
|
||||
_smsResultRepository.Create(createSmsResult);
|
||||
_smsResultRepository.SaveChanges();
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
|
||||
string name = item.ContractingPartyName.Length > 18 ? item.ContractingPartyName.Substring(0, 18) : item.ContractingPartyName;
|
||||
string errMess = $"{name}-خطا";
|
||||
_smsService.Alarm("09114221321", errMess);
|
||||
_logger.LogError(e, "BlueWarningSms");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user