TCR registry update, AM*F/AM*T/AM*B creation
This commit is contained in:
parent
90a2b858bb
commit
43911cbb58
2 changed files with 95 additions and 0 deletions
|
|
@ -5,6 +5,8 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.misc.Currency;
|
||||
import ru.clearing.classes.statics.data.payment.PaymentInstruction;
|
||||
import ru.clearing.classes.statics.data.registry.Registry;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||
|
|
@ -47,6 +49,7 @@ import java.util.Map;
|
|||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static ru.spcex.clearing.session.stage.impl.GatewayRequester.mapError;
|
||||
import static ru.spcex.platform.utils.number.BigDecimalUtil.safeBD;
|
||||
|
|
@ -58,6 +61,9 @@ public class RegistryService {
|
|||
private final ImdgProvider imdgProvider;
|
||||
private final Imdg<TradingClearingRegistry> tradingClearingRegistryImdg;
|
||||
private final Imdg<Registry> registryImdg;
|
||||
private final Imdg<Account> accImdg;
|
||||
private final Imdg<Currency> currImdg;
|
||||
private final Imdg<Company> cmpImdg;
|
||||
private final Imdg<PaymentInstruction> pmtImdg;
|
||||
private final Function<RegistryReturnDepositRequest, IValidator> returnDepositVal;
|
||||
private final Function<RegistryChangeRefundDateRequest, IValidator> refundDateVal;
|
||||
|
|
@ -90,6 +96,9 @@ public class RegistryService {
|
|||
this.tradingClearingRegistryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||
this.registryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Registry, Registry.class);
|
||||
this.pmtImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_PaymentInstruction, PaymentInstruction.class);
|
||||
this.accImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
this.currImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Currency, Currency.class);
|
||||
this.cmpImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
this.returnDepositVal = returnDepositVal;
|
||||
this.refundDateVal = refundDateVal;
|
||||
this.identificationFundsVal = identificationFundsVal;
|
||||
|
|
@ -155,6 +164,52 @@ public class RegistryService {
|
|||
registryImdg.update(rgs);
|
||||
log.trace("TCR#id={} registry#id={} updated", tcr.getId(), rgs.getId());
|
||||
});
|
||||
|
||||
if (registries.size() > 0) {
|
||||
log.info("assets size {} updated by TCR#id={}, will not create new assets",
|
||||
registries.size(), tcr.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
Account acc = accImdg.getSingleObjectByID(tcr.getMoneyAccountId());
|
||||
Currency currency = currImdg.getFirstObjectBySQL("currencyCode = '%s'".formatted(CurrencyCode.RUB.getKey()));
|
||||
Company cmp = cmpImdg.getSingleObjectByID(tcr.getCompanyId());
|
||||
|
||||
if (acc == null) {
|
||||
log.warn("TCR#id={} account {} not found", tcr.getId(), tcr.getMoneyAccountId());
|
||||
return;
|
||||
}
|
||||
if (currency == null) {
|
||||
log.warn("TCR#id={} currency {} not found", tcr.getId(), CurrencyCode.RUB.getKey());
|
||||
return;
|
||||
}
|
||||
if (cmp == null) {
|
||||
log.warn("TCR#id={} company {} not found", tcr.getId(), tcr.getCompanyId());
|
||||
return;
|
||||
}
|
||||
log.debug("TCR#id={} account#id={} company#id={}, creating assets", tcr.getId(), acc.getId(), cmp.getId());
|
||||
|
||||
AssetTrio assets = this.assets.createMAssets(acc,
|
||||
CurrencyCode.RUB.getKey(),
|
||||
currency.getId(),
|
||||
tcr.getTradingClearingRegistryType(),
|
||||
tcr.getId(),
|
||||
tcr.getCode(),
|
||||
cmp);
|
||||
|
||||
|
||||
Stream.of(assets.a__t(), assets.a__b(), assets.a__f())
|
||||
.forEach(a -> {
|
||||
a.setRegistryStatus(RegistryStatus.PROC.getKey());
|
||||
registryImdg.insert(a);
|
||||
});
|
||||
|
||||
log.debug("TCR#id={} created {}#id={} {}#id={} {}#id={}",
|
||||
tcr.getId(),
|
||||
assets.a__f().getRegistryCode(), assets.a__f().getId(),
|
||||
assets.a__t().getRegistryCode(), assets.a__t().getId(),
|
||||
assets.a__b().getRegistryCode(), assets.a__b().getId());
|
||||
|
||||
}
|
||||
|
||||
public RequestInfoUpdate returnDeposit(BaseRequest<RegistryReturnDepositRequest> req) {
|
||||
|
|
|
|||
|
|
@ -162,6 +162,46 @@ public class AssetTBFProcessing {
|
|||
return new AssetTrio(asf, asb, ast);
|
||||
}
|
||||
|
||||
public AssetTrio createMAssets(Account acc,
|
||||
String securitySymbol,
|
||||
Long securityId,
|
||||
String tcrType,
|
||||
Long tcrId,
|
||||
String tcr,
|
||||
Company company) {
|
||||
Registry ast = new Registry();
|
||||
ast.setCreated(Instant.now());
|
||||
ast.setSecuritySymbol(securitySymbol);
|
||||
ast.setSecurityId(securityId);
|
||||
ast.setAccountId(acc.getId());
|
||||
ast.setAccount(acc.getAccount());
|
||||
ast.setAccountType(acc.getAccountType());
|
||||
ast.setRegistryDesignation(RegistryDesignation.A.getKey());
|
||||
ast.setRegistryInstrumentType(RegistryInstrumentType.M.getKey());
|
||||
ast.setRegistryCapacity(tcrType);
|
||||
ast.setRegistryUnit(RegistryUnit.T.getKey());
|
||||
ast.setRegistryCode(RegistryUtil.clearingCode(ast));
|
||||
ast.setClearingCode(company.getClearingCode());
|
||||
ast.setTradingCode(company.getClearingCode());
|
||||
ast.setCompanyId(company.getId());
|
||||
ast.setShortName(company.getShortName());
|
||||
ast.setFullName(company.getFullName());
|
||||
ast.setTradingClearingRegistryId(tcrId);
|
||||
ast.setTradingClearingRegistry(tcr);
|
||||
ast.setRegistryStatus(RegistryStatus.OK.getKey());
|
||||
ast.setBalanceDimension(BalanceDimension.MONY.getKey());
|
||||
RegistryManager.zeroState(ast);
|
||||
Registry asf = ast.clone();
|
||||
asf.setRegistryUnit(RegistryUnit.F.getKey());
|
||||
asf.setRegistryCode(RegistryUtil.clearingCode(asf));
|
||||
RegistryManager.zeroState(asf);
|
||||
Registry asb = ast.clone();
|
||||
asb.setRegistryUnit(RegistryUnit.B.getKey());
|
||||
asb.setRegistryCode(RegistryUtil.clearingCode(asb));
|
||||
RegistryManager.zeroState(asb);
|
||||
return new AssetTrio(asf, asb, ast);
|
||||
}
|
||||
|
||||
public Optional<Registry> searchByTcrCompanyAccount(Registry rgs,
|
||||
RegistryTradingParams params) {
|
||||
ImdgPredicateBuilder pb = rgsImdg.predicateBuilder();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue