feat(backend): 新增留言通知 — add_task_record 自动推送给任务负责人

触发条件:
- 有人对任务添加流转记录(留言/备注)
- 任务有 assignee_id
- 留言人 != 任务负责人 (不给自己发通知)

通知内容:
- title: 💬 收到新留言
- content: 产品[SN]的「任务名」有新留言:{前30字摘要}
- type: COMMENT

额外:
- Notification 模型新增 NOTIFY_COMMENT 常量
- 前端 notify 页新增 COMMENT 图标(💬)和标题(收到新留言)
This commit is contained in:
2026-08-11 18:17:52 +08:00
parent 7e4d796ce3
commit 991d713777
4 changed files with 31 additions and 2 deletions

View File

@ -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)