reports-service http://jira.mfd.msk:8088/browse/CLS-28 часть P2
This commit is contained in:
parent
f66c334100
commit
c7f6d097cc
5 changed files with 131 additions and 12 deletions
|
|
@ -45,10 +45,6 @@ public class ReportBR_0420314_P2 extends ReportWithPeriod {
|
||||||
@XStreamAlias("company_clearingCode")
|
@XStreamAlias("company_clearingCode")
|
||||||
protected String companyClearingCode;
|
protected String companyClearingCode;
|
||||||
|
|
||||||
@XStreamAsAttribute
|
|
||||||
@XStreamAlias("paymentInstruction_senderId")
|
|
||||||
private String paymentInstructionSenderId;
|
|
||||||
|
|
||||||
@XStreamAsAttribute
|
@XStreamAsAttribute
|
||||||
@XStreamAlias("profileDocument_id")
|
@XStreamAlias("profileDocument_id")
|
||||||
private String profileDocumentId;
|
private String profileDocumentId;
|
||||||
|
|
@ -70,14 +66,12 @@ public class ReportBR_0420314_P2 extends ReportWithPeriod {
|
||||||
private String accountBalanceCloseBalanceAmount;
|
private String accountBalanceCloseBalanceAmount;
|
||||||
|
|
||||||
public Info_0420314_P2(String companyClearingCode,
|
public Info_0420314_P2(String companyClearingCode,
|
||||||
String paymentInstructionSenderId,
|
|
||||||
String profileDocumentId,
|
String profileDocumentId,
|
||||||
String accountBalanceOpenBalanceAmount,
|
String accountBalanceOpenBalanceAmount,
|
||||||
String paymentInstructionCreditLegAmount,
|
String paymentInstructionCreditLegAmount,
|
||||||
String paymentInstructionDebitLegAmount,
|
String paymentInstructionDebitLegAmount,
|
||||||
String accountBalanceCloseBalanceAmount) {
|
String accountBalanceCloseBalanceAmount) {
|
||||||
this.companyClearingCode = companyClearingCode;
|
this.companyClearingCode = companyClearingCode;
|
||||||
this.paymentInstructionSenderId = paymentInstructionSenderId;
|
|
||||||
this.profileDocumentId = profileDocumentId;
|
this.profileDocumentId = profileDocumentId;
|
||||||
this.accountBalanceOpenBalanceAmount = accountBalanceOpenBalanceAmount;
|
this.accountBalanceOpenBalanceAmount = accountBalanceOpenBalanceAmount;
|
||||||
this.paymentInstructionCreditLegAmount = paymentInstructionCreditLegAmount;
|
this.paymentInstructionCreditLegAmount = paymentInstructionCreditLegAmount;
|
||||||
|
|
|
||||||
|
|
@ -48,11 +48,16 @@ public abstract class ReportDataCollector<T extends AbstractReport> {
|
||||||
|
|
||||||
protected String toString(BigDecimal val) {
|
protected String toString(BigDecimal val) {
|
||||||
if (val == null) return null;
|
if (val == null) return null;
|
||||||
return val.toString(); // todo есть ли требования на точность знаков?
|
return val.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String toString(Instant val) {
|
protected String toString(Instant val) {
|
||||||
if (val == null) return null;
|
if (val == null) return null;
|
||||||
return DATE_TIME_FORMATTER.format(val.atZone(ZoneId.systemDefault()));
|
return DATE_TIME_FORMATTER.format(val.atZone(ZoneId.systemDefault()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String toString(LocalDate date) {
|
||||||
|
if (date == null) return null;
|
||||||
|
return DATE_TIME_FORMATTER.format(date);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,6 @@ public class ReportsService {
|
||||||
|
|
||||||
ReportBR_0420314_P2 reportBR_0420314P2 = new ReportBR_0420314_P2(LocalDate.now(), LocalDate.now(), "transactionStatus", "BR");
|
ReportBR_0420314_P2 reportBR_0420314P2 = new ReportBR_0420314_P2(LocalDate.now(), LocalDate.now(), "transactionStatus", "BR");
|
||||||
ReportBR_0420314_P2.Info_0420314_P2 info_0420314P2 = new ReportBR_0420314_P2.Info_0420314_P2("companyClearingCode",
|
ReportBR_0420314_P2.Info_0420314_P2 info_0420314P2 = new ReportBR_0420314_P2.Info_0420314_P2("companyClearingCode",
|
||||||
"paymentInstructionSenderId",
|
|
||||||
"profileDocumentId",
|
"profileDocumentId",
|
||||||
"accountBalanceOpenBalanceAmt",
|
"accountBalanceOpenBalanceAmt",
|
||||||
"paymentInstructionCreditLegAmount",
|
"paymentInstructionCreditLegAmount",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,114 @@
|
||||||
|
package ru.spcex.clearing.reports.services.collector;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import ru.clearing.classes.statics.data.account.AccountBalance;
|
||||||
|
import ru.clearing.classes.statics.data.company.Company;
|
||||||
|
import ru.clearing.classes.statics.data.payment.PaymentInstruction;
|
||||||
|
import ru.clearing.classes.statics.data.profile.ProfileDocument;
|
||||||
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
import ru.spcex.clearing.reports.reports.bt_17_4.ReportBR_0420314_P2;
|
||||||
|
import ru.spcex.clearing.reports.services.ReportDataCollector;
|
||||||
|
import ru.spcex.platform.enumeration.AccountType;
|
||||||
|
import ru.spcex.platform.enumeration.DocumentTypes;
|
||||||
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* accountTransactionLiabilities
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class Repbr0420314_P2_bt_17_4_collector extends ReportDataCollector<ReportBR_0420314_P2> {
|
||||||
|
private Imdg<Company> companyImdg;
|
||||||
|
private Imdg<PaymentInstruction> paymentInstructionImdg;
|
||||||
|
private Imdg<AccountBalance> accountBalanceImdg;
|
||||||
|
private Imdg<ProfileDocument> profileDocumentImdg;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public Repbr0420314_P2_bt_17_4_collector(ImdgProvider imdgProvider) {
|
||||||
|
companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
|
paymentInstructionImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_PaymentInstruction, PaymentInstruction.class);
|
||||||
|
accountBalanceImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_AccountBalance, AccountBalance.class);
|
||||||
|
profileDocumentImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ProfileDocument, ProfileDocument.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ReportBR_0420314_P2 collectReportWithPeriod(LocalDate startDate, LocalDate endDate) {
|
||||||
|
validateDateRange(startDate, endDate);
|
||||||
|
|
||||||
|
ReportBR_0420314_P2 reportBR_0420312P2 = new ReportBR_0420314_P2(startDate, endDate,
|
||||||
|
"", "BR"
|
||||||
|
);
|
||||||
|
|
||||||
|
String ql = String.format("'%s' <= created and created <= '%s'",
|
||||||
|
startDate, endDate);
|
||||||
|
Collection<PaymentInstruction> paymentInstructionsAll = paymentInstructionImdg.getCollectionObjectsBySQL(ql);
|
||||||
|
|
||||||
|
Map<Long, List<PaymentInstruction>> companyIdPyPaymtInstruction =
|
||||||
|
MapUtil.indexList(paymentInstructionsAll, PaymentInstruction::getSenderId);
|
||||||
|
|
||||||
|
for (Map.Entry<Long, List<PaymentInstruction>> entry : companyIdPyPaymtInstruction.entrySet()) {
|
||||||
|
final Long companyId = entry.getKey();
|
||||||
|
List<PaymentInstruction> paymentInstructionsByCompany = entry.getValue();
|
||||||
|
Company company = companyImdg.getSingleObjectByID(companyId);
|
||||||
|
ProfileDocument profileDocumentCntr = profileDocumentImdg.getSingleObjectByFieldValues(Map.of(
|
||||||
|
"companyId", companyId,
|
||||||
|
"documentType", DocumentTypes.cntr.getKey()
|
||||||
|
));
|
||||||
|
AccountBalance accountBalance = accountBalanceImdg.getSingleObjectByFieldValues(Map.of(
|
||||||
|
"accountType", AccountType.Clrn.getKey(),
|
||||||
|
"companyId", companyId
|
||||||
|
));
|
||||||
|
|
||||||
|
String documentTypeStr = null;
|
||||||
|
if (profileDocumentCntr != null) {
|
||||||
|
documentTypeStr = profileDocumentCntr.getNumber();
|
||||||
|
if (profileDocumentCntr.getValidFromDate() != null) {
|
||||||
|
if (StringUtils.isEmpty(documentTypeStr)) {
|
||||||
|
documentTypeStr = "";
|
||||||
|
} else {
|
||||||
|
documentTypeStr += " ";
|
||||||
|
}
|
||||||
|
documentTypeStr += toString(profileDocumentCntr.getValidFromDate());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Long paymentInstruction_creditLeg_amount = paymentInstructionsByCompany.stream()
|
||||||
|
.map(PaymentInstruction::getCreditLegAmount)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.reduce(Long::sum)
|
||||||
|
.orElse(0L);
|
||||||
|
Long paymentInstructiont_debitLeg_amount = paymentInstructionsByCompany.stream()
|
||||||
|
.map(PaymentInstruction::getDebitLegAmount)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.reduce(Long::sum)
|
||||||
|
.orElse(0L);
|
||||||
|
|
||||||
|
|
||||||
|
ReportBR_0420314_P2.Info_0420314_P2 info_0420314P2 = new ReportBR_0420314_P2.Info_0420314_P2(
|
||||||
|
company.getClearingCode(),
|
||||||
|
documentTypeStr,
|
||||||
|
accountBalance == null ? null : toString(accountBalance.getOpenBalanceAmount()),
|
||||||
|
toString(paymentInstruction_creditLeg_amount),
|
||||||
|
toString(paymentInstructiont_debitLeg_amount),
|
||||||
|
accountBalance == null ? null : toString(accountBalance.getCloseBalanceAmount())
|
||||||
|
);
|
||||||
|
|
||||||
|
reportBR_0420312P2.getRows().add(info_0420314P2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return reportBR_0420312P2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<ReportBR_0420314_P2> getReportClass() {
|
||||||
|
return ReportBR_0420314_P2.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,20 +14,27 @@ class ReportDataCollectorTest extends ReportDataCollector {
|
||||||
@Test
|
@Test
|
||||||
void testToString() {
|
void testToString() {
|
||||||
ReportDataCollectorTest instance = new ReportDataCollectorTest();
|
ReportDataCollectorTest instance = new ReportDataCollectorTest();
|
||||||
assertEquals(null, instance.toString((Long)null));
|
assertEquals(null, instance.toString((Long) null));
|
||||||
assertEquals("1", instance.toString((Long)1L));
|
assertEquals("1", instance.toString((Long) 1L));
|
||||||
assertEquals("1230", instance.toString((Long)1230L));
|
assertEquals("1230", instance.toString((Long) 1230L));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testToString1() {
|
void testToString1() {
|
||||||
ReportDataCollectorTest instance = new ReportDataCollectorTest();
|
ReportDataCollectorTest instance = new ReportDataCollectorTest();
|
||||||
assertEquals(null, instance.toString((Instant)null));
|
assertEquals(null, instance.toString((Instant) null));
|
||||||
Instant val = Instant.ofEpochMilli(1672058774338L);
|
Instant val = Instant.ofEpochMilli(1672058774338L);
|
||||||
assertEquals("26.12.2022T15:46:14", instance.toString(val)); // msk timezone
|
assertEquals("26.12.2022T15:46:14", instance.toString(val)); // msk timezone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testToString2() {
|
||||||
|
ReportDataCollectorTest instance = new ReportDataCollectorTest();
|
||||||
|
LocalDate val = LocalDate.of(2022, 12, 26);
|
||||||
|
assertEquals("26.12.2022", instance.toString(val));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractReport collectReportWithPeriod(LocalDate startDate, LocalDate endDate) {
|
public AbstractReport collectReportWithPeriod(LocalDate startDate, LocalDate endDate) {
|
||||||
throw new IllegalStateException("test");
|
throw new IllegalStateException("test");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue