models.py
5.43 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
"""SOP 的表:定义(带草稿)、发布版本(不可变)、运行实例、步骤运行。"""
from __future__ import annotations
import datetime as dt
from sqlalchemy import DateTime, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from ..core.db import _LONGTEXT, Base
from ..core.dbx import now
class SopDefinition(Base):
__tablename__ = "otlg_sop_def"
id: Mapped[str] = mapped_column(String(64), primary_key=True)
workspace: Mapped[str] = mapped_column(String(64), default="default", index=True)
title: Mapped[str] = mapped_column(String(255), default="")
description: Mapped[str] = mapped_column(Text, default="")
process_concept_id: Mapped[str] = mapped_column(String(64), default="", index=True)
owner_role: Mapped[str] = mapped_column(String(128), default="")
draft_spec_json: Mapped[str] = mapped_column(_LONGTEXT, default="{}")
draft_hash: Mapped[str] = mapped_column(String(64), default="")
status: Mapped[str] = mapped_column(String(16), default="draft") # draft / published / archived
current_version: Mapped[int] = mapped_column(Integer, default=0)
last_dry_run_json: Mapped[str] = mapped_column(Text, default="{}") # {hash, ok, run_id}
ai_generated: Mapped[int] = mapped_column(Integer, default=0)
created_by: Mapped[str] = mapped_column(String(128), default="")
created_at: Mapped[dt.datetime] = mapped_column(DateTime, default=now)
updated_at: Mapped[dt.datetime] = mapped_column(DateTime, default=now, onupdate=now)
class SopVersion(Base):
__tablename__ = "otlg_sop_version"
id: Mapped[str] = mapped_column(String(64), primary_key=True)
def_id: Mapped[str] = mapped_column(String(64), index=True)
version: Mapped[int] = mapped_column(Integer, default=1)
spec_json: Mapped[str] = mapped_column(_LONGTEXT, default="{}")
note: Mapped[str] = mapped_column(Text, default="")
published_by: Mapped[str] = mapped_column(String(128), default="")
created_at: Mapped[dt.datetime] = mapped_column(DateTime, default=now)
class SopRun(Base):
__tablename__ = "otlg_sop_run"
id: Mapped[str] = mapped_column(String(64), primary_key=True)
workspace: Mapped[str] = mapped_column(String(64), default="default", index=True)
def_id: Mapped[str] = mapped_column(String(64), index=True)
version_id: Mapped[str] = mapped_column(String(64), default="")
version: Mapped[int] = mapped_column(Integer, default=0) # 0 = 草稿试运行
title: Mapped[str] = mapped_column(String(255), default="")
mode: Mapped[str] = mapped_column(String(16), default="live") # live / dry_run / ai_readonly
params_json: Mapped[str] = mapped_column(_LONGTEXT, default="{}")
vars_json: Mapped[str] = mapped_column(_LONGTEXT, default="{}")
spec_json: Mapped[str] = mapped_column(_LONGTEXT, default="{}") # 运行时冻结的定义
status: Mapped[str] = mapped_column(String(24), default="running", index=True)
current_step: Mapped[str] = mapped_column(String(64), default="")
trigger: Mapped[str] = mapped_column(String(255), default="manual", index=True)
parent_step_run: Mapped[str] = mapped_column(String(64), default="", index=True)
# main = 人或定时发起的一次运行;row = 逐条处理里某一行的运行;subflow = 被当作子流程调起的运行
kind: Mapped[str] = mapped_column(String(16), default="main")
row_index: Mapped[int] = mapped_column(Integer, default=0)
parent_run_id: Mapped[str] = mapped_column(String(64), default="", index=True)
outcome: Mapped[str] = mapped_column(String(255), default="")
error: Mapped[str] = mapped_column(Text, default="")
started_by: Mapped[str] = mapped_column(String(128), default="")
# 这次运行处理的是哪个对象 / 哪条预警:流程运行是本体里的系统对象,靠它们连到业务对象和预警事件
subject_type: Mapped[str] = mapped_column(String(64), default="", index=True)
subject_key: Mapped[str] = mapped_column(String(255), default="", index=True)
subject_label: Mapped[str] = mapped_column(String(255), default="")
event_id: Mapped[str] = mapped_column(String(64), default="", index=True)
created_at: Mapped[dt.datetime] = mapped_column(DateTime, default=now, index=True)
finished_at: Mapped[dt.datetime | None] = mapped_column(DateTime, nullable=True)
class SopStepRun(Base):
__tablename__ = "otlg_sop_step_run"
id: Mapped[str] = mapped_column(String(64), primary_key=True)
run_id: Mapped[str] = mapped_column(String(64), index=True)
seq: Mapped[int] = mapped_column(Integer, default=0)
step_id: Mapped[str] = mapped_column(String(64), default="")
step_type: Mapped[str] = mapped_column(String(24), default="")
title: Mapped[str] = mapped_column(String(255), default="")
status: Mapped[str] = mapped_column(String(24), default="running")
inputs_json: Mapped[str] = mapped_column(_LONGTEXT, default="{}")
output_json: Mapped[str] = mapped_column(_LONGTEXT, default="null")
note: Mapped[str] = mapped_column(Text, default="")
error: Mapped[str] = mapped_column(Text, default="")
task_id: Mapped[str] = mapped_column(String(64), default="", index=True)
action_run_id: Mapped[str] = mapped_column(String(64), default="", index=True)
child_run_id: Mapped[str] = mapped_column(String(64), default="")
started_at: Mapped[dt.datetime] = mapped_column(DateTime, default=now)
finished_at: Mapped[dt.datetime | None] = mapped_column(DateTime, nullable=True)