Skip to content

Commit

Permalink
fix(job): correct user that should do day report notification
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Aug 29, 2023
1 parent 756985a commit 904f26d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
25 changes: 13 additions & 12 deletions internal/logic/job/poll/daily_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
23 changes: 19 additions & 4 deletions internal/logic/notification/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 列表
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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). // 全局开启邮件通知
Expand Down

0 comments on commit 904f26d

Please sign in to comment.