sdf06 missing TCR
при ожидание ответа gateway новые sdf06 запросы добавляются в очередь
This commit is contained in:
parent
4763724315
commit
d6a790cec7
2 changed files with 78 additions and 39 deletions
|
|
@ -43,10 +43,7 @@ import ru.spcex.platform.utils.validation.ValidatorImpl;
|
|||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static ru.spcex.platform.utils.number.BigDecimalUtil.safeBD;
|
||||
|
|
@ -71,16 +68,18 @@ public class Sdf06Executor {
|
|||
private final DmiService dmiService;
|
||||
|
||||
private final static BigDecimal successResult = BigDecimal.ZERO;
|
||||
//ошибка проверок
|
||||
private final static BigDecimal errorResult2 = new BigDecimal("3");
|
||||
//ошибка проверок баланса или наличия сессии - в этом сценарии session создается
|
||||
//идет сессия (не возвращаем такую ошибку)
|
||||
private final static BigDecimal errorResult1 = new BigDecimal("1");
|
||||
//отказ от gateway
|
||||
//Участник не найден – переход в ручной режим
|
||||
private final static BigDecimal errorResult2 = new BigDecimal("2");
|
||||
//отказ от gateway либо недостаточно средств у нас
|
||||
private final static BigDecimal errorResult3 = new BigDecimal("3");
|
||||
private final static BigDecimal errorResult4 = new BigDecimal("4");
|
||||
|
||||
|
||||
//not thread safe: used in EventReceiver single thread executor
|
||||
//переменная контроля за тем что от гейтвея пришел ответ именно на наш запрос
|
||||
LinkedList<BaseRequest<StatementRequest>> cachedRequests = new LinkedList<>();
|
||||
private Long sdf06GroupId;
|
||||
private Long sdf07GroupId;
|
||||
|
||||
|
|
@ -116,13 +115,8 @@ public class Sdf06Executor {
|
|||
Instant now = Instant.now();
|
||||
Long sdf07GroupId = idGenerator.nextId();
|
||||
if (sdf06GroupId != null) {
|
||||
log.warn("currently awaiting gateway response for groupId: {}. skipping groupId {}", sdf06GroupId, groupId);
|
||||
sdfs.forEach(sdf06 -> {
|
||||
SDf07 errorSdf07 = createSdf07(sdf06, now, errorResult2); //fixme "1"
|
||||
errorSdf07.setGenerationId(sdf07GroupId);
|
||||
sdf07Imdg.insert(errorSdf07);
|
||||
});
|
||||
sendToExporter(sdf07GroupId, fileName);
|
||||
log.warn("currently awaiting gateway response for groupId: {}. adding to cache groupId {}", sdf06GroupId, groupId);
|
||||
cachedRequests.add(systemRequest);
|
||||
return;
|
||||
}
|
||||
Collection<AssetOperationRequest> requests = new ArrayList<>();
|
||||
|
|
@ -161,10 +155,12 @@ public class Sdf06Executor {
|
|||
requests.add(GatewayRequestCreator.gatewayRequestPart(stmt, company.getTradingCode(), tcr.getCode()));
|
||||
} else {
|
||||
processedApproved(stmt, sDf06, now, sdf07GroupId);
|
||||
dmiService.setProc(tcr.getId(),
|
||||
CurrencyCode.RUB.getKey(),
|
||||
safeBD(sDf06.getSum()),
|
||||
sDf06.getNumber());
|
||||
if (tcr != null) {
|
||||
dmiService.setProc(tcr.getId(),
|
||||
CurrencyCode.RUB.getKey(),
|
||||
safeBD(sDf06.getSum()),
|
||||
sDf06.getNumber());
|
||||
}
|
||||
sdf07WasCreated = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -203,15 +199,23 @@ public class Sdf06Executor {
|
|||
}
|
||||
|
||||
private BigDecimal errorById(EnumMessage err) {
|
||||
if (ClearingError.BalanceInsufficient.equals(err.getSubject())) {
|
||||
return errorResult3;
|
||||
}
|
||||
if ( ClearingError.CompanyNotFoundB.equals(err.getSubject())
|
||||
BigDecimal result = null;
|
||||
if (ClearingError.CompanyNotFoundB.equals(err.getSubject())
|
||||
|| ClearingError.AccountNotFoundB.equals(err.getSubject())
|
||||
|| ClearingError.TCRegistryNotFound.equals(err.getSubject())) {
|
||||
return errorResult2;
|
||||
result = Sdf06Executor.errorResult2;
|
||||
}
|
||||
return errorResult2;
|
||||
if (ClearingError.BalanceInsufficient.equals(err.getSubject())) {
|
||||
result = errorResult3;
|
||||
}
|
||||
if (ClearingError.WrongField.equals(err.getSubject())) {
|
||||
result = errorResult4;
|
||||
}
|
||||
if (result == null) {
|
||||
result = errorResult4;
|
||||
}
|
||||
log.debug("error subject {} result {}", err.getSubject(), result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void processGatewayResponse(BaseRequest<AssetOperationApprovalRequest> req) {
|
||||
|
|
@ -285,6 +289,10 @@ public class Sdf06Executor {
|
|||
} else {
|
||||
log.debug("gateway response was not for SDF06 executor");
|
||||
}
|
||||
if (cachedRequests.size() > 0) {
|
||||
BaseRequest<StatementRequest> statementRequest = cachedRequests.removeFirst();
|
||||
execute(statementRequest);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearContext() {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ 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.InOutDirection;
|
||||
import ru.spcex.platform.enumeration.RegistryTradingParams;
|
||||
import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
|
|
@ -31,6 +32,8 @@ import java.util.Objects;
|
|||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static ru.spcex.platform.utils.number.BigDecimalUtil.safeBD;
|
||||
|
||||
public enum Sdf06NewValidationRule implements IValidationRule<ImdgValidationContext<SDf06>> {
|
||||
Fields() {
|
||||
@Override
|
||||
|
|
@ -39,6 +42,9 @@ public enum Sdf06NewValidationRule implements IValidationRule<ImdgValidationCont
|
|||
if (validatedObject.getNumber() == null) {
|
||||
return of(ClearingError.WrongField, "number");
|
||||
}
|
||||
if (validatedObject.getSum() == null) {
|
||||
return of(ClearingError.WrongField, "sum");
|
||||
}
|
||||
return empty();
|
||||
}
|
||||
},
|
||||
|
|
@ -147,33 +153,58 @@ public enum Sdf06NewValidationRule implements IValidationRule<ImdgValidationCont
|
|||
if (account == null) {
|
||||
return of(ClearingError.TCRegistryNotFound, "<no account to search for>");
|
||||
}
|
||||
InOutDirection dir;
|
||||
if (safeBD(sdf06.getSum()).compareTo(BigDecimal.ZERO) >= 0) {
|
||||
dir = (InOutDirection.in);
|
||||
} else {
|
||||
dir = (InOutDirection.out);
|
||||
}
|
||||
Imdg<TradingClearingRegistry> tcrImdg;
|
||||
tcrImdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||
//если направление in то ТКР необязателен
|
||||
Function<Optional<EnumMessage>, Optional<EnumMessage>> err = msg -> {
|
||||
if (dir.equals(InOutDirection.in)) {
|
||||
return Optional.empty();
|
||||
} else {
|
||||
return msg;
|
||||
}
|
||||
};
|
||||
AnltSearcher.AnltSearch anltSrch;
|
||||
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>");
|
||||
log.debug("ANLT couldn't find by account.id={} spec empty", account.getId());
|
||||
return err.apply(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());
|
||||
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());
|
||||
log.debug("ANLT couldn't find by account.id={} by spec {}", account.getId(), sdf06.getSpec());
|
||||
return err.apply(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());
|
||||
log.debug("account.id={}, TCR.id={} ANLT found by account.id={} by spec {}",
|
||||
anltSrch.getAccount().getId(),
|
||||
anltSrch.getTcr().getId(),
|
||||
account.getId(),
|
||||
sdf06.getSpec());
|
||||
context.storeObject(ValidationStored.Sdf06Tcr, anltSrch.getTcr());
|
||||
return empty();
|
||||
}
|
||||
} else {
|
||||
TradingClearingRegistry tcr = tcrImdg.getFirstObjectByFieldValues(
|
||||
Map.of("moneyAccountId", account.getId())
|
||||
);
|
||||
if (tcr != null) {
|
||||
context.storeObject(ValidationStored.Sdf06Tcr, tcr);
|
||||
return empty();
|
||||
} else {
|
||||
log.debug("couldn't find TCR by account.id={} accountType {}",
|
||||
account.getId(), account.getAccountType());
|
||||
return err.apply(of(ClearingError.TCRegistryNotFound, "<moneyAccountId = " + account.getId() + ">"));
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue