public void BackgroundJobManagerTest() { IIocManager iocResolver = new IocManager(); // 注册服务 iocResolver.Register <SimpleSendEmailJob>(DependencyLifeStyle.Transient); IBackgroundJobStore jobStore = new InMemoryBackgroundJobStore(); IBackgroundJobManager _backgroundJobManager = new BackgroundJobManager(iocResolver, jobStore, new Enterprises.Framework.Threading.AbpTimer()); _backgroundJobManager.Enqueue <SimpleSendEmailJob, SimpleSendEmailJobArgs>( new SimpleSendEmailJobArgs { Subject = "邮件主题", Body = "测试邮件", SenderUserId = 1000, TargetUserId = 2000 }); _backgroundJobManager.Enqueue <SimpleSendEmailJob, SimpleSendEmailJobArgs>( new SimpleSendEmailJobArgs { Subject = "邮件主题2", Body = "测试邮件2", SenderUserId = 1000, TargetUserId = 2000 }, BackgroundJobPriority.Normal, TimeSpan.FromSeconds(10)); _backgroundJobManager.Start(); Console.WriteLine($"datetime={DateTime.Now} end send Email "); }
/// <summary> /// 开单审核提醒 /// </summary> /// <param name="processTask"></param> /// <returns></returns> public virtual async Task SendTaskConfirmRemind(ProcessTask processTask) { var remindLogManager = Resolve <RemindLogManager>(); //所有有审核权限的用户 var users = await Resolve <UserManager>().FindByPermission("Module.JGKD.Button.ConfirmProcess"); //如果任务设定了审核人,只发送给此审核人员 if (!string.IsNullOrEmpty(processTask.Verifier) && users.Exists(o => o.Name == processTask.Verifier)) { users = users.Where(o => o.Name == processTask.Verifier).ToList(); } //获取对应用户的微信登录信息 var userLogins = await UserLoginRepository.GetAll() .Where(o => users.Select(u => u.Id).Contains(o.UserId)) .Where(o => o.LoginProvider == WeChatAuthProviderApi.Name) .Select(o => new { o.ProviderKey, o.UserId }) .ToListAsync(); foreach (var userLogin in userLogins) { var openid = userLogin.ProviderKey; var name = users.Where(o => o.Id == userLogin.UserId).Single().Name; //先产生一条提醒记录 var remindLog = new RemindLog() { RemindType = "开单审核提醒", Name = name, TenantId = AbpSession.TenantId, Message = processTask.Part?.Project?.ProjectSN + processTask.Part?.PartName + processTask.ProcessType?.ProcessTypeName, }; var remindLogId = await remindLogManager.InsertAndGetIdAsync(remindLog); var arg = new SendWeiXinMessageJobArgs() { OpenId = openid, DataId = processTask.Id, RemindLogId = remindLogId, }; BackgroundJobManager.Enqueue <TaskConfirmMessageJob, SendWeiXinMessageJobArgs>(arg); } }
/// <summary> /// 发送往来单位公告 /// </summary> /// <param name="units"></param> /// <param name="notice"></param> /// <returns></returns> public virtual async Task SendUnitsNotice(IEnumerable <Unit> units, Notice notice) { var remindLogManager = Resolve <RemindLogManager>(); foreach (var unit in units) { //被提醒人微信openid var openId = ""; try { openId = (await FindUnitOpenId(unit))[0]; } catch (Exception ex) { } if (!string.IsNullOrEmpty(openId)) { //进行发送提醒 //先产生一条提醒记录 var remindLog = new RemindLog() { RemindType = "往来单位公告提醒", Name = unit.UnitName, Message = notice.NoticeTitle, TenantId = AbpSession.TenantId }; var remindLogId = await remindLogManager.InsertAndGetIdAsync(remindLog); var arg = new SendWeiXinMessageJobArgs() { OpenId = openId, DataId = notice.Id, RemindLogId = remindLogId }; BackgroundJobManager.Enqueue <SendUnitNoticeMessageJob, SendWeiXinMessageJobArgs>(arg); } } }