feat: Add owner account management feature with a new frontend list component and backend API/database integration.
This commit is contained in:
@@ -128,6 +128,84 @@ func HandleUploadValidate(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
// HandleRefetchAccountIDs 重新获取缺少 account_id 的母号
|
||||
func HandleRefetchAccountIDs(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
Error(w, http.StatusMethodNotAllowed, "仅支持 POST")
|
||||
return
|
||||
}
|
||||
if database.Instance == nil {
|
||||
Error(w, http.StatusInternalServerError, "数据库未初始化")
|
||||
return
|
||||
}
|
||||
|
||||
// 获取所有缺少 account_id 的 owners
|
||||
owners, err := database.Instance.GetOwnersWithoutAccountID()
|
||||
if err != nil {
|
||||
Error(w, http.StatusInternalServerError, fmt.Sprintf("查询数据库失败: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
if len(owners) == 0 {
|
||||
Success(w, map[string]interface{}{
|
||||
"message": "所有母号都已有 account_id",
|
||||
"total": 0,
|
||||
"success": 0,
|
||||
"fail": 0,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
logger.Info(fmt.Sprintf("开始重新获取 account_id: 共 %d 个", len(owners)), "", "upload")
|
||||
|
||||
// 并发获取 account_id
|
||||
var wg sync.WaitGroup
|
||||
sem := make(chan struct{}, 20) // 20 并发
|
||||
var mu sync.Mutex
|
||||
successCount := 0
|
||||
failCount := 0
|
||||
|
||||
for _, owner := range owners {
|
||||
wg.Add(1)
|
||||
sem <- struct{}{}
|
||||
|
||||
go func(o database.TeamOwner) {
|
||||
defer wg.Done()
|
||||
defer func() { <-sem }()
|
||||
|
||||
accountID, err := fetchAccountID(o.Token)
|
||||
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
if err != nil {
|
||||
failCount++
|
||||
logger.Warning(fmt.Sprintf("获取 account_id 失败 (%s): %v", o.Email, err), "", "upload")
|
||||
} else {
|
||||
// 更新数据库
|
||||
if updateErr := database.Instance.UpdateOwnerAccountID(o.ID, accountID); updateErr != nil {
|
||||
failCount++
|
||||
logger.Error(fmt.Sprintf("更新 account_id 失败 (%s): %v", o.Email, updateErr), "", "upload")
|
||||
} else {
|
||||
successCount++
|
||||
logger.Info(fmt.Sprintf("获取 account_id 成功: %s -> %s", o.Email, accountID), "", "upload")
|
||||
}
|
||||
}
|
||||
}(owner)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
logger.Info(fmt.Sprintf("重新获取 account_id 完成: 成功=%d, 失败=%d", successCount, failCount), "", "upload")
|
||||
|
||||
Success(w, map[string]interface{}{
|
||||
"message": "重新获取 account_id 完成",
|
||||
"total": len(owners),
|
||||
"success": successCount,
|
||||
"fail": failCount,
|
||||
})
|
||||
}
|
||||
|
||||
// fetchAccountIDsConcurrent 并发获取 account_id
|
||||
func fetchAccountIDsConcurrent(owners []database.TeamOwner, concurrency int) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
Reference in New Issue
Block a user