From 9d166ef60f04b02fdc76144e658c985bce8657e5 Mon Sep 17 00:00:00 2001 From: zhu327 Date: Thu, 9 Nov 2023 16:21:26 +0800 Subject: [PATCH] fix: subject template group --- pkg/database/dao/subject_template_group.go | 2 +- pkg/service/group.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/database/dao/subject_template_group.go b/pkg/database/dao/subject_template_group.go index b1d2fdbc..1bf23f56 100644 --- a/pkg/database/dao/subject_template_group.go +++ b/pkg/database/dao/subject_template_group.go @@ -120,7 +120,7 @@ func (m *subjectTemplateGroupManager) GetMaxExpiredAtBySubjectGroup( ) (int64, error) { var expiredAt int64 query := `SELECT - MAX(expired_at) + COALESCE(MAX(expired_at), 0) FROM subject_template_group WHERE subject_pk = ? AND group_pk = ? diff --git a/pkg/service/group.go b/pkg/service/group.go index e8afbb8d..a1792089 100644 --- a/pkg/service/group.go +++ b/pkg/service/group.go @@ -514,7 +514,7 @@ func (l *groupService) BulkDeleteGroupMembers( for _, subjectPK := range subjectPKs { // 如果还有其它的未过期的, 不需要删除 expiredAt, err := l.subjectTemplateGroupManager.GetMaxExpiredAtBySubjectGroup(subjectPK, groupPK, 0) - if err != nil && err != ErrGroupMemberNotFound { + if err != nil { return nil, errorWrapf( err, "getMaxExpiredAtBySubjectGroup subjectPK=`%d`, groupPK=`%d` fail", @@ -523,7 +523,7 @@ func (l *groupService) BulkDeleteGroupMembers( ) } - if err == nil && expiredAt > now { + if expiredAt > now { continue } @@ -880,7 +880,7 @@ func (l *groupService) GetMaxExpiredAtBySubjectGroup(subjectPK, groupPK int64, e groupPK, excludeTemplateID, ) - if err2 != nil && !errors.Is(err2, sql.ErrNoRows) { + if err2 != nil { err2 = errorx.Wrapf( err2, GroupSVC, @@ -893,7 +893,7 @@ func (l *groupService) GetMaxExpiredAtBySubjectGroup(subjectPK, groupPK int64, e return 0, err2 } - if errors.Is(err1, sql.ErrNoRows) && errors.Is(err2, sql.ErrNoRows) { + if errors.Is(err1, sql.ErrNoRows) && subjectTemplateGroupExpiredAt == 0 { return 0, ErrGroupMemberNotFound }