fix export tri
This commit is contained in:
parent
c60e37d699
commit
43847b4a0a
2 changed files with 16 additions and 18 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package ru.spcex.clearing.dflt.management.listener;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -282,7 +283,7 @@ public class OrderCurrencyListener extends QueueConsumer implements Initializing
|
|||
BigDecimal n = transferDateService.numberOfDaysOfTransfer();
|
||||
LocalDate searchingValueDate = LocalDate.now().plusDays(n.longValue());
|
||||
Rates rates = imdgQueryService.getRate(pair.getBaseCurrency(), searchingValueDate);
|
||||
|
||||
BigDecimal rateValue = null;
|
||||
copyCommonFields(order1, swap);
|
||||
swap.setSecurityId(listing.getSecurityId());
|
||||
swap.setSecuritySymbol(listing.getSymbolCode());
|
||||
|
|
@ -290,7 +291,13 @@ public class OrderCurrencyListener extends QueueConsumer implements Initializing
|
|||
swap.setOvernightType(OvernightType.SWAP.getKey());
|
||||
swap.setMarket(market.getCode());
|
||||
swap.setPrice(safeBD(spotT1.getPrice()).subtract(safeBD(spotT0.getPrice())));
|
||||
swap.setBasePrice(safeBD(rates.getValue()));
|
||||
|
||||
if (rates != null) {
|
||||
rateValue = rates.getValue().setScale(listing.getPrecision().intValue(), RoundingMode.HALF_UP);
|
||||
} else {
|
||||
log.warn("Rates not found for listing {}", listing.getId());
|
||||
}
|
||||
swap.setBasePrice(safeBD(rateValue));
|
||||
swap.setCreated(Instant.now());
|
||||
return swap;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,22 +41,9 @@ public class OrderCurrencyTriExportService {
|
|||
* Возвращает содержимое tri-файла в виде строки.
|
||||
*/
|
||||
public String exportToTri(Collection<OrderCurrency> orders) {
|
||||
boolean allSuccess = true;
|
||||
List<String> rows = new ArrayList<>();
|
||||
for (OrderCurrency orderCurrency : orders) {
|
||||
String baseCurrency = resolveBaseRate(orderCurrency);
|
||||
if (OvernightType.SWAP.equalsByKey(orderCurrency.getOvernightType()) && baseCurrency == null) {
|
||||
allSuccess = false;
|
||||
}
|
||||
rows.add(toTriLine(orderCurrency, baseCurrency));
|
||||
}
|
||||
if (!allSuccess) {
|
||||
String comment = "При формировании файла с заявками не определен Базовый курс";
|
||||
NotificationNewRequest newReq = new NotificationNewRequest();
|
||||
newReq.setObjectType(ObjectType.rgst.getKey());
|
||||
newReq.setPriority(Priority.HIGH.getKey());
|
||||
newReq.setComment(comment);
|
||||
kafkaSender.sendRequestToQueue(Consts.NOTIFICATION_NEW, newReq);
|
||||
rows.add(toTriLine(orderCurrency));
|
||||
}
|
||||
return rows.stream()
|
||||
.reduce((a, b) -> a + System.lineSeparator() + b)
|
||||
|
|
@ -70,7 +57,7 @@ public class OrderCurrencyTriExportService {
|
|||
return exportToTri(orders).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private String toTriLine(OrderCurrency orderCurrency, String baseCurrency) {
|
||||
private String toTriLine(OrderCurrency orderCurrency) {
|
||||
StringJoiner joiner = new StringJoiner(";", "", ";");
|
||||
joiner.add("TRANS_ID=" + nullSafe(orderCurrency.getId()));
|
||||
joiner.add("CLASSCODE=" + nullSafe(orderCurrency.getMarket()));
|
||||
|
|
@ -86,7 +73,7 @@ public class OrderCurrencyTriExportService {
|
|||
joiner.add("Ссылка=");
|
||||
joiner.add("Код расчетов=" + nullSafe(orderCurrency.getSettleCode()));
|
||||
joiner.add("На заявку №=");
|
||||
joiner.add("Базовый курс=" + nullSafe(baseCurrency));
|
||||
joiner.add("Базовый курс=" + nullSafe(orderCurrency.getBasePrice()));
|
||||
|
||||
return joiner.toString();
|
||||
}
|
||||
|
|
@ -136,4 +123,8 @@ public class OrderCurrencyTriExportService {
|
|||
private String nullSafe(Object value) {
|
||||
return value == null ? "" : String.valueOf(value);
|
||||
}
|
||||
|
||||
private String nullSafe(BigDecimal value) {
|
||||
return value == null || BigDecimal.ZERO.compareTo(value) == 0 ? "" : formatDecimalStripZeroes(value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue