feat(后端): 添加授权体系、系统监控与试用期计提

按 2026-11-02 需求补齐计划交付后端能力:
- 角色授权:权限目录化,接口统一准入校验,未登记默认拒绝;
  管理员判断改为按数据库角色重新判定,防止权限码持有者绕过
- 系统监控:单进程采集资源、请求与异常指标,分钟级聚合,
  阈值配置化;敏感配置增加 repr 保护,Redis 密码 URL 转义
- 试用期计提:按回款日判定并写入快照,年度结清与调整单联动;
  人员模型补试用期、离职日期与工资版本历史字段
- 计提模板:公式骨架受控,页面维护名称与参数绑定
- T+ 采集:自动化配置表与进度查询

内置角色禁停用保护对齐模块注释;核算规则版本提为常量并
补充批量核算失败堆栈日志。

影响范围:后端全部模块、数据库迁移 V22-V28
验证:uv run ruff check 通过;922 个单元测试全部通过;
集成测试因本机 MySQL 数据卷被其他容器锁定暂未运行
This commit is contained in:
liuwenxin committed 2026-11-03 11:20:55 +08:00
1 parent 02fb06e0af
commit 1461a8d113
149 files changed
+8736 -368

No files matched your search

+21 -6
View File
@@ -35,7 +35,7 @@ from app.core.constants import (
ROLE_FINANCE,
ROLE_LEADER,
)
from app.core.exceptions import BadRequestError, ForbiddenError, NotFoundError
from app.core.exceptions import BadRequestError, NotFoundError
from app.core.response import PageResult
from app.models import ApprovalOrder, ApprovalStep, Business, User
from app.models.approval import (
@@ -53,7 +53,6 @@ from app.models.approval import (
APPROVAL_STATUS_REJECTED,
APPROVAL_STATUS_WITHDRAWN,
)
from app.repositories import user_repository
from app.schemas.approval import (
ApprovalActionIn,
ApprovalOrderDetailOut,
@@ -261,7 +260,6 @@ def act(
驳回:任一在途状态 → 4(整体驳回,一期不退回重走)。
节点留痕的 node 取**动作发生时的当前节点**(通过/驳回都记在操作节点上)。
"""
codes = set(user_repository.get_role_codes(operator))
verb = ACTION_APPROVE if payload.action == APPROVAL_ACTION_APPROVE else ACTION_REJECT
from app.core.config import get_settings
@@ -281,15 +279,29 @@ def act(
),
meta=meta,
):
order = session.get(ApprovalOrder, order_id, with_for_update=True)
# 与工资生成保持相同人员锁顺序,审核驳回释放年度余额不得绕过结清锁。
hint = session.get(ApprovalOrder, order_id)
if hint is not None and hint.order_type in (2, 3):
from app.models import AdjustmentOrder, Personnel, SettlementItem
person_ids = []
if hint.order_type == 2:
person_ids = list(session.scalars(select(SettlementItem.personnel_id).where(SettlementItem.settlement_id == hint.ref_id)))
else:
target_adjustment = session.get(AdjustmentOrder, hint.ref_id)
if target_adjustment:
person_ids = [target_adjustment.personnel_id]
list(session.scalars(select(Personnel).where(Personnel.id.in_(person_ids)).order_by(Personnel.id).with_for_update()))
order = session.get(ApprovalOrder, order_id, with_for_update=True, populate_existing=True)
if order is None:
raise NotFoundError("审批单不存在")
if order.status not in _PENDING_STATUSES:
raise BadRequestError("审批单已结束,不可重复操作")
required_role = _NODE_ROLE_BY_STATUS[order.status]
if required_role not in codes:
raise ForbiddenError(f"当前节点须{_ROLE_LABEL[required_role]}角色操作")
from app.services.authorization_service import require_permission
require_permission(session, operator, "approvals:" + required_role)
node_now = APPROVAL_NODES[order.status]
rejected = payload.action == APPROVAL_ACTION_REJECT
@@ -528,6 +540,9 @@ def settlement_content(session: Session, settlement_id: int) -> dict | None:
"basic_amount": _amount_text(item.basic_amount),
"salary_mode": item.salary_mode,
"net_amount": _amount_text(item.net_amount),
"normal_payable_sum": str(item.normal_payable_sum),
"deferred_sum": str(item.deferred_sum),
"probation_payment_sum": str(item.probation_payment_sum),
"is_probation": item.is_probation,
}
for item in items