company-service ClearingMemberCategoryService -> RelationService правки взаимодествия
This commit is contained in:
parent
a622fccc71
commit
86b9bd095f
3 changed files with 100 additions and 8 deletions
|
|
@ -50,7 +50,8 @@ public class RelationValidationConfig {
|
||||||
IMDGDistributedNames.Map_ClearingCategoryDictionary,
|
IMDGDistributedNames.Map_ClearingCategoryDictionary,
|
||||||
ClearingCategoryDictionary.class,
|
ClearingCategoryDictionary.class,
|
||||||
CompanyErrors.RequiredFieldEmpty,
|
CompanyErrors.RequiredFieldEmpty,
|
||||||
CompanyErrors.WrongFieldValue),
|
CompanyErrors.WrongFieldValue,
|
||||||
|
false),
|
||||||
DictionaryPresentRule.instance("serviceStatus",
|
DictionaryPresentRule.instance("serviceStatus",
|
||||||
RelationNewRequest::getServiceStatus,
|
RelationNewRequest::getServiceStatus,
|
||||||
IMDGDistributedNames.Map_ServiceStatusDictionary,
|
IMDGDistributedNames.Map_ServiceStatusDictionary,
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,18 @@ 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.util.security.UserRoleVerification;
|
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||||
|
import ru.spcex.platform.enumeration.ClearingCategory;
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
import ru.spcex.platform.imdg.api.ImdgId;
|
import ru.spcex.platform.imdg.api.ImdgId;
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
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.validation.IValidator;
|
import ru.spcex.platform.utils.validation.IValidator;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import static ru.spcex.platform.utils.enumeration.IEnumKey.getEnumByKey;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ClearingMemberCategoryService extends QueueConsumer implements InitializingBean {
|
public class ClearingMemberCategoryService extends QueueConsumer implements InitializingBean {
|
||||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
@ -127,9 +131,29 @@ public class ClearingMemberCategoryService extends QueueConsumer implements Init
|
||||||
log.debug("ClearingMemberCategoryUpdateRequest received");
|
log.debug("ClearingMemberCategoryUpdateRequest received");
|
||||||
ClearingMemberCategory clearingMemberCategory = clearingMemberCategoryMap.getSingleObjectByID(req.getId());
|
ClearingMemberCategory clearingMemberCategory = clearingMemberCategoryMap.getSingleObjectByID(req.getId());
|
||||||
|
|
||||||
|
// if (Objects.equals(clearingMemberCategory.getClearingMemberCategory(), req.getClearingMemberCategory()))
|
||||||
|
String oldClearingMemberCategory = clearingMemberCategory.getClearingMemberCategory();
|
||||||
clearingMemberCategory.setClearingMemberCategory(req.getClearingMemberCategory());
|
clearingMemberCategory.setClearingMemberCategory(req.getClearingMemberCategory());
|
||||||
|
synchronized (companyService) {
|
||||||
|
ImdgTransaction transaction = imdgProvider.newTransaction();
|
||||||
|
transaction.beginTransaction();
|
||||||
|
boolean txOk = false;
|
||||||
|
try {
|
||||||
|
//todo сложный кейс с возможным изменением релейшена или пересозданием. Скоро ТЗ доделают.
|
||||||
|
//companyService.relationService.updateExistRelation(transaction,clearingMemberCategory.getCompanyId(), oldClearingMemberCategory,
|
||||||
|
// clearingMemberCategory.getClearingMemberCategory());
|
||||||
|
companyService.relationService.createNewRelation(transaction, clearingMemberCategory.getCompanyId(), clearingMemberCategory);
|
||||||
|
Imdg<ClearingMemberCategory> txClearingMemberCategoryMap = transaction.getImdg(IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class);
|
||||||
|
txClearingMemberCategoryMap.insert(clearingMemberCategory);
|
||||||
|
txOk = true;
|
||||||
|
} finally {
|
||||||
|
if (txOk)
|
||||||
|
transaction.commitTransaction();
|
||||||
|
else
|
||||||
|
transaction.rollbackTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
clearingMemberCategoryMap.update(clearingMemberCategory);
|
|
||||||
log.debug("successfully processed, id {}", clearingMemberCategory.getId());
|
log.debug("successfully processed, id {}", clearingMemberCategory.getId());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -145,7 +169,25 @@ public class ClearingMemberCategoryService extends QueueConsumer implements Init
|
||||||
|
|
||||||
log.debug("CommonDeleteRequest received id = {}", req.getId());
|
log.debug("CommonDeleteRequest received id = {}", req.getId());
|
||||||
ClearingMemberCategory clearingMemberCategory = clearingMemberCategoryMap.getSingleObjectByID(req.getId());
|
ClearingMemberCategory clearingMemberCategory = clearingMemberCategoryMap.getSingleObjectByID(req.getId());
|
||||||
clearingMemberCategoryMap.delete(clearingMemberCategory);
|
|
||||||
|
synchronized (companyService) {
|
||||||
|
ImdgTransaction transaction = imdgProvider.newTransaction();
|
||||||
|
transaction.beginTransaction();
|
||||||
|
boolean txOk = false;
|
||||||
|
try {
|
||||||
|
companyService.relationService.cancelRelation(transaction, clearingMemberCategory.getCompanyId(), clearingMemberCategory);
|
||||||
|
Imdg<ClearingMemberCategory> txClearingMemberCategoryMap = transaction.getImdg(IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class);
|
||||||
|
txClearingMemberCategoryMap.delete(clearingMemberCategory);
|
||||||
|
txOk = true;
|
||||||
|
} finally {
|
||||||
|
if (txOk)
|
||||||
|
transaction.commitTransaction();
|
||||||
|
else
|
||||||
|
transaction.rollbackTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("clearingMemberCategory.id={} deleted.", clearingMemberCategory.getId());
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,7 @@ public class RelationService extends QueueConsumer implements InitializingBean {
|
||||||
relation.setId(idSequence.nextId());
|
relation.setId(idSequence.nextId());
|
||||||
relation.setCreated(Instant.now());
|
relation.setCreated(Instant.now());
|
||||||
relation.setUpdated(relation.getCreated());
|
relation.setUpdated(relation.getCreated());
|
||||||
|
log.debug("New relation.id={}", relation.getId());
|
||||||
} else {
|
} else {
|
||||||
log.info("Found exist relation id={}, it will be update.", existRelation.getId());
|
log.info("Found exist relation id={}, it will be update.", existRelation.getId());
|
||||||
relation = existRelation;
|
relation = existRelation;
|
||||||
|
|
@ -199,13 +200,17 @@ public class RelationService extends QueueConsumer implements InitializingBean {
|
||||||
) {
|
) {
|
||||||
svc = ru.spcex.platform.enumeration.Service.FOND.getKey();
|
svc = ru.spcex.platform.enumeration.Service.FOND.getKey();
|
||||||
} else {
|
} else {
|
||||||
log.warn("Unexpected relation Relation={}", clearingMemberCategory);
|
log.warn("Unexpected relation clearingMemberCategory={}", clearingMemberCategory);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Relation existRelation = relationMap.getSingleObjectByFieldValues(Map.of(
|
Relation existRelation = relationMap.getSingleObjectByFieldValues(Map.of(
|
||||||
"consumerId", consumerId,
|
"consumerId", consumerId,
|
||||||
"service", svc
|
"service", svc
|
||||||
));
|
));
|
||||||
|
if (existRelation == null)
|
||||||
|
log.trace("Relation with consumerId={} and service={} not exist.", consumerId, svc);
|
||||||
|
else
|
||||||
|
log.trace("Exist relation.id={}", existRelation.getId());
|
||||||
return existRelation;
|
return existRelation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -285,7 +290,6 @@ public class RelationService extends QueueConsumer implements InitializingBean {
|
||||||
protected void createNewRelation(ImdgTransaction transaction, Long companyId, ClearingMemberCategory clearingMemberCategory) {
|
protected void createNewRelation(ImdgTransaction transaction, Long companyId, ClearingMemberCategory clearingMemberCategory) {
|
||||||
Objects.requireNonNull(companyId, "companyId");
|
Objects.requireNonNull(companyId, "companyId");
|
||||||
Imdg<Relation> relationMap = transaction.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
Imdg<Relation> relationMap = transaction.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
||||||
Relation relation = new Relation();
|
|
||||||
Company company = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class).getSingleObjectByFieldValues(Map.of("id", companyId));
|
Company company = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class).getSingleObjectByFieldValues(Map.of("id", companyId));
|
||||||
|
|
||||||
WorkflowStatus workflowStatus = getEnumByKey(WorkflowStatus.class, company.getWorkflowStatus());
|
WorkflowStatus workflowStatus = getEnumByKey(WorkflowStatus.class, company.getWorkflowStatus());
|
||||||
|
|
@ -309,14 +313,59 @@ public class RelationService extends QueueConsumer implements InitializingBean {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
relation.setCreated(Instant.now());
|
Relation relation = searchRelation(clearingMemberCategory.getClearingMemberCategory(), companyId);
|
||||||
relation.setUpdated(relation.getCreated());
|
if (relation == null) {
|
||||||
|
relation = new Relation();
|
||||||
|
relation.setId(idSequence.nextId());
|
||||||
|
relation.setCreated(Instant.now());
|
||||||
|
relation.setUpdated(relation.getCreated());
|
||||||
|
log.debug("Create new relation.id={}", relation.getId());
|
||||||
|
} else {
|
||||||
|
relation.setUpdated(Instant.now());
|
||||||
|
log.debug("Update exist relation.id={}", relation.getId());
|
||||||
|
}
|
||||||
relation.setConsumerId(companyId);
|
relation.setConsumerId(companyId);
|
||||||
relation.setSupplierId(SPVB_ID); // 1 СПВБ
|
relation.setSupplierId(SPVB_ID); // 1 СПВБ
|
||||||
relation.setServiceStatus(Objects.requireNonNull(workflowStatus).getKey());
|
relation.setServiceStatus(Objects.requireNonNull(workflowStatus).getKey());
|
||||||
relation.setService(serviceStatus);
|
relation.setService(serviceStatus);
|
||||||
relation.setServiceProduct(ServiceProduct.ZERO.getKey());
|
relation.setServiceProduct(ServiceProduct.ZERO.getKey());
|
||||||
log.debug("New Relation[{}] created.", relation.getId());
|
log.debug("New Relation[{}] created by clearingMemberCategory[{}].", relation.getId(), clearingMemberCategory.getId());
|
||||||
|
relationMap.insert(relation);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void cancelRelation(ImdgTransaction transaction, Long companyId, ClearingMemberCategory clearingMemberCategory) {
|
||||||
|
Objects.requireNonNull(companyId, "companyId");
|
||||||
|
Imdg<Relation> relationMap = transaction.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
||||||
|
String serviceStatus = null;
|
||||||
|
if (clearingMemberCategory == null) {
|
||||||
|
log.warn("clearingMemberCategory not set for companyId={}", companyId);
|
||||||
|
} else {
|
||||||
|
ClearingCategory clearingCategory = getEnumByKey(ClearingCategory.class, clearingMemberCategory.getClearingMemberCategory());
|
||||||
|
switch (Objects.requireNonNull(clearingCategory)) {
|
||||||
|
case B:
|
||||||
|
case I:
|
||||||
|
case V:
|
||||||
|
serviceStatus = MKR.getKey();
|
||||||
|
break;
|
||||||
|
case C:
|
||||||
|
case F:
|
||||||
|
serviceStatus = FOND.getKey();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException("Illegal state of clearingCategory");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Relation relation = searchRelation(clearingMemberCategory.getClearingMemberCategory(), companyId);
|
||||||
|
if (relation == null) {
|
||||||
|
log.debug("Relation for clearingMemberCategory.id={} {} not found", clearingMemberCategory.getId(), clearingMemberCategory.getClearingMemberCategory());
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
relation.setUpdated(Instant.now());
|
||||||
|
log.debug("Update exist relation.id={}", relation.getId());
|
||||||
|
}
|
||||||
|
relation.setServiceStatus(Closed.getKey());
|
||||||
|
log.debug("Relation[{}] updated (closed) by clearingMemberCategory[{}].", relation.getId(), clearingMemberCategory.getId());
|
||||||
relationMap.insert(relation);
|
relationMap.insert(relation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue