CalendarSystemNotifyJob.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Abp.BackgroundJobs;
  2. using Abp.Dependency;
  3. using Abp.Domain.Repositories;
  4. using Abp.Domain.Uow;
  5. using VberZero.BaseSystem;
  6. using VberZero.BaseSystem.Users;
  7. using VberZero.DomainService.Calendar;
  8. using VberZero.DomainService.Notifications;
  9. using VberZero.DomainService.Notifications.Data;
  10. namespace VberZero.BackgroundJobs.CalendarNotify;
  11. public class CalendarNotifyBackgroundJob : BackgroundJob<CalendarNotifyArg>, ITransientDependency
  12. {
  13. public CalendarNotifyBackgroundJob(IRepository<User, long> userRepository, IRepository<SysCalendar> calendarRepository, IAppNotifier appNotifier, ICalendarEmail calendarEmail)
  14. {
  15. _userRepository = userRepository;
  16. _calendarRepository = calendarRepository;
  17. _appNotifier = appNotifier;
  18. _calendarEmail = calendarEmail;
  19. }
  20. private readonly IAppNotifier _appNotifier;
  21. private readonly ICalendarEmail _calendarEmail;
  22. private readonly IRepository<User, long> _userRepository;
  23. private readonly IRepository<SysCalendar> _calendarRepository;
  24. [UnitOfWork]
  25. public override void Execute(CalendarNotifyArg args)
  26. {
  27. var calendar = _calendarRepository.FirstOrDefault(a => a.Id == args.CalendarId);
  28. if (!calendar.IsNotify)
  29. {
  30. return;
  31. }
  32. var user = _userRepository.FirstOrDefault(a => a.Id == args.UserId);
  33. if (calendar.NotifyTypes.Contains(VzDefinition.CalendarNotifyType.All))
  34. {
  35. SystemNotify(user, calendar);
  36. EmailNotify(user, calendar);
  37. PhoneNotify(user, calendar);
  38. }
  39. else
  40. {
  41. if (calendar.NotifyTypes.Contains(VzDefinition.CalendarNotifyType.System))
  42. {
  43. SystemNotify(user, calendar);
  44. }
  45. if (calendar.NotifyTypes.Contains(VzDefinition.CalendarNotifyType.Email))
  46. {
  47. EmailNotify(user, calendar);
  48. }
  49. if (calendar.NotifyTypes.Contains(VzDefinition.CalendarNotifyType.Phone))
  50. {
  51. PhoneNotify(user, calendar);
  52. }
  53. }
  54. }
  55. private void SystemNotify(User user, SysCalendar calendar)
  56. {
  57. _appNotifier.SendCalendarNotifyAsync(user, new CalendarNotificationData(calendar.Title, calendar.Description, calendar.Id));
  58. }
  59. private void EmailNotify(User user, SysCalendar calendar)
  60. {
  61. _calendarEmail.SendCalendarNotifyAsync(user, calendar);
  62. }
  63. private void PhoneNotify(User user, SysCalendar calendar)
  64. {
  65. }
  66. }