一个批量处理数组的方法

一个批量处理数组的方法

#region Send MobileMessage By userList 
        
/// <summary>
        
/// Send MobileMessage By userList 
        
/// Tony 2007-05-31
        
/// <param name="site">Site</param>
        
/// <param name="lng">lng</param>
        
/// <param name="UserList">userList</param>
        
/// <param name="SendContent">SendContent</param>
        
/// <param name="MobileSource">1为PassPort,1为Message</param>
        public static  void SendToMobileByUserList(string site,string lng,string [] UserList,string SendContent,short MobileSource)
        {
            
if(UserList ==null || UserList.Length==0 )
            {
return;}
            
else
            {
                
if(IsLoginWithSite(site.Trim()))
                {
                    
try
                    {
                        
#region 定义变量
                        SendHistory s;
                        StringBuilder sb 
= new StringBuilder();
                        
//组内计数
                        int LevelCount=0;
                        
//数组长度
                        int userLen=UserList.Length;
                        
string temp1 = string.Empty;
                        
//当前组序号
                        int CurrentLevel=0;
                        
//总的组数(取整) such as 8/3=2
                        
//MaxBatchMobileNumber为外部public Vars,每批处理的数量
                        int MaxLevel=userLen/MaxBatchMobileNumber;
                        PassPort.User2007.Framework.Components.User2007 ur;
                        PassPortWebService pws
=new PassPortWebService();
                        MobileMessageSet m;
                        
string m1;
                        
#endregion
                        
foreach(string u in UserList)
                        {
                            
if(u==null || u.Trim().Length==0)
                            {
                                
//组内计数加一
                                LevelCount++;
                                
continue;
                            }
                            
#region 获取一串手机号码
                            
switch (MobileSource)
                            {
                                
case 1:
                                    
#region 从Passport获取号码
                                    ur
=pws.GetUser2007(u,lng);
                                    
if(ur!=null  &&  ur.Mobile!=null)  
                                    {
                                        m1
=string.Empty;
                                        m1
=GetMobileStartWith13(ur.Mobile.Trim());
                                        
if(m1.Length>10)
                                        {sb.Append(m1
+",");}
                                    }
                                    ur
=null;
                                    
#endregion
                                    
break;
                                
case 2:
                                    
#region 从短信提醒设置获取号码
                                    m
=SMS.MobileMessageSet.Framework.Data.DataDTOProvider.MobileMessageSetSelectByLoginID(0,u,lng);
                                    
if(m!=null && m.ToMobile!=null )
                                    {
                                        m1
=string.Empty;
                                        m1
=GetMobileStartWith13(m.ToMobile);
                                        
if(m1.Length>10)
                                        {sb.Append(m1
+",");    }
                                    }
                                    m
=null;
                                    
#endregion
                                    
break;
                                
default:
                                    
#region 从Passport获取号码
                                    ur
=pws.GetUser2007(u,lng);
                                    
if(ur!=null  &&  ur.Mobile!=null)  
                                    {
                                        m1
=string.Empty;
                                        m1
=GetMobileStartWith13(ur.Mobile.Trim());
                                        
if(m1.Length>10)
                                        {sb.Append(m1
+",");}
                                    }
                                    ur
=null;
                                    
#endregion
                                    
break;
                            }
                            
//组内计数加一
                            LevelCount++;
                            
#endregion
                            
#region 发送一批号码
                            
                            
if(LevelCount==userLen && LevelCount<MaxBatchMobileNumber)
                            {
                                
#region 用户数量小于批数量
                                temp1
=sb.ToString();                                
                                
if(temp1.EndsWith(","))
                                {
                                    temp1
=temp1.Remove(temp1.Length-1,1);
                                }
                                
int bRtn = new JL().SendMsg(pHandle,strMobileCode,temp1,SendContent,"");
                                
#region 发送成功后写入数据库
                                
if(bRtn==0)
                                {
                                    s
=new SendHistory();
                                    s.MessageID
=-100;
                                    s.Status
=0;
                                    lng
=(lng==null || lng.Trim().Length==0)?"cn":lng;
                                
                                    
string str="来自于{0},语言为{1},发送给{2}的手机({3})的短信内容:{4}";
                                    s.Topic
=string.Format(str,site,lng,u,temp1,SendContent);;
                                    s.CreatTime
=DateTime.Now;
                                    s.F1
=0;
                                    s.F2
=0;
                                    s.F3
=site+"-"+lng;
                                    s.F4
="";
                                    s.UpdateTime
=DateTime.Now;
                                    SMS.SendHistory.Framework.Data.DataDTOProvider.SendHistoryInsert(s);
                                    s
=null;
                                }
                                
#endregion
                                
#region 完成后清零
                                sb
=new StringBuilder();
                                temp1
=string.Empty;
                                LevelCount
=0;
                                
#endregion
                                
#endregion
                            }
                            
else if (LevelCount == MaxBatchMobileNumber)
                            {
                                
#region 刚好一批
                                temp1
=sb.ToString();                                
                                
if(temp1.EndsWith(","))
                                {
                                    temp1
=temp1.Remove(temp1.Length-1,1);
                                }
                                
int bRtn = new JL().SendMsg(pHandle,strMobileCode,temp1,SendContent,"");
                                
#region 发送成功后写入数据库
                                
if(bRtn==0)
                                {
                                    s
=new SendHistory();
                                    s.MessageID
=-100;
                                    s.Status
=0;
                                    lng
=(lng==null || lng.Trim().Length==0)?"cn":lng;
                                
                                    
string str="来自于{0},语言为{1},发送给{2}的手机({3})的短信内容:{4}";
                                    s.Topic
=string.Format(str,site,lng,u,temp1,SendContent);;
                                    s.CreatTime
=DateTime.Now;
                                    s.F1
=0;
                                    s.F2
=0;
                                    s.F3
=site+"-"+lng;
                                    s.F4
="";
                                    s.UpdateTime
=DateTime.Now;
                                    SMS.SendHistory.Framework.Data.DataDTOProvider.SendHistoryInsert(s);
                                    s
=null;
                                }
                                
#endregion
                                
#region 完成后清零
                                sb
=new StringBuilder();
                                temp1
=string.Empty;
                                LevelCount
=0;
                                
//当前组数加一
                                CurrentLevel++;
                                
#endregion
                                
#endregion
                            }
                            
else if(LevelCount<MaxBatchMobileNumber   && (userLen%MaxBatchMobileNumber)==LevelCount && MaxLevel==CurrentLevel)
                            {
                                
#region 最后一批
                                temp1
=sb.ToString();                                
                                
if(temp1.EndsWith(","))
                                {
                                    temp1
=temp1.Remove(temp1.Length-1,1);
                                }
                                
int bRtn = new JL().SendMsg(pHandle,strMobileCode,temp1,SendContent,"");
                                
#region 发送成功后写入数据库
                                
if(bRtn==0)
                                {
                                    s
=new SendHistory();
                                    s.MessageID
=-100;
                                    s.Status
=0;
                                    lng
=(lng==null || lng.Trim().Length==0)?"cn":lng;
                                
                                    
string str="来自于{0},语言为{1},发送给{2}的手机({3})的短信内容:{4}";
                                    s.Topic
=string.Format(str,site,lng,u,temp1,SendContent);;
                                    s.CreatTime
=DateTime.Now;
                                    s.F1
=0;
                                    s.F2
=0;
                                    s.F3
=site+"-"+lng;
                                    s.F4
="";
                                    s.UpdateTime
=DateTime.Now;
                                    SMS.SendHistory.Framework.Data.DataDTOProvider.SendHistoryInsert(s);
                                    s
=null;
                                }
                                
#endregion
                                
#region 完成后清零
                                sb
=new StringBuilder();
                                temp1
=string.Empty;
                                LevelCount
=0;
                                
#endregion
                                
#endregion

                            }
                            
#endregion
                        }
                    }
                    
catch //(Exception ex)
                    {
                        
return;
                    }
                }
            }
        }
                
        
#endregion
posted @   邀月  阅读(1213)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示