This commit is contained in:
AKurakin 2022-12-29 16:51:58 +03:00
parent f66c334100
commit c7f6d097cc
5 changed files with 131 additions and 12 deletions

View file

@ -45,10 +45,6 @@ public class ReportBR_0420314_P2 extends ReportWithPeriod {
@XStreamAlias("company_clearingCode")
protected String companyClearingCode;
@XStreamAsAttribute
@XStreamAlias("paymentInstruction_senderId")
private String paymentInstructionSenderId;
@XStreamAsAttribute
@XStreamAlias("profileDocument_id")
private String profileDocumentId;
@ -70,14 +66,12 @@ public class ReportBR_0420314_P2 extends ReportWithPeriod {
private String accountBalanceCloseBalanceAmount;
public Info_0420314_P2(String companyClearingCode,
String paymentInstructionSenderId,
String profileDocumentId,
String accountBalanceOpenBalanceAmount,
String paymentInstructionCreditLegAmount,
String paymentInstructionDebitLegAmount,
String accountBalanceCloseBalanceAmount) {
this.companyClearingCode = companyClearingCode;
this.paymentInstructionSenderId = paymentInstructionSenderId;
this.profileDocumentId = profileDocumentId;
this.accountBalanceOpenBalanceAmount = accountBalanceOpenBalanceAmount;
this.paymentInstructionCreditLegAmount = paymentInstructionCreditLegAmount;

View file

@ -48,11 +48,16 @@ public abstract class ReportDataCollector<T extends AbstractReport> {
protected String toString(BigDecimal val) {
if (val == null) return null;
return val.toString(); // todo есть ли требования на точность знаков?
return val.toString();
}
protected String toString(Instant val) {
if (val == null) return null;
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);
}
}

View file

@ -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.Info_0420314_P2 info_0420314P2 = new ReportBR_0420314_P2.Info_0420314_P2("companyClearingCode",
"paymentInstructionSenderId",
"profileDocumentId",
"accountBalanceOpenBalanceAmt",
"paymentInstructionCreditLegAmount",

View file

@ -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;
}
}

View file

@ -14,20 +14,27 @@ class ReportDataCollectorTest extends ReportDataCollector {
@Test
void testToString() {
ReportDataCollectorTest instance = new ReportDataCollectorTest();
assertEquals(null, instance.toString((Long)null));
assertEquals("1", instance.toString((Long)1L));
assertEquals("1230", instance.toString((Long)1230L));
assertEquals(null, instance.toString((Long) null));
assertEquals("1", instance.toString((Long) 1L));
assertEquals("1230", instance.toString((Long) 1230L));
}
@Test
void testToString1() {
ReportDataCollectorTest instance = new ReportDataCollectorTest();
assertEquals(null, instance.toString((Instant)null));
assertEquals(null, instance.toString((Instant) null));
Instant val = Instant.ofEpochMilli(1672058774338L);
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
public AbstractReport collectReportWithPeriod(LocalDate startDate, LocalDate endDate) {
throw new IllegalStateException("test");