Merge branch 'dev' into plan_balance_dmx_dmt

This commit is contained in:
ialbert 2023-09-28 17:26:38 +03:00
commit bd7f6ad460
14 changed files with 54 additions and 58 deletions

View file

@ -211,6 +211,9 @@ public class Sdf06Executor {
if (ClearingError.WrongField.equals(err.getSubject())) {
result = errorResult4;
}
if (ClearingError.ActiveSessionIsPresent.equals(err.getSubject())) {
result = errorResult1;
}
if (result == null) {
result = errorResult4;
}

View file

@ -131,10 +131,6 @@ public class MultiCompanyService
);
companyId = getCompanyIdForCompanySymbols(req.getUuid(), req.getCompany(), req.getCompanySymbols());
log.debug("For request {} (uuid {}) company {}.", baseRequest.getId(), req.getUuid(), companyId == null ? "not found" : ("found, id=" + companyId));
if (companyId == null) {
log.debug("For request {} (uuid {}) company not found. Try find by other symbols.", baseRequest.getId(), req.getUuid());
companyId = getCompanyIdForCompanySymbols(req.getCompanySymbols());
}
if (companyId == null) {
companyId = companyService.create(req.getCompany());
@ -353,9 +349,11 @@ public class MultiCompanyService
}
}
if (companySymbol == null && StringUtils.isNotEmpty(cnr.getCompanySymbolValue())
&& IEnumKey.contains(cnr.getCompanySymbol(), CompanySymbol.INN, CompanySymbol.CIO)) { // вероятно там будет только UUID
&& IEnumKey.contains(cnr.getCompanySymbol(), CompanySymbol.UUID, CompanySymbol.INN, CompanySymbol.CIO)) { // вероятно там будет только UUID
{
String companySymbolType = cnr.getCompanySymbol();
log.debug("Company not found by UUID=\"{}\", try find by {}={}",
uuid, companySymbolType, cnr.getCompanySymbolValue());
log.trace("Search company by companySymbol {}={}", companySymbolType, cnr.getCompanySymbolValue());
Collection<CompanySymbols> companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
Map.of(
@ -375,6 +373,7 @@ public class MultiCompanyService
for (CompanySymbolNewRequest cSymbolReq : companySymbols) {
if (IEnumKey.contains(cSymbolReq.getCompanySymbol(), CompanySymbol.INN, CompanySymbol.CIO)) {
String companySymbolType = cSymbolReq.getCompanySymbol();
log.debug("Company not found by UUID=\"{}\", try find by {}", uuid, companySymbolType);
log.trace("Search company by companySymbol {}={}", companySymbolType, cSymbolReq.getCompanySymbolValue());
Collection<CompanySymbols> companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
Map.of(
@ -399,32 +398,6 @@ public class MultiCompanyService
return null;
}
Long getCompanyIdForCompanySymbols(List<CompanySymbolNewRequest> otherRequests) {
CompanySymbols companySymbol = null;
for (CompanySymbolNewRequest req : otherRequests) {
if (req.getCompanySymbol() == null) continue;
log.trace("Search company by companySymbol {}={}", req.getCompanySymbol(), req.getCompanySymbolValue());
Collection<CompanySymbols> companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
Map.of(
"companySymbol", req.getCompanySymbol(),
"companySymbolValue", req.getCompanySymbolValue()
)
);
if (!companySymbolsFromImdg.isEmpty()) {
companySymbol = companySymbolsFromImdg.iterator().next();
if (companySymbolsFromImdg.size() > 1) {
log.warn("For {} found > 1 company_symbols, use first (id = {})", req.getCompanySymbol(), req.getCompanySymbolValue());
}
log.debug("Found by company symbol {} {}", req.getCompanySymbol(), req.getCompanySymbolValue());
break;
}
}
if (companySymbol != null)
return companySymbol.getCompanyId();
else
return null;
}
private <T> BaseRequest<T> wrapRequest(BaseRequest<?> template, T payload, ActionType action) {
BaseRequest<T> r = new BaseRequest<>();
r.setId(template.getId());

View file

@ -53,6 +53,8 @@ public class CompanyProcessor {
map(companyRequestAdapter::toCategoryRequest).toList();
CompanyGatewayRequest companyGatewayRequest = new CompanyGatewayRequest();
if (companyId != null)
companyGatewayRequest.setUuid(companyId.toString());
companyGatewayRequest.setCompany(companyRequestAdapter.toCompanyRequest(memberCompany));
request.getCompanyInfoList()
.stream()

View file

@ -74,7 +74,7 @@ public class AdmittedLiabilitiesRegisterService extends QueueConsumer implements
log.debug("AdmittedLiabilitiesRegisterNewRequest received from {}", Consts.REGISTRY_ADMITTED_LIABILITIES_REGISTER_NEW);
String sqlConditionForRegistry = getSqlForRegistries();
Collection<Registry> registries = registryMap.getCollectionObjectsBySQL(sqlConditionForRegistry);
if (registries == null) {
if (registries.isEmpty()) {
log.debug("No registry with such conditions {}", sqlConditionForRegistry);
return;
}
@ -131,6 +131,7 @@ public class AdmittedLiabilitiesRegisterService extends QueueConsumer implements
@Override
public Optional<AdmittedLiabilitiesRegister> isDuplicateInMap(Registry entity) {
return Optional.empty();
//todo для всех isDuplicateInMap: сказали надо по критерию чистить мапу перед вставкой записей, критерий уточнят.
// Map<String, ? extends Comparable<?>> fieldValues = Map.of(
// "companyId", entity.getRegistryCode(),
// "sessionId", entity.getSessionId(),

View file

@ -75,7 +75,7 @@ public class CoveredLiabilitiesRegisterService extends QueueConsumer implements
log.debug("CoveredLiabilitiesRegisterNew received");
String sqlConditionForRegistry = getSqlForRegistries();
Collection<Registry> registries = registryMap.getCollectionObjectsBySQL(sqlConditionForRegistry);
if (registries == null) {
if (registries.isEmpty()) {
log.debug("No registry with such conditions {}", sqlConditionForRegistry);
return;
}

View file

@ -13,6 +13,7 @@ import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.schedule.LauncherCommandRequest;
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
import ru.spcex.platform.enumeration.AccountType;
import ru.spcex.platform.enumeration.RegistryTradingParams;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgProvider;
@ -63,7 +64,7 @@ public class DepoBalanceRegisterService extends QueueConsumer implements Initial
ImdgPredicate prdctForRegistries = getPredicateForRegistries(userRequest.getRequestPayload().getCompanyId());
Collection<Registry> registries = registryMap.getCollectionObjectsByPredicate(prdctForRegistries);
log.trace("Started searching depoBalanceRegister in register by '{}'", prdctForRegistries);
if (registries == null) {
if (registries.isEmpty()) {
log.debug("No registry with such conditions '{}'", prdctForRegistries);
return;
}
@ -83,8 +84,12 @@ public class DepoBalanceRegisterService extends QueueConsumer implements Initial
depoBalanceRegister.setCreated(depoBalanceRegister.getUpdated());
depoBalanceRegister.setCompanyId(registry.getCompanyId());
depoBalanceRegister.setSessionId(registry.getSessionId());
depoBalanceRegister.setDepoCode(registry.getAccountType());
depoBalanceRegister.setQuantity(registry.getCloseBalance());
if (AccountType.Depo.equalsByKey(registry.getAccountType())) {
depoBalanceRegister.setDepoCode(registry.getAccount());
} else if (registry.getAccountType() != null) {
log.warn("Unexpected registry[{}].accountType={}", registry.getId(), registry.getAccountType());
}
depoBalanceRegister.setQuantity(registry.getBalance());
depoBalanceRegister.setSecuritySymbol(registry.getSecuritySymbol());
depoBalanceRegisterMap.insert(depoBalanceRegister);
log.debug("inserted successfully DepoBalanceRegister entity with id: {}", depoBalanceRegister.getId());

View file

@ -68,7 +68,7 @@ public class DepoPaymentInstructionRegisterService extends QueueConsumer impleme
public void depoPaymentInstructionRegisterNew(BaseRequest<LauncherCommandRequest> userRequest) {
log.debug("LauncherCommandRequest received from {}", createRegistry_GORR.topic());
Collection<Session> actualSessions = sessionMap.getCollectionObjectsByFieldValues(Map.of("section", "FOND"));
if (actualSessions == null) {
if (actualSessions.isEmpty()) {
log.debug("No Session with such conditions section = FOND");
return;
}
@ -89,7 +89,8 @@ public class DepoPaymentInstructionRegisterService extends QueueConsumer impleme
private void insertDepoPaymentInstructionRegister(PaymentInstruction paymentInstruction) {
log.trace("Started generating DepoPaymentInstructionRegister entity...");
DepoPaymentInstructionRegister depoPaymentInstructionRegister = new DepoPaymentInstructionRegister();
TradingClearingRegistry tradingClearingRegistry = paymentInstruction.getSenderId() == null ? null : tradingClearingRegistryMap.getFirstObjectByFieldValues(Map.of("companyId", paymentInstruction.getSenderId()));
TradingClearingRegistry tradingClearingRegistry = paymentInstruction.getCreditLeg_accountId() == null ? null :
tradingClearingRegistryMap.getFirstObjectByFieldValues(Map.of("depoAccountId", paymentInstruction.getCreditLeg_accountId()));
InOutDirectionDictionary inOutDirectionDictionary = InOutDirectionDictionaryMap.getFirstObjectByFieldValues(Map.of("code", paymentInstruction.getCreditLeg_direction()));
depoPaymentInstructionRegister.setCreated(Instant.now());
depoPaymentInstructionRegister.setUpdated(Instant.now());

View file

@ -78,7 +78,7 @@ public class ExcludeLiabilitiesRegisterService extends QueueConsumer implements
log.debug("ExcludeLiabilitiesRegisterNew received");
String sqlForRegistries = getSqlForRegistries();
Collection<Registry> registries = registryMap.getCollectionObjectsBySQL(sqlForRegistries);
if (registries == null) {
if (registries.isEmpty()) {
log.debug("No registry with such conditions {}", sqlForRegistries);
return;
}

View file

@ -115,6 +115,19 @@ public class ExecutionRegisterService extends QueueConsumer implements Initializ
private void insertExecutionRegister(Boolean isFond, ExecutionCommon common) {
log.trace("Started generating ExecutionRegister entity...");
/* todo сверить с ТЗ, замечания от 28.09.2023:
executionRegister - Реестр сделок
sellerId - Если executionDeposit/Fond.side=BUY - company.shortName [executionDeposit/Fond.counterPartyId = company.id]. Если executionDeposit/Fond.side=SELL - company.shortName [executionDeposit/Fond.companyId = company.id]
sellerClearingCode - не заполняется
sellerTradingClearingRegister - не заполняется
sellerMoneyAccount - не заполняется
sellerDepoAccount - не заполняется
buyerId - Если executionDeposit/Fond.side=BUY - company.shortName [executionDeposit/Fond.counterPartyId = company.id]. Если executionDeposit/Fond.side=SELL - company.shortName [executionDeposit/Fond.counterPartyId = company.id]
buyerClearingCode - не заполняется
buyerTradingClearingRegister - не заполняется
buyerMoneyAccount - не заполняется
buyerDepoAccount - не заполняется
*/
String sellerClearingCode = null;
String sellerTradingClearingRegister = null;
String sellerMoneyAccount = null;

View file

@ -18,6 +18,7 @@ import ru.spcex.clearing.platform.messaging.domain.Consts;
import ru.spcex.clearing.platform.messaging.domain.cud.registry.LiabilitiesRegisterNewRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.schedule.LauncherCommandRequest;
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
import ru.spcex.platform.enumeration.CompanySymbol;
import ru.spcex.platform.enumeration.RegistryDesignation;
import ru.spcex.platform.enumeration.RegistryInstrumentType;
import ru.spcex.platform.enumeration.RegistryUnit;
@ -97,10 +98,8 @@ public class LiabilitiesRegisterService extends QueueConsumer implements Initial
)
);
CompanySymbols companySymbols = companySymbolsMap.getFirstObjectByFieldValues(
Map.of("companyId",
registry.getCompanyId(),
"companySymbol",
"INN"
Map.of("companyId", registry.getCompanyId(),
"companySymbol", CompanySymbol.INN.getKey()
)
);
MoneyMarketSecurity moneyMarketSecurity = moneyMarketSecurityMap.getFirstObjectByFieldValues(
@ -116,7 +115,7 @@ public class LiabilitiesRegisterService extends QueueConsumer implements Initial
liabilitiesRegister.setValidToDate(TimeUtil.toLocalDate(session.getUpdated()));
}
if (companySymbols == null) {
log.warn("CompanySymbols is empty!");
log.warn("CompanySymbols is empty! For companyId={}", registry.getCompanyId());
} else {
liabilitiesRegister.setInn(companySymbols.getCompanySymbolValue());
}
@ -127,6 +126,7 @@ public class LiabilitiesRegisterService extends QueueConsumer implements Initial
}
liabilitiesRegister.setSessionId(registry.getSessionId());
liabilitiesRegister.setCompanyId(registry.getCompanyId());
liabilitiesRegister.setCompanyFullName(registry.getFullName());
liabilitiesRegister.setRegistryCode(registry.getRegistryCode());
liabilitiesRegister.setAccount(registry.getAccount());
liabilitiesRegister.setRegistryStatus(registry.getRegistryStatus());

View file

@ -16,6 +16,7 @@ import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.schedule.LauncherCommandRequest;
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
import ru.spcex.platform.enumeration.CompanySymbol;
import ru.spcex.platform.enumeration.RegistryTradingParams;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgProvider;
@ -76,6 +77,7 @@ public class MoneyBalanceRegisterService extends QueueConsumer implements Initia
log.debug("No registry with such conditions {}", sqlConditionForRegistry);
return;
}
//todo надо группировать!
registries.forEach((registry -> {
if (isDuplicateInMap(registry).isEmpty()) {
insertMoneyBalanceRegister(registry);
@ -92,7 +94,7 @@ public class MoneyBalanceRegisterService extends QueueConsumer implements Initia
Registry registryForBlockedSum = registryMap.getFirstObjectByPredicate(getSqlForBlockedSum(registry.getCompanyId(), registry.getAccount()));
Registry registryForUnblockedSum = registryMap.getFirstObjectByPredicate(getSqlForUnblockedSum(registry.getCompanyId(), registry.getAccount()));
Company company = companyMap.getFirstObjectByFieldValues(Map.of("id", 2L));
CompanySymbols companySymbol = companySymbolsMap.getFirstObjectByFieldValues(Map.of("companyId", registry.getCompanyId()));
CompanySymbols companySymbol = companySymbolsMap.getFirstObjectByFieldValues(Map.of("companySymbol", CompanySymbol.INN.getKey(), "companyId", registry.getCompanyId()));
String setHouseName = company != null ? company.getShortName() : null;
String inn = companySymbol != null ? companySymbol.getCompanySymbolValue() : null;
String accountType = registry.getAccountType();

View file

@ -67,13 +67,11 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
String sql = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.TM_T, RegistryTradingParams.OM_T).build();
List<Long> sessionIds = params.getSessionId();
if (sessionIds == null || sessionIds.isEmpty()) sessionIds = getSessionIdsForCurrentDate(sessionImdg);
ImdgPredicate finalPredicate = pb.and(
pb.not(pb.in("registryStatus",
RegistryStatus.CLRD.getKey(),
RegistryStatus.UNCV.getKey(),
RegistryStatus.FAIL.getKey(),
RegistryStatus.NACK.getKey(),
RegistryStatus.NACC.getKey())),
pb.in("sessionId", sessionIds.toArray(new Long[0])),
pb.equals("clearingDate", nowDate),
pb.sql(sql),
pb.or(
pb.equals("accountType", AccountType.Clrn.getKey()),

View file

@ -66,14 +66,12 @@ public class KSRepDepoNettoReportBuilder extends CSVReportBuilder<SessionIdParam
LocalDate nowDate = LocalDate.now();
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
List<Long> sessionIds = params.getSessionId();
if (sessionIds == null || sessionIds.isEmpty()) sessionIds = getSessionIdsForCurrentDate(sessionImdg);
String sql = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.TS_T, RegistryTradingParams.OS_T).build();
ImdgPredicate finalPredicate = pb.and(
pb.not(pb.in("registryStatus",
RegistryStatus.CLRD.getKey(),
RegistryStatus.UNCV.getKey(),
RegistryStatus.FAIL.getKey(),
RegistryStatus.NACK.getKey(),
RegistryStatus.NACC.getKey())),
pb.in("sessionId", sessionIds.toArray(new Long[0])),
pb.equals("clearingDate", nowDate),
pb.sql(sql),
pb.equals("accountType", AccountType.Depo.getKey()),
pb.notNull("account")

View file

@ -142,7 +142,7 @@ public class KSRepDepoRegisterQuantitiesReportBuilder extends CSVReportBuilder<E
}
KSRepDepoRegisterQuantitiesReport ksRepDepoRegisterQuantitiesReport = new KSRepDepoRegisterQuantitiesReport();
ksRepDepoRegisterQuantitiesReport.setFirmId(String.valueOf(statement.getAddresseeId()));
ksRepDepoRegisterQuantitiesReport.setFirmId(company.getTradingCode());
ksRepDepoRegisterQuantitiesReport.setAccount(statement.getAccount());
ksRepDepoRegisterQuantitiesReport.setTkr(registry.getTradingClearingRegistry());
ksRepDepoRegisterQuantitiesReport.setSecurityId(security.getSecuritySymbol());