vs_plg.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # vs_plg.py
  2. from typing import Callable, List, Dict
  3. from abc import ABC, abstractmethod
  4. from vs_types import VSPlgConfig, AppointmentType, VSQueryResult, VSBookResult
  5. # ================== 接口类 ==================
  6. class IVSPlg(ABC):
  7. """
  8. @brief 签证 API 接口类
  9. 该接口定义了签证系统的基本操作,包括配置、会话管理、查询、预订、
  10. 健康检查以及错误处理等。所有具体的签证 API 实现都需要继承该接口。
  11. """
  12. @abstractmethod
  13. def set_config(self, config: VSPlgConfig):
  14. """
  15. @brief 设置 API 的配置信息
  16. @param config 签证 API 配置对象
  17. """
  18. pass
  19. @abstractmethod
  20. def create_session(self) -> None:
  21. """
  22. @brief 创建一个新的会话, 抛异常则创建失败
  23. """
  24. pass
  25. @abstractmethod
  26. def query(self, apt_type: AppointmentType) -> VSQueryResult:
  27. """
  28. @brief 查询可用的签证预约信息, 抛异常则查询失败
  29. @return VSQueryResult 查询结果
  30. """
  31. pass
  32. @abstractmethod
  33. def book(self, slot_info: VSQueryResult, user_inputs) -> VSBookResult:
  34. """
  35. @brief 进行预约操作, 抛异常则预定失败
  36. @param slot_info 查询得到的可用时段信息
  37. @param user_inputs 用户输入的预约信息
  38. @return VSBookResult 预约结果
  39. """
  40. pass
  41. @abstractmethod
  42. def get_group_id(self) -> str:
  43. """
  44. @brief 获取当前 API 实例所属的分组 ID
  45. @return 分组 ID 字符串
  46. """
  47. pass
  48. @abstractmethod
  49. def keep_alive(self):
  50. """
  51. @brief 会话保活
  52. """
  53. pass
  54. @abstractmethod
  55. def health_check(self) -> bool:
  56. """
  57. @brief 健康检查,用于检测 API 服务是否正常
  58. @return true 表示健康状态良好,false 表示存在问题
  59. """
  60. pass
  61. @abstractmethod
  62. def set_log(self, logger: Callable[[str], None]) -> None:
  63. """
  64. @brief 设置日志输出工具
  65. """
  66. pass