This commit is contained in:
parent
fe79868712
commit
967877537d
3 changed files with 56 additions and 2 deletions
|
|
@ -15,10 +15,14 @@ import ru.spcex.platform.classes.base.interfaces.IExecution;
|
|||
import ru.spcex.platform.classes.base.interfaces.WithExchangeExecutionId;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
|
@ -27,6 +31,8 @@ public class DealsPrepare implements ISessionStage {
|
|||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final Imdg<ExecutionDeposit> executionDepositImdg;
|
||||
private final Imdg<ExecutionFond> executionFondImdg;
|
||||
private final List<ImdgPredicate> execDepositPredicates = new ArrayList<>();
|
||||
private final List<ImdgPredicate> execFondPredicates = new ArrayList<>();
|
||||
|
||||
@Autowired
|
||||
public DealsPrepare(ImdgProvider imdgProvider) {
|
||||
|
|
@ -55,8 +61,19 @@ public class DealsPrepare implements ISessionStage {
|
|||
if (securityId != null) {
|
||||
executionDepositSQL.append(" and securityId = ").append(securityId);
|
||||
}
|
||||
Collection<ExecutionDeposit> excDpsts = executionDepositImdg.getCollectionObjectsBySQL(executionDepositSQL.toString());
|
||||
Collection<ExecutionFond> excFonds = executionFondImdg.getCollectionObjectsBySQL(executionDepositSQL.toString());
|
||||
ImdgPredicate sqlPredicate = executionFondImdg.predicateBuilder().sql(executionDepositSQL.toString());
|
||||
BiFunction<List<ImdgPredicate>, Imdg<?>, ImdgPredicate> prdComposer = (imdgPredicates, imdg) -> {
|
||||
ImdgPredicateBuilder pb = imdg.predicateBuilder();
|
||||
if (imdgPredicates.isEmpty()) {
|
||||
return sqlPredicate;
|
||||
} else {
|
||||
return pb.and(sqlPredicate, pb.and(execDepositPredicates.toArray(new ImdgPredicate[0])));
|
||||
}
|
||||
};
|
||||
ImdgPredicate excDepPrct = prdComposer.apply(execDepositPredicates, executionDepositImdg);
|
||||
ImdgPredicate excFondPrct = prdComposer.apply(execFondPredicates, executionFondImdg);
|
||||
Collection<ExecutionDeposit> excDpsts = executionDepositImdg.getCollectionObjectsByPredicate(excDepPrct);
|
||||
Collection<ExecutionFond> excFonds = executionFondImdg.getCollectionObjectsByPredicate(excFondPrct);
|
||||
List<IExecution> excs = Stream.concat(excDpsts.stream().map(execToInterface()),
|
||||
excFonds.stream().map(execToInterface()))
|
||||
.sorted(Comparator.comparing(WithExchangeExecutionId::getExchangeExecutionId))
|
||||
|
|
@ -74,6 +91,18 @@ public class DealsPrepare implements ISessionStage {
|
|||
return res;
|
||||
}
|
||||
|
||||
public DealsPrepare addExecutionDepositCondition(ImdgPredicate imdgPredicate) {
|
||||
this.execDepositPredicates.add(imdgPredicate);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DealsPrepare addExecutionFondCondition(ImdgPredicate imdgPredicate) {
|
||||
this.execFondPredicates.add(imdgPredicate);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static <E extends IExecution> Function<E, IExecution> execToInterface() {
|
||||
return (e) -> e;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package ru.spcex.platform.imdg.iml.hazelcast.adapter.predicate;
|
||||
|
||||
import com.hazelcast.query.Predicate;
|
||||
import com.hazelcast.query.Predicates;
|
||||
import com.hazelcast.query.SqlPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
|
||||
|
|
@ -64,6 +66,15 @@ public class ImdgPredicateBuilderHazelcast implements ImdgPredicateBuilder {
|
|||
return new ImdgPredicateHazelcast(Predicates.and(paramAMy.hazelcastPredicate, paramBMy.hazelcastPredicate, paramCMy.hazelcastPredicate));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImdgPredicate and(ImdgPredicate... param) {
|
||||
Predicate[] paramMy = new Predicate[param.length];
|
||||
for (int i = 0; i < param.length; i++) {
|
||||
paramMy[i] = ((ImdgPredicateHazelcast) param[i]).getRawPredicate();
|
||||
}
|
||||
return new ImdgPredicateHazelcast(Predicates.and(paramMy));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImdgPredicate or(ImdgPredicate paramA, ImdgPredicate paramB) {
|
||||
ImdgPredicateHazelcast paramAMy = (ImdgPredicateHazelcast) paramA;
|
||||
|
|
@ -78,4 +89,14 @@ public class ImdgPredicateBuilderHazelcast implements ImdgPredicateBuilder {
|
|||
ImdgPredicateHazelcast paramCMy = (ImdgPredicateHazelcast) paramC;
|
||||
return new ImdgPredicateHazelcast(Predicates.or(paramAMy.hazelcastPredicate, paramBMy.hazelcastPredicate, paramCMy.hazelcastPredicate));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImdgPredicate sql(String sql) {
|
||||
return new ImdgPredicateHazelcast(new SqlPredicate(sql));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImdgPredicate regex(String key, String regex) {
|
||||
return new ImdgPredicateHazelcast(Predicates.regex(key, regex));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@ public interface ImdgPredicateBuilder {
|
|||
ImdgPredicate not(ImdgPredicate param);
|
||||
ImdgPredicate and(ImdgPredicate paramA, ImdgPredicate paramB);
|
||||
ImdgPredicate and(ImdgPredicate paramA, ImdgPredicate paramB, ImdgPredicate paramC);
|
||||
ImdgPredicate and(ImdgPredicate... param);
|
||||
ImdgPredicate or(ImdgPredicate paramA, ImdgPredicate paramB);
|
||||
ImdgPredicate or(ImdgPredicate paramA, ImdgPredicate paramB, ImdgPredicate paramC);
|
||||
|
||||
ImdgPredicate sql(String sql);
|
||||
ImdgPredicate regex(String key, String regex);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue