refactor: region from document, not app config
- Add region column to leaudit_documents + LeauditDocument model - AuditServiceImpl: read region from document.region, not APP_REGION - RuleServiceImpl: ListBindings/CreateBinding accept Region parameter - RuleBindingCreateDTO: add region field - RuleController: pass region from query param/DTO to service - APP_REGION removed from binding queries; region flows from document Region is now per-document: each document carries its region at upload time, and rules are matched to the document's region at run time.
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from fastapi_admin.config import APP_REGION
|
||||
from fastapi_common.fastapi_common_logger import logger
|
||||
from fastapi_common.fastapi_common_sqlalchemy.database import GetAsyncSession
|
||||
from fastapi_common.fastapi_common_web.domain.responses import StatusCodeEnum
|
||||
@@ -78,7 +77,7 @@ class AuditServiceImpl(IAuditService):
|
||||
LIMIT 1
|
||||
"""
|
||||
),
|
||||
{"doc_type_id": document.typeId, "region": APP_REGION},
|
||||
{"doc_type_id": document.typeId, "region": document.region},
|
||||
)
|
||||
binding = bindingResult.mappings().first()
|
||||
if not binding or not binding["rule_set_id"] or not binding["rule_version_id"]:
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
from fastapi_admin.config import APP_REGION
|
||||
from fastapi_common.fastapi_common_sqlalchemy.database import GetAsyncSession
|
||||
from fastapi_common.fastapi_common_web.domain.responses import StatusCodeEnum
|
||||
from fastapi_common.fastapi_common_web.exception.LeauditException import LeauditException
|
||||
@@ -341,10 +340,11 @@ class RuleServiceImpl(IRuleService):
|
||||
Rollback=True,
|
||||
)
|
||||
|
||||
async def ListBindings(self, RuleType: str | None = None) -> list[RuleBindingVO]:
|
||||
"""列出规则类型绑定,可按规则类型过滤。"""
|
||||
async def ListBindings(self, RuleType: str | None = None, Region: str | None = None) -> list[RuleBindingVO]:
|
||||
"""列出规则类型绑定,可按规则类型/地区过滤。"""
|
||||
region = Region or ""
|
||||
async with GetAsyncSession() as Session:
|
||||
if RuleType:
|
||||
if RuleType and region:
|
||||
Result = await Session.execute(
|
||||
text(
|
||||
"""
|
||||
@@ -367,9 +367,9 @@ class RuleServiceImpl(IRuleService):
|
||||
ORDER BY b.priority DESC, b.id DESC
|
||||
"""
|
||||
),
|
||||
{"rule_type": RuleType, "region": APP_REGION},
|
||||
{"rule_type": RuleType, "region": region},
|
||||
)
|
||||
else:
|
||||
elif region:
|
||||
Result = await Session.execute(
|
||||
text(
|
||||
"""
|
||||
@@ -391,7 +391,53 @@ class RuleServiceImpl(IRuleService):
|
||||
ORDER BY rs.rule_type, b.priority DESC, b.id DESC
|
||||
"""
|
||||
),
|
||||
{"region": APP_REGION},
|
||||
{"region": region},
|
||||
)
|
||||
elif RuleType:
|
||||
Result = await Session.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT
|
||||
b.id,
|
||||
b.doc_type_id,
|
||||
b.doc_type_code,
|
||||
b.rule_set_id,
|
||||
b.binding_mode,
|
||||
b.priority,
|
||||
b.is_active,
|
||||
b.note,
|
||||
rs.rule_type,
|
||||
rs.rule_name
|
||||
FROM leaudit_rule_type_bindings b
|
||||
JOIN leaudit_rule_sets rs ON rs.id = b.rule_set_id
|
||||
WHERE rs.rule_type = :rule_type
|
||||
AND rs.deleted_at IS NULL
|
||||
ORDER BY b.priority DESC, b.id DESC
|
||||
"""
|
||||
),
|
||||
{"rule_type": RuleType},
|
||||
)
|
||||
else:
|
||||
Result = await Session.execute(
|
||||
text(
|
||||
"""
|
||||
SELECT
|
||||
b.id,
|
||||
b.doc_type_id,
|
||||
b.doc_type_code,
|
||||
b.rule_set_id,
|
||||
b.binding_mode,
|
||||
b.priority,
|
||||
b.is_active,
|
||||
b.note,
|
||||
rs.rule_type,
|
||||
rs.rule_name
|
||||
FROM leaudit_rule_type_bindings b
|
||||
JOIN leaudit_rule_sets rs ON rs.id = b.rule_set_id
|
||||
WHERE rs.deleted_at IS NULL
|
||||
ORDER BY rs.rule_type, b.priority DESC, b.id DESC
|
||||
"""
|
||||
),
|
||||
)
|
||||
return [
|
||||
RuleBindingVO(
|
||||
@@ -413,6 +459,7 @@ class RuleServiceImpl(IRuleService):
|
||||
self,
|
||||
DocTypeId: int,
|
||||
RuleSetId: int,
|
||||
Region: str = "default",
|
||||
BindingMode: str = "explicit",
|
||||
Priority: int = 0,
|
||||
DocTypeCode: str | None = None,
|
||||
@@ -473,7 +520,7 @@ class RuleServiceImpl(IRuleService):
|
||||
"rule_set_id": RuleSetId,
|
||||
"binding_mode": BindingMode,
|
||||
"priority": Priority,
|
||||
"region": APP_REGION,
|
||||
"region": Region,
|
||||
"note": Note,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user