fix stage 5
This commit is contained in:
parent
5daab77c0a
commit
79637d1bd9
1 changed files with 36 additions and 46 deletions
|
|
@ -20,10 +20,7 @@ import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||||
import ru.spcex.platform.utils.enumeration.SimpleMessageResolver;
|
import ru.spcex.platform.utils.enumeration.SimpleMessageResolver;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -74,9 +71,7 @@ public class InspectionObligations implements ISessionStage {
|
||||||
case InspectionObligations -> {
|
case InspectionObligations -> {
|
||||||
return inspectionObligations();
|
return inspectionObligations();
|
||||||
}
|
}
|
||||||
default -> {
|
default -> throw new IllegalStateException("Unknown task type: " + task.getTaskType());
|
||||||
throw new IllegalStateException("Unknown task type: " + task.getTaskType());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,29 +92,27 @@ public class InspectionObligations implements ISessionStage {
|
||||||
obligationsInGroup.stream()
|
obligationsInGroup.stream()
|
||||||
.map(Registry::getId).collect(Collectors.toList()),
|
.map(Registry::getId).collect(Collectors.toList()),
|
||||||
entry.getKey());
|
entry.getKey());
|
||||||
boolean isFail = false;
|
boolean isUncovered = false;
|
||||||
Optional<Registry> firstUncoveredRegistry = Optional.empty();
|
List<CheckResult> checkResults = new ArrayList<>();
|
||||||
for (Registry obligation : obligationsInGroup) {
|
for (Registry obligation : obligationsInGroup) {
|
||||||
String sqlAssetRegistryCondition = searchAssetsByObligationSql(obligation);
|
String sqlAssetRegistryCondition = searchAssetsByObligationSql(obligation);
|
||||||
log.debug("search asset by registry.id={} sql {}", sqlAssetRegistryCondition, obligation.getId());
|
log.debug("search asset by registry.id={} sql {}", sqlAssetRegistryCondition, obligation.getId());
|
||||||
Registry counter = registryImdg.getSingleObjectBySQL(sqlAssetRegistryCondition);
|
Registry asset = registryImdg.getSingleObjectBySQL(sqlAssetRegistryCondition);
|
||||||
if (counter == null) {
|
if (asset == null) {
|
||||||
log.warn("Not found asset by registry.id={}", obligation.getId());
|
log.warn("Not found asset by registry.id={}", obligation.getId());
|
||||||
isFail = true;
|
isUncovered = true;
|
||||||
firstUncoveredRegistry = Optional.of(obligation);
|
} else if (obligation.getBalance().compareTo(asset.getBalance()) > 0) {
|
||||||
break;
|
if (obligation.getBalance().compareTo(asset.getBalance()) > 0) {
|
||||||
}
|
log.warn("groupId: {}: {}", obligation.getGroupId(),
|
||||||
if (obligation.getBalance().compareTo(counter.getBalance()) > 0) {
|
msgResolver.resolve(new EnumMessage(ClearingError.InsecurityObligation, obligation.getCompanyId())));
|
||||||
log.warn("groupId: {}: {}", obligation.getGroupId(),
|
isUncovered = true;
|
||||||
msgResolver.resolve(new EnumMessage(ClearingError.InsecurityObligation, obligation.getCompanyId())));
|
}
|
||||||
isFail = true;
|
|
||||||
firstUncoveredRegistry = Optional.of(obligation);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
checkResults.add(new CheckResult(obligation, isUncovered));
|
||||||
}
|
}
|
||||||
|
defineStatusAndUpdateRegistry(checkResults, group);
|
||||||
defineStatusAndUpdateRegistry(group, firstUncoveredRegistry, isFail);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new StageResult(null, true);
|
return new StageResult(null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,31 +139,25 @@ public class InspectionObligations implements ISessionStage {
|
||||||
return sqlCounterRegistryCondition;
|
return sqlCounterRegistryCondition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void defineStatusAndUpdateRegistry(List<CheckResult> checkResults, List<Registry> registries) {
|
||||||
private void defineStatusAndUpdateRegistry(List<Registry> registries, Optional<Registry> firstUncoveredRegistry, boolean isFail) {
|
boolean isOneUncovered = checkResults.stream().anyMatch(checkResult -> checkResult.isUncovered);
|
||||||
if (isFail) {
|
if (isOneUncovered) {
|
||||||
Registry uncoveredRegistry = firstUncoveredRegistry.get();
|
for (CheckResult checkResult : checkResults){
|
||||||
updateRegistryStatus(uncoveredRegistry, RegistryStatus.UNCV);
|
Optional<Registry> tRegistryWithSameCompany = registries.stream().filter(registry ->
|
||||||
|
registry.getCompanyId().equals(checkResult.registry.getCompanyId()) &&
|
||||||
Optional<Registry> sameRegistryWithOtherCompany = registries.stream().filter(registry ->
|
!registry.getRegistryDesignation().equals(checkResult.registry.getRegistryDesignation())
|
||||||
!registry.getCompanyId().equals(uncoveredRegistry.getCompanyId()) &&
|
).findFirst();
|
||||||
registry.getRegistryDesignation().equals(uncoveredRegistry.getRegistryDesignation())
|
if (checkResult.isUncovered){
|
||||||
).findFirst();
|
updateRegistryStatus(checkResult.registry, RegistryStatus.UNCV);
|
||||||
sameRegistryWithOtherCompany.ifPresent(registry -> {
|
tRegistryWithSameCompany.ifPresent(registry -> updateRegistryStatus(registry, RegistryStatus.FAIL));
|
||||||
updateRegistryStatus(registry, RegistryStatus.UNCV);
|
} else {
|
||||||
});
|
updateRegistryStatus(checkResult.registry, RegistryStatus.FAIL);
|
||||||
|
tRegistryWithSameCompany.ifPresent(registry -> updateRegistryStatus(registry, RegistryStatus.FAIL));
|
||||||
Collection<Registry> otherRegistry = registries.stream().filter(registry ->
|
}
|
||||||
!registry.getRegistryDesignation().equals(uncoveredRegistry.getRegistryDesignation())).toList();
|
}
|
||||||
otherRegistry.forEach(registry -> {
|
|
||||||
updateRegistryStatus(registry, RegistryStatus.FAIL);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
registries.forEach(registry -> {
|
registries.forEach(registry -> updateRegistryStatus(registry, RegistryStatus.OK));
|
||||||
updateRegistryStatus(registry, RegistryStatus.OK);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRegistryStatus(Registry registry, RegistryStatus registryStatus) {
|
private void updateRegistryStatus(Registry registry, RegistryStatus registryStatus) {
|
||||||
|
|
@ -179,4 +166,7 @@ public class InspectionObligations implements ISessionStage {
|
||||||
registry.setUpdated(Instant.now());
|
registry.setUpdated(Instant.now());
|
||||||
registryImdg.update(registry);
|
registryImdg.update(registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record CheckResult(Registry registry, boolean isUncovered) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue