我正在学习springwebflux,我正在尝试更新一个记录列表,我想知道我是否在尽可能有效地进行更新。
我想知道如何改进“persisstatusorderlinenumber”方法,因为我正在学习这项技术,我应该使用subscribeon吗?使用subordersflux异步更新数据库中的行最有效的方法是什么?
private Mono<Void> persistStatusOrderLineNumber(Long orderNumber, SubOrdersItem subOrder) {
Flux<OrderLinesItem> subOrdersFlux = Flux.fromIterable(subOrder.getOrderLines());
return subOrdersFlux
.flatMap(x -> orderLineRepository
.updateShipmentCustomerOrderOrderLine(orderNumber, x, subOrder).then())
.then();
}
这是更新数据库的方法:
public Mono<Void> updateShipmentCustomerOrderOrderLine(
Long id, OrderLinesItem orderLinesItem, SubOrdersItem subOrdersItem) {
Optional<OrderLinesItem> optionalOrderLinesItem = Optional.ofNullable(orderLinesItem);
if(orderLinesItem.getOrderLineStatus() == null) return Mono.empty();
int statusId = getStatusId(orderLinesItem.getOrderLineStatus());
DatabaseClient.GenericExecuteSpec bindings =
client
.execute(
"UPDATE public.order_line "
+ "SET status_id = :status_id, "
+ "updated_at = :updated_at, "
+ "physical_location = :physical_location "
+ "WHERE order_line_number = :order_line_number AND order_number = :order_number AND sub_order_number = :sub_order_number")
.bind("status_id", statusId)
.bind("updated_at", LocalDateTime.now())
.bind(
"physical_location",
optionalOrderLinesItem.map(OrderLinesItem::getPhysicalLocation).orElse(""))
.bind("order_line_number", orderLinesItem.getOrderLineNumber())
.bind("order_number", id)
.bind("sub_order_number", subOrdersItem.getSuborderNumber());
FetchSpec<Map<String, Object>> sqlResult = bindings.fetch();
return sqlResult
.rowsUpdated()
.doOnNext(ex -> retryUpdate(id, ex)).log()
.onErrorResume(
ex ->
Mono.error(new CustomException(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage())))
.then();
}
暂无答案!
目前还没有任何答案,快来回答吧!