models.py
50.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
"""全部表定义。每张表、每个字段都有中文注释(tests 里有校验),Navicat「设计表」里能直接看到含义。
表名规则:atrs_<分类>_<名称>,注释以「【分类】」开头。分类:
sys 系统与门店:门店、用户、系统配置、厂商账号、业务功能、对话技能、话术、定时触发记录
edge 取数端:设备、任务、步骤、日志、DMS 接口流水、证据文件、版本包
ops 运维监控:操作日志、运行事件、告警
im 企微与消息:机器人、接收对象、消息去重、消息收发记录
ai 智能助手:每句话的处理过程、系统提示词(按内容去重)
restock 库存补货:补货单及明细 / 快照 / 出库明细、采购单、零件分类、SO 单、历史导出
概念(为多门店 / 多品牌预留,现在只有一个门店):
门店 atrs_sys_store ──1:N── 门店厂商账号 atrs_sys_store_dms_account(dms = 连接器代码,如 gtmc 广汽丰田 DMS)
└──────1:N── 门店业务功能 atrs_sys_store_feature(feature = restock 库存补货 …,含该门店的功能参数)
所有业务表都带 store_id;取数端按设备令牌归属门店。
"""
from __future__ import annotations
from .core.db import (JSON, BigInteger, Boolean, Column, Date, DateTime, Float, Index, Integer, LongText, String,
Table, Text, UniqueConstraint, metadata, now)
md = metadata
# ====================================================================== sys 系统与门店
stores_t = Table(
"atrs_sys_store", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="门店ID(自增主键)"),
Column("code", String(40), nullable=False, unique=True, comment="门店编码(唯一)"),
Column("name", String(100), nullable=False, comment="门店名称"),
Column("brand", String(60), comment="经营品牌,多个用逗号分隔,如 广汽丰田"),
Column("timezone", String(40), nullable=False, default="Asia/Shanghai", comment="门店时区(定时推送、截单都按门店本地时间)"),
Column("status", String(20), nullable=False, default="active", comment="状态:active 正常 / disabled 停用"),
Column("config_version", Integer, nullable=False, default=1, comment="取数端配置版本号:厂商账号、运行参数改动时 +1,取数端发现变化即重新拉取"),
Column("created_at", DateTime, default=now, comment="创建时间"),
Column("updated_at", DateTime, default=now, onupdate=now, comment="最后修改时间"),
comment="【系统】门店表:取数端、厂商账号、业务功能、企微接收对象都挂在门店上")
users_t = Table(
"atrs_sys_user", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="用户ID(自增主键)"),
Column("username", String(60), nullable=False, unique=True, comment="登录名(唯一)"),
Column("password_hash", String(200), nullable=False, comment="密码哈希(scrypt,不可逆)"),
Column("display_name", String(60), comment="显示名称"),
Column("role", String(30), nullable=False, default="admin", comment="角色:admin 管理员 / operator 普通用户(给客户用,只看业务页面;仅前端隐藏)"),
Column("status", String(20), nullable=False, default="active", comment="状态:active 正常 / disabled 停用"),
Column("default_password", Boolean, nullable=False, default=False, comment="是否仍在使用初始密码(后台顶部提示修改)"),
Column("token_version", Integer, nullable=False, default=1, comment="登录令牌版本:改密码时 +1,旧令牌立即失效"),
Column("last_login_at", DateTime, comment="最后登录时间"),
Column("created_at", DateTime, default=now, comment="创建时间"),
Column("updated_at", DateTime, default=now, onupdate=now, comment="最后修改时间"),
comment="【系统】后台用户表:企业后台的登录账号")
settings_t = Table(
"atrs_sys_config", md,
Column("k", String(100), primary_key=True, comment="配置项名称(主键):system 系统设置 / assistant 智能助手人设 / edge_runtime 取数端运行参数"),
Column("v", LongText, comment="配置值(JSON;敏感字段以 enc: 开头加密保存)"),
Column("updated_by", String(60), comment="最后修改人"),
Column("updated_at", DateTime, default=now, onupdate=now, comment="最后修改时间"),
comment="【系统】系统配置表:系统设置、智能助手人设、取数端运行参数等,每项一行,后台改完立即生效")
store_dms_t = Table(
"atrs_sys_store_dms_account", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="自增主键"),
Column("store_id", Integer, nullable=False, comment="门店ID(atrs_sys_store.id)"),
Column("dms", String(40), nullable=False, comment="厂商系统(连接器代码),如 gtmc = 广汽丰田 DMS"),
Column("username", String(100), comment="DMS 登录账号"),
Column("password_enc", String(500), comment="DMS 登录密码(加密保存,只在下发给取数端时解密)"),
Column("options", JSON, comment="连接参数 JSON:系统地址、客户端 ID 等(没填的用连接器默认值)"),
Column("enabled", Boolean, nullable=False, default=True, comment="是否启用:1 启用 / 0 停用"),
Column("updated_by", String(60), comment="最后修改人"),
Column("updated_at", DateTime, default=now, onupdate=now, comment="最后修改时间"),
UniqueConstraint("store_id", "dms"),
comment="【系统】门店厂商账号表:门店在各厂商系统(DMS)里的登录账号和连接参数,由云端统一下发给取数端;一个门店一个厂商一行")
store_features_t = Table(
"atrs_sys_store_feature", md,
Column("store_id", Integer, primary_key=True, comment="门店ID(atrs_sys_store.id,联合主键)"),
Column("feature", String(40), primary_key=True, comment="业务功能代码(联合主键),如 restock 库存补货"),
Column("enabled", Boolean, nullable=False, default=True, comment="是否开通:1 开通 / 0 关闭"),
Column("config", JSON, comment="功能参数 JSON(按功能的参数定义校验,没填的用默认值)"),
Column("updated_by", String(60), comment="最后修改人"),
Column("updated_at", DateTime, default=now, onupdate=now, comment="最后修改时间"),
comment="【系统】门店业务功能表:门店开通了哪些功能,以及每个功能的参数(如补货的推送时间、截单时间、关注仓)")
store_skills_t = Table(
"atrs_sys_store_skill", md,
Column("store_id", Integer, primary_key=True, comment="门店ID(atrs_sys_store.id,联合主键)"),
Column("skill", String(60), primary_key=True, comment="对话技能代码(联合主键),如 restock.single 单次补货 / restock.scheduled 定时补货"),
Column("enabled", Boolean, nullable=False, default=True, comment="是否启用:1 启用 / 0 停用(所属功能没开通时一律不可用)"),
Column("config", JSON, comment="技能参数 JSON(按技能的参数定义校验,没填的用默认值)"),
comment="【系统】门店对话技能表:智能助手在会话里能做哪些事(单次补货、定时补货进度 …)以及每个技能的参数;没有这一行 = 用技能的默认开关和参数")
texts_t = Table(
"atrs_sys_text_template", md,
Column("key", String(100), primary_key=True, comment="话术 / 提示词键(主键),如 restock.msg_list / agent.system"),
Column("content", LongText, comment="修改后的内容(Jinja2 语法);删掉这一行 = 恢复默认"),
Column("updated_by", String(60), comment="最后修改人"),
Column("updated_at", DateTime, default=now, onupdate=now, comment="最后修改时间"),
comment="【系统】话术与提示词表:企微消息模板和大模型提示词,只存后台改过的;没改过的用代码里的默认值")
schedule_marks_t = Table(
"atrs_sys_job_fired", md,
Column("id", BigInteger, primary_key=True, autoincrement=True, comment="自增主键"),
Column("store_id", Integer, nullable=False, comment="门店ID"),
Column("feature", String(40), nullable=False, comment="业务功能代码,如 restock"),
Column("job_key", String(60), nullable=False, comment="定时任务标识,如 push 推送 / preflight 预检"),
Column("biz_date", Date, nullable=False, comment="业务日期(门店本地日期)"),
Column("slot", String(10), nullable=False, comment="触发时刻 HH:MM"),
Column("fired_at", DateTime, default=now, comment="实际触发时间"),
UniqueConstraint("store_id", "feature", "job_key", "biz_date", "slot"),
comment="【系统】定时触发记录表:保证同一门店同一天同一时刻的定时任务只触发一次(服务重启也不会重复)")
# ====================================================================== edge 取数端
devices_t = Table(
"atrs_edge_device", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="设备ID(自增主键)"),
Column("store_id", Integer, nullable=False, index=True, comment="所属门店ID"),
Column("name", String(60), comment="设备名称(如 配件部电脑)"),
Column("token_hash", String(64), nullable=False, unique=True, comment="设备令牌的 sha256(鉴权用;明文的加密串见 token_enc)"),
Column("token_hint", String(16), comment="令牌前几位,便于人工辨认"),
Column("token_enc", String(255), comment="设备令牌明文的加密串(Fernet,页面上展示 / 复制用;老设备为空,重置令牌后补上)"),
Column("status", String(20), nullable=False, default="enabled", comment="状态:enabled 启用 / disabled 停用(拒绝连接)"),
Column("version", String(20), comment="取数端程序版本(心跳上报)"),
Column("capabilities", JSON, comment="支持的任务类型列表 JSON(心跳上报)"),
Column("online", Boolean, nullable=False, default=False, comment="是否在线(巡检判定;超过离线阈值没有心跳即离线)"),
Column("last_seen_at", DateTime, comment="最后一次心跳 / 领任务时间"),
Column("last_heartbeat", JSON, comment="最后一次心跳内容 JSON:状态、当前任务和步骤、DMS 登录统计、磁盘、待补发数等"),
Column("last_ip", String(60), comment="最后连接的来源 IP"),
Column("created_at", DateTime, default=now, comment="创建时间"),
comment="【取数端】设备表:每台门店电脑一条,每台一个令牌")
tasks_t = Table(
"atrs_edge_task", md,
Column("id", String(32), primary_key=True, comment="任务ID(主键,32 位十六进制)"),
Column("store_id", Integer, nullable=False, index=True, comment="门店ID"),
Column("device_id", Integer, comment="领取任务的设备ID(atrs_edge_device.id,领取前为空)"),
Column("feature", String(40), comment="发起任务的业务功能(sys = 系统自身)"),
Column("type", String(60), nullable=False, comment="任务类型:sys.check 自检 / restock.outbound 零件出库明细 / restock.quote 查库存·主数据·全国仓 / restock.so_sync 近期 SO 单同步 / restock.create_po 建采购单 / restock.screenshot_po 截图 / restock.export_history 历史导出 …"),
Column("params", LongText, comment="任务参数 JSON:含门店 store、厂商系统 dms、各步骤超时 _steps"),
Column("status", String(20), nullable=False, index=True, comment="状态:queued 待领取 / dispatched 执行中 / done 完成 / failed 失败 / expired 超时未领取 / unknown 已领取但结果未知 / late_done、late_failed 超时后才回传"),
Column("idempotency_key", String(100), unique=True, comment="幂等键:同一键只会建一个任务(如同一补货单只建一次采购单)"),
Column("ref", String(60), index=True, comment="业务关联(如 restock:run:12)"),
Column("timeout_s", Integer, comment="整体超时(秒)"),
Column("current_step", String(60), comment="当前步骤(取数端进度上报)"),
Column("step_started_at", DateTime, comment="当前步骤开始时间"),
Column("step_deadline", DateTime, comment="当前步骤超时时间点(超过即告警)"),
Column("last_progress_at", DateTime, comment="最后一次进度上报时间"),
Column("alerted", String(200), comment="已经告过警的事项(避免重复告警),逗号分隔"),
Column("created_at", DateTime, default=now, comment="下发时间"),
Column("dispatched_at", DateTime, comment="领取时间"),
Column("finished_at", DateTime, comment="回传结果时间"),
Column("result", LongText, comment="执行结果 JSON"),
Column("error", Text, comment="失败原因"),
Column("error_code", String(40), comment="结构化错误码:login_rejected / step_timeout / network / dms_error / unknown_result …"),
Index("ix_atrs_edge_task_store_status", "store_id", "status"),
comment="【取数端】任务表:云端下发、取数端长轮询领取(每个任务只会被领取一次);所有 DMS 操作都走这里")
task_steps_t = Table(
"atrs_edge_task_step", md,
Column("id", BigInteger, primary_key=True, autoincrement=True, comment="自增主键"),
Column("task_id", String(32), nullable=False, index=True, comment="任务ID(atrs_edge_task.id)"),
Column("seq", Integer, comment="步骤序号"),
Column("step", String(60), comment="步骤:login 登录 / query_part 查配件 / create_po 建单 / verify_po 回查 / screenshot 截图 …"),
Column("detail", String(300), comment="步骤说明(如 配件号)"),
Column("status", String(20), comment="状态:running 进行中 / ok 成功 / failed 失败 / timeout 超时"),
Column("timeout_s", Float, comment="本步骤超时(秒)"),
Column("started_at", DateTime, comment="开始时间"),
Column("finished_at", DateTime, comment="结束时间"),
Column("duration_ms", Integer, comment="耗时(毫秒)"),
Column("error", Text, comment="失败原因"),
comment="【取数端】任务步骤表:每个任务的分步骤进度和耗时(实时上报),用于定位卡在哪一步")
edge_logs_t = Table(
"atrs_edge_log", md,
Column("id", BigInteger, primary_key=True, autoincrement=True, comment="自增主键"),
Column("device_id", Integer, nullable=False, comment="设备ID(atrs_edge_device.id)"),
Column("store_id", Integer, nullable=False, comment="门店ID"),
Column("seq", BigInteger, nullable=False, comment="设备端日志序号(纳秒时间戳 + 计数,用于补传去重)"),
Column("ts", DateTime, comment="日志时间(设备本地时间)"),
Column("level", String(10), comment="级别:DEBUG / INFO / WARNING / ERROR"),
Column("logger", String(40), comment="来源 logger 名称"),
Column("task_id", String(32), comment="当时正在执行的任务ID(atrs_edge_task.id)"),
Column("msg", Text, comment="日志内容(已脱敏)"),
Column("received_at", DateTime, default=now, index=True, comment="云端收到时间(按它清理过期日志)"),
UniqueConstraint("device_id", "seq"),
Index("ix_atrs_edge_log_store_ts", "store_id", "ts"),
comment="【取数端】日志表:门店取数端的日志实时上传到云端(断网时本地暂存,恢复后补传)")
api_calls_t = Table(
"atrs_edge_dms_api_log", md,
Column("id", BigInteger, primary_key=True, autoincrement=True, comment="自增主键"),
Column("store_id", Integer, nullable=False, comment="门店ID"),
Column("task_id", String(32), nullable=False, index=True, comment="取数端任务ID(atrs_edge_task.id)"),
Column("ref", String(60), index=True, comment="业务关联(如 restock:run:12)"),
Column("seq", Integer, comment="任务内第几次调用"),
Column("ts", DateTime, comment="调用时间(取数端本地时间)"),
Column("endpoint", String(80), comment="接口名(地址最后一段,如 page-parts-shipmen-detailed)"),
Column("method", String(10), comment="HTTP 方法"),
Column("status", Integer, comment="HTTP 状态码(0 = 网络失败)"),
Column("code", String(20), comment="DMS 业务码 header.code(10000000 = 成功)"),
Column("message", String(200), comment="DMS 业务消息 header.message"),
Column("trace_id", String(80), comment="DMS traceId(找 DMS 方核对时用)"),
Column("elapsed_ms", Integer, comment="耗时(毫秒)"),
Column("rows", Integer, comment="返回行数"),
Column("ok", Boolean, comment="是否成功:1 成功 / 0 失败"),
Column("error", Text, comment="失败原因"),
Column("evidence_id", Integer, comment="完整流水文件(含请求体、响应正文)的文件ID(atrs_edge_file.id)"),
comment="【取数端】DMS 接口调用流水表:取数端每次调用 DMS 接口一行(完整请求 / 响应在证据文件里),审计时间线逐条可查")
evidence_t = Table(
"atrs_edge_file", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="文件ID(自增主键)"),
Column("store_id", Integer, nullable=False, index=True, comment="门店ID"),
Column("task_id", String(32), index=True, comment="来源任务ID(atrs_edge_task.id)"),
Column("kind", String(20), comment="类型:screenshot 截图 / screenshot_fallback 接口数据渲染的兜底截图 / api_trace DMS 接口调用流水(含请求、响应)/ request DMS 请求快照 / response DMS 响应快照 / export 导出文件 / file 其他"),
Column("name", String(120), comment="文件名"),
Column("path", String(300), comment="存储路径(相对 data/evidence 目录)"),
Column("sha256", String(64), comment="文件 sha256(防篡改校验)"),
Column("size", BigInteger, comment="文件大小(字节)"),
Column("mime", String(80), comment="MIME 类型"),
Column("created_at", DateTime, default=now, comment="上传时间"),
comment="【取数端】证据文件表:取数端上传的截图、建单请求 / 响应快照、DMS 接口流水、导出文件等")
releases_t = Table(
"atrs_edge_release", md,
Column("version", String(20), primary_key=True, comment="取数端版本号(主键),如 3.2.0"),
Column("build", String(60), comment="构建信息:构建时间 + 代码版本(git 短哈希)"),
Column("source", String(10), nullable=False, comment="来源:bundled 云端自带(部署时随云端代码带来)/ upload 后台上传"),
Column("sha256", String(64), nullable=False, comment="更新包 sha256(取数端下载后校验)"),
Column("size", BigInteger, comment="更新包大小(字节)"),
Column("path", String(300), nullable=False, comment="更新包路径(相对 data/edge_releases 目录)"),
Column("notes", Text, comment="版本说明"),
Column("created_by", String(60), comment="上传人 / 系统"),
Column("created_at", DateTime, default=now, comment="登记时间"),
comment="【取数端】版本包表:可推送给门店取数端的更新包(只含程序代码,不含 Python / 浏览器运行时)")
# ====================================================================== ops 运维监控
audit_t = Table(
"atrs_ops_audit_log", md,
Column("id", BigInteger, primary_key=True, autoincrement=True, comment="自增主键"),
Column("ts", DateTime, nullable=False, default=now, comment="发生时间"),
Column("store_id", Integer, comment="门店ID"),
Column("actor_type", String(20), comment="操作人类型:user 后台用户 / planner_im 企微计划员 / agent 智能体 / system 系统定时 / edge 取数端 / public 免登录页面"),
Column("actor_id", String(80), comment="操作人标识(用户ID / 企微 sender_id / 设备ID)"),
Column("actor_name", String(80), comment="操作人名称"),
Column("action", String(80), nullable=False, comment="动作,如 restock.run.confirm / dms.account.update / settings.update"),
Column("target_type", String(40), comment="操作对象类型"),
Column("target_id", String(80), comment="操作对象标识"),
Column("before", JSON, comment="修改前的内容 JSON"),
Column("after", JSON, comment="修改后的内容 JSON"),
Column("detail", JSON, comment="详情 JSON,如原话、工具调用、请求快照摘要"),
Column("ip", String(60), comment="来源 IP"),
Column("ua", String(200), comment="浏览器 User-Agent"),
Column("ref", String(60), comment="业务关联(如 restock:run:12)"),
Column("task_id", String(32), comment="关联的取数端任务ID(atrs_edge_task.id)"),
Index("ix_atrs_ops_audit_log_store_ts", "store_id", "ts"),
Index("ix_atrs_ops_audit_log_action", "action"),
comment="【运维】操作日志表:所有真实操作的留痕(只追加,不修改)")
events_t = Table(
"atrs_ops_event_log", md,
Column("id", BigInteger, primary_key=True, autoincrement=True, comment="自增主键"),
Column("ts", DateTime, default=now, index=True, comment="发生时间"),
Column("store_id", Integer, index=True, comment="门店ID(系统级事件为空)"),
Column("ref", String(60), index=True, comment="业务关联(如 restock:run:12)"),
Column("level", String(10), comment="级别:info / ok / warn / error"),
Column("source", String(20), comment="来源:flow 流程 / edge 取数端 / im 企业微信 / agent 智能体 / web 后台 / notify 通知 / system 系统"),
Column("msg", Text, comment="事件内容"),
comment="【运维】运行事件表:后台「实时日志」看到的流程运行记录(不等同于操作日志),定期清理")
alerts_t = Table(
"atrs_ops_alert", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="告警ID(自增主键)"),
Column("store_id", Integer, index=True, comment="门店ID(系统级告警为空)"),
Column("kind", String(60), nullable=False, comment="告警类型,如 edge.offline / edge.dms_login_rejected / restock.scan_failed"),
Column("key", String(120), nullable=False, comment="去重键(同类型同键的告警合并为一条)"),
Column("severity", String(10), comment="级别:info / warn / error / critical"),
Column("status", String(10), nullable=False, default="open", comment="状态:open 未解决 / resolved 已恢复"),
Column("title", String(200), comment="告警标题"),
Column("detail", Text, comment="告警详情"),
Column("first_at", DateTime, comment="首次发生时间"),
Column("last_at", DateTime, comment="最近一次发生时间"),
Column("last_notified_at", DateTime, comment="最近一次通知时间"),
Column("notify_count", Integer, default=0, comment="已通知次数"),
Column("occur_count", Integer, default=1, comment="发生次数"),
Column("resolved_at", DateTime, comment="恢复时间"),
Column("resolved_note", String(300), comment="恢复说明"),
Index("ix_atrs_ops_alert_open", "status", "store_id", "kind", "key"),
comment="【运维】告警表:取数端离线、DMS 账号异常、流程失败等,按去重键合并,恢复后关闭")
# ====================================================================== im 企微与消息
im_bots_t = Table(
"atrs_im_bot", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="自增主键"),
Column("name", String(60), nullable=False, comment="机器人名称(后台显示用)"),
Column("bot_id", String(80), nullable=False, unique=True, comment="网关里的机器人标识 bot_id(发消息时的 robot_key)"),
Column("channel", String(40), nullable=False, default="yjy_ww", comment="网关通道,默认 yjy_ww"),
Column("enabled", Boolean, nullable=False, default=True, comment="是否启用:1 启用 / 0 停用"),
Column("note", String(200), comment="备注"),
Column("created_at", DateTime, default=now, comment="创建时间"),
Column("updated_at", DateTime, default=now, onupdate=now, comment="最后修改时间"),
comment="【企微】机器人表:通过 imhub 网关接入的企业微信机器人账号")
im_targets_t = Table(
"atrs_im_target", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="自增主键"),
Column("store_id", Integer, nullable=False, index=True, comment="门店ID"),
Column("name", String(60), nullable=False, comment="接收对象名称,如 配件计划群 / 张三"),
Column("bot_ref", Integer, nullable=False, comment="使用哪个机器人发送(atrs_im_bot.id)"),
Column("kind", String(10), nullable=False, default="group", comment="类型:group 群聊 / single 单人"),
Column("contact_id", String(80), nullable=False, comment="会话 ID:群 id 或联系人 id"),
Column("contact_name", String(120), comment="通讯录里的群名 / 联系人名(从通讯录选择时一并保存,手填 ID 时为空)"),
Column("at_ids", String(300), comment="群里推清单 / 提醒时要 @ 的人(企微 user id,逗号分隔)"),
Column("bot_names", String(200), comment="机器人在这个群里的昵称(逗号分隔可写多个别名),用来判断消息是否 @ 了机器人"),
Column("purposes", JSON, comment="用途 JSON 列表:chat 补货对话(推清单、收回复、回执、提醒)/ alert 告警通知"),
Column("alert_min", String(10), nullable=False, default="warn", comment="告警通知的最低级别:info / warn / error / critical"),
Column("enabled", Boolean, nullable=False, default=True, comment="是否启用:1 启用 / 0 停用"),
Column("created_at", DateTime, default=now, comment="创建时间"),
Column("updated_at", DateTime, default=now, onupdate=now, comment="最后修改时间"),
comment="【企微】接收对象表:机器人把消息发到哪个群 / 哪个人、做什么用;补货对话对象同时也是计划员和智能体对话的地方")
im_seen_t = Table(
"atrs_im_msg_dedup", md,
Column("msg_id", String(80), primary_key=True, comment="企微消息ID(主键,插入冲突即已处理过)"),
Column("target_id", Integer, comment="接收对象ID(atrs_im_target.id)"),
Column("seen_at", DateTime, default=now, comment="首次处理时间"),
comment="【企微】消息去重表:收到的企微消息只处理一次")
notify_logs_t = Table(
"atrs_im_msg_log", md,
Column("id", BigInteger, primary_key=True, autoincrement=True, comment="自增主键"),
Column("ts", DateTime, default=now, index=True, comment="收发时间"),
Column("store_id", Integer, index=True, comment="门店ID"),
Column("direction", String(4), nullable=False, default="out", comment="方向:out 发出 / in 收到"),
Column("event", String(80), comment="事件:chat 补货对话 / reply 智能体回复 / alert 告警 / test 测试 …"),
Column("severity", String(10), comment="级别:info / warn / error / critical(告警消息)"),
Column("channel_kind", String(20), comment="通道:wecom 企业微信 / email 邮件"),
Column("target_name", String(60), comment="接收对象 / 发言人名称"),
Column("address", String(200), comment="实际地址(会话 ID / 邮箱)"),
Column("content", Text, comment="消息内容"),
Column("ref", String(60), index=True, comment="业务关联(如 restock:run:12,审计时间线按它把聊天记录串到补货单上)"),
Column("msg_id", String(80), comment="企微消息ID(收到的消息)"),
Column("ok", Boolean, comment="是否成功:1 成功 / 0 失败"),
Column("error", Text, comment="失败原因"),
Column("fallback", Boolean, default=False, comment="是否为企微失败后的邮件兜底:1 是 / 0 否"),
comment="【企微】消息收发记录表:企微 / 邮件的每一条收发记录")
# ====================================================================== ai 智能助手
ai_prompts_t = Table(
"atrs_ai_prompt", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="提示词版本ID(自增主键)"),
Column("sha1", String(40), nullable=False, unique=True, comment="内容的 sha1(同样的系统提示词只存一份)"),
Column("content", LongText, nullable=False, comment="发给大模型的完整系统提示词"),
Column("created_at", DateTime, default=now, comment="第一次用到的时间"),
comment="【智能助手】系统提示词表:每句话的处理记录只存提示词版本ID,内容按 sha1 去重存在这里")
ai_traces_t = Table(
"atrs_ai_trace", md,
Column("id", BigInteger, primary_key=True, autoincrement=True, comment="处理记录ID(自增主键)"),
Column("ts", DateTime, nullable=False, default=now, comment="收到这句话的时间"),
Column("store_id", Integer, nullable=False, comment="门店ID"),
Column("log_id", BigInteger, index=True, comment="收到的这条消息(atrs_im_msg_log.id)"),
Column("target_id", Integer, comment="会话(atrs_im_target.id)"),
Column("sender", String(80), comment="发言人"),
Column("text", Text, comment="原话(去掉 @机器人 之后)"),
Column("route", String(20), comment="处理方式:llm 大模型 / none 没有启用技能"),
Column("result", String(40), comment="结果:tool 工具已回复 / free_reply 自由回复 / free_reply_blocked 自由回复含数字被拦(旧规则,已不再产生) / "
"no_tool_text 没调工具就直接回复被拦 / reply_blocked 直接回复涉及业务被拦 / "
"refused 固定引导语 / llm_unavailable 大模型不可用 / tool_then_llm_error / no_skills"),
Column("model", String(80), comment="大模型名称"),
Column("prompt_id", Integer, comment="系统提示词版本(atrs_ai_prompt.id)"),
Column("context", LongText, comment="发给大模型的上下文:当前状态 + 最近聊天记录 + 这句话"),
Column("rounds", JSON, comment="每一轮大模型调用 JSON:耗时、token、思考、输出文字、发起的工具调用"),
Column("calls", JSON, comment="工具执行 JSON:工具、参数、结果、是否已回复、耗时、重复 / 被拦截"),
Column("reply", Text, comment="助手自己发出的回复(工具发的消息在收发记录里)"),
Column("error", Text, comment="大模型出错原因"),
Column("seconds", Float, comment="整句话处理耗时(秒)"),
Column("llm_ms", Integer, comment="其中大模型调用合计耗时(毫秒)"),
Column("tokens_in", Integer, comment="输入 token 合计"),
Column("tokens_out", Integer, comment="输出 token 合计"),
Column("ref", String(60), index=True, comment="业务关联(如 restock:run:12,单据时间线按它取)"),
Index("ix_atrs_ai_trace_store_ts", "store_id", "ts"),
comment="【智能助手】处理记录表:每句收到的话怎么处理的(给模型的输入、每一轮输出、工具执行、结果),按保留天数自动清理")
# ====================================================================== restock 库存补货
runs_t = Table(
"atrs_restock_plan", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="补货单ID(自增主键)"),
Column("store_id", Integer, nullable=False, comment="门店ID"),
Column("biz_date", Date, nullable=False, comment="业务日期(门店本地日期)"),
Column("doc_no", String(40), comment="补货单号 RP-日期-门店-序号"),
Column("token", String(40), unique=True, comment="手机单据页访问令牌(随机串)"),
Column("kind", String(10), nullable=False, default="scheduled", comment="类型:scheduled 定时补货(出库驱动,定时推送 + 后台手动补充)/ single 单次补货(群里一句话,不限次数)"),
Column("trigger", String(20), comment="触发方式:schedule 定时推送 / console 后台按钮 / chat 企微对话(仅单次补货)"),
Column("triggered_by", String(80), comment="触发人(计划员名称 / 系统 / 后台用户)"),
Column("trigger_target_id", Integer, index=True, comment="单次补货所属的企微接收对象ID(会话,atrs_im_target.id):每个会话同时只有一张,消息只发回这个会话"),
Column("trigger_text", String(500), comment="触发原话(对话触发)"),
Column("status", String(30), nullable=False, comment="状态:scanning 取数中 / scan_retry 取数失败等待重试 / refreshing 刷新取数中 / awaiting_confirm 待确认(定时:页面确认清单;单次:群里回「订」)/ creating 建单中 / create_unknown 建单异常(单次补货:建单结果未知,系统自动到 DMS 核实,期间会话暂停操作)/ screenshotting 截图中 / awaiting_submit 待确认提交(定时:页面点「确认提交」;单次:会话里回「确认提交」)/ submitting 提交中 / done 完成 / cancelled 不订 / 不提交 / error 出错 / superseded 被新单作废 / expired 过截单 / 过提交有效期未完成"),
Column("window_start", DateTime, comment="出库窗口起点(定时补货:前一天 15:00,含)"),
Column("window_end", DateTime, comment="出库窗口终点(定时补货:当天 15:00,不含)"),
Column("data_fetched_at", DateTime, comment="最近一次取数成功的时间(确认时超过有效期须刷新)"),
Column("fetch_seq", Integer, default=0, comment="第几轮取数(首次 1,每刷新一次 +1)"),
Column("refresh_count", Integer, default=0, comment="页面刷新次数"),
Column("outbound_stats", JSON, comment="最近一轮出库明细统计 JSON(行数、纯牌、厂家分类分布、对账结果等)"),
Column("message", Text, comment="状态说明 / 出错原因"),
Column("scan_attempts", Integer, default=0, comment="取数次数(失败自动重试会累加)"),
Column("next_retry_at", DateTime, comment="下次自动重试的时间(定时补货:重试取数;单次补货建单异常:下次自动核实)"),
Column("listed_at", DateTime, comment="补货清单推送给计划员的时间"),
Column("reminder_count", Integer, default=0, comment="提醒已发次数(定时补货:未确认提醒;单次补货:建单异常仍在核实的提醒)"),
Column("last_reminded_at", DateTime, comment="最近一次提醒时间(同上)"),
Column("urgent_sent", Boolean, default=False, comment="截单前紧急告警是否已发:1 已发 / 0 未发"),
Column("confirmed_by", String(80), comment="确认人"),
Column("confirmed_via", String(20), comment="确认渠道:chat 企微 / order_page 单据页 / console 后台"),
Column("confirmed_at", DateTime, comment="确认时间"),
Column("order_id", String(40), comment="DMS 采购单内部ID"),
Column("order_no", String(40), comment="DMS 采购单号"),
Column("create_unknown_at", DateTime, comment="上次建单结果未知的时间(定时补货:有值 = 再确认时先到 DMS 核实;单次补货:进入建单异常的时间,核实清楚后清空)"),
Column("submitted_by", String(80), comment="确认提交的人"),
Column("submitted_via", String(20), comment="确认提交渠道:chat 企微 / order_page 单据页"),
Column("submitted_at", DateTime, comment="确认提交时间"),
Column("closed_at", DateTime, comment="结束时间"),
Column("created_at", DateTime, default=now, comment="触发时间"),
Column("updated_at", DateTime, default=now, onupdate=now, comment="最后状态变更时间"),
Index("ix_atrs_restock_plan_store_date", "store_id", "biz_date"),
comment="【补货】补货单表:一次「取数 → 出补货清单 → 确认 → 建采购单 → 截图 → 确认提交」流程一条")
lines_t = Table(
"atrs_restock_plan_item", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="自增主键"),
Column("run_id", Integer, nullable=False, index=True, comment="补货单ID(atrs_restock_plan.id)"),
Column("store_id", Integer, nullable=False, comment="门店ID"),
Column("seq", Integer, comment="清单序号(只给建议量 > 0 的配件编号)"),
Column("part_no", String(40), comment="配件编号(DMS 零件号)"),
Column("name", String(100), comment="配件名称"),
Column("grp", String(10), comment="分组:stock 历史常备件(默认勾选)/ other 其他出库件(默认不勾)/ single 单次补货"),
Column("category", String(20), comment="在库零件分类(保养零件 / 机油 / 轮胎 / 养护品 / 钣喷件 / 未分类;分类表里没有为空)"),
Column("so_hit", JSON, comment="近 N 个月 SO 单命中 JSON:{order_count, last_order_no, last_order_date, order_nos}"),
Column("outbound_qty", Float, comment="窗口内纯牌净出库量"),
Column("outbound_rows", Integer, comment="窗口内出库明细行数"),
Column("mad", Float, comment="月均需求 MAD(DMS 库存查询)"),
Column("checked", Boolean, comment="是否勾选参与补货:1 勾选 / 0 不勾"),
Column("default_expected", Integer, comment="系统给的默认期望库存:有上次人工修改用上次,否则 推荐 = 库存 + 出库"),
Column("default_source", String(10), comment="默认期望来源:last 上次 / recommend 推荐"),
Column("last_expected", Integer, comment="上次人工修改的期望库存(没有为空)"),
Column("last_at", DateTime, comment="上次人工修改的时间"),
Column("last_by", String(80), comment="上次人工修改人 / 来源"),
Column("modified", Boolean, comment="本次是否人工修改过期望:1 是 / 0 否(只有人工修改才会成为下次的「上次」)"),
Column("expected", Integer, comment="期望库存(本次最终值:默认值或人工修改后的值)"),
Column("stock", Float, comment="DMS 实时库存"),
Column("trans_shipped", Float, comment="调拨在途"),
Column("unreceived", Float, comment="未收货"),
Column("in_transit", Float, comment="计入计算的在途(按配置取调拨在途 / 未收货 / 两者取大)"),
Column("suggested", Integer, comment="建议订购量 = 期望 −(库存 + 在途),小于 0 按 0"),
Column("cap", Integer, comment="DMS 当日剩余可订数量(空 = 无上限信息)"),
Column("min_qty", Integer, comment="DMS 起订量(订购数不能小于它)"),
Column("pack_qty", Integer, comment="DMS 包装数(订购数必须是它的整数倍)"),
Column("storage_limit", Integer, comment="DMS 库存上限(库存超过它时 DMS 当日可订为 0)"),
Column("purchased_today", Integer, comment="DMS 今日已订数量"),
Column("final_qty", Integer, comment="最终订购量(上限、缺货、计划员调整之后)"),
Column("tag", String(20), comment="标记:normal 正常 / capped 按上限 / oos 厂家缺货 / enough 库存充足 / in_transit_ok 在途已达标 / removed 计划员剔除 / error 查询失败"),
Column("note", String(300), comment="说明(也是「未订原因」)"),
Column("unit_price", Float, comment="单价(元)"),
Column("wh", JSON, comment="关注仓(全国仓)库存 JSON:{仓库名: 可用数量}"),
Column("error", Text, comment="查询失败原因"),
comment="【补货】补货单明细表:补货单里每个配件一行,含库存、在途、期望、建议量、最终订购量")
snapshots_t = Table(
"atrs_restock_plan_snapshot", md,
Column("id", BigInteger, primary_key=True, autoincrement=True, comment="自增主键"),
Column("run_id", Integer, nullable=False, index=True, comment="补货单ID(atrs_restock_plan.id)"),
Column("store_id", Integer, nullable=False, comment="门店ID"),
Column("kind", String(20), nullable=False, comment="快照类型:pushed 推给用户的清单 / refreshed 刷新后的清单 / confirmed 用户确认时提交的清单 / single_quote 单次补货的查询结果"),
Column("fetch_seq", Integer, comment="对应第几轮取数"),
Column("data", JSON, comment="完整清单 JSON(每行的分组、出库、库存、在途、月均、可订、全国仓、默认期望及来源、期望、补货数、是否勾选)"),
Column("actor", String(80), comment="操作人(确认快照)"),
Column("ip", String(60), comment="来源 IP(页面操作)"),
Column("created_at", DateTime, default=now, comment="快照时间"),
comment="【补货】补货清单快照表:给用户看过的每一版清单、用户确认时提交的清单,原样留存(只追加),避免扯皮")
outbound_rows_t = Table(
"atrs_restock_plan_outbound", md,
Column("id", BigInteger, primary_key=True, autoincrement=True, comment="自增主键"),
Column("run_id", Integer, nullable=False, index=True, comment="补货单ID(atrs_restock_plan.id)"),
Column("store_id", Integer, nullable=False, comment="门店ID"),
Column("fetch_seq", Integer, comment="第几轮取数(首次 1,每刷新一次 +1)"),
Column("ship_id", String(40), comment="出库明细ID(DMS)"),
Column("shipment_date", String(20), comment="出库日(带时分秒,DMS 原值)"),
Column("work_order_no", String(40), comment="工单号"),
Column("shipment_batch_no", String(40), comment="出库单号"),
Column("license_plate", String(20), comment="车牌号"),
Column("mfr", String(20), comment="厂家分类:纯牌 / 非纯"),
Column("part_no", String(40), comment="零件号码"),
Column("part_name", String(100), comment="零件名称"),
Column("settl_status", String(10), comment="结算状态(DMS 原值)"),
Column("qty", Float, comment="数量(负数为退货冲销)"),
Column("unit_price", Float, comment="店端销售单价(元)"),
Column("amount", Float, comment="销售金额(元)"),
Column("cost_price", Float, comment="成本单价(元)"),
Column("cost_amount", Float, comment="成本金额(元)"),
Column("raw", JSON, comment="DMS 返回的原始行 JSON"),
comment="【补货】补货单出库明细表:每轮取数时窗口内的全部出库明细(所有厂家分类,原样保存,审计用)")
po_t = Table(
"atrs_restock_purchase_order", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="自增主键"),
Column("run_id", Integer, index=True, comment="补货单ID(atrs_restock_plan.id)"),
Column("store_id", Integer, nullable=False, comment="门店ID"),
Column("order_id", String(40), comment="DMS 采购单内部ID"),
Column("order_no", String(40), comment="DMS 采购单号"),
Column("supplier_code", String(20), comment="供应商代码"),
Column("order_type", String(10), comment="订单类型(固定 S = SO 库存补充)"),
Column("status", String(20), comment="采购单状态:待提交 / 已提交(人工确认后系统在 DMS「检查并提交」)"),
Column("item_num", String(10), comment="明细项数"),
Column("total_amount", Float, comment="总金额(元)"),
Column("lines", JSON, comment="建单后 DMS 回查到的明细 JSON"),
Column("mismatch", JSON, comment="回查明细与请求不一致的项 JSON"),
Column("shots", JSON, comment="截图文件ID列表 JSON(atrs_edge_file.id)"),
Column("shots_fallback", String(10), comment="截图兜底:空 = DMS 页面真实截图 / image = 用接口数据渲染的兜底图 / text = 只发了文字明细"),
Column("fallback_reason", Text, comment="DMS 页面截图失败的原因(兜底时)"),
Column("create_task_id", String(32), comment="建单任务ID(atrs_edge_task.id)"),
Column("created_at", DateTime, default=now, comment="建单时间"),
Column("expect", JSON, comment="建单时的请求明细 JSON {lines:[{part_no, qty}], supplier_code, remark}(提交前核对用)"),
Column("submit_task_id", String(32), comment="提交任务ID(atrs_edge_task.id)"),
Column("submitted_by", String(80), comment="确认提交的人(群里回复人 / 单据页访客)"),
Column("submitted_at", DateTime, comment="云端确认提交成功的时间"),
Column("apply_operator", String(80), comment="DMS 提交人(info-parts-po.applyOperator,即 DMS 登录账号)"),
Column("apply_time", String(30), comment="DMS 提交时间(applyTime 原值)"),
Column("submit_lines", JSON, comment="提交后 DMS 回查的明细 JSON"),
Column("submit_error", Text, comment="最近一次提交失败的原因"),
comment="【补货】DMS 采购单表:在 DMS 创建的采购单(先建「待提交」,人工确认后提交),含回查明细、截图和提交结果")
categories_t = Table(
"atrs_restock_part_category", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="自增主键"),
Column("store_id", Integer, nullable=False, comment="门店ID"),
Column("part_no", String(40), nullable=False, comment="零件号码"),
Column("name", String(100), comment="零件名称"),
Column("category", String(20), nullable=False, comment="零件分类:保养零件 / 机油 / 轮胎 / 养护品 / 钣喷件 / 未分类(#N/A 和 0 都记为未分类)"),
Column("note", String(200), comment="备注"),
Column("source", String(20), comment="来源:seed 首次导入(需求文档里客户给的《在库零件分类》)/ console 后台维护 / import 批量导入"),
Column("updated_by", String(80), comment="最后修改人"),
Column("updated_at", DateTime, default=now, onupdate=now, comment="最后修改时间"),
UniqueConstraint("store_id", "part_no"),
comment="【补货】在库零件分类表:客户提供的《在库零件分类》,只取「零件分类」;属于常备分类(默认 保养零件/机油/轮胎/养护品)的出库件进「历史常备件」组")
so_parts_t = Table(
"atrs_restock_so_part", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="自增主键"),
Column("store_id", Integer, nullable=False, comment="门店ID"),
Column("part_no", String(40), nullable=False, comment="零件号码"),
Column("name", String(100), comment="零件名称"),
Column("order_count", Integer, comment="近 N 个月出现在几张 SO 单里"),
Column("qty_sum", Float, comment="近 N 个月 SO 单订购数量合计(扣除取消数量)"),
Column("order_nos", JSON, comment="命中的 SO 单号列表 JSON(最多 20 个)"),
Column("last_order_no", String(40), comment="最近一张 SO 单号"),
Column("last_order_date", String(20), comment="最近一张 SO 单创建时间"),
Column("sync_id", Integer, comment="来自哪次同步(atrs_restock_so_sync_log.id)"),
Column("synced_at", DateTime, comment="同步时间"),
UniqueConstraint("store_id", "part_no"),
comment="【补货】SO 单零件表:近 N 个月 SO(库存补充)单里出现过的零件,每周同步一次整表替换;出现在这里的出库件进「历史常备件」组")
so_orders_t = Table(
"atrs_restock_so_order", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="自增主键"),
Column("store_id", Integer, nullable=False, comment="门店ID"),
Column("order_no", String(40), nullable=False, comment="SO 单号"),
Column("create_time", String(20), comment="SO 单创建时间(DMS 原值)"),
Column("fingerprint", String(200), comment="订单头指纹(状态 / 项数 / 金额 / 更新时间):没变就复用明细,不再取"),
Column("lines", JSON, comment="明细按零件汇总 JSON:[{part_no, name, qty}]"),
Column("sync_id", Integer, comment="明细来自哪次同步(atrs_restock_so_sync_log.id)"),
Column("synced_at", DateTime, comment="明细取回时间"),
UniqueConstraint("store_id", "order_no"),
comment="【补货】SO 单明细缓存表:增量同步时订单头没变的单直接复用,只给新单 / 有变化的单取明细")
so_syncs_t = Table(
"atrs_restock_so_sync_log", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="同步ID(自增主键)"),
Column("store_id", Integer, nullable=False, index=True, comment="门店ID"),
Column("since", Date, comment="同步范围起点(SO 单创建时间 >= 这一天)"),
Column("status", String(20), nullable=False, comment="状态:running 进行中 / done 完成 / failed 失败"),
Column("trigger", String(20), comment="触发方式:schedule 每周定时 / console 后台手动"),
Column("triggered_by", String(80), comment="触发人"),
Column("orders", Integer, comment="SO 单张数"),
Column("lines", Integer, comment="明细行数"),
Column("parts", Integer, comment="零件种数"),
Column("filter_trusted", Boolean, comment="DMS 列表接口的 orderType 过滤是否生效:1 生效 / 0 不生效(取数端改为全量翻页 + 本地筛选)"),
Column("stats", JSON, comment="同步统计 JSON:过滤参数、第 1 页类型分布、翻页数、停在哪页、明细不一致等"),
Column("task_id", String(32), comment="取数端任务ID(atrs_edge_task.id)"),
Column("error", Text, comment="失败原因"),
Column("started_at", DateTime, default=now, comment="开始时间"),
Column("finished_at", DateTime, comment="结束时间"),
comment="【补货】SO 单同步记录表:每周一次(或后台手动)拉近 N 个月 SO 单,每次一行,留痕可查")
exports_t = Table(
"atrs_restock_history_export", md,
Column("id", Integer, primary_key=True, autoincrement=True, comment="导出ID(自增主键)"),
Column("store_id", Integer, nullable=False, index=True, comment="门店ID"),
Column("kind", String(20), nullable=False, comment="导出内容:stock 全量库存 / po 采购单及明细"),
Column("year", Integer, comment="采购单年份(kind=po 时)"),
Column("status", String(20), nullable=False, comment="状态:running 进行中 / done 完成 / failed 失败"),
Column("task_id", String(32), comment="取数端任务ID(atrs_edge_task.id)"),
Column("files", JSON, comment="导出文件ID列表 JSON(atrs_edge_file.id)"),
Column("summary", JSON, comment="导出摘要 JSON:条数、校验结果等"),
Column("error", Text, comment="失败原因"),
Column("created_by", String(60), comment="发起人"),
Column("created_at", DateTime, default=now, comment="发起时间"),
Column("finished_at", DateTime, comment="完成时间"),
comment="【补货】历史数据导出表:从 DMS 一次性导出全量库存 / 采购单历史,文件可在后台下载")
ALL = list(md.sorted_tables)