Tasks Specification

Historical product spec / Superseded(2026-07-15):本文的 UI、type_categoryclose_result 是 V1 snapshot,不得作为新实现依据。现行规范见 Task System Design

定义 Tasks 页面展示的所有数据的来源和计算方式。数据全部来自 tasks 表callytics-common/src/db/schema/tasks.ts)。


一、数据来源字段

字段DB 列名类型用途
taskIdtask_iduuid (PK)任务唯一标识
contactPhonecontact_phonetext关联客户电话
franchiseIdfranchise_idtext多租户隔离
siteIdsite_idtext多租户隔离
taskTypetask_typetext'lead_outreach' / 'follow_up'
typeCategorytype_categorytext11 个业务场景(见 §二)
statusstatustext'pending' / 'closed'(DB 只存这两个)
closeTypeclose_typetext'auto_closed' / 'manual_closed'
actionNeededaction_neededboolean是否需要跟进
actionNeededReasonaction_needed_reasontext为什么需要行动
suggestedActionssuggested_actionsjsonbAI 建议列表 [{action, reason, priority, priorityReason}]
priorityprioritytext'high' / 'medium' / 'low'
sourceTypesource_typetext'lead' / 'contact_analysis' / 'manual'
dueAtdue_attimestamp截止时间
closedAtclosed_attimestamp关闭时间
closedByStaffNameclosed_by_staff_nametext关闭员工姓名
closeResultclose_resulttext13 个关闭结果(见 §三)
closeNoteclose_notetext关闭备注
createdAtcreated_attimestamp创建时间

Overdue / Due Soon 不存 DB,由前端实时计算:Overdue = status='pending' AND due_at < NOW(),Due Soon = status='pending' AND due_at BETWEEN NOW() AND NOW() + interval


二、前端展示

2.1 Summary Cards(顶部汇总)

前端展示名计算方式来源字段
OPEN 总数COUNT(status='pending')status
Ongoing 数量COUNT(status='pending' AND due_at >= NOW() + interval)status + due_at
Due Soon 数量COUNT(status='pending' AND due_at BETWEEN NOW() AND NOW() + interval)status + due_at
Overdue 数量COUNT(status='pending' AND due_at < NOW())status + due_at
CLOSED 总数COUNT(status='closed')status
Manual 数量COUNT(close_type='manual_closed')close_type
Auto 数量COUNT(close_type='auto_closed')close_type

2.2 筛选器

前端筛选名来源字段选项
All PrioritiespriorityAll / High / Medium / Low
All Typestype_categoryAll / 11 个 type_category
Open Datecreated_atAll / Today / Last 7 Days / Last 30 Days
Close Dateclosed_atAll / Today / Last 7 Days / Last 30 Days

2.3 Task Card 展示字段

每个 task card 展示以下数据:

前端展示位置前端展示名来源字段说明
顶部标签ONGOING / DUE SOON / OVERDUE / AUTO-CLOSED / MANUAL-CLOSEDstatus + due_at + close_type状态标签,颜色区分
第一行左客户姓名contact_phone → JOIN contacts firstName + lastName跨表关联
第一行左电话号码contact_phone直读
第一行左Lead / Member badgecontact_phone → JOIN contacts lifecycleStage跨表关联
第一行右Due 时间due_at格式:Due: Apr 5 9:18 PM
第二行左Priority badgepriorityHIGH / MEDIUM / LOW,颜色区分
第二行左Type Category badgetype_categoryLEAD OUTREACH / CANCELLATION RISK 等
第三行AI Summaryaction_needed_reason 或 JOIN contacts customerSummary任务描述
第四行Suggested Actionsuggested_actions[0].actionAI 建议操作
第五行First attempted / First connected / Last touch / Calls / SMS跨表派生 calls + messages通话和消息统计
底部按钮View Details展开详情
底部按钮Close Task打开关闭弹窗
关闭后额外行Close Type + Close Result + Close Noteclose_type + close_result + close_note仅已关闭 task 显示

2.4 Close Task 弹窗

前端展示名来源字段说明
Who are you?(下拉)写入 closed_by_staff_name员工选择姓名
Close Result(13 选 1)写入 close_result见 §三
Close Note(文本框)写入 close_noteclose_result='other' 时必填

三、枚举值

3.1 type_category(11 个)

#type_category显示文字task_type
1lead_outreachLEAD OUTREACHlead_outreach
2lead_follow_upLEAD FOLLOW-UPfollow_up
3booked_not_convertedBOOKED NOT CONVERTEDfollow_up
4cancellation_riskCANCELLATION RISKfollow_up
5complaint_retentionCOMPLAINT RETENTIONfollow_up
6win_backWIN-BACKfollow_up
7upgradeUPGRADEfollow_up
8payment_recoveryPAYMENT RECOVERYfollow_up
9freeze_recoveryFREEZE RECOVERYfollow_up
10event_promotionEVENT PROMOTIONfollow_up
11special_promotionSPECIAL PROMOTIONfollow_up

:当前 schema 为 9 个(缺 complaint_retentionpayment_recoveryfreeze_recoveryevent_promotionspecial_promotion,多了 retentionrenewalreferral),需后端更新。

3.2 close_result(13 个)

#close_result显示文字说明
1lead_outreachedLead Outreached仅 Lead Outreach task,已尝试联系但未接通
2convertedConverted客户签约
3upgradedUpgraded客户升级
4complaint_resolvedComplaint Resolved投诉解决
5payment_recoveredPayment Recovered更新 credit card 成功
6cancel_savedCancel Saved挽留成功
7freeze_recoveredFreeze Recovered冻结会员恢复活跃
8win_backWin-back前会员重新签约
9event_signed_upEvent Signed Up会员报名活动
10promotion_convertedPromotion Converted推广协议签约
11wrong_numberWrong Number号码错误
12do_not_contactDo Not Contact客户要求不联系
13otherOther其他(需填 close_note)

:当前 schema 为 11 个(缺 lead_outreachedcomplaint_resolvedpayment_recoveredfreeze_recoveredevent_signed_uppromotion_converted,多了 attemptedissue_resolvedrenewedreferral_obtained),需后端更新。


四、Schema 差异说明

当前 schema(callytics-common/src/db/schema/tasks.ts)和本文档设计目标有差异,需后端更新:

type_category 变更

动作原因
重命名retentioncomplaint_retention更精确
删除renewal不是独立业务场景
删除referral不是独立业务场景
新增payment_recovery支付恢复
新增freeze_recovery冻结恢复
新增event_promotion活动推广
新增special_promotion特别推广

close_result 变更

动作旧值新值原因
重命名attemptedlead_outreached仅 Lead Outreach task
重命名issue_resolvedcomplaint_resolved匹配 Complaint Retention MRR
删除renewed不是独立 close result
删除referral_obtained不产生直接营收
新增payment_recoveredPayment Recovery MRR
新增freeze_recoveredFreeze Recovery MRR
新增event_signed_upEvent Revenue
新增promotion_convertedPromotion Revenue

参考文档