Merge branch 'dev' into plan_balance_dmx_dmt

This commit is contained in:
ialbert 2023-09-28 15:17:14 +03:00
commit 90a2b858bb
12 changed files with 128 additions and 29 deletions

View file

@ -246,6 +246,8 @@
<task id="23" code="GRET" name="Формирование отчетности по сделкам"/>
<task id="24" code="GREF" name="Формирование итоговой отчетности"/>
<task id="25" code="FDFF" name="Формирование ДФ-05 с кодом 9 (финальный)"/>
<task id="26" code="SDEP" name="Время начала возврата депозитов"/>
<task id="27" code="EDEP" name="Время завершения возврата депозитов"/>
<taskStatus id="1" code="ACTV" name="Активна"/>
<taskStatus id="2" code="BLKD" name="Не активна"/>
<taskStatus id="3" code="CNCL" name="Отмена расписания"/>
@ -473,6 +475,7 @@
<errorCode id="5430" code="CLRN" name="Неверный код регистра: %s"/>
<errorCode id="5431" code="CLRN" name="Дата возврата для депозита с разделением не может быть изменена"/>
<errorCode id="5432" code="CLRN" name="После сверки обнаружена разница между плановым и фактическим балансом"/>
<errorCode id="5433" code="CLRN" name="Сессия по возврату депозита не может исполняться вне временного интервала, установленного в системе"/>
<!-- error code for dbf-importer -->
<errorCode id="5600" code="DBFI" name="Общая ошибка модуля dbf-importer."/>
<!-- error code for dbf-exporter -->

View file

@ -35,6 +35,7 @@ public enum ClearingError implements IErrorEnumId {
RgsWrongCode(5430L),
RefundDateCannotBeChanged(5431L),
PlanBalanceReviseError(5432L),
XdepTimeIntervalNotMatch(5433L),
//ошибки "перенесенные" из balance-service,
CompanyNotFoundB(5211L),
CurrencyNotFound(5213L),

View file

@ -25,7 +25,7 @@ public class TradingTimeService {
this.plannerAllTodayImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_PlannerAllToday, PlannerAllToday.class);
}
public boolean isTradingTime() {
private boolean isTradingTime(Task startTime, Task endTime) {
ImdgPredicateBuilder pb = plannerAllTodayImdg.predicateBuilder();
Function<Task, Optional<PlannerAllToday>> plannerByTask = task -> {
ImdgPredicate plannerPrdct = pb.and(
@ -34,19 +34,28 @@ public class TradingTimeService {
);
return Optional.ofNullable(plannerAllTodayImdg.getFirstObjectByPredicate(plannerPrdct));
};
LocalTime startTradingTime = plannerByTask.apply(Task.createRegistry_STRS)
LocalTime startTradingTime = plannerByTask.apply(startTime)
.map(PlannerAllToday::getTaskTime)
.orElse(null);
LocalTime endTradingTime = plannerByTask.apply(Task.createRegistry_ETRS)
LocalTime endTradingTime = plannerByTask.apply(endTime)
.map(PlannerAllToday::getTaskTime)
.orElse(null);
if (startTradingTime == null || endTradingTime == null) {
log.warn("startTradingTime or endTradingTime is null");
log.warn("{} or {} not found in planner all today", startTime.getKey(), endTime.getKey());
return false;
}
LocalTime now = LocalTime.now();
boolean isTradingTime = !now.isBefore(startTradingTime) && !now.isAfter(endTradingTime);
log.debug("now: {}, startTradingTime: {}, endTradingTime: {}. trading time: {}", now, startTradingTime, endTradingTime, isTradingTime);
log.debug("now: {}, {}: {}, {}: {}. period check in: {}",
now, startTime.getKey(), startTradingTime, endTime.getKey(), endTradingTime, isTradingTime);
return isTradingTime;
}
public boolean isTradingTime() {
return isTradingTime(Task.createRegistry_STRS, Task.createRegistry_ETRS);
}
public boolean timeForXdep() {
return isTradingTime(Task.startTime_SDEP, Task.endTime_EDEP);
}
}

View file

@ -9,6 +9,7 @@ import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.notification.NotificationSender;
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.schedule.LauncherCommandRequest;
import ru.spcex.clearing.service.schedule.TradingTimeService;
import ru.spcex.platform.enumeration.*;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgProvider;
@ -33,13 +34,14 @@ public class SessionManager {
private final IntermediateMkrSession intermediateMkrSession;
private final FinalMkrSession finalMkrSession;
private final ReturnDepositSession returnDepositSession;
private final TradingTimeService time;
public SessionManager(ImdgProvider imdgProvider,
NotificationSender notification, IMessageResolver msgs, PrimaryAuctionT0Session primaryAuctionT0Session,
PrimaryAuctionBnSession primaryAuctionBnSession,
PrimaryAuctionB0Session primaryAuctionB0Session,
SecondaryAuctionT0Session secondaryAuctionT0Session,
IntermediateMkrSession intermediateMkrSession, FinalMkrSession finalMkrSession, ReturnDepositSession returnDepositSession) {
IntermediateMkrSession intermediateMkrSession, FinalMkrSession finalMkrSession, ReturnDepositSession returnDepositSession, TradingTimeService time) {
this.notification = notification;
this.msgs = msgs;
this.primaryAuctionT0Session = primaryAuctionT0Session;
@ -51,6 +53,7 @@ public class SessionManager {
this.returnDepositSession = returnDepositSession;
sessionImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Session, Session.class);
this.time = time;
}
public void defineAndStartSession(BaseRequest<LauncherCommandRequest> r) throws ValidationException { //task sclr section fond sessiontype trdt
@ -76,19 +79,27 @@ public class SessionManager {
if (session != null) {
//checkActive
checkActiveSession();
checkAllowSessionStart(sessionType);
session.runSession(baseRequest);
}
}
protected void checkActiveSession() throws ValidationException {
Session existActiveSession = sessionImdg.getFirstObjectByFieldValues(Map.of(
"workflowStatus", SessionStatus.ACTV.getKey()
));
if (existActiveSession != null) {
log.warn("Can not start new session, cause exist active session.id={}", existActiveSession.getId());
EnumMessage err = new EnumMessage(ClearingError.ActiveSessionIsPresent, String.valueOf(existActiveSession.getId()));
protected void checkAllowSessionStart(SessionType sessionType) throws ValidationException {
EnumMessage err = null;
if (sessionType.equals(SessionType.XDEP) && !time.timeForXdep()) {
log.warn("cannot launch {} reason: time interval not matched", sessionType);
err = new EnumMessage(ClearingError.XdepTimeIntervalNotMatch);
} else {
Session existActiveSession = sessionImdg.getFirstObjectByFieldValues(Map.of(
"workflowStatus", SessionStatus.ACTV.getKey()
));
if (existActiveSession != null) {
log.warn("Can not start new session, cause exist active session.id={}", existActiveSession.getId());
err = new EnumMessage(ClearingError.ActiveSessionIsPresent, String.valueOf(existActiveSession.getId()));
}
}
if (err != null) {
notification.sendNotification(ObjectType.session, msgs.resolve(err), Priority.HIGH);
throw new ValidationException(err);
}

View file

@ -230,6 +230,7 @@ public class RequirementsAndObligationCreation implements ISessionStage {
}
if (invalid != null) {
log.error("FATAL couldn't match Execution#id({}) with Execution#id({}) error: {}", exec1.getId(), exec2.getId(), invalid);
return null;
}
return new Pair<>(exec1, exec2);
}

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));

View file

@ -25,6 +25,8 @@ public enum Task implements IEnumKey {
liquidationSession_LIQU("LIQU"),//Ликвидационная сессия по обязательтсвам участника
startSession_STRM("STRM"),//Начало торговой сессии секции МКР
terminationSession_ETRM("ETRM"),//Завершение торговой сессии секции МКР
startTime_SDEP("SDEP"),
endTime_EDEP("EDEP"),
startSession_SIPO("SIPO"),//Начало торговой сессии по первичным торгам
terminationSession_EIPO("EIPO"),//Завершение торговой сессии по первичным торгам
startSession_STRF("STRF"),//Начало торговой сессии по вторичным торгам