Merge branch 'CLS_258_259' into dev
This commit is contained in:
commit
9b92dfdf93
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));
|
||||
log.debug("For account[{}] send termination by document request id={}", account.getId(), reqId);
|
||||
}
|
||||
// ответ должен послаться в DESTINATION_COMPANY_BLOCK = "company-block";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -46,6 +46,7 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
|||
private final RequestHelper requestHelper;
|
||||
private final ImdgProvider imdgProvider;
|
||||
private final ImdgId idSequence;
|
||||
private final Imdg<Company> companyIMap;
|
||||
protected UserRoleVerification userRoleVerification;
|
||||
|
||||
private ValidationHelper validationHelper;
|
||||
|
|
@ -89,6 +90,8 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
|||
companySymbolService.setCompanyService(this);
|
||||
this.accountNotification = accountNotification;
|
||||
this.relationHelper = relationHelper;
|
||||
|
||||
companyIMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -96,6 +99,9 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
|||
callback(CommonDeleteRequest.class)
|
||||
.setConsumer(request -> requestHelper.requestFunction(this::deleteCompany, request))
|
||||
.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)
|
||||
.setFunction(request -> requestHelper.requestFunction(this::createCompany, request))
|
||||
.forDestination(Consts.DESTINATION_COMPANY_NEW, callbacks::put);
|
||||
|
|
@ -294,4 +300,57 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
|||
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 {
|
||||
log.debug("Company id={} status changed from {} to {}",
|
||||
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());
|
||||
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);
|
||||
log.trace("Selected {} Relation by query: {}", relations.size(), query);
|
||||
Instant now = Instant.now();
|
||||
|
|
@ -80,15 +93,5 @@ public class RelationHelper {
|
|||
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