ialbert 2023-02-07 13:15:42 +03:00
parent 09605b610d
commit 54e7a99b77
2 changed files with 30 additions and 26 deletions

View file

@ -101,13 +101,13 @@ public class AccountBalanceService {
public void updateAccountBalanceByClearing(AccountBalanceClearingRequest req) {
ClearingCategory category = getClearingCategoryByCompanyId(req.getCompanyId());
req.setFirstLegAmount(safeBD(req.getFirstLegAmount()));
if (category.equals(ClearingCategory.I)) {
if (ClearingCategory.I.equals(category)) {
updateAccountCategoryIClrn(req.getAccountId(), req.getCompanyId(), req.getFirstLegAmount());
updateAccountCategoryITran(req.getFirstLegAmount());
} else if (category.equals(ClearingCategory.V)) {
} else if (ClearingCategory.V.equals(category)) {
updateAccountCategoryVInfo(req.getAccountId(), req.getCompanyId(), req.getFirstLegAmount());
updateAccountCategoryVAnlt(req.getFirstLegAmount());
} else if (category.equals(ClearingCategory.B)) {
} else if (ClearingCategory.B.equals(category)) {
updateAccountCategoryBClrn(req.getAccountId(), req.getCompanyId(), req.getFirstLegAmount());
}
}

View file

@ -59,25 +59,7 @@ public class SdfCreatorBySTLDPayment {
Map.of("transactionStatus", TransactionStatus.stld.getKey()));
log.info("Found {} PaymentInstruction by status {}", paymentInstructionFound.size(), TransactionStatus.stld.getKey());
/*Map<GroupWrapper, List<PaymentInstruction>> byOrder = */
List<Map.Entry<GroupWrapper, Collection<List<PaymentInstruction>>>> allEntries = paymentInstructionFound.stream().flatMap(paymentInstruction -> {
ClearingCategory clearingCategory = getClearingCategory(paymentInstruction);
Long senderId = paymentInstruction.getSenderId();
if (senderId == null) {
return Stream.empty();
} else {
return Stream.of(new Pair<>(new GroupWrapper(clearingCategory, senderId), paymentInstruction));
}
//группируем по equals/hashCode группы
}).collect(Collectors.groupingBy(Pair::getFirst, Collectors.mapping(Pair::getSecond, Collectors.toList())))
.entrySet()
.stream()
//сортируем по группе compareTo
.sorted(Map.Entry.comparingByKey())
//преобразуем поток entry<group, list<paymentInstruction>>, разбиваем список на группы по senderId
.map((Function<Map.Entry<GroupWrapper, List<PaymentInstruction>>, Map.Entry<GroupWrapper, Collection<List<PaymentInstruction>>>>) entry -> {
Collection<List<PaymentInstruction>> values = entry.getValue().stream().collect(Collectors.groupingBy(PaymentInstruction::getSenderId)).values();
return new AbstractMap.SimpleEntry<>(entry.getKey(), values);
}).toList();
List<Map.Entry<GroupWrapper, Collection<List<PaymentInstruction>>>> allEntries = group(paymentInstructionFound);
allEntries.forEach(entry -> {
log.info("Group category {}, index {}", entry.getKey().category, entry.getKey().getSortIndex());
@ -112,6 +94,28 @@ public class SdfCreatorBySTLDPayment {
});
}
public List<Map.Entry<GroupWrapper, Collection<List<PaymentInstruction>>>> group(Collection<PaymentInstruction> payments) {
return payments.stream().flatMap(paymentInstruction -> {
ClearingCategory clearingCategory = getClearingCategory(paymentInstruction);
Long senderId = paymentInstruction.getSenderId();
if (senderId == null) {
return Stream.empty();
} else {
return Stream.of(new Pair<>(new GroupWrapper(clearingCategory, senderId), paymentInstruction));
}
//группируем по equals/hashCode группы
}).collect(Collectors.groupingBy(Pair::getFirst, Collectors.mapping(Pair::getSecond, Collectors.toList())))
.entrySet()
.stream()
//сортируем по группе compareTo
.sorted(Map.Entry.comparingByKey())
//преобразуем поток entry<group, list<paymentInstruction>>, разбиваем список на группы по senderId
.map((Function<Map.Entry<GroupWrapper, List<PaymentInstruction>>, Map.Entry<GroupWrapper, Collection<List<PaymentInstruction>>>>) entry -> {
Collection<List<PaymentInstruction>> values = entry.getValue().stream().collect(Collectors.groupingBy(PaymentInstruction::getSenderId)).values();
return new AbstractMap.SimpleEntry<>(entry.getKey(), values);
}).toList();
}
private void saveSdfAnSendToKafka(Long senderId, ClearingCategory category, List<PaymentInstruction> batch, Long generationId) {
SdfClearingRequest kafkaMessage = new SdfClearingRequest();
kafkaMessage.setGroupId(generationId);
@ -132,9 +136,9 @@ public class SdfCreatorBySTLDPayment {
log.debug("Send to kafka command, CategoryD={}, requestId={}", category, requestId);
}
private static class GroupWrapper implements Comparable<GroupWrapper> {
private Long senderId;
private ClearingCategory category;
public static class GroupWrapper implements Comparable<GroupWrapper> {
private final Long senderId;
private final ClearingCategory category;
public GroupWrapper(ClearingCategory clearingCategory, Long senderId) {
this.category = clearingCategory;
@ -174,7 +178,7 @@ public class SdfCreatorBySTLDPayment {
}
}
private ClearingCategory getClearingCategory(PaymentInstruction paymentInstruction) {
ClearingCategory getClearingCategory(PaymentInstruction paymentInstruction) {
ClearingMemberCategory category = clearingMemberCategoryImdg.getSingleObjectByFieldValues(
Map.of("companyId", paymentInstruction.getSenderId()));
return IEnumKey.getEnumByKeyOrUndefined(ClearingCategory.class,