fix( db):修复db 查询 结果为空
This commit is contained in:
1 parent
ba2f17599d
commit
b87a0c5a8f
22 files changed
+100
-85
No files matched your search
@@ -65,7 +65,7 @@ func (s *sAdmin) ListUsers(ctx context.Context, req *v1.AdminUserListReq) (*v1.A
|
||||
err = m.OrderDesc("id").
|
||||
Page(page, pageSize).
|
||||
Scan(&users)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ func (s *sAdmin) DeleteUser(ctx context.Context, req *v1.AdminUserDeleteReq) (*v
|
||||
}
|
||||
err := dao.SysAdminUsers.Ctx(ctx).
|
||||
Where("id", req.Id).Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
@@ -242,7 +242,7 @@ func (s *sAdmin) UpdateUserStatus(ctx context.Context, req *v1.AdminUserUpdateSt
|
||||
}
|
||||
err := dao.SysAdminUsers.Ctx(ctx).
|
||||
Where("id", req.Id).Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
|
||||
@@ -39,7 +39,7 @@ func (s *sAdmin) Login(ctx context.Context, req *v1.AdminLoginReq) (*v1.AdminLog
|
||||
err := dao.SysAdminUsers.Ctx(ctx).
|
||||
Where("username", strings.TrimSpace(req.Username)).
|
||||
Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
@@ -192,7 +192,7 @@ func (s *sAdmin) Refresh(ctx context.Context, req *v1.AdminRefreshReq) (*v1.Admi
|
||||
// Fetch current role from user table
|
||||
var adminUser *entity.SysAdminUsers
|
||||
err = dao.SysAdminUsers.Ctx(ctx).Where("id", session.UserId).Fields("role").Scan(&adminUser)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if adminUser == nil {
|
||||
@@ -249,7 +249,7 @@ func (s *sAdmin) ListSessions(ctx context.Context, req *v1.AdminSessionListReq)
|
||||
|
||||
var sessions []entity.SysSessions
|
||||
err = q.OrderDesc("created_at").Page(page, pageSize).Scan(&sessions)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ func (s *sAdmin) ChangePassword(ctx context.Context, req *v1.AdminChangePassword
|
||||
err := dao.SysAdminUsers.Ctx(ctx).
|
||||
Where("id", userID).
|
||||
Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
|
||||
@@ -63,7 +63,7 @@ func (s *sAdmin) UpdateChangelog(ctx context.Context, req *v1.ChangelogUpdateReq
|
||||
Id int64 `json:"id"`
|
||||
}
|
||||
err := g.DB().Model("clg_changelogs").Ctx(ctx).Where("id", req.Id).Scan(&cl)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cl == nil {
|
||||
@@ -93,7 +93,7 @@ func (s *sAdmin) DeleteChangelog(ctx context.Context, req *v1.ChangelogDeleteReq
|
||||
Id int64 `json:"id"`
|
||||
}
|
||||
err := g.DB().Model("clg_changelogs").Ctx(ctx).Where("id", req.Id).Scan(&cl)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cl == nil {
|
||||
@@ -115,7 +115,7 @@ func (s *sAdmin) PublishChangelog(ctx context.Context, req *v1.ChangelogPublishR
|
||||
Status string `json:"status"`
|
||||
}
|
||||
err := g.DB().Model("clg_changelogs").Ctx(ctx).Where("id", req.Id).Scan(&cl)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cl == nil {
|
||||
|
||||
@@ -95,7 +95,7 @@ func (s *sAdmin) ReplyToFeedback(ctx context.Context, req *v1.FeedbackReplyReq)
|
||||
Title string `json:"title"`
|
||||
}
|
||||
err := g.DB().Model("spt_feedbacks").Ctx(ctx).Where("id", req.Id).Scan(&fb)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if fb == nil {
|
||||
@@ -144,7 +144,7 @@ func (s *sAdmin) UpdateFeedbackStatus(ctx context.Context, req *v1.FeedbackUpdat
|
||||
Id int64 `json:"id"`
|
||||
}
|
||||
err := g.DB().Model("spt_feedbacks").Ctx(ctx).Where("id", req.Id).Scan(&fb)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if fb == nil {
|
||||
@@ -179,7 +179,7 @@ func (s *sAdmin) GetFeedbackStats(ctx context.Context, req *v1.FeedbackStatsReq)
|
||||
Fields("status, COUNT(*) as count").
|
||||
Group("status").
|
||||
Scan(&statusCounts)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ func (s *sAdmin) UpdateHelpCategory(ctx context.Context, req *v1.HelpCategoryUpd
|
||||
Id int64 `json:"id"`
|
||||
}
|
||||
err := g.DB().Model("spt_categories").Ctx(ctx).Where("id", req.Id).Scan(&cat)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cat == nil {
|
||||
@@ -104,7 +104,7 @@ func (s *sAdmin) DeleteHelpCategory(ctx context.Context, req *v1.HelpCategoryDel
|
||||
Id int64 `json:"id"`
|
||||
}
|
||||
err := g.DB().Model("spt_categories").Ctx(ctx).Where("id", req.Id).Scan(&cat)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cat == nil {
|
||||
@@ -174,7 +174,7 @@ func (s *sAdmin) CreateHelpArticle(ctx context.Context, req *v1.HelpArticleCreat
|
||||
Id int64 `json:"id"`
|
||||
}
|
||||
err := g.DB().Model("spt_categories").Ctx(ctx).Where("id", req.CategoryId).Scan(&cat)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cat == nil {
|
||||
@@ -226,7 +226,7 @@ func (s *sAdmin) UpdateHelpArticle(ctx context.Context, req *v1.HelpArticleUpdat
|
||||
Status string `json:"status"`
|
||||
}
|
||||
err := g.DB().Model("spt_articles").Ctx(ctx).Where("id", req.Id).Scan(&article)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if article == nil {
|
||||
@@ -247,7 +247,7 @@ func (s *sAdmin) UpdateHelpArticle(ctx context.Context, req *v1.HelpArticleUpdat
|
||||
Id int64 `json:"id"`
|
||||
}
|
||||
err = g.DB().Model("spt_categories").Ctx(ctx).Where("id", req.CategoryId).Scan(&cat)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cat.Id == 0 {
|
||||
@@ -296,7 +296,7 @@ func (s *sAdmin) DeleteHelpArticle(ctx context.Context, req *v1.HelpArticleDelet
|
||||
CategoryId int64 `json:"category_id"`
|
||||
}
|
||||
err := g.DB().Model("spt_articles").Ctx(ctx).Where("id", req.Id).Scan(&article)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if article == nil {
|
||||
@@ -347,7 +347,7 @@ func (s *sAdmin) ListHelpArticles(ctx context.Context, req *v1.HelpArticleListRe
|
||||
func (s *sAdmin) GetHelpArticle(ctx context.Context, req *v1.HelpArticleGetReq) (*v1.HelpArticleGetRes, error) {
|
||||
var article *v1.HelpArticleGetRes
|
||||
err := g.DB().Model("spt_articles").Ctx(ctx).Where("id", req.Id).Scan(&article)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if article == nil {
|
||||
|
||||
@@ -49,7 +49,7 @@ func (s *sAdmin) CreateMember(ctx context.Context, req *v1.AdminMemberCreateReq)
|
||||
}
|
||||
err := tx.Model("tnt_tenants").Ctx(ctx).
|
||||
Where("id", req.TenantID).Scan(&tenant)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return err
|
||||
}
|
||||
if tenant == nil {
|
||||
@@ -182,7 +182,7 @@ func (s *sAdmin) ListAllMembers(ctx context.Context, req *v1.AdminMemberListReq)
|
||||
OrderDesc("tnt_users.id").
|
||||
Page(page, pageSize).
|
||||
Scan(&members)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ func (s *sAdmin) DisableMember(ctx context.Context, req *v1.AdminMemberDisableRe
|
||||
err := dao.TntUsers.Ctx(ctx).
|
||||
Where("id", req.Id).
|
||||
Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
@@ -260,7 +260,7 @@ func (s *sAdmin) EnableMember(ctx context.Context, req *v1.AdminMemberEnableReq)
|
||||
err := dao.TntUsers.Ctx(ctx).
|
||||
Where("id", req.Id).
|
||||
Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
@@ -297,7 +297,7 @@ func (s *sAdmin) ResetMemberPassword(ctx context.Context, req *v1.AdminMemberRes
|
||||
err := dao.TntUsers.Ctx(ctx).
|
||||
Where("id", req.Id).
|
||||
Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
|
||||
@@ -41,7 +41,7 @@ func (s *sAdmin) ListModelOptions(ctx context.Context, req *v1.ModelOptionsReq)
|
||||
err := query.Fields("id, model_id, model_name, category").
|
||||
OrderAsc("category").OrderAsc("model_id").
|
||||
Scan(&models)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ func (s *sAdmin) ListModelPricing(ctx context.Context, req *v1.PricingListReq) (
|
||||
Fields("model_id, billing_mode, input_price, output_price, per_request_price").
|
||||
Where("model_id IN (?) AND min_tokens = 0", modelIDs).
|
||||
Scan(&pricingRows)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -434,7 +434,7 @@ func (s *sAdmin) GetModelPricing(ctx context.Context, req *v1.PricingGetReq) (*v
|
||||
Where("model_id", req.ModelID).
|
||||
OrderAsc("min_tokens").
|
||||
Scan(&rows)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ func (s *sAdmin) GetOrder(ctx context.Context, req *v1.OrderDetailReq) (*v1.Orde
|
||||
err := dao.OrdOrders.Ctx(ctx).
|
||||
Where("id", req.Id).
|
||||
Scan(&order)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if order == nil {
|
||||
@@ -71,7 +71,7 @@ func (s *sAdmin) RefundOrder(ctx context.Context, req *v1.OrderRefundReq) (*v1.O
|
||||
err := dao.OrdOrders.Ctx(ctx).
|
||||
Where("id", req.Id).
|
||||
Scan(&order)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if order.Status != "paid" && order.Status != "fulfilled" {
|
||||
@@ -183,7 +183,7 @@ func getOrderForComplete(ctx context.Context, orderID int64) (orderNo string, er
|
||||
}
|
||||
err = dao.OrdOrders.Ctx(ctx).
|
||||
Where("id", orderID).Scan(&order)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if order.Status != "pending" {
|
||||
|
||||
@@ -117,7 +117,7 @@ func (s *sAdmin) GetUserPermissions(ctx context.Context, req *v1.AdminPermission
|
||||
err := dao.SysAdminRolePerms.Ctx(ctx).
|
||||
Where("admin_user_id", req.Id).
|
||||
Scan(&perms)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ func (s *sAdmin) GetUserPermissions(ctx context.Context, req *v1.AdminPermission
|
||||
err = dao.SysAdminDataScopes.Ctx(ctx).
|
||||
Where("admin_user_id", req.Id).
|
||||
Scan(&scopes)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ func (s *sAdmin) UpdateUserPermissions(ctx context.Context, req *v1.AdminPermiss
|
||||
}
|
||||
err := dao.SysAdminUsers.Ctx(ctx).
|
||||
Where("id", req.Id).Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user.Role == "super_admin" {
|
||||
@@ -210,7 +210,7 @@ func (s *sAdmin) UpdateUserDataScopes(ctx context.Context, req *v1.AdminDataScop
|
||||
}
|
||||
err := dao.SysAdminUsers.Ctx(ctx).
|
||||
Where("id", req.Id).Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user.Role == "super_admin" {
|
||||
@@ -291,7 +291,7 @@ func GetDataScopes(ctx context.Context, userID int64, role string) ([]v1.DataSco
|
||||
err := dao.SysAdminDataScopes.Ctx(ctx).
|
||||
Where("admin_user_id", userID).
|
||||
Scan(&scopes)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ func (s *sAdmin) Verify2FA(ctx context.Context, req *v1.Admin2FAVerifyReq) (*v1.
|
||||
// Get user info for response
|
||||
var user *entity.SysAdminUsers
|
||||
err = dao.SysAdminUsers.Ctx(ctx).Where("id", claims.UserID).Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
@@ -235,7 +235,7 @@ func (s *sAdmin) LoginHistory(ctx context.Context, req *v1.AdminLoginHistoryReq)
|
||||
|
||||
var records []entity.AudLoginHistory
|
||||
err = q.OrderDesc("created_at").Page(page, pageSize).Scan(&records)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ func adminUserIdsByUsername(ctx context.Context, keyword string) ([]int64, error
|
||||
WhereLike("username", "%"+keyword+"%").
|
||||
WhereOrLike("display_name", "%"+keyword+"%").
|
||||
Scan(&users)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids := make([]int64, len(users))
|
||||
@@ -358,7 +358,7 @@ func (s *sAdmin) TenantLoginHistory(ctx context.Context, req *v1.AdminTenantLogi
|
||||
|
||||
var records []entity.AudLoginHistory
|
||||
err = q.OrderDesc("created_at").Page(page, pageSize).Scan(&records)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -402,7 +402,7 @@ func tenantUserIdsByKeyword(ctx context.Context, tenantID int64, keyword string)
|
||||
}
|
||||
var users []entity.TntUsers
|
||||
err := q.Scan(&users)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids := make([]int64, len(users))
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
v1 "github.com/qianfree/team-api/api/admin/v1"
|
||||
"github.com/qianfree/team-api/internal/consts"
|
||||
"github.com/qianfree/team-api/internal/dao"
|
||||
"github.com/qianfree/team-api/internal/logic/common"
|
||||
do "github.com/qianfree/team-api/internal/model/do"
|
||||
)
|
||||
|
||||
@@ -113,7 +114,7 @@ func (s *sAdmin) TaskDetail(ctx context.Context, req *v1.TaskDetailReq) (*v1.Tas
|
||||
CreatedAt *gtime.Time `json:"created_at"`
|
||||
}
|
||||
err := dao.TskModelTasks.Ctx(ctx).Where("id", req.ID).Scan(&task)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if task == nil {
|
||||
|
||||
@@ -49,7 +49,7 @@ func (s *sAdmin) TenantSelect(ctx context.Context, req *v1.TenantSelectReq) (*v1
|
||||
err = m.Fields("id, name, code").OrderAsc("id").
|
||||
Page(page, pageSize).
|
||||
Scan(&tenants)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ func (s *sAdmin) ListTenants(ctx context.Context, req *v1.TenantListReq) (*v1.Te
|
||||
err = m.OrderDesc("id").
|
||||
Page(page, pageSize).
|
||||
Scan(&tenants)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ func (s *sAdmin) GetTenant(ctx context.Context, req *v1.TenantGetReq) (*v1.Tenan
|
||||
}
|
||||
err := dao.TntTenants.Ctx(ctx).
|
||||
Where("id", req.Id).Scan(&tenant)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tenant == nil {
|
||||
@@ -375,7 +375,7 @@ func (s *sAdmin) UpdateTenantStatus(ctx context.Context, req *v1.TenantUpdateSta
|
||||
}
|
||||
err := dao.TntTenants.Ctx(ctx).
|
||||
Where("id", req.Id).Scan(&tenant)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tenant == nil {
|
||||
@@ -414,7 +414,7 @@ func (s *sAdmin) UpdateTenant(ctx context.Context, req *v1.TenantUpdateReq) (*v1
|
||||
data.Level = *req.Level
|
||||
var config entity.TntTenantLevelConfigs
|
||||
err := dao.TntTenantLevelConfigs.Ctx(ctx).Where("level", *req.Level).Scan(&config)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, common.NewBadRequestError("等级配置不存在")
|
||||
}
|
||||
if config.Id > 0 {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
|
||||
@@ -43,3 +46,13 @@ func NewUnauthorizedError(message string) error {
|
||||
message,
|
||||
)
|
||||
}
|
||||
|
||||
// IgnoreScanNoRows normalizes sql.ErrNoRows to nil.
|
||||
// GoFrame's Scan(&struct) returns sql.ErrNoRows when no record is found,
|
||||
// but callers typically check the zero-value result afterwards.
|
||||
func IgnoreScanNoRows(err error) error {
|
||||
if err != nil && errors.Is(err, sql.ErrNoRows) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
func getTenantSettings(ctx context.Context, tenantID int64) (map[string]any, error) {
|
||||
var tenant *entity.TntTenants
|
||||
err := dao.TntTenants.Ctx(ctx).Where("id", tenantID).Fields("settings").Scan(&tenant)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tenant == nil {
|
||||
@@ -255,7 +255,7 @@ func (s *sTenant) TenantRequestAuditLogDetail(ctx context.Context, req *v1.Tenan
|
||||
Where("id", req.Id).
|
||||
Where("tenant_id", tenantID).
|
||||
Scan(&record)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if record == nil {
|
||||
|
||||
@@ -432,7 +432,7 @@ func (s *sTenant) Refresh(ctx context.Context, req *v1.TenantRefreshReq) (*v1.Te
|
||||
// Fetch current role from user table
|
||||
var tntUser *entity.TntUsers
|
||||
err = dao.TntUsers.Ctx(ctx).Where("id", session.UserId).Fields("role").Scan(&tntUser)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tntUser == nil {
|
||||
@@ -458,7 +458,7 @@ func (s *sTenant) ChangePassword(ctx context.Context, req *v1.TenantChangePasswo
|
||||
var user *entity.TntUsers
|
||||
err := dao.TntUsers.Ctx(ctx).
|
||||
Where("id", userID).Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
|
||||
@@ -62,7 +62,7 @@ func (s *sTenant) ResetPassword(ctx context.Context, req *v1.TenantResetPassword
|
||||
err = dao.TntUsers.Ctx(ctx).
|
||||
Where("email", email).
|
||||
Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
@@ -130,7 +130,7 @@ func (s *sTenant) ChangeEmail(ctx context.Context, req *v1.TenantChangeEmailReq)
|
||||
var user *entity.TntUsers
|
||||
err = dao.TntUsers.Ctx(ctx).
|
||||
Where("id", userID).Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
|
||||
@@ -57,7 +57,7 @@ func (s *sTenant) ListMembers(ctx context.Context, req *v1.TenantMemberListReq)
|
||||
err = model.OrderDesc("id").
|
||||
Page(page, pageSize).
|
||||
Scan(&users)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func (s *sTenant) InviteMember(ctx context.Context, req *v1.TenantMemberInviteRe
|
||||
Where("id", tenantID).
|
||||
Fields("max_members").
|
||||
Scan(&tenant)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, gerror.Wrapf(err, "查询租户信息失败")
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ func (s *sTenant) JoinByInvite(ctx context.Context, req *v1.TenantMemberJoinReq)
|
||||
err := dao.TntInvitations.Ctx(ctx).
|
||||
Where("code", req.Code).
|
||||
Scan(&invitation)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if invitation.ID == 0 {
|
||||
@@ -246,7 +246,7 @@ func (s *sTenant) JoinByInvite(ctx context.Context, req *v1.TenantMemberJoinReq)
|
||||
Where("id", tenantID).
|
||||
Fields("max_members").
|
||||
Scan(&tenant)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return err
|
||||
}
|
||||
if int(memberCount) >= tenant.MaxMembers {
|
||||
@@ -402,7 +402,7 @@ func (s *sTenant) CreateMember(ctx context.Context, req *v1.TenantMemberCreateRe
|
||||
Where("id", tenantID).
|
||||
Fields("max_members").
|
||||
Scan(&tenant)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return gerror.Wrapf(err, "查询租户信息失败")
|
||||
}
|
||||
if int(memberCount) >= tenant.MaxMembers {
|
||||
@@ -481,7 +481,7 @@ func (s *sTenant) RemoveMember(ctx context.Context, req *v1.TenantMemberRemoveRe
|
||||
Where("id", memberID).
|
||||
Where("tenant_id", tenantID).
|
||||
Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user.Role == "owner" {
|
||||
@@ -532,7 +532,7 @@ func (s *sTenant) DisableMember(ctx context.Context, tenantID, userID int64) err
|
||||
Where("id", userID).
|
||||
Where("tenant_id", tenantID).
|
||||
Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return err
|
||||
}
|
||||
if user.Role == "owner" {
|
||||
@@ -570,7 +570,7 @@ func (s *sTenant) EnableMember(ctx context.Context, tenantID, userID int64) erro
|
||||
Where("id", userID).
|
||||
Where("tenant_id", tenantID).
|
||||
Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return err
|
||||
}
|
||||
if user.Status != "disabled" {
|
||||
@@ -616,7 +616,7 @@ func (s *sTenant) UpdateMemberRole(ctx context.Context, req *v1.TenantMemberUpda
|
||||
Where("id", memberID).
|
||||
Where("tenant_id", tenantID).
|
||||
Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user.Role == "owner" {
|
||||
@@ -653,7 +653,7 @@ func (s *sTenant) ResetMemberPassword(ctx context.Context, req *v1.TenantMemberR
|
||||
Where("id", memberID).
|
||||
Where("tenant_id", tenantID).
|
||||
Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user.Role == "owner" {
|
||||
@@ -703,7 +703,7 @@ func (s *sTenant) GetMember(ctx context.Context, req *v1.TenantMemberGetReq) (*v
|
||||
Where("id", req.Id).
|
||||
Where("tenant_id", tenantID).
|
||||
Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user.Id == 0 {
|
||||
@@ -734,7 +734,7 @@ func (s *sTenant) GetMemberUsage(ctx context.Context, req *v1.TenantMemberUsageR
|
||||
Where("id", req.Id).
|
||||
Where("tenant_id", tenantID).
|
||||
Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user.Id == 0 {
|
||||
@@ -789,7 +789,7 @@ func (s *sTenant) ListMemberApiKeys(ctx context.Context, req *v1.TenantMemberApi
|
||||
Where("id", req.Id).
|
||||
Where("tenant_id", tenantID).
|
||||
Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user.Id == 0 {
|
||||
@@ -885,7 +885,7 @@ func (s *sTenant) ExportMembers(ctx context.Context, req *v1.TenantMemberExportR
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
err := model.OrderDesc("id").Limit(1000).Offset(offset).Scan(&users)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return
|
||||
}
|
||||
for _, u := range users {
|
||||
|
||||
@@ -62,7 +62,7 @@ func (s *sTenant) OrderDetail(ctx context.Context, req *v1.TenantOrderDetailReq)
|
||||
Where("id", req.Id).
|
||||
Where("tenant_id", tenantID).
|
||||
Scan(&order)
|
||||
if err != nil {
|
||||
if err = lcommon.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if order == nil {
|
||||
@@ -95,7 +95,7 @@ func (s *sTenant) OrderCreate(ctx context.Context, req *v1.TenantOrderCreateReq)
|
||||
err := dao.PlnPlans.Ctx(ctx).
|
||||
Where("id", planID).
|
||||
Scan(&plan)
|
||||
if err != nil {
|
||||
if err = lcommon.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if plan.Status != "active" {
|
||||
@@ -264,7 +264,7 @@ func getOrderForPay(ctx context.Context, tenantID int64, orderID int64) (orderNo
|
||||
}
|
||||
err = dao.OrdOrders.Ctx(ctx).
|
||||
Where("id", orderID).Where("tenant_id", tenantID).Scan(&order)
|
||||
if err != nil {
|
||||
if err = lcommon.IgnoreScanNoRows(err); err != nil {
|
||||
return
|
||||
}
|
||||
if order == nil {
|
||||
@@ -426,7 +426,7 @@ func (s *sTenant) ExportOrders(ctx context.Context, req *v1.TenantOrderExportReq
|
||||
query = query.Where("status", req.Status)
|
||||
}
|
||||
err := query.OrderDesc("created_at").Limit(1000).Offset(offset).Scan(&orders)
|
||||
if err != nil {
|
||||
if err = lcommon.IgnoreScanNoRows(err); err != nil {
|
||||
return
|
||||
}
|
||||
for _, o := range orders {
|
||||
|
||||
@@ -37,7 +37,7 @@ func (s *sTenant) GetOrgInfo(ctx context.Context, req *v1.TenantOrgInfoReq) (*v1
|
||||
}
|
||||
err := dao.TntTenants.Ctx(ctx).
|
||||
Where("id", tenantID).Scan(&tenant)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tenant == nil {
|
||||
@@ -117,7 +117,7 @@ func (s *sTenant) TransferOwnership(ctx context.Context, req *v1.TenantOrgTransf
|
||||
Where("id", currentOwnerID).
|
||||
Where("tenant_id", tenantID).
|
||||
Scan(¤tUser)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ func (s *sTenant) TransferOwnership(ctx context.Context, req *v1.TenantOrgTransf
|
||||
Where("tenant_id", tenantID).
|
||||
Where("status", "active").
|
||||
Scan(&newOwner)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if newOwner.ID == 0 {
|
||||
@@ -197,7 +197,7 @@ func (s *sTenant) GetProfile(ctx context.Context, req *v1.TenantProfileReq) (*v1
|
||||
}
|
||||
err := dao.TntUsers.Ctx(ctx).
|
||||
Where("id", userID).Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
|
||||
@@ -42,7 +42,7 @@ func (s *sTenant) Verify2FA(ctx context.Context, req *v1.Tenant2FAVerifyReq) (*v
|
||||
|
||||
var user *entity.TntUsers
|
||||
err = dao.TntUsers.Ctx(ctx).Where("id", claims.UserID).Scan(&user)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if user == nil {
|
||||
@@ -83,7 +83,7 @@ func (s *sTenant) Verify2FA(ctx context.Context, req *v1.Tenant2FAVerifyReq) (*v
|
||||
// Get tenant info
|
||||
var tenant *entity.TntTenants
|
||||
err = dao.TntTenants.Ctx(ctx).Where("id", user.TenantId).Scan(&tenant)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tenant == nil {
|
||||
@@ -243,7 +243,7 @@ func (s *sTenant) LoginHistory(ctx context.Context, req *v1.TenantLoginHistoryRe
|
||||
|
||||
var records []entity.AudLoginHistory
|
||||
err = q.OrderDesc("created_at").Page(page, pageSize).Scan(&records)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ func tenantUserIdsByUsernameLocal(ctx context.Context, tenantID int64, keyword s
|
||||
Where("tenant_id", tenantID).
|
||||
Where("username LIKE ? OR display_name LIKE ?", "%"+keyword+"%", "%"+keyword+"%").
|
||||
Scan(&users)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids := make([]int64, len(users))
|
||||
@@ -356,7 +356,7 @@ func (s *sTenant) GetIPWhitelist(ctx context.Context, _ *v1.TenantIPWhitelistGet
|
||||
tenantID := middleware.GetTenantID(ctx)
|
||||
var tenant *entity.TntTenants
|
||||
err := dao.TntTenants.Ctx(ctx).Where("id", tenantID).Scan(&tenant)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tenant == nil {
|
||||
@@ -389,7 +389,7 @@ func (s *sTenant) UpdateIPWhitelist(ctx context.Context, req *v1.TenantIPWhiteli
|
||||
tenantID := middleware.GetTenantID(ctx)
|
||||
var tenant *entity.TntTenants
|
||||
err := dao.TntTenants.Ctx(ctx).Where("id", tenantID).Scan(&tenant)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tenant == nil {
|
||||
@@ -428,7 +428,7 @@ func (s *sTenant) UpdateIPWhitelist(ctx context.Context, req *v1.TenantIPWhiteli
|
||||
func CheckIPWhitelist(ctx context.Context, tenantID int64, ip string) bool {
|
||||
var tenant *entity.TntTenants
|
||||
err := dao.TntTenants.Ctx(ctx).Where("id", tenantID).Scan(&tenant)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return true
|
||||
}
|
||||
if tenant == nil {
|
||||
|
||||
@@ -132,7 +132,7 @@ func (s *sTenant) TenantTaskDetail(ctx context.Context, req *v1.TenantTaskDetail
|
||||
}
|
||||
|
||||
err := m.Scan(&task)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if task.Id == 0 {
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
|
||||
"github.com/qianfree/team-api/internal/dao"
|
||||
"github.com/qianfree/team-api/internal/logic/common"
|
||||
do "github.com/qianfree/team-api/internal/model/do"
|
||||
"github.com/qianfree/team-api/internal/model/entity"
|
||||
)
|
||||
@@ -39,7 +40,7 @@ var retryIntervals = []time.Duration{
|
||||
func deliverEventByID(ctx context.Context, eventID int64) {
|
||||
var evt *entity.OpnWebhookEvents
|
||||
err := dao.OpnWebhookEvents.Ctx(ctx).Where("id", eventID).Scan(&evt)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
g.Log().Errorf(ctx, "webhook: load event %d failed: %v", eventID, err)
|
||||
return
|
||||
}
|
||||
@@ -62,7 +63,7 @@ func deliverEventByID(ctx context.Context, eventID int64) {
|
||||
func deliverEvent(ctx context.Context, evt entity.OpnWebhookEvents) {
|
||||
var config *entity.OpnWebhookConfigs
|
||||
err := dao.OpnWebhookConfigs.Ctx(ctx).Where("id", evt.WebhookConfigId).Scan(&config)
|
||||
if err != nil {
|
||||
if err = common.IgnoreScanNoRows(err); err != nil {
|
||||
g.Log().Errorf(ctx, "webhook: load config %d failed: %v", evt.WebhookConfigId, err)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user