mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 23:57:12 +08:00
fix(warehouse): 修复供应商统计查询结果为 null 的问题
- 在 SQL 查询中使用 COALESCE 函数,将可能为 null 的结果替换为 0 -优化了多个子查询,确保统计结果更加准确 - 调整了 SQL 语句的格式,提高了可读性
This commit is contained in:
@@ -950,14 +950,14 @@ from (
|
||||
String sql =
|
||||
FreeMakerUtils.render(
|
||||
"""
|
||||
|
||||
|
||||
|
||||
|
||||
with tmp1 as (
|
||||
|
||||
|
||||
|
||||
|
||||
select s.*,
|
||||
|
||||
(select count(distinct re.id)
|
||||
|
||||
(select COALESCE(count(distinct re.id),0)
|
||||
from t_warehouse_receipt re
|
||||
inner join t_warehouse_receipt_detail d
|
||||
on re.id = d.receipt_id
|
||||
@@ -977,39 +977,39 @@ from (
|
||||
<#if goodsIds?has_content>
|
||||
and gs.id in :goodsIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if barCode??>
|
||||
and gs.bar_code like '%' || :barCode || '%'
|
||||
</#if>
|
||||
<#if code??>
|
||||
and gs.code like '%' || :code || '%'
|
||||
</#if>
|
||||
|
||||
|
||||
|
||||
|
||||
<#if goodsName??>
|
||||
|
||||
|
||||
and gs.name like '%' || :goodsName || '%'
|
||||
|
||||
|
||||
</#if>
|
||||
<#if categoryIds?has_content>
|
||||
and gs.category_id in :categoryIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if brandIds?has_content>
|
||||
and gs.brand_id in :brandIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if unitIds?has_content>
|
||||
and gs.unit_id in :unitIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if warehouseIds?has_content>
|
||||
and d.warehouse_id in :warehouseIds
|
||||
</#if>
|
||||
|
||||
|
||||
) as "入库单数量",
|
||||
|
||||
(select count(d.id)
|
||||
|
||||
(select COALESCE(count(d.id),0)
|
||||
from t_warehouse_receipt re
|
||||
inner join t_warehouse_receipt_detail d
|
||||
on re.id = d.receipt_id
|
||||
@@ -1017,7 +1017,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
|
||||
</#if>
|
||||
@@ -1030,28 +1030,28 @@ from (
|
||||
<#if goodsIds?has_content>
|
||||
and gs.id in :goodsIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if barCode??>
|
||||
and gs.bar_code like '%' || :barCode || '%'
|
||||
</#if>
|
||||
<#if code??>
|
||||
and gs.code like '%' || :code || '%'
|
||||
</#if>
|
||||
|
||||
|
||||
|
||||
|
||||
<#if goodsName??>
|
||||
|
||||
|
||||
and gs.name like '%' || :goodsName || '%'
|
||||
|
||||
|
||||
</#if>
|
||||
<#if categoryIds?has_content>
|
||||
and gs.category_id in :categoryIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if brandIds?has_content>
|
||||
and gs.brand_id in :brandIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if unitIds?has_content>
|
||||
and gs.unit_id in :unitIds
|
||||
</#if>
|
||||
@@ -1059,8 +1059,8 @@ from (
|
||||
and d.warehouse_id in :warehouseIds
|
||||
</#if>
|
||||
) as "入库单明细数量",
|
||||
|
||||
(select count(distinct d.goods_id)
|
||||
|
||||
(select COALESCE(count(distinct d.goods_id),0)
|
||||
from t_warehouse_receipt re
|
||||
inner join t_warehouse_receipt_detail d
|
||||
on re.id = d.receipt_id
|
||||
@@ -1080,28 +1080,28 @@ from (
|
||||
<#if goodsIds?has_content>
|
||||
and gs.id in :goodsIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if barCode??>
|
||||
and gs.bar_code like '%' || :barCode || '%'
|
||||
</#if>
|
||||
<#if code??>
|
||||
and gs.code like '%' || :code || '%'
|
||||
</#if>
|
||||
|
||||
|
||||
|
||||
|
||||
<#if goodsName??>
|
||||
|
||||
|
||||
and gs.name like '%' || :goodsName || '%'
|
||||
|
||||
|
||||
</#if>
|
||||
<#if categoryIds?has_content>
|
||||
and gs.category_id in :categoryIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if brandIds?has_content>
|
||||
and gs.brand_id in :brandIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if unitIds?has_content>
|
||||
and gs.unit_id in :unitIds
|
||||
</#if>
|
||||
@@ -1109,8 +1109,8 @@ from (
|
||||
and d.warehouse_id in :warehouseIds
|
||||
</#if>
|
||||
) as "入库商品种数",
|
||||
|
||||
(select round(sum(d.number)::::numeric, 2)
|
||||
|
||||
(select COALESCE(round(sum(d.number)::::numeric, 2),0)
|
||||
from t_warehouse_receipt re
|
||||
inner join t_warehouse_receipt_detail d
|
||||
on re.id = d.receipt_id
|
||||
@@ -1130,38 +1130,38 @@ from (
|
||||
<#if goodsIds?has_content>
|
||||
and gs.id in :goodsIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if barCode??>
|
||||
and gs.bar_code like '%' || :barCode || '%'
|
||||
</#if>
|
||||
<#if code??>
|
||||
and gs.code like '%' || :code || '%'
|
||||
</#if>
|
||||
|
||||
|
||||
|
||||
|
||||
<#if goodsName??>
|
||||
|
||||
|
||||
and gs.name like '%' || :goodsName || '%'
|
||||
|
||||
|
||||
</#if>
|
||||
<#if categoryIds?has_content>
|
||||
and gs.category_id in :categoryIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if brandIds?has_content>
|
||||
and gs.brand_id in :brandIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if unitIds?has_content>
|
||||
and gs.unit_id in :unitIds
|
||||
</#if>
|
||||
<#if warehouseIds?has_content>
|
||||
and d.warehouse_id in :warehouseIds
|
||||
</#if>
|
||||
|
||||
|
||||
) as "入库商品数量",
|
||||
|
||||
(select round(sum(d.amount)::::numeric, 2)
|
||||
|
||||
(select COALESCE(round(sum(d.amount)::::numeric, 2), 0)
|
||||
from t_warehouse_receipt re
|
||||
inner join t_warehouse_receipt_detail d
|
||||
on re.id = d.receipt_id
|
||||
@@ -1169,7 +1169,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
|
||||
</#if>
|
||||
@@ -1182,58 +1182,58 @@ from (
|
||||
<#if goodsIds?has_content>
|
||||
and gs.id in :goodsIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if barCode??>
|
||||
and gs.bar_code like '%' || :barCode || '%'
|
||||
</#if>
|
||||
<#if code??>
|
||||
and gs.code like '%' || :code || '%'
|
||||
</#if>
|
||||
|
||||
|
||||
|
||||
|
||||
<#if goodsName??>
|
||||
|
||||
|
||||
and gs.name like '%' || :goodsName || '%'
|
||||
|
||||
|
||||
</#if>
|
||||
<#if categoryIds?has_content>
|
||||
and gs.category_id in :categoryIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if brandIds?has_content>
|
||||
and gs.brand_id in :brandIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if unitIds?has_content>
|
||||
and gs.unit_id in :unitIds
|
||||
</#if>
|
||||
|
||||
|
||||
<#if warehouseIds?has_content>
|
||||
and d.warehouse_id in :warehouseIds
|
||||
</#if>
|
||||
|
||||
|
||||
) as "入库商品总价"
|
||||
|
||||
|
||||
|
||||
|
||||
from t_warehouse_supplier s
|
||||
where s.organization_id = :organizationId
|
||||
|
||||
|
||||
<#if supplierIds?has_content>
|
||||
and s.id in :supplierIds
|
||||
</#if>
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
select * from tmp1
|
||||
|
||||
|
||||
|
||||
|
||||
<#if excludeEmpty>
|
||||
|
||||
|
||||
where "入库单数量" > 0
|
||||
</#if>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
""",
|
||||
request);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user