feat(entity-dim): 账套维度收口批 — subjects/analysis_results 加列 + 分析结论账套化 + 模板实例化构造点补账套
ci/woodpecker/push/main Pipeline failed

- ① kpi_templates instantiate 构造点显式传会话账套(原缺 entity_id ⇒ 静默落 e1),kpi_code 判重按账套收紧
- ② kpi_subject_map 3 个读取点加护栏注释(不加列、不改语义)
- ③ subjects 分层:读口 union(NULL=全局标准准则科目 / N=账套私有),UPSERT 唯一键改 (entity_id, subject_code)
- ④ analysis_results 账套化:读/写/删三端点按会话账套判定归属(列未落地时 kpi_code JOIN 止血),
     无归属行进 unattributed 登记、删除一律 404
- 模型层按现网 DDL 补齐:KPIDefinition(template_id/is_system + uk_entity_kpi)、AnalysisResult.entity_id、Subject.entity_id
- 新增 migrate_{subjects,analysis_results}_entity_id_20260923.py(--check/--apply/--down)、
  22 条对账用例 test_entity_dimension_convergence_20260923.py

DDL 已由 ops 受控通道落地(subjects 21:31:56 / analysis_results 21:31:59 CST,审批 1e9b4d9a/5ffb1640)
本提交为切片提交,未 push(发布须另取放行)
This commit is contained in:
Hermes CI Fix
2026-09-23 21:39:24 +08:00
parent 0b3a8aa111
commit fb4609be14
14 changed files with 1429 additions and 65 deletions
+4 -4
View File
@@ -554,7 +554,7 @@ class TestSubjectsWrite:
def test_update_existing_switch(self, client: TestClient, db: Session):
db.add(Subject(subject_code="9301", subject_name="旧名称", level=1,
category="equity", is_active=1))
category="equity", is_active=1, entity_id=1)) # 账套维度:本账套私有行(分层后 NULL=全局标准科目)
db.commit()
resp = client.post(self.URL, json={
"subjects": [self._row("9301", "新名称", category="cost", level=2)],
@@ -603,9 +603,9 @@ class TestSubjectsWrite:
def test_revenue_existing_row_update_existing_true(self, client: TestClient, db: Session):
"""原 400 复现用例:库内既有 revenue 行(6001 主营业务收入)+ update_existing=true"""
db.add(Subject(subject_code="6001", subject_name="主营业务收入", level=1,
category="revenue", is_active=1))
category="revenue", is_active=1, entity_id=1)) # 本账套私有行(分层口径)
other = Subject(subject_code="6051", subject_name="其他业务收入", level=1,
category="revenue", is_active=1)
category="revenue", is_active=1, entity_id=1)
db.add(other)
db.commit()
before = db.query(Subject).count()
@@ -625,7 +625,7 @@ class TestSubjectsWrite:
def test_profit_loss_existing_row_update_existing_true(self, client: TestClient, db: Session):
db.add(Subject(subject_code="6901", subject_name="终止经营损益", level=1,
category="profit_loss", is_active=1))
category="profit_loss", is_active=1, entity_id=1)) # 本账套私有行(分层口径)
db.commit()
resp = client.post(self.URL, json={
"subjects": [self._row("6901", "终止经营损益(V2)", category="profit_loss")],