feat(api-converter): 添加进销存采购订单API配置并实现本地缓存机制
新增api_config_9p04kww1pu.json配置文件,包含进销存采购订单相关的四个核心 API接口(查询列表、新建、详情、编辑),完善了load_api_configs函数, 增加本地文件缓存机制,支持从本地文件加载配置并在配置变更时同步保存, 优化refresh_api_configs函数以同步清理本地文件缓存。 BREAKING CHANGE: API配置方式调整,引入本地缓存机制可能影响原有部署流程
This commit is contained in:
@@ -0,0 +1,483 @@
|
||||
{
|
||||
"serverName": "lzwcai_mcp_api_converter",
|
||||
"description": "业务API集合",
|
||||
"domainUrl": "https://erp.lzwc.cn/api",
|
||||
"packageName": "lzwcai-mcp-dyntoolapi",
|
||||
"version": "1.0.0",
|
||||
"apiConfig": [
|
||||
{
|
||||
"id": "2019327913872793602",
|
||||
"enterpriseId": "1932095424144715777",
|
||||
"bizSysId": "1970385781825785858",
|
||||
"domainUrl": "https://erp.lzwc.cn/api",
|
||||
"interfaceName": "获取内容列表(进销存-采购订单)",
|
||||
"businessPrompts": "",
|
||||
"returnType": "JSON",
|
||||
"returnConversion": "{\"success_param\": \"code==200\", \"status_param\": \"code\", \"msg_param\": \"msg\", \"data\": \"data\"}",
|
||||
"header": null,
|
||||
"apiUrl": "/jxcPurchase/queryPageList",
|
||||
"parametersFormat": "0",
|
||||
"method": "POST",
|
||||
"status": 1,
|
||||
"version": "v1.0",
|
||||
"authenticationRequired": 1,
|
||||
"responseExample": null,
|
||||
"crudType": "0",
|
||||
"isView": 0,
|
||||
"templateType": "markdown",
|
||||
"viewTemplates": null,
|
||||
"parameters": [
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 1,
|
||||
"paramName": "Authorization",
|
||||
"paramType": "STRING",
|
||||
"paramPrompts": "注意Bearer后面有一个空格,即Bearer+空格+登录返回的token",
|
||||
"defaultValue": "Bearer {{token}}",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019327913872793602",
|
||||
"requestType": "header",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "1",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "page",
|
||||
"paramType": "INTEGER",
|
||||
"paramPrompts": "当前页码",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019327913872793602",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "2",
|
||||
"tags": "0",
|
||||
"example": "1"
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "limit",
|
||||
"paramType": "INTEGER",
|
||||
"paramPrompts": "每页条数",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019327913872793602",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "3",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "search",
|
||||
"paramType": "STRING",
|
||||
"paramPrompts": "搜索关键字",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019327913872793602",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "4",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "searchList[]",
|
||||
"paramType": "STRING",
|
||||
"paramPrompts": "高级搜索条件数组,注意用的时候参数名去掉中括号",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019327913872793602",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "5",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "sceneId",
|
||||
"paramType": "INTEGER",
|
||||
"paramPrompts": "场景ID",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019327913872793602",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "6",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "type",
|
||||
"paramType": "INTEGER",
|
||||
"paramPrompts": "",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019327913872793602",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "7",
|
||||
"tags": "0",
|
||||
"example": "10-采购订单"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "2019328946728542210",
|
||||
"enterpriseId": "1932095424144715777",
|
||||
"bizSysId": "1970385781825785858",
|
||||
"domainUrl": "https://erp.lzwc.cn/api",
|
||||
"interfaceName": "新建内容(进销存-采购订单)",
|
||||
"businessPrompts": "",
|
||||
"returnType": "JSON",
|
||||
"returnConversion": "{\"success_param\": \"code==200\", \"status_param\": \"code\", \"msg_param\": \"msg\", \"data\": \"data\"}",
|
||||
"header": null,
|
||||
"apiUrl": "/jxcPurchase/add",
|
||||
"parametersFormat": "0",
|
||||
"method": "POST",
|
||||
"status": 1,
|
||||
"version": "v1.0",
|
||||
"authenticationRequired": 1,
|
||||
"responseExample": null,
|
||||
"crudType": "0",
|
||||
"isView": 0,
|
||||
"templateType": "markdown",
|
||||
"viewTemplates": null,
|
||||
"parameters": [
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 1,
|
||||
"paramName": "Authorization",
|
||||
"paramType": "STRING",
|
||||
"paramPrompts": "注意Bearer后面有一个空格,即Bearer+空格+登录返回的token",
|
||||
"defaultValue": "Bearer {{token}}",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019328946728542210",
|
||||
"requestType": "header",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "1",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "entity",
|
||||
"paramType": "ARRAY",
|
||||
"paramPrompts": "基本信息,参考合同",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019328946728542210",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "2",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "examineFlowData",
|
||||
"paramType": "ARRAY",
|
||||
"paramPrompts": "审批流相关信息,参考合同",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019328946728542210",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "3",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "field",
|
||||
"paramType": "ARRAY",
|
||||
"paramPrompts": "字段相关信息,参考合同",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019328946728542210",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "4",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "productList",
|
||||
"paramType": "ARRAY",
|
||||
"paramPrompts": "产品列表",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019328946728542210",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "5",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "expendList",
|
||||
"paramType": "ARRAY",
|
||||
"paramPrompts": "扩展数据列表,字段参数参考为空",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019328946728542210",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "6",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "2019329359485804545",
|
||||
"enterpriseId": "1932095424144715777",
|
||||
"bizSysId": "1970385781825785858",
|
||||
"domainUrl": "https://erp.lzwc.cn/api",
|
||||
"interfaceName": "获取内容详情(进销存-采购订单)",
|
||||
"businessPrompts": "",
|
||||
"returnType": "JSON",
|
||||
"returnConversion": "{\"success_param\": \"code==200\", \"status_param\": \"code\", \"msg_param\": \"msg\", \"data\": \"data\"}",
|
||||
"header": null,
|
||||
"apiUrl": "/jxcPurchase/queryById/{id}",
|
||||
"parametersFormat": "0",
|
||||
"method": "POST",
|
||||
"status": 1,
|
||||
"version": "v1.0",
|
||||
"authenticationRequired": 1,
|
||||
"responseExample": null,
|
||||
"crudType": "0",
|
||||
"isView": 0,
|
||||
"templateType": "markdown",
|
||||
"viewTemplates": null,
|
||||
"parameters": [
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 1,
|
||||
"paramName": "Authorization",
|
||||
"paramType": "STRING",
|
||||
"paramPrompts": "注意Bearer后面有一个空格,即Bearer+空格+登录返回的token",
|
||||
"defaultValue": "Bearer {{token}}",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019329359485804545",
|
||||
"requestType": "header",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "1",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 1,
|
||||
"paramName": "id",
|
||||
"paramType": "STRING",
|
||||
"paramPrompts": "",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019329359485804545",
|
||||
"requestType": "path",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "2",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "2019330096911556610",
|
||||
"enterpriseId": "1932095424144715777",
|
||||
"bizSysId": "1970385781825785858",
|
||||
"domainUrl": "https://erp.lzwc.cn/api",
|
||||
"interfaceName": "编辑内容(进销存-采购订单)",
|
||||
"businessPrompts": "",
|
||||
"returnType": "JSON",
|
||||
"returnConversion": "{\"success_param\": \"code==200\", \"status_param\": \"code\", \"msg_param\": \"msg\", \"data\": \"data\"}",
|
||||
"header": null,
|
||||
"apiUrl": "/jxcPurchase/update",
|
||||
"parametersFormat": "0",
|
||||
"method": "POST",
|
||||
"status": 1,
|
||||
"version": "v1.0",
|
||||
"authenticationRequired": 1,
|
||||
"responseExample": null,
|
||||
"crudType": "0",
|
||||
"isView": 0,
|
||||
"templateType": "markdown",
|
||||
"viewTemplates": null,
|
||||
"parameters": [
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 1,
|
||||
"paramName": "Authorization",
|
||||
"paramType": "STRING",
|
||||
"paramPrompts": "注意Bearer后面有一个空格,即Bearer+空格+登录返回的token",
|
||||
"defaultValue": "Bearer {{token}}",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019330096911556610",
|
||||
"requestType": "header",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "1",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "entity",
|
||||
"paramType": "STRING",
|
||||
"paramPrompts": "基本信息,参考合同",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019330096911556610",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "2",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "examineFlowData",
|
||||
"paramType": "STRING",
|
||||
"paramPrompts": "审批流相关信息,参考合同",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019330096911556610",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "3",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "field",
|
||||
"paramType": "STRING",
|
||||
"paramPrompts": "字段相关信息,参考合同",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019330096911556610",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "4",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "productList",
|
||||
"paramType": "STRING",
|
||||
"paramPrompts": "产品列表",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019330096911556610",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "5",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
},
|
||||
{
|
||||
"keyParam": null,
|
||||
"required": 0,
|
||||
"paramName": "expendList",
|
||||
"paramType": "STRING",
|
||||
"paramPrompts": "扩展数据列表,字段参数参考为空",
|
||||
"defaultValue": "",
|
||||
"assoKey": null,
|
||||
"assoApiId": null,
|
||||
"memory": 0,
|
||||
"apiId": "2019330096911556610",
|
||||
"requestType": "formdata",
|
||||
"dataFormat": null,
|
||||
"validity": null,
|
||||
"sort": "6",
|
||||
"tags": "0",
|
||||
"example": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -138,13 +138,32 @@ def load_api_configs():
|
||||
config_key = f"business{business_uuid}"
|
||||
logger.info(f"租户配置变量名: {config_key}")
|
||||
|
||||
# 构建租户专属的配置文件路径
|
||||
memory_config_path = os.path.join(current_dir, f"api_config_{business_uuid}.json")
|
||||
|
||||
# 检查内存中是否已有该租户的配置
|
||||
if config_key in business_configs:
|
||||
logger.info(f"从内存中获取租户 {business_uuid} 的配置")
|
||||
return business_configs[config_key]
|
||||
|
||||
# 内存中没有,从业务平台获取
|
||||
logger.info(f"内存中没有租户 {business_uuid} 的配置,开始从业务平台获取...")
|
||||
# 内存中没有,尝试从本地文件加载
|
||||
if os.path.exists(memory_config_path):
|
||||
try:
|
||||
logger.info(f"尝试从本地文件加载租户配置: {memory_config_path}")
|
||||
with open(memory_config_path, "r", encoding="utf-8") as f:
|
||||
config = json.load(f)
|
||||
logger.info(f"成功从本地文件加载租户 {business_uuid} 的配置,包含 {len(config.get('apiConfig', []))} 个API配置")
|
||||
|
||||
# 存储到内存中
|
||||
business_configs[config_key] = config
|
||||
logger.info(f"配置已加载到内存变量: {config_key}")
|
||||
|
||||
return config
|
||||
except Exception as e:
|
||||
logger.warning(f"从本地文件加载配置失败: {str(e)},将从业务平台重新获取")
|
||||
|
||||
# 本地文件不存在或加载失败,从业务平台获取
|
||||
logger.info(f"本地文件不存在,开始从业务平台获取租户 {business_uuid} 的配置...")
|
||||
|
||||
try:
|
||||
# 从环境变量获取API ID列表
|
||||
@@ -181,6 +200,15 @@ def load_api_configs():
|
||||
logger.info(f"配置已存储到内存变量: {config_key}")
|
||||
logger.info(f"当前内存中共有 {len(business_configs)} 个租户配置")
|
||||
|
||||
# 保存到本地文件作为备份
|
||||
try:
|
||||
logger.info(f"保存配置到本地文件: {memory_config_path}")
|
||||
with open(memory_config_path, "w", encoding="utf-8") as f:
|
||||
json.dump(config, f, ensure_ascii=False, indent=2)
|
||||
logger.info("配置文件保存成功")
|
||||
except Exception as save_error:
|
||||
logger.warning(f"保存配置到本地文件失败(不影响运行): {str(save_error)}")
|
||||
|
||||
return config
|
||||
|
||||
except Exception as e:
|
||||
@@ -639,7 +667,7 @@ def refresh_api_configs():
|
||||
|
||||
这个函数实现了配置的热加载功能,支持两种模式:
|
||||
- 文件模式:当检测到配置文件变化时会被调用
|
||||
- 内存模式:强制重新从业务平台获取配置并更新内存
|
||||
- 内存模式:强制重新从业务平台获取配置并更新内存和本地文件
|
||||
|
||||
全局变量更新:
|
||||
- api_configs: 重新加载的API配置
|
||||
@@ -658,7 +686,7 @@ def refresh_api_configs():
|
||||
# 获取配置模式
|
||||
config_mode = os.getenv('configMode', 'memory').lower()
|
||||
|
||||
# 内存模式下需要清除当前租户的缓存配置,强制重新获取
|
||||
# 内存模式下需要清除当前租户的缓存配置和本地文件,强制重新获取
|
||||
if config_mode == 'memory':
|
||||
business_uuid = os.getenv('businessUuid')
|
||||
if business_uuid:
|
||||
@@ -666,6 +694,16 @@ def refresh_api_configs():
|
||||
if config_key in business_configs:
|
||||
logger.info(f"清除租户 {business_uuid} 的缓存配置")
|
||||
del business_configs[config_key]
|
||||
|
||||
# 删除本地配置文件,强制从业务平台重新获取
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
memory_config_path = os.path.join(current_dir, f"api_config_{business_uuid}.json")
|
||||
if os.path.exists(memory_config_path):
|
||||
try:
|
||||
os.remove(memory_config_path)
|
||||
logger.info(f"已删除本地配置文件: {memory_config_path}")
|
||||
except Exception as e:
|
||||
logger.warning(f"删除本地配置文件失败: {str(e)}")
|
||||
|
||||
# 重新加载API配置
|
||||
api_configs = load_api_configs()
|
||||
|
||||
@@ -2,11 +2,11 @@ import os
|
||||
|
||||
os.environ["modelId"] = "1946471611735015425"
|
||||
os.environ["bizSysId"] = "1970385781825785858"
|
||||
os.environ["bizSysApiIds"] = "[\"1970386761072058369\",\"1970386761185304578\",\"1970386761583763457\",\"1970386761420185602\"]"
|
||||
os.environ["businessUuid"] = "u9ua9ss2l8c"
|
||||
os.environ["bizSysApiIds"] = "[\"2019327913872793602\",\"2019328946728542210\",\"2019329359485804545\",\"2019330096911556610\"]"
|
||||
os.environ["businessUuid"] = "9p04kww1pu"
|
||||
os.environ["LZWCAI_CORP_MANAGER_URL"] = "http://192.168.2.236:8088"
|
||||
# 导入模块
|
||||
from lzwcai_mcp_api_converter.src.create_mcp import run_main
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_main()
|
||||
run_main()
|
||||
|
||||
Reference in New Issue
Block a user