This commit is contained in:
parent
09605b610d
commit
54e7a99b77
2 changed files with 30 additions and 26 deletions
|
|
@ -101,13 +101,13 @@ public class AccountBalanceService {
|
||||||
public void updateAccountBalanceByClearing(AccountBalanceClearingRequest req) {
|
public void updateAccountBalanceByClearing(AccountBalanceClearingRequest req) {
|
||||||
ClearingCategory category = getClearingCategoryByCompanyId(req.getCompanyId());
|
ClearingCategory category = getClearingCategoryByCompanyId(req.getCompanyId());
|
||||||
req.setFirstLegAmount(safeBD(req.getFirstLegAmount()));
|
req.setFirstLegAmount(safeBD(req.getFirstLegAmount()));
|
||||||
if (category.equals(ClearingCategory.I)) {
|
if (ClearingCategory.I.equals(category)) {
|
||||||
updateAccountCategoryIClrn(req.getAccountId(), req.getCompanyId(), req.getFirstLegAmount());
|
updateAccountCategoryIClrn(req.getAccountId(), req.getCompanyId(), req.getFirstLegAmount());
|
||||||
updateAccountCategoryITran(req.getFirstLegAmount());
|
updateAccountCategoryITran(req.getFirstLegAmount());
|
||||||
} else if (category.equals(ClearingCategory.V)) {
|
} else if (ClearingCategory.V.equals(category)) {
|
||||||
updateAccountCategoryVInfo(req.getAccountId(), req.getCompanyId(), req.getFirstLegAmount());
|
updateAccountCategoryVInfo(req.getAccountId(), req.getCompanyId(), req.getFirstLegAmount());
|
||||||
updateAccountCategoryVAnlt(req.getFirstLegAmount());
|
updateAccountCategoryVAnlt(req.getFirstLegAmount());
|
||||||
} else if (category.equals(ClearingCategory.B)) {
|
} else if (ClearingCategory.B.equals(category)) {
|
||||||
updateAccountCategoryBClrn(req.getAccountId(), req.getCompanyId(), req.getFirstLegAmount());
|
updateAccountCategoryBClrn(req.getAccountId(), req.getCompanyId(), req.getFirstLegAmount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,25 +59,7 @@ public class SdfCreatorBySTLDPayment {
|
||||||
Map.of("transactionStatus", TransactionStatus.stld.getKey()));
|
Map.of("transactionStatus", TransactionStatus.stld.getKey()));
|
||||||
log.info("Found {} PaymentInstruction by status {}", paymentInstructionFound.size(), TransactionStatus.stld.getKey());
|
log.info("Found {} PaymentInstruction by status {}", paymentInstructionFound.size(), TransactionStatus.stld.getKey());
|
||||||
/*Map<GroupWrapper, List<PaymentInstruction>> byOrder = */
|
/*Map<GroupWrapper, List<PaymentInstruction>> byOrder = */
|
||||||
List<Map.Entry<GroupWrapper, Collection<List<PaymentInstruction>>>> allEntries = paymentInstructionFound.stream().flatMap(paymentInstruction -> {
|
List<Map.Entry<GroupWrapper, Collection<List<PaymentInstruction>>>> allEntries = group(paymentInstructionFound);
|
||||||
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();
|
|
||||||
|
|
||||||
allEntries.forEach(entry -> {
|
allEntries.forEach(entry -> {
|
||||||
log.info("Group category {}, index {}", entry.getKey().category, entry.getKey().getSortIndex());
|
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) {
|
private void saveSdfAnSendToKafka(Long senderId, ClearingCategory category, List<PaymentInstruction> batch, Long generationId) {
|
||||||
SdfClearingRequest kafkaMessage = new SdfClearingRequest();
|
SdfClearingRequest kafkaMessage = new SdfClearingRequest();
|
||||||
kafkaMessage.setGroupId(generationId);
|
kafkaMessage.setGroupId(generationId);
|
||||||
|
|
@ -132,9 +136,9 @@ public class SdfCreatorBySTLDPayment {
|
||||||
log.debug("Send to kafka command, CategoryD={}, requestId={}", category, requestId);
|
log.debug("Send to kafka command, CategoryD={}, requestId={}", category, requestId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class GroupWrapper implements Comparable<GroupWrapper> {
|
public static class GroupWrapper implements Comparable<GroupWrapper> {
|
||||||
private Long senderId;
|
private final Long senderId;
|
||||||
private ClearingCategory category;
|
private final ClearingCategory category;
|
||||||
|
|
||||||
public GroupWrapper(ClearingCategory clearingCategory, Long senderId) {
|
public GroupWrapper(ClearingCategory clearingCategory, Long senderId) {
|
||||||
this.category = clearingCategory;
|
this.category = clearingCategory;
|
||||||
|
|
@ -174,7 +178,7 @@ public class SdfCreatorBySTLDPayment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClearingCategory getClearingCategory(PaymentInstruction paymentInstruction) {
|
ClearingCategory getClearingCategory(PaymentInstruction paymentInstruction) {
|
||||||
ClearingMemberCategory category = clearingMemberCategoryImdg.getSingleObjectByFieldValues(
|
ClearingMemberCategory category = clearingMemberCategoryImdg.getSingleObjectByFieldValues(
|
||||||
Map.of("companyId", paymentInstruction.getSenderId()));
|
Map.of("companyId", paymentInstruction.getSenderId()));
|
||||||
return IEnumKey.getEnumByKeyOrUndefined(ClearingCategory.class,
|
return IEnumKey.getEnumByKeyOrUndefined(ClearingCategory.class,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue