Exemple #1
0
        public PushTaskDTO GetTask(string Id = "")
        {
            PushTaskDTO task = null;

            if (string.IsNullOrWhiteSpace(Id))
            {
                task = PushTaskRepository.TaskList.OrderBy(a => a.SendTime).FirstOrDefault(a => a.State == "New");
            }
            else
            {
                task = PushTaskRepository.TaskList.FirstOrDefault(a => a.ID == Id);
            }
            return(task);
        }
Exemple #2
0
        public void EndTask(PushTaskDTO task)
        {
            var db  = SqlHelper.Create("Base");
            var sql = string.Format(@"
insert into S_D_PushTask (ID,SourceID,FormInstanceID,Title,ShortContent,
SendUserID,SendUserName,SendTime,SourceType,
UserID,UserName,PushType,BeginTime,EndTime,
State,DoneLog) VALUES ('{0}','{1}','{2}','{3}','{4}',
'{5}','{6}','{7}','{8}',
'{9}','{10}','{11}','{12}','{13}',
'{14}','{15}')
", task.ID, task.SourceID, task.FormInstanceID, task.Title, task.ShortContent,
                                    task.SendUserID, task.SendUserName, task.SendTime, task.SourceType,
                                    task.UserID, task.UserName, task.PushType, task.BeginTime.ToString("yyyy-MM-dd HH:mm:ss"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                                    task.State, task.DoneLog);

            db.ExecuteNonQuery(sql);
        }
Exemple #3
0
        public void Execute(IJobExecutionContext context)
        {
            Log4NetConfig.Configure();
            var taskId        = "";
            var jobDataTaskId = context.Trigger.JobDataMap["taskId"];

            if (jobDataTaskId != null)
            {
                taskId = jobDataTaskId.ToString();
            }

            PushTaskRepository repo = new PushTaskRepository();

            try
            {
                //1.重新检测生成推送队列
                repo.AddTask();

                //2.循环队列推送
                PushTaskDTO task = repo.GetTask(taskId);
                while (task != null)
                {
                    try
                    {
                        taskId         = task.ID;
                        task.BeginTime = DateTime.Now;
                        //推送附带的总角标数(待办任务+待办消息)
                        string badgeCount = GetBadgeCountByUserID(task.UserID).ToString();
                        //接收人的账户名(唯一索引)
                        string userCode = GetUserCode(task.UserID);
                        string result   = "ok";

                        if (task.SourceType == "Task")
                        {
                            #region Task
                            //找到任务对应的菜单
                            var menuItem = PushTaskRepository.MenuItems.FirstOrDefault(c => c["Code"].ToString().Contains(task.FlowCode) && c["Type"].ToString() == "2");
                            if (menuItem != null)
                            {
                                var name             = menuItem["Name"].ToString();
                                var senderTaskUserId = task.SendUserID.Split(',').FirstOrDefault();
                                var senderCode       = GetUserCode(senderTaskUserId);

                                HttpHelper httpHelper = new HttpHelper();
                                Hashtable  pars       = new Hashtable();
                                pars.Add("FromUser", senderCode);
                                pars.Add("ToUser", userCode);
                                pars.Add("Content", task.ShortContent);
                                pars.Add("ID", task.SourceID);
                                pars.Add("Pid", task.FormInstanceID);
                                pars.Add("Type", PushTask.UndoTaskType);
                                pars.Add("Name", name);
                                pars.Add("Title", "审批任务(" + task.ShortContent + ")");
                                pars.Add("Description", task.ShortContent);
                                pars.Add("Badge", badgeCount);

                                if (string.IsNullOrEmpty(task.HuaWeiToken))
                                {
                                    result = httpHelper.GetHtml(MobileMsgsUrl, pars, true);
                                }
                                else
                                {
                                    HuaWeiPushNcMsg.sendPushMessage(task.HuaWeiToken, pars, 1);
                                    result = "ok";
                                }
                            }
                            else
                            {
                                result = "没有找到对应的对应入口菜单!发送失败!";
                            }
                            #endregion
                        }
                        else if (task.SourceType == "Msg")
                        {
                            #region Msg
                            HttpHelper httpHelper = new HttpHelper();
                            Hashtable  pars       = new Hashtable();
                            pars.Add("FromUser", "");
                            pars.Add("ToUser", userCode);
                            pars.Add("Content", task.ShortContent);
                            pars.Add("ID", task.SourceID);
                            pars.Add("Pid", "");
                            pars.Add("Type", PushTask.UnrecMsgType);
                            pars.Add("Name", "消息");
                            pars.Add("Title", "新消息(" + task.Title + ")");
                            pars.Add("Description", task.ShortContent);
                            pars.Add("Badge", badgeCount);

                            if (string.IsNullOrEmpty(task.HuaWeiToken))
                            {
                                result = httpHelper.GetHtml(MobileMsgsUrl, pars, true);
                            }
                            else
                            {
                                HuaWeiPushNcMsg.sendPushMessage(task.HuaWeiToken, pars, 1);
                                result = "ok";
                            }

                            #endregion
                        }
                        else if (task.SourceType == "Alarm")
                        {
                            #region Alarm
                            HttpHelper httpHelper = new HttpHelper();
                            Hashtable  pars       = new Hashtable();
                            pars.Add("FromUser", "");
                            pars.Add("ToUser", userCode);
                            pars.Add("Content", task.ShortContent);
                            pars.Add("ID", task.SourceID);
                            pars.Add("Pid", "");
                            pars.Add("Type", PushTask.UnexpiredAlarmType);
                            pars.Add("Name", "提醒");
                            pars.Add("Title", "事项提醒(" + task.Title + ")");
                            pars.Add("Description", task.ShortContent);
                            pars.Add("Badge", badgeCount);

                            if (string.IsNullOrEmpty(task.HuaWeiToken))
                            {
                                result = httpHelper.GetHtml(MobileMsgsUrl, pars, true);
                            }
                            else
                            {
                                HuaWeiPushNcMsg.sendPushMessage(task.HuaWeiToken, pars, 1);
                                result = "ok";
                            }

                            #endregion
                        }
                        task.State = "Success";
                        result     = result.Trim('\'', '"', ' ');
                        if (result != "ok")
                        {
                            throw new Exception(result);
                        }
                    }
                    catch (Exception e)
                    {
                        task.State   = "Error";
                        task.DoneLog = e.Message;
                        repo.EndTask(task);
                    }
                    finally
                    {
                        //获取下一个推送任务
                        task = repo.GetTask();
                    }
                }
            }
            catch (Exception ex)
            {
                var errorTask = repo.GetTask(taskId);
                if (errorTask != null)
                {
                    errorTask.State   = "Error";
                    errorTask.DoneLog = ex.Message;
                    repo.EndTask(errorTask);
                }
                LogWriter.Error(ex, ex.Message);
            }
            finally
            {
                var endTask = repo.GetTask(taskId);
                if (endTask != null)
                {
                    PushTaskRepository.LastSendTime = endTask.SendTime;
                }
            }
        }