fix_followup

This commit is contained in:
hangyu.tao 2026-01-15 15:16:04 +08:00
parent d7d1872db6
commit da118f41f9

View File

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