etreschenkov 2023-05-29 17:52:20 +03:00
parent 1775ababa1
commit 0390f3d20e
3 changed files with 75 additions and 53 deletions

View file

@ -45,10 +45,13 @@ public class PaymentInstructionBuilder {
"companyId", registry.getCompanyId(), "companyId", registry.getCompanyId(),
"companySymbol", CompanySymbol.BIC.getKey()) "companySymbol", CompanySymbol.BIC.getKey())
); );
CompanySymbols counterCompanySymbols = companySymbolsImdg.getSingleObjectByFieldValues(Map.of( CompanySymbols counterCompanySymbols = null;
"companyId", registry.getCounterPartyId(), if (registry.getCounterPartyId() != null) {
"companySymbol", CompanySymbol.BIC.getKey()) counterCompanySymbols = companySymbolsImdg.getSingleObjectByFieldValues(Map.of(
); "companyId", registry.getCounterPartyId(),
"companySymbol", CompanySymbol.BIC.getKey())
);
}
if (companySymbols != null) { if (companySymbols != null) {
paymentInstruction.setPayeeBic(companySymbols.getCompanySymbolValue()); paymentInstruction.setPayeeBic(companySymbols.getCompanySymbolValue());

View file

@ -4,56 +4,56 @@ import ru.spcex.platform.utils.enumeration.IEnumKey;
public enum TaskType implements IEnumKey { public enum TaskType implements IEnumKey {
/** /**
* step 0 * step 0/9
*/ */
StartRevise("rev"), StartRevise("CLR0"),
ContinueRevise("s-1"), ContinueRevise("CLR 0_0"),
/** /**
* step 1 * step 1
*/ */
DealsPrepare("s-2"), DealsPrepare("CL01"),
/** /**
* step 2 * step 2
*/ */
RequirementsAndObligationsCreate("s-3"), RequirementsAndObligationsCreate("CL02"),
/** /**
* step 3 * step 3
*/ */
ObligationsAdmission("s-4"), ObligationsAdmission("CL03"),
/** /**
* step 4 * step 4
*/ */
InclusionToPool("s-5"), InclusionToPool("CL04"),
/** /**
* step 5 * step 5
*/ */
InspectionObligations("S-6"), InspectionObligations("CL05"),
/** /**
* Step 6: forming Registry on Obligations and Settlement requirements * Step 6: forming Registry on Obligations and Settlement requirements
*/ */
FormingRegistersOnOS("s-7"), FormingRegistersOnOS("CL06"),
/** /**
* step 7 * step 7
*/ */
FormingPaymentInstruction("s-8"), FormingPaymentInstruction("CL07"),
/** /**
* step 8 * step 8
*/ */
UnlockResources("unlc"), UnlockResources("CL08"),
// /**
// * step 0/9
// */
// AgainRevise("CL09"),
/** /**
* Step 10 * Step 10
*/ */
FinishingSession("s-10"), FinishingSession("CL10"),
/** /**
* Step 11 * Step 11
*/ */
EndStageNotification("s-11"); EndStageNotification("CL11");
private String key; private String key;

View file

@ -65,63 +65,82 @@ public class InspectionObligations implements ISessionStage {
RegistryInstrumentType.S, RegistryInstrumentType.S,
null, null,
RegistryUnit.T); RegistryUnit.T);
RegistryTradingParams registryTradingParamsOMT = new RegistryTradingParams(RegistryDesignation.O,
RegistryInstrumentType.M,
null,
RegistryUnit.T);
RegistryTradingParams registryTradingParamsTMT = new RegistryTradingParams(RegistryDesignation.T, RegistryTradingParams registryTradingParamsTMT = new RegistryTradingParams(RegistryDesignation.T,
RegistryInstrumentType.M, RegistryInstrumentType.M,
null, null,
RegistryUnit.T); RegistryUnit.T);
String sqlCondition = String.format("%s and registryStatus = '%s'", String sqlCondition = String.format("%s and registryStatus = '%s'",
RegistryCodeSqlBuilder.getInstance(registryTradingParamsOST, registryTradingParamsTMT).build(), RegistryCodeSqlBuilder.getInstance(registryTradingParamsOST, registryTradingParamsTMT, registryTradingParamsOMT).build(),
RegistryStatus.POOL.getKey()); RegistryStatus.POOL.getKey());
Collection<Registry> obligations = registryImdg.getCollectionObjectsBySQL(sqlCondition); Collection<Registry> obligations = registryImdg.getCollectionObjectsBySQL(sqlCondition);
Map<Long, Map<Long, List<Registry>>> registryByGroupIdAndCompanyId = obligations.stream(). Map<Long, List<Registry>> registryByGroupIdAndCompanyId = obligations.stream().
collect(Collectors.groupingBy(Registry::getGroupId, Collectors.groupingBy(Registry::getCompanyId))); collect(Collectors.groupingBy(Registry::getGroupId));
List<Long> insecurityGroups = new ArrayList<>(); List<Long> insecurityGroups = new ArrayList<>();
List<Long> alreadyUpdatedToUncover = new ArrayList<>();
for (Registry currentRegistry : obligations) { for (Registry currentRegistry : obligations) {
if (insecurityGroups.contains(currentRegistry.getGroupId())) { if (insecurityGroups.contains(currentRegistry.getGroupId())) {
log.debug("Skip insecurity groupId: {}", currentRegistry.getGroupId()); log.debug("Skip insecurity groupId: {}", currentRegistry.getGroupId());
continue; continue;
} }
if (IEnumKey.getEnumByKey(RegistryDesignation.class, currentRegistry.getRegistryDesignation()) == RegistryDesignation.A) { if (IEnumKey.getEnumByKey(RegistryDesignation.class, currentRegistry.getRegistryDesignation()) == RegistryDesignation.O) {
String sqlCounterRegistryCondition = String.format("registryDesignation = '%s' and " + log.debug("Its t registry, skip");
"registryInstrumentType in ('%s', '%s') and " + continue;
"registryUnit = '%s' and " +
"tradingClearingRegistryId = '%s' and " +
"companyId = '%s' and ",
RegistryDesignation.A,
RegistryInstrumentType.S.getKey(), RegistryInstrumentType.M.getKey(),
RegistryUnit.F.getKey(),
currentRegistry.getTradingClearingRegistryId(),
currentRegistry.getCompanyId());
Registry counterRegistry = registryImdg.getSingleObjectBySQL(sqlCounterRegistryCondition);
if (currentRegistry.getBalance().compareTo(counterRegistry.getBalance()) > 0) {
log.warn("{}", msgResolver.resolve(new EnumMessage(ClearingError.InsecurityObligation, currentRegistry.getCompanyId())));
insecurityGroups.add(currentRegistry.getGroupId());
break;
}
currentRegistry.setRegistryStatus("OK");
registryImdg.update(counterRegistry);
} }
RegistryTradingParams counterRegistryTradingParams = null;
if (IEnumKey.getEnumByKey(RegistryDesignation.class, currentRegistry.getRegistryDesignation()) == RegistryDesignation.O
&& IEnumKey.getEnumByKey(RegistryInstrumentType.class, currentRegistry.getRegistryInstrumentType()) == RegistryInstrumentType.S) {
counterRegistryTradingParams = new RegistryTradingParams(RegistryDesignation.A,
RegistryInstrumentType.S,
null,
RegistryUnit.T);
} else if (IEnumKey.getEnumByKey(RegistryDesignation.class, currentRegistry.getRegistryDesignation()) == RegistryDesignation.O
&& IEnumKey.getEnumByKey(RegistryInstrumentType.class, currentRegistry.getRegistryInstrumentType()) == RegistryInstrumentType.M) {
counterRegistryTradingParams = new RegistryTradingParams(RegistryDesignation.A,
RegistryInstrumentType.M,
null,
RegistryUnit.F);
}
String sqlCounterRegistryCondition = String.format("%s and " +
"tradingClearingRegistryId = '%s' and " +
"companyId = '%s' and ",
RegistryCodeSqlBuilder.getInstance(counterRegistryTradingParams).build(),
currentRegistry.getTradingClearingRegistryId(),
currentRegistry.getCompanyId());
Registry counterRegistry = registryImdg.getSingleObjectBySQL(sqlCounterRegistryCondition);
if (currentRegistry.getBalance().compareTo(counterRegistry.getBalance()) > 0) {
log.warn("{}", msgResolver.resolve(new EnumMessage(ClearingError.InsecurityObligation, currentRegistry.getCompanyId())));
currentRegistry.setRegistryStatus("UNCV");
alreadyUpdatedToUncover.add(currentRegistry.getId());
insecurityGroups.add(currentRegistry.getGroupId());
registryImdg.update(currentRegistry);
continue;
}
currentRegistry.setRegistryStatus("OK");
registryImdg.update(currentRegistry);
} }
for (Long insecuritiesGroupId : insecurityGroups) { if (!insecurityGroups.isEmpty()) {
for (Map.Entry<Long, List<Registry>> entrySet : registryByGroupIdAndCompanyId.get(insecuritiesGroupId).entrySet()) { for (Long insecuritiesGroupId : insecurityGroups) {
if (entrySet.getKey().equals(processedCompanyId)) { for (Registry registry : registryByGroupIdAndCompanyId.get(insecuritiesGroupId)) {
for (Registry registry : entrySet.getValue()) { if (!alreadyUpdatedToUncover.contains(registry)) {
registry.setRegistryStatus("UNCV");
registryImdg.update(registry);
}
} else {
for (Registry registry : entrySet.getValue()) {
registry.setRegistryStatus("FAIL"); registry.setRegistryStatus("FAIL");
registryImdg.update(registry); registryImdg.update(registry);
} }
} }
} }
} }
return new StageResult(null, true); return new StageResult(null, true);
} }
} }