From 991d713777085095bf6433d0b8ab603ac818067d Mon Sep 17 00:00:00 2001 From: duxingchen Date: Tue, 11 Aug 2026 18:17:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(backend):=20=E6=96=B0=E5=A2=9E=E7=95=99?= =?UTF-8?q?=E8=A8=80=E9=80=9A=E7=9F=A5=20=E2=80=94=20add=5Ftask=5Frecord?= =?UTF-8?q?=20=E8=87=AA=E5=8A=A8=E6=8E=A8=E9=80=81=E7=BB=99=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E8=B4=9F=E8=B4=A3=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 触发条件: - 有人对任务添加流转记录(留言/备注) - 任务有 assignee_id - 留言人 != 任务负责人 (不给自己发通知) 通知内容: - title: 💬 收到新留言 - content: 产品[SN]的「任务名」有新留言:{前30字摘要} - type: COMMENT 额外: - Notification 模型新增 NOTIFY_COMMENT 常量 - 前端 notify 页新增 COMMENT 图标(💬)和标题(收到新留言) --- backend/app/api/v1/endpoints/tasks.py | 2 +- backend/app/models/notification.py | 1 + backend/app/services/task_service.py | 29 ++++++++++++++++++++++++- track-uniapp/src/pages/notify/index.vue | 1 + 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/backend/app/api/v1/endpoints/tasks.py b/backend/app/api/v1/endpoints/tasks.py index cd0c78a..a07510d 100644 --- a/backend/app/api/v1/endpoints/tasks.py +++ b/backend/app/api/v1/endpoints/tasks.py @@ -308,4 +308,4 @@ async def add_task_record_endpoint( current_user: dict = Depends(get_current_user), ): """追加进度记录(备注+图片),不改变任务状态""" - return await task_service.add_task_record(db, uuid.UUID(task_id), data) + return await task_service.add_task_record(db, uuid.UUID(task_id), data, current_user) diff --git a/backend/app/models/notification.py b/backend/app/models/notification.py index 4ae76f5..aab12d4 100644 --- a/backend/app/models/notification.py +++ b/backend/app/models/notification.py @@ -11,6 +11,7 @@ from app.core.time_utils import get_beijing_time # 通知类型常量 NOTIFY_TRANSFER = "TRANSFER" # 新任务派发/转交 NOTIFY_REJECT = "REJECT" # 品质驳回 +NOTIFY_COMMENT = "COMMENT" # 留言提醒 class Notification(Base): diff --git a/backend/app/services/task_service.py b/backend/app/services/task_service.py index b866038..91803ff 100644 --- a/backend/app/services/task_service.py +++ b/backend/app/services/task_service.py @@ -1042,7 +1042,8 @@ async def create_subtask( # ============================================================ async def add_task_record( - db: AsyncSession, task_id: uuid.UUID, data: TaskRecordCreate + db: AsyncSession, task_id: uuid.UUID, data: TaskRecordCreate, + current_user: dict | None = None, ) -> TaskResponse: """追加进度记录(备注+图片),不改变任务状态""" import json @@ -1055,6 +1056,32 @@ async def add_task_record( images=json.dumps(data.images) if data.images else None, ) db.add(record) + await db.flush() + + # 🚀 留言通知:给任务当前负责人发送提醒(不给自己发) + if ( + current_user + and task.assignee_id + and task.assignee_id != current_user.get("username", "") + and data.remark + ): + # 截取留言内容前 30 字作为摘要 + remark_text = data.remark.strip() + short_content = remark_text[:30] + ("..." if len(remark_text) > 30 else "") + # 查询产品条码 + product_result = await db.execute( + select(Product).where(Product.id == task.product_id) + ) + product = product_result.scalar_one_or_none() + product_sn = product.serial_number if product else "未知" + db.add(Notification( + user_id=task.assignee_id, + title="💬 收到新留言", + content=f"产品 [{product_sn}] 的「{task.task_name}」有新留言:{short_content}", + type="COMMENT", + task_id=task.id, + )) + await db.commit() await db.refresh(record) diff --git a/track-uniapp/src/pages/notify/index.vue b/track-uniapp/src/pages/notify/index.vue index a117ab9..9092b8e 100644 --- a/track-uniapp/src/pages/notify/index.vue +++ b/track-uniapp/src/pages/notify/index.vue @@ -51,6 +51,7 @@ import { getNotifications, markNotificationRead } from "../../api/notification"; const TYPE_CONFIG = { TRANSFER: { icon: "🟢", title: "新任务派发" }, REJECT: { icon: "🔴", title: "品质驳回提醒" }, + COMMENT: { icon: "💬", title: "收到新留言" }, }; const notifications = ref([]);