feat: 支持顺运宝批量创建采集任务 (#153)
This commit is contained in:
@@ -611,6 +611,27 @@ func (h *Handler) SybCollectPdd(c *gin.Context) {
|
||||
h.sybRedirect(c, service.FormatCollectTaskMessage(result))
|
||||
}
|
||||
|
||||
// SybCollectPddBatch 为勾选的顺运宝明细批量创建 PDD 采集任务。
|
||||
// Service 会重新校验阶段、按 PDD 商品去重并核对指定客户端的可见范围。
|
||||
func (h *Handler) SybCollectPddBatch(c *gin.Context) {
|
||||
ids := c.PostFormArray("ids")
|
||||
if len(ids) == 0 {
|
||||
h.sybRedirect(c, "没有选择可采集的顺运宝明细,没有创建任务。")
|
||||
return
|
||||
}
|
||||
result, err := service.CreateSybPddCollectTasksForUser(
|
||||
h.db, currentUser(c), ids, c.PostForm("client_id"))
|
||||
if err != nil {
|
||||
message := "批量采集任务未创建:系统没有改动这一批数据,请稍后重试。"
|
||||
if service.IsValidationError(err) {
|
||||
message = "批量采集任务未创建:" + err.Error()
|
||||
}
|
||||
h.sybRedirect(c, message)
|
||||
return
|
||||
}
|
||||
h.sybRedirect(c, service.FormatCollectTaskMessage(result))
|
||||
}
|
||||
|
||||
// SybMatch 保存规格匹配结果。
|
||||
//
|
||||
// 关键:保存的是**可复用的商品规格映射**(写 spec_mappings),
|
||||
|
||||
@@ -166,3 +166,26 @@ func TestPurchaseTaskOptionsFromForm_忽略篡改模式并固定Live(t *testing.
|
||||
t.Fatalf("采购客户端读取错误: %+v", options)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSybCollectPddBatch_未选择时保留列表筛选(t *testing.T) {
|
||||
context, recorder := sybPostContext(t, url.Values{
|
||||
"order_no": {"ORDER-1"}, "shop": {"qwg8fkb044"},
|
||||
"stage": {"pdd_pending"}, "page": {"2"},
|
||||
})
|
||||
(&Handler{}).SybCollectPddBatch(context)
|
||||
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": "qwg8fkb044", "stage": "pdd_pending", "page": "2",
|
||||
} {
|
||||
if got := query.Get(name); got != want {
|
||||
t.Errorf("批量采集返回丢失 %s:got=%q want=%q Location=%s", name, got, want, location.String())
|
||||
}
|
||||
}
|
||||
if !strings.Contains(query.Get("msg"), "没有选择") {
|
||||
t.Fatalf("未选择应返回可读提示:%s", location.String())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ func Register(r *gin.Engine, db *sql.DB, onlineThreshold time.Duration) {
|
||||
pages.POST("/syb/login-and-sync", h.SybLoginAndSync)
|
||||
pages.POST("/syb/associate-pdd", h.SybAssociatePdd)
|
||||
pages.POST("/syb/collect-pdd", h.SybCollectPdd)
|
||||
pages.POST("/syb/collect-pdd-batch", h.SybCollectPddBatch)
|
||||
pages.POST("/syb/match", h.SybMatch)
|
||||
pages.POST("/syb/create-task", h.SybCreateTask)
|
||||
pages.POST("/syb/delete", h.SybDelete)
|
||||
|
||||
Reference in New Issue
Block a user