http://jira.mfd.msk:8088/browse/CLS-358 GREF and GRET processing
This commit is contained in:
parent
d0d4c3a19f
commit
20f84b8311
4 changed files with 176 additions and 5 deletions
|
|
@ -172,6 +172,44 @@ public class ValidationConfig {
|
|||
};
|
||||
}
|
||||
|
||||
// todo оставил бин валидатора на будущее, если в дальнейшем придется проверять запрос. в текущей версии, по факту,
|
||||
// запрос не проверяется: в случае если sessionId не указан отчеты не строятся
|
||||
@Bean("reportRequestGRET")
|
||||
public Function<LauncherCommandRequest, IValidator> reportRequestGRETValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return launcherCommandRequest -> {
|
||||
ImdgValidationContext<LauncherCommandRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(launcherCommandRequest);
|
||||
return new ValidatorImpl<>(context,
|
||||
FieldRequiredRule.instance(
|
||||
"sessionId",
|
||||
LauncherCommandRequest::getSessionId,
|
||||
ReportError.RequiredFieldEmpty,
|
||||
false)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
// todo оставил бин валидатора на будущее, если в дальнейшем придется проверять запрос. в текущей версии, по факту,
|
||||
// запрос не проверяется: в случае если sessionId не указан отчеты не строятся
|
||||
@Bean("reportRequestGREF")
|
||||
public Function<LauncherCommandRequest, IValidator> reportRequestGREFValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return launcherCommandRequest -> {
|
||||
ImdgValidationContext<LauncherCommandRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(launcherCommandRequest);
|
||||
return new ValidatorImpl<>(context,
|
||||
FieldRequiredRule.instance(
|
||||
"sessionId",
|
||||
LauncherCommandRequest::getSessionId,
|
||||
ReportError.RequiredFieldEmpty,
|
||||
false)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class KSRepDepoNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
|
||||
@Override
|
||||
public ReportType getReportType() {
|
||||
return ReportType.KS_REP_CASH_NETTO;
|
||||
return ReportType.KS_REP_DEPO_NETTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class KSRepDepoRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
|
||||
@Override
|
||||
public ReportType getReportType() {
|
||||
return ReportType.KS_REP_CASH_REGISTERS;
|
||||
return ReportType.KS_REP_DEPO_REGISTERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
private final Function<ReportRequestWithSessionIdList, IValidator> reportRequestWithSessionIdListValidator;
|
||||
private final Function<ReportRequestWithPeriod, IValidator> reportRequestWithPeriodValidator;
|
||||
private final Function<LauncherCommandRequest, IValidator> reportRequestGREPValidator;
|
||||
private final Function<LauncherCommandRequest, IValidator> reportRequestGRETValidator;
|
||||
private final Function<LauncherCommandRequest, IValidator> reportRequestGREFValidator;
|
||||
private final Map<ReportType, List<CSVReportBuilder<EmptyParams>>> reportBuildersWithoutParams;
|
||||
private final Map<ReportType, List<CSVReportBuilder<SessionIdParam>>> reportBuildersWithSessionIdParam;
|
||||
private final Map<ReportType, List<CSVReportBuilder<SessionIdListParams>>> reportBuildersWithSessionIdListParam;
|
||||
|
|
@ -72,7 +74,11 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
@Qualifier("reportRequestWithPeriodValidator")
|
||||
Function<ReportRequestWithPeriod, IValidator> reportRequestWithPeriodValidator,
|
||||
@Qualifier("reportRequestGREP")
|
||||
Function<LauncherCommandRequest, IValidator> reportRequestGREPValidator) {
|
||||
Function<LauncherCommandRequest, IValidator> reportRequestGREPValidator,
|
||||
@Qualifier("reportRequestGRET")
|
||||
Function<LauncherCommandRequest, IValidator> reportRequestGRETValidator,
|
||||
@Qualifier("reportRequestGREF")
|
||||
Function<LauncherCommandRequest, IValidator> reportRequestGREFValidator) {
|
||||
super(kafkaQueue, kafkaResponseQueue);
|
||||
this.userRoleVerification = userRoleVerification;
|
||||
this.validationHelper = validationHelper;
|
||||
|
|
@ -85,6 +91,8 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
this.reportBuildersWithSessionIdListParam = reportBuildersWithSessionIdListParam;
|
||||
this.reportBuildersWithPeriodParams = reportBuildersWithPeriodParams;
|
||||
this.reportRequestGREPValidator = reportRequestGREPValidator;
|
||||
this.reportRequestGRETValidator = reportRequestGRETValidator;
|
||||
this.reportRequestGREFValidator = reportRequestGREFValidator;
|
||||
this.outFolder = new File(reportsServiceSettings.getReportModuleOut());
|
||||
assert outFolder.isDirectory();
|
||||
}
|
||||
|
|
@ -106,6 +114,12 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
callback(LauncherCommandRequest.class)
|
||||
.setFunction(this::createReportForGREP)
|
||||
.forDestination(Task.createReport_GREP.topic(), callbacks::put);
|
||||
callback(LauncherCommandRequest.class)
|
||||
.setFunction(this::createReportForGRET)
|
||||
.forDestination(Task.createDealsReport_GRET.topic(), callbacks::put);
|
||||
callback(LauncherCommandRequest.class)
|
||||
.setFunction(this::createReportForGREF)
|
||||
.forDestination(Task.createDealsReport_GREF.topic(), callbacks::put);
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
@ -257,7 +271,7 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
}
|
||||
|
||||
public RequestInfoUpdate createReportForGREP(BaseRequest<LauncherCommandRequest> userRequest) {
|
||||
log.debug("ReportRequestWithPeriod received");
|
||||
log.debug("GREP task received");
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return null;
|
||||
|
||||
|
|
@ -289,9 +303,12 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
Collection<List<CSVReportBuilder<SessionIdParam>>> buildersWithSessionIdParam = reportBuildersWithSessionIdParam.values();
|
||||
for (List<CSVReportBuilder<SessionIdParam>> builderList : buildersWithSessionIdParam) {
|
||||
for (CSVReportBuilder<SessionIdParam> builder : builderList) {
|
||||
// todo возможно, для тасков GRET/GREP/GREF стоит сделать отдельные коллекции с билдерами, чтобы не проверять эти условия
|
||||
if (
|
||||
builder.getReportType() == ReportType.OPERATIONAL_MONEY_CHANGE ||
|
||||
builder.getReportType() == ReportType.OPERATIONAL_LIABILITIES_CLAIMS
|
||||
builder.getReportType() == ReportType.OPERATIONAL_LIABILITIES_CLAIMS ||
|
||||
builder.getReportType() == ReportType.UNFULFILLED_DEAL_REPORT ||
|
||||
builder.getReportType() == ReportType.EXECUTED_DEAL_REPORT
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -347,6 +364,122 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
return null;
|
||||
}
|
||||
|
||||
public RequestInfoUpdate createReportForGRET(BaseRequest<LauncherCommandRequest> userRequest) {
|
||||
log.debug("GRET task received");
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return null;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, reportRequestGRETValidator);
|
||||
if (requestInfoUpdate != null) return null;
|
||||
|
||||
Long sessionId = userRequest.getRequestPayload().getSessionId();
|
||||
|
||||
logUnknownProperties(userRequest);
|
||||
|
||||
int cntErrors = 0;
|
||||
List<String> outFilenames = new ArrayList<>();
|
||||
|
||||
if (sessionId != null) {
|
||||
|
||||
Collection<List<CSVReportBuilder<SessionIdParam>>> buildersWithSessionIdParam = reportBuildersWithSessionIdParam.values();
|
||||
for (List<CSVReportBuilder<SessionIdParam>> builderList : buildersWithSessionIdParam) {
|
||||
for (CSVReportBuilder<SessionIdParam> builder : builderList) {
|
||||
// todo возможно, для тасков GRET/GREP/GREF стоит сделать отдельные коллекции с билдерами, чтобы не проверять эти условия
|
||||
if (
|
||||
builder.getReportType() != ReportType.UNFULFILLED_DEAL_REPORT &&
|
||||
builder.getReportType() != ReportType.EXECUTED_DEAL_REPORT
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
SessionIdParam sessionIdParam = new SessionIdParam();
|
||||
sessionIdParam.setSessionId(sessionId);
|
||||
File outFile = builder.createReport(sessionIdParam, outFolder);
|
||||
if (outFile == null) {
|
||||
log.warn("Something wrong, report type: {}", builder.getReportType().getKey());
|
||||
cntErrors++;
|
||||
continue;
|
||||
}
|
||||
outFilenames.add(outFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cntErrors == 0) log.debug("All reports successfully created. Output files: {}", String.join(", ", outFilenames));
|
||||
else log.debug("Some reports ({}) create failed. Output files: {}", cntErrors, String.join(", ", outFilenames));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public RequestInfoUpdate createReportForGREF(BaseRequest<LauncherCommandRequest> userRequest) {
|
||||
log.debug("GREF task received");
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return null;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, reportRequestGREFValidator);
|
||||
if (requestInfoUpdate != null) return null;
|
||||
|
||||
Long sessionId = userRequest.getRequestPayload().getSessionId();
|
||||
|
||||
logUnknownProperties(userRequest);
|
||||
|
||||
int cntErrors = 0;
|
||||
List<String> outFilenames = new ArrayList<>();
|
||||
|
||||
Collection<List<CSVReportBuilder<EmptyParams>>> buildersWithoutParams = reportBuildersWithoutParams.values();
|
||||
for (List<CSVReportBuilder<EmptyParams>> builderList : buildersWithoutParams) {
|
||||
for (CSVReportBuilder<EmptyParams> builder : builderList) {
|
||||
// todo возможно, для тасков GRET/GREP/GREF стоит сделать отдельные коллекции с билдерами, чтобы не проверять эти условия
|
||||
if (
|
||||
builder.getReportType() != ReportType.KS_REP_CASH_REGISTERS &&
|
||||
builder.getReportType() != ReportType.KS_REP_CASH_REGISTER_SUMS &&
|
||||
builder.getReportType() != ReportType.KS_REP_DEPO_REGISTERS &&
|
||||
builder.getReportType() != ReportType.KS_REP_DEPO_REGISTER_QUANTITIES &&
|
||||
builder.getReportType() != ReportType.KS_REP_TRADES &&
|
||||
builder.getReportType() != ReportType.KS_REP_FIRM_DETAILS
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
File outFile = builder.createReport(new EmptyParams(), outFolder);
|
||||
if (outFile == null) {
|
||||
log.warn("Something wrong, report type: {}", builder.getReportType().getKey());
|
||||
cntErrors++;
|
||||
continue;
|
||||
}
|
||||
outFilenames.add(outFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
if (sessionId != null) {
|
||||
Collection<List<CSVReportBuilder<SessionIdParam>>> buildersWithSessionIdParam = reportBuildersWithSessionIdParam.values();
|
||||
for (List<CSVReportBuilder<SessionIdParam>> builderList : buildersWithSessionIdParam) {
|
||||
for (CSVReportBuilder<SessionIdParam> builder : builderList) {
|
||||
// todo возможно, для тасков GRET/GREP/GREF стоит сделать отдельные коллекции с билдерами, чтобы не проверять эти условия
|
||||
if (
|
||||
builder.getReportType() != ReportType.KS_REP_CASH_NETTO &&
|
||||
builder.getReportType() != ReportType.KS_REP_DEPO_NETTO
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
SessionIdParam sessionIdParam = new SessionIdParam();
|
||||
sessionIdParam.setSessionId(sessionId);
|
||||
File outFile = builder.createReport(sessionIdParam, outFolder);
|
||||
if (outFile == null) {
|
||||
log.warn("Something wrong, report type: {}", builder.getReportType().getKey());
|
||||
cntErrors++;
|
||||
continue;
|
||||
}
|
||||
outFilenames.add(outFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cntErrors == 0) log.debug("All reports successfully created. Output files: {}", String.join(", ", outFilenames));
|
||||
else log.debug("Some reports ({}) create failed. Output files: {}", cntErrors, String.join(", ", outFilenames));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void logUnknownProperties(BaseRequest<?> request) {
|
||||
Map<String, Object> unknownProperties = request.getUnknownProperties();
|
||||
for (Map.Entry<String, Object> unknownProperty : unknownProperties.entrySet()) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue