feat: 工单列表重设计+权限组实例过滤+通知修复
后端: - Ticket model 新增 ticket_no 字段(格式: YYYYMMDDHHmmss+ms+seq, 如20260522160543841) - create_ticket 自动生成工单编号(flush后生成) - _enrich_ticket 新增 instance_name, current_approver_name 字段 - current_approver: 从 ticket_approvals 查询第一个 pending 状态的审批步骤获取审核人 - TicketResponse schema 新增 ticket_no, instance_name, current_approver_name - 新增 /instances/accessible endpoint(按用户权限组过滤实例, 无admin bypass) - instance_group response_model 改为 InstanceGroupDetailResponse(含readonly/write实例) - instance_group_members 脏数据清理, 重建 group_id=2 正确数据 - notification 模板修复: \n→\n 换行, 钉钉 \n→\n\n 双换行 - test_notification endpoint 改为真正调用 NotificationSender.send() - auditor 角色添加到 audit_rule/ticket 只读端点 - seed_data() 创建4个默认用户(admin/zhangsan/laoliu/lurenjia) - SQLite ALTER TABLE 添加 ticket_no 列, 迁移现有6条工单数据 前端: - TicketsPage 完全重设计: 工单编号/实例名称/提交人/当前审核人/状态/操作 - 状态映射简化: pending/reviewing/approved→审核中, success→完成, failed→失败 - 执行详情弹框: 解析 execute_result JSON 展示状态/影响行数/耗时/验证/原始输出/错误信息 - 状态流程可视化(提交→审批→通过→执行→完成) - 快速筛选: 全部/待审批/执行中/完成/失败 (合并 pending+reviewing+approved 统计) - TicketCreatePage: 去掉数据库类型选择器, 用 accessible(write) 过滤变更实例 - QueriesPage: 用 accessible(readonly) 过滤查询实例 - instance.ts 新增 accessible 方法 - 分页优化: 动态计算页码范围(总页>5时中间滚动)
This commit is contained in:
1 parent
88d064ea95
commit
08f0f88cf1
20 files changed
+1672
-944
No files matched your search
@@ -38,6 +38,24 @@ import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _generate_ticket_no(ticket_id: int) -> str:
|
||||
"""生成工单编号,格式: YYYYMMDDHHmmss + 微秒前3位 + 序号补齐。
|
||||
|
||||
示例: 20260522160543841
|
||||
|
||||
Args:
|
||||
ticket_id: 工单自增ID,用作末尾序号
|
||||
|
||||
Returns:
|
||||
工单编号字符串
|
||||
"""
|
||||
now = datetime.now()
|
||||
base = now.strftime("%Y%m%d%H%M%S")
|
||||
ms = f"{now.microsecond:06d}"[:3] # 取前3位毫秒
|
||||
seq = str(ticket_id).zfill(3)[-3:] # ID 补齐到3位
|
||||
return f"{base}{ms}{seq}"
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.services.ticket_executor import ExecutionReport
|
||||
|
||||
@@ -112,17 +130,10 @@ class TicketExecuteConfirm(BaseModel):
|
||||
|
||||
|
||||
async def _enrich_ticket(ticket: Ticket, db: AsyncSession) -> Dict[str, Any]:
|
||||
"""丰富工单数据,添加申请人/审批人名称等信息。
|
||||
|
||||
Args:
|
||||
ticket: 工单对象
|
||||
db: 数据库会话
|
||||
|
||||
Returns:
|
||||
丰富的工单字典
|
||||
"""
|
||||
"""丰富工单数据,添加申请人/审批人/实例名称/当前审核人等信息。"""
|
||||
data = {
|
||||
"id": ticket.id,
|
||||
"ticket_no": ticket.ticket_no,
|
||||
"title": ticket.title,
|
||||
"db_type": ticket.db_type,
|
||||
"instance_id": ticket.instance_id,
|
||||
@@ -147,12 +158,39 @@ async def _enrich_ticket(ticket: Ticket, db: AsyncSession) -> Dict[str, Any]:
|
||||
applicant = r.scalar_one_or_none()
|
||||
data["applicant_name"] = applicant.display_name if applicant else "未知"
|
||||
|
||||
# Resolve approver name
|
||||
# Resolve approver name (最终审批人)
|
||||
if ticket.approver_id:
|
||||
r = await db.execute(select(User).where(User.id == ticket.approver_id))
|
||||
approver = r.scalar_one_or_none()
|
||||
data["approver_name"] = approver.display_name if approver else "未知"
|
||||
|
||||
# Resolve instance name
|
||||
if ticket.instance_id:
|
||||
r = await db.execute(select(Instance).where(Instance.id == ticket.instance_id))
|
||||
inst = r.scalar_one_or_none()
|
||||
data["instance_name"] = inst.name if inst else "未知"
|
||||
|
||||
# Resolve current approver (审批/执行阶段的当前待审核人)
|
||||
data["current_approver_name"] = None
|
||||
if ticket.status in ("reviewing", "approved", "executing"):
|
||||
pending_approval = await db.execute(
|
||||
select(TicketApproval)
|
||||
.where(
|
||||
TicketApproval.ticket_id == ticket.id,
|
||||
TicketApproval.action == "pending",
|
||||
)
|
||||
.order_by(TicketApproval.step_number)
|
||||
.limit(1)
|
||||
)
|
||||
pending = pending_approval.scalar_one_or_none()
|
||||
if pending:
|
||||
if pending.approver_id:
|
||||
r = await db.execute(select(User).where(User.id == pending.approver_id))
|
||||
approver_user = r.scalar_one_or_none()
|
||||
data["current_approver_name"] = approver_user.display_name if approver_user else None
|
||||
elif pending.approver_role:
|
||||
data["current_approver_name"] = pending.approver_role
|
||||
|
||||
return data
|
||||
|
||||
|
||||
@@ -370,6 +408,10 @@ async def create_ticket(
|
||||
db.add(ticket)
|
||||
await db.flush() # flush to get ticket.id
|
||||
|
||||
# 生成工单编号
|
||||
ticket.ticket_no = _generate_ticket_no(ticket.id)
|
||||
await db.flush()
|
||||
|
||||
# 7. 创建审批步骤(多级审批流)
|
||||
if default_workflow:
|
||||
wf_steps_result = await db.execute(
|
||||
|
||||
Reference in new issue
Block a user