account-service http://jira.mfd.msk:8088/browse/CLS-265
This commit is contained in:
parent
e9a1b245f1
commit
42b26f4988
3 changed files with 67 additions and 32 deletions
|
|
@ -115,13 +115,7 @@ public class AccountValidationConfig {
|
|||
IMDGDistributedNames.Map_Account,
|
||||
Account.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.AccountNotFound,
|
||||
account -> {
|
||||
// проверка на заблокированность счёта
|
||||
if (!AccountStatus.ACTIVE.getKey().equalsIgnoreCase(account.getStatus()))
|
||||
return AccountError.AccountNotActive;
|
||||
return null;
|
||||
}),
|
||||
AccountError.AccountNotFound),
|
||||
IdPresentRule.instance("companyId",
|
||||
CorrespondentAccountUpdateRequest::getCompanyId,
|
||||
IMDGDistributedNames.Map_Company,
|
||||
|
|
@ -130,16 +124,17 @@ public class AccountValidationConfig {
|
|||
AccountError.CompanyNotFound,
|
||||
false,
|
||||
company -> {
|
||||
IErrorEnumId error = WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus()) ? null : AccountError.CompanyNotActive;
|
||||
error = Objects.equals(company.getId(), correspondentAccountUpdateRequest.getCompanyId()) ? error : AccountError.WrongFieldValue;
|
||||
return error;
|
||||
if (Objects.equals(company.getId(), correspondentAccountUpdateRequest.getCompanyId()))
|
||||
return null;
|
||||
return AccountError.WrongFieldValue;
|
||||
}),
|
||||
DictionaryPresentRule.instance("status",
|
||||
CorrespondentAccountUpdateRequest::getStatus,
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary,
|
||||
ServiceStatusDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.WrongFieldValue),
|
||||
AccountError.WrongFieldValue,
|
||||
false),
|
||||
DictionaryPresentRule.instance("accountType",
|
||||
CorrespondentAccountUpdateRequest::getAccountType,
|
||||
IMDGDistributedNames.Map_AccountTypeDictionary,
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import ru.spcex.clearing.util.security.UserRoleVerification;
|
|||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||
import ru.spcex.platform.enumeration.ClearingCategory;
|
||||
import ru.spcex.platform.enumeration.ServiceStatus;
|
||||
import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
|
|
@ -127,7 +128,7 @@ public class AccountService extends QueueConsumer implements InitializingBean {
|
|||
account.setCompanyId(req.getCompanyId());
|
||||
account.setAccount(req.getAccount());
|
||||
account.setAccountType(req.getAccountType());
|
||||
account.setStatus(req.getStatus());
|
||||
account.setStatus(WorkflowStatus.Active.getKey());
|
||||
account.setCreated(now);
|
||||
account.setUpdated(now);
|
||||
|
||||
|
|
@ -194,6 +195,9 @@ public class AccountService extends QueueConsumer implements InitializingBean {
|
|||
account.setAccount(accountReq.getAccount());
|
||||
account.setCompanyId(accountReq.getCompanyId());
|
||||
account.setAccountType(accountReq.getAccountType());
|
||||
account.setStatus(WorkflowStatus.Active.getKey());
|
||||
account.setCreated(Instant.now());
|
||||
account.setUpdated(account.getCreated());
|
||||
accountMap.insert(account);
|
||||
AccountSdfToStatementRequestPart responsePart = responsePart(accountReq.getSdfId());
|
||||
accountToStatement.add(responsePart);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
|||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.InformationAccountNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.reports.ReportRequest;
|
||||
import ru.spcex.clearing.platform.messaging.serialization.LogFormatter;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
|
|
@ -24,6 +25,7 @@ import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
|||
import ru.spcex.clearing.util.services.RequestHelper;
|
||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.enumeration.ReportType;
|
||||
import ru.spcex.platform.enumeration.ServiceStatus;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
|
@ -173,7 +175,7 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
|||
|
||||
|
||||
public RequestInfoUpdate informationAccountSystemNew(BaseRequest<InformationAccountNewRequest> userRequest) {
|
||||
log.debug("InformationAccountNewRequest received (system)");
|
||||
log.debug("InformationAccountNewRequest received (system), request id={}", userRequest.getId());
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate;
|
||||
// RequestInfoUpdate requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, infoAccountNewRequestValidator);
|
||||
|
|
@ -194,23 +196,27 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
|||
}
|
||||
|
||||
|
||||
// todo требуется последовательность n+1
|
||||
Long newId = informationAccountImdg.nextIDSequenceFor();
|
||||
Long infoSequenceId = accountNextId();
|
||||
Long infoSequenceId = accountNextId(); // требуется последовательность n+1
|
||||
String accountValue = generateInfoAccount(infoSequenceId);
|
||||
log.trace("New info-account id={}, sequenceId={}, account={}", newId, infoSequenceId, accountValue);
|
||||
|
||||
ImdgPredicate andPredicate = pb.and(
|
||||
pb.equals("companyId", 1L),
|
||||
pb.equals("accountType", AccountType.Anlt.getKey())
|
||||
);
|
||||
Collection<Account> accountsAnlt = accountImdg.getCollectionObjectsByPredicate(andPredicate);
|
||||
if (accountsAnlt.isEmpty()) {
|
||||
return requestHelper.makeErrorResponse(userRequest, AccountError.WrongFieldValue, "clearingAccountId");
|
||||
} else if (accountsAnlt.size() > 1) {
|
||||
log.warn("Account for companyId 1 and accountType=ANLT contains multiply elements, use first");
|
||||
Long anltAccountId = null;
|
||||
{
|
||||
ImdgPredicate andPredicate = pb.and(
|
||||
pb.equals("companyId", 1L),
|
||||
pb.equals("accountType", AccountType.Anlt.getKey())
|
||||
);
|
||||
Collection<Account> accountsAnlt = accountImdg.getCollectionObjectsByPredicate(andPredicate);
|
||||
if (accountsAnlt.isEmpty()) {
|
||||
log.error("Account with {} not exist.", andPredicate);
|
||||
return requestHelper.makeErrorResponse(userRequest, AccountError.WrongFieldValue, "clearingAccountId");
|
||||
} else if (accountsAnlt.size() > 1) {
|
||||
log.warn("Account for companyId 1 and accountType=ANLT contains multiply elements, use first");
|
||||
}
|
||||
Account anltAccount = accountsAnlt.iterator().next();
|
||||
anltAccountId = anltAccount.getId();
|
||||
}
|
||||
Account anltAccount = accountsAnlt.iterator().next();
|
||||
|
||||
Instant now = Instant.now();
|
||||
Account account = new Account();
|
||||
|
|
@ -221,7 +227,10 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
|||
account.setCreated(now);
|
||||
account.setUpdated(now);
|
||||
requestInfoUpdate = accountService.fillAccountFromRelation(account, userRequest.getId(), true);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
if (requestInfoUpdate != null) {
|
||||
log.debug("Stop make new account, cause error: {}", requestInfoUpdate.getMessage());
|
||||
return requestInfoUpdate;
|
||||
}
|
||||
|
||||
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||
imdgTransaction.beginTransaction();
|
||||
|
|
@ -235,18 +244,13 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
|||
informationAccount = new InformationAccount();
|
||||
informationAccount.setId(newId);
|
||||
informationAccount.setAccountId(accountId);
|
||||
informationAccount.setClearingAccountId(anltAccount.getId());
|
||||
informationAccount.setClearingAccountId(anltAccountId);
|
||||
informationAccount.setCompanyId(userRequest.getRequestPayload().getCompanyId());
|
||||
informationAccountId = informationAccountImdg.insert(informationAccount);
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk) {
|
||||
imdgTransaction.commitTransaction();
|
||||
TradingClearingRegistryNewRequest request = new TradingClearingRegistryNewRequest();
|
||||
request.setMoneyAccountId(informationAccountId);
|
||||
request.setCompanyId(informationAccount.getCompanyId());
|
||||
log.debug("Send message to kafka \"{}\": {}", Consts.DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW, LogFormatter.toStringWrapper(request));
|
||||
kafkaSender.sendRequestToQueue(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW, request);
|
||||
log.debug("successfully processed, new information account id {}, new account id {}",
|
||||
informationAccountId,
|
||||
accountId);
|
||||
|
|
@ -258,9 +262,37 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
|||
}
|
||||
}
|
||||
|
||||
// send to kafka
|
||||
sendNotificationToTCR(informationAccount, account);
|
||||
sendNotificationToReport(informationAccount, account);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Автоматическое добавление ТКР
|
||||
*/
|
||||
protected void sendNotificationToTCR(InformationAccount informationAccount, Account account) {
|
||||
TradingClearingRegistryNewRequest request = new TradingClearingRegistryNewRequest();
|
||||
request.setMoneyAccountId(account.getId());
|
||||
request.setCompanyId(informationAccount.getCompanyId());
|
||||
log.debug("Send message to kafka \"{}\": {}", Consts.DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW, LogFormatter.toStringWrapper(request));
|
||||
kafkaSender.sendRequestToQueue(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Формирование уведолмения о регистрации УК
|
||||
*/
|
||||
protected void sendNotificationToReport(InformationAccount informationAccount, Account account) {
|
||||
//todo актуализировать ТЗ или ReportRequest
|
||||
// ReportRequest request = new ReportRequest();
|
||||
// request.setReportId(ReportType.REGISTRACTION_UK/NEW_INFO_ACCOUNT);
|
||||
// request.setCompanyId(informationAccount.getCompanyId());
|
||||
// log.debug("Send message to kafka \"{}\": {}", Consts.CREATE_REPORT_WITH_COMPANY_ID, LogFormatter.toStringWrapper(request));
|
||||
// kafkaSender.sendRequestToQueue(Consts.CREATE_REPORT_WITH_COMPANY_ID, request);
|
||||
// // см. в report-service: ROOT_ACTV_NotificationBuilder, ru.spcex.clearing.reports.services.ReportService
|
||||
}
|
||||
|
||||
public String generateInfoAccount(Long id) {
|
||||
return "%d%d%08d%d".formatted(39911, 810, id, 7000);
|
||||
}
|
||||
|
|
@ -283,10 +315,12 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
|||
Pattern accPattern = Pattern.compile("39911810([0-9]{8})7000");
|
||||
int maxN = 1;
|
||||
int parsedCount = 0;
|
||||
String lastAccount = null; // for debug
|
||||
for (Account acc : allInfoAcc) {
|
||||
try {
|
||||
String number = acc.getAccount();
|
||||
if (StringUtils.isEmpty(number)) continue;
|
||||
lastAccount = number;
|
||||
Matcher m = accPattern.matcher(number);
|
||||
if (m.find()) {
|
||||
String seqNumber = m.group(1);
|
||||
|
|
@ -303,6 +337,8 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
|||
infoCounter = new AtomicLong(maxN);
|
||||
log.debug("Parsed {} information accounts ({} pattern match) in map. n={}",
|
||||
allInfoAcc.size(), parsedCount, infoCounter.get());
|
||||
if (parsedCount == 0 && lastAccount != null)
|
||||
log.debug("Last unparseable account: {}", lastAccount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue