This commit is contained in:
parent
60b89f6fa0
commit
ebfd4fe7d2
2 changed files with 52 additions and 33 deletions
|
|
@ -43,6 +43,7 @@ import ru.spcex.platform.enumeration.OrderAffil;
|
||||||
import ru.spcex.platform.enumeration.OrderStatus;
|
import ru.spcex.platform.enumeration.OrderStatus;
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||||
import ru.spcex.platform.imdg.api.predicate.specific.IdEqualPredicate;
|
import ru.spcex.platform.imdg.api.predicate.specific.IdEqualPredicate;
|
||||||
import static ru.spcex.platform.imdg.api.predicate.specific.IdEqualPredicate.byId;
|
import static ru.spcex.platform.imdg.api.predicate.specific.IdEqualPredicate.byId;
|
||||||
|
|
@ -460,13 +461,7 @@ public class ValidationConfig {
|
||||||
.builder(r -> {
|
.builder(r -> {
|
||||||
OrderCurrency oc = ctx.getStoredObject(OrderCurrencyValidationStored.OrderCurrency);
|
OrderCurrency oc = ctx.getStoredObject(OrderCurrencyValidationStored.OrderCurrency);
|
||||||
ImdgPredicateBuilder pb = orderCurrencyImdg.predicateBuilder();
|
ImdgPredicateBuilder pb = orderCurrencyImdg.predicateBuilder();
|
||||||
return pb.and(
|
return relatedOrders(pb, oc);
|
||||||
pb.equals("type", OrderAffil.PLBL.getKey()),
|
|
||||||
pb.equals("registryId", oc.getRegistryId()),
|
|
||||||
pb.equals("companyId", oc.getCounterPartyId()),
|
|
||||||
pb.equals("counterPartyId", oc.getCompanyId()),
|
|
||||||
pb.equals("status", OrderStatus.CREATED.getKey())
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.mapName(IMDGDistributedNames.Map_OrderCurrency)
|
.mapName(IMDGDistributedNames.Map_OrderCurrency)
|
||||||
.errorProvider(r -> recordNotFound("counter OrderCurrency"))
|
.errorProvider(r -> recordNotFound("counter OrderCurrency"))
|
||||||
|
|
@ -508,13 +503,7 @@ public class ValidationConfig {
|
||||||
.builder(r -> {
|
.builder(r -> {
|
||||||
OrderCurrency oc = ctx.getStoredObject(OrderCurrencyValidationStored.OrderCurrency);
|
OrderCurrency oc = ctx.getStoredObject(OrderCurrencyValidationStored.OrderCurrency);
|
||||||
ImdgPredicateBuilder pb = orderCurrencyImdg.predicateBuilder();
|
ImdgPredicateBuilder pb = orderCurrencyImdg.predicateBuilder();
|
||||||
return pb.and(
|
return relatedOrders(pb, oc);
|
||||||
pb.equals("type", OrderAffil.PLBL.getKey()),
|
|
||||||
pb.equals("registryId", oc.getRegistryId()),
|
|
||||||
pb.equals("companyId", oc.getCounterPartyId()),
|
|
||||||
pb.equals("counterPartyId", oc.getCompanyId()),
|
|
||||||
pb.equals("status", OrderStatus.CREATED.getKey())
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.mapName(IMDGDistributedNames.Map_OrderCurrency)
|
.mapName(IMDGDistributedNames.Map_OrderCurrency)
|
||||||
.errorProvider(r -> recordNotFound("counter OrderCurrency"))
|
.errorProvider(r -> recordNotFound("counter OrderCurrency"))
|
||||||
|
|
@ -528,5 +517,24 @@ public class ValidationConfig {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ImdgPredicate relatedOrders(ImdgPredicateBuilder pb, OrderCurrency oc) {
|
||||||
|
return pb.and(
|
||||||
|
pb.equals("type", OrderAffil.PLBL.getKey()),
|
||||||
|
pb.equals("registryId", oc.getRegistryId()),
|
||||||
|
pb.or(
|
||||||
|
pb.and(
|
||||||
|
pb.equals("companyId", oc.getCounterPartyId()),
|
||||||
|
pb.equals("counterPartyId", oc.getCompanyId())
|
||||||
|
),
|
||||||
|
pb.and(
|
||||||
|
pb.equals("companyId", oc.getCompanyId()),
|
||||||
|
pb.equals("counterPartyId", oc.getCounterPartyId())
|
||||||
|
)
|
||||||
|
),
|
||||||
|
pb.equals("status", OrderStatus.CREATED.getKey()),
|
||||||
|
pb.not(pb.equals("id", oc.getId()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,11 @@ import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import org.apache.kafka.clients.consumer.Consumer;
|
import org.apache.kafka.clients.consumer.Consumer;
|
||||||
import org.apache.kafka.clients.producer.Producer;
|
import org.apache.kafka.clients.producer.Producer;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
@ -362,25 +364,30 @@ public class OrderCurrencyListener extends QueueConsumer implements Initializing
|
||||||
OrderCurrency order = validator.getStored(OrderCurrencyValidationStored.OrderCurrency);
|
OrderCurrency order = validator.getStored(OrderCurrencyValidationStored.OrderCurrency);
|
||||||
Company company = validator.getStored(OrderCurrencyValidationStored.Company);
|
Company company = validator.getStored(OrderCurrencyValidationStored.Company);
|
||||||
TradingClearingRegistry tcr = validator.getStored(OrderCurrencyValidationStored.TCR);
|
TradingClearingRegistry tcr = validator.getStored(OrderCurrencyValidationStored.TCR);
|
||||||
Collection<OrderCurrency> counterOrders = validator.getStored(OrderCurrencyValidationStored.CounterOrderCurrency);
|
Collection<OrderCurrency> relatedOrders = validator.getStored(OrderCurrencyValidationStored.CounterOrderCurrency);
|
||||||
|
|
||||||
order.setCompanyId(payload.getCompanyId());
|
|
||||||
order.setTradingClearingRegistryId(payload.getTradingClearingRegistryId());
|
|
||||||
order.setQuantityLot(new BigDecimal(payload.getQuantityLot()));
|
|
||||||
order.setAccount(tcr.getCode());
|
|
||||||
order.setTradingCode(company.getTradingCode());
|
|
||||||
order.setUpdated(now);
|
|
||||||
|
|
||||||
log.info("updating OrderCurrency[{}, {}]", order.getId(),
|
log.info("updating OrderCurrency[{}, {}]", order.getId(),
|
||||||
counterOrders.stream().map(OrderCurrency::getId).map(Object::toString).collect(Collectors.joining(",")));
|
relatedOrders
|
||||||
orderCurrencyImdg.update(order);
|
.stream()
|
||||||
|
.map(OrderCurrency::getId)
|
||||||
|
.map(Object::toString)
|
||||||
|
.collect(Collectors.joining(", ")));
|
||||||
|
|
||||||
counterOrders.forEach(counterOrder -> {
|
Stream
|
||||||
counterOrder.setCounterPartyId(payload.getCompanyId());
|
.concat(Stream.of(order), relatedOrders.stream())
|
||||||
counterOrder.setCounterTradingCode(company.getTradingCode());
|
.forEach(item -> {
|
||||||
counterOrder.setQuantityLot(new BigDecimal(payload.getQuantityLot()));
|
if (Objects.equals(item.getCompanyId(), order.getCounterPartyId())) {
|
||||||
counterOrder.setUpdated(now);
|
item.setCounterPartyId(payload.getCompanyId());
|
||||||
orderCurrencyImdg.update(counterOrder);
|
item.setCounterTradingCode(company.getTradingCode());
|
||||||
|
} else {
|
||||||
|
item.setCompanyId(payload.getCompanyId());
|
||||||
|
item.setTradingClearingRegistryId(payload.getTradingClearingRegistryId());
|
||||||
|
item.setAccount(tcr.getCode());
|
||||||
|
item.setTradingCode(company.getTradingCode());
|
||||||
|
}
|
||||||
|
item.setQuantityLot(new BigDecimal(payload.getQuantityLot()));
|
||||||
|
item.setUpdated(now);
|
||||||
|
orderCurrencyImdg.update(item);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -394,12 +401,16 @@ public class OrderCurrencyListener extends QueueConsumer implements Initializing
|
||||||
return new RequestInfoUpdate(req.getId(), Status.Error, msgResolver.resolve(error.get()));
|
return new RequestInfoUpdate(req.getId(), Status.Error, msgResolver.resolve(error.get()));
|
||||||
}
|
}
|
||||||
OrderCurrency order = validator.getStored(OrderCurrencyValidationStored.OrderCurrency);
|
OrderCurrency order = validator.getStored(OrderCurrencyValidationStored.OrderCurrency);
|
||||||
Collection<OrderCurrency> counterOrders = validator.getStored(OrderCurrencyValidationStored.CounterOrderCurrency);
|
Collection<OrderCurrency> relatedOrders = validator.getStored(OrderCurrencyValidationStored.CounterOrderCurrency);
|
||||||
|
|
||||||
log.info("deleting OrderCurrency[{}, {}]", order.getId(),
|
log.info("deleting OrderCurrency[{}, {}]", order.getId(),
|
||||||
counterOrders.stream().map(OrderCurrency::getId).map(Object::toString).collect(Collectors.joining(",")));
|
relatedOrders
|
||||||
|
.stream()
|
||||||
|
.map(OrderCurrency::getId)
|
||||||
|
.map(Object::toString)
|
||||||
|
.collect(Collectors.joining(", ")));
|
||||||
reject(order);
|
reject(order);
|
||||||
counterOrders.forEach(this::reject);
|
relatedOrders.forEach(this::reject);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue