using Abp.BackgroundJobs; using Abp.Dependency; using Abp.Domain.Repositories; using Abp.Domain.Uow; using VberZero.BaseSystem; using VberZero.BaseSystem.Users; using VberZero.DomainService.Calendar; using VberZero.DomainService.Notifications; using VberZero.DomainService.Notifications.Data; namespace VberZero.BackgroundJobs.CalendarNotify; public class CalendarNotifyBackgroundJob : BackgroundJob, ITransientDependency { public CalendarNotifyBackgroundJob(IRepository userRepository, IRepository calendarRepository, IAppNotifier appNotifier, ICalendarEmail calendarEmail) { _userRepository = userRepository; _calendarRepository = calendarRepository; _appNotifier = appNotifier; _calendarEmail = calendarEmail; } private readonly IAppNotifier _appNotifier; private readonly ICalendarEmail _calendarEmail; private readonly IRepository _userRepository; private readonly IRepository _calendarRepository; [UnitOfWork] public override void Execute(CalendarNotifyArg args) { var calendar = _calendarRepository.FirstOrDefault(a => a.Id == args.CalendarId); if (!calendar.IsNotify) { return; } var user = _userRepository.FirstOrDefault(a => a.Id == args.UserId); if (calendar.NotifyTypes.Contains(VzDefinition.CalendarNotifyType.All)) { SystemNotify(user, calendar); EmailNotify(user, calendar); PhoneNotify(user, calendar); } else { if (calendar.NotifyTypes.Contains(VzDefinition.CalendarNotifyType.System)) { SystemNotify(user, calendar); } if (calendar.NotifyTypes.Contains(VzDefinition.CalendarNotifyType.Email)) { EmailNotify(user, calendar); } if (calendar.NotifyTypes.Contains(VzDefinition.CalendarNotifyType.Phone)) { PhoneNotify(user, calendar); } } } private void SystemNotify(User user, SysCalendar calendar) { _appNotifier.SendCalendarNotifyAsync(user, new CalendarNotificationData(calendar.Title, calendar.Description, calendar.Id)); } private void EmailNotify(User user, SysCalendar calendar) { _calendarEmail.SendCalendarNotifyAsync(user, calendar); } private void PhoneNotify(User user, SysCalendar calendar) { } }