Ejemplo n.º 1
0
        private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            IDispatchInterface    bll  = new DispatchService();
            SmsMessage            c    = new SmsMessage();
            List <OrdDispatchDto> list = bll.GetDispatch();

            //var ls = t.GroupBy(a => new { a.Sort }).Select(g => new TempList() { Sort = g.Key.Sort, Days = g.Max(item => item.Days) }).ToList();
            List <GroupDispatchDto> newlist = list.GroupBy(p => new { p.ConstId, p.Phone }).Select(g => new GroupDispatchDto()
            {
                ConstId = g.Key.ConstId, Phone = g.Key.Phone
            }).ToList();
            List <SendSmsDto> sendList = new List <SendSmsDto>();

            foreach (var item in newlist)
            {
                var temp = list.Where(p => p.ConstId == item.ConstId).ToList();
                if (temp[0].CreateTime.AddHours(24) < DateTime.Now)
                {
                    SendSmsDto senddto = new SendSmsDto();
                    senddto.ConstId = item.ConstId;
                    senddto.Phone   = item.Phone;
                    string roleNames = "";
                    foreach (var model in temp)
                    {
                        roleNames        += RoleConvert.GetRoleName(model.RoleId) + ",";
                        senddto.ConstName = model.Name;
                        senddto.RoleId    = model.RoleId;
                        bll.DelDispatch(senddto);
                    }
                    senddto.RolesName = roleNames.Length > 0 ? roleNames.Substring(0, roleNames.Length - 1) : "";
                    sendList.Add(senddto);
                }
            }

            //发送
            string content = System.Configuration.ConfigurationSettings.AppSettings["content"];

            foreach (var temp in sendList)
            {
                string message  = string.Format(content, temp.ConstName, temp.RolesName);
                var    smsState = c.SendMessages(temp.Phone, message);
            }
        }