split deposit contract index and parentId
This commit is contained in:
parent
d2cf49b7c8
commit
6d5e5fd00e
4 changed files with 64 additions and 6 deletions
|
|
@ -412,7 +412,8 @@ public class ValidationConfig {
|
|||
IMDGDistributedNames.Map_InOutDirectionDictionary, InOutDirectionDictionary.class,
|
||||
ClearingError.RequiredFieldEmpty, ClearingError.DictionaryNotFound, false),
|
||||
SplitDepositRequestValidationRule.PositiveAmount,
|
||||
SplitDepositRequestValidationRule.CrossvalidateByRegistry
|
||||
SplitDepositRequestValidationRule.CrossvalidateByRegistry,
|
||||
SplitDepositRequestValidationRule.LoadContractIndexes
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static ru.spcex.platform.utils.number.BigDecimalUtil.safeBD;
|
||||
|
|
@ -498,6 +497,7 @@ public class RegistryService {
|
|||
return roleCheck;
|
||||
}
|
||||
Collection<Registry> baseRegistrys;
|
||||
Integer index;
|
||||
{
|
||||
IValidator validator = splitDepositActionVal.apply(requestPayload);
|
||||
Optional<EnumMessage> err = validator.tillFirstError();
|
||||
|
|
@ -508,6 +508,8 @@ public class RegistryService {
|
|||
return new RequestInfoUpdate(req.getId(), Status.Error, msgResolver.resolve(err.get()));
|
||||
}
|
||||
baseRegistrys = validator.getStored(ValidationStored.RegistrysByContract);
|
||||
index = validator.getStored(ValidationStored.SplitDepositMaxNumber);
|
||||
if (index == null) index = 0;
|
||||
}
|
||||
|
||||
ImdgTransaction txCtx = imdgProvider.newTransaction();
|
||||
|
|
@ -524,6 +526,13 @@ public class RegistryService {
|
|||
log.debug("Process {} for {} registry", direction, baseRegistrys.size());
|
||||
Long groupId = null;
|
||||
for (Registry baseRegistry : baseRegistrys) {
|
||||
String cntrctWithoutTilda;
|
||||
{
|
||||
cntrctWithoutTilda = baseRegistry.getContract();
|
||||
if (cntrctWithoutTilda.contains("~")) {
|
||||
cntrctWithoutTilda = cntrctWithoutTilda.substring(0, cntrctWithoutTilda.indexOf("~"));
|
||||
}
|
||||
}
|
||||
log.trace("Registry[{}], groupId={}, ClearingCode={}", baseRegistry.getId(), baseRegistry.getGroupId(), baseRegistry.getClearingCode());
|
||||
if (groupId == null)
|
||||
groupId = baseRegistry.getGroupId();
|
||||
|
|
@ -542,9 +551,9 @@ public class RegistryService {
|
|||
} else {
|
||||
log.warn("Direction not set, do not change Balance");
|
||||
}
|
||||
firstRegistry.setContract(baseRegistry.getContract() + "~1");
|
||||
firstRegistry.setContract(cntrctWithoutTilda + "~" + (index + 1));
|
||||
firstRegistry.setParentId(baseRegistry.getId());
|
||||
registryTMap.insert(firstRegistry);
|
||||
|
||||
// 2. Вторая группа
|
||||
Registry secondRegistry = null;
|
||||
if (InOutDirection.out == direction) {
|
||||
|
|
@ -553,9 +562,10 @@ public class RegistryService {
|
|||
secondRegistry.setCreated(now);
|
||||
secondRegistry.setUpdated(null);
|
||||
secondRegistry.setBalance(requestPayload.getOutboundAmount());
|
||||
secondRegistry.setContract(baseRegistry.getContract() + "~2");
|
||||
secondRegistry.setContract(cntrctWithoutTilda + "~" + (index + 2));
|
||||
secondRegistry.setRefundDate(requestPayload.getRefundDate());
|
||||
secondRegistry.setSettlementDate(requestPayload.getRefundDate());
|
||||
secondRegistry.setParentId(baseRegistry.getId());
|
||||
registryTMap.insert(secondRegistry);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,12 +14,14 @@ import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
|||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.imdg.validation.ImdgValidationContext;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.text.TextUtil;
|
||||
import ru.spcex.platform.utils.validation.IValidationRule;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public enum SplitDepositRequestValidationRule implements IValidationRule<ImdgValidationContext<RegistrySplitDepositActionRequest>> {
|
||||
PositiveAmount() {
|
||||
|
|
@ -78,6 +80,51 @@ public enum SplitDepositRequestValidationRule implements IValidationRule<ImdgVal
|
|||
return Optional.of(new EnumMessage(ClearingError.WrongFieldValue, "RefundDate"));
|
||||
}
|
||||
|
||||
return empty();
|
||||
}
|
||||
},
|
||||
LoadContractIndexes() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<RegistrySplitDepositActionRequest> context) {
|
||||
Imdg<Registry> registryImdg = context.obtainMap(IMDGDistributedNames.Map_Registry, Registry.class);
|
||||
RegistrySplitDepositActionRequest validatedObject = context.getValidatedObject();
|
||||
String contract = validatedObject.getContract();
|
||||
if (TextUtil.isEmpty(contract)) {
|
||||
return of(ClearingError.WrongField, "contract");
|
||||
}
|
||||
String cntrSrch;
|
||||
int i = contract.indexOf("~");
|
||||
if (i == -1) {
|
||||
context.storeObject(ValidationStored.SplitDepositMaxNumber, 0);
|
||||
return empty();
|
||||
} else {
|
||||
cntrSrch = contract.substring(0, i);
|
||||
}
|
||||
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||
ImdgPredicate allContracts = pb.and(
|
||||
pb.or(pb.equals("registryStatus", RegistryStatus.PROC.getKey()), pb.equals("registryStatus", RegistryStatus.MNG.getKey())),
|
||||
pb.or(pb.equals("registryDesignation", RegistryDesignation.O.getKey()), pb.equals("registryDesignation", RegistryDesignation.T.getKey())),
|
||||
pb.equals("registryUnit", RegistryUnit.T.getKey()),
|
||||
pb.regex("contract", cntrSrch + ".*")
|
||||
);
|
||||
Collection<Registry> rgss = registryImdg.getCollectionObjectsByPredicate(allContracts);
|
||||
Integer maxContractNumber = rgss.stream()
|
||||
.map(Registry::getContract)
|
||||
.filter(c -> c.contains("~"))
|
||||
.map(c -> c.substring(c.lastIndexOf("~") + 1))
|
||||
.flatMap(number -> {
|
||||
try {
|
||||
return Stream.of(Integer.valueOf(number));
|
||||
} catch (NumberFormatException e) {
|
||||
return Stream.empty();
|
||||
}
|
||||
})
|
||||
.max(Integer::compareTo)
|
||||
.orElse(0);
|
||||
if (maxContractNumber == 0) {
|
||||
log.warn("contract {} contains '~' but no maximum number was extracted", contract);
|
||||
}
|
||||
context.storeObject(ValidationStored.SplitDepositMaxNumber, maxContractNumber);
|
||||
return empty();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,5 +32,5 @@ public enum ValidationStored {
|
|||
|
||||
SecurityBySecurityCode,
|
||||
|
||||
RegistrysByContract
|
||||
RegistrysByContract, SplitDepositMaxNumber
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue