Exemple #1
0
        private void SendDelayTaskMessage(List <ProcessTask> processTasks, DelayType delayType)
        {
            foreach (var task in processTasks)
            {
                var remindInfos = _tacticManager.GetRemindPersonByDelayTask(task, delayType).GetAwaiter().GetResult();
                foreach (var remindInfo in remindInfos)
                {
                    var remindPerson = remindInfo.Person;
                    //如果提醒间隔小于1天,则不再提醒
                    var count = RemindLogManager.GetAll().Where(o => o.RemindType == "延期提醒" && o.Name == remindPerson.Name && o.TenantId == task.TenantId && o.Message == (task.ProcessSN + "-" + delayType.ToString()) && (o.CreationTime - DateTime.Now).TotalDays < 1).Count();
                    if (count == 0)
                    {
                        var openid = remindPerson.GetPropertyValue <string>("OpenId");
                        //先产生一条提醒记录
                        var remindLog = new RemindLog()
                        {
                            RemindType = "延期提醒",
                            Name       = remindPerson.Name,
                            TenantId   = task.TenantId,
                            Message    = task.ProcessSN + "-" + delayType.ToString()
                        };
                        var timespan = remindInfo.GetAvailableRemindTimeSpan();
                        if (timespan.TotalMinutes > 0)
                        {
                            remindLog.SetPropertyValue("errMsg", $"延迟{timespan.TotalMinutes.ToString("0")}分钟后运行");
                        }
                        var remindLogId = RemindLogManager.InsertAndGetIdAsync(remindLog).Result;
                        var arg         = new SendWeiXinMessageJobArgs()
                        {
                            OpenId      = openid,
                            DataId      = task.Id,
                            RemindLogId = remindLogId,
                            ExtendInfo  = delayType.ToString()
                        };


                        _backgroundJobManager.Enqueue <SendDelayTaskWeiXinMessageJob, SendWeiXinMessageJobArgs>(arg, BackgroundJobPriority.Normal, timespan);
                    }
                }
            }
        }
        public virtual void HandleEvent(EntityCreatedEventData <ProcessTaskReport> eventData)
        {
            //获取所有的被提醒人
            var remindInfos = _tacticManager.GetRemindPersonsByReport(eventData.Entity.Id).Result;

            foreach (var remindInfo in remindInfos)
            {
                var timespan     = remindInfo.GetAvailableRemindTimeSpan();
                var remindPerson = remindInfo.Person;
                var openid       = remindPerson.GetPropertyValue <string>("OpenId");
                //先产生一条提醒记录
                var remindLog = new RemindLog()
                {
                    RemindType = "报工提醒",
                    Name       = remindPerson.Name,
                    TenantId   = eventData.Entity.TenantId,
                    Message    = eventData.Entity.ReportType.ToString(),
                };
                if (timespan.TotalMinutes > 0)
                {
                    remindLog.SetPropertyValue("errMsg", $"延迟{timespan.TotalMinutes.ToString("0")}分钟后运行");
                }
                var remindLogId = RemindLogManager.InsertAndGetIdAsync(remindLog).Result;

                var arg = new SendWeiXinMessageJobArgs()
                {
                    OpenId      = openid,
                    DataId      = eventData.Entity.Id,
                    RemindLogId = remindLogId,
                };


                _backgroundJobManager.Enqueue <SendReportWeiXinMessageJob, SendWeiXinMessageJobArgs>(arg, BackgroundJobPriority.Normal, timespan);
                //_backgroundJobManager.Enqueue<SendReportWeiXinMessageJob, SendWeiXinMessageJobArgs>(arg);
                //WeiXin.WeiXinHelper.SendTemplateMessage(openid, templateId, url, message);
            }
            //_backgroundJobManager.Enqueue<SendReportWeiXinMessageJob, int>(eventData.Entity.Id);
        }