diff --git a/lib/__tests__/performance-survey-notifications.test.ts b/lib/__tests__/performance-survey-notifications.test.ts index 942ba602..7909de32 100644 --- a/lib/__tests__/performance-survey-notifications.test.ts +++ b/lib/__tests__/performance-survey-notifications.test.ts @@ -248,13 +248,16 @@ describe('performance survey notifications', () => { expect(prisma.performanceSurveyNotification.create).toHaveBeenCalledWith({ data: expect.objectContaining({ title: '待提交作品|七月视觉评分', - content: expect.stringContaining('**作品要求:** 3 个案例作品'), + content: expect.stringContaining('**作品要求** 3 个案例作品'), actionUrl: expect.stringContaining( '%2Fperformance-survey%2Fsurvey%2Fsurvey-visual%3FtargetId%3Dtarget-other', ), }), select: { id: true }, }) + const createdContent = (prisma.performanceSurveyNotification.create as jest.Mock).mock.calls[0][0].data.content + expect(createdContent).toContain('### 🖼️ 视觉评分作品') + expect(createdContent).toContain('**待提交|七月视觉评分**') }) test('视觉评分创建后只为自评任务排队通知', async () => { @@ -274,7 +277,19 @@ describe('performance survey notifications', () => { expect(prisma.performanceSurveyNotification.create).toHaveBeenCalledTimes(1) expect(prisma.performanceSurveyNotification.create).toHaveBeenCalledWith({ - data: expect.objectContaining({ assignmentId: 'assignment-self' }), + data: expect.objectContaining({ + assignmentId: 'assignment-self', + title: '待填写|七月视觉评分', + content: [ + '### 📝 新的考核调研', + '', + '**待填写|七月视觉评分**', + '', + '**评价对象** 视觉同事 ', + '', + '> 请在截止时间前完成评分', + ].join('\n'), + }), select: { id: true }, }) }) diff --git a/lib/performance-survey-notifications.ts b/lib/performance-survey-notifications.ts index 84ac0d9a..2d6f8509 100644 --- a/lib/performance-survey-notifications.ts +++ b/lib/performance-survey-notifications.ts @@ -66,19 +66,21 @@ function escapeDingtalkMarkdown(value: unknown) { } function buildNotificationCard(input: { + icon: string heading: string + statusLabel: string surveyTitle: string fields: Array<{ label: string; value: string | null | undefined }> note?: string | null }) { const fieldLines = input.fields .filter((field) => clean(field.value)) - .map((field) => `**${escapeDingtalkMarkdown(field.label)}:** ${escapeDingtalkMarkdown(field.value)} `) + .map((field) => `**${escapeDingtalkMarkdown(field.label)}** ${escapeDingtalkMarkdown(field.value)} `) return [ - `### ${escapeDingtalkMarkdown(input.heading)}`, + `### ${input.icon} ${escapeDingtalkMarkdown(input.heading)}`, '', - `**${escapeDingtalkMarkdown(input.surveyTitle)}**`, + `**${escapeDingtalkMarkdown(input.statusLabel)}|${escapeDingtalkMarkdown(input.surveyTitle)}**`, '', ...fieldLines, input.note ? `\n> ${escapeDingtalkMarkdown(input.note)}` : null, @@ -257,7 +259,9 @@ export async function queueSurveyAssignmentNotifications(surveyId: string) { businessKey: `assignment:${assignment.id}`, title: `待填写|${survey.title}`, content: buildNotificationCard({ - heading: '新的考核调研待填写', + icon: '📝', + heading: '新的考核调研', + statusLabel: '待填写', surveyTitle: survey.title, fields: [ { label: '评价对象', value: targetName }, @@ -319,7 +323,9 @@ export async function queueSurveyTargetConfirmationNotifications(surveyId: strin businessKey: `target-confirmation:${survey.id}:${target.id}`, title: isVisualSurvey ? `待提交作品|${survey.title}` : `待确认|${survey.title}`, content: buildNotificationCard({ - heading: isVisualSurvey ? '请确认并提交视觉评分作品' : '请确认代发起调研', + icon: isVisualSurvey ? '🖼️' : '📋', + heading: isVisualSurvey ? '视觉评分作品' : '考核调研确认', + statusLabel: isVisualSurvey ? '待提交' : '待确认', surveyTitle: survey.title, fields: [ { label: '发起人', value: survey.creatorName }, @@ -367,7 +373,9 @@ export async function queueSurveyResultNotifications(surveyId: string) { businessKey: `result:${survey.id}:${target.id}`, title: `结果已生成|${survey.title}`, content: buildNotificationCard({ - heading: '考核调研结果已生成', + icon: '📊', + heading: '考核调研结果', + statusLabel: '已生成', surveyTitle: survey.title, fields: [{ label: '评价对象', value: target.targetName }], note: '点击下方按钮查看完整结果', @@ -407,7 +415,9 @@ export async function queueSurveyCreatorNotification(surveyId: string, eventType businessKey: `${eventType}:${survey.id}`, title: `${eventType === 'survey.creator.closed' ? '已关闭' : '已完成'}|${survey.title}`, content: buildNotificationCard({ - heading: eventType === 'survey.creator.closed' ? '考核调研已关闭' : '考核调研已完成', + icon: eventType === 'survey.creator.closed' ? '⏹️' : '✅', + heading: '考核调研', + statusLabel: eventType === 'survey.creator.closed' ? '已关闭' : '已完成', surveyTitle: survey.title, fields: [{ label: '提交进度', value: `${submitted}/${total}` }], note: '点击下方按钮查看调研结果', @@ -454,7 +464,9 @@ export async function queueDuePerformanceSurveyReminders() { businessKey: `due:${dueKey}:${assignment.id}`, title: `即将截止|${survey.title}`, content: buildNotificationCard({ - heading: '考核调研即将截止', + icon: '⏰', + heading: '考核调研提醒', + statusLabel: '即将截止', surveyTitle: survey.title, fields: [ { label: '评价对象', value: assignment.target.targetName },