| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- class QueryFuelRateListTool:
- name = 'query_fuel_rate_list'
- route_path = '/mcp/tools/queryFuelRateList'
- backend = 'base'
- def __init__(self, api_client=None):
- self.api_client = api_client
- def metadata(self):
- return {
- 'name': self.name,
- 'description': (
- '使用场景:用户要查询燃油系数配置时调用。可按燃油代码、生效时间、'
- '燃油类型、状态、产品、渠道、产品分类、渠道分类筛选。'
- '产品、渠道、产品分类、渠道分类可以填代码或名称,必须完整匹配,不能按包含搜索。'
- '燃油代码格式为RY加数字,例如RY12。燃油类型为销售燃油或成本燃油。'
- '状态为草稿、失效或启用。生效时间筛选的是该时间点正在生效的配置。'
- '不传筛选条件时返回当前公司的燃油系数。'
- '编辑草稿请使用save_fuel_rate并传入这里返回的燃油代码。'
- '生效或启用请使用enable_fuel_rate。'
- '禁止使用:失效、删除燃油系数。'
- '参数只用于工具内部调用;最终回答只能展示中文业务名称和燃油代码。'
- ),
- 'input_schema': {
- 'type': 'object',
- 'properties': {
- 'fuel_no': {
- 'type': 'string',
- 'minLength': 1,
- 'maxLength': 20,
- 'description': '燃油代码,格式为RY加数字,例如RY12。',
- },
- 'start_date': {
- 'type': 'string',
- 'minLength': 8,
- 'maxLength': 30,
- 'description': '生效时间,筛选该时间点生效的配置,格式YYYY-MM-DD。',
- },
- 'product': {
- 'type': 'string',
- 'minLength': 1,
- 'maxLength': 100,
- 'description': '产品代码或产品名称,必须完整匹配。',
- },
- 'channel': {
- 'type': 'string',
- 'minLength': 1,
- 'maxLength': 100,
- 'description': '渠道代码或渠道名称,必须完整匹配。',
- },
- 'product_type': {
- 'type': 'string',
- 'minLength': 1,
- 'maxLength': 100,
- 'description': '产品分类代码或名称,必须完整匹配。只适用于销售燃油。',
- },
- 'channel_type': {
- 'type': 'string',
- 'minLength': 1,
- 'maxLength': 100,
- 'description': '渠道分类代码或名称,必须完整匹配。只适用于成本燃油。',
- },
- 'price_type': {
- 'type': 'string',
- 'minLength': 1,
- 'maxLength': 20,
- 'description': '燃油类型。1或销售燃油,2或成本燃油。',
- },
- 'status': {
- 'type': 'string',
- 'minLength': 1,
- 'maxLength': 10,
- 'description': '状态。1或草稿,2或失效,3或启用。',
- },
- 'page': {'type': 'integer', 'minimum': 1, 'maximum': 100, 'default': 1},
- 'limit': {'type': 'integer', 'minimum': 1, 'maximum': 100, 'default': 20},
- },
- 'additionalProperties': False,
- },
- }
- def call(
- self,
- fuel_no=None,
- start_date=None,
- product=None,
- channel=None,
- product_type=None,
- channel_type=None,
- price_type=None,
- status=None,
- page=1,
- limit=20,
- request_id='rq_query_fuel_rate',
- ):
- if self.api_client is None:
- raise RuntimeError('api client is required for query_fuel_rate_list')
- payload = {
- 'page': _page(page),
- 'limit': _limit(limit),
- }
- _put_text(payload, 'fuel_no', fuel_no, 20)
- _put_text(payload, 'start_date', start_date, 30)
- _put_text(payload, 'product', product, 100)
- _put_text(payload, 'channel', channel, 100)
- _put_text(payload, 'product_type', product_type, 100)
- _put_text(payload, 'channel_type', channel_type, 100)
- _put_choice(payload, 'price_type', price_type, ('1', '2', '销售燃油', '成本燃油'))
- _put_choice(payload, 'status', status, ('1', '2', '3', '草稿', '失效', '启用'))
- return self.api_client.call_tool(self.name, self.route_path, payload, request_id)
- def _page(value):
- if isinstance(value, bool) or not isinstance(value, int) or value < 1 or value > 100:
- raise ValueError('page is invalid')
- return value
- def _limit(value):
- if isinstance(value, bool) or not isinstance(value, int) or value < 1 or value > 100:
- raise ValueError('limit is invalid')
- return value
- def _put_text(payload, key, value, max_length):
- if value is None:
- return
- if not isinstance(value, str):
- raise ValueError(key + ' is invalid')
- value = value.strip()
- if not value:
- return
- if len(value) > max_length:
- raise ValueError(key + ' is invalid')
- payload[key] = value
- def _put_choice(payload, key, value, choices):
- if value is None:
- return
- if isinstance(value, bool):
- raise ValueError(key + ' is invalid')
- if isinstance(value, int):
- value = str(value)
- if not isinstance(value, str) or value.strip() not in choices:
- raise ValueError(key + ' is invalid')
- payload[key] = value.strip()
|