From be946cc6390ceef5f8d89041b6bde471468b9ac9 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Tue, 11 Mar 2025 00:35:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E9=80=81=E6=97=B6=E6=AE=B5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/community_timeperiod.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/api/endpoints/community_timeperiod.py b/app/api/endpoints/community_timeperiod.py index 154751a..8e7fe88 100644 --- a/app/api/endpoints/community_timeperiod.py +++ b/app/api/endpoints/community_timeperiod.py @@ -249,19 +249,16 @@ async def get_group_by_community( ): """根据社区进行 group 的配送时段列表""" try: - #1. 查询有配送时段数据的社区 - community_time_periods = db.query(CommunityTimePeriodDB).all() communities = db.query(CommunityDB).offset(skip).limit(limit).all() - #2. 查询社区的配送时段 - community_time_periods = db.query(CommunityTimePeriodDB, TimePeriodDB.name.label("time_period_name"),TimePeriodDB.from_time.label("time_period_from_time"), TimePeriodDB.to_time.label("time_period_to_time")).join(TimePeriodDB).filter( - CommunityTimePeriodDB.community_id.in_([community.id for community in communities]) - ).all() - #3. 根据社区进行 group 的配送时段列表 communities_with_time_periods = [] for community in communities: - community_time_periods = [ctp for ctp in community_time_periods if ctp.CommunityTimePeriodDB.community_id == community.id] + # 查询配送时段 + community_time_periods = db.query(CommunityTimePeriodDB, TimePeriodDB.name.label("time_period_name"),TimePeriodDB.from_time.label("time_period_from_time"), TimePeriodDB.to_time.label("time_period_to_time")).join(TimePeriodDB).filter( + CommunityTimePeriodDB.community_id == community.id + ).all() + communities_with_time_periods.append({ "community_id": community.id, "community_name": community.name,