http://jira.mfd.msk:8088/browse/CLS-358 fix SessionIdParam reports
This commit is contained in:
parent
7f400066b9
commit
3b30b34a34
8 changed files with 65 additions and 27 deletions
|
|
@ -1,16 +1,18 @@
|
|||
package ru.spcex.clearing.reports.reports;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Параметры для формирования отчета по SessionId
|
||||
*/
|
||||
public class SessionIdParam {
|
||||
private Long sessionId;
|
||||
private List<Long> sessionId;
|
||||
|
||||
public Long getSessionId() {
|
||||
public List<Long> getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(Long sessionId) {
|
||||
public void setSessionId(List<Long> sessionId) {
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class ExecutedDealReportBuilder_INFTYPE_1 extends ExecutedDealReportBuild
|
|||
ImdgPredicateBuilder pb = executionFondImdg.predicateBuilder();
|
||||
return executionFondImdg.getCollectionObjectsByPredicate(
|
||||
pb.and(
|
||||
pb.equals("sessionId", params.getSessionId()),
|
||||
pb.in("sessionId", params.getSessionId().toArray(new Long[0])),
|
||||
pb.less("tradingDate", LocalDate.now()),
|
||||
pb.equals("settlementDate", LocalDate.now())
|
||||
)
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class ExecutedDealReportBuilder_INFTYPE_2 extends ExecutedDealReportBuild
|
|||
ImdgPredicateBuilder pb = executionFondImdg.predicateBuilder();
|
||||
return executionFondImdg.getCollectionObjectsByPredicate(
|
||||
pb.and(
|
||||
pb.equals("sessionId", params.getSessionId()),
|
||||
pb.in("sessionId", params.getSessionId().toArray(new Long[0])),
|
||||
pb.equals("tradingDate", LocalDate.now()),
|
||||
pb.equals("settlementDate", LocalDate.now())
|
||||
)
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class UnfulfilledDealReportBuilder extends CSVReportBuilder<SessionIdPara
|
|||
protected void collect(SessionIdParam params) {
|
||||
ImdgPredicateBuilder pb = executionFondImdg.predicateBuilder();
|
||||
ImdgPredicate predicate = pb.and(
|
||||
pb.equals("sessionId", params.getSessionId()),
|
||||
pb.in("sessionId", params.getSessionId().toArray(new Long[0])),
|
||||
pb.equals("coverageStatus", Allowed.DENIED.getKey())
|
||||
);
|
||||
Collection<ExecutionFond> executionFonds = executionFondImdg.getCollectionObjectsByPredicate(predicate);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||
String sql = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.TM_T, RegistryTradingParams.OM_T).build();
|
||||
ImdgPredicate finalPredicate = pb.and(
|
||||
pb.equals("sessionId", params.getSessionId()),
|
||||
pb.in("sessionId", params.getSessionId().toArray(new Long[0])),
|
||||
pb.equals("clearingDate", nowDate),
|
||||
pb.sql(sql),
|
||||
pb.or(
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public class KSRepDepoNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||
String sql = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.TS_T, RegistryTradingParams.OS_T).build();
|
||||
ImdgPredicate finalPredicate = pb.and(
|
||||
pb.equals("sessionId", params.getSessionId()),
|
||||
pb.in("sessionId", params.getSessionId().toArray(new Long[0])),
|
||||
pb.equals("clearingDate", nowDate),
|
||||
pb.sql(sql),
|
||||
pb.equals("accountType", AccountType.Depo.getKey()),
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.misc.Session;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.gateway.ReportPart;
|
||||
|
|
@ -27,12 +29,16 @@ import ru.spcex.platform.enumeration.ReportBuilderType;
|
|||
import ru.spcex.platform.enumeration.ReportKeys;
|
||||
import ru.spcex.platform.enumeration.ReportType;
|
||||
import ru.spcex.platform.enumeration.Task;
|
||||
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.validation.IValidator;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ReportService extends QueueConsumer implements InitializingBean {
|
||||
|
|
@ -53,6 +59,8 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
private final Map<ReportBuilderType, List<CSVReportBuilder<?, ?>>> reportBuildersForGREF;
|
||||
private final Map<ReportBuilderType, List<CSVReportBuilder<?, ?>>> reportBuildersForGRET;
|
||||
|
||||
private final Imdg<Session> sessionImdg;
|
||||
|
||||
private final File outFolder;
|
||||
|
||||
public ReportService(Consumer<String, Object> kafkaQueue,
|
||||
|
|
@ -84,7 +92,9 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
@Qualifier("reportRequestGRETValidator")
|
||||
Function<LauncherCommandRequest, IValidator> reportRequestGRETValidator,
|
||||
@Qualifier("reportRequestGREFValidator")
|
||||
Function<LauncherCommandRequest, IValidator> reportRequestGREFValidator
|
||||
Function<LauncherCommandRequest, IValidator> reportRequestGREFValidator,
|
||||
|
||||
ImdgProvider imdgProvider
|
||||
|
||||
) {
|
||||
super(kafkaQueue, kafkaResponseQueue);
|
||||
|
|
@ -102,6 +112,7 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
this.reportBuildersForGREP = reportBuildersForGREP;
|
||||
this.reportBuildersForGREF = reportBuildersForGREF;
|
||||
this.reportBuildersForGRET = reportBuildersForGRET;
|
||||
this.sessionImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Session, Session.class);
|
||||
assert outFolder.isDirectory();
|
||||
}
|
||||
|
||||
|
|
@ -180,7 +191,7 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
List<String> outFilenames = new ArrayList<>();
|
||||
for (CSVReportBuilder<SessionIdParam, ?> builder : builders) {
|
||||
SessionIdParam sessionIdParam = new SessionIdParam();
|
||||
sessionIdParam.setSessionId(req.getSessionId());
|
||||
sessionIdParam.setSessionId(List.of(req.getSessionId()));
|
||||
File outFile = builder.createReport(sessionIdParam, outFolder);
|
||||
if (outFile == null) continue;
|
||||
outFilenames.add(outFile.getAbsolutePath());
|
||||
|
|
@ -206,10 +217,15 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
if (requestInfoUpdate != null) return null;
|
||||
logUnknownProperties(userRequest);
|
||||
|
||||
Long sessionId = userRequest.getRequestPayload().getSessionId();
|
||||
Map<String, ReportKeys> outFilenames = createReportsForTask(sessionId, reportBuildersForGREP.values());
|
||||
List<Long> sessionIds = null;
|
||||
if (userRequest.getRequestPayload().getSessionId() != null) {
|
||||
sessionIds = List.of(userRequest.getRequestPayload().getSessionId());
|
||||
} else {
|
||||
sessionIds = getSessionIdsForDate(LocalDate.now());
|
||||
}
|
||||
Map<String, ReportKeys> outFilenames = createReportsForTask(sessionIds, reportBuildersForGREP.values());
|
||||
|
||||
sendReportsToGateway(sessionId, outFilenames, ReportType.REPORT_KS_TMP.getKey());
|
||||
sendReportsToGateway(sessionIds, outFilenames, ReportType.REPORT_KS_TMP.getKey());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -222,10 +238,15 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
if (requestInfoUpdate != null) return null;
|
||||
logUnknownProperties(userRequest);
|
||||
|
||||
Long sessionId = userRequest.getRequestPayload().getSessionId();
|
||||
Map<String, ReportKeys> outFilenames = createReportsForTask(sessionId, reportBuildersForGRET.values());
|
||||
List<Long> sessionIds = null;
|
||||
if (userRequest.getRequestPayload().getSessionId() != null) {
|
||||
sessionIds = List.of(userRequest.getRequestPayload().getSessionId());
|
||||
} else {
|
||||
sessionIds = getSessionIdsForDate(LocalDate.now());
|
||||
}
|
||||
Map<String, ReportKeys> outFilenames = createReportsForTask(sessionIds, reportBuildersForGRET.values());
|
||||
|
||||
sendReportsToGateway(sessionId, outFilenames, null);
|
||||
sendReportsToGateway(sessionIds, outFilenames, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -238,14 +259,19 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
if (requestInfoUpdate != null) return null;
|
||||
logUnknownProperties(userRequest);
|
||||
|
||||
Long sessionId = userRequest.getRequestPayload().getSessionId();
|
||||
Map<String, ReportKeys> outFilenames = createReportsForTask(sessionId, reportBuildersForGREF.values());
|
||||
List<Long> sessionIds = null;
|
||||
if (userRequest.getRequestPayload().getSessionId() != null) {
|
||||
sessionIds = List.of(userRequest.getRequestPayload().getSessionId());
|
||||
} else {
|
||||
sessionIds = getSessionIdsForDate(LocalDate.now());
|
||||
}
|
||||
Map<String, ReportKeys> outFilenames = createReportsForTask(sessionIds, reportBuildersForGREF.values());
|
||||
|
||||
sendReportsToGateway(sessionId, outFilenames, ReportType.REPORT_KS_FINAL.getKey());
|
||||
sendReportsToGateway(sessionIds, outFilenames, ReportType.REPORT_KS_FINAL.getKey());
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<String, ReportKeys> createReportsForTask(Long sessionId, Collection<List<CSVReportBuilder<?, ?>>> buildersForTask) {
|
||||
private Map<String, ReportKeys> createReportsForTask(List<Long> sessionIds, Collection<List<CSVReportBuilder<?, ?>>> buildersForTask) {
|
||||
Map<String, ReportKeys> outFilenames = new HashMap<>();
|
||||
int cntErrors = 0;
|
||||
for (List<CSVReportBuilder<?, ?>> builders : buildersForTask) {
|
||||
|
|
@ -258,9 +284,9 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
continue;
|
||||
}
|
||||
outFilenames.put(outFile.getName(), builder.getReportKey());
|
||||
} else if (builder.getParamsClass() == SessionIdParam.class && sessionId != null) {
|
||||
} else if (builder.getParamsClass() == SessionIdParam.class) {
|
||||
SessionIdParam sessionIdParam = new SessionIdParam();
|
||||
sessionIdParam.setSessionId(sessionId);
|
||||
sessionIdParam.setSessionId(sessionIds);
|
||||
File outFile = ((CSVReportBuilder<SessionIdParam, ?>) builder).createReport(sessionIdParam, outFolder);
|
||||
if (outFile == null) {
|
||||
log.warn("Something wrong, report type: {}", builder.getReportType().getKey());
|
||||
|
|
@ -277,9 +303,9 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
return outFilenames;
|
||||
}
|
||||
|
||||
private void sendReportsToGateway(Long sessionId, Map<String, ReportKeys> reportsWithReportType, String type) {
|
||||
private void sendReportsToGateway(List<Long> sessionIds, Map<String, ReportKeys> reportsWithReportType, String type) {
|
||||
SendReportRequest sendReportRequest = new SendReportRequest();
|
||||
sendReportRequest.setSessionId(sessionId);
|
||||
sendReportRequest.setSessionId(sessionIds);
|
||||
sendReportRequest.setType(type);
|
||||
List<ReportPart> reports = new ArrayList<>(reportsWithReportType.size());
|
||||
for (Map.Entry<String, ReportKeys> entry : reportsWithReportType.entrySet()) {
|
||||
|
|
@ -299,4 +325,14 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
}
|
||||
}
|
||||
|
||||
private List<Long> getSessionIdsForDate(LocalDate date) {
|
||||
Collection<Session> sessionForCurrentDay = sessionImdg.getCollectionObjectsByFieldValues(
|
||||
Map.of(
|
||||
"clearingDate", date
|
||||
)
|
||||
);
|
||||
Set<Long> sessionIds = sessionForCurrentDay.stream().map(Session::getId).collect(Collectors.toSet());
|
||||
return sessionIds.stream().toList();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
|||
|
||||
public class SendReportRequest {
|
||||
@JsonProperty
|
||||
private Long sessionId;
|
||||
private List<Long> sessionId;
|
||||
|
||||
@JsonProperty
|
||||
private String type;
|
||||
|
|
@ -14,11 +14,11 @@ public class SendReportRequest {
|
|||
@JsonProperty
|
||||
private List<ReportPart> reports;
|
||||
|
||||
public Long getSessionId() {
|
||||
public List<Long> getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(Long sessionId) {
|
||||
public void setSessionId(List<Long> sessionId) {
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue