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,