группировка registry с учетом market и groupId для шага 7 активной сессии
This commit is contained in:
parent
d27b7d003d
commit
bd2d8fcc58
4 changed files with 14 additions and 26 deletions
|
|
@ -2,12 +2,12 @@ package ru.spcex.clearing.component;
|
|||
|
||||
import java.util.Objects;
|
||||
|
||||
public record GroupingRegistryKey(Long groupId, String market) {
|
||||
public record GroupRgsKey(Long groupId, String market) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
GroupingRegistryKey that = (GroupingRegistryKey) o;
|
||||
GroupRgsKey that = (GroupRgsKey) o;
|
||||
return Objects.equals(groupId, that.groupId) && Objects.equals(market, that.market);
|
||||
}
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ import ru.clearing.classes.statics.data.registry.Registry;
|
|||
import ru.clearing.classes.statics.data.sdf.SDf03;
|
||||
import ru.clearing.classes.statics.data.sdf.SDf12;
|
||||
import ru.clearing.classes.statics.data.security.Security;
|
||||
import ru.spcex.clearing.component.GroupingRegistryKey;
|
||||
import ru.spcex.clearing.component.GroupRgsKey;
|
||||
import ru.spcex.clearing.error.ClearingError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
|
@ -161,14 +161,15 @@ public class FormingPaymentInstructionSecurities implements ISessionStage {
|
|||
Collection<Registry> registries = selectSecurityRegistries(sessionId);
|
||||
log.debug("found registries.size() = {}", registries.size());
|
||||
//группируем регистры по groupId и market
|
||||
Map<GroupingRegistryKey, List<Registry>> groups = registries
|
||||
Map<GroupRgsKey, List<Registry>> groups = registries
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(r -> new GroupingRegistryKey(r.getGroupId(), r.getMarket())));
|
||||
.collect(Collectors.groupingBy(r -> new GroupRgsKey(r.getGroupId(), r.getMarket())));
|
||||
|
||||
log.debug("groups.size = {}", groups.size());
|
||||
Map<Long, PaymentGroup> lstGroups = RegistryLiabilitiesGroup.group(groups);
|
||||
for (Map.Entry<GroupingRegistryKey, List<Registry>> group : groups.entrySet()) {
|
||||
for (Map.Entry<GroupRgsKey, List<Registry>> group : groups.entrySet()) {
|
||||
Long groupId = group.getKey().groupId();
|
||||
String market = group.getKey().market();
|
||||
Function<RegistryTradingParams, Registry> findByCode = rgsCode -> group.getValue()
|
||||
.stream()
|
||||
.filter(rgs -> RegistryManager.equalsByCode(rgsCode, rgs))
|
||||
|
|
@ -178,12 +179,12 @@ public class FormingPaymentInstructionSecurities implements ISessionStage {
|
|||
Registry cs_t = findByCode.apply(RegistryTradingParams.TS_T);
|
||||
Registry ls_t = findByCode.apply(RegistryTradingParams.OS_T);
|
||||
if (cs_t == null || ls_t == null) {
|
||||
log.error("groupId {} cmt_t {} ls_t {} - both must be present", groupId, cs_t, ls_t);
|
||||
log.error("groupId/market {}/{} cmt_t {} ls_t {} - both must be present", groupId, market, cs_t, ls_t);
|
||||
continue;
|
||||
}
|
||||
PaymentGroup ls_t_group = lstGroups.get(ls_t.getId());
|
||||
if (ls_t_group == null) {
|
||||
log.debug("groupId {} cmt_t {} ls_t {} were included in a group, skipping", groupId, cs_t, ls_t);
|
||||
log.debug("groupId/market {}/{} cmt_t {} ls_t {} were included in a group, skipping", groupId, market, cs_t, ls_t);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +195,7 @@ public class FormingPaymentInstructionSecurities implements ISessionStage {
|
|||
AS_T
|
||||
);
|
||||
payerAstO.ifPresent(as_t -> {
|
||||
log.debug("groupId {} cmt_t {} ls_t {} changing AS*T.id={} sender", groupId, cs_t, ls_t, as_t.getId());
|
||||
log.debug("groupId/market {}/{} cmt_t {} ls_t {} changing AS*T.id={} sender", groupId, market, cs_t, ls_t, as_t.getId());
|
||||
as_t.setSettledDebit(safeBD(as_t.getSettledDebit()).add(safeBD(ls_t_group.getSum())));
|
||||
setUpdatedStoreInImdg(as_t, now);
|
||||
});
|
||||
|
|
@ -205,7 +206,7 @@ public class FormingPaymentInstructionSecurities implements ISessionStage {
|
|||
AS_T
|
||||
);
|
||||
receiverAstO.ifPresent(as_t -> {
|
||||
log.debug("groupId {} cmt_t {} ls_t {} changing AS*T.id={} receiver", groupId, cs_t, ls_t, as_t.getId());
|
||||
log.debug("groupId/market {}/{} cmt_t {} ls_t {} changing AS*T.id={} receiver", groupId, market, cs_t, ls_t, as_t.getId());
|
||||
as_t.setSettledCredit(safeBD(as_t.getSettledCredit()).add(safeBD(ls_t_group.getSum())));
|
||||
setUpdatedStoreInImdg(as_t, now);
|
||||
});
|
||||
|
|
@ -238,7 +239,7 @@ public class FormingPaymentInstructionSecurities implements ISessionStage {
|
|||
|
||||
paymentInstructionImdg.insert(pmt);
|
||||
paymentInstructionAll.add(pmt);
|
||||
log.trace("generated PaymentInstructions for groupId {}: pmtInstr.id={}", groupId, pmt.getId());
|
||||
log.trace("generated PaymentInstructions for groupId/market {}/{}: pmtInstr.id={}", groupId, market, pmt.getId());
|
||||
}
|
||||
}
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import java.util.stream.Collectors;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.clearing.classes.statics.data.registry.Registry;
|
||||
import ru.spcex.clearing.component.GroupingRegistryKey;
|
||||
import ru.spcex.clearing.component.GroupRgsKey;
|
||||
import ru.spcex.clearing.service.registry.RegistryManager;
|
||||
import ru.spcex.platform.enumeration.RegistryTradingParams;
|
||||
import static ru.spcex.platform.enumeration.RegistryTradingParams.OS_T;
|
||||
|
|
@ -22,7 +22,7 @@ import ru.spcex.platform.utils.text.TextUtil;
|
|||
public class RegistryLiabilitiesGroup {
|
||||
private static final Logger log = LoggerFactory.getLogger(RegistryLiabilitiesGroup.class);
|
||||
|
||||
public static Map<Long, PaymentGroup> group(Map<GroupingRegistryKey, List<Registry>> registriesCollection) {
|
||||
public static Map<Long, PaymentGroup> group(Map<GroupRgsKey, List<Registry>> registriesCollection) {
|
||||
Map<Long, PaymentGroup> result = new HashMap<>();
|
||||
List<Pair<Registry, Registry>> lstCstGroup = registriesCollection.entrySet()
|
||||
.stream()
|
||||
|
|
|
|||
|
|
@ -57,17 +57,4 @@ public class RegistryUtil {
|
|||
newRgsCde.setCharAt(2, '-');
|
||||
return newRgsCde.toString();
|
||||
}
|
||||
|
||||
public static Map<Long, List<Registry>> groupByGroupId(Collection<Registry> registries) {
|
||||
HashMap<Long, List<Registry>> groups = new HashMap<>();
|
||||
for (Registry reg : registries) {
|
||||
List<Registry> lst = groups.get(reg.getGroupId());
|
||||
if (lst == null) {
|
||||
lst = new ArrayList<>();
|
||||
groups.put(reg.getGroupId(), lst);
|
||||
}
|
||||
lst.add(reg);
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue