实施业务用户组成员管理
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m42s

This commit is contained in:
2026-09-21 21:20:38 +08:00
parent 4a16eb0b1e
commit 22c3e7cc1a
14 changed files with 836 additions and 106 deletions

View File

@@ -151,12 +151,16 @@ func (s *BusinessUserGroupStore) ReplaceMemberGroup(ctx context.Context, account
return s.db.WithContext(ctx).Create(&missing).Error
}
// ClearMembers 删除给定账号的未删除成员关系,使账号回到未分组
func (s *BusinessUserGroupStore) ClearMembers(ctx context.Context, accountIDs []uint) error {
// RemoveMembersByGroup 按目标组和账号集合软删除成员关系,并返回实际影响行数
func (s *BusinessUserGroupStore) RemoveMembersByGroup(ctx context.Context, groupID uint, accountIDs []uint, operatorID uint) (int64, error) {
if len(accountIDs) == 0 {
return nil
return 0, nil
}
return s.db.WithContext(ctx).Where("account_id IN ?", accountIDs).Delete(&model.BusinessUserGroupMember{}).Error
now := time.Now()
result := s.db.WithContext(ctx).Model(&model.BusinessUserGroupMember{}).
Where("business_user_group_id = ? AND account_id IN ? AND deleted_at IS NULL", groupID, accountIDs).
Updates(map[string]any{"deleted_at": now, "updater": operatorID, "updated_at": now})
return result.RowsAffected, result.Error
}
// LockAccountsByIDs 在事务内对账号行本身按主键升序加行锁。
@@ -168,7 +172,7 @@ func (s *BusinessUserGroupStore) LockAccountsByIDs(ctx context.Context, accountI
return nil
}
var accounts []model.Account
return s.db.WithContext(ctx).Clauses(clause.Locking{Strength: "UPDATE"}).
return s.db.WithContext(ctx).Unscoped().Clauses(clause.Locking{Strength: "UPDATE"}).
Select("id").Where("id IN ?", accountIDs).Order("id ASC").Find(&accounts).Error
}