Merge remote-tracking branch 'origin/dev' into dev
# Conflicts: # clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/service/Clearing.java
This commit is contained in:
commit
37e7ee1f2e
2 changed files with 106 additions and 59 deletions
|
|
@ -226,4 +226,33 @@ public class LiabilitiesClaimsAssets extends BusinessObject {
|
|||
this.refundPaymentId = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LiabilitiesClaimsAssets{" +
|
||||
"companyId=" + companyId +
|
||||
", clearingDate=" + clearingDate +
|
||||
", accountId=" + accountId +
|
||||
", accountType='" + accountType + '\'' +
|
||||
", account='" + account + '\'' +
|
||||
", liabilitiesQuantity=" + liabilitiesQuantity +
|
||||
", claimsQuantity=" + claimsQuantity +
|
||||
", currency='" + currency + '\'' +
|
||||
", settlementDate=" + settlementDate +
|
||||
", tradingDate=" + tradingDate +
|
||||
", refundDate=" + refundDate +
|
||||
", price=" + price +
|
||||
", securityId=" + securityId +
|
||||
", tradingCode='" + tradingCode + '\'' +
|
||||
", clearingCode='" + clearingCode + '\'' +
|
||||
", shortName='" + shortName + '\'' +
|
||||
", contract='" + contract + '\'' +
|
||||
", comment='" + comment + '\'' +
|
||||
", fullName='" + fullName + '\'' +
|
||||
", parentId=" + parentId +
|
||||
", liabilitiesClaimsMoneyId=" + liabilitiesClaimsMoneyId +
|
||||
", clearingStatus=" + clearingStatus +
|
||||
", paymentId=" + paymentId +
|
||||
", refundPaymentId=" + refundPaymentId +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ public class PaymentInstructionCreator {
|
|||
|
||||
// I
|
||||
if (clearingCategory.contains(ClearingCategory.I)) {
|
||||
log.debug("By liabilitiesClaimsAssets[{}] create for category I 1 record", liabilitiesClaimsAssets.getId());
|
||||
log.debug("By liabilitiesClaimsAssets[{}] create for category I 2 PaymentInstruction record", liabilitiesClaimsAssets.getId());
|
||||
PaymentInstruction payment1 = new PaymentInstruction();
|
||||
PaymentInstruction payment2 = new PaymentInstruction();
|
||||
|
||||
|
|
@ -115,13 +115,16 @@ public class PaymentInstructionCreator {
|
|||
payment2.setSenderId(SPVB_ID); // СПВБ
|
||||
|
||||
payment1.setAddresseeId(SPVB_ID); // СПВБ
|
||||
String sqlLCA = String.format("securityId = %s and companyId != %s",
|
||||
liabilitiesClaimsAssets.getSecurityId(), liabilitiesClaimsAssets.getCompanyId());
|
||||
ExecutionDeposit counterExecutionDeposit = executionDepositImdg.getSingleObjectBySQL(sqlLCA);
|
||||
if (counterExecutionDeposit == null) {
|
||||
log.warn("Counter ExecutionDeposit not found for : {}", sqlLCA);
|
||||
} else {
|
||||
payment2.setAddresseeId(counterExecutionDeposit.getCompanyId());
|
||||
{
|
||||
String sqlLCA = String.format("securityId = %s and companyId != %s",
|
||||
liabilitiesClaimsAssets.getSecurityId(), liabilitiesClaimsAssets.getCompanyId());
|
||||
ExecutionDeposit counterExecutionDeposit = executionDepositImdg.getSingleObjectBySQL(sqlLCA);
|
||||
if (counterExecutionDeposit == null) {
|
||||
log.warn("Counter ExecutionDeposit not found for : {}", sqlLCA);
|
||||
} else {
|
||||
payment2.setAddresseeId(counterExecutionDeposit.getCompanyId());
|
||||
log.trace("payment2.AddresseeId={} found by: {}", payment2.getAddresseeId(), sqlLCA);
|
||||
}
|
||||
}
|
||||
|
||||
String symbol1 = selectSymbolValue(payment1.getAddresseeId(), CompanySymbol.BIC);
|
||||
|
|
@ -140,7 +143,7 @@ public class PaymentInstructionCreator {
|
|||
Company companyPRC = companyImdg.getSingleObjectByID(PRC_ID); // 2 "НКО АО ПРЦ"
|
||||
String companyPRCName = null;
|
||||
if (companyPRC == null) {
|
||||
log.warn("Company.id=2 not found");
|
||||
log.warn("Company.id={} not found", PRC_ID);
|
||||
} else {
|
||||
companyPRCName = companyPRC.getShortName();
|
||||
}
|
||||
|
|
@ -170,13 +173,14 @@ public class PaymentInstructionCreator {
|
|||
payment2.setDebitLegAmount(amount);
|
||||
|
||||
payment1.setCreditLegAccountId(liabilitiesClaimsAssets.getAccountId());
|
||||
String accSql = String.format("companyId = %s AND accountType=TRAN AND accountStatus=ACTV AND processingSign=ALWD",
|
||||
payment2.getSenderId());
|
||||
Account anotherAcc = accountImdg.getSingleObjectBySQL(accSql);
|
||||
if (anotherAcc == null) {
|
||||
log.warn("Account not found: {}", accSql);
|
||||
} else {
|
||||
payment2.setCreditLegAccountId(anotherAcc.getId());
|
||||
{
|
||||
Account anotherAcc = selectAccount(payment2.getSenderId(), AccountType.Tran, Status.Active, Allowed.ALLOWED);
|
||||
if (anotherAcc == null) {
|
||||
log.warn("Account not found: companyId = {} AND accountType={} AND accountStatus={} AND processingSign={}",
|
||||
payment2.getSenderId(), AccountType.Tran, Status.Active, Allowed.ALLOWED);
|
||||
} else {
|
||||
payment2.setCreditLegAccountId(anotherAcc.getId());
|
||||
}
|
||||
}
|
||||
|
||||
payment1.setCreditCsAccount(null);
|
||||
|
|
@ -189,7 +193,7 @@ public class PaymentInstructionCreator {
|
|||
}
|
||||
Account acc2 = accountImdg.getSingleObjectByID(payment2.getCreditLegAccountId());
|
||||
if (acc2 != null) {
|
||||
payment1.setCreditLegAccount(acc2.getAccount());
|
||||
payment2.setCreditLegAccount(acc2.getAccount());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -231,7 +235,7 @@ public class PaymentInstructionCreator {
|
|||
} else {
|
||||
// V / B
|
||||
if (clearingCategory.contains(ClearingCategory.V)) {
|
||||
log.debug("By liabilitiesClaimsAssets[{}] create for category V 1 record", liabilitiesClaimsAssets.getId());
|
||||
log.debug("By liabilitiesClaimsAssets[{}] create for category V 1 PaymentInstruction record", liabilitiesClaimsAssets.getId());
|
||||
PaymentInstruction payment1 = new PaymentInstruction();
|
||||
payment1.setId(idGenerator.nextId());
|
||||
payment1.setCreated(now);
|
||||
|
|
@ -239,13 +243,16 @@ public class PaymentInstructionCreator {
|
|||
|
||||
payment1.setSenderId(SPVB_ID); // СПВБ
|
||||
|
||||
String sqlLCA = String.format("securityId = %s and companyId != %s",
|
||||
liabilitiesClaimsAssets.getSecurityId(), liabilitiesClaimsAssets.getCompanyId());
|
||||
ExecutionDeposit counterExecutionDeposit = executionDepositImdg.getSingleObjectBySQL(sqlLCA);
|
||||
if (counterExecutionDeposit == null) {
|
||||
log.warn("Counter ExecutionDeposit not found for : {}", sqlLCA);
|
||||
} else {
|
||||
payment1.setAddresseeId(counterExecutionDeposit.getCompanyId());
|
||||
{
|
||||
String sqlLCA = String.format("securityId = %s and companyId != %s",
|
||||
liabilitiesClaimsAssets.getSecurityId(), liabilitiesClaimsAssets.getCompanyId());
|
||||
ExecutionDeposit counterExecutionDeposit = executionDepositImdg.getSingleObjectBySQL(sqlLCA);
|
||||
if (counterExecutionDeposit == null) {
|
||||
log.warn("Counter ExecutionDeposit not found for : {}", sqlLCA);
|
||||
} else {
|
||||
payment1.setAddresseeId(counterExecutionDeposit.getCompanyId());
|
||||
log.trace("payment1.AddresseeId={} found by: {}", payment1.getAddresseeId(), sqlLCA);
|
||||
}
|
||||
}
|
||||
|
||||
String symbol1 = selectSymbolValue(payment1.getAddresseeId(), CompanySymbol.BIC);
|
||||
|
|
@ -258,7 +265,7 @@ public class PaymentInstructionCreator {
|
|||
Company companyPRC = companyImdg.getSingleObjectByID(PRC_ID); // 2 "НКО АО ПРЦ"
|
||||
String companyPRCName = null;
|
||||
if (companyPRC == null) {
|
||||
log.warn("Company.id=2 not found");
|
||||
log.warn("Company.id={} not found", PRC_ID);
|
||||
} else {
|
||||
companyPRCName = companyPRC.getShortName();
|
||||
}
|
||||
|
|
@ -280,11 +287,10 @@ public class PaymentInstructionCreator {
|
|||
payment1.setDebitLegAmount(amount);
|
||||
|
||||
{
|
||||
String accSql = String.format("companyId = %s AND accountType=ANLT AND accountStatus=ACTV AND processingSign=ALWD",
|
||||
payment1.getSenderId());
|
||||
Account acc1 = accountImdg.getSingleObjectBySQL(accSql);
|
||||
Account acc1 = selectAccount(payment1.getSenderId(), AccountType.Anlt, Status.Active, Allowed.ALLOWED);
|
||||
if (acc1 == null) {
|
||||
log.warn("Account not found: {}", accSql);
|
||||
log.warn("Account not found: companyId = {} AND accountType={} AND accountStatus={} AND processingSign={}",
|
||||
payment1.getSenderId(), AccountType.Anlt, Status.Active, Allowed.ALLOWED);
|
||||
} else {
|
||||
payment1.setCreditLegAccountId(acc1.getId());
|
||||
payment1.setCreditLegAccount(acc1.getAccount());
|
||||
|
|
@ -317,7 +323,7 @@ public class PaymentInstructionCreator {
|
|||
newPaymentInstructions.add(payment1);
|
||||
} else // Для V,B только 1 PaymentInstruction
|
||||
if (clearingCategory.contains(ClearingCategory.B)) {
|
||||
log.debug("By liabilitiesClaimsAssets[{}] create for category B 1 record", liabilitiesClaimsAssets.getId());
|
||||
log.debug("By liabilitiesClaimsAssets[{}] create for category B 1 PaymentInstruction record", liabilitiesClaimsAssets.getId());
|
||||
PaymentInstruction payment1 = new PaymentInstruction();
|
||||
payment1.setId(idGenerator.nextId());
|
||||
payment1.setCreated(now);
|
||||
|
|
@ -337,7 +343,7 @@ public class PaymentInstructionCreator {
|
|||
Company companyPRC = companyImdg.getSingleObjectByID(PRC_ID); // 2 "НКО АО ПРЦ"
|
||||
String companyPRCName = null;
|
||||
if (companyPRC == null) {
|
||||
log.warn("Company.id=2 not found");
|
||||
log.warn("Company.id={} not found", PRC_ID);
|
||||
} else {
|
||||
companyPRCName = companyPRC.getShortName();
|
||||
}
|
||||
|
|
@ -359,11 +365,10 @@ public class PaymentInstructionCreator {
|
|||
payment1.setDebitLegAmount(amount);
|
||||
|
||||
{
|
||||
String accSql = String.format("companyId = %s AND accountType=ANLT AND accountStatus=ACTV AND processingSign=ALWD",
|
||||
payment1.getSenderId());
|
||||
Account acc1 = accountImdg.getSingleObjectBySQL(accSql);
|
||||
Long accountId = liabilitiesClaimsAssets.getAccountId();
|
||||
Account acc1 = accountImdg.getSingleObjectByID(accountId);
|
||||
if (acc1 == null) {
|
||||
log.warn("Account not found: {}", accSql);
|
||||
log.warn("Account not found: {}", accountId);
|
||||
} else {
|
||||
payment1.setCreditLegAccountId(acc1.getId());
|
||||
payment1.setCreditLegAccount(acc1.getAccount());
|
||||
|
|
@ -443,6 +448,15 @@ public class PaymentInstructionCreator {
|
|||
"accountStatus", accountStatus.getKey(),
|
||||
"processingSign", processingSign.getKey()
|
||||
));
|
||||
if (account == null) {
|
||||
log.trace("Account not found by: companyId={} accountType={} accountStatus={} processingSign={}",
|
||||
companyId, accountType.getKey(), accountStatus.getKey(), processingSign.getKey()
|
||||
);
|
||||
} else {
|
||||
log.trace("Found Account.id={} by: companyId={} accountType={} accountStatus={} processingSign={}", account.getId(),
|
||||
companyId, accountType.getKey(), accountStatus.getKey(), processingSign.getKey()
|
||||
);
|
||||
}
|
||||
return account;
|
||||
}
|
||||
|
||||
|
|
@ -451,33 +465,35 @@ public class PaymentInstructionCreator {
|
|||
* 2.2.2.1. Выполнить Изменение liabilitiesClaimsAssets по paymentInstruction.
|
||||
*/
|
||||
public void updateFieldLiabilitiesClaimsAssetsByPayment(LiabilitiesClaimsAssets liabilitiesClaimsAssets,
|
||||
LiabilitiesClaimsMoney liabilitiesClaimsMoney,
|
||||
List<PaymentInstruction> paymentInstructions,
|
||||
Collection<ClearingCategory> clearingCategory) {
|
||||
|
||||
final boolean isFirstLeg = true;
|
||||
final boolean isSecondLeg = !isFirstLeg;
|
||||
PaymentInstruction paymentIAny = paymentInstructions.iterator().next();
|
||||
|
||||
if (clearingCategory.contains(ClearingCategory.I) || clearingCategory.contains(ClearingCategory.V)) {
|
||||
BigDecimal amount = bdFromLongSafe(paymentIAny.getCreditLegAmount());
|
||||
// При обновлении (по paymentInstruction и категория I и счет CLRN):=liabilitiesClaimsAssets.liabilitiesQuantity - paymentInstruction.creditLeg_amount
|
||||
// При обновлении (по paymentInstruction и категория V и счет INFO):=liabilitiesClaimsAssets.liabilitiesQuantity - paymentInstruction.creditLeg_amount
|
||||
amount = liabilitiesClaimsAssets.getLiabilitiesQuantity().subtract(amount);
|
||||
liabilitiesClaimsAssets.setLiabilitiesQuantity(amount);
|
||||
}
|
||||
if (clearingCategory.contains(ClearingCategory.B)) {
|
||||
BigDecimal amount = bdFromLongSafe(paymentIAny.getCreditLegAmount());
|
||||
// При обновлении (по paymentInstruction и категория B и счет CLRN): из paymentInstruction.creditLeg_amount
|
||||
liabilitiesClaimsAssets.setLiabilitiesQuantity(amount);
|
||||
}
|
||||
// if (clearingCategory.contains(ClearingCategory.I) || clearingCategory.contains(ClearingCategory.V)) {
|
||||
// BigDecimal amount = bdFromLongSafe(paymentIAny.getCreditLegAmount());
|
||||
//// При обновлении (по paymentInstruction и категория I и счет CLRN):=liabilitiesClaimsAssets.liabilitiesQuantity - paymentInstruction.creditLeg_amount
|
||||
//// При обновлении (по paymentInstruction и категория V и счет INFO):=liabilitiesClaimsAssets.liabilitiesQuantity - paymentInstruction.creditLeg_amount
|
||||
// amount = liabilitiesClaimsAssets.getLiabilitiesQuantity().subtract(amount);
|
||||
// liabilitiesClaimsAssets.setLiabilitiesQuantity(amount);
|
||||
// }
|
||||
// if (clearingCategory.contains(ClearingCategory.B)) {
|
||||
// BigDecimal amount = bdFromLongSafe(paymentIAny.getCreditLegAmount());
|
||||
// // При обновлении (по paymentInstruction и категория B и счет CLRN): из paymentInstruction.creditLeg_amount
|
||||
// liabilitiesClaimsAssets.setLiabilitiesQuantity(amount);
|
||||
// }
|
||||
|
||||
if (clearingCategory.contains(ClearingCategory.I) || clearingCategory.contains(ClearingCategory.V)) {
|
||||
BigDecimal amount = bdFromLongSafe(paymentIAny.getDebitLegAmount());
|
||||
liabilitiesClaimsAssets.setClaimsQuantity(amount);
|
||||
}
|
||||
if (clearingCategory.contains(ClearingCategory.B)) {
|
||||
BigDecimal amount = bdFromLongSafe(paymentIAny.getDebitLegAmount());
|
||||
amount = safeBD(liabilitiesClaimsAssets.getClaimsQuantity()).subtract(amount);
|
||||
liabilitiesClaimsAssets.setClaimsQuantity(amount);
|
||||
}
|
||||
// if (clearingCategory.contains(ClearingCategory.I) || clearingCategory.contains(ClearingCategory.V)) {
|
||||
// BigDecimal amount = bdFromLongSafe(paymentIAny.getDebitLegAmount());
|
||||
// liabilitiesClaimsAssets.setClaimsQuantity(amount);
|
||||
// }
|
||||
// if (clearingCategory.contains(ClearingCategory.B)) {
|
||||
// BigDecimal amount = bdFromLongSafe(paymentIAny.getDebitLegAmount());
|
||||
// amount = safeBD(liabilitiesClaimsAssets.getClaimsQuantity()).subtract(amount);
|
||||
// liabilitiesClaimsAssets.setClaimsQuantity(amount);
|
||||
// }
|
||||
|
||||
// //на базе успешного/неуспешного изменения по paymentInstruction
|
||||
// if (TransactionStatus.fail.equalsByKey(paymentIAny.getTransactionStatus())) {
|
||||
|
|
@ -486,6 +502,8 @@ public class PaymentInstructionCreator {
|
|||
// liabilitiesClaimsAssets.setClearingStatus(ClearingStatus.OK.getKey());
|
||||
// }
|
||||
|
||||
liabilitiesClaimsAssets.setLiabilitiesClaimsMoneyId(liabilitiesClaimsMoney.getId());
|
||||
liabilitiesClaimsAssets.setPaymentId(paymentIAny.getId());
|
||||
liabilitiesClaimsAssets.setUpdated(Instant.now());
|
||||
}
|
||||
|
||||
|
|
@ -495,7 +513,7 @@ public class PaymentInstructionCreator {
|
|||
* Обновление liabilitiesClaimsMoney первой/второй ноги по liabilitiesClaimsAssets
|
||||
*
|
||||
* @param liabilitiesClaimsMoney обновить этот объект (firstLeg)
|
||||
* @param isFirstLeg true - первая, false вторая
|
||||
* @param isFirstLeg true - первая, false вторая
|
||||
* @param paymentInstructions
|
||||
* @param clearingCategory
|
||||
* @return были внесены изменения в liabilitiesClaimsMoney
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue