class AllocUser
{
//客户多于客服
public static void Test()
{
var customers = new List<Customer>()
{
new Customer()
{
Name = "A"
},
new Customer()
{
Name = "B"
},
new Customer()
{
Name = "C"
},
new Customer()
{
Name = "D"
},
new Customer()
{
Name = "E"
},
new Customer()
{
Name = "F"
},
new Customer()
{
Name = "G"
},
}; var waiters = new List<Waiter>()
{
new Waiter()
{
Name = ""
},
new Waiter()
{
Name = ""
},
new Waiter()
{
Name = ""
},
}; Alloc(customers, waiters.OrderBy(p => Guid.NewGuid()).ToList());
} private static void Alloc(List<Customer> customers, List<Waiter> waiters)
{
for (int i = ; i < customers.Count; i++)
{
var customer = customers[i];
if (i < waiters.Count)
{
customer.WaiterName = waiters[i].Name;
}
else
{
customer.WaiterName = waiters[(i % waiters.Count)].Name;
} System.Console.WriteLine(customer.ToString());
}
}
} class Customer
{
public string Name { get; set; }
public string WaiterName { get; set; }
public override string ToString()
{
return string.Format("客户{0}被分配客服{1}", Name, WaiterName);
}
} class Waiter
{
public string Name { get; set; }
}
05-27 20:08