From e0ea946e0894ad658f74eba1a400f9967c7a4aa5 Mon Sep 17 00:00:00 2001 From: yueli Date: Mon, 21 Sep 2026 10:33:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(outbound):=20=E5=87=BA=E5=BA=93=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E8=A1=A5=E4=BC=A0=E6=97=A5=E6=9C=9F=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=97=A5=E6=9C=9F=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E9=9D=99=E9=BB=98=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 前端 el-date-picker 一直传 start_date/end_date(outbound/index.vue:472), service 层 get_grouped_list() 也早有完整实现(签名接收 + 10 位日期补全 时分秒 + outbound_time 过滤),但中间 API 层从未读取这两个参数: outbound.py: get_outbound_list() 只读 page/limit/keyword/search_type/ company/advancedFilters,调用 get_grouped_list() 时也没传日期。 get_grouped_list 全项目仅此一个调用方,因此 start_date/end_date 恒为 None,service 层 `if start_date and end_date:` 永远为假——用户在页面上 选了日期,后端直接忽略,结果集与不筛选时完全一致,且不报错。 修复: · outbound.py 读取 start_date/end_date 并透传给 service · outbound_service.py 把 BETWEEN 改为分别判断(原写法只传一侧时 整段条件静默失效,与 /returns 等接口的边界处理对齐) 实测验证(SUPER_ADMIN 全量口径,与 SQL count(distinct outbound_no) 逐项对齐): 无日期 494 (基准) 2026-08-24 单日 3 SQL=3 2026-05-11 单日 9 SQL=9 2026-08 整月 88 SQL=88 只传 start_date 229 SQL=229 修复前上述四项均恒等于 494。运行中容器经 --reload 重载后实测一致。 影响范围:仅出库主列表。其余带日期筛选的接口(/returns、transactions、 scrap、purchase、audit、inbound_summary)均已正确读取参数,未受影响。 --- inventory-backend/app/api/v1/outbound.py | 5 +++++ inventory-backend/app/services/outbound_service.py | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/inventory-backend/app/api/v1/outbound.py b/inventory-backend/app/api/v1/outbound.py index d3e5019..b5896ed 100644 --- a/inventory-backend/app/api/v1/outbound.py +++ b/inventory-backend/app/api/v1/outbound.py @@ -238,6 +238,10 @@ def get_outbound_list(): keyword = request.args.get('keyword', '') search_type = request.args.get('search_type', 'all') company = request.args.get('company', '') + # ★ 出库日期范围:前端 el-date-picker 传 10 位 YYYY-MM-DD, + # 时分秒补全在 service 层完成(与 /returns 等处口径一致) + start_date = (request.args.get('start_date') or '').strip() + end_date = (request.args.get('end_date') or '').strip() # ★ 高级筛选:JSON 字符串 → 条件列表(解析失败退化为空,不影响主查询) from app.utils.advanced_filter import parse_advanced_filters @@ -259,6 +263,7 @@ def get_outbound_list(): # ★ [修改] 调用分组查询服务,支持搜索类型 result = OutboundService.get_grouped_list( page, limit, keyword, search_type=search_type, + start_date=start_date, end_date=end_date, company=company, consumer_name=consumer_name, advanced_filters=advanced_filters, ) diff --git a/inventory-backend/app/services/outbound_service.py b/inventory-backend/app/services/outbound_service.py index 6b86b92..7b03c33 100644 --- a/inventory-backend/app/services/outbound_service.py +++ b/inventory-backend/app/services/outbound_service.py @@ -708,8 +708,11 @@ class OutboundService: ) continue - if start_date and end_date: - stmt = stmt.filter(TransOutbound.outbound_time.between(start_date, end_date)) + # ★ 日期边界分别判断:用 BETWEEN 时若只传一侧会整段静默失效 + if start_date: + stmt = stmt.filter(TransOutbound.outbound_time >= start_date) + if end_date: + stmt = stmt.filter(TransOutbound.outbound_time <= end_date) # 【行级数据隔离】应用公司过滤到主查询 if company_limit is not None: