company-service gateway-api http://jira.mfd.msk:8088/browse/CLS-347 bug fix, правки поиска

This commit is contained in:
AKurakin 2023-09-28 14:22:32 +03:00
parent 8a2855e32b
commit 2ee26a3d68
6 changed files with 87 additions and 15 deletions

View file

@ -179,7 +179,11 @@ public class ClearingMemberCategoryService extends QueueConsumer implements Init
try {
Imdg<ClearingMemberCategory> txClearingMemberCategoryMap = transaction.getImdg(IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class);
txClearingMemberCategoryMap.delete(clearingMemberCategory); // далить до cancelRelation внутри транзакции
companyService.relationService.cancelRelation(transaction, clearingMemberCategory.getCompanyId(), clearingMemberCategory);
if (clearingMemberCategory.getCompanyId() == null) { // never, только тестовые данные
log.warn("Deleted clearingMemberCategory[{}] has not companyId", clearingMemberCategory.getId());
} else {
companyService.relationService.cancelRelation(transaction, clearingMemberCategory.getCompanyId(), clearingMemberCategory);
}
txOk = true;
} finally {
if (txOk)

View file

@ -27,6 +27,7 @@ import ru.spcex.clearing.validation.common.ValidationHelper;
import ru.spcex.platform.enumeration.CompanySymbol;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgProvider;
import ru.spcex.platform.utils.enumeration.IEnumKey;
import ru.spcex.platform.utils.enumeration.IMessageResolver;
import ru.spcex.platform.utils.error.ValidationException;
import ru.spcex.platform.utils.log.ExceptionUtils;
@ -48,7 +49,7 @@ public class MultiCompanyService
private final RequestHelper requestHelper;
protected UserRoleVerification userRoleVerification;
// private final ValidationHelper validationHelper;
// private final ValidationHelper validationHelper;
protected IMessageResolver messageResolver;
final CompanyService companyService;
@ -128,7 +129,7 @@ public class MultiCompanyService
req.setCompanySymbols(
Stream.concat(req.getCompanySymbols().stream(), additionalSymbols(req.getCompany())).collect(Collectors.toList())
);
companyId = getCompanyIdForCompanySymbols(req.getUuid(), req.getCompany());
companyId = getCompanyIdForCompanySymbols(req.getUuid(), req.getCompany(), req.getCompanySymbols());
log.debug("For request {} (uuid {}) company {}.", baseRequest.getId(), req.getUuid(), companyId == null ? "not found" : ("found, id=" + companyId));
if (companyId == null) {
log.debug("For request {} (uuid {}) company not found. Try find by other symbols.", baseRequest.getId(), req.getUuid());
@ -334,7 +335,7 @@ public class MultiCompanyService
return r;
}
Long getCompanyIdForCompanySymbols(String uuid, CompanyNewRequest cnr) {
Long getCompanyIdForCompanySymbols(String uuid, CompanyNewRequest cnr, Collection<CompanySymbolNewRequest> companySymbols) {
CompanySymbols companySymbol = null;
if (StringUtils.isNotEmpty(uuid)) {
log.trace("Search company by companySymbol uuid={}", uuid);
@ -351,10 +352,10 @@ public class MultiCompanyService
}
}
}
if (companySymbol == null && StringUtils.isNotEmpty(cnr.getCompanySymbolValue())) {
for (String companySymbolType : Arrays.asList(
cnr.getCompanySymbol(), CompanySymbol.INN.getKey(), CompanySymbol.CIO.getKey()
)) {
if (companySymbol == null && StringUtils.isNotEmpty(cnr.getCompanySymbolValue())
&& IEnumKey.contains(cnr.getCompanySymbol(), CompanySymbol.INN, CompanySymbol.CIO)) { // вероятно там будет только UUID
{
String companySymbolType = cnr.getCompanySymbol();
log.trace("Search company by companySymbol {}={}", companySymbolType, cnr.getCompanySymbolValue());
Collection<CompanySymbols> companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
Map.of(
@ -367,10 +368,31 @@ public class MultiCompanyService
if (companySymbolsFromImdg.size() > 1) {
log.warn("For {} found > 1 company_symbols, use first (id = {})", companySymbolType, cnr.getCompanySymbolValue());
}
break;
}
}
}
if (companySymbol == null && companySymbols != null) {
for (CompanySymbolNewRequest cSymbolReq : companySymbols) {
if (IEnumKey.contains(cSymbolReq.getCompanySymbol(), CompanySymbol.INN, CompanySymbol.CIO)) {
String companySymbolType = cSymbolReq.getCompanySymbol();
log.trace("Search company by companySymbol {}={}", companySymbolType, cSymbolReq.getCompanySymbolValue());
Collection<CompanySymbols> companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
Map.of(
"companySymbol", companySymbolType,
"companySymbolValue", cSymbolReq.getCompanySymbolValue()
)
);
if (!companySymbolsFromImdg.isEmpty()) {
companySymbol = companySymbolsFromImdg.iterator().next();
if (companySymbolsFromImdg.size() > 1) {
log.warn("For {} found > 1 company_symbols, use first (id = {})", companySymbolType, cSymbolReq.getCompanySymbolValue());
}
break;
}
}
}
}
if (companySymbol != null)
return companySymbol.getCompanyId();
else

View file

@ -168,6 +168,7 @@ class ClearingMemberCategoryServiceTest {
String clearingMemberCategory = "0000";
ClearingMemberCategory existsClearingMemberCategory = new ClearingMemberCategory();
existsClearingMemberCategory.setClearingMemberCategory(clearingMemberCategory);
existsClearingMemberCategory.setCompanyId(COMPANY_ID);
Long id = memberCategoryImdg.insert(existsClearingMemberCategory);
CommonDeleteRequest memberCategoryDeleteRequest = new CommonDeleteRequest();

View file

@ -26,6 +26,8 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
import javax.annotation.PostConstruct;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
import static ru.spcex.clearing.test.config.ImdgTestConfig.waitAvailableImdgProviderAndAddAdminWithDefaultId;
@ -48,6 +50,8 @@ import static ru.spcex.clearing.test.config.ImdgTestConfig.waitAvailableImdgProv
ProfileDocumentValidationConfig.class,
ContactService.class,
ContactValidationConfig.class,
ClearingMemberCategoryService.class,
ClearingMemberCategoryValidationConfig.class,
KafkaTestConfig.class,
ImdgTestConfig.class,
@ -101,8 +105,8 @@ class MultiCompanyServiceTest {
CompanySymbols companySymbol = new CompanySymbols();
companySymbol.setId(222L);
companySymbol.setCompanyId(company.getId());
companySymbol.setCompanySymbol(CompanySymbol.CLRC.getKey());
companySymbol.setCompanySymbolValue("CL-VALUE");
companySymbol.setCompanySymbol(CompanySymbol.INN.getKey());
companySymbol.setCompanySymbolValue("INN-VALUE");
companySymbolsImdg.insert(companySymbol);
Imdg<ProfileDocument> profileDocumentImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_ProfileDocument, ProfileDocument.class);
@ -130,9 +134,13 @@ class MultiCompanyServiceTest {
req.setCompanyId(COMPANY_ID);
req.setCompanySymbol(CompanySymbol.CLRC.getKey());
req.setCompanySymbolValue("CL-VALUE-2");
assertNull(multiCompanyService.findCompanySymbols(req));
req.setCompanySymbol(CompanySymbol.INN.getKey());
req.setCompanySymbolValue("INN-VALUE");
CompanySymbols symbol = multiCompanyService.findCompanySymbols(req);
assertNotNull(symbol);
assertEquals("CL-VALUE", symbol.getCompanySymbolValue());
assertEquals("INN-VALUE", symbol.getCompanySymbolValue());
}
@Test
@ -151,8 +159,32 @@ class MultiCompanyServiceTest {
CompanyNewRequest req = new CompanyNewRequest();
req.setCompanySymbol(CompanySymbol.CLRC.getKey());
req.setCompanySymbolValue("CL-VALUE");
Long theId = multiCompanyService.getCompanyIdForCompanySymbols("SAMPLE-NO-uuid", req);
assertEquals(COMPANY_ID, theId);
assertNull(multiCompanyService.getCompanyIdForCompanySymbols("SAMPLE-NO-uuid", req, null));
req.setCompanySymbolValue("INN-VALUE");
assertNull(multiCompanyService.getCompanyIdForCompanySymbols("SAMPLE-NO-uuid", req, null));
req.setCompanySymbol(CompanySymbol.INN.getKey());
assertEquals(COMPANY_ID, multiCompanyService.getCompanyIdForCompanySymbols("SAMPLE-NO-uuid", req, null));
req.setCompanySymbol(null);
req.setCompanySymbolValue(null);
assertNull(multiCompanyService.getCompanyIdForCompanySymbols(null, req, null));
List<CompanySymbolNewRequest> csReq=new ArrayList<>();
assertNull(multiCompanyService.getCompanyIdForCompanySymbols(null, req, null));
assertNull(multiCompanyService.getCompanyIdForCompanySymbols(null, req, csReq));
{
CompanySymbolNewRequest cs=new CompanySymbolNewRequest();
cs.setCompanySymbol(CompanySymbol.CLRC.getKey());
cs.setCompanySymbolValue("INN-VALUE");
csReq.add(cs);
}
assertNull(multiCompanyService.getCompanyIdForCompanySymbols(null, req, csReq));
{
CompanySymbolNewRequest cs=new CompanySymbolNewRequest();
cs.setCompanySymbol(CompanySymbol.INN.getKey());
cs.setCompanySymbolValue("INN-VALUE");
csReq.add(cs);
}
assertEquals(COMPANY_ID, multiCompanyService.getCompanyIdForCompanySymbols(null, req, csReq));
}
@Test

View file

@ -11,6 +11,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
import ru.clearing.classes.statics.data.company.Company;
import ru.clearing.classes.statics.data.company.relation.Relation;
import ru.clearing.platform.dictionary.ClearingCategoryDictionary;
import ru.clearing.platform.dictionary.ServiceStatusDictionary;
import ru.clearing.platform.dictionary.WorkflowStatusDictionary;
import ru.spcex.clearing.company.config.BeanConfiguration;
import ru.spcex.clearing.company.config.validation.RelationValidationConfig;
@ -92,6 +93,18 @@ class RelationServiceTest {
workflowStatusDictionary.setName("not active");
workflowStatusDictionaryImdg.insert(workflowStatusDictionary);
{
Imdg<ServiceStatusDictionary> serviceStatusDictionaryImdg = hazelcastServiceTest.getImdg(
IMDGDistributedNames.Map_ServiceStatusDictionary,
ServiceStatusDictionary.class
);
ServiceStatusDictionary status=new ServiceStatusDictionary();
status.setId(1L);
status.setCode("ACTV");
status.setName("\"ACTV\"");
serviceStatusDictionaryImdg.insert(status);
}
Imdg<ClearingCategoryDictionary> clearingCategoryDictionaryImdg = hazelcastServiceTest.getImdg(
IMDGDistributedNames.Map_ClearingCategoryDictionary,
ClearingCategoryDictionary.class

View file

@ -87,7 +87,7 @@ public class CompanyRequestAdapter {
log.warn("Money account \"{}\" not found", client.getMoneyAccount());
} else {
log.debug("Money account \"{}\" found with id={}", client.getMoneyAccount(), mAccount.getId());
client.setDepoAccountId(mAccount.getId());
client.setMoneyAccountId(mAccount.getId());
}
} catch (Exception e) {
log.warn("Error happened when search money account \"{}\": {}", client.getMoneyAccount(), ExceptionUtils.getStackTrace(e));