diff --git a/inventory-backend/app/api/v1/transactions.py b/inventory-backend/app/api/v1/transactions.py index 2c2207e..ef5c60f 100644 --- a/inventory-backend/app/api/v1/transactions.py +++ b/inventory-backend/app/api/v1/transactions.py @@ -162,6 +162,8 @@ def get_records(): page = int(request.args.get('page', 1)) keyword = request.args.get('keyword', '') search_type = request.args.get('search_type', 'all') + start_date = request.args.get('start_date', '') + end_date = request.args.get('end_date', '') # ★ 数据权限:普通用户只看“借用人=本人姓名(不含账号前缀)”的借还记录;管理者看全部 borrower_name = None @@ -175,7 +177,8 @@ def get_records(): res = TransService.get_records( page=page, limit=10, status=status, keyword=keyword, - search_type=search_type, borrower_name=borrower_name + search_type=search_type, borrower_name=borrower_name, + start_date=start_date, end_date=end_date, ) # ★ service 层异常时:code==500 的字典(带 traceback),需要直通到前端,便于排查 diff --git a/inventory-backend/app/services/trans_service.py b/inventory-backend/app/services/trans_service.py index 1f10c57..78c8172 100644 --- a/inventory-backend/app/services/trans_service.py +++ b/inventory-backend/app/services/trans_service.py @@ -414,7 +414,8 @@ class TransService: raise e @staticmethod - def get_records(page=1, limit=10, status='all', keyword=None, search_type='all', borrower_name=None): + def get_records(page=1, limit=10, status='all', keyword=None, search_type='all', + borrower_name=None, start_date=None, end_date=None): """ 获取借还记录列表(按单号 borrow_no 维度分页,避免明细撑爆 pageSize) @@ -429,7 +430,14 @@ class TransService: 状态过滤按"单号聚合"判定: - borrowed: 单号下至少有一条 is_returned=False - returned: 单号下所有明细 is_returned=True + + 日期范围按「借出时间」过滤,边界补全时分秒以解决零点截断问题。 """ + # 日期补全:与出库记录同口径 + if end_date and len(str(end_date).strip()) == 10: + end_date = f"{str(end_date).strip()} 23:59:59" + if start_date and len(str(start_date).strip()) == 10: + start_date = f"{str(start_date).strip()} 00:00:00" try: # ==================================================================== # 步骤 1a:构造"单号维度"基础子查询(GROUP BY borrow_no 在这里完成) @@ -680,6 +688,20 @@ class TransService: order_subq.c.borrow_no.in_(company_borrow_nos_subq) ) + # 日期范围过滤(按借出时间;边界已在入口补全时分秒) + if start_date: + borrow_no_q = borrow_no_q.filter(order_subq.c.borrow_no.in_( + db.session.query(TransBorrow.borrow_no) + .filter(TransBorrow.borrow_time >= start_date) + .distinct() + )) + if end_date: + borrow_no_q = borrow_no_q.filter(order_subq.c.borrow_no.in_( + db.session.query(TransBorrow.borrow_no) + .filter(TransBorrow.borrow_time <= end_date) + .distinct() + )) + # 状态过滤(按"单号聚合"判定) if status == 'borrowed': # 单号下至少一条未还 diff --git a/inventory-web/src/views/outbound/index.vue b/inventory-web/src/views/outbound/index.vue index 6c6a251..66a369f 100644 --- a/inventory-web/src/views/outbound/index.vue +++ b/inventory-web/src/views/outbound/index.vue @@ -1,41 +1,51 @@