http://jira.mfd.msk:8088/browse/CLS-189 PaymentInstructionCreator логика обновления PaymentInstruction (правка хака 650583bd7e)
This commit is contained in:
parent
bfe9f42e04
commit
8b119cc145
2 changed files with 109 additions and 53 deletions
|
|
@ -253,18 +253,26 @@ public class Clearing {
|
||||||
liabilitiesClaimsAssetsImdg.update(lcaSecondLeg);
|
liabilitiesClaimsAssetsImdg.update(lcaSecondLeg);
|
||||||
|
|
||||||
log.trace("creating paymentInstructions");
|
log.trace("creating paymentInstructions");
|
||||||
boolean isCreatedFirstLegI = ClearingCategory.I.equals(category) && !lcaFirstLegFound.isPresent();
|
PaymentInstruction firstInstructionIExist = null;
|
||||||
if (isCreatedFirstLegI) {
|
if (ClearingCategory.I.equals(category)) {
|
||||||
log.debug("ignore create paymentInstruction for I firstLeg new: execDeposit {}, lcaFirstLeg {}",
|
log.trace("For category I search paymentInstruction by lca[{}]", lcaFirstLeg.getId());
|
||||||
execDeposit.getId(), lcaFirstLeg.getId());
|
firstInstructionIExist = paymentInstructionCreator.searchExistPaymentInstructionsFirstI(lcaFirstLeg);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PaymentInstruction> paymentInstructions;
|
||||||
|
if (firstInstructionIExist != null) {
|
||||||
|
log.debug("ignore create paymentInstruction for I firstLeg: execDeposit {}, lcaFirstLeg {}, updating paymentInstruction {}",
|
||||||
|
execDeposit.getId(), lcaFirstLeg.getId(), firstInstructionIExist.getId());
|
||||||
|
paymentInstructionCreator.updatePaymentInstructionsFirstI(firstInstructionIExist, lcaFirstLeg, category);
|
||||||
|
paymentInstructions = Collections.singletonList(firstInstructionIExist);
|
||||||
} else {
|
} else {
|
||||||
List<PaymentInstruction> paymentInstructions = paymentInstructionCreator.createAndSavePaymentInstructions(execDeposit, lcaFirstLeg, Collections.singleton(category));
|
paymentInstructions = paymentInstructionCreator.createAndSavePaymentInstructions(execDeposit, lcaFirstLeg, Collections.singleton(category));
|
||||||
if (paymentInstructions.isEmpty()) {
|
}
|
||||||
log.trace("For lcaFirstLeg[{}] did not creaded paymentInstruction's", lcaFirstLeg.getId());
|
if (paymentInstructions.isEmpty()) {
|
||||||
} else {
|
log.trace("For lcaFirstLeg[{}] did not created paymentInstruction's", lcaFirstLeg.getId());
|
||||||
paymentInstructionCreator.updateFieldLiabilitiesClaimsAssetsByPayment(lcaFirstLeg, lcmFirstLeg, paymentInstructions, Collections.singleton(category));
|
} else {
|
||||||
liabilitiesClaimsAssetsImdg.update(lcaFirstLeg);
|
paymentInstructionCreator.updateFieldLiabilitiesClaimsAssetsByPayment(lcaFirstLeg, lcmFirstLeg, paymentInstructions, Collections.singleton(category));
|
||||||
}
|
liabilitiesClaimsAssetsImdg.update(lcaFirstLeg);
|
||||||
}
|
}
|
||||||
log.trace("lcaFirstLeg {}, lcaSecondLeg {}", lcaFirstLeg, lcaSecondLeg);
|
log.trace("lcaFirstLeg {}, lcaSecondLeg {}", lcaFirstLeg, lcaSecondLeg);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,21 +22,11 @@ import java.math.BigDecimal;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import static ru.spcex.platform.utils.number.BigDecimalUtil.safeBD;
|
import static ru.spcex.platform.utils.number.BigDecimalUtil.safeBD;
|
||||||
|
|
||||||
/*
|
|
||||||
todo использовать так:
|
|
||||||
paymentInstructionCreator.createAndSavePaymentInstructions()
|
|
||||||
paymentInstructionCreator.updateLiabilitiesClaimsAssetsByPaymentInstruction();
|
|
||||||
paymentInstructionCreator.updateLiabilitiesClaimsMoneyByPaymentInstruction();
|
|
||||||
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
public class PaymentInstructionCreator {
|
public class PaymentInstructionCreator {
|
||||||
protected static final Long SPVB_ID = 1L; // СПВБ
|
protected static final Long SPVB_ID = 1L; // СПВБ
|
||||||
|
|
@ -85,35 +75,13 @@ public class PaymentInstructionCreator {
|
||||||
return newPaymentInstructions;
|
return newPaymentInstructions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Создаёт и сохраняет
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param executionDeposit
|
|
||||||
* @param liabilitiesClaimsAssets
|
|
||||||
* @param clearingCategory
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
protected List<PaymentInstruction> createPaymentInstructions(ExecutionDeposit executionDeposit, LiabilitiesClaimsAssets liabilitiesClaimsAssets,
|
|
||||||
Collection<ClearingCategory> clearingCategory) {
|
|
||||||
List<PaymentInstruction> newPaymentInstructions = new ArrayList<>();
|
|
||||||
Instant now = Instant.now();
|
|
||||||
LocalDate today = LocalDate.now();
|
|
||||||
if (!today.equals(liabilitiesClaimsAssets.getSettlementDate())) {
|
|
||||||
log.debug("For liabilitiesClaimsAssets.SettlementDate={} is not today.", liabilitiesClaimsAssets.getSettlementDate());
|
|
||||||
return newPaymentInstructions;
|
|
||||||
}
|
|
||||||
// I
|
|
||||||
if (clearingCategory.contains(ClearingCategory.I)) {
|
|
||||||
log.debug("By liabilitiesClaimsAssets[{}] create for category I 1 PaymentInstruction record", liabilitiesClaimsAssets.getId());
|
|
||||||
PaymentInstruction payment1 = new PaymentInstruction();
|
|
||||||
|
|
||||||
payment1.setId(idGenerator.nextId());
|
protected void updateOrNewFieldPaymentInstructionsFirstI(PaymentInstruction payment1,
|
||||||
payment1.setCreated(now);
|
LiabilitiesClaimsAssets liabilitiesClaimsAssets,
|
||||||
|
Instant now) {
|
||||||
|
|
||||||
payment1.setClearingDate(TimeUtil.toLocalDate(now));
|
payment1.setClearingDate(TimeUtil.toLocalDate(now));
|
||||||
|
|
||||||
payment1.setSenderId(liabilitiesClaimsAssets.getCompanyId());
|
payment1.setSenderId(liabilitiesClaimsAssets.getCompanyId());
|
||||||
|
|
||||||
payment1.setAddresseeId(SPVB_ID); // СПВБ
|
payment1.setAddresseeId(SPVB_ID); // СПВБ
|
||||||
|
|
||||||
String symbol1 = selectSymbolValue(payment1.getAddresseeId(), CompanySymbol.BIC);
|
String symbol1 = selectSymbolValue(payment1.getAddresseeId(), CompanySymbol.BIC);
|
||||||
|
|
@ -136,13 +104,11 @@ public class PaymentInstructionCreator {
|
||||||
payment1.setPayeeBic(symbolPRC);
|
payment1.setPayeeBic(symbolPRC);
|
||||||
|
|
||||||
payment1.setAddresseeBankName(companyPRCName);
|
payment1.setAddresseeBankName(companyPRCName);
|
||||||
|
|
||||||
payment1.setPaymentDate(TimeUtil.localDateToInstant(liabilitiesClaimsAssets.getSettlementDate()));
|
payment1.setPaymentDate(TimeUtil.localDateToInstant(liabilitiesClaimsAssets.getSettlementDate()));
|
||||||
|
|
||||||
payment1.setPaymentPurpose("Размещение депозита " + liabilitiesClaimsAssets.getContract());
|
payment1.setPaymentPurpose(paymentPurpose(liabilitiesClaimsAssets.getContract()));
|
||||||
|
|
||||||
payment1.setSettlementDate(liabilitiesClaimsAssets.getSettlementDate());
|
payment1.setSettlementDate(liabilitiesClaimsAssets.getSettlementDate());
|
||||||
|
|
||||||
Long amount = liabilitiesClaimsAssets.getLiabilitiesQuantity() == null ? null : liabilitiesClaimsAssets.getLiabilitiesQuantity().abs().longValue();
|
Long amount = liabilitiesClaimsAssets.getLiabilitiesQuantity() == null ? null : liabilitiesClaimsAssets.getLiabilitiesQuantity().abs().longValue();
|
||||||
payment1.setCreditLegAmount(amount);
|
payment1.setCreditLegAmount(amount);
|
||||||
payment1.setDebitLegAmount(amount);
|
payment1.setDebitLegAmount(amount);
|
||||||
|
|
@ -167,7 +133,6 @@ public class PaymentInstructionCreator {
|
||||||
}
|
}
|
||||||
|
|
||||||
payment1.setDebitCsAccount(null);
|
payment1.setDebitCsAccount(null);
|
||||||
|
|
||||||
// payment1.setCreditLegDirection(InOutDirection.out.getKey());
|
// payment1.setCreditLegDirection(InOutDirection.out.getKey());
|
||||||
// payment1.setDebitLegDirection(InOutDirection.in.getKey());
|
// payment1.setDebitLegDirection(InOutDirection.in.getKey());
|
||||||
|
|
||||||
|
|
@ -177,6 +142,39 @@ public class PaymentInstructionCreator {
|
||||||
payment1.setTransactionStatus(TransactionStatus.stld.getKey());
|
payment1.setTransactionStatus(TransactionStatus.stld.getKey());
|
||||||
|
|
||||||
|
|
||||||
|
// payment1.setDocumentNumber(nextDocumentNumber(liabilitiesClaimsAssets, payment1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Создаёт и сохраняет
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param executionDeposit
|
||||||
|
* @param liabilitiesClaimsAssets
|
||||||
|
* @param clearingCategory
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected List<PaymentInstruction> createPaymentInstructions(ExecutionDeposit executionDeposit, LiabilitiesClaimsAssets liabilitiesClaimsAssets,
|
||||||
|
Collection<ClearingCategory> clearingCategory) {
|
||||||
|
List<PaymentInstruction> newPaymentInstructions = new ArrayList<>();
|
||||||
|
Instant now = Instant.now();
|
||||||
|
LocalDate today = LocalDate.now();
|
||||||
|
if (!today.equals(liabilitiesClaimsAssets.getSettlementDate())) {
|
||||||
|
log.debug("For liabilitiesClaimsAssets.SettlementDate={} is not today.", liabilitiesClaimsAssets.getSettlementDate());
|
||||||
|
return newPaymentInstructions;
|
||||||
|
}
|
||||||
|
// I
|
||||||
|
if (clearingCategory.contains(ClearingCategory.I)) {
|
||||||
|
// см. updatePaymentInstructionsFirstI() - код одинаковый
|
||||||
|
log.debug("By liabilitiesClaimsAssets[{}] create for category I 1 PaymentInstruction record", liabilitiesClaimsAssets.getId());
|
||||||
|
PaymentInstruction payment1 = new PaymentInstruction();
|
||||||
|
|
||||||
|
payment1.setId(idGenerator.nextId());
|
||||||
|
payment1.setCreated(now);
|
||||||
|
payment1.setClearingDate(TimeUtil.toLocalDate(now));
|
||||||
|
|
||||||
|
updateOrNewFieldPaymentInstructionsFirstI(payment1, liabilitiesClaimsAssets, now);
|
||||||
|
|
||||||
payment1.setDocumentNumber(nextDocumentNumber(liabilitiesClaimsAssets, payment1));
|
payment1.setDocumentNumber(nextDocumentNumber(liabilitiesClaimsAssets, payment1));
|
||||||
|
|
||||||
newPaymentInstructions.add(payment1);
|
newPaymentInstructions.add(payment1);
|
||||||
|
|
@ -529,6 +527,56 @@ public class PaymentInstructionCreator {
|
||||||
return newPaymentInstructions;
|
return newPaymentInstructions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param contract liabilitiesClaimsAssets.contract
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String paymentPurpose(String contract) {
|
||||||
|
return "Размещение депозита " + (contract == null ? "" : contract);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PaymentInstruction searchExistPaymentInstructionsFirstI(LiabilitiesClaimsAssets lca) {
|
||||||
|
HashMap<String, Comparable<?>> criteria = new HashMap<>();
|
||||||
|
criteria.put("creditLegAccountId", lca.getAccountId());
|
||||||
|
criteria.put("senderId", lca.getCompanyId());
|
||||||
|
criteria.put("paymentPurpose", paymentPurpose(lca.getContract()));
|
||||||
|
criteria.put("settlementDate", lca.getSettlementDate());
|
||||||
|
PaymentInstruction payment1 = paymentInstructionImdg.getSingleObjectByFieldValues(criteria);
|
||||||
|
return payment1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Обновление п оаналогии с createPaymentInstructions
|
||||||
|
* @param payment1
|
||||||
|
* @param liabilitiesClaimsAssets
|
||||||
|
* @param clearingCategory
|
||||||
|
*/
|
||||||
|
public void updatePaymentInstructionsFirstI(PaymentInstruction payment1,
|
||||||
|
LiabilitiesClaimsAssets liabilitiesClaimsAssets,
|
||||||
|
ClearingCategory clearingCategory) {
|
||||||
|
Instant now = Instant.now();
|
||||||
|
LocalDate today = TimeUtil.toLocalDate(now);
|
||||||
|
if (!today.equals(liabilitiesClaimsAssets.getSettlementDate())) {
|
||||||
|
log.debug("For liabilitiesClaimsAssets.SettlementDate={} is not today.", liabilitiesClaimsAssets.getSettlementDate());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("By liabilitiesClaimsAssets[{}] update for category I 1 PaymentInstruction {} record",
|
||||||
|
liabilitiesClaimsAssets.getId(), payment1.getId());
|
||||||
|
|
||||||
|
// I check
|
||||||
|
if (!ClearingCategory.I.equals(clearingCategory)) {
|
||||||
|
throw new IllegalArgumentException("Clearing category is not I. Method not implemented for " + clearingCategory);
|
||||||
|
}
|
||||||
|
|
||||||
|
payment1.setUpdated(now);
|
||||||
|
updateOrNewFieldPaymentInstructionsFirstI(payment1, liabilitiesClaimsAssets, now);
|
||||||
|
|
||||||
|
paymentInstructionImdg.update(payment1);
|
||||||
|
log.trace("PaymentInstruction {} was updated", payment1.getId());
|
||||||
|
}
|
||||||
|
|
||||||
protected String nextDocumentNumber(LiabilitiesClaimsAssets liabilitiesClaimsAssets, PaymentInstruction paymentInstruction) {
|
protected String nextDocumentNumber(LiabilitiesClaimsAssets liabilitiesClaimsAssets, PaymentInstruction paymentInstruction) {
|
||||||
LocalDate nowD = LocalDate.now();
|
LocalDate nowD = LocalDate.now();
|
||||||
if (documentNumberResetAt == null || documentNumberResetAt.isBefore(nowD)) synchronized (this) {
|
if (documentNumberResetAt == null || documentNumberResetAt.isBefore(nowD)) synchronized (this) {
|
||||||
|
|
@ -595,7 +643,7 @@ public class PaymentInstructionCreator {
|
||||||
Collection<ClearingCategory> clearingCategory) {
|
Collection<ClearingCategory> clearingCategory) {
|
||||||
// final boolean isFirstLeg = true;
|
// final boolean isFirstLeg = true;
|
||||||
// final boolean isSecondLeg = !isFirstLeg;
|
// final boolean isSecondLeg = !isFirstLeg;
|
||||||
PaymentInstruction paymentIAny = paymentInstructions.iterator().next();
|
PaymentInstruction paymentIAny = paymentInstructions.get(paymentInstructions.size() - 1); // брать последнюю запись для ID
|
||||||
|
|
||||||
// if (clearingCategory.contains(ClearingCategory.I) || clearingCategory.contains(ClearingCategory.V)) {
|
// if (clearingCategory.contains(ClearingCategory.I) || clearingCategory.contains(ClearingCategory.V)) {
|
||||||
// BigDecimal amount = bdFromLongSafe(paymentIAny.getCreditLegAmount());
|
// BigDecimal amount = bdFromLongSafe(paymentIAny.getCreditLegAmount());
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue