Example #1
0
        /// <summary>
        /// 功能单据 发送系统处理消息、短信处理信息、微信处理信息
        /// </summary>
        /// <param name="billMasterRow">功能单据 主表行数据</param>
        /// <param name="billProgId">功能单据 功能标识</param>
        /// <param name="title">消息标题</param>
        /// <param name="content">消息内容</param>
        /// <param name="personIds">额外发送人员,可以为空</param>
        public void SendBusinessMsg(DataRow billMasterRow, string billProgId, string title, string content, List <string> personIds)
        {
            string data = GetMsgData(billMasterRow);

            //系统消息类,用于发送系统消息,其属性用户列表中的用户不可重复
            LibSysNews news = new LibSysNews();
            //电话列表,用于发送短信,列表中手机号不可重复
            List <string> phoneList = new List <string>();
            //微信列表,用于发送微信,列表中微信号不可重复
            List <string> weChatList = new List <string>();

            #region 为额外需要发送信息的人发短信、发微信、发系统信息
            if (personIds != null && personIds.Count > 0)
            {
                //获取人员信息【人员代码,微信,电话】
                string sql = "SELECT PERSONID,WECHAT,PHONENO FROM COMPERSON WHERE PERSONID in(";
                foreach (string personId in personIds)
                {
                    sql = sql + string.Format("{0},", LibStringBuilder.GetQuotString(personId));
                }
                sql = sql.TrimEnd(',') + ")";

                using (IDataReader reader = this.DataAccess.ExecuteDataReader(sql))
                {
                    while (reader.Read())
                    {
                        //将人员手机(手机号存在)添加到电话列表中,以便发短信
                        string phoneNo = LibSysUtils.ToString(reader["PHONENO"]);
                        if (!string.IsNullOrEmpty(phoneNo) && !phoneList.Contains(phoneNo))
                        {
                            phoneList.Add(phoneNo);
                        }
                        //将人员微信(微信号存在,若不存在则将其手机号作为微信号)添加到微信列表中,以便发微信
                        string weChat = LibSysUtils.ToString(reader["WECHAT"]);
                        if (!string.IsNullOrEmpty(weChat))
                        {
                            if (!weChatList.Contains(weChat))
                            {
                                weChatList.Add(weChat);
                            }
                        }
                        else if (!string.IsNullOrEmpty(phoneNo) && !weChatList.Contains(phoneNo))
                        {
                            weChatList.Add(phoneNo);
                        }
                        //将人员添加到其用户列表中,以便发系统信息
                        string personId = LibSysUtils.ToString(reader["PERSONID"]);
                        if (!string.IsNullOrEmpty(personId) && !news.UserList.Contains(personId))
                        {
                            news.UserList.Add(personId);
                        }
                    }
                }
            }
            #endregion

            #region 获得单据业务流配置下跟当前功能单据数据相匹配的业务流配置明细并为其接收人(根据需要)发短信/发微信、发系统信息
            List <BusinessInfo> curBusinessInfo = GetBusinessInfo(billMasterRow, billProgId);
            if (curBusinessInfo != null)
            {
                foreach (var info in curBusinessInfo)
                {
                    //将接收人手机(需要接受人接收短信且手机号存在)添加到电话列表中,以便发短信
                    if (info.NeedSMS && !string.IsNullOrEmpty(info.PhoneNo) && !phoneList.Contains(info.PhoneNo))
                    {
                        phoneList.Add(info.PhoneNo);
                    }
                    //将接收人微信(需要接收人接受微信且微信号存在,若不存在则将其手机号作为微信号)添加到微信列表中,以便发微信
                    if (info.SendWeChat)
                    {
                        if (!string.IsNullOrEmpty(info.WeChat))
                        {
                            if (!weChatList.Contains(info.WeChat))
                            {
                                weChatList.Add(info.WeChat);
                            }
                        }
                        else if (!string.IsNullOrEmpty(info.PhoneNo))
                        {
                            if (!weChatList.Contains(info.PhoneNo))
                            {
                                weChatList.Add(info.PhoneNo);
                            }
                        }
                    }
                    //将接收人添加到其用户列表中,以便发系统信息
                    if (!news.UserList.Contains(info.PersonId))
                    {
                        news.UserList.Add(info.PersonId);
                    }
                }
            }
            #endregion

            #region 发送系统信息
            if (news.UserList.Count > 0)
            {
                news.Title    = title;
                news.Content  = content;
                news.Data     = data;
                news.PersonId = LibSysUtils.ToString(billMasterRow["CREATORID"]);
                news.ProgId   = billProgId;
                LibSysNewsHelper.SendNews(news);
            }
            #endregion

            #region 发送短信
            if (phoneList.Count > 0)
            {
                SendSMSParam param = new SendSMSParam();
                param.PhoneList = phoneList;
                param.Message   = news.Content;
                //ThreadPool.QueueUserWorkItem(LibSMSHelper.SendMsg, param);
            }
            #endregion

            #region 发送微信
            if (weChatList.Count > 0)
            {
                SendSMSParam param = new SendSMSParam();
                param.PhoneList = weChatList;
                param.Message   = news.Content;
                ThreadPool.QueueUserWorkItem(new WaitCallback(LibSMSHelper.SendWeiXinMsg), param);
            }
            #endregion
        }
Example #2
0
        private void ExecBusinessTask(object obj)
        {
            LibTaskParam    param      = (LibTaskParam)obj;
            LibBusinessTask taskDefine = param.TaskDefine;

            //系统当天是否可以执行
            if (IsExecOfDay(taskDefine))
            {
                try
                {
                    param.Task.TaskState = TaskRunState.Running;
                    LibBcfBase bcf = LibBcfSystem.Default.GetBcfInstance(taskDefine.ProgId);
                    bcf.Handle = LibHandleCache.Default.GetSystemHandle();
                    Type     type      = bcf.GetType();
                    object[] destParam = RestoreParamFormat(type, taskDefine.BusinessTaskId, new string[] { taskDefine.ExecCondition });
                    object   result    = bcf.GetType().InvokeMember(taskDefine.BusinessTaskId, BindingFlags.InvokeMethod, null, bcf, destParam);
                    switch (bcf.Template.BillType)
                    {
                    case AxCRL.Template.BillType.Master:
                    case AxCRL.Template.BillType.Bill:
                        break;

                    case AxCRL.Template.BillType.Grid:
                        break;

                    case AxCRL.Template.BillType.DataFunc:
                        break;

                    case AxCRL.Template.BillType.Rpt:
                    case AxCRL.Template.BillType.DailyRpt:
                        DataSet dataSet = result as DataSet;
                        if (dataSet != null)
                        {
                            LibSysNews news = new LibSysNews();
                            news.Content  = taskDefine.MainContent;
                            news.Data     = LibBillDataSerializeHelper.Serialize(dataSet);
                            news.PersonId = "SYSTEM";
                            news.ProgId   = taskDefine.ProgId;
                            news.Title    = taskDefine.Title;
                            foreach (LibBusinessTaskLiaison item in taskDefine.Liaison)
                            {
                                news.UserList.Add(item.UserId);
                            }
                            LibSysNewsHelper.SendNews(news, false);
                        }
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    //将错误输出
                    string path = System.IO.Path.Combine(AxCRL.Comm.Runtime.EnvProvider.Default.MainPath, "Output", "Error", "ScheduleTask", string.Format("{0}.txt", DateTime.Now.Ticks));
                    OutputInfo(path, ex.ToString());
                }
                finally
                {
                    param.Task.TaskState = TaskRunState.Wait;
                }
            }
            bool canNextExec = true;

            if (taskDefine.ExecDate != 0)
            {
                int curDate = LibDateUtils.GetCurrentDate();
                if (taskDefine.ExecDate > curDate)
                {
                    param.Task.Timer.Dispose();
                    canNextExec          = false;
                    param.Task.TaskState = TaskRunState.Stop;
                }
                else if (taskDefine.ExecDate == curDate && taskDefine.ExecTime.Count > 0)
                {
                    int curTime = LibDateUtils.GetLibTimePart(LibDateUtils.GetCurrentDateTime(), LibDateTimePartEnum.Time);
                    if (taskDefine.ExecTime[taskDefine.ExecTime.Count - 1] < curTime)
                    {
                        param.Task.Timer.Dispose();
                        canNextExec          = false;
                        param.Task.TaskState = TaskRunState.Stop;
                    }
                }
            }
            if (canNextExec)
            {
                param.Task.Timer.Change(param.GetTaskDueTime(), Timeout.InfiniteTimeSpan);
            }
            else if (taskDefine.TaskType == LibTaskType.TempTask)
            {
                //删除临时任务
                LibDataAccess dataAccess = new LibDataAccess();
                dataAccess.ExecuteNonQuery(string.Format("delete AXPBUSINESSTEMPTASK where TASKID={0}", LibStringBuilder.GetQuotString(taskDefine.TaskId)), false);
            }
        }