feat: 增加顺运宝批量 AI 规格匹配 (#202)

This commit is contained in:
chengma
2026-08-14 10:30:08 +08:00
parent 0201dab98c
commit d64579e9b3
26 changed files with 1289 additions and 26 deletions
+53
View File
@@ -179,6 +179,46 @@ func (h *Handler) renderSybListWithLoginReason(c *gin.Context, keyword, pageRaw,
rangeWarning = defaults.Warning
}
actor := currentUser(c)
aiBatchID := strings.TrimSpace(c.Query("ai_batch_id"))
var aiBatch *service.AIMatchBatchView
if aiBatchID != "" {
aiBatch, err = service.GetAIMatchBatchView(h.db, actor, aiBatchID)
if errors.Is(err, service.ErrForbidden) {
fail(c, http.StatusForbidden, "没有权限查看这个 AI 匹配批次。")
return
}
if err != nil {
fail(c, http.StatusInternalServerError, "读取 AI 匹配批次失败,请刷新页面后重试。")
return
}
if aiBatch == nil {
fail(c, http.StatusNotFound, "AI 匹配批次不存在,可能已被清理。")
return
}
}
latestAIBatchID, err := service.LatestAIMatchBatchID(h.db, actor)
if err != nil {
fail(c, http.StatusInternalServerError, "读取最近 AI 匹配批次失败,请刷新页面后重试。")
return
}
aiBatchPageURL := func(id string) string {
query := url.Values{"ai_batch_id": {id}}
if keyword != "" {
query.Set("order_no", keyword)
}
if shop != "" {
query.Set("shop", shop)
}
if stage != "" {
query.Set("stage", stage)
}
query.Set("page", strconv.Itoa(result.Page))
query.Set("date_from", dateFrom)
query.Set("date_to", dateTo)
return "/syb?" + query.Encode()
}
cfg, cfgErr := config.Load()
switch {
case cfgErr != nil:
@@ -238,6 +278,19 @@ func (h *Handler) renderSybListWithLoginReason(c *gin.Context, keyword, pageRaw,
"AssignableClients": purchaseClients.Rows,
"PurchaseClientCount": purchaseClients.SelectableCount,
"EnabledSyncShopCount": enabledShopCount,
"AIMatchBatch": aiBatch,
"AIMatchBatchFetchURL": func() string {
if aiBatch == nil {
return ""
}
return "/syb/ai-match/" + url.PathEscape(aiBatch.BatchID)
}(),
"LatestAIMatchBatchURL": func() string {
if latestAIBatchID == "" {
return ""
}
return aiBatchPageURL(latestAIBatchID)
}(),
}))
}