This commit is contained in:
parent
b81559002f
commit
142c534aa2
4 changed files with 133 additions and 229 deletions
|
|
@ -13,6 +13,7 @@ import ru.clearing.classes.statics.data.company.CompanySymbols;
|
||||||
import ru.clearing.classes.statics.data.profile.CompanyInfo;
|
import ru.clearing.classes.statics.data.profile.CompanyInfo;
|
||||||
import ru.spcex.clearing.company.error.CompanyErrors;
|
import ru.spcex.clearing.company.error.CompanyErrors;
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.ActionType;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountTerminationRequest;
|
import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountTerminationRequest;
|
||||||
|
|
@ -20,6 +21,7 @@ import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteReques
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.company.CompanyNewRequest;
|
import ru.spcex.clearing.platform.messaging.domain.cud.company.CompanyNewRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||||
|
import ru.spcex.clearing.platform.messaging.service.Status;
|
||||||
import ru.spcex.clearing.util.security.UserRoleVerification;
|
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||||
import ru.spcex.clearing.util.services.RequestHelper;
|
import ru.spcex.clearing.util.services.RequestHelper;
|
||||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||||
|
|
@ -37,6 +39,7 @@ import ru.spcex.platform.utils.validation.IValidator;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|
@ -63,11 +66,11 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
||||||
ValidationHelper validationHelper,
|
ValidationHelper validationHelper,
|
||||||
UserRoleVerification userRoleVerification,
|
UserRoleVerification userRoleVerification,
|
||||||
@Qualifier("companyNewRequestValidator")
|
@Qualifier("companyNewRequestValidator")
|
||||||
Function<CompanyNewRequest, IValidator> companyNewRequestValidator,
|
Function<CompanyNewRequest, IValidator> companyNewRequestValidator,
|
||||||
@Qualifier("companyUpdateRequestValidator")
|
@Qualifier("companyUpdateRequestValidator")
|
||||||
Function<CompanyNewRequest, IValidator> companyUpdateRequestValidator,
|
Function<CompanyNewRequest, IValidator> companyUpdateRequestValidator,
|
||||||
@Qualifier("CompanyDeleteRequestValidator")
|
@Qualifier("CompanyDeleteRequestValidator")
|
||||||
Function<CommonDeleteRequest, IValidator> companyDeleteRequestValidator,
|
Function<CommonDeleteRequest, IValidator> companyDeleteRequestValidator,
|
||||||
CompanySymbolService companySymbolService,
|
CompanySymbolService companySymbolService,
|
||||||
AccountNotificationHelper accountNotification,
|
AccountNotificationHelper accountNotification,
|
||||||
RelationService relationService) {
|
RelationService relationService) {
|
||||||
|
|
@ -98,10 +101,10 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
||||||
.setFunction(request -> requestHelper.requestFunction(this::blockCompanyAfterDocument, request))
|
.setFunction(request -> requestHelper.requestFunction(this::blockCompanyAfterDocument, request))
|
||||||
.forDestination(Consts.DESTINATION_COMPANY_BLOCK, callbacks::put);
|
.forDestination(Consts.DESTINATION_COMPANY_BLOCK, callbacks::put);
|
||||||
callback(CompanyNewRequest.class)
|
callback(CompanyNewRequest.class)
|
||||||
.setFunction(request -> requestHelper.requestFunction(this::createCompany, request))
|
.setFunction(request -> requestHelper.requestFunction(this::processBaseRequest, request))
|
||||||
.forDestination(Consts.DESTINATION_COMPANY_NEW, callbacks::put);
|
.forDestination(Consts.DESTINATION_COMPANY_NEW, callbacks::put);
|
||||||
callback(CompanyNewRequest.class)
|
callback(CompanyNewRequest.class)
|
||||||
.setFunction(request -> requestHelper.requestFunction(this::updateCompany, request))
|
.setFunction(request -> requestHelper.requestFunction(this::processBaseRequest, request))
|
||||||
.forDestination(Consts.DESTINATION_COMPANY_UPDATE, callbacks::put);
|
.forDestination(Consts.DESTINATION_COMPANY_UPDATE, callbacks::put);
|
||||||
callback(AccountTerminationRequest.class)
|
callback(AccountTerminationRequest.class)
|
||||||
.setFunction(request -> requestHelper.requestFunction(this::finishCompanyTermination, request))
|
.setFunction(request -> requestHelper.requestFunction(this::finishCompanyTermination, request))
|
||||||
|
|
@ -109,41 +112,58 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized RequestInfoUpdate createCompany(BaseRequest<CompanyNewRequest> companyNewRequestBaseRequest) throws ValidationException {
|
private RequestInfoUpdate processBaseRequest(BaseRequest<?> request) {
|
||||||
CompanyNewRequest req = companyNewRequestBaseRequest.getRequestPayload();
|
RequestInfoUpdate requestInfoUpdate = null;
|
||||||
log.debug("company-new request received, BaseRequest.id = {}", companyNewRequestBaseRequest.getId());
|
// Валидация
|
||||||
{ // Валидация
|
requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(request);
|
||||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(companyNewRequestBaseRequest);
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
|
||||||
|
|
||||||
requestInfoUpdate = validationHelper.validateTillFirstError(companyNewRequestBaseRequest, companyNewRequestValidator);
|
try {
|
||||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
ActionType actionType = request.getActionType();
|
||||||
|
switch (actionType) {
|
||||||
|
case NEW -> create((CompanyNewRequest) request.getRequestPayload());
|
||||||
|
case UPDATE -> update((CompanyNewRequest) request.getRequestPayload());
|
||||||
|
}
|
||||||
|
} catch (ValidationException e) {
|
||||||
|
requestInfoUpdate = new RequestInfoUpdate(request.getId(), Status.Error, e.getMessage());
|
||||||
}
|
}
|
||||||
|
return requestInfoUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized Long create(CompanyNewRequest companyNewRequest) throws ValidationException {
|
||||||
|
log.debug("creating new company");
|
||||||
|
IValidator validator = companyNewRequestValidator.apply(companyNewRequest);
|
||||||
|
Optional<EnumMessage> error = validator.tillFirstError();
|
||||||
|
if (error.isPresent()) {
|
||||||
|
throw new ValidationException(error.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
Instant now = Instant.now();
|
||||||
Company company = new Company();
|
Company company = new Company();
|
||||||
company.setId(idSequence.nextId());
|
company.setId(idSequence.nextId());
|
||||||
Instant now = Instant.now();
|
|
||||||
company.setCreated(now);
|
company.setCreated(now);
|
||||||
company.setUpdated(now);
|
company.setUpdated(now);
|
||||||
|
company.setShortName(companyNewRequest.getShortName());
|
||||||
company.setShortName(req.getShortName());
|
company.setFullName(companyNewRequest.getFullName());
|
||||||
company.setFullName(req.getFullName());
|
company.setTradingCode(companyNewRequest.getTradingCode());
|
||||||
|
company.setClearingCode(companyNewRequest.getClearingCode());
|
||||||
|
company.setRegistrationCode(companyNewRequest.getRegistrationCode());
|
||||||
|
company.setWorkflowStatus(companyNewRequest.getWorkflowStatus());
|
||||||
|
fillNewCompanyInfo(company, companyNewRequest);
|
||||||
|
|
||||||
ImdgTransaction transaction = imdgProvider.newTransaction();
|
ImdgTransaction transaction = imdgProvider.newTransaction();
|
||||||
transaction.beginTransaction();
|
transaction.beginTransaction();
|
||||||
boolean txOk = false;
|
boolean txOk = false;
|
||||||
try {
|
try {
|
||||||
if (req.getCompanySymbol() != null) {
|
if (companyNewRequest.getCompanySymbol() != null) {
|
||||||
CompanySymbols newSymbol = companySymbolService.createCompanySymbol(transaction, company.getId(), req.getCompanySymbol(), req.getCompanySymbolValue());
|
CompanySymbols companySymbols = companySymbolService.create(company.getId(), companyNewRequest.getCompanySymbol(),
|
||||||
updateCompanyBySymbol(company, newSymbol, false);
|
companyNewRequest.getCompanySymbolValue());
|
||||||
|
log.debug("Creating companySymbols with id: {} by company.id: {} done", companySymbols.getId(), company.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
company.setWorkflowStatus(req.getWorkflowStatus());
|
|
||||||
fillNewCompanyInfo(company, req);
|
|
||||||
|
|
||||||
Imdg<Company> companyMap = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
Imdg<Company> companyMap = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
companyMap.insert(company);
|
companyMap.insert(company);
|
||||||
log.debug("company-new request processed, BaseRequest.id = {}, company.id={}",
|
log.debug("company-new request processed, BaseRequest.id = {}, company.id={}",
|
||||||
companyNewRequestBaseRequest.getId(), company.getId());
|
companyNewRequest.getId(), company.getId());
|
||||||
txOk = true;
|
txOk = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (txOk)
|
if (txOk)
|
||||||
|
|
@ -152,48 +172,25 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
||||||
transaction.rollbackTransaction();
|
transaction.rollbackTransaction();
|
||||||
}
|
}
|
||||||
accountNotification.makeInfoAccount(company.getId());
|
accountNotification.makeInfoAccount(company.getId());
|
||||||
return null;
|
return company.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void fillNewCompanyInfo(Company company, CompanyNewRequest req) {
|
public synchronized void update(CompanyNewRequest updateRequest) throws ValidationException {
|
||||||
if (company.getProfile() == null)
|
IValidator validator = companyUpdateRequestValidator.apply(updateRequest);
|
||||||
company.setProfile(new CompanyInfo());
|
Optional<EnumMessage> error = validator.tillFirstError();
|
||||||
CompanyInfo ci = company.getProfile();
|
if (error.isPresent()) {
|
||||||
ci.setId(company.getId());
|
throw new ValidationException(error.get());
|
||||||
ci.setCompanyId(company.getId());
|
|
||||||
//todo раскоментировать, когда в реквест добавят новые поля:
|
|
||||||
// req.getWorkflowStatus()
|
|
||||||
//ci.setCorporationSoleType(req.getCorporationSoleType());
|
|
||||||
// ci.setCountryCode(req.getCountryCode());
|
|
||||||
// ci.setDescription(req.getDescription());
|
|
||||||
// ci.setProfessionalSign(req.getProfessionalSign());
|
|
||||||
// ci.setLegalKind(req.getLegalKind());
|
|
||||||
// ci.setOrganizationType(req.getOrganizationType());
|
|
||||||
// ci.setResidence(req.getResidence());
|
|
||||||
// ci.setShortNameEng(req.getShortNameEng());
|
|
||||||
// ci.setFullNameEng(req.getFullNameEng());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private synchronized RequestInfoUpdate updateCompany(BaseRequest<CompanyNewRequest> companyUpdateRequestBaseRequest) throws ValidationException {
|
|
||||||
CompanyNewRequest updateRequest = companyUpdateRequestBaseRequest.getRequestPayload();
|
|
||||||
{ // Валидация,
|
|
||||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(companyUpdateRequestBaseRequest);
|
|
||||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
|
||||||
|
|
||||||
requestInfoUpdate = validationHelper.validateTillFirstError(companyUpdateRequestBaseRequest, companyUpdateRequestValidator);
|
|
||||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImdgTransaction transaction = imdgProvider.newTransaction();
|
ImdgTransaction transaction = imdgProvider.newTransaction();
|
||||||
transaction.beginTransaction();
|
transaction.beginTransaction();
|
||||||
boolean txOk = false;
|
boolean txOk = false;
|
||||||
try {
|
try {
|
||||||
Imdg<Company> companyMap = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
Imdg<Company> companyMap = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
|
|
||||||
Company company = companyMap.getSingleObjectByID(updateRequest.getId());
|
Company company = companyMap.getSingleObjectByID(updateRequest.getId());
|
||||||
if (company == null) {
|
if (company == null) {
|
||||||
log.trace("Company {} not found", updateRequest.getId());
|
log.trace("Company {} not found", updateRequest.getId());
|
||||||
return requestHelper.makeErrorResponse(companyUpdateRequestBaseRequest, CompanyErrors.CompanyNotFound, updateRequest.getId());
|
throw new ValidationException(new EnumMessage(CompanyErrors.CompanyNotFound));
|
||||||
}
|
}
|
||||||
// if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) {
|
// if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) {
|
||||||
// log.trace("Company {} not active: {}", company.getId(), company.getWorkflowStatus());
|
// log.trace("Company {} not active: {}", company.getId(), company.getWorkflowStatus());
|
||||||
|
|
@ -207,8 +204,6 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
||||||
if (updateRequest.getCompanySymbol() != null || updateRequest.getCompanySymbolValue() != null) {
|
if (updateRequest.getCompanySymbol() != null || updateRequest.getCompanySymbolValue() != null) {
|
||||||
log.trace("Request field CompanySymbol, CompanySymbolValue ignore for update company request.");
|
log.trace("Request field CompanySymbol, CompanySymbolValue ignore for update company request.");
|
||||||
}
|
}
|
||||||
// CompanySymbols не обновляем
|
|
||||||
|
|
||||||
|
|
||||||
String prevStatus = company.getWorkflowStatus();
|
String prevStatus = company.getWorkflowStatus();
|
||||||
if (updateRequest.getWorkflowStatus() != null) {
|
if (updateRequest.getWorkflowStatus() != null) {
|
||||||
|
|
@ -229,7 +224,6 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
||||||
else
|
else
|
||||||
transaction.rollbackTransaction();
|
transaction.rollbackTransaction();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateCompanyBySymbol(Company company, CompanySymbols companySymbol, boolean shouldBeDeleted) {
|
protected void updateCompanyBySymbol(Company company, CompanySymbols companySymbol, boolean shouldBeDeleted) {
|
||||||
|
|
@ -374,112 +368,6 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized Company createOrUpdateCompany(BaseRequest<CompanyNewRequest> companyNewRequestBaseRequest, Long existCompanyId) throws ValidationException {
|
|
||||||
CompanyNewRequest req = companyNewRequestBaseRequest.getRequestPayload();
|
|
||||||
log.debug("company new or update, request {}, existCOmpanyId={}", companyNewRequestBaseRequest.getId(), existCompanyId);
|
|
||||||
{ // Валидация
|
|
||||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(companyNewRequestBaseRequest);
|
|
||||||
if (requestInfoUpdate != null)
|
|
||||||
throw new ValidationException(CompanyErrors.GeneralError, requestInfoUpdate.getMessage());
|
|
||||||
// requestInfoUpdate = validationHelper.validateTillFirstError(companyNewRequestBaseRequest, companyNewRequestValidator);
|
|
||||||
// if (requestInfoUpdate != null) throw new ValidationException(CompanyErrors.GeneralError, requestInfoUpdate.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
Company company = null;
|
|
||||||
if (existCompanyId != null) {
|
|
||||||
company = companyIMap.getSingleObjectByID(existCompanyId);
|
|
||||||
if (company == null) {
|
|
||||||
throw new ValidationException(CompanyErrors.CompanyNotFound, String.valueOf(existCompanyId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (company == null) {
|
|
||||||
// #createCompany
|
|
||||||
company = new Company();
|
|
||||||
company.setId(idSequence.nextId());
|
|
||||||
Instant now = Instant.now();
|
|
||||||
company.setCreated(now);
|
|
||||||
company.setUpdated(now);
|
|
||||||
log.debug("Create new company {}", company.getId());
|
|
||||||
|
|
||||||
company.setShortName(req.getShortName());
|
|
||||||
company.setFullName(req.getFullName());
|
|
||||||
company.setTradingCode(req.getTradingCode());
|
|
||||||
company.setClearingCode(req.getClearingCode());
|
|
||||||
company.setRegistrationCode(req.getRegistrationCode());
|
|
||||||
// company.setInitiatorCode(req.getInitiatorCode());
|
|
||||||
|
|
||||||
ImdgTransaction transaction = imdgProvider.newTransaction();
|
|
||||||
transaction.beginTransaction();
|
|
||||||
boolean txOk = false;
|
|
||||||
try {
|
|
||||||
if (req.getCompanySymbol() != null) {
|
|
||||||
CompanySymbols newSymbol = companySymbolService.createCompanySymbol(transaction, company.getId(), req.getCompanySymbol(), req.getCompanySymbolValue());
|
|
||||||
updateCompanyBySymbol(company, newSymbol, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
company.setWorkflowStatus(req.getWorkflowStatus());
|
|
||||||
fillNewCompanyInfo(company, req);
|
|
||||||
|
|
||||||
Imdg<Company> companyMap = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
|
||||||
companyMap.insert(company);
|
|
||||||
log.debug("company-new request processed, BaseRequest.id = {}, company.id={}",
|
|
||||||
companyNewRequestBaseRequest.getId(), company.getId());
|
|
||||||
txOk = true;
|
|
||||||
} finally {
|
|
||||||
if (txOk)
|
|
||||||
transaction.commitTransaction();
|
|
||||||
else
|
|
||||||
transaction.rollbackTransaction();
|
|
||||||
}
|
|
||||||
accountNotification.makeInfoAccount(company.getId());
|
|
||||||
} else {
|
|
||||||
log.debug("Update exist company {}", company.getId());
|
|
||||||
company.setUpdated(Instant.now());
|
|
||||||
// #updateCompany
|
|
||||||
|
|
||||||
company.setUpdated(Instant.now());
|
|
||||||
company.setShortName(req.getShortName());
|
|
||||||
company.setFullName(req.getFullName());
|
|
||||||
company.setTradingCode(req.getTradingCode());
|
|
||||||
company.setClearingCode(req.getClearingCode());
|
|
||||||
company.setRegistrationCode(req.getRegistrationCode());
|
|
||||||
|
|
||||||
if (req.getCompanySymbol() != null || req.getCompanySymbolValue() != null) {
|
|
||||||
log.trace("Request field CompanySymbol, CompanySymbolValue ignore for update company request.");
|
|
||||||
}
|
|
||||||
// CompanySymbols не обновляем
|
|
||||||
ImdgTransaction transaction = imdgProvider.newTransaction();
|
|
||||||
transaction.beginTransaction();
|
|
||||||
boolean txOk = false;
|
|
||||||
try {
|
|
||||||
String prevStatus = company.getWorkflowStatus();
|
|
||||||
if (req.getWorkflowStatus() != null) {
|
|
||||||
company.setWorkflowStatus(req.getWorkflowStatus());
|
|
||||||
if (!Objects.equals(prevStatus, company.getWorkflowStatus())) {
|
|
||||||
relationService.onChangeWorkflowStatus(transaction, company, prevStatus, company.getWorkflowStatus());
|
|
||||||
} else {
|
|
||||||
log.trace("Status was not changed");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.trace("Null new WorkflowStatus");
|
|
||||||
}
|
|
||||||
Imdg<Company> companyMap = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
|
||||||
companyMap.update(company);
|
|
||||||
txOk = true;
|
|
||||||
} finally {
|
|
||||||
if (txOk)
|
|
||||||
transaction.commitTransaction();
|
|
||||||
else
|
|
||||||
transaction.rollbackTransaction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return company;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Блокировка компании после блокировки счетов
|
* Блокировка компании после блокировки счетов
|
||||||
*
|
*
|
||||||
|
|
@ -520,4 +408,12 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fillNewCompanyInfo(Company company, CompanyNewRequest req) {
|
||||||
|
if (company.getProfile() == null)
|
||||||
|
company.setProfile(new CompanyInfo());
|
||||||
|
CompanyInfo ci = company.getProfile();
|
||||||
|
ci.setId(company.getId());
|
||||||
|
ci.setCompanyId(company.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.clearing.classes.statics.data.company.Company;
|
||||||
import ru.clearing.classes.statics.data.company.CompanySymbols;
|
import ru.clearing.classes.statics.data.company.CompanySymbols;
|
||||||
import ru.spcex.clearing.company.error.CompanyErrors;
|
import ru.spcex.clearing.company.error.CompanyErrors;
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
|
@ -19,6 +20,7 @@ import ru.spcex.clearing.platform.messaging.domain.cud.company.CompanySymbolNewR
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.company.CompanySymbolUpdateRequest;
|
import ru.spcex.clearing.platform.messaging.domain.cud.company.CompanySymbolUpdateRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||||
|
import ru.spcex.clearing.platform.messaging.service.Status;
|
||||||
import ru.spcex.clearing.util.security.UserRoleVerification;
|
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||||
import ru.spcex.clearing.util.services.RequestHelper;
|
import ru.spcex.clearing.util.services.RequestHelper;
|
||||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||||
|
|
@ -29,9 +31,11 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
||||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||||
import ru.spcex.platform.utils.error.ClearingBaseException;
|
import ru.spcex.platform.utils.error.ClearingBaseException;
|
||||||
|
import ru.spcex.platform.utils.error.ValidationException;
|
||||||
import ru.spcex.platform.utils.validation.IValidator;
|
import ru.spcex.platform.utils.validation.IValidator;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|
@ -54,11 +58,11 @@ public class CompanySymbolService extends QueueConsumer implements InitializingB
|
||||||
ValidationHelper validationHelper,
|
ValidationHelper validationHelper,
|
||||||
UserRoleVerification userRoleVerification,
|
UserRoleVerification userRoleVerification,
|
||||||
@Qualifier("companySymbolNewRequestValidator")
|
@Qualifier("companySymbolNewRequestValidator")
|
||||||
Function<CompanySymbolNewRequest, IValidator> companySymbolNewRequestValidator,
|
Function<CompanySymbolNewRequest, IValidator> companySymbolNewRequestValidator,
|
||||||
@Qualifier("companySymbolDeleteRequestValidator")
|
@Qualifier("companySymbolDeleteRequestValidator")
|
||||||
Function<CommonDeleteRequest, IValidator> companySymbolDeleteRequestValidator,
|
Function<CommonDeleteRequest, IValidator> companySymbolDeleteRequestValidator,
|
||||||
@Qualifier("companySymbolUpdateRequestValidator")
|
@Qualifier("companySymbolUpdateRequestValidator")
|
||||||
Function<CompanySymbolUpdateRequest, IValidator> companySymbolUpdateRequestValidator
|
Function<CompanySymbolUpdateRequest, IValidator> companySymbolUpdateRequestValidator
|
||||||
) {
|
) {
|
||||||
super(kafkaQueue, kafkaProducer);
|
super(kafkaQueue, kafkaProducer);
|
||||||
this.imdgProvider = imdgProvider;
|
this.imdgProvider = imdgProvider;
|
||||||
|
|
@ -76,7 +80,7 @@ public class CompanySymbolService extends QueueConsumer implements InitializingB
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
callback(CompanySymbolNewRequest.class)
|
callback(CompanySymbolNewRequest.class)
|
||||||
.setFunction(this::companySymbolNew)
|
.setFunction(this::processBaseRequest)
|
||||||
.forDestination(Consts.DESTINATION_COMPANY_SYMBOL_NEW, callbacks::put);
|
.forDestination(Consts.DESTINATION_COMPANY_SYMBOL_NEW, callbacks::put);
|
||||||
callback(CompanySymbolUpdateRequest.class)
|
callback(CompanySymbolUpdateRequest.class)
|
||||||
.setFunction(this::companySymbolUpdate)
|
.setFunction(this::companySymbolUpdate)
|
||||||
|
|
@ -87,40 +91,60 @@ public class CompanySymbolService extends QueueConsumer implements InitializingB
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RequestInfoUpdate processBaseRequest(BaseRequest<?> request) {
|
||||||
|
RequestInfoUpdate requestInfoUpdate = null;
|
||||||
|
// Валидация
|
||||||
|
requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(request);
|
||||||
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
|
||||||
|
try {
|
||||||
|
create((CompanySymbolNewRequest) request.getRequestPayload());
|
||||||
|
} catch (ValidationException e) {
|
||||||
|
requestInfoUpdate = new RequestInfoUpdate(request.getId(), Status.Error, e.getMessage());
|
||||||
|
}
|
||||||
|
return requestInfoUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
public void setCompanyService(CompanyService companyService) {
|
public void setCompanyService(CompanyService companyService) {
|
||||||
this.companyService = companyService;
|
this.companyService = companyService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public RequestInfoUpdate companySymbolNew(BaseRequest<CompanySymbolNewRequest> symbolRequest) {
|
public Long create(CompanySymbolNewRequest symbolRequest) throws ValidationException {
|
||||||
CompanySymbolNewRequest req = symbolRequest.getRequestPayload();
|
log.debug("CompanySymbolNewRequest received");
|
||||||
log.debug("CompanySymbolNewRequest received, id={}", symbolRequest.getId());
|
|
||||||
{ // validate
|
{ // validate
|
||||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(symbolRequest);
|
IValidator validator = companySymbolNewRequestValidator.apply(symbolRequest);
|
||||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
Optional<EnumMessage> error = validator.tillFirstError();
|
||||||
|
if (error.isPresent()) {
|
||||||
requestInfoUpdate = validationHelper.validateTillFirstError(symbolRequest, companySymbolNewRequestValidator);
|
throw new ValidationException(error.get());
|
||||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CompanySymbols companySymbols = create(symbolRequest.companyId, symbolRequest.getCompanySymbol(),
|
||||||
|
symbolRequest.getCompanySymbolValue());
|
||||||
|
log.debug("successfully processed, id {}", companySymbols.getId());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
CompanySymbols companySymbols = new CompanySymbols();
|
public CompanySymbols create(Long companyId, String companySymbol, String companySymbolValue) {
|
||||||
companySymbols.setId(idSequence.nextId());
|
Objects.requireNonNull(companyId);
|
||||||
companySymbols.setCompanyId(req.getCompanyId());
|
CompanySymbols newSymbol = new CompanySymbols();
|
||||||
companySymbols.setCompanySymbol(req.getCompanySymbol());
|
newSymbol.setId(idSequence.nextId());
|
||||||
companySymbols.setCompanySymbolValue(req.getCompanySymbolValue());
|
newSymbol.setCompanyId(companyId);
|
||||||
|
newSymbol.setCompanySymbol(companySymbol);
|
||||||
|
newSymbol.setCompanySymbolValue(companySymbolValue);
|
||||||
|
log.debug("Created new companySymbols.id={} for company {}", newSymbol.getId(), companyId);
|
||||||
ImdgTransaction transaction = imdgProvider.newTransaction();
|
ImdgTransaction transaction = imdgProvider.newTransaction();
|
||||||
transaction.beginTransaction();
|
transaction.beginTransaction();
|
||||||
boolean txOk = false;
|
boolean txOk = false;
|
||||||
try {
|
try {
|
||||||
Imdg<CompanySymbols> companySymbolsTMap = transaction.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
Imdg<CompanySymbols> companySymbolsTMap = transaction.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||||
companySymbolsTMap.update(companySymbols);
|
companySymbolsTMap.update(newSymbol);
|
||||||
try {
|
|
||||||
companyService.updateCompanyBySymbol(transaction, companySymbols, false);
|
Imdg<Company> companyMap = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
} catch (ClearingBaseException e) {
|
Company company = companyMap.getSingleObjectByID(newSymbol.getCompanyId());
|
||||||
return requestHelper.makeErrorResponse(symbolRequest, e.getEnumMsg());
|
companyService.updateCompanyBySymbol(company, newSymbol, false);
|
||||||
}
|
companyMap.update(company);
|
||||||
txOk = true;
|
txOk = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (txOk)
|
if (txOk)
|
||||||
|
|
@ -128,9 +152,7 @@ public class CompanySymbolService extends QueueConsumer implements InitializingB
|
||||||
else
|
else
|
||||||
transaction.rollbackTransaction();
|
transaction.rollbackTransaction();
|
||||||
}
|
}
|
||||||
|
return newSymbol;
|
||||||
log.debug("successfully processed, id {}", companySymbols.getId());
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RequestInfoUpdate companySymbolUpdate(BaseRequest<CompanySymbolUpdateRequest> symbolRequest) {
|
public RequestInfoUpdate companySymbolUpdate(BaseRequest<CompanySymbolUpdateRequest> symbolRequest) {
|
||||||
|
|
@ -210,22 +232,4 @@ public class CompanySymbolService extends QueueConsumer implements InitializingB
|
||||||
log.debug("successfully processed, id {}", companySymbols.getId());
|
log.debug("successfully processed, id {}", companySymbols.getId());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompanySymbols createCompanySymbol(ImdgTransaction transaction, Long companyId, String companySymbol, String companySymbolValue) {
|
|
||||||
Objects.requireNonNull(companyId);
|
|
||||||
CompanySymbols newSymbol = new CompanySymbols();
|
|
||||||
newSymbol.setId(idSequence.nextId());
|
|
||||||
newSymbol.setCompanyId(companyId);
|
|
||||||
newSymbol.setCompanySymbol(companySymbol);
|
|
||||||
newSymbol.setCompanySymbolValue(companySymbolValue);
|
|
||||||
log.debug("Created new companySymbols.id={} for company {}", newSymbol.getId(), companyId);
|
|
||||||
if (transaction == null) {
|
|
||||||
Imdg<CompanySymbols> companySymbolsTMap = transaction.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
|
||||||
companySymbolsTMap.insert(newSymbol);
|
|
||||||
} else {
|
|
||||||
Imdg<CompanySymbols> tMap = transaction.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
|
||||||
tMap.insert(newSymbol);
|
|
||||||
}
|
|
||||||
return newSymbol;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -117,12 +117,14 @@ public class MultiCompanyService
|
||||||
companyId = getCompanyIdForCompanySymbols(req.getUuid(), req.getCompany());
|
companyId = getCompanyIdForCompanySymbols(req.getUuid(), req.getCompany());
|
||||||
log.debug("For request {} (uuid {}) company {}.", baseRequest.getId(), req.getUuid(), companyId == null ? "not found" : ("found, id=" + companyId));
|
log.debug("For request {} (uuid {}) company {}.", baseRequest.getId(), req.getUuid(), companyId == null ? "not found" : ("found, id=" + companyId));
|
||||||
|
|
||||||
RequestInfoUpdate replyI;
|
if (companyId == null) {
|
||||||
Company company = companyService.createOrUpdateCompany(wrapRequest(baseRequest, req.getCompany(), null), companyId);
|
companyId = companyService.create(req.getCompany());
|
||||||
companyId = company.getId();
|
log.debug("The companyId={}", companyId);
|
||||||
log.debug("The companyId={}", companyId);
|
} else {
|
||||||
fillCompanyId(req, companyId);
|
companyService.update(req.getCompany());
|
||||||
|
}
|
||||||
|
|
||||||
|
RequestInfoUpdate replyI;
|
||||||
if (req.getCompanyInfo() != null) {
|
if (req.getCompanyInfo() != null) {
|
||||||
log.trace("For company {} do update CompanyInfo", companyId);
|
log.trace("For company {} do update CompanyInfo", companyId);
|
||||||
replyI = companyInfoService.companyInfoUpdate(wrapRequest(baseRequest, req.getCompanyInfo(), null));
|
replyI = companyInfoService.companyInfoUpdate(wrapRequest(baseRequest, req.getCompanyInfo(), null));
|
||||||
|
|
@ -141,19 +143,21 @@ public class MultiCompanyService
|
||||||
validateReply(companyId, "profileDocumentUpdate", replyI);
|
validateReply(companyId, "profileDocumentUpdate", replyI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (CompanySymbolNewRequest partRequest : req.getCompanySymbols()) {
|
|
||||||
CompanySymbols existSymbol = findCompanySymbols(partRequest);
|
//todo по идее эта логика выполнена в companyService.create(req.getCompany())
|
||||||
if (existSymbol == null) {
|
// for (CompanySymbolNewRequest partRequest : req.getCompanySymbols()) {
|
||||||
log.trace("For company[{}] do new companySymbol", companyId);
|
// CompanySymbols existSymbol = findCompanySymbols(partRequest);
|
||||||
replyI = companySymbolService.companySymbolNew(wrapRequest(baseRequest, partRequest, ActionType.NEW));
|
// if (existSymbol == null) {
|
||||||
validateReply(companyId, "companySymbolNew", replyI);
|
// log.trace("For company[{}] do new companySymbol", companyId);
|
||||||
} else {
|
// Long id = companySymbolService.create(partRequest);
|
||||||
log.trace("For company[{}] do update companySymbol[{}]", companyId, existSymbol.getId());
|
// validateReply(companyId, "companySymbolNew", replyI);
|
||||||
CompanySymbolUpdateRequest partUpdateRequest = createUpdateRequest(existSymbol, partRequest);
|
// } else {
|
||||||
replyI = companySymbolService.companySymbolUpdate(wrapRequest(baseRequest, partUpdateRequest, ActionType.UPDATE));
|
// log.trace("For company[{}] do update companySymbol[{}]", companyId, existSymbol.getId());
|
||||||
validateReply(companyId, "companySymbolUpdate", replyI);
|
// CompanySymbolUpdateRequest partUpdateRequest = createUpdateRequest(existSymbol, partRequest);
|
||||||
}
|
// replyI = companySymbolService.companySymbolUpdate(wrapRequest(baseRequest, partUpdateRequest, ActionType.UPDATE));
|
||||||
}
|
// validateReply(companyId, "companySymbolUpdate", replyI);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
for (ContactNewRequest partRequest : req.getContacts()) {
|
for (ContactNewRequest partRequest : req.getContacts()) {
|
||||||
Contact existContact = findContact(partRequest);
|
Contact existContact = findContact(partRequest);
|
||||||
if (existContact == null) {
|
if (existContact == null) {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ public class RequestInfoUpdate {
|
||||||
|
|
||||||
public RequestInfoUpdate() {}
|
public RequestInfoUpdate() {}
|
||||||
|
|
||||||
public RequestInfoUpdate(Long id, Status status, Long errorId, String message) {
|
public RequestInfoUpdate(Long id, Status status, String message) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue