fix(chat): 区分咨询与正常会话待处理规则
This commit is contained in:
@@ -99,8 +99,8 @@ func TestListAdminConversationsUsesPersonalStateAndBatchData(t *testing.T) {
|
|||||||
if item.UnreadCount != 1 {
|
if item.UnreadCount != 1 {
|
||||||
t.Fatalf("管理员未读数 = %d, want 1", item.UnreadCount)
|
t.Fatalf("管理员未读数 = %d, want 1", item.UnreadCount)
|
||||||
}
|
}
|
||||||
if !item.NeedsReply {
|
if item.NeedsReply {
|
||||||
t.Fatal("用户消息未回复时应保持待处理")
|
t.Fatal("订单群用户消息不应因未回复停留在待处理")
|
||||||
}
|
}
|
||||||
counts, err := repo.AdminConversationCounts(t.Context(), Principal{Type: "admin", ID: admin.ID}, adminChatFilterMine, adminChatStageAll, "")
|
counts, err := repo.AdminConversationCounts(t.Context(), Principal{Type: "admin", ID: admin.ID}, adminChatFilterMine, adminChatStageAll, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -109,6 +109,16 @@ func TestListAdminConversationsUsesPersonalStateAndBatchData(t *testing.T) {
|
|||||||
if counts.Ownership[adminChatFilterMine] != 1 || counts.Stages[adminChatStageAll] != 1 {
|
if counts.Ownership[adminChatFilterMine] != 1 || counts.Stages[adminChatStageAll] != 1 {
|
||||||
t.Fatalf("聚合统计异常: ownership=%v stages=%v", counts.Ownership, counts.Stages)
|
t.Fatalf("聚合统计异常: ownership=%v stages=%v", counts.Ownership, counts.Stages)
|
||||||
}
|
}
|
||||||
|
if err := db.Model(&conversation).Update("type", ConversationTypeGeneralSupport).Error; err != nil {
|
||||||
|
t.Fatalf("切换咨询会话类型失败: %v", err)
|
||||||
|
}
|
||||||
|
result, err = repo.ListConversationsWithFilter(t.Context(), Principal{Type: "admin", ID: admin.ID}, 1, 20, adminChatFilterMine, adminChatStagePending, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("查询咨询待处理会话失败: %v", err)
|
||||||
|
}
|
||||||
|
if result.Total != 1 {
|
||||||
|
t.Fatalf("咨询未回复待处理数量 = %d, want 1", result.Total)
|
||||||
|
}
|
||||||
|
|
||||||
adminMessage := model.ChatMessage{ConversationID: conversation.ID, SenderType: "admin", SenderID: admin.ID, SenderRole: "support", ContentType: "text", Content: "客服回复", CreatedAt: now.Add(2 * time.Second)}
|
adminMessage := model.ChatMessage{ConversationID: conversation.ID, SenderType: "admin", SenderID: admin.ID, SenderRole: "support", ContentType: "text", Content: "客服回复", CreatedAt: now.Add(2 * time.Second)}
|
||||||
if err := db.Create(&adminMessage).Error; err != nil {
|
if err := db.Create(&adminMessage).Error; err != nil {
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ func (r *Repository) listAdminConversations(ctx context.Context, principal Princ
|
|||||||
COALESCE(explicit_lo.handoff_status, listing_lo.handoff_status) AS latest_handoff_status,
|
COALESCE(explicit_lo.handoff_status, listing_lo.handoff_status) AS latest_handoff_status,
|
||||||
COALESCE(explicit_lo.refund_status, listing_lo.refund_status) AS latest_refund_status,
|
COALESCE(explicit_lo.refund_status, listing_lo.refund_status) AS latest_refund_status,
|
||||||
lm.sender_type AS last_sender_type, lm.sender_id AS last_sender_id, lm.sender_role AS last_sender_role,
|
lm.sender_type AS last_sender_type, lm.sender_id AS last_sender_id, lm.sender_role AS last_sender_role,
|
||||||
CASE WHEN ` + adminNeedsReplyExpression() + ` THEN 1 ELSE 0 END AS needs_reply,
|
CASE WHEN c.type = 'general_support' AND (` + adminNeedsReplyExpression() + `) THEN 1 ELSE 0 END AS needs_reply,
|
||||||
(
|
(
|
||||||
SELECT COUNT(1)
|
SELECT COUNT(1)
|
||||||
FROM chat_messages AS cm
|
FROM chat_messages AS cm
|
||||||
@@ -415,7 +415,7 @@ func adminChatStageCondition(stage string, principal Principal) (string, []inter
|
|||||||
latestRefundStatus := "COALESCE(explicit_lo.refund_status, listing_lo.refund_status)"
|
latestRefundStatus := "COALESCE(explicit_lo.refund_status, listing_lo.refund_status)"
|
||||||
switch stage {
|
switch stage {
|
||||||
case adminChatStagePending:
|
case adminChatStagePending:
|
||||||
return adminNeedsReplyExpression(), nil
|
return "c.type = 'general_support' AND (" + adminNeedsReplyExpression() + ")", nil
|
||||||
case adminChatStageUnjoined:
|
case adminChatStageUnjoined:
|
||||||
return latestID + " IS NULL", nil
|
return latestID + " IS NULL", nil
|
||||||
case adminChatStageHandoff:
|
case adminChatStageHandoff:
|
||||||
|
|||||||
Reference in New Issue
Block a user