Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
8ce4158ce7
3 changed files with 74 additions and 11 deletions
|
|
@ -79,6 +79,7 @@ public class AccountNotificationHelper {
|
||||||
Long reqId = kafkaSender.sendRequestToQueue(Consts.ACCOUNT_TERMINATION, createAccountsRequest(companyId, account));
|
Long reqId = kafkaSender.sendRequestToQueue(Consts.ACCOUNT_TERMINATION, createAccountsRequest(companyId, account));
|
||||||
log.debug("For account[{}] send termination by document request id={}", account.getId(), reqId);
|
log.debug("For account[{}] send termination by document request id={}", account.getId(), reqId);
|
||||||
}
|
}
|
||||||
|
// ответ должен послаться в DESTINATION_COMPANY_BLOCK = "company-block";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -46,6 +46,7 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
||||||
private final RequestHelper requestHelper;
|
private final RequestHelper requestHelper;
|
||||||
private final ImdgProvider imdgProvider;
|
private final ImdgProvider imdgProvider;
|
||||||
private final ImdgId idSequence;
|
private final ImdgId idSequence;
|
||||||
|
private final Imdg<Company> companyIMap;
|
||||||
protected UserRoleVerification userRoleVerification;
|
protected UserRoleVerification userRoleVerification;
|
||||||
|
|
||||||
private ValidationHelper validationHelper;
|
private ValidationHelper validationHelper;
|
||||||
|
|
@ -89,6 +90,8 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
||||||
companySymbolService.setCompanyService(this);
|
companySymbolService.setCompanyService(this);
|
||||||
this.accountNotification = accountNotification;
|
this.accountNotification = accountNotification;
|
||||||
this.relationHelper = relationHelper;
|
this.relationHelper = relationHelper;
|
||||||
|
|
||||||
|
companyIMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -96,6 +99,9 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
||||||
callback(CommonDeleteRequest.class)
|
callback(CommonDeleteRequest.class)
|
||||||
.setConsumer(request -> requestHelper.requestFunction(this::deleteCompany, request))
|
.setConsumer(request -> requestHelper.requestFunction(this::deleteCompany, request))
|
||||||
.forDestination(Consts.DESTINATION_COMPANY_DELETE, callbacks::put);
|
.forDestination(Consts.DESTINATION_COMPANY_DELETE, callbacks::put);
|
||||||
|
callback(CommonDeleteRequest.class)
|
||||||
|
.setConsumer(request -> requestHelper.requestFunction(this::blockCompanyAfterDocument, request))
|
||||||
|
.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::createCompany, request))
|
||||||
.forDestination(Consts.DESTINATION_COMPANY_NEW, callbacks::put);
|
.forDestination(Consts.DESTINATION_COMPANY_NEW, callbacks::put);
|
||||||
|
|
@ -294,4 +300,57 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Блокировка компании по документу о расторжении
|
||||||
|
*
|
||||||
|
* @param companyBlockRequestBaseRequest
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private synchronized RequestInfoUpdate blockCompanyAfterDocument(BaseRequest<CommonDeleteRequest> companyBlockRequestBaseRequest) throws ValidationException {
|
||||||
|
CommonDeleteRequest request = companyBlockRequestBaseRequest.getRequestPayload();
|
||||||
|
log.debug("CommonDeleteRequest (block request) received id = {}", request.getId());
|
||||||
|
{ // Валидация
|
||||||
|
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(companyBlockRequestBaseRequest);
|
||||||
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
|
||||||
|
// requestInfoUpdate = validationHelper.validateTillFirstError(companyBlockRequestBaseRequest, companyDeleteRequestValidator);
|
||||||
|
// if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
Company company = companyIMap.getSingleObjectByID(request.getId());
|
||||||
|
if (company == null) {
|
||||||
|
log.warn("Company {} not found", request.getId());
|
||||||
|
return requestHelper.makeErrorResponse(companyBlockRequestBaseRequest, CompanyErrors.CompanyNotFound);
|
||||||
|
}
|
||||||
|
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) {
|
||||||
|
log.info("Company {} already blocked", request.getId());
|
||||||
|
return requestHelper.makeErrorResponse(companyBlockRequestBaseRequest, CompanyErrors.CompanyDisabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ImdgTransaction transaction = imdgProvider.newTransaction();
|
||||||
|
transaction.beginTransaction();
|
||||||
|
boolean txOk = false;
|
||||||
|
try {
|
||||||
|
Imdg<Company> companyMap = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
|
|
||||||
|
company.setUpdated(Instant.now());
|
||||||
|
|
||||||
|
company.setWorkflowStatus(WorkflowStatus.Blocked.getKey());
|
||||||
|
|
||||||
|
relationHelper.onChangeWorkflowStatusOnlyRelationChange(transaction, company, company.getWorkflowStatus());
|
||||||
|
log.debug("Update company.id={}", company.getId());
|
||||||
|
companyMap.update(company);
|
||||||
|
|
||||||
|
txOk = true;
|
||||||
|
} finally {
|
||||||
|
if (txOk)
|
||||||
|
transaction.commitTransaction();
|
||||||
|
else
|
||||||
|
transaction.rollbackTransaction();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,22 @@ public class RelationHelper {
|
||||||
public void onChangeWorkflowStatus(ImdgTransaction transaction, Company company, String oldStatus, String newStatus) throws ValidationException {
|
public void onChangeWorkflowStatus(ImdgTransaction transaction, Company company, String oldStatus, String newStatus) throws ValidationException {
|
||||||
log.debug("Company id={} status changed from {} to {}",
|
log.debug("Company id={} status changed from {} to {}",
|
||||||
company.getId(), oldStatus, company.getWorkflowStatus());
|
company.getId(), oldStatus, company.getWorkflowStatus());
|
||||||
|
onChangeWorkflowStatusOnlyRelationChange(transaction, company, newStatus);
|
||||||
|
|
||||||
|
if (WorkflowStatus.Blocked.equalsByKey(newStatus)) {
|
||||||
|
// IV - сообщения на добавления документа расторжения договора
|
||||||
|
CompanyErrors hasError = accountNotification.accountTerminationNotification(company.getId());
|
||||||
|
if (hasError != null) {
|
||||||
|
log.warn("Can not block company, cause error {}", hasError);
|
||||||
|
throw new ValidationException(hasError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onChangeWorkflowStatusOnlyRelationChange(ImdgTransaction transaction, Company company, String newStatus) throws ValidationException {
|
||||||
assert Objects.equals(newStatus, company.getWorkflowStatus());
|
assert Objects.equals(newStatus, company.getWorkflowStatus());
|
||||||
String query = String.format("consumerId=%s", company.getId());
|
String query = String.format("consumerId=%s", company.getId());
|
||||||
Imdg<Relation> relationMap = transaction.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
Imdg<Relation> relationMap = transaction.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
||||||
Collection<Relation> relations = relationMap.getCollectionObjectsBySQL(query);
|
Collection<Relation> relations = relationMap.getCollectionObjectsBySQL(query);
|
||||||
log.trace("Selected {} Relation by query: {}", relations.size(), query);
|
log.trace("Selected {} Relation by query: {}", relations.size(), query);
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
|
|
@ -80,15 +93,5 @@ public class RelationHelper {
|
||||||
relationMap.update(relation);
|
relationMap.update(relation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WorkflowStatus.Blocked.equalsByKey(newStatus)) {
|
|
||||||
// IV - сообщения на добавления документа расторжения договора
|
|
||||||
CompanyErrors hasError = accountNotification.accountTerminationNotification(company.getId());
|
|
||||||
if (hasError != null) {
|
|
||||||
log.warn("Can not block company, cause error {}", hasError);
|
|
||||||
throw new ValidationException(hasError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue