refactor: 重构为 im_platform 包结构,表定义移入 models/

This commit is contained in:
yumoqing 2026-11-03 21:44:18 +08:00
parent 10af1ca2ad
commit 37e6c0e9f2
9 changed files with 295 additions and 79 deletions

16
.gitignore vendored Normal file
View File

@ -0,0 +1,16 @@
# build/test artifacts
.DS_Store
__pycache__/
*.pyc
*.pyo
build/
*.egg-info/
*.dist-info/
*.whl
logs/
*.log
.idea/
~$*
models/mysql.ddl.sql
*.pid
init/

0
im_platform/__init__.py Normal file
View File

12
im_platform/init.py Normal file
View File

@ -0,0 +1,12 @@
from aiohttp import web
from im_platform.api.webhooks import feishu_webhook, wecom_webhook
async def init_job(app):
app.router.add_post("/noimapi/feishu", feishu_webhook)
app.router.add_post("/noimapi/wecom", wecom_webhook)
yield
def load_im_platform():
add_cleanupctx(init_job)

View File

@ -1,63 +0,0 @@
{
"summary": [
{
"name": "im_tenant",
"title": "IM\u79df\u6237",
"primary": "id",
"catelog": "relation"
}
],
"fields": [
{
"name": "id",
"title": "ID",
"type": "str",
"length": 32
},
{
"name": "org_id",
"title": "\u7ec4\u7ec7ID",
"type": "str",
"length": 32
},
{
"name": "platform",
"title": "\u5e73\u53f0",
"type": "str",
"length": 16
},
{
"name": "app_id",
"title": "APPID",
"type": "str",
"length": 64
},
{
"name": "app_secret",
"title": "APPSECRET",
"type": "str",
"length": 128
},
{
"name": "corp_id",
"title": "\u4f01\u4e1aID",
"type": "str",
"length": 64
},
{
"name": "agent_id",
"title": "AgentID",
"type": "str",
"length": 32
}
],
"indexes": [
{
"name": "idx_org",
"idxtype": "index",
"idxfields": [
"org_id"
]
}
]
}

View File

@ -1,16 +0,0 @@
from aiohttp import web
from im_platform.api.webhooks import feishu_webhook, wecom_webhook
async def init_app():
app = web.Application()
app.router.add_post("/webhook/feishu", feishu_webhook)
app.router.add_post("/webhook/wecom", wecom_webhook)
return app
if __name__ == "__main__":
import asyncio
app = asyncio.run(init_app())
web.run_app(app, port=8080)

99
models/im_event_log.json Normal file
View File

@ -0,0 +1,99 @@
{
"summary":[
{
"name":"im_event_log",
"title":"IM事件日志",
"primary":"id",
"catelog":"entity"
}
],
"fields":[
{
"name":"id",
"title":"ID",
"type":"str",
"length":32,
"nullable":"no",
"comments":"主键"
},
{
"name":"event_id",
"title":"事件ID",
"type":"str",
"length":64,
"nullable":"no",
"comments":"平台事件ID"
},
{
"name":"org_id",
"title":"组织ID",
"type":"str",
"length":32,
"nullable":"no",
"comments":"系统组织ID"
},
{
"name":"platform",
"title":"平台",
"type":"str",
"length":16,
"nullable":"no",
"comments":"feishu wecom"
},
{
"name":"event_type",
"title":"事件类型",
"type":"str",
"length":64,
"nullable":"yes",
"comments":"事件类型"
},
{
"name":"im_user_id",
"title":"IM用户ID",
"type":"str",
"length":64,
"nullable":"yes",
"comments":"平台用户ID"
},
{
"name":"payload",
"title":"事件数据",
"type":"text",
"nullable":"yes",
"comments":"完整事件数据"
},
{
"name":"status",
"title":"处理状态",
"type":"short",
"nullable":"no",
"default":"0",
"comments":"0未处理 1已处理"
},
{
"name":"ctime",
"title":"创建时间",
"type":"timestamp",
"nullable":"no",
"comments":"事件时间"
}
],
"indexes":[
{
"name":"idx_event",
"idxtype":"unique",
"idxfields":["event_id"]
},
{
"name":"idx_org",
"idxtype":"index",
"idxfields":["org_id"]
},
{
"name":"idx_platform",
"idxtype":"index",
"idxfields":["platform"]
}
]
}

128
models/im_message.json Normal file
View File

@ -0,0 +1,128 @@
{
"summary":[
{
"name":"im_message",
"title":"IM消息中心",
"primary":"id",
"catelog":"entity"
}
],
"fields":[
{
"name":"id",
"title":"ID",
"type":"str",
"length":32,
"nullable":"no",
"comments":"主键"
},
{
"name":"org_id",
"title":"组织ID",
"type":"str",
"length":32,
"nullable":"no",
"comments":"组织ID"
},
{
"name":"platform",
"title":"平台",
"type":"str",
"length":16,
"nullable":"no",
"comments":"feishu wecom"
},
{
"name":"msg_id",
"title":"消息ID",
"type":"str",
"length":64,
"nullable":"yes",
"comments":"平台消息ID"
},
{
"name":"chat_id",
"title":"会话ID",
"type":"str",
"length":64,
"nullable":"yes",
"comments":"群聊或会话ID"
},
{
"name":"from_user",
"title":"发送用户",
"type":"str",
"length":64,
"nullable":"yes",
"comments":"发送人"
},
{
"name":"to_user",
"title":"接收用户",
"type":"str",
"length":64,
"nullable":"yes",
"comments":"接收人"
},
{
"name":"msg_type",
"title":"消息类型",
"type":"str",
"length":32,
"nullable":"no",
"comments":"text image file markdown"
},
{
"name":"content",
"title":"消息内容",
"type":"text",
"nullable":"yes",
"comments":"消息体"
},
{
"name":"direction",
"title":"消息方向",
"type":"short",
"nullable":"no",
"default":"0",
"comments":"0接收 1发送"
},
{
"name":"status",
"title":"状态",
"type":"short",
"nullable":"no",
"default":"0",
"comments":"0正常 1撤回"
},
{
"name":"ctime",
"title":"创建时间",
"type":"timestamp",
"nullable":"no",
"comments":"消息时间"
}
],
"indexes":[
{
"name":"idx_org",
"idxtype":"index",
"idxfields":["org_id"]
},
{
"name":"idx_msg",
"idxtype":"index",
"idxfields":["msg_id"]
},
{
"name":"idx_chat",
"idxtype":"index",
"idxfields":["chat_id"]
},
{
"name":"idx_user",
"idxtype":"index",
"idxfields":["from_user","to_user"]
}
]
}

24
models/im_tenant.json Normal file
View File

@ -0,0 +1,24 @@
{
"summary":[
{
"name":"im_tenant",
"title":"IM租户",
"primary":"id",
"catelog":"relation"
}
],
"fields":[
{"name":"id","title":"ID","type":"str","length":32},
{"name":"org_id","title":"组织ID","type":"str","length":32},
{"name":"platform","title":"平台","type":"str","length":16},
{"name":"app_id","title":"APPID","type":"str","length":64},
{"name":"app_secret","title":"APPSECRET","type":"str","length":128},
{"name":"corp_id","title":"企业ID","type":"str","length":64},
{"name":"agent_id","title":"AgentID","type":"str","length":32},
{"name":"status","title":"状态","type":"short"}
],
"indexes":[
{"name":"idx_org","idxtype":"index","idxfields":["org_id"]},
{"name":"idx_platform","idxtype":"index","idxfields":["platform"]}
]
}

16
models/im_user_map.json Normal file
View File

@ -0,0 +1,16 @@
{
"summary":[
{
"name":"im_user_map",
"title":"IM用户映射",
"primary":"id"
}
],
"fields":[
{"name":"id","title":"ID","type":"str","length":32},
{"name":"org_id","title":"组织ID","type":"str","length":32},
{"name":"user_id","title":"系统用户","type":"str","length":32},
{"name":"platform","title":"平台","type":"str","length":16},
{"name":"im_user_id","title":"IM用户ID","type":"str","length":64}
]
}