update
This commit is contained in:
parent
b11520234f
commit
9d75cc250d
@ -348,7 +348,7 @@ async def create_order(
|
|||||||
# 添加到新订单队列
|
# 添加到新订单队列
|
||||||
if db_order.address_community_id:
|
if db_order.address_community_id:
|
||||||
background_tasks.add_task(
|
background_tasks.add_task(
|
||||||
redis_client.push_order_to_queue,
|
redis_client.push_new_order_to_queue,
|
||||||
db_order.address_community_id,
|
db_order.address_community_id,
|
||||||
db_order.orderid,
|
db_order.orderid,
|
||||||
db
|
db
|
||||||
@ -1461,7 +1461,7 @@ async def deliveryman_check_new_orders(
|
|||||||
"""检查新订单"""
|
"""检查新订单"""
|
||||||
|
|
||||||
# 从Redis获取新订单ID列表
|
# 从Redis获取新订单ID列表
|
||||||
order_ids = redis_client.pop_orders_from_queue(deliveryman.userid, deliveryman.community_id, 10)
|
order_ids = redis_client.pop_new_orders_from_queue(deliveryman.userid)
|
||||||
|
|
||||||
if not order_ids:
|
if not order_ids:
|
||||||
return success_response(data={
|
return success_response(data={
|
||||||
|
|||||||
@ -67,7 +67,7 @@ class RedisClient:
|
|||||||
logging.error(f"获取今日队列中的订单数量失败: {str(e)}")
|
logging.error(f"获取今日队列中的订单数量失败: {str(e)}")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def push_order_to_queue(self, community_id: int, order_id: str, db: Session) -> bool:
|
def push_new_order_to_queue(self, community_id: int, order_id: str, db: Session) -> bool:
|
||||||
"""
|
"""
|
||||||
添加新订单到社区队列
|
添加新订单到社区队列
|
||||||
|
|
||||||
@ -81,9 +81,9 @@ class RedisClient:
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# 查询所有社区的用户
|
# 查询所有社区的用户
|
||||||
users = db.query(UserDB).filter(UserDB.community_id == community_id, UserDB.roles == UserRole.DELIVERYMAN).all()
|
users = db.query(UserDB).filter(UserDB.community_id == community_id).all()
|
||||||
for user in users:
|
for user in users:
|
||||||
key = f"user:{user.userid}:community:{community_id}:new_orders"
|
key = f"deliveryman:{user.userid}:new_orders"
|
||||||
# 使用 LPUSH 将订单ID添加到列表头部
|
# 使用 LPUSH 将订单ID添加到列表头部
|
||||||
self.client.lpush(key, order_id)
|
self.client.lpush(key, order_id)
|
||||||
# 设置过期时间为24小时
|
# 设置过期时间为24小时
|
||||||
@ -93,7 +93,7 @@ class RedisClient:
|
|||||||
logging.error(f"添加新订单到队列失败: {str(e)}")
|
logging.error(f"添加新订单到队列失败: {str(e)}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def pop_orders_from_queue(self, user_id: int, community_id: int, count: int = 10) -> List[str]:
|
def pop_new_orders_from_queue(self, user_id: int, count: int = 10) -> List[str]:
|
||||||
"""
|
"""
|
||||||
获取社区新订单列表
|
获取社区新订单列表
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ class RedisClient:
|
|||||||
List[str]: 订单ID列表
|
List[str]: 订单ID列表
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
key = f"user:{user_id}:community:{community_id}:new_orders"
|
key = f"deliveryman:{user_id}:new_orders"
|
||||||
# 获取订单列表,
|
# 获取订单列表,
|
||||||
orders = self.client.lpop(key, count)
|
orders = self.client.lpop(key, count)
|
||||||
return orders
|
return orders
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user