fix: 增加 AI 匹配失败弹窗并补齐部署配置 (#229)

This commit is contained in:
chengma
2026-08-14 17:48:58 +08:00
parent 03d3cb5ac9
commit 0208dc6b76
11 changed files with 105 additions and 6 deletions
+13 -2
View File
@@ -18,7 +18,7 @@ func (h *Handler) SybAIMatchCreate(c *gin.Context) {
actor := currentUser(c)
snapshot, err := service.LoadActiveAIMatchSnapshot(c.Request.Context(), h.db, h.aiSecrets, h.aiPolicy)
if err != nil {
h.sybRedirect(c, "AI 规格匹配未开始:"+err.Error())
h.sybRedirectAIMatchError(c, "AI 规格匹配未开始:"+err.Error())
return
}
batch, err := service.CreateAIMatchBatch(h.db, actor, c.PostFormArray("ids"), snapshot, time.Now())
@@ -27,7 +27,7 @@ func (h *Handler) SybAIMatchCreate(c *gin.Context) {
if service.IsValidationError(err) {
message = "AI 规格匹配未开始:" + err.Error()
}
h.sybRedirect(c, message)
h.sybRedirectAIMatchError(c, message)
return
}
actorCopy := *actor
@@ -42,6 +42,17 @@ func (h *Handler) SybAIMatchCreate(c *gin.Context) {
h.sybRedirectAIMatch(c, batch.BatchID, "AI 规格匹配已开始,可在进度窗口查看逐条结果")
}
// sybRedirectAIMatchError 使用独立参数返回列表,让页面明确弹出 AI 失败提示。
// 普通列表状态仍使用 msg,避免同步、采集等操作结果被误当成 AI 错误。
func (h *Handler) sybRedirectAIMatchError(c *gin.Context, message string) {
params := url.Values{}
appendSybFormState(params, c)
if message != "" {
params.Set("ai_error", strings.TrimSpace(message))
}
c.Redirect(http.StatusSeeOther, "/syb?"+params.Encode())
}
func (h *Handler) SybAIMatchStatus(c *gin.Context) {
view, err := service.GetAIMatchBatchView(h.db, currentUser(c), c.Param("batch_id"))
if errors.Is(err, service.ErrForbidden) {
+1
View File
@@ -279,6 +279,7 @@ func (h *Handler) renderSybListWithLoginReason(c *gin.Context, keyword, pageRaw,
"PurchaseClientCount": purchaseClients.SelectableCount,
"EnabledSyncShopCount": enabledShopCount,
"AIMatchBatch": aiBatch,
"AIMatchError": strings.TrimSpace(c.Query("ai_error")),
"AIMatchBatchFetchURL": func() string {
if aiBatch == nil {
return ""
+25
View File
@@ -87,6 +87,31 @@ func TestSybRedirectAfterStart_清除本次日期范围(t *testing.T) {
}
}
func TestSybRedirectAIMatchError_独立错误参数并保留列表状态(t *testing.T) {
context, recorder := sybPostContext(t, url.Values{
"order_no": {"ORDER-1"}, "shop": {"店铺A"}, "stage": {"mapping_pending"},
"page": {"2"}, "date_from": {"2026-08-13"}, "date_to": {"2026-08-14"},
})
(&Handler{}).sybRedirectAIMatchError(context, "AI 规格匹配未开始:密钥存储不可用")
location, err := url.Parse(recorder.Header().Get("Location"))
if err != nil {
t.Fatal(err)
}
query := location.Query()
for name, want := range map[string]string{
"order_no": "ORDER-1", "shop": "店铺A", "stage": "mapping_pending", "page": "2",
"date_from": "2026-08-13", "date_to": "2026-08-14",
"ai_error": "AI 规格匹配未开始:密钥存储不可用",
} {
if got := query.Get(name); got != want {
t.Errorf("AI 错误跳转丢失 %s:got=%q want=%q Location=%s", name, got, want, location.String())
}
}
if query.Has("msg") {
t.Fatalf("AI 错误不能混入普通状态消息:%s", location.String())
}
}
func TestSybHistoryPagination_保留筛选并重开弹窗(t *testing.T) {
view := sybHistoryPagination(2, 3, "ORDER-1", "店铺A", "pdd_missing", "2026-08-01", "2026-08-09")
for _, raw := range []string{view.FirstURL, view.PrevURL, view.NextURL, view.LastURL} {