account-service http://jira.mfd.msk:8088/browse/CLS-361 TCR sequence
This commit is contained in:
parent
fa2cb814c8
commit
5aa1de8b18
2 changed files with 49 additions and 5 deletions
|
|
@ -250,10 +250,9 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
|
|||
tradingClearingRegistry.setTradingClearingRegistryPurpose(registryPurpose.getKey());
|
||||
|
||||
Company company = companyImdg.getSingleObjectByID(req.getCompanyId());
|
||||
String code = "%4s".formatted(company.getClearingCode()).replace(' ', '0');
|
||||
code += registryPurpose.getKey();
|
||||
if (registryPurpose == TradingClearingRegistryPurpose.C) code += tradingRegistryType + id;
|
||||
else code += "AT" + id;
|
||||
Long seqId = companySequenceNextId(req.getCompanyId());
|
||||
String code = makeCode(company.getClearingCode(), registryPurpose, tradingRegistryType, seqId);
|
||||
log.debug("For new TCR.id={} of companyId={} next sequence={}; code={}", id, req.getCompanyId(), seqId, code);
|
||||
tradingClearingRegistry.setCode(code);
|
||||
|
||||
Instant now = Instant.now();
|
||||
|
|
@ -323,7 +322,9 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
|
|||
tradingClearingRegistry.setTradingClearingRegistryPurpose(registryPurpose.getKey());
|
||||
|
||||
Company company = companyImdg.getSingleObjectByID(req.getCompanyId());
|
||||
String code = makeCode(company.getClearingCode(), registryPurpose, tradingRegistryType, id);
|
||||
Long seqId = companySequenceNextId(req.getCompanyId());
|
||||
String code = makeCode(company.getClearingCode(), registryPurpose, tradingRegistryType, seqId);
|
||||
log.debug("For new TCR.id={} of companyId={} next sequence={}; code={}", id, req.getCompanyId(), seqId, code);
|
||||
tradingClearingRegistry.setCode(code);
|
||||
|
||||
Instant now = Instant.now();
|
||||
|
|
@ -341,6 +342,40 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
|
|||
return null;
|
||||
}
|
||||
|
||||
protected Long companySequenceNextId(Long companyId) {
|
||||
Collection<TradingClearingRegistry> existTCR = tradingClearingRegistryImdg.getCollectionObjectsByFieldValues(Map.of(
|
||||
"companyId", companyId
|
||||
));
|
||||
if (existTCR.isEmpty()) {
|
||||
log.trace("For company id={} not found exist TCR.", companyId);
|
||||
return 1L;
|
||||
}
|
||||
log.trace("For company id={} found {} exist TCR.", companyId, existTCR.size());
|
||||
long maxN = 0;
|
||||
for (TradingClearingRegistry tcr : existTCR) {
|
||||
Long codeN = parseCodeSeqId(tcr.getCode());
|
||||
if (codeN != null) {
|
||||
if (maxN < codeN)
|
||||
maxN = codeN;
|
||||
}
|
||||
}
|
||||
return maxN + 1;
|
||||
}
|
||||
|
||||
protected Long parseCodeSeqId(String code) {
|
||||
if (code == null || code.isBlank())
|
||||
return null;
|
||||
try {
|
||||
String toParse = code.trim();
|
||||
if (toParse.length() > 5)
|
||||
toParse = toParse.substring(toParse.length() - 5);
|
||||
return Long.parseLong(toParse);
|
||||
} catch (NumberFormatException nan) {
|
||||
log.warn("Can not parse number from TCR code \"{}\": {}", code, nan.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String makeCode(String companyClearingCode, TradingClearingRegistryPurpose registryPurpose, String tradingRegistryType, Long id) {
|
||||
String code;
|
||||
code = companyClearingCode;
|
||||
|
|
|
|||
|
|
@ -337,4 +337,13 @@ class TradingClearingRegistryServiceTest {
|
|||
"000000105", TradingClearingRegistryPurpose.M, "ER", 100012L
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseCodeSeqId() {
|
||||
Assertions.assertEquals(Long.valueOf(1L), tradingClearingRegistryService.parseCodeSeqId("0005CAT00001"));
|
||||
Assertions.assertEquals(Long.valueOf(5001), tradingClearingRegistryService.parseCodeSeqId("0005CAT05001"));
|
||||
Assertions.assertEquals(null, tradingClearingRegistryService.parseCodeSeqId("0005CAT"));
|
||||
Assertions.assertEquals(null, tradingClearingRegistryService.parseCodeSeqId(""));
|
||||
Assertions.assertEquals(null, tradingClearingRegistryService.parseCodeSeqId(null));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue