feat(后端): 添加授权体系、系统监控与试用期计提
按 2026-11-02 需求补齐计划交付后端能力: - 角色授权:权限目录化,接口统一准入校验,未登记默认拒绝; 管理员判断改为按数据库角色重新判定,防止权限码持有者绕过 - 系统监控:单进程采集资源、请求与异常指标,分钟级聚合, 阈值配置化;敏感配置增加 repr 保护,Redis 密码 URL 转义 - 试用期计提:按回款日判定并写入快照,年度结清与调整单联动; 人员模型补试用期、离职日期与工资版本历史字段 - 计提模板:公式骨架受控,页面维护名称与参数绑定 - T+ 采集:自动化配置表与进度查询 内置角色禁停用保护对齐模块注释;核算规则版本提为常量并 补充批量核算失败堆栈日志。 影响范围:后端全部模块、数据库迁移 V22-V28 验证:uv run ruff check 通过;922 个单元测试全部通过; 集成测试因本机 MySQL 数据卷被其他容器锁定暂未运行
这个提交包含在:
1 父节点
02fb06e0af
当前提交
1461a8d113
149 个文件已更改
+8736
-368
没有与搜索条件相匹配的文件
@@ -0,0 +1,68 @@
|
||||
"""源级自动采集设置;页面、周期维护共用,不修改进程环境配置。"""
|
||||
|
||||
from sqlalchemy import inspect, select, update
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from app.core.exceptions import BadRequestError, ConflictError
|
||||
from app.models import TPlusAutomationConfig
|
||||
from app.services.authorization_service import require_permission
|
||||
from app.services.tplus import task_service
|
||||
|
||||
|
||||
def configuration(session, settings):
|
||||
from app.services.tplus.automation import source_identity
|
||||
|
||||
result = {"enabled": settings.t_plus_automation_enabled, "version": 0,
|
||||
"editable": False, "configuration_origin": "ENVIRONMENT"}
|
||||
try:
|
||||
key, _database = source_identity(settings)
|
||||
except RuntimeError:
|
||||
return result
|
||||
if not inspect(session.connection()).has_table(TPlusAutomationConfig.__tablename__):
|
||||
return result
|
||||
result["editable"] = True
|
||||
row = session.scalar(select(TPlusAutomationConfig).where(
|
||||
TPlusAutomationConfig.source_key == key
|
||||
).execution_options(populate_existing=True))
|
||||
if row is not None:
|
||||
result.update(enabled=bool(row.enabled), version=row.version, configuration_origin="SAVED")
|
||||
return result
|
||||
|
||||
|
||||
def save(session, payload, actor):
|
||||
from app.services.tplus.automation import source_identity
|
||||
|
||||
require_permission(session, actor.user, "tplus:collect")
|
||||
settings = task_service.get_settings()
|
||||
try:
|
||||
key, database = source_identity(settings)
|
||||
except RuntimeError:
|
||||
raise BadRequestError("请先配置可用的 T+ 数据源") from None
|
||||
if not inspect(session.connection()).has_table(TPlusAutomationConfig.__tablename__):
|
||||
raise BadRequestError("自动采集设置尚未升级,请联系维护人员")
|
||||
data = {"enabled": payload.enabled, "expected_version": payload.expected_version}
|
||||
with task_service._audit(session, actor, "修改自动采集", data):
|
||||
row = session.scalar(select(TPlusAutomationConfig).where(TPlusAutomationConfig.source_key == key))
|
||||
if row is None:
|
||||
if payload.expected_version != 0:
|
||||
raise ConflictError()
|
||||
session.add(TPlusAutomationConfig(source_key=key, source_database=database,
|
||||
enabled=int(payload.enabled), version=1, updated_by=actor.user.id))
|
||||
try:
|
||||
session.commit()
|
||||
except IntegrityError:
|
||||
session.rollback()
|
||||
raise ConflictError() from None
|
||||
else:
|
||||
changed = session.execute(update(TPlusAutomationConfig).where(
|
||||
TPlusAutomationConfig.source_key == key,
|
||||
TPlusAutomationConfig.version == payload.expected_version,
|
||||
).values(enabled=int(payload.enabled), version=payload.expected_version + 1,
|
||||
updated_by=actor.user.id))
|
||||
if changed.rowcount != 1:
|
||||
session.rollback()
|
||||
raise ConflictError()
|
||||
session.commit()
|
||||
from app.services.tplus.automation import overview
|
||||
|
||||
return overview(session, settings=settings)
|
||||
在新工单中引用
屏蔽一个用户