From da118f41f94c9ba90fb2ea340b14aec97e17e4dc Mon Sep 17 00:00:00 2001 From: "hangyu.tao" Date: Thu, 15 Jan 2026 15:16:04 +0800 Subject: [PATCH] fix_followup --- internal/handlers/followup_handler.go | 32 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/internal/handlers/followup_handler.go b/internal/handlers/followup_handler.go index fd26f40..c7e079a 100644 --- a/internal/handlers/followup_handler.go +++ b/internal/handlers/followup_handler.go @@ -278,24 +278,34 @@ func (h *FollowUpHandler) GetCustomerList(w http.ResponseWriter, r *http.Request } // Deduplicate by customer name - only show each unique customer name once in dropdown - // Use a map to track which customer names we've already added + // But also create a complete mapping of all customer IDs to names seenNames := make(map[string]bool) - var customerList []CustomerInfo + customerMap := make(map[string]string) // All ID -> Name mappings + var customerList []CustomerInfo // Deduplicated list for dropdown + for _, customer := range customers { - if customer.CustomerName != "" && !seenNames[customer.CustomerName] { - customerList = append(customerList, CustomerInfo{ - ID: customer.ID, - CustomerName: customer.CustomerName, - }) - seenNames[customer.CustomerName] = true - fmt.Printf("DEBUG: Added customer: ID=%s, Name=%s\n", customer.ID, customer.CustomerName) + if customer.CustomerName != "" { + // Add to complete mapping (all records) + customerMap[customer.ID] = customer.CustomerName + + // Add to deduplicated list (only first occurrence of each name) + if !seenNames[customer.CustomerName] { + customerList = append(customerList, CustomerInfo{ + ID: customer.ID, + CustomerName: customer.CustomerName, + }) + seenNames[customer.CustomerName] = true + fmt.Printf("DEBUG: Added customer: ID=%s, Name=%s\n", customer.ID, customer.CustomerName) + } } } - fmt.Printf("DEBUG: Total customer list items: %d\n", len(customerList)) + fmt.Printf("DEBUG: Total unique customer list items: %d\n", len(customerList)) + fmt.Printf("DEBUG: Total customer ID mappings: %d\n", len(customerMap)) w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(map[string]interface{}{ - "customers": customerList, + "customers": customerList, // Deduplicated list for dropdown + "customerMap": customerMap, // Complete ID->Name mapping for display }) }