sdf04 fix TRAN accounts
SDF57 & SDF06 fix currency on gateway
This commit is contained in:
parent
1ff7fb4b23
commit
c13f0d8270
4 changed files with 51 additions and 39 deletions
|
|
@ -6,6 +6,8 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -86,24 +88,17 @@ public class Sdf04Executor extends AbstractExecutor<SDf04> {
|
|||
for (SDf04 sdf04 : sdf) {
|
||||
//обычно мы ищем по группу sdf04, здесь как будто всегда только одна запись, todo нужно прочекать этот момент
|
||||
log.debug("Process sdf04 record; sdf04.id: {}", sdf04.getId());
|
||||
|
||||
Account accDeb = accountImdg.getFirstObjectBySQL("account = '%s'".formatted(sdf04.getC_acc_deb()));
|
||||
Account accCred = accountImdg.getFirstObjectBySQL("account = '%s'".formatted(sdf04.getC_acc_cred()));
|
||||
BiFunction<Account, AccountType, Boolean> isType = (acc, type)
|
||||
-> acc != null && type.equalsByKey(acc.getAccountType());
|
||||
|
||||
Function<Account, Collection<Registry>> srch = (acc) -> {
|
||||
Collection<Registry> registries;
|
||||
Account anltAcc = accountImdg.getFirstObjectBySQL("account = '%s' and accountType = '%s' and currency = '%s'"
|
||||
.formatted(sdf04.getC_acc_deb(),
|
||||
AccountType.Anlt.getKey(),
|
||||
sdf04.getPay_val()));
|
||||
// Account tranAcc = accountImdg.getFirstObjectBySQL("account = '%s' and accountType = '%s'"
|
||||
// .formatted(sdf04.getC_acc_cred(), AccountType.Tran.getKey()));
|
||||
// //если сдф04 не по аналитическому счету ни по tran счету, выбираем по тому c_acc_deb/c_acc_cred что пришло
|
||||
// boolean isAnltAcc = anltAcc != null;
|
||||
// boolean isTranAcc = tranAcc != null;
|
||||
// if (isAnltAcc && isTranAcc) {
|
||||
// log.warn("Found ANLT and TRAN acc by sdf04.id: {}", sdf04.getId());
|
||||
// }
|
||||
if (anltAcc == null) {
|
||||
registries = selectRegistryForSDF04(sdf04.getC_acc_deb());
|
||||
// String acc = anltAcc == null ? sdf04.getC_acc_deb() : sdf04.getC_acc_cred();
|
||||
// registries = selectRegistryForSDF04(acc);
|
||||
} else {
|
||||
if (isType.apply(acc, AccountType.Clrn) || isType.apply(acc, AccountType.Tran)) {
|
||||
registries = selectRegistryForSDF04(acc.getAccount());
|
||||
} else if (isType.apply(acc, AccountType.Anlt)) {
|
||||
//в сдф04 указан ANLT или TRAN счет, ищем по контракту
|
||||
AnltSearcher.AnltSearch anltSearch = anltSearcher.loadByAnlt(sdf04.getSpecif_1(), sdf04.getPay_val());
|
||||
if (!anltSearch.isFound()) {
|
||||
|
|
@ -112,10 +107,18 @@ public class Sdf04Executor extends AbstractExecutor<SDf04> {
|
|||
} else {
|
||||
registries = selectRegistryForSDF04(anltSearch.getAccount().getAccount());
|
||||
}
|
||||
} else {
|
||||
log.error("FATAL error: no registry search defined for '{}' account type",
|
||||
acc.getAccountType());
|
||||
registries = Collections.emptyList();
|
||||
}
|
||||
return registries;
|
||||
};
|
||||
srch.apply(accDeb).forEach(am_b -> assets.processByAm_b(am_b, parseString(sdf04.getSum_deb())));
|
||||
if (isType.apply(accCred, AccountType.Tran)) {
|
||||
srch.apply(accCred).forEach(am_b -> assets.processByAm_b(am_b, parseString(sdf04.getSum_deb()).negate()));
|
||||
}
|
||||
registries.forEach(am_b -> assets.processByAm_b(am_b, parseString(sdf04.getSum_deb())));
|
||||
}
|
||||
//todo переписать логику поиска на аналогичную по счетам(TRAN)
|
||||
Session activeSession = sessionImdg.getSingleObjectByFieldValues(Map.of("workflowStatus", Status.Active.getKey()));
|
||||
Instant now = Instant.now();
|
||||
if (activeSession != null) {
|
||||
|
|
|
|||
|
|
@ -167,7 +167,8 @@ public class Sdf06Executor {
|
|||
statementImdg.insert(stmt);
|
||||
log.debug("Statement created: {}", stmt.getId());
|
||||
if (InOutDirection.out.getKey().equals(stmt.getInOutDirection()) && tradingTimeService.isTradingTime()) {
|
||||
requests.add(GatewayRequestCreator.from(stmt, company.getTradingCode(), tcr.getCode()));
|
||||
requests.add(GatewayRequestCreator.from(stmt, company.getTradingCode(), tcr.getCode(),
|
||||
currency.getCurrencyCode()));
|
||||
} else {
|
||||
processedApproved(stmt, sDf06, now, sdf07GroupId);
|
||||
if (tcr != null) {
|
||||
|
|
|
|||
|
|
@ -813,14 +813,20 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
|
|||
}
|
||||
String tradingCode = company.getTradingCode();
|
||||
AssetOperationListRequest gatewayRequest = new AssetOperationListRequest();
|
||||
AssetOperationRequest req = GatewayRequestCreator.from(stmt, tradingCode, tcrCode);
|
||||
Currency currency = currencyImdg.getSingleObjectByID(stmt.getSecurityId());
|
||||
AssetOperationRequest req = GatewayRequestCreator.from(
|
||||
stmt,
|
||||
tradingCode,
|
||||
tcrCode,
|
||||
currency != null ? currency.getCurrencyCode() : CurrencyCode.RUB.getKey());
|
||||
String specif = stmt.getComment();
|
||||
|
||||
Matcher m;
|
||||
if (!TextUtil.isEmpty(specif) && (m = csBlkd.matcher(specif)).find()) {
|
||||
try {
|
||||
Long sessionId = Long.valueOf(m.group(1));
|
||||
List<Registry> d__vs = assets.searchByParams(account.getAccount(), CurrencyCode.RUB.getKey(), company.getId(), D__V)
|
||||
List<Registry> d__vs = assets.searchByParams(account.getAccount(),
|
||||
currency != null ? currency.getCurrencyCode() : CurrencyCode.RUB.getKey(),
|
||||
company.getId(), D__V)
|
||||
.stream()
|
||||
.filter(rgs -> sessionId.equals(rgs.getSessionId()))
|
||||
.toList();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package ru.spcex.clearing.service.integration;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import ru.clearing.classes.statics.data.payment.PaymentInstruction;
|
||||
import ru.clearing.classes.statics.data.registry.Registry;
|
||||
import ru.clearing.classes.statics.data.statement.Statement;
|
||||
|
|
@ -8,14 +9,15 @@ import ru.spcex.platform.enumeration.CurrencyCode;
|
|||
import ru.spcex.platform.enumeration.InOutDirection;
|
||||
import ru.spcex.platform.utils.number.BigDecimalUtil;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class GatewayRequestCreator {
|
||||
public static AssetOperationRequest from(Statement stmt, String tradingCode, String tcrCode) {
|
||||
public static AssetOperationRequest from(Statement stmt,
|
||||
String tradingCode,
|
||||
String tcrCode,
|
||||
String currency) {
|
||||
AssetOperationRequest req = new AssetOperationRequest();
|
||||
req.setEntityId(stmt.getId());
|
||||
req.setAmount(stmt.getAmount());
|
||||
req.setSecuritySymbol(CurrencyCode.RUB.getKey()); //fixme retrieve security symbol from validator
|
||||
req.setSecuritySymbol(currency);
|
||||
req.setTradingCode(tradingCode);
|
||||
req.setCode(tcrCode);
|
||||
req.setDirection(stmt.getInOutDirection());
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue