From 5cd919308d7ed08179437b1467f9b748aea0eca1 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Sat, 22 Feb 2025 12:42:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(warehouse):=20=E4=BE=9B=E5=BA=94=E5=95=86?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=9F=A5=E8=AF=A2=E6=8A=A5=E9=94=99=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 SQL 查询中添加了对 supplierIds 的判断和使用 - 优化了 SQL 查询的格式和可读性- 通过 FreeMarker 模板生成 SQL,修复了可能导致查询报错的问题 --- .../service/WarehouseReceiptService.java | 122 +++++++++--------- 1 file changed, 63 insertions(+), 59 deletions(-) diff --git a/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java b/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java index ae9eeb24..c1f45ce3 100644 --- a/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java +++ b/src/main/java/cn/lihongjie/coal/warehouseReceipt/service/WarehouseReceiptService.java @@ -950,13 +950,13 @@ from ( String sql = FreeMakerUtils.render( """ - - + + with tmp1 as ( - - + + select s.*, - + (select count(distinct re.id) from t_warehouse_receipt re inner join t_warehouse_receipt_detail d @@ -977,34 +977,34 @@ from ( <#if goodsIds?has_content> and gs.id in :goodsIds - + <#if barCode??> and gs.bar_code like '%' || :barCode || '%' <#if code??> and gs.code like '%' || :code || '%' - - + + <#if goodsName??> - + and gs.name like '%' || :goodsName || '%' - + <#if categoryIds?has_content> and gs.category_id in :categoryIds - + <#if brandIds?has_content> and gs.brand_id in :brandIds - + <#if unitIds?has_content> and gs.unit_id in :unitIds - + ) as "入库单数量", - + (select count(d.id) from t_warehouse_receipt re inner join t_warehouse_receipt_detail d @@ -1013,7 +1013,7 @@ from ( where re.organization_id = s.organization_id and re.receipt_type = '0' and d.supplier_id = s.id - + <#if startTime??> and re.receipt_date >= :startTime @@ -1026,33 +1026,33 @@ from ( <#if goodsIds?has_content> and gs.id in :goodsIds - + <#if barCode??> and gs.bar_code like '%' || :barCode || '%' <#if code??> and gs.code like '%' || :code || '%' - - + + <#if goodsName??> - + and gs.name like '%' || :goodsName || '%' - + <#if categoryIds?has_content> and gs.category_id in :categoryIds - + <#if brandIds?has_content> and gs.brand_id in :brandIds - + <#if unitIds?has_content> and gs.unit_id in :unitIds ) as "入库单明细数量", - + (select count(distinct d.goods_id) from t_warehouse_receipt re inner join t_warehouse_receipt_detail d @@ -1073,34 +1073,34 @@ from ( <#if goodsIds?has_content> and gs.id in :goodsIds - + <#if barCode??> and gs.bar_code like '%' || :barCode || '%' <#if code??> and gs.code like '%' || :code || '%' - - + + <#if goodsName??> - + and gs.name like '%' || :goodsName || '%' - + <#if categoryIds?has_content> and gs.category_id in :categoryIds - + <#if brandIds?has_content> and gs.brand_id in :brandIds - + <#if unitIds?has_content> and gs.unit_id in :unitIds - + ) as "入库商品种数", - + (select round(sum(d.number)::::numeric, 2) from t_warehouse_receipt re inner join t_warehouse_receipt_detail d @@ -1121,33 +1121,33 @@ from ( <#if goodsIds?has_content> and gs.id in :goodsIds - + <#if barCode??> and gs.bar_code like '%' || :barCode || '%' <#if code??> and gs.code like '%' || :code || '%' - - + + <#if goodsName??> - + and gs.name like '%' || :goodsName || '%' - + <#if categoryIds?has_content> and gs.category_id in :categoryIds - + <#if brandIds?has_content> and gs.brand_id in :brandIds - + <#if unitIds?has_content> and gs.unit_id in :unitIds ) as "入库商品数量", - + (select round(sum(d.amount)::::numeric, 2) from t_warehouse_receipt re inner join t_warehouse_receipt_detail d @@ -1156,7 +1156,7 @@ from ( where re.organization_id = s.organization_id and re.receipt_type = '0' and d.supplier_id = s.id - + <#if startTime??> and re.receipt_date >= :startTime @@ -1169,50 +1169,54 @@ from ( <#if goodsIds?has_content> and gs.id in :goodsIds - + <#if barCode??> and gs.bar_code like '%' || :barCode || '%' <#if code??> and gs.code like '%' || :code || '%' - - + + <#if goodsName??> - + and gs.name like '%' || :goodsName || '%' - + <#if categoryIds?has_content> and gs.category_id in :categoryIds - + <#if brandIds?has_content> and gs.brand_id in :brandIds - + <#if unitIds?has_content> and gs.unit_id in :unitIds - + ) as "入库商品总价" - - + + from t_warehouse_supplier s where s.organization_id = :organizationId + + <#if supplierIds?has_content> + and s.id in :supplierIds + ) - - + + select * from tmp1 - - + + <#if excludeEmpty> - + where "入库单数量" > 0 - - - + + + """, request);