export_container_timeliness_report.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from tools.query_container_timeliness_list import QueryContainerTimelinessListTool
  2. class ExportContainerTimelinessReportTool:
  3. name = 'export_container_timeliness_report'
  4. route_path = '/mcp/tools/exportContainerTimelinessReport'
  5. def __init__(self, api_client=None):
  6. self.api_client = api_client
  7. def metadata(self):
  8. date_field = {
  9. 'type': 'string',
  10. 'format': 'date',
  11. 'pattern': '^\\d{4}-\\d{2}-\\d{2}$',
  12. }
  13. number_array = {
  14. 'type': 'array',
  15. 'minItems': 1,
  16. 'maxItems': 200,
  17. 'items': {
  18. 'type': 'string',
  19. 'minLength': 1,
  20. 'maxLength': 100,
  21. 'pattern': '.*\\S.*',
  22. },
  23. }
  24. return {
  25. 'name': self.name,
  26. 'description': (
  27. '本工具只提交异步导出任务,不会在本次调用中等待文件生成,也禁止在一次调用内'
  28. '轮询任务状态。成功后返回任务引用(task_ref)和建议等待时间'
  29. '(retry_after_seconds)。稍后单独使用 query_export_task 查询任务状态或下载链接。'
  30. '使用场景:只有用户明确要求导出柜子时效统计报表并需要下载文件时才可调用。'
  31. '必须提供柜号数组、提单号数组或最多31个起运港当地日历日的干线实际出发时间闭区间;'
  32. '没有号码时干线实际出发时间必填,有号码时时间可选。柜号与提单号可同时传入并按AND收窄。'
  33. '号码类型不明确时必须先询问用户;用户没有明确号码类型时必须先询问:'
  34. '“请确认使用哪种号码导出:柜号还是提单号?”确认前不得调用。'
  35. '禁止使用:查看柜子时效表格、排舱列表、混用出库时间或其他后台页面筛选、'
  36. '一次调用内轮询 query_export_task。看表格改走 query_container_timeliness_list。'
  37. '不得根据号码格式猜测,不得跨字段或跨工具试查。'
  38. '参数名仅用于工具调用;向用户回答时只能使用中文业务名称,'
  39. '不得展示内部参数名。'
  40. ),
  41. 'input_schema': {
  42. 'type': 'object',
  43. 'properties': {
  44. 'container_codes': dict(
  45. number_array,
  46. description=(
  47. '柜号数组。仅当用户明确说柜号时使用;'
  48. '不得放入其他类型号码。'
  49. ),
  50. ),
  51. 'bl_numbers': dict(
  52. number_array,
  53. description=(
  54. '提单号数组。仅当用户明确说提单号时使用;'
  55. '不得放入其他类型号码。'
  56. ),
  57. ),
  58. 'departure_time_start': dict(
  59. date_field,
  60. description='干线实际出发时间开始日期,起运港当地日历日 YYYY-MM-DD。',
  61. ),
  62. 'departure_time_end': dict(
  63. date_field,
  64. description=(
  65. '干线实际出发时间结束日期,起运港当地日历日 YYYY-MM-DD,'
  66. '且与开始日期跨度不超过31个日历日。'
  67. ),
  68. ),
  69. },
  70. 'required': [],
  71. 'additionalProperties': False,
  72. },
  73. }
  74. def call(
  75. self,
  76. container_codes=None,
  77. bl_numbers=None,
  78. departure_time_start=None,
  79. departure_time_end=None,
  80. request_id='rq_export_container_timeliness_report',
  81. ):
  82. if self.api_client is None:
  83. raise RuntimeError(
  84. 'api client is required for export_container_timeliness_report'
  85. )
  86. payload = QueryContainerTimelinessListTool._locator_payload(
  87. container_codes,
  88. bl_numbers,
  89. departure_time_start,
  90. departure_time_end,
  91. )
  92. return self.api_client.call_tool(
  93. self.name, self.route_path, payload, request_id,
  94. )