diff --git a/internal/logic/job/poll/daily_report.go b/internal/logic/job/poll/daily_report.go index 3454d7f..6604571 100644 --- a/internal/logic/job/poll/daily_report.go +++ b/internal/logic/job/poll/daily_report.go @@ -174,18 +174,19 @@ func generateUserInformation( func getReviewsAndAdminsThatShouldDoNotification(ctx context.Context) ([]entity.Users, error) { var users []entity.Users - err := dao.Users.Ctx(ctx).Raw(fmt.Sprintf( - "SELECT * FROM `%s` WHERE `%s` = 1 OR `%s` = 1 IN ("+ // 筛选出管理员和审核员 - "SELECT `%s` FROM `%s` WHERE `%s` = 1 AND `%s` = 1"+ // 筛选出开启通知的用户 - ")", - dao.Users.Table(), - dao.Users.Columns().IsReviewer, - dao.Users.Columns().IsAdmin, - dao.UserNotification.Columns().UserId, - dao.UserNotification.Table(), - dao.UserNotification.Columns().EmailNotificationGlobal, - dao.UserNotification.Columns().EmailNotificationPollDailyReport, - )).Scan(&users) + err := dao.Users.Ctx(ctx).Raw( + fmt.Sprintf( + "SELECT * FROM `%s` WHERE `%s` IN (SELECT `%s` FROM `%s` WHERE `%s` = 1 AND `%s` = 1) AND (`%s` = 1 OR `%s` = 1)", + dao.Users.Table(), + dao.Users.Columns().Id, + dao.UserNotification.Columns().UserId, + dao.UserNotification.Table(), + dao.UserNotification.Columns().EmailNotificationGlobal, + dao.UserNotification.Columns().EmailNotificationPollDailyReport, + dao.Users.Columns().IsReviewer, + dao.Users.Columns().IsAdmin, + ), + ).Scan(&users) return users, err } diff --git a/internal/logic/notification/settings.go b/internal/logic/notification/settings.go index a34a7c7..752afde 100644 --- a/internal/logic/notification/settings.go +++ b/internal/logic/notification/settings.go @@ -10,7 +10,11 @@ import ( "github.com/hitokoto-osc/reviewer/internal/dao" ) -func (s *sNotification) GetUserIDsShouldDoNotification(ctx context.Context, userIDs []uint, settingField string) ([]uint, error) { +func (s *sNotification) GetUserIDsShouldDoNotification( + ctx context.Context, + userIDs []uint, + settingField string, +) ([]uint, error) { records, err := dao.UserNotification.Ctx(ctx). Fields(dao.UserNotification.Columns().UserId). // 只获取 UserId Where(dao.UserNotification.Columns().UserId, userIDs). // 给定 UserIds 列表 @@ -23,7 +27,10 @@ func (s *sNotification) GetUserIDsShouldDoNotification(ctx context.Context, user return gconv.Uints(records), nil } -func (s *sNotification) GetUsersShouldDoNotification(ctx context.Context, settingField string) ([]entity.Users, error) { +func (s *sNotification) GetUsersShouldDoNotification( + ctx context.Context, + settingField string, +) ([]entity.Users, error) { users, err := service.User().GetReviewersAndAdmins(ctx) if err != nil { return nil, err @@ -32,7 +39,11 @@ func (s *sNotification) GetUsersShouldDoNotification(ctx context.Context, settin for i := 0; i < len(users); i++ { usersIDs = append(usersIDs, users[i].Id) } - userIdsThatShouldDoNotification, err := s.GetUserIDsShouldDoNotification(ctx, usersIDs, PollCreatedNotificationSettingField) + userIdsThatShouldDoNotification, err := s.GetUserIDsShouldDoNotification( + ctx, + usersIDs, + PollCreatedNotificationSettingField, + ) if err != nil { return nil, err } @@ -52,7 +63,11 @@ func (s *sNotification) GetUsersShouldDoNotification(ctx context.Context, settin return users, nil } -func (s *sNotification) IsUserShouldDoNotification(ctx context.Context, settingField string, userID uint) (bool, error) { +func (s *sNotification) IsUserShouldDoNotification( + ctx context.Context, + settingField string, + userID uint, +) (bool, error) { record, err := dao.UserNotification.Ctx(ctx). Where(dao.UserNotification.Columns().UserId, userID). // 给定 UserIds 列表 Where(dao.UserNotification.Columns().EmailNotificationGlobal, 1). // 全局开启邮件通知