from typing import Dict, Callable, Optional from vs_types import VSQueryResult, VSBookResult from toolkit.vs_cloud_api import VSCloudApi from toolkit.thread_pool import ThreadPool def notify_date_changes( query_result: VSQueryResult, cache: Optional[Dict[str, str]] = None, logger: Optional[Callable[[str], None]] = None ) -> bool: """ 档期变化微信通知。 若提供了 cache 字典(如 {routing_key: earliest_date}),仅在最早档期发生变化时推送并更新 cache。 """ current_earliest_date = query_result.earliest_date apt_type = query_result.apt_type if not current_earliest_date or not apt_type: return False if cache is not None: last_date = cache.get(apt_type.routing_key) if last_date == current_earliest_date: return False cache[apt_type.routing_key] = current_earliest_date def _push_to_wx(): try: push_content = ( f"📢【档期变化通知】\n" f"最早日期: {query_result.earliest_date}\n" f"目标国家: {apt_type.country}\n" f"递交城市: {apt_type.city}\n" f"签证类型: {apt_type.visa_type}\n" f"Routing: {apt_type.routing_key}" ) VSCloudApi.Instance().push_weixin_text(push_content) except Exception as e: if logger: logger(f"Failed to notify date change to cloud: {e}") ThreadPool.getInstance().enqueue(_push_to_wx) return True def notify_book_result( book_result: VSBookResult, order_id: Optional[str] = None, logger: Optional[Callable[[str], None]] = None ) -> bool: """ 预定成功微信通知。 仅在 book_result.success 为 True 时进行推送。 """ if not book_result.success: return False def _push_to_wx(): try: lines = [ "🎉 【预定成功通知】", "━━━━━━━━━━━━━━━", ] if order_id: lines.append(f"订单编号: {order_id}") lines.extend([ f"预约账号: {book_result.account}", f"预约日期: {book_result.book_date}", f"预约时间: {book_result.book_time}", f"预约编号: {book_result.urn}", f"支付链接: {book_result.payment_link if book_result.payment_link else '无需支付/暂无'}", "━━━━━━━━━━━━━━━", ]) push_content = "\n".join(lines) VSCloudApi.Instance().push_weixin_text(push_content) except Exception as e: if logger: logger(f"Failed to notify book result to cloud: {e}") ThreadPool.getInstance().enqueue(_push_to_wx) return True