gateway-api company-service http://jira.mfd.msk:8088/browse/CLS-347
This commit is contained in:
parent
d81c4b7040
commit
e9de1c87a7
4 changed files with 101 additions and 11 deletions
|
|
@ -56,6 +56,9 @@ public class ProfileDocumentValidationConfig {
|
|||
FieldRequiredRule.instance("issuer",
|
||||
ProfileDocumentNewRequest::getIssuer,
|
||||
CompanyErrors.RequiredFieldEmpty),
|
||||
FieldRequiredRule.instance("number",
|
||||
ProfileDocumentNewRequest::getNumber,
|
||||
CompanyErrors.RequiredFieldEmpty),
|
||||
FieldRequiredRule.instance("validToDate",
|
||||
ProfileDocumentNewRequest::getValidToDate,
|
||||
CompanyErrors.RequiredFieldEmpty),
|
||||
|
|
|
|||
|
|
@ -119,11 +119,11 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
|||
switch (actionType) {
|
||||
case NEW -> {
|
||||
CompanyNewRequest companyNewRequest = (CompanyNewRequest) request.getRequestPayload();
|
||||
IValidator validator = companyNewRequestValidator.apply(companyNewRequest);
|
||||
Optional<EnumMessage> error = validator.tillFirstError();
|
||||
if (error.isPresent()) {
|
||||
throw new ValidationException(error.get());
|
||||
}
|
||||
// IValidator validator = companyNewRequestValidator.apply(companyNewRequest);
|
||||
// Optional<EnumMessage> error = validator.tillFirstError();
|
||||
// if (error.isPresent()) {
|
||||
// throw new ValidationException(error.get());
|
||||
// }
|
||||
create(companyNewRequest);
|
||||
}
|
||||
case UPDATE -> update((CompanyNewRequest) request.getRequestPayload(), true);
|
||||
|
|
@ -132,6 +132,12 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
|||
}
|
||||
|
||||
public synchronized Long create(CompanyNewRequest companyNewRequest) throws ValidationException {
|
||||
IValidator validator = companyNewRequestValidator.apply(companyNewRequest);
|
||||
Optional<EnumMessage> error = validator.tillFirstError();
|
||||
if (error.isPresent()) {
|
||||
throw new ValidationException(error.get());
|
||||
}
|
||||
|
||||
log.debug("creating new company");
|
||||
Instant now = Instant.now();
|
||||
Company company = new Company();
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import ru.spcex.clearing.validation.common.ValidationHelper;
|
|||
import ru.spcex.platform.enumeration.CompanySymbol;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
import ru.spcex.platform.utils.error.ValidationException;
|
||||
import ru.spcex.platform.utils.log.ExceptionUtils;
|
||||
import ru.spcex.platform.utils.text.TextUtil;
|
||||
|
|
@ -48,6 +49,7 @@ public class MultiCompanyService
|
|||
|
||||
protected UserRoleVerification userRoleVerification;
|
||||
// private final ValidationHelper validationHelper;
|
||||
protected IMessageResolver messageResolver;
|
||||
|
||||
final CompanyService companyService;
|
||||
final CompanyInfoService companyInfoService;
|
||||
|
|
@ -69,6 +71,7 @@ public class MultiCompanyService
|
|||
public MultiCompanyService(Consumer<String, Object> kafkaQueue, Producer<String, Object> kafkaProducer,
|
||||
ImdgProvider imdgProvider,
|
||||
RequestHelper requestHelper,
|
||||
IMessageResolver messageResolver,
|
||||
|
||||
CompanyService companyService,
|
||||
CompanyInfoService companyInfoService,
|
||||
|
|
@ -83,6 +86,7 @@ public class MultiCompanyService
|
|||
super(kafkaQueue, kafkaProducer);
|
||||
this.imdgProvider = imdgProvider;
|
||||
this.requestHelper = requestHelper.setLogger(log);
|
||||
this.messageResolver = messageResolver;
|
||||
this.userRoleVerification = userRoleVerification;
|
||||
this.companyService = companyService;
|
||||
this.companyInfoService = companyInfoService;
|
||||
|
|
@ -126,6 +130,10 @@ public class MultiCompanyService
|
|||
);
|
||||
companyId = getCompanyIdForCompanySymbols(req.getUuid(), req.getCompany());
|
||||
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());
|
||||
|
|
@ -197,7 +205,8 @@ public class MultiCompanyService
|
|||
}
|
||||
txOk = true;
|
||||
} catch (ValidationException vex) {
|
||||
log.error("For companyId={} error: {}", companyId, ExceptionUtils.getStackTrace(vex));
|
||||
log.error("For gateway request.id={}, companyId={} error validate: {}", baseRequest.getId(), companyId, messageResolver.resolve(vex.getEnumMsg()));
|
||||
log.debug("For companyId={} error validation: {}", companyId, ExceptionUtils.getStackTrace(vex));
|
||||
}
|
||||
}
|
||||
if (txOk) {
|
||||
|
|
@ -342,19 +351,50 @@ public class MultiCompanyService
|
|||
}
|
||||
}
|
||||
}
|
||||
if (companySymbol == null && StringUtils.isNotEmpty(cnr.getCompanySymbol())) {
|
||||
log.trace("Search company by companySymbol {}={}", cnr.getCompanySymbol(), cnr.getCompanySymbolValue());
|
||||
if (companySymbol == null && StringUtils.isNotEmpty(cnr.getCompanySymbolValue())) {
|
||||
for (String companySymbolType : Arrays.asList(
|
||||
cnr.getCompanySymbol(), CompanySymbol.INN.getKey(), CompanySymbol.CIO.getKey()
|
||||
)) {
|
||||
log.trace("Search company by companySymbol {}={}", companySymbolType, cnr.getCompanySymbolValue());
|
||||
Collection<CompanySymbols> companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
||||
Map.of(
|
||||
"companySymbol", companySymbolType,
|
||||
"companySymbolValue", cnr.getCompanySymbolValue()
|
||||
)
|
||||
);
|
||||
if (!companySymbolsFromImdg.isEmpty()) {
|
||||
companySymbol = companySymbolsFromImdg.iterator().next();
|
||||
if (companySymbolsFromImdg.size() > 1) {
|
||||
log.warn("For {} found > 1 company_symbols, use first (id = {})", companySymbolType, cnr.getCompanySymbolValue());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (companySymbol != null)
|
||||
return companySymbol.getCompanyId();
|
||||
else
|
||||
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", cnr.getCompanySymbol(),
|
||||
"companySymbolValue", cnr.getCompanySymbolValue()
|
||||
"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 = {})", cnr.getCompanySymbol(), cnr.getCompanySymbolValue());
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -1,14 +1,31 @@
|
|||
package ru.spcex.clearing.gatewayapi.service.adapter;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.spcex.clearing.gatewayapi.controller.inbound.request.company.*;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClientCodeNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.company.*;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.enumeration.CompanySymbol;
|
||||
import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class CompanyRequestAdapter {
|
||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||
protected final Imdg<Account> accountMap;
|
||||
|
||||
@Autowired
|
||||
public CompanyRequestAdapter(ImdgProvider imdgProvider) {
|
||||
accountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
}
|
||||
|
||||
public CompanyNewRequest toCompanyRequest(Company company) {
|
||||
CompanyNewRequest companyNewRequest = new CompanyNewRequest();
|
||||
|
|
@ -64,6 +81,30 @@ public class CompanyRequestAdapter {
|
|||
clientCodeNewRequest.setCode(client.getClientCode());
|
||||
clientCodeNewRequest.setMoneyAccountId(client.getMoneyAccountId());
|
||||
clientCodeNewRequest.setDepoAccountId(client.getDepoAccountId());
|
||||
if (client.getMoneyAccount() != null) {
|
||||
Account mAccount = accountMap.getSingleObjectByFieldValues(Map.of(
|
||||
// "accountType", AccountType.Clrn.getKey(), or "accountType", AccountType.Info.getKey(),
|
||||
"account", client.getDepoAccount()
|
||||
));
|
||||
if (mAccount == null) {
|
||||
log.warn("Money account \"{}\" not found", client.getMoneyAccount());
|
||||
} else {
|
||||
log.warn("Money account \"{}\" found with id={}", client.getMoneyAccount(), mAccount.getId());
|
||||
client.setDepoAccountId(mAccount.getId());
|
||||
}
|
||||
}
|
||||
if (client.getDepoAccount() != null) {
|
||||
Account dAccount = accountMap.getSingleObjectByFieldValues(Map.of(
|
||||
"accountType", AccountType.Depo.getKey(),
|
||||
"account", client.getDepoAccount()
|
||||
));
|
||||
if (dAccount == null) {
|
||||
log.warn("Depo account \"{}\" not found", client.getDepoAccount());
|
||||
} else {
|
||||
log.warn("Depo account \"{}\" found with id={}", client.getDepoAccount(), dAccount.getId());
|
||||
client.setDepoAccountId(dAccount.getId());
|
||||
}
|
||||
}
|
||||
return clientCodeNewRequest;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue