using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml.Serialization; using WX.CRM.BLL.Res; using WX.CRM.Model.Entity; namespace WX.CRM.CRMServices.ServicesModel { public class ResIdAndPhone { public string ResId { get; set; } public string Number { get; set; } } public class RegPhone { public List listPhone { get; private set; } public RegPhone(List _listPhone) { this.listPhone = _listPhone; } public void RegisterList() { List resIds = this.listPhone.Select(p => p.ResId).ToList(); RES_CUSTOMER_BL res_customer = new RES_CUSTOMER_BL(); List exists_customer = new List(); int count = Convert.ToInt32(Math.Ceiling(resIds.Count / 300.00)); for (int i = 1; i <= count; i++) { string[] _resid = null; if (i <= 1) { _resid = resIds.Take(300).ToArray(); } else { _resid = resIds.Skip((i - 1) * 300).Take(300).ToArray();//分页 } var resList = res_customer.getResByResIds(_resid); exists_customer.AddRange(resList); } string[] isRegs = exists_customer.Select(p => p.RESID).ToArray(); var needToRegister = this.listPhone.Where(p => !isRegs.Contains(p.ResId)); foreach (var model in needToRegister) { RES_CUSTOMER customer = new RES_CUSTOMER(); customer.RESID = model.ResId; var customerDetail = customer.RES_CUSTOMERDETAIL; var xmls = new XmlSerializer(typeof(RES_CUSTOMERDETAIL)); var sw = new StringWriter(); xmls.Serialize(sw, customerDetail); res_customer.ResgisterCustomer(model.Number, model.ResId, "CallRecord", sw.ToString()); } } } }