feat(server): 站内通知基础设施与关键事件触发(F14,F30)
- 新增 notifications 表与 API(list/mark-read) - submit/approve/reject/return/transfer/pay/forgot-password 写入站内通知 - 通知失败降级,不阻塞主流程
这个提交包含在:
@@ -0,0 +1,23 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "notifications" (
|
||||
"id" UUID NOT NULL,
|
||||
"recipient_employee_id" UUID NOT NULL,
|
||||
"type" VARCHAR(64) NOT NULL,
|
||||
"title" VARCHAR(200) NOT NULL,
|
||||
"body" TEXT,
|
||||
"target_type" VARCHAR(64),
|
||||
"target_id" UUID,
|
||||
"read_at" TIMESTAMP(3),
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "notifications_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "notifications_recipient_employee_id_created_at_idx" ON "notifications"("recipient_employee_id", "created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "idx_notifications_unread_query" ON "notifications"("recipient_employee_id", "read_at", "created_at");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "notifications" ADD CONSTRAINT "notifications_recipient_employee_id_fkey" FOREIGN KEY ("recipient_employee_id") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -172,6 +172,7 @@ model Employee {
|
||||
|
||||
auth_sessions AuthSession[]
|
||||
audit_logs AuditLog[] @relation("AuditActor")
|
||||
notifications Notification[]
|
||||
|
||||
submitted_reimbursements ReimbursementForm[] @relation("ReimbursementSubmitter")
|
||||
owned_reimbursements ReimbursementForm[] @relation("ReimbursementOwner")
|
||||
@@ -286,6 +287,24 @@ model AuditLog {
|
||||
@@map("audit_logs")
|
||||
}
|
||||
|
||||
model Notification {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
recipient_employee_id String @db.Uuid
|
||||
type String @db.VarChar(64)
|
||||
title String @db.VarChar(200)
|
||||
body String?
|
||||
target_type String? @db.VarChar(64)
|
||||
target_id String? @db.Uuid
|
||||
read_at DateTime?
|
||||
created_at DateTime @default(now())
|
||||
|
||||
recipient Employee @relation(fields: [recipient_employee_id], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([recipient_employee_id, created_at])
|
||||
@@index([recipient_employee_id, read_at, created_at], map: "idx_notifications_unread_query")
|
||||
@@map("notifications")
|
||||
}
|
||||
|
||||
model ExpenseType {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
code String @unique
|
||||
|
||||
在新工单中引用
屏蔽一个用户