группировка registry с учетом market и groupId для шага 5 активной сессии
This commit is contained in:
parent
485b269dcf
commit
8b21e7aec2
2 changed files with 27 additions and 9 deletions
|
|
@ -0,0 +1,13 @@
|
|||
package ru.spcex.clearing.component;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import ru.clearing.classes.statics.data.registry.Registry;
|
||||
|
||||
public class GroupRgsKeyComparator implements Comparator<Map.Entry<GroupRgsKey, List<Registry>>> {
|
||||
@Override
|
||||
public int compare(Map.Entry<GroupRgsKey, List<Registry>> o1, Map.Entry<GroupRgsKey, List<Registry>> o2) {
|
||||
return o1.getKey().groupId().compareTo(o2.getKey().groupId());
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,8 @@ import org.springframework.context.annotation.Scope;
|
|||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||
import ru.clearing.classes.statics.data.registry.Registry;
|
||||
import ru.spcex.clearing.component.GroupRgsKey;
|
||||
import ru.spcex.clearing.component.GroupRgsKeyComparator;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.service.AssetTrio;
|
||||
import ru.spcex.clearing.service.integration.GatewayRequestCreator;
|
||||
|
|
@ -53,6 +55,7 @@ public class InspectionObligationsDepositReturn implements ISessionStage {
|
|||
private final TradingTimeService tradingTimeService;
|
||||
private final GatewayRequester gateway;
|
||||
private final PlanBalanceCalc planBalanceCalc;
|
||||
private static final GroupRgsKeyComparator groupRgsKeyComparator = new GroupRgsKeyComparator();
|
||||
|
||||
@Autowired
|
||||
public InspectionObligationsDepositReturn(ImdgProvider imdgProvider, RegistryManager rgsMng, AssetTBFProcessing assets, TradingTimeService tradingTimeService, GatewayRequester gateway, PlanBalanceCalc planBalanceCalc) {
|
||||
|
|
@ -97,27 +100,27 @@ public class InspectionObligationsDepositReturn implements ISessionStage {
|
|||
RegistryCodeSqlBuilder.getInstance(OS_T, OM_T, TS_T, TM_T).build(),
|
||||
RegistryStatus.POOL.getKey());
|
||||
|
||||
List<Map.Entry<Long, List<Registry>>> registriesByGroupSorted = registryImdg.getCollectionObjectsBySQL(sqlCondition)
|
||||
List<Map.Entry<GroupRgsKey, List<Registry>>> registriesByGroupSorted = registryImdg.getCollectionObjectsBySQL(sqlCondition)
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(Registry::getGroupId))
|
||||
.collect(Collectors.groupingBy(registry -> new GroupRgsKey(registry.getGroupId(), registry.getMarket())))
|
||||
.entrySet()
|
||||
.stream()
|
||||
.sorted(Map.Entry.comparingByKey())
|
||||
.sorted(groupRgsKeyComparator)
|
||||
.toList();
|
||||
log.info("registry groups found {}", registriesByGroupSorted.size());
|
||||
|
||||
for (Map.Entry<Long, List<Registry>> entry : registriesByGroupSorted) {
|
||||
for (Map.Entry<GroupRgsKey, List<Registry>> entry : registriesByGroupSorted) {
|
||||
List<Registry> group = entry.getValue();
|
||||
Optional<Registry> omtInGroupO = group.stream().filter(registry -> equalByRgs(OM_T, registry)).findFirst();
|
||||
Optional<Registry> tmtInGroupO = group.stream().filter(registry -> equalByRgs(TM_T, registry)).findFirst();
|
||||
if (omtInGroupO.isEmpty() || tmtInGroupO.isEmpty()) {
|
||||
log.error("groupId {} failed to find OM*T/TM*T registry", entry.getKey());
|
||||
log.error("groupId/market {}/{} failed to find OM*T/TM*T registry", entry.getKey().groupId(), entry.getKey().market());
|
||||
group.forEach(rgs -> updateStatus(rgs, registryStatusFailed())); // FAIL or MNG
|
||||
continue;
|
||||
}
|
||||
Registry omtRgs = omtInGroupO.get();
|
||||
Registry tmtRgs = tmtInGroupO.get();
|
||||
log.debug("groupId={}, OM*T.id={}", entry.getKey(), omtRgs.getId());
|
||||
log.debug("groupId={}, market={}, OM*T.id={}", entry.getKey().groupId(), entry.getKey().market(), omtRgs.getId());
|
||||
BigDecimal omtBalance = safeBD(omtRgs.getBalance());
|
||||
|
||||
//первая часть сделки депозита
|
||||
|
|
@ -150,18 +153,20 @@ public class InspectionObligationsDepositReturn implements ISessionStage {
|
|||
Optional<Registry> amfAssetO = searchAssetByOMT(omtRgs);
|
||||
Optional<Registry> amfAssetReceiverO = searchAssetByOMT(tmtRgs);
|
||||
if (amfAssetO.isEmpty()) {
|
||||
log.error("OM*T register.id={} groupId={} failed to find AM*F asset", omtRgs.getId(), entry.getKey());
|
||||
log.error("OM*T register.id={} groupId={}, market={} failed to find AM*F asset", omtRgs.getId(),
|
||||
entry.getKey().groupId(), entry.getKey().market());
|
||||
group.forEach(rgs -> updateStatus(rgs, registryStatusFailed())); // FAIL or MNG
|
||||
continue;
|
||||
}
|
||||
if (amfAssetReceiverO.isEmpty()) {
|
||||
log.error("TM*T register.id={} groupId={} failed to find AM*F asset", tmtRgs.getId(), entry.getKey());
|
||||
log.error("TM*T register.id={} groupId={}, market={} failed to find AM*F asset", tmtRgs.getId(),
|
||||
entry.getKey().groupId(), entry.getKey().market());
|
||||
group.forEach(rgs -> updateStatus(rgs, registryStatusFailed())); // FAIL or MNG
|
||||
continue;
|
||||
}
|
||||
|
||||
Registry amfAsset = amfAssetO.get();
|
||||
log.debug("groupId={}, AM*F.id={}", entry.getKey(), amfAsset.getId());
|
||||
log.debug("groupId={}, market={}, AM*F.id={}", entry.getKey().groupId(), entry.getKey().market(), amfAsset.getId());
|
||||
BigDecimal amfBalance = safeBD(amfAsset.getBalance());
|
||||
BiConsumer<Registry, BigDecimal> processAssetsAndSetSessionId = (amf, amount) -> {
|
||||
Optional<AssetTrio> asts = assets.processByAm_f(amf, amount);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue