This commit is contained in:
AKurakin 2024-01-24 13:16:56 +03:00
parent 2572e7ea26
commit ad0d807b2c
6 changed files with 52 additions and 4 deletions

View file

@ -41,7 +41,10 @@ public class DepoPaymentInstructionRegisterReportBuilder extends XLSXReportBuild
protected DepoPaymentInstructionRegisterReport toRow(PaymentInstruction input) {
DepoPaymentInstructionRegisterReport entity = new DepoPaymentInstructionRegisterReport();
entity.setNumber(input.getId());
if (input.getSessionId() == null)
entity.setNumber(input.getId());
else
entity.setNumber(input.getSessionId());
entity.setDate(input.getClearingDate());
if (input.getCreated() != null) entity.setTime(LocalDateTime.from(input.getCreated().atZone(ZoneId.systemDefault())));

View file

@ -14,6 +14,7 @@ import ru.spcex.platform.enumeration.MoneyFlowSide;
import ru.spcex.platform.enumeration.Side;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgProvider;
import ru.spcex.platform.utils.number.BigDecimalUtil;
import java.time.LocalDateTime;
import java.time.ZoneId;
@ -117,7 +118,7 @@ public class ExecutionRegisterReportBuilder extends XLSXReportBuilder<ExecutionR
} else if (input instanceof ExecutionFond fond) {
entity.setSettlementDate(fond.getSettlementDate());
entity.setSecurity(fond.getSecuritySymbol());
entity.setAmount(fond.getSettlementAmount());
entity.setAmount(BigDecimalUtil.safeSumBD(fond.getSettlementAmount(), fond.getInterestAmount()));
entity.setQuantity(fond.getQuantity());
}

View file

@ -38,7 +38,10 @@ public class MoneyPaymentInstructionRegisterReportBuilder extends XLSXReportBuil
protected MoneyPaymentInstructionRegisterReport toRow(PaymentInstruction input) {
MoneyPaymentInstructionRegisterReport entity = new MoneyPaymentInstructionRegisterReport();
entity.setNumber(input.getId());
if (input.getSessionId() == null)
entity.setNumber(input.getId());
else
entity.setNumber(input.getSessionId());
entity.setDate(input.getClearingDate());
if (input.getCreated() != null) entity.setTime(LocalDateTime.from(input.getCreated().atZone(ZoneId.systemDefault())));

View file

@ -27,6 +27,7 @@ import ru.spcex.platform.enumeration.AccountType;
import ru.spcex.platform.enumeration.TransactionStatus;
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;
@ -110,7 +111,7 @@ public class DepoPaymentInstructionRegisterService extends QueueConsumer impleme
log.warn("Account id={} not found for paymentInstruction.id={}",
paymentInstruction.getCreditLeg_accountId(), paymentInstruction.getId());
else {
if (AccountType.Depo.equalsByKey(account.getAccountType())) {
if (IEnumKey.contains(account.getAccountType(), AccountType.Depo, AccountType.Dtrn)) {
depoPaymentInstructions.add(paymentInstruction);
}
}

View file

@ -23,6 +23,7 @@ public class BigDecimalUtil {
/**
* для парсинга вида '-00001234'/'00000123'
*
* @param number
* @return
*/
@ -44,6 +45,7 @@ public class BigDecimalUtil {
/**
* Для кейсов когда есть String поле с десятичной частью, и хотим ограничить число знаков после запятой
*
* @param fillZero - дополнить 0 если не хватает знаков дробной части
*/
public static String limitDecimalPlaces(String number, int decimalPlaces, boolean fillZero) {
@ -75,4 +77,24 @@ public class BigDecimalUtil {
return bd == null ? BigDecimal.ZERO : bd;
}
/**
* Null safe add:
*
* @param a nullable
* @param b nullable
* @return если оба числа null то результат ZERO, иначе сложит их.
*/
public static BigDecimal safeSumBD(BigDecimal a, BigDecimal b) {
if (b == null) {
if (a == null)
return BigDecimal.ZERO;
else
return a;
} else {
if (a == null)
return b;
else
return a.add(b);
}
}
}

View file

@ -3,6 +3,8 @@ package ru.spcex.platform.utils.number;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import static org.junit.jupiter.api.Assertions.*;
class BigDecimalUtilTest {
@ -21,4 +23,20 @@ class BigDecimalUtilTest {
Assertions.assertEquals("123.00", BigDecimalUtil.limitDecimalPlaces("123.", 2, true));
Assertions.assertEquals("123.00", BigDecimalUtil.limitDecimalPlaces("123", 2, true));
}
@Test
void safeBD() {
Assertions.assertEquals("1", BigDecimalUtil.safeBD(BigDecimal.ONE).toString());
Assertions.assertEquals("0", BigDecimalUtil.safeBD(null).toString());
}
@Test
void safeSumBD() {
Assertions.assertEquals("11", BigDecimalUtil.safeSumBD(BigDecimal.ONE, BigDecimal.TEN).toString());
Assertions.assertEquals("1", BigDecimalUtil.safeSumBD(BigDecimal.ONE, null).toString());
Assertions.assertEquals("10", BigDecimalUtil.safeSumBD(null, BigDecimal.TEN).toString());
Assertions.assertEquals("0", BigDecimalUtil.safeSumBD(null, null).toString());
}
}