rest - Tuple.of (vert.x pgclient) 中的数组
问题描述
这是我的 postgresql CTE。适用于各种示例。
with vtas_itms as (
insert into ventas (idafip, tipo_venta, nrodoc_persona, tperso_persona, nrodoc_vendedor,
tperso_vendedor, idfinanciacion, cancuotas, fecha_comprobante, punto_venta,
numero_comprobante, cae, fecha_vtocae, situacion_fiscal, nombre_cliente,
numero_remito, coeficiente, bonificacion, obs_generales, obs_comerciales,
obs_afip, estado)
values (6, 'Efectivo', 17412018, 'Cliente', 14808837,
'Vendedor', 1, null, '2020-10-27', 6,
215, '70332083246226', '2020-11-02', 'Consumidor Final', 'Consumidor Final',
null, null, null, null, null,
null, 'Pagada')
returning idventa
)
insert into ventas_items (idventa, idarticulo, cantidad, precio_unitario, descuento_articulo, saldo_articulo)
select vtas_itms.idventa, d1.col1, d1.col2, d1.col3::numeric, d1.col4::numeric, d1.col5::numeric
from vtas_itms
cross join (values (3,2,82.38,null,null), (4,1,43.12,null,null),(1,0.750,286.30,null,null)) as d1(col1,col2,col3,col4,col5)
注意交叉连接值:出现“n”个的 5 列……当然,它是一个数组。
现在,在服务器端(业务):
private static final String INSERT_VENTA = "with vtas_itms as ("
+ "insert into ventas (idafip, tipo_venta, nrodoc_persona, tperso_persona, nrodoc_vendedor, tperso_vendedor, idfinanciacion, cancuotas, fecha_comprobante, punto_venta, "
+ "numero_comprobante, cae, fecha_vtocae, situacion_fiscal, nombre_cliente, numero_remito, coeficiente, bonificacion, obs_generales, obs_comerciales, "
+ "obs_afip, estado) "
+ "values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22) "
+ "returning idventa) "
+ "insert into ventas_items (idventa, idarticulo, cantidad, precio_unitario, descuento_articulo, saldo_articulo) "
+ "select vtas_itms.idventa, d1.col1, d1.col2, d1.col3::numeric, d1.col4::numeric, d1.col5::numeric "
+ "from vtas_itms "
+ "cross join ($23::text[]) as d1(col1,col2,col3,col4,col5)";
查看 $23::text[] 参数...我需要输入准备好的查询(在“venta.getEstado()”之后)和 API...我不知道如何
public void putVenta(RoutingContext routingContext) {
Venta venta = Json.decodeValue(routingContext.getBodyAsString(), Venta.class);
HttpServerResponse response = routingContext.response();
pgClient
.preparedQuery(INSERT_VENTA)
.execute(Tuple.of(venta.getIdafip(), venta.getTventa(), venta.getNrodoc_persona(), venta.getTperso_persona(), venta.getNrodoc_vendedor(), venta.getTperso_vendedor(),
venta.getIdfinanciacion(), venta.getCancuotas(), venta.getFecha_comprobante(), venta.getPunto_venta(), venta.getNumero_comprobante(), venta.getCae(),
venta.getFecha_vtocae(), venta.getSituacion_fiscal(), venta.getNombre_cliente(), venta.getNumero_remito(), venta.getCoeficiente(), venta.getBonificacion(),
venta.getObs_generales(), venta.getObs_comerciales(), venta.getObs_afip(), venta.getEstado()), ar -> {
if (ar.succeeded()) {
response.putHeader("content-type", "application/json; charset=utf-8")
.setStatusCode(201)
.end();
} else {
System.out.println("Failure: " + ar.cause().getMessage());
response.putHeader("content-type", "application/json; charset=utf-8")
.end(Json.encodePrettily(ar.cause().getMessage()));
}
});
}
´´´
API (routes). After parameter /:estado)
// tag::createRoutes[]
router.put("/api/ventas/insertVenta/:idafip/:tipo_venta/:nrodoc_persona/:tperso_persona/:nrodoc_vendedor/:tperso_vendedor/:idfinanciacion"
+ "/:cancuotas/:fecha_comprobante/:punto_venta/:numero_comprobante/:cae/:fecha_vtocae/:situacion_fiscal/:nombre_cliente"
+ "/:nro_remito/:coeficiente/:bonificacion/:obs_generales/:obs_comerciales/:obs_afip/:estado").handler(bizVentas::putVenta);
Any help?. TIA
Ernesto
解决方案
您正在寻找从单个字符串创建虚拟表。
Postres实际上可以做到这一点。
您可以使用数组语法提供字符串,{}
然后使用 unnest 将每个字符串拆分为单独的行。
然后,您使用string_to_array
将每一行拆分为单独的列。
select a[1], a[2], a[3], a[4], a[5]
from (
select string_to_array(nest.l, ',') as a
from (
select unnest('{"3,2,82.38,null,null","4,1,43.12,null,null"}'::text[]) as l
) nest) b
您values ()
现在可以使用此查询替换您的部分。
在 Vert.x 方面,您必须准确地创建这个字符串并绑定它。
推荐阅读
- c++ - 如何使用 vtkStreamTracer 类使用我的非结构化网格数据 (vtu) 生成流线
- c - 解码字典中尚未包含的 TIFF LZW 代码
- delphi - 控制台中的 Unicode
- flutter - 我想从 Future 中获取一个整数值,该值在 Flutter 和 Firestore 中打印 Future 'dynamic' 函数的实例
- python - 片段无法在 ST3 中静默插入
- python - 在 VS Code 中调试时如何提供输入数据?
- java - SAML2 - 响应没有任何可以通过主题验证的有效断言
- mysql - 如何在 MySQL 中启用 ONLY_FULL_GROUP_BY
- azure - Azure Service Fabric 无状态服务的配置和资源治理选项?
- list - 在 Prolog 的列表中合并元组的元素