company-service http://jira.mfd.msk:8088/browse/CLS-284 доделал.
This commit is contained in:
parent
a37fea5061
commit
84870fb64f
2 changed files with 78 additions and 50 deletions
|
|
@ -25,6 +25,8 @@ public enum CompanyErrors implements IErrorEnumId {
|
|||
EditContactType(3021L), // Тип контакта компании %s не может быть изменен.
|
||||
TradingClearingRegistryNotFound(3022L), // ТКР с %s не найден
|
||||
AccountNotFound(3023L), // Счет %s не найден
|
||||
ClearingMemberCategoryOnMKRAlreadyExist(3024L), // Договорные отношения %s в секции МКР уже созданы.
|
||||
ClearingMemberCategoryOnFONDAlreadyExist(3025L), // Договорные отношения %s на фондовой секции уже созданы.
|
||||
RelationNotFound(3026L), // Запись о договорных отношениях не найдена
|
||||
;
|
||||
private final Long id;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
|||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
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.ServiceProduct;
|
||||
import ru.spcex.platform.enumeration.ServiceStatus;
|
||||
import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||
|
|
@ -33,6 +34,7 @@ import ru.spcex.platform.utils.validation.IValidator;
|
|||
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
|
@ -115,38 +117,48 @@ public class RelationService extends QueueConsumer implements InitializingBean {
|
|||
|
||||
Company company = companyMap.getSingleObjectByID(req.getCompanyId());
|
||||
|
||||
// if (ClearingCategory.B.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.I.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.V.equalsByKey(req.getClearingMemberCategory())
|
||||
// ) {
|
||||
// /*
|
||||
// relation.consumerId (clearingMemberCategory.companyId=relation.companyId) и service=MKR,
|
||||
// если запись создана и serviceStatus=CLOS,
|
||||
// изменить запись в relation согласно описанию с тегом При возобнолвении
|
||||
// , иначе вернуть ошибку (3024)"Договорные отношения %s в секции МКР уже созданы."
|
||||
// */
|
||||
// }
|
||||
// if (ClearingCategory.C.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.F.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.V.equalsByKey(req.getClearingMemberCategory())
|
||||
// ) {
|
||||
// /*
|
||||
//проверить по relation.consumerId (clearingMemberCategory.companyId=relation.companyId) и service=FOND,
|
||||
//если запись создана и serviceStatus=CLOS, изменить запись в relation согласно описанию с тегом При возобнолвении,
|
||||
// иначе вернуть ошибку (3025)"Договорные отношения %s на фондовой секции уже созданы." */
|
||||
// }
|
||||
Relation relation = new Relation();
|
||||
relation.setId(idSequence.nextId());
|
||||
relation.setCreated(Instant.now());
|
||||
relation.setUpdated(relation.getCreated());
|
||||
Relation existRelation = searchRelation(req.getClearingMemberCategory(), req.getCompanyId());
|
||||
if (existRelation != null && !WorkflowStatus.Blocked.equalsByKey(existRelation.getServiceStatus())) {
|
||||
CompanyErrors errorType;
|
||||
if (ru.spcex.platform.enumeration.Service.MKR.equalsByKey(existRelation.getService())) {
|
||||
errorType = CompanyErrors.ClearingMemberCategoryOnMKRAlreadyExist;
|
||||
} else if (ru.spcex.platform.enumeration.Service.FOND.equalsByKey(existRelation.getService())) {
|
||||
errorType = CompanyErrors.ClearingMemberCategoryOnFONDAlreadyExist;
|
||||
} else {
|
||||
log.warn("Unknown relation[{}] service={}", existRelation.getId(), existRelation.getService());
|
||||
errorType = CompanyErrors.GeneralError;
|
||||
}
|
||||
return requestHelper.makeErrorResponse(relationNewBaseRequest, errorType);
|
||||
}
|
||||
|
||||
Relation relation;
|
||||
if (existRelation == null) {
|
||||
relation = new Relation();
|
||||
relation.setId(idSequence.nextId());
|
||||
relation.setCreated(Instant.now());
|
||||
relation.setUpdated(relation.getCreated());
|
||||
} else {
|
||||
log.info("Found exist relation id={}, it will be update.", existRelation.getId());
|
||||
relation = existRelation;
|
||||
relation.setUpdated(Instant.now());
|
||||
}
|
||||
|
||||
relation.setConsumerId(req.getCompanyId());
|
||||
relation.setSupplierId(SPVB_ID); // 1 СПВБ
|
||||
if (req.getServiceStatus() != null) {
|
||||
relation.setServiceStatus(req.getServiceStatus());
|
||||
} else {
|
||||
log.warn("Request has no status. Set status from company[{}].status={}", company.getId(), company.getWorkflowStatus());
|
||||
relation.setServiceStatus(company.getWorkflowStatus());
|
||||
if (existRelation != null) {
|
||||
relation.setServiceStatus(ServiceStatus.Reopened.getKey());
|
||||
log.debug("Request has no status. Set status by resume: {}", relation.getServiceStatus());
|
||||
} else {
|
||||
String toStatus = WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus()) ? ServiceStatus.Active.getKey() :
|
||||
WorkflowStatus.Blocked.equalsByKey(company.getWorkflowStatus()) ? ServiceStatus.Closed.getKey() :
|
||||
null;
|
||||
log.debug("Request has no status. Set status by company[{}].status={}. Relation[{}].serviceSStatus={}",
|
||||
company.getId(), company.getWorkflowStatus(), toStatus);
|
||||
relation.setServiceStatus(toStatus);
|
||||
}
|
||||
}
|
||||
relation.setService(ru.spcex.platform.enumeration.Service.MKR.getKey()); // MKR
|
||||
relation.setServiceProduct(ServiceProduct.ZERO.getKey());
|
||||
|
|
@ -158,6 +170,27 @@ public class RelationService extends QueueConsumer implements InitializingBean {
|
|||
return null;
|
||||
}
|
||||
|
||||
private Relation searchRelation(String clearingMemberCategory, Long consumerId) {
|
||||
String svc;
|
||||
if (ClearingCategory.B.equalsByKey(clearingMemberCategory)
|
||||
|| ClearingCategory.I.equalsByKey(clearingMemberCategory)
|
||||
|| ClearingCategory.V.equalsByKey(clearingMemberCategory)
|
||||
) {
|
||||
svc = ru.spcex.platform.enumeration.Service.MKR.getKey();
|
||||
} else if (ClearingCategory.C.equalsByKey(clearingMemberCategory)
|
||||
|| ClearingCategory.F.equalsByKey(clearingMemberCategory)
|
||||
) {
|
||||
svc = ru.spcex.platform.enumeration.Service.FOND.getKey();
|
||||
} else {
|
||||
log.warn("Unexpected relation Relation={}", clearingMemberCategory);
|
||||
return null;
|
||||
}
|
||||
Relation existRelation = relationMap.getSingleObjectByFieldValues(Map.of(
|
||||
"consumerId", consumerId,
|
||||
"service", svc
|
||||
));
|
||||
return existRelation;
|
||||
}
|
||||
|
||||
private synchronized RequestInfoUpdate relationUpdate(BaseRequest<RelationUpdateRequest> relationUpdateBaseRequest) {
|
||||
RelationUpdateRequest req = relationUpdateBaseRequest.getRequestPayload();
|
||||
|
|
@ -171,37 +204,30 @@ public class RelationService extends QueueConsumer implements InitializingBean {
|
|||
}
|
||||
|
||||
|
||||
//Company company = companyMap.getSingleObjectByID(req.getCompanyId());
|
||||
//
|
||||
// if (ClearingCategory.B.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.I.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.V.equalsByKey(req.getClearingMemberCategory())
|
||||
// ) {
|
||||
// /*
|
||||
// relation.consumerId (clearingMemberCategory.companyId=relation.companyId) и service=MKR,
|
||||
// если запись создана и serviceStatus=CLOS,
|
||||
// изменить запись в relation согласно описанию с тегом При возобнолвении
|
||||
// , иначе вернуть ошибку (3024)"Договорные отношения %s в секции МКР уже созданы."
|
||||
// */
|
||||
// }
|
||||
// if (ClearingCategory.C.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.F.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.V.equalsByKey(req.getClearingMemberCategory())
|
||||
// ) {
|
||||
// /*
|
||||
//проверить по relation.consumerId (clearingMemberCategory.companyId=relation.companyId) и service=FOND,
|
||||
//если запись создана и serviceStatus=CLOS, изменить запись в relation согласно описанию с тегом При возобнолвении,
|
||||
// иначе вернуть ошибку (3025)"Договорные отношения %s на фондовой секции уже созданы." */
|
||||
// }
|
||||
|
||||
Relation relation = relationMap.getSingleObjectByID(req.getId());
|
||||
relation.setUpdated(relation.getCreated());
|
||||
|
||||
if (req.getServiceStatus() != null) {
|
||||
log.debug("To relation {} set serivceStatus=\"{}\" by user request.", relation.getId(), req.getServiceStatus());
|
||||
relation.setServiceStatus(req.getServiceStatus());
|
||||
} else {
|
||||
// relation.setServiceStatus(company.getStatus());
|
||||
if (relation.getConsumerId() == null) {
|
||||
log.warn("Relation[{}]. consumerId was null", relation.getId());
|
||||
}
|
||||
Company company = companyMap.getSingleObjectByID(relation.getConsumerId());
|
||||
String toStatus = WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus()) ? ServiceStatus.Active.getKey() :
|
||||
WorkflowStatus.Blocked.equalsByKey(company.getWorkflowStatus()) ? ServiceStatus.Closed.getKey() :
|
||||
null;
|
||||
if (ServiceStatus.Active.equalsByKey(toStatus) && ServiceStatus.Closed.equalsByKey(relation.getServiceStatus())) {
|
||||
relation.setServiceStatus(ServiceStatus.Reopened.getKey());
|
||||
log.debug("Set status by resume: {}", relation.getServiceStatus());
|
||||
} else {
|
||||
relation.setServiceStatus(toStatus);
|
||||
log.debug("Request has no status. Set status by company[{}].status={}. Relation[{}].serviceSStatus={}",
|
||||
company.getId(), company.getWorkflowStatus(), toStatus, relation.getServiceStatus());
|
||||
}
|
||||
}
|
||||
|
||||
relation.setComment(req.getComment());
|
||||
|
||||
relationMap.insert(relation);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue