SDF06 поиск по ANLT account
вынес поиск ТКР в валидацию
This commit is contained in:
parent
38a0c7c0f8
commit
0b81edefbb
5 changed files with 67 additions and 12 deletions
|
|
@ -253,12 +253,14 @@ public class ValidationConfig {
|
|||
context.addImdg(IMDGDistributedNames.Map_Company, imdgCompany);
|
||||
context.addImdg(IMDGDistributedNames.Map_Registry, imdgRegistry);
|
||||
context.addImdg(IMDGDistributedNames.Map_Session, imdgSession);
|
||||
context.addImdg(IMDGDistributedNames.Map_TradingClearingRegistry, imdgTradingClearingRegistry);
|
||||
context.setLogPrefix(LogPrefixId.INSTANCE);
|
||||
return new ValidatorImpl<>(context,
|
||||
Sdf06NewValidationRule.CompanySymbolAndCompanyPresent,
|
||||
Sdf06NewValidationRule.AccountPresent,
|
||||
Sdf06NewValidationRule.Session,
|
||||
Sdf06NewValidationRule.Balance
|
||||
Sdf06NewValidationRule.Balance,
|
||||
Sdf06NewValidationRule.TcrPresent
|
||||
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package ru.spcex.clearing.service;
|
|||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
|
|
@ -24,12 +25,19 @@ public class AnltSearcher {
|
|||
private final Imdg<Company> companyImdg;
|
||||
private final Imdg<Account> accountImdg;
|
||||
|
||||
@Autowired
|
||||
public AnltSearcher(ImdgProvider imdgProvider) {
|
||||
this.tradingClearingRegistryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||
this.companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
this.accountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
}
|
||||
|
||||
public AnltSearcher(Imdg<TradingClearingRegistry> tcrImdg, Imdg<Company> companyImdg, Imdg<Account> accountImdg) {
|
||||
this.tradingClearingRegistryImdg = tcrImdg;
|
||||
this.companyImdg = companyImdg;
|
||||
this.accountImdg = accountImdg;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface AnltLogger {
|
||||
void log(IEnumId subject, Object... args);
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ public class Sdf06Executor {
|
|||
if (sdf06GroupId != null) {
|
||||
log.warn("currently awaiting gateway response for groupId: {}. skipping groupId {}", sdf06GroupId, groupId);
|
||||
sdfs.forEach(sdf06 -> {
|
||||
SDf07 errorSdf07 = createSdf07(sdf06, now, errorResult2);
|
||||
SDf07 errorSdf07 = createSdf07(sdf06, now, errorResult2); //fixme "1"
|
||||
errorSdf07.setGenerationId(sdf07GroupId);
|
||||
sdf07Imdg.insert(errorSdf07);
|
||||
});
|
||||
|
|
@ -152,12 +152,9 @@ public class Sdf06Executor {
|
|||
continue;
|
||||
}
|
||||
Company company = validator.getStored(ValidationStored.Sdf06Company);
|
||||
Account account = validator.getStored(ValidationStored.Sdf06Account);
|
||||
TradingClearingRegistry tcr = tradingClearingRegistryImdg.getFirstObjectByFieldValues(
|
||||
Map.of("moneyAccountId", account.getId())
|
||||
);
|
||||
TradingClearingRegistry tcr = validator.getStored(ValidationStored.Sdf06Tcr);
|
||||
//проверка существует ли statement пока убрал
|
||||
Statement stmt = createStatementBySdf06(sDf06, company.getId(), account);
|
||||
Statement stmt = createStatementBySdf06(sDf06, company.getId(), validator.getStored(ValidationStored.Sdf06Account));
|
||||
statementImdg.insert(stmt);
|
||||
log.debug("Statement created: {}", stmt.getId());
|
||||
if (InOutDirection.in.getKey().equals(stmt.getInOutDirection())) {
|
||||
|
|
@ -197,10 +194,12 @@ public class Sdf06Executor {
|
|||
}
|
||||
|
||||
private boolean needToCreateStatement(EnumMessage err) {
|
||||
return ClearingError.ActiveSessionIsPresent.equals(err.getSubject()) || ClearingError.BalanceInsufficient.equals(err.getSubject());
|
||||
return ClearingError.ActiveSessionIsPresent.equals(err.getSubject()) || ClearingError.BalanceInsufficient.equals(err.getSubject())
|
||||
|| ClearingError.TCRegistryNotFound.equals(err.getSubject());
|
||||
}
|
||||
|
||||
public void processGatewayResponse(BaseRequest<AssetOperationApprovalRequest> req) {
|
||||
//может прийти неограниченно позже 06го, после того как прошел клиринг например...
|
||||
Instant now = Instant.now();
|
||||
String fileName = null;
|
||||
for (SingleAssetResponse gatewayMsg : req.getRequestPayload().getApprovals()) {
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ import ru.clearing.classes.statics.data.account.Account;
|
|||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.misc.Session;
|
||||
import ru.clearing.classes.statics.data.registry.Registry;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||
import ru.clearing.classes.statics.data.sdf.SDf06;
|
||||
import ru.spcex.clearing.error.ClearingError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.service.AnltSearcher;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.enumeration.RegistryTradingParams;
|
||||
import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||
|
|
@ -55,9 +57,16 @@ public enum Sdf06NewValidationRule implements IValidationRule<ImdgValidationCont
|
|||
return of(ClearingError.AccountNotFoundB, sdf06.getAccount());
|
||||
}
|
||||
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
||||
Account account = accountImdg.getFirstObjectByFieldValues(Map.of(
|
||||
"account", sdf06.getAccount(),
|
||||
"accountType", AccountType.Clrn.getKey()));
|
||||
ImdgPredicateBuilder pb = accountImdg.predicateBuilder();
|
||||
Account account = accountImdg.getFirstObjectByPredicate(
|
||||
pb.and(
|
||||
pb.equals("account", sdf06.getAccount()),
|
||||
pb.or(
|
||||
pb.equals("accountType", AccountType.Clrn.getKey()),
|
||||
pb.equals("accountType", AccountType.Anlt.getKey())
|
||||
)
|
||||
)
|
||||
);
|
||||
if (account == null) {
|
||||
return of(ClearingError.AccountNotFoundB, sdf06.getAccount());
|
||||
}
|
||||
|
|
@ -107,6 +116,43 @@ public enum Sdf06NewValidationRule implements IValidationRule<ImdgValidationCont
|
|||
}
|
||||
return empty();
|
||||
}
|
||||
},
|
||||
TcrPresent() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<SDf06> context) {
|
||||
SDf06 sdf06 = context.getValidatedObject();
|
||||
Account account = context.getStoredObject(ValidationStored.Sdf06Account);
|
||||
if (account == null) {
|
||||
return of(ClearingError.TCRegistryNotFound, "<no account to search for>");
|
||||
}
|
||||
Imdg<TradingClearingRegistry> tcrImdg;
|
||||
tcrImdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||
if (AccountType.Anlt.getKey().equals(account.getAccountType())) {
|
||||
log.debug("account.id={} is ANLT", account.getId());
|
||||
if (TextUtil.isEmpty(sdf06.getSpec())) {
|
||||
return of(ClearingError.TCRegistryNotFound, "<spec empty>");
|
||||
}
|
||||
Imdg<Company> companyImdg = context.obtainMap(IMDGDistributedNames.Map_Company, Company.class);
|
||||
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
||||
AnltSearcher anltSearcher = new AnltSearcher(tcrImdg, companyImdg, accountImdg);
|
||||
AnltSearcher.AnltSearch anltSrch = anltSearcher.loadByAnlt(sdf06.getSpec());
|
||||
if (!anltSrch.isFound()) {
|
||||
log.debug("account.id={} ANLT couldn't find account by spec {}", account.getId(), sdf06.getSpec());
|
||||
return of(ClearingError.TCRegistryNotFound, sdf06.getSpec());
|
||||
} else {
|
||||
account = anltSrch.getAccount();
|
||||
log.debug("account.id={} ANLT found account.id={} by spec {}", account.getId(), account.getId(), sdf06.getSpec());
|
||||
}
|
||||
}
|
||||
TradingClearingRegistry tcr = tcrImdg.getFirstObjectByFieldValues(
|
||||
Map.of("moneyAccountId", account.getId())
|
||||
);
|
||||
if (tcr == null) {
|
||||
return of(ClearingError.TCRegistryNotFound, "<moneyAccountId = " + account.getId() + ">");
|
||||
}
|
||||
context.storeObject(ValidationStored.Sdf06Tcr, tcr);
|
||||
return empty();
|
||||
}
|
||||
}
|
||||
;
|
||||
private final static Logger log = LoggerFactory.getLogger(Sdf06NewValidationRule.class);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public enum ValidationStored {
|
|||
|
||||
Sdf21Account,
|
||||
|
||||
Sdf06Company, Sdf06Account,
|
||||
Sdf06Company, Sdf06Account, Sdf06Tcr,
|
||||
|
||||
ReturnDepositDmx,
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue