XDEP time interval

RequirementsAndObligationCreation execution match bugfix
This commit is contained in:
ialbert 2023-09-28 15:16:16 +03:00
parent 1be10820a3
commit c93e59c814
5 changed files with 38 additions and 14 deletions

View file

@ -34,6 +34,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

@ -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"),//Начало торговой сессии по вторичным торгам