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.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 ru.spcex.platform.imdg.api.predicate.specific.IdEqualPredicate;
|
||||
import static ru.spcex.platform.imdg.api.predicate.specific.IdEqualPredicate.byId;
|
||||
|
|
@ -460,13 +461,7 @@ public class ValidationConfig {
|
|||
.builder(r -> {
|
||||
OrderCurrency oc = ctx.getStoredObject(OrderCurrencyValidationStored.OrderCurrency);
|
||||
ImdgPredicateBuilder pb = orderCurrencyImdg.predicateBuilder();
|
||||
return pb.and(
|
||||
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())
|
||||
);
|
||||
return relatedOrders(pb, oc);
|
||||
})
|
||||
.mapName(IMDGDistributedNames.Map_OrderCurrency)
|
||||
.errorProvider(r -> recordNotFound("counter OrderCurrency"))
|
||||
|
|
@ -508,13 +503,7 @@ public class ValidationConfig {
|
|||
.builder(r -> {
|
||||
OrderCurrency oc = ctx.getStoredObject(OrderCurrencyValidationStored.OrderCurrency);
|
||||
ImdgPredicateBuilder pb = orderCurrencyImdg.predicateBuilder();
|
||||
return pb.and(
|
||||
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())
|
||||
);
|
||||
return relatedOrders(pb, oc);
|
||||
})
|
||||
.mapName(IMDGDistributedNames.Map_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.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -362,25 +364,30 @@ public class OrderCurrencyListener extends QueueConsumer implements Initializing
|
|||
OrderCurrency order = validator.getStored(OrderCurrencyValidationStored.OrderCurrency);
|
||||
Company company = validator.getStored(OrderCurrencyValidationStored.Company);
|
||||
TradingClearingRegistry tcr = validator.getStored(OrderCurrencyValidationStored.TCR);
|
||||
Collection<OrderCurrency> counterOrders = 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);
|
||||
Collection<OrderCurrency> relatedOrders = validator.getStored(OrderCurrencyValidationStored.CounterOrderCurrency);
|
||||
|
||||
log.info("updating OrderCurrency[{}, {}]", order.getId(),
|
||||
counterOrders.stream().map(OrderCurrency::getId).map(Object::toString).collect(Collectors.joining(",")));
|
||||
orderCurrencyImdg.update(order);
|
||||
relatedOrders
|
||||
.stream()
|
||||
.map(OrderCurrency::getId)
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.joining(", ")));
|
||||
|
||||
counterOrders.forEach(counterOrder -> {
|
||||
counterOrder.setCounterPartyId(payload.getCompanyId());
|
||||
counterOrder.setCounterTradingCode(company.getTradingCode());
|
||||
counterOrder.setQuantityLot(new BigDecimal(payload.getQuantityLot()));
|
||||
counterOrder.setUpdated(now);
|
||||
orderCurrencyImdg.update(counterOrder);
|
||||
Stream
|
||||
.concat(Stream.of(order), relatedOrders.stream())
|
||||
.forEach(item -> {
|
||||
if (Objects.equals(item.getCompanyId(), order.getCounterPartyId())) {
|
||||
item.setCounterPartyId(payload.getCompanyId());
|
||||
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;
|
||||
|
|
@ -394,12 +401,16 @@ public class OrderCurrencyListener extends QueueConsumer implements Initializing
|
|||
return new RequestInfoUpdate(req.getId(), Status.Error, msgResolver.resolve(error.get()));
|
||||
}
|
||||
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(),
|
||||
counterOrders.stream().map(OrderCurrency::getId).map(Object::toString).collect(Collectors.joining(",")));
|
||||
relatedOrders
|
||||
.stream()
|
||||
.map(OrderCurrency::getId)
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.joining(", ")));
|
||||
reject(order);
|
||||
counterOrders.forEach(this::reject);
|
||||
relatedOrders.forEach(this::reject);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue